# build a platform or a module\r
#\r
# Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
#\r
# This program and the accompanying materials\r
from __future__ import print_function\r
import Common.LongFilePathOs as os\r
import re\r
-from io import BytesIO\r
import sys\r
import glob\r
import time\r
import platform\r
import traceback\r
import encodings.ascii\r
-import itertools\r
import multiprocessing\r
\r
from struct import *\r
from threading import *\r
+import threading\r
from optparse import OptionParser\r
from subprocess import *\r
from Common import Misc as Utils\r
# read one line a time\r
Line = From.readline()\r
# empty string means "end"\r
- if Line is not None and Line != "":\r
- To(Line.rstrip())\r
+ if Line is not None and Line != b"":\r
+ To(Line.rstrip().decode(encoding='utf-8', errors='ignore'))\r
else:\r
break\r
if ExitFlag.isSet():\r
\r
# get all pending tasks\r
BuildTask._PendingQueueLock.acquire()\r
- BuildObjectList = BuildTask._PendingQueue.keys()\r
+ BuildObjectList = list(BuildTask._PendingQueue.keys())\r
#\r
# check if their dependency is resolved, and if true, move them\r
# into ready queue\r
time.sleep(0.1)\r
except BaseException as X:\r
#\r
- # TRICK: hide the output of threads left runing, so that the user can\r
+ # TRICK: hide the output of threads left running, so that the user can\r
# catch the error message easily\r
#\r
EdkLogger.SetLevel(EdkLogger.ERROR)\r
self.CompleteFlag = True\r
except:\r
#\r
- # TRICK: hide the output of threads left runing, so that the user can\r
+ # TRICK: hide the output of threads left running, so that the user can\r
# catch the error message easily\r
#\r
if not BuildTask._ErrorFlag.isSet():\r
self.OutputDir = OutputDir\r
self.DebugDir = DebugDir\r
self.Image = ImageClass\r
- self.Image.Size = (self.Image.Size / 0x1000 + 1) * 0x1000\r
+ self.Image.Size = (self.Image.Size // 0x1000 + 1) * 0x1000\r
\r
## The class implementing the EDK2 build process\r
#\r
GlobalData.gBinCacheDest = BuildOptions.BinCacheDest\r
GlobalData.gBinCacheSource = BuildOptions.BinCacheSource\r
GlobalData.gEnableGenfdsMultiThread = BuildOptions.GenfdsMultiThread\r
+ GlobalData.gDisableIncludePathCheck = BuildOptions.DisableIncludePathCheck\r
\r
if GlobalData.gBinCacheDest and not GlobalData.gUseHashCache:\r
EdkLogger.error("build", OPTION_NOT_SUPPORTED, ExtraData="--binary-destination must be used together with --hash.")\r
# Print the same path style with WORKSPACE env.\r
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]))))\r
EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory))\r
+ if "PYTHON3_ENABLE" in os.environ:\r
+ PYTHON3_ENABLE = os.environ["PYTHON3_ENABLE"]\r
+ if PYTHON3_ENABLE != "TRUE":\r
+ PYTHON3_ENABLE = "FALSE"\r
+ EdkLogger.quiet("%-16s = %s" % ("PYTHON3_ENABLE", PYTHON3_ENABLE))\r
+ if "PYTHON_COMMAND" in os.environ:\r
+ EdkLogger.quiet("%-16s = %s" % ("PYTHON_COMMAND", os.environ["PYTHON_COMMAND"]))\r
self.InitPreBuild()\r
self.InitPostBuild()\r
if self.Prebuild:\r
f = open(PrebuildEnvFile)\r
envs = f.readlines()\r
f.close()\r
- envs = itertools.imap(lambda l: l.split('=', 1), envs)\r
- envs = itertools.ifilter(lambda l: len(l) == 2, envs)\r
- envs = itertools.imap(lambda l: [i.strip() for i in l], envs)\r
+ envs = [l.split("=", 1) for l in envs ]\r
+ envs = [[I.strip() for I in item] for item in envs if len(item) == 2]\r
os.environ.update(dict(envs))\r
EdkLogger.info("\n- Prebuild Done -\n")\r
\r
LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)\r
#\r
- # Collect funtion address from Map file\r
+ # Collect function address from Map file\r
#\r
ImageMapTable = ModuleOutputImage.replace('.efi', '.map')\r
FunctionList = []\r
Name = StrList[1]\r
RelativeAddress = int (StrList[2], 16) - OrigImageBaseAddress\r
FunctionList.append ((Name, RelativeAddress))\r
- if ModuleInfo.Arch == 'IPF' and Name.endswith('_ModuleEntryPoint'):\r
- #\r
- # Get the real entry point address for IPF image.\r
- #\r
- ModuleInfo.Image.EntryPoint = RelativeAddress\r
+\r
ImageMap.close()\r
#\r
# Add general information.\r
#\r
if ModeIsSmm:\r
- MapBuffer.write('\n\n%s (Fixed SMRAM Offset, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
+ MapBuffer.append('\n\n%s (Fixed SMRAM Offset, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
elif AddrIsOffset:\r
- MapBuffer.write('\n\n%s (Fixed Memory Offset, BaseAddress=-0x%010X, EntryPoint=-0x%010X)\n' % (ModuleName, 0 - BaseAddress, 0 - (BaseAddress + ModuleInfo.Image.EntryPoint)))\r
+ MapBuffer.append('\n\n%s (Fixed Memory Offset, BaseAddress=-0x%010X, EntryPoint=-0x%010X)\n' % (ModuleName, 0 - BaseAddress, 0 - (BaseAddress + ModuleInfo.Image.EntryPoint)))\r
else:\r
- MapBuffer.write('\n\n%s (Fixed Memory Address, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
+ MapBuffer.append('\n\n%s (Fixed Memory Address, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
#\r
# Add guid and general seciton section.\r
#\r
elif SectionHeader[0] in ['.data', '.sdata']:\r
DataSectionAddress = SectionHeader[1]\r
if AddrIsOffset:\r
- MapBuffer.write('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress)))\r
+ MapBuffer.append('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress)))\r
else:\r
- MapBuffer.write('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress))\r
+ MapBuffer.append('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress))\r
#\r
# Add debug image full path.\r
#\r
- MapBuffer.write('(IMAGE=%s)\n\n' % (ModuleDebugImage))\r
+ MapBuffer.append('(IMAGE=%s)\n\n' % (ModuleDebugImage))\r
#\r
- # Add funtion address\r
+ # Add function address\r
#\r
for Function in FunctionList:\r
if AddrIsOffset:\r
- MapBuffer.write(' -0x%010X %s\n' % (0 - (BaseAddress + Function[1]), Function[0]))\r
+ MapBuffer.append(' -0x%010X %s\n' % (0 - (BaseAddress + Function[1]), Function[0]))\r
else:\r
- MapBuffer.write(' 0x%010X %s\n' % (BaseAddress + Function[1], Function[0]))\r
+ MapBuffer.append(' 0x%010X %s\n' % (BaseAddress + Function[1], Function[0]))\r
ImageMap.close()\r
\r
#\r
GuidString = MatchGuid.group()\r
if GuidString.upper() in ModuleList:\r
Line = Line.replace(GuidString, ModuleList[GuidString.upper()].Name)\r
- MapBuffer.write(Line)\r
+ MapBuffer.append(Line)\r
#\r
# Add the debug image full path.\r
#\r
if MatchGuid is not None:\r
GuidString = MatchGuid.group().split("=")[1]\r
if GuidString.upper() in ModuleList:\r
- MapBuffer.write('(IMAGE=%s)\n' % (os.path.join(ModuleList[GuidString.upper()].DebugDir, ModuleList[GuidString.upper()].Name + '.efi')))\r
+ MapBuffer.append('(IMAGE=%s)\n' % (os.path.join(ModuleList[GuidString.upper()].DebugDir, ModuleList[GuidString.upper()].Name + '.efi')))\r
\r
FvMap.close()\r
\r
RtSize = 0\r
# reserve 4K size in SMRAM to make SMM module address not from 0.\r
SmmSize = 0x1000\r
- IsIpfPlatform = False\r
- if 'IPF' in self.ArchList:\r
- IsIpfPlatform = True\r
for ModuleGuid in ModuleList:\r
Module = ModuleList[ModuleGuid]\r
GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (Module.MetaFile, Module.Arch, Module.ToolChain, Module.BuildTarget)\r
BtSize += ImageInfo.Image.Size\r
elif Module.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, EDK_COMPONENT_TYPE_RT_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, EDK_COMPONENT_TYPE_SAL_RT_DRIVER]:\r
RtModuleList[Module.MetaFile] = ImageInfo\r
- #IPF runtime driver needs to be at 2 page alignment.\r
- if IsIpfPlatform and ImageInfo.Image.Size % 0x2000 != 0:\r
- ImageInfo.Image.Size = (ImageInfo.Image.Size / 0x2000 + 1) * 0x2000\r
RtSize += ImageInfo.Image.Size\r
elif Module.ModuleType in [SUP_MODULE_SMM_CORE, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
SmmModuleList[Module.MetaFile] = ImageInfo\r
TopMemoryAddress = self.LoadFixAddress\r
if TopMemoryAddress < RtSize + BtSize + PeiSize:\r
EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is too low to load driver")\r
- # Make IPF runtime driver at 2 page alignment.\r
- if IsIpfPlatform:\r
- ReservedRuntimeMemorySize = TopMemoryAddress % 0x2000\r
- RtSize = RtSize + ReservedRuntimeMemorySize\r
\r
#\r
# Patch FixAddress related PCDs into EFI image\r
for PcdInfo in PcdTable:\r
ReturnValue = 0\r
if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:\r
- ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize / 0x1000))\r
+ ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize // 0x1000))\r
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:\r
- ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize / 0x1000))\r
+ ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize // 0x1000))\r
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:\r
- ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize / 0x1000))\r
+ ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize // 0x1000))\r
elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:\r
- ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize / 0x1000))\r
+ ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize // 0x1000))\r
if ReturnValue != 0:\r
EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo)\r
\r
- MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize / 0x1000))\r
- MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize / 0x1000))\r
- MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize / 0x1000))\r
+ MapBuffer.append('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize // 0x1000))\r
+ MapBuffer.append('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize // 0x1000))\r
+ MapBuffer.append('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize // 0x1000))\r
if len (SmmModuleList) > 0:\r
- MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize / 0x1000))\r
+ MapBuffer.append('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize // 0x1000))\r
\r
PeiBaseAddr = TopMemoryAddress - RtSize - BtSize\r
BtBaseAddr = TopMemoryAddress - RtSize\r
self._RebaseModule (MapBuffer, BtBaseAddr, BtModuleList, TopMemoryAddress == 0)\r
self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)\r
self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset=False, ModeIsSmm=True)\r
- MapBuffer.write('\n\n')\r
+ MapBuffer.append('\n\n')\r
sys.stdout.write ("\n")\r
sys.stdout.flush()\r
\r
#\r
# Save address map into MAP file.\r
#\r
- SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)\r
- MapBuffer.close()\r
+ SaveFileOnChange(MapFilePath, ''.join(MapBuffer), False)\r
if self.LoadFixAddress != 0:\r
sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" % (MapFilePath))\r
sys.stdout.flush()\r
if not Ma.IsLibrary:\r
ModuleList[Ma.Guid.upper()] = Ma\r
\r
- MapBuffer = BytesIO('')\r
+ MapBuffer = []\r
if self.LoadFixAddress != 0:\r
#\r
# Rebase module to the preferred memory address before GenFds\r
if not Ma.IsLibrary:\r
ModuleList[Ma.Guid.upper()] = Ma\r
\r
- MapBuffer = BytesIO('')\r
+ MapBuffer = []\r
if self.LoadFixAddress != 0:\r
#\r
# Rebase module to the preferred memory address before GenFds\r
#\r
# Rebase module to the preferred memory address before GenFds\r
#\r
- MapBuffer = BytesIO('')\r
+ MapBuffer = []\r
if self.LoadFixAddress != 0:\r
self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
\r
\r
# Look through the tool definitions for GUIDed tools\r
guidAttribs = []\r
- for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.iteritems():\r
+ for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.items():\r
if attrib.upper().endswith('_GUID'):\r
split = attrib.split('_')\r
thisPrefix = '_'.join(split[0:3]) + '_'\r
def Relinquish(self):\r
OldLogLevel = EdkLogger.GetLevel()\r
EdkLogger.SetLevel(EdkLogger.ERROR)\r
- #self.DumpBuildData()\r
Utils.Progressor.Abort()\r
if self.SpawnMode == True:\r
BuildTask.Abort()\r
EdkLogger.SetLevel(OldLogLevel)\r
\r
- def DumpBuildData(self):\r
- CacheDirectory = os.path.dirname(GlobalData.gDatabasePath)\r
- Utils.CreateDirectory(CacheDirectory)\r
- Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache"))\r
- Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase"))\r
-\r
- def RestoreBuildData(self):\r
- FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache")\r
- if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath):\r
- Utils.gFileTimeStampCache = Utils.DataRestore(FilePath)\r
- if Utils.gFileTimeStampCache is None:\r
- Utils.gFileTimeStampCache = {}\r
-\r
- FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase")\r
- if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath):\r
- Utils.gDependencyDatabase = Utils.DataRestore(FilePath)\r
- if Utils.gDependencyDatabase is None:\r
- Utils.gDependencyDatabase = {}\r
-\r
def ParseDefines(DefineList=[]):\r
DefineDict = {}\r
if DefineList is not None:\r
#\r
def MyOptionParser():\r
Parser = OptionParser(description=__copyright__, version=__version__, prog="build.exe", usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")\r
- Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'IPF', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch",\r
- help="ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.")\r
+ Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch",\r
+ help="ARCHS is one of list: IA32, X64, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.")\r
Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback,\r
help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,\r
Parser.add_option("--binary-destination", action="store", type="string", dest="BinCacheDest", help="Generate a cache of binary files in the specified directory.")\r
Parser.add_option("--binary-source", action="store", type="string", dest="BinCacheSource", help="Consume a cache of binary files from the specified directory.")\r
Parser.add_option("--genfds-multi-thread", action="store_true", dest="GenfdsMultiThread", default=False, help="Enable GenFds multi thread to generate ffs file.")\r
+ Parser.add_option("--disable-include-path-check", action="store_true", dest="DisableIncludePathCheck", default=False, help="Disable the include path check for outside of package.")\r
(Opt, Args) = Parser.parse_args()\r
return (Opt, Args)\r
\r
if not (MyBuild.LaunchPrebuildFlag and os.path.exists(MyBuild.PlatformBuildPath)):\r
MyBuild.Launch()\r
\r
- #MyBuild.DumpBuildData()\r
#\r
# All job done, no error found and no exception raised\r
#\r