]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
Add IMAGE_ATTRIBUTE_UEFI_IMAGE definition from UEFI 2.4 specification.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 5dc2cfd7bdc5cae62836dd54f78d824904aef4a9..8c62ac8e72a80e5ba79272a837908b5eabbe7cbf 100644 (file)
@@ -269,6 +269,7 @@ class WorkspaceAutoGen(AutoGen):
             GlobalData.gAutoGenPhase = True    \r
             Fdf = FdfParser(self.FdfFile.Path)\r
             Fdf.ParseFile()\r
+            GlobalData.gFdfParser = Fdf\r
             GlobalData.gAutoGenPhase = False\r
             PcdSet = Fdf.Profile.PcdDict\r
             ModuleList = Fdf.Profile.InfList\r
@@ -298,7 +299,14 @@ class WorkspaceAutoGen(AutoGen):
             DecPcds = {}\r
             DecPcdsKey = set()\r
             PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
-            Pkgs = PGen.PackageList\r
+            PkgSet = set()\r
+            for Inf in ModuleList:\r
+                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                if ModuleFile in Platform.Modules:\r
+                    continue\r
+                ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                PkgSet.update(ModuleData.Packages)\r
+            Pkgs = list(PkgSet) + list(PGen.PackageList)\r
             for Pkg in Pkgs:\r
                 for Pcd in Pkg.Pcds:\r
                     DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
@@ -760,6 +768,8 @@ class PlatformAutoGen(AutoGen):
         self.FdTargetList = self.Workspace.FdTargetList\r
         self.FvTargetList = self.Workspace.FvTargetList\r
         self.AllPcdList = []\r
+        # get the original module/package/platform objects\r
+        self.BuildDatabase = Workspace.BuildDatabase\r
 \r
         # flag indicating if the makefile/C-code file has been created or not\r
         self.IsMakeFileCreated  = False\r
@@ -794,12 +804,22 @@ class PlatformAutoGen(AutoGen):
         self._ModuleAutoGenList  = None\r
         self._LibraryAutoGenList = None\r
         self._BuildCommand = None\r
-\r
+        self._AsBuildInfList = []\r
+        self._AsBuildModuleList = []\r
+        if GlobalData.gFdfParser != None:\r
+            self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
+            for Inf in self._AsBuildInfList:\r
+                InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
+                M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
+                if not M.IsSupportedArch:\r
+                    continue\r
+                self._AsBuildModuleList.append(InfClass)\r
         # get library/modules for build\r
         self.LibraryBuildDirectoryList = []\r
         self.ModuleBuildDirectoryList = []\r
         # get the original module/package/platform objects\r
-        self.BuildDatabase = Workspace.BuildDatabase\r
+        self.LibraryBuildDirectoryList = []\r
+        self.ModuleBuildDirectoryList = []\r
         return True\r
 \r
     def __repr__(self):\r
@@ -886,8 +906,12 @@ class PlatformAutoGen(AutoGen):
     def CollectPlatformDynamicPcds(self):\r
         # for gathering error information\r
         NoDatumTypePcdList = set()\r
-\r
+        PcdNotInDb = []\r
         self._GuidValue = {}\r
+        FdfModuleList = []\r
+        for InfName in self._AsBuildInfList:\r
+            InfName = os.path.join(self.WorkspaceDir, InfName)\r
+            FdfModuleList.append(os.path.normpath(InfName))\r
         for F in self.Platform.Modules.keys():\r
             M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
             #GuidValue.update(M.Guids)\r
@@ -899,7 +923,42 @@ class PlatformAutoGen(AutoGen):
                 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
                     NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
 \r
+                if M.IsBinaryModule == True:\r
+                    PcdFromModule.IsFromBinaryInf = True\r
+                if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():\r
+                    PcdFromModule.IsFromDsc = True\r
+                else:\r
+                    PcdFromModule.IsFromDsc = False\r
                 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
+                    if F.Path not in FdfModuleList:\r
+                        # If one of the Source built modules listed in the DSC is not listed \r
+                        # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic \r
+                        # access method (it is only listed in the DEC file that declares the \r
+                        # PCD as PcdsDynamic), then build tool will report warning message\r
+                        # notify the PI that they are attempting to build a module that must \r
+                        # be included in a flash image in order to be functional. These Dynamic \r
+                        # PCD will not be added into the Database unless it is used by other \r
+                        # modules that are included in the FDF file.\r
+                        if PcdFromModule.Type in GenC.gDynamicPcd and \\r
+                            PcdFromModule.IsFromBinaryInf == False:\r
+                            # Print warning message to let the developer make a determine.\r
+                            if PcdFromModule not in PcdNotInDb:\r
+                                EdkLogger.warn("build",\r
+                                               "A PCD listed in the DSC (%s.%s, %s) is used by a module not in the FDF. If the PCD is not used by any module listed in the FDF this PCD will be ignored. " \\r
+                                               % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, self.Platform.MetaFile.Path),\r
+                                               File=self.MetaFile, \\r
+                                               ExtraData=None)\r
+                                PcdNotInDb.append(PcdFromModule)\r
+                            continue\r
+                        # If one of the Source built modules listed in the DSC is not listed in \r
+                        # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
+                        # access method (it is only listed in the DEC file that declares the \r
+                        # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
+                        # PCD to the Platform's PCD Database.\r
+                        if PcdFromModule.Type in GenC.gDynamicExPcd:\r
+                            if PcdFromModule not in PcdNotInDb:\r
+                                PcdNotInDb.append(PcdFromModule)\r
+                            continue\r
                     #\r
                     # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
                     # it should be stored in Pcd PEI database, If a dynamic only\r
@@ -916,6 +975,68 @@ class PlatformAutoGen(AutoGen):
                         self._DynaPcdList_[Index] = PcdFromModule\r
                 elif PcdFromModule not in self._NonDynaPcdList_:\r
                     self._NonDynaPcdList_.append(PcdFromModule)\r
+                elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
+                    Index = self._NonDynaPcdList_.index(PcdFromModule)\r
+                    if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
+                        #The PCD from Binary INF will override the same one from source INF\r
+                        self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
+                        PcdFromModule.Pending = False\r
+                        self._NonDynaPcdList_.append (PcdFromModule)\r
+        # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
+        DscModuleList = []\r
+        for ModuleInf in self.Platform.Modules.keys():\r
+            DscModuleList.append (os.path.normpath(ModuleInf.Path))\r
+        # add the PCD from modules that listed in FDF but not in DSC to Database \r
+        for InfName in FdfModuleList:\r
+            if InfName not in DscModuleList:\r
+                InfClass = PathClass(InfName)\r
+                M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
+                # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
+                # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here. \r
+                # For binary module, if in current arch, we need to list the PCDs into database.   \r
+                if not M.IsSupportedArch:\r
+                    continue\r
+                # Override the module PCD setting by platform setting\r
+                ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
+                for PcdFromModule in ModulePcdList:\r
+                    PcdFromModule.IsFromBinaryInf = True\r
+                    PcdFromModule.IsFromDsc = False\r
+                    # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
+                    if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
+                        EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
+                                        File=self.MetaFile,\r
+                                        ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
+                                        % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
+                    # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
+                    if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
+                        NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
+                    if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
+                        PcdFromModule.Phase = "PEI"\r
+                    if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:\r
+                        self._DynaPcdList_.append(PcdFromModule)\r
+                    elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
+                        self._NonDynaPcdList_.append(PcdFromModule)\r
+                    if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:\r
+                        Index = self._DynaPcdList_.index(PcdFromModule)\r
+                        self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
+                        self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
+        for PcdFromModule in self._NonDynaPcdList_:\r
+            # If a PCD is not listed in the DSC file, but binary INF files used by \r
+            # this platform all (that use this PCD) list the PCD in a [PatchPcds] \r
+            # section, AND all source INF files used by this platform the build \r
+            # that use the PCD list the PCD in either a [Pcds] or [PatchPcds] \r
+            # section, then the tools must NOT add the PCD to the Platform's PCD\r
+            # Database; the build must assign the access method for this PCD as \r
+            # PcdsPatchableInModule.\r
+            if PcdFromModule not in self._DynaPcdList_:\r
+                continue\r
+            Index = self._DynaPcdList_.index(PcdFromModule)\r
+            if PcdFromModule.IsFromDsc == False and \\r
+                PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
+                PcdFromModule.IsFromBinaryInf == True and \\r
+                self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
+                Index = self._DynaPcdList_.index(PcdFromModule)\r
+                self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
 \r
         # print out error information and break the build, if error found\r
         if len(NoDatumTypePcdList) > 0:\r
@@ -926,8 +1047,19 @@ class PlatformAutoGen(AutoGen):
                                       % NoDatumTypePcdListString)\r
         self._NonDynamicPcdList = self._NonDynaPcdList_\r
         self._DynamicPcdList = self._DynaPcdList_\r
-        self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
-        \r
+        # If PCD is listed in a PcdsDynamicHii, PcdsDynamicExHii, PcdsDynamicHii or PcdsDynamicExHii\r
+        # section, and the PCD is not used by any module that is listed in the DSC file, the build \r
+        # provide a warning message.\r
+        for PcdKey in self.Platform.Pcds.keys():\r
+            Pcd = self.Platform.Pcds[PcdKey]\r
+            if Pcd not in self._DynamicPcdList + PcdNotInDb and \\r
+                Pcd.Type in [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_HII, TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_HII]:\r
+                # Print warning message to let the developer make a determine.\r
+                EdkLogger.warn("build",\r
+                               "A %s PCD listed in the DSC (%s.%s, %s) is not used by any module." \\r
+                               % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, self.Platform.MetaFile.Path),\r
+                               File=self.MetaFile, \\r
+                               ExtraData=None)\r
         #\r
         # Sort dynamic PCD list to:\r
         # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
@@ -1099,7 +1231,7 @@ class PlatformAutoGen(AutoGen):
         self._DynamicPcdList.extend(UnicodePcdArray)\r
         self._DynamicPcdList.extend(HiiPcdArray)\r
         self._DynamicPcdList.extend(OtherPcdArray)\r
-            \r
+        self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
         \r
     ## Return the platform build data object\r
     def _GetPlatform(self):\r
@@ -1320,7 +1452,14 @@ class PlatformAutoGen(AutoGen):
                 self._PackageList.update(La.DependentPackageList)\r
             for Ma in self.ModuleAutoGenList:\r
                 self._PackageList.update(Ma.DependentPackageList)\r
-            self._PackageList = list(self._PackageList)\r
+            #Collect package set information from INF of FDF\r
+            PkgSet = set()\r
+            for ModuleFile in self._AsBuildModuleList:\r
+                if ModuleFile in self.Platform.Modules:\r
+                    continue\r
+                ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
+                PkgSet.update(ModuleData.Packages)\r
+            self._PackageList = list(self._PackageList) + list (PkgSet)\r
         return self._PackageList\r
 \r
     def _GetNonDynamicPcdDict(self):\r
@@ -1428,7 +1567,8 @@ class PlatformAutoGen(AutoGen):
     #  by the platform or current configuration\r
     #\r
     def ValidModule(self, Module):\r
-        return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances\r
+        return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
+            or Module in self._AsBuildModuleList\r
 \r
     ## Resolve the library classes in a module to library instances\r
     #\r
@@ -1962,6 +2102,7 @@ class PlatformAutoGen(AutoGen):
     BuildRule           = property(_GetBuildRule)\r
     ModuleAutoGenList   = property(_GetModuleAutoGenList)\r
     LibraryAutoGenList  = property(_GetLibraryAutoGenList)\r
+    GenFdsCommand       = property(_GenFdsCommand)\r
 \r
 ## ModuleAutoGen class\r
 #\r
@@ -3019,6 +3160,10 @@ class ModuleAutoGen(AutoGen):
     #                                       dependent libraries will be created\r
     #\r
     def CreateMakeFile(self, CreateLibraryMakeFile=True):\r
+        # Ignore generating makefile when it is a binary module\r
+        if self.IsBinaryModule:\r
+            return\r
+\r
         if self.IsMakeFileCreated:\r
             return\r
 \r
@@ -3039,6 +3184,11 @@ class ModuleAutoGen(AutoGen):
 \r
         self.IsMakeFileCreated = True\r
 \r
+    def CopyBinaryFiles(self):\r
+        for File in self.Module.Binaries:\r
+            SrcPath = File.Path\r
+            DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))\r
+            CopyLongFilePath(SrcPath, DstPath)\r
     ## Create autogen code for the module and its dependent libraries\r
     #\r
     #   @param      CreateLibraryCodeFile   Flag indicating if or not the code of\r
@@ -3052,6 +3202,9 @@ class ModuleAutoGen(AutoGen):
         if self.IsBinaryModule and self.PcdIsDriver != '':\r
             CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
             return\r
+        if self.IsBinaryModule:\r
+            self.CopyBinaryFiles()\r
+            return\r
 \r
         if not self.IsLibrary and CreateLibraryCodeFile:\r
             for LibraryAutoGen in self.LibraryAutoGenList:\r