]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
BaseTools: Fix the bug for CArray PCD override in command line
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index c2e9418b84caaa219e08fb257fd5cd797a1538ee..277da357af0164b75584c347ddc570eb51f4853b 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # generate flash image\r
 #\r
-#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -30,7 +30,7 @@ from EfiSection import EfiSection
 import StringIO\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
-import Common.DataType\r
+from Common.DataType import *\r
 import Common.GlobalData as GlobalData\r
 from Common import EdkLogger\r
 from Common.String import *\r
@@ -39,13 +39,14 @@ from Common.Misc import SaveFileOnChange
 from Common.Misc import ClearDuplicatedInf\r
 from Common.Misc import GuidStructureStringToGuidString\r
 from Common.Misc import CheckPcdDatum\r
+from Common.Misc import BuildOptionPcdValueFormat\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + versionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2016, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation  All rights reserved."\r
 \r
 ## Tool entrance method\r
 #\r
@@ -303,6 +304,25 @@ def main():
         """Modify images from build output if the feature of loading driver at fixed address is on."""\r
         if GenFdsGlobalVariable.FixedLoadAddress:\r
             GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform)\r
+\r
+        # Record the FV Region info that may specific in the FD\r
+        if FdfParserObj.Profile.FvDict and FdfParserObj.Profile.FdDict:\r
+            for Fv in FdfParserObj.Profile.FvDict:\r
+                FvObj = FdfParserObj.Profile.FvDict[Fv]\r
+                for Fd in FdfParserObj.Profile.FdDict:\r
+                    FdObj = FdfParserObj.Profile.FdDict[Fd]\r
+                    for RegionObj in FdObj.RegionList:\r
+                        if RegionObj.RegionType != 'FV':\r
+                            continue\r
+                        for RegionData in RegionObj.RegionDataList:\r
+                            if FvObj.UiFvName.upper() == RegionData.upper():\r
+                                if FvObj.FvRegionInFD:\r
+                                    if FvObj.FvRegionInFD != RegionObj.Size:\r
+                                        EdkLogger.error("GenFds", FORMAT_INVALID, "The FV %s's region is specified in multiple FD with different value." %FvObj.UiFvName)\r
+                                else:\r
+                                    FvObj.FvRegionInFD = RegionObj.Size\r
+                                    RegionObj.BlockInfoOfRegion(FdObj.BlockSizeList, FvObj)\r
+\r
         """Call GenFds"""\r
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)\r
 \r
@@ -389,31 +409,6 @@ def CheckBuildOptionPcd():
 \r
             GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
 \r
-def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
-    if PcdDatumType == 'VOID*':\r
-        if Value.startswith('L'):\r
-            if not Value[1]:\r
-                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
-            Value = Value[0] + '"' + Value[1:] + '"'\r
-        elif Value.startswith('B'):\r
-            if not Value[1]:\r
-                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
-            Value = Value[1:]\r
-        else:\r
-            if not Value[0]:\r
-                EdkLogger.error('GenFds', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
-            Value = '"' + Value + '"'\r
-\r
-    IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
-    if not IsValid:\r
-        EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
-    if PcdDatumType == 'BOOLEAN':\r
-        Value = Value.upper()\r
-        if Value == 'TRUE' or Value == '1':\r
-            Value = '1'\r
-        elif Value == 'FALSE' or Value == '0':\r
-            Value = '0'\r
-    return  Value\r
 \r
 ## FindExtendTool()\r
 #\r
@@ -424,11 +419,11 @@ def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Val
 #  @param  NameGuid         The Guid name\r
 #\r
 def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
+    ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
     # if user not specify filter, try to deduce it from global data.\r
     if KeyStringList == None or KeyStringList == []:\r
         Target = GenFdsGlobalVariable.TargetName\r
         ToolChain = GenFdsGlobalVariable.ToolChainTag\r
-        ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
         if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
             EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
         KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
@@ -443,6 +438,9 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
     ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
     ToolPathTmp = None\r
     ToolOption = None\r
+    ToolPathKey = None\r
+    ToolOptionKey = None\r
+    KeyList = None\r
     for ToolDef in ToolDefinition.items():\r
         if NameGuid == ToolDef[1]:\r
             KeyList = ToolDef[0].split('_')\r
@@ -452,24 +450,55 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                   '_' + \\r
                   KeyList[2]\r
             if Key in KeyStringList and KeyList[4] == 'GUID':\r
-\r
-                ToolPath = ToolDefinition.get(Key + \\r
-                                               '_' + \\r
-                                               KeyList[3] + \\r
-                                               '_' + \\r
-                                               'PATH')\r
-\r
-                ToolOption = ToolDefinition.get(Key + \\r
-                                                '_' + \\r
-                                                KeyList[3] + \\r
-                                                '_' + \\r
-                                                'FLAGS')\r
+                ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+                ToolPath = ToolDefinition.get(ToolPathKey)\r
+                ToolOption = ToolDefinition.get(ToolOptionKey)\r
                 if ToolPathTmp == None:\r
                     ToolPathTmp = ToolPath\r
                 else:\r
                     if ToolPathTmp != ToolPath:\r
                         EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
 \r
+    BuildOption = {}\r
+    for Arch in CurrentArchList:\r
+        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+        # key is (ToolChainFamily, ToolChain, CodeBase)\r
+        for item in Platform.BuildOptions:\r
+            if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
+                if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
+                    if item[1] not in BuildOption:\r
+                        BuildOption[item[1]] = Platform.BuildOptions[item]\r
+        if BuildOption:\r
+            ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]\r
+            for Index in range(2, -1, -1):\r
+                for Key in dict(BuildOption):\r
+                    List = Key.split('_')\r
+                    if List[Index] == '*':\r
+                        for String in ToolDb[ToolList[Index]]:\r
+                            if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
+                                List[Index] = String\r
+                                NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
+                                if NewKey not in BuildOption:\r
+                                    BuildOption[NewKey] = BuildOption[Key]\r
+                                    continue\r
+                                del BuildOption[Key]\r
+                    elif List[Index] not in ToolDb[ToolList[Index]]:\r
+                        del BuildOption[Key]\r
+    if BuildOption:\r
+        if not KeyList:\r
+            for Op in BuildOption:\r
+                if NameGuid == BuildOption[Op]:\r
+                    KeyList = Op.split('_')\r
+                    Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
+                    if Key in KeyStringList and KeyList[4] == 'GUID':\r
+                        ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                        ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+        if ToolPathKey in BuildOption.keys():\r
+            ToolPathTmp = BuildOption.get(ToolPathKey)\r
+        if ToolOptionKey in BuildOption.keys():\r
+            ToolOption = BuildOption.get(ToolOptionKey)\r
+\r
     GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
     return ToolPathTmp, ToolOption\r
 \r