from GuidSection import GuidSection\r
from FvImageSection import FvImageSection\r
from Common.Misc import PeImageClass\r
+from AutoGen.GenDepex import DependencyExpression\r
+from PatchPcdValue.PatchPcdValue import PatchBinaryFile\r
\r
## generate FFS from INF\r
#\r
self.OptRomDefs = {}\r
self.PiSpecVersion = '0x00000000'\r
self.InfModule = None\r
- self.FinalBuildTargetList = []\r
+ self.FinalTargetSuffixMap = {}\r
+ self.CurrentLineNum = None\r
+ self.CurrentLineContent = None\r
+ self.FileName = None\r
+ self.InfFileName = None\r
\r
- ## GetFinalBuildTargetList() method\r
+ ## GetFinalTargetSuffixMap() method\r
#\r
# Get final build target list\r
- def GetFinalBuildTargetList(self):\r
+ def GetFinalTargetSuffixMap(self):\r
if not self.InfModule or not self.CurrentArch:\r
return []\r
- if not self.FinalBuildTargetList:\r
- self.FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch)\r
- return self.FinalBuildTargetList\r
+ if not self.FinalTargetSuffixMap:\r
+ FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch)\r
+ for File in FinalBuildTargetList:\r
+ self.FinalTargetSuffixMap.setdefault(os.path.splitext(File)[1], []).append(File)\r
+\r
+ # Check if current INF module has DEPEX\r
+ if '.depex' not in self.FinalTargetSuffixMap and self.InfModule.ModuleType != "USER_DEFINED" \\r
+ and not self.InfModule.DxsFile and not self.InfModule.LibraryClass:\r
+ ModuleType = self.InfModule.ModuleType\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+\r
+ if ModuleType != DataType.SUP_MODULE_USER_DEFINED:\r
+ for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():\r
+ if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:\r
+ self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]\r
+\r
+ StrModule = str(self.InfModule)\r
+ PlatformModule = None\r
+ if StrModule in PlatformDataBase.Modules:\r
+ PlatformModule = PlatformDataBase.Modules[StrModule]\r
+ for LibraryClass in PlatformModule.LibraryClasses:\r
+ if LibraryClass.startswith("NULL"):\r
+ self.InfModule.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
+\r
+ DependencyList = [self.InfModule]\r
+ LibraryInstance = {}\r
+ DepexList = []\r
+ while len(DependencyList) > 0:\r
+ Module = DependencyList.pop(0)\r
+ if not Module:\r
+ continue\r
+ for Dep in Module.Depex[self.CurrentArch, ModuleType]:\r
+ if DepexList != []:\r
+ DepexList.append('AND')\r
+ DepexList.append('(')\r
+ DepexList.extend(Dep)\r
+ if DepexList[-1] == 'END': # no need of a END at this time\r
+ DepexList.pop()\r
+ DepexList.append(')')\r
+ if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
+ break\r
+ for LibName in Module.LibraryClasses:\r
+ if LibName in LibraryInstance:\r
+ continue\r
+ if PlatformModule and LibName in PlatformModule.LibraryClasses:\r
+ LibraryPath = PlatformModule.LibraryClasses[LibName]\r
+ else:\r
+ LibraryPath = PlatformDataBase.LibraryClasses[LibName, ModuleType]\r
+ if not LibraryPath:\r
+ LibraryPath = Module.LibraryClasses[LibName]\r
+ if not LibraryPath:\r
+ continue\r
+ LibraryModule = GenFdsGlobalVariable.WorkSpace.BuildObject[LibraryPath, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+ LibraryInstance[LibName] = LibraryModule\r
+ DependencyList.append(LibraryModule)\r
+ if DepexList:\r
+ Dpx = DependencyExpression(DepexList, ModuleType, True)\r
+ if len(Dpx.PostfixNotation) != 0:\r
+ # It means this module has DEPEX\r
+ self.FinalTargetSuffixMap['.depex'] = [os.path.join(self.EfiOutputPath, self.BaseName) + '.depex']\r
+ return self.FinalTargetSuffixMap\r
\r
## __InfParse() method\r
#\r
\r
if self.CurrentArch != None:\r
\r
- Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch]\r
+ Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
#\r
# Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath\r
#\r
self.ShadowFromInfFile = Inf.Shadow\r
\r
else:\r
- Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON']\r
+ Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
self.BaseName = Inf.BaseName\r
self.ModuleGuid = Inf.Guid\r
self.ModuleType = Inf.ModuleType\r
\r
if Inf._Defs != None and len(Inf._Defs) > 0:\r
self.OptRomDefs.update(Inf._Defs)\r
- \r
+ self.PatchPcds = []\r
+ InfPcds = Inf.Pcds\r
+ Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+ FdfPcdDict = GenFdsGlobalVariable.FdfParser.Profile.PcdDict\r
+ DscModules = {}\r
+ for DscModule in Platform.Modules:\r
+ DscModules[str(DscModule).lower()] = Platform.Modules[DscModule]\r
+ for PcdKey in InfPcds:\r
+ Pcd = InfPcds[PcdKey]\r
+ if not hasattr(Pcd, 'Offset'):\r
+ continue\r
+ if Pcd.Type != 'PatchableInModule':\r
+ continue\r
+ PatchPcd = None\r
+ InfLowerPath = str(PathClassObj).lower()\r
+ if InfLowerPath in DscModules and PcdKey in DscModules[InfLowerPath].Pcds:\r
+ PatchPcd = DscModules[InfLowerPath].Pcds[PcdKey]\r
+ elif PcdKey in Platform.Pcds:\r
+ PatchPcd = Platform.Pcds[PcdKey]\r
+ DscOverride = False\r
+ if PatchPcd and Pcd.Type == PatchPcd.Type:\r
+ DefaultValue = PatchPcd.DefaultValue\r
+ DscOverride = True\r
+ FdfOverride = False\r
+ if PcdKey in FdfPcdDict:\r
+ DefaultValue = FdfPcdDict[PcdKey]\r
+ FdfOverride = True\r
+ if not DscOverride and not FdfOverride:\r
+ continue\r
+ if Pcd.DatumType == "VOID*":\r
+ if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:\r
+ continue\r
+ if DefaultValue[0] == 'L':\r
+ MaxDatumSize = str((len(DefaultValue) - 2) * 2)\r
+ elif DefaultValue[0] == '{':\r
+ MaxDatumSize = str(len(DefaultValue.split(',')))\r
+ else:\r
+ MaxDatumSize = str(len(DefaultValue) - 1)\r
+ if DscOverride:\r
+ Pcd.MaxDatumSize = PatchPcd.MaxDatumSize\r
+ if Pcd.MaxDatumSize in ['', None]:\r
+ Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))\r
+ else:\r
+ Base1 = Base2 = 10\r
+ if Pcd.DefaultValue.upper().startswith('0X'):\r
+ Base1 = 16\r
+ if DefaultValue.upper().startswith('0X'):\r
+ Base2 = 16\r
+ try:\r
+ PcdValueInImg = int(Pcd.DefaultValue, Base1)\r
+ PcdValueInDscOrFdf = int(DefaultValue, Base2)\r
+ if PcdValueInImg == PcdValueInDscOrFdf:\r
+ continue\r
+ except:\r
+ continue\r
+ if Pcd.DatumType == "VOID*":\r
+ if int(MaxDatumSize) > int(Pcd.MaxDatumSize):\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \\r
+ % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize)))\r
+ else:\r
+ if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \\r
+ or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]:\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \\r
+ % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+ Pcd.DefaultValue = DefaultValue\r
+ self.PatchPcds.append(Pcd)\r
self.InfModule = Inf\r
- \r
- GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)\r
- GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)\r
- GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" %self.ModuleType)\r
- GenFdsGlobalVariable.VerboseLogger("VersionString : %s" %self.VersionString)\r
- GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" %self.InfFileName)\r
+ self.PcdIsDriver = Inf.PcdIsDriver\r
+ self.IsBinaryModule = Inf.IsBinaryModule\r
+ GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)\r
+ GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid)\r
+ GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType)\r
+ GenFdsGlobalVariable.VerboseLogger("VersionString : %s" % self.VersionString)\r
+ GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName)\r
\r
#\r
# Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\\r
self.EfiOutputPath = self.__GetEFIOutPutPath__()\r
GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)\r
\r
+## PatchEfiFile\r
+ #\r
+ # Patch EFI file with patch PCD\r
+ #\r
+ # @param EfiFile: EFI file needs to be patched.\r
+ # @retval: Full path of patched EFI file: self.OutputPath + EfiFile base name\r
+ # If passed in file does not end with efi, return as is\r
+ #\r
+ def PatchEfiFile(self, EfiFile):\r
+ if os.path.splitext(EfiFile)[1].lower() != '.efi':\r
+ return EfiFile\r
+ if not self.PatchPcds:\r
+ return EfiFile\r
+ Basename = os.path.basename(EfiFile)\r
+ Output = os.path.join(self.OutputPath, Basename)\r
+ CopyLongFilePath(EfiFile, Output)\r
+ for Pcd in self.PatchPcds:\r
+ RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Pcd.DefaultValue, Pcd.MaxDatumSize)\r
+ if RetVal:\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, RetStr, File=self.InfFileName)\r
+ return Output\r
## GenFfs() method\r
#\r
# Generate FFS\r
\r
InfFileKey = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
DscArchList = []\r
- PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32']\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
if PlatformDataBase != None:\r
if InfFileKey in PlatformDataBase.Modules:\r
DscArchList.append ('IA32')\r
\r
- PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64']\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
if PlatformDataBase != None:\r
if InfFileKey in PlatformDataBase.Modules:\r
DscArchList.append ('X64')\r
\r
- PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF']\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
if PlatformDataBase != None:\r
if InfFileKey in (PlatformDataBase.Modules):\r
DscArchList.append ('IPF')\r
\r
- PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM']\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
if PlatformDataBase != None:\r
if InfFileKey in (PlatformDataBase.Modules):\r
DscArchList.append ('ARM')\r
\r
- PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC']\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
if PlatformDataBase != None:\r
if InfFileKey in (PlatformDataBase.Modules):\r
DscArchList.append ('EBC')\r
\r
+ PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'AARCH64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+ if PlatformDataBase != None:\r
+ if InfFileKey in (PlatformDataBase.Modules):\r
+ DscArchList.append ('AARCH64')\r
+\r
return DscArchList\r
\r
## GetCurrentArch() method\r
Arch = ''\r
OutputPath = ''\r
(ModulePath, FileName) = os.path.split(self.InfFileName)\r
- Index = FileName.find('.')\r
+ Index = FileName.rfind('.')\r
FileName = FileName[0:Index]\r
Arch = "NoneArch"\r
if self.CurrentArch != None:\r
SectAlignments = []\r
Index = 1\r
HasGneratedFlag = False\r
+ if self.PcdIsDriver == 'PEI_PCD_DRIVER':\r
+ if self.IsBinaryModule:\r
+ PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw")\r
+ else:\r
+ PcdExDbFileName = os.path.join(self.EfiOutputPath, "PEIPcdDataBase.raw")\r
+ PcdExDbSecName = os.path.join(self.OutputPath, "PEIPcdDataBaseSec.raw")\r
+ GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
+ [PcdExDbFileName],\r
+ "EFI_SECTION_RAW",\r
+ )\r
+ SectFiles.append(PcdExDbSecName)\r
+ SectAlignments.append(None)\r
+ elif self.PcdIsDriver == 'DXE_PCD_DRIVER':\r
+ if self.IsBinaryModule:\r
+ PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "DXEPcdDataBase.raw")\r
+ else:\r
+ PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw")\r
+ PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw")\r
+ GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
+ [PcdExDbFileName],\r
+ "EFI_SECTION_RAW",\r
+ )\r
+ SectFiles.append(PcdExDbSecName)\r
+ SectAlignments.append(None)\r
for Sect in Rule.SectionList:\r
SecIndex = '%d' %Index\r
SectList = []\r