]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / DscBuildData.py
index c2bc7050916f3f5f7afa443c1e9c19852dc0815a..f34cf180567f4dddfab26e80b55e4bdd02cc1579 100644 (file)
@@ -3,13 +3,7 @@
 #\r
 # Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>\r
 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ## Platform build information from DSC file\r
@@ -155,8 +149,14 @@ def GetDependencyList(FileStack, SearchPathList):
             if len(FileContent) == 0:\r
                 continue\r
 \r
-            if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
-                FileContent = unicode(FileContent, "utf-16")\r
+            try:\r
+                if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
+                    FileContent = FileContent.decode('utf-16')\r
+                else:\r
+                    FileContent = FileContent.decode()\r
+            except:\r
+                # The file is not txt file. for example .mcb file\r
+                continue\r
             IncludedFileList = gIncludePattern.findall(FileContent)\r
 \r
             for Inc in IncludedFileList:\r
@@ -242,7 +242,6 @@ class DscBuildData(PlatformBuildClassObject):
         self._Toolchain = Toolchain\r
         self._ToolChainFamily = None\r
         self._Clear()\r
-        self._HandleOverridePath()\r
         self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") else ""\r
         self.DefaultStores = None\r
         self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)\r
@@ -301,24 +300,6 @@ class DscBuildData(PlatformBuildClassObject):
         self._MacroDict         = None\r
         self.DefaultStores      = None\r
 \r
-    ## handle Override Path of Module\r
-    def _HandleOverridePath(self):\r
-        RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]\r
-        for Record in RecordList:\r
-            ModuleId = Record[6]\r
-            LineNo = Record[7]\r
-            ModuleFile = PathClass(NormPath(Record[0]), GlobalData.gWorkspace, Arch=self._Arch)\r
-            RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]\r
-            if RecordList != []:\r
-                SourceOverridePath = mws.join(GlobalData.gWorkspace, NormPath(RecordList[0][0]))\r
-\r
-                # Check if the source override path exists\r
-                if not os.path.isdir(SourceOverridePath):\r
-                    EdkLogger.error('build', FILE_NOT_FOUND, Message='Source override path does not exist:', File=self.MetaFile, ExtraData=SourceOverridePath, Line=LineNo)\r
-\r
-                # Add to GlobalData Variables\r
-                GlobalData.gOverrideDir[ModuleFile.Key] = SourceOverridePath\r
-\r
     ## Get current effective macros\r
     @property\r
     def _Macros(self):\r
@@ -336,7 +317,7 @@ class DscBuildData(PlatformBuildClassObject):
 \r
     ## Retrieve all information in [Defines] section\r
     #\r
-    #   (Retriving all [Defines] information in one-shot is just to save time.)\r
+    #   (Retrieving all [Defines] information in one-shot is just to save time.)\r
     #\r
     def _GetHeaderInfo(self):\r
         RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]\r
@@ -1512,9 +1493,9 @@ class DscBuildData(PlatformBuildClassObject):
                         else:\r
                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}\r
                     S_pcd_set[Pcd] = str_pcd_obj_str\r
-        self.FilterStrcturePcd(S_pcd_set)\r
         if S_pcd_set:\r
-            GlobalData.gStructurePcd[self.Arch] = S_pcd_set\r
+            GlobalData.gStructurePcd[self.Arch] = S_pcd_set.copy()\r
+        self.FilterStrcturePcd(S_pcd_set)\r
         for stru_pcd in S_pcd_set.values():\r
             for skuid in SkuIds:\r
                 if skuid in stru_pcd.SkuOverrideValues:\r
@@ -1530,6 +1511,9 @@ class DscBuildData(PlatformBuildClassObject):
                     stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {}) #{TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues})\r
                     if not NoDefault:\r
                         stru_pcd.ValueChain.add((skuid, ''))\r
+                if 'DEFAULT' in stru_pcd.SkuOverrideValues and not GlobalData.gPcdSkuOverrides.get((stru_pcd.TokenCName, stru_pcd.TokenSpaceGuidCName)):\r
+                    GlobalData.gPcdSkuOverrides.update(\r
+                        {(stru_pcd.TokenCName, stru_pcd.TokenSpaceGuidCName): {'DEFAULT':stru_pcd.SkuOverrideValues['DEFAULT']}})\r
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
                 for skuid in SkuIds:\r
                     nextskuid = skuid\r
@@ -1606,7 +1590,7 @@ class DscBuildData(PlatformBuildClassObject):
                 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
                     del pcd.SkuInfoList[TAB_COMMON]\r
 \r
-        map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])\r
+        list(map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType]))\r
         return Pcds\r
     @cached_property\r
     def PlatformUsedPcds(self):\r
@@ -1615,7 +1599,7 @@ class DscBuildData(PlatformBuildClassObject):
             FdfInfList = GlobalData.gFdfParser.Profile.InfList\r
         FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch) for Inf in FdfInfList]\r
         AllModulePcds = set()\r
-        ModuleSet = set(self._Modules.keys() + FdfModuleList)\r
+        ModuleSet = set(list(self._Modules.keys()) + FdfModuleList)\r
         for ModuleFile in ModuleSet:\r
             ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]\r
             AllModulePcds = AllModulePcds | ModuleData.PcdsName\r
@@ -1743,7 +1727,7 @@ class DscBuildData(PlatformBuildClassObject):
         except:\r
             EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)\r
         Result = Process.communicate()\r
-        return Process.returncode, Result[0], Result[1]\r
+        return Process.returncode, Result[0].decode(encoding='utf-8', errors='ignore'), Result[1].decode(encoding='utf-8', errors='ignore')\r
 \r
     @staticmethod\r
     def IntToCString(Value, ValueSize):\r
@@ -1789,7 +1773,8 @@ class DscBuildData(PlatformBuildClassObject):
                         EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
                                         (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
                     Value, ValueSize = ParseFieldValue(Value)\r
-                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
+                    if not Pcd.IsArray():\r
+                        CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                 else:\r
                     NewFieldName = ''\r
                     FieldName_ori = FieldName.strip('.')\r
@@ -1798,7 +1783,7 @@ class DscBuildData(PlatformBuildClassObject):
                         ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
                         FieldName = FieldName.split(']', 1)[1]\r
                     FieldName = NewFieldName + FieldName\r
-                    while '[' in FieldName:\r
+                    while '[' in FieldName and not Pcd.IsArray():\r
                         FieldName = FieldName.rsplit('[', 1)[0]\r
                         CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])\r
         for skuname in Pcd.SkuOverrideValues:\r
@@ -1820,7 +1805,8 @@ class DscBuildData(PlatformBuildClassObject):
                                     EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
                                                     (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
                                 Value, ValueSize = ParseFieldValue(Value)\r
-                                CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
+                                if not Pcd.IsArray():\r
+                                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                             else:\r
                                 NewFieldName = ''\r
                                 FieldName_ori = FieldName.strip('.')\r
@@ -1829,7 +1815,7 @@ class DscBuildData(PlatformBuildClassObject):
                                     ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
                                     FieldName = FieldName.split(']', 1)[1]\r
                                 FieldName = NewFieldName + FieldName\r
-                                while '[' in FieldName:\r
+                                while '[' in FieldName and not Pcd.IsArray():\r
                                     FieldName = FieldName.rsplit('[', 1)[0]\r
                                     CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])\r
         if Pcd.PcdFieldValueFromFdf:\r
@@ -1844,7 +1830,8 @@ class DscBuildData(PlatformBuildClassObject):
                     EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
                                     (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2]))\r
                 Value, ValueSize = ParseFieldValue(Value)\r
-                CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]);\r
+                if not Pcd.IsArray():\r
+                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]);\r
             else:\r
                 NewFieldName = ''\r
                 FieldName_ori = FieldName.strip('.')\r
@@ -1868,7 +1855,8 @@ class DscBuildData(PlatformBuildClassObject):
                     EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
                                     (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2]))\r
                 Value, ValueSize = ParseFieldValue(Value)\r
-                CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]);\r
+                if not Pcd.IsArray():\r
+                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromComm[FieldName.strip(".")][1], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][2], Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]);\r
             else:\r
                 NewFieldName = ''\r
                 FieldName_ori = FieldName.strip('.')\r
@@ -1877,7 +1865,7 @@ class DscBuildData(PlatformBuildClassObject):
                     ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
                     FieldName = FieldName.split(']', 1)[1]\r
                 FieldName = NewFieldName + FieldName\r
-                while '[' in FieldName:\r
+                while '[' in FieldName and not Pcd.IsArray():\r
                     FieldName = FieldName.rsplit('[', 1)[0]\r
                     CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])\r
         if Pcd.GetPcdMaxSize():\r
@@ -1908,10 +1896,11 @@ class DscBuildData(PlatformBuildClassObject):
                 PcdDefValue = Pcd.DefaultValue\r
             if lastoneisEmpty:\r
                 if "{CODE(" not in PcdDefValue:\r
-                    sizebasevalue_plus = "(%s / sizeof(%s) + 1)" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), "".join(r_datatype)))\r
-                    sizebasevalue = "(%s / sizeof(%s))" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), "".join(r_datatype)))\r
+                    sizebasevalue_plus = "(%s / sizeof(%s) + 1)" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), Pcd.BaseDatumType))\r
+                    sizebasevalue = "(%s / sizeof(%s))" % ((DscBuildData.GetStructurePcdMaxSize(Pcd), Pcd.BaseDatumType))\r
                     sizeof = "sizeof(%s)" % Pcd.BaseDatumType\r
-                    CApp = '  Size = %s %% %s ? %s : %s ;\n' % ( (DscBuildData.GetStructurePcdMaxSize(Pcd), sizeof, sizebasevalue_plus, sizebasevalue))\r
+                    CApp = '  int ArraySize = %s %% %s ? %s : %s ;\n' % ( (DscBuildData.GetStructurePcdMaxSize(Pcd), sizeof, sizebasevalue_plus, sizebasevalue))\r
+                    CApp += '  Size = ArraySize * sizeof(%s); \n' % Pcd.BaseDatumType\r
                 else:\r
                     CApp = "  Size = 0;\n"\r
             else:\r
@@ -1971,9 +1960,7 @@ class DscBuildData(PlatformBuildClassObject):
                                 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))\r
         DefaultValueFromDec = StringToArray(DefaultValueFromDec)\r
         Value, ValueSize = ParseFieldValue (DefaultValueFromDec)\r
-        if isinstance(Value, str):\r
-            CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)\r
-        elif IsArray:\r
+        if IsArray:\r
         #\r
         # Use memcpy() to copy value into field\r
         #\r
@@ -1982,6 +1969,8 @@ class DscBuildData(PlatformBuildClassObject):
             else:\r
                 CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)\r
                 CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
+        elif isinstance(Value, str):\r
+            CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)\r
         for index in Pcd.DefaultValues:\r
             FieldList = Pcd.DefaultValues[index]\r
             if not FieldList:\r
@@ -2001,18 +1990,16 @@ class DscBuildData(PlatformBuildClassObject):
                     EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
 \r
                 indicator = self.GetIndicator(index, FieldName,Pcd)\r
-                if isinstance(Value, str):\r
-                    CApp = CApp + '  %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                elif IsArray:\r
+                if IsArray:\r
                     #\r
                     # Use memcpy() to copy value into field\r
                     #\r
-                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)\r
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                     CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)\r
-\r
+                elif isinstance(Value, str):\r
+                    CApp = CApp + '  %s = %s; // From %s Line %d Value %s\n' % (indicator, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                 else:\r
                     if '[' in FieldName and ']' in FieldName:\r
                         Index = int(FieldName.split('[')[1].split(']')[0])\r
@@ -2121,8 +2108,7 @@ class DscBuildData(PlatformBuildClassObject):
                     #\r
                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)\r
                         CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                        CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
+                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                         CApp = CApp + '  memcpy (&%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (indicator, ValueSize, ValueSize)\r
                     else:\r
                         if '[' in FieldName and ']' in FieldName:\r
@@ -2191,7 +2177,7 @@ class DscBuildData(PlatformBuildClassObject):
                 #\r
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)\r
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
                 else:\r
                     if '[' in FieldName and ']' in FieldName:\r
@@ -2259,7 +2245,7 @@ class DscBuildData(PlatformBuildClassObject):
                 #\r
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.BaseDatumType, FieldName)\r
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.BaseDatumType, FieldName, ValueSize, Pcd.BaseDatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
                 else:\r
                     if '[' in FieldName and ']' in FieldName:\r
@@ -2385,7 +2371,7 @@ class DscBuildData(PlatformBuildClassObject):
                     for defaultstore in skuinfo.DefaultStoreDict:\r
                         pcddscrawdefaultvalue = self.GetPcdDscRawDefaultValue(Pcd, skuname, defaultstore)\r
                         if pcddscrawdefaultvalue:\r
-                            Value = skuinfo[defaultstore]\r
+                            Value = skuinfo.DefaultStoreDict[defaultstore]\r
                             if "{CODE(" in Value:\r
                                 realvalue = Value.strip()[6:-2] # "{CODE(").rstrip(")}"\r
                                 CApp += "static %s %s_%s_%s_%s_Value%s = %s;\n" % (Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,Pcd.TokenCName,skuname,defaultstore,Demesion,realvalue)\r
@@ -2560,7 +2546,7 @@ class DscBuildData(PlatformBuildClassObject):
         if BuildOptions:\r
             ArchBuildOptions = {arch:flags for arch,flags in BuildOptions.items() if arch != 'COMMON'}\r
             if len(ArchBuildOptions.keys()) == 1:\r
-                BuildOptions['COMMON'] |= (ArchBuildOptions.values()[0])\r
+                BuildOptions['COMMON'] |= (list(ArchBuildOptions.values())[0])\r
             elif len(ArchBuildOptions.keys()) > 1:\r
                 CommonBuildOptions = reduce(lambda x,y: x&y, ArchBuildOptions.values())\r
                 BuildOptions['COMMON'] |= CommonBuildOptions\r
@@ -2778,7 +2764,7 @@ class DscBuildData(PlatformBuildClassObject):
             elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
                 del pcd.SkuInfoList[TAB_COMMON]\r
 \r
-        map(self.FilterSkuSettings, Pcds.values())\r
+        list(map(self.FilterSkuSettings, Pcds.values()))\r
 \r
         return Pcds\r
 \r
@@ -2843,7 +2829,7 @@ class DscBuildData(PlatformBuildClassObject):
                     PcdObj.SkuInfoList[skuname].SkuId = skuid\r
                     PcdObj.SkuInfoList[skuname].SkuIdName = skuname\r
             if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
-                PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
+                PcdObj.DefaultValue = list(PcdObj.SkuInfoList.values())[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
             Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
         return Pcds\r
     ## Retrieve dynamic HII PCD settings\r
@@ -2964,7 +2950,6 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
             Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][DefaultStore] = DefaultValue\r
         for pcd in Pcds.values():\r
-            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
             pcd.DatumType = pcdDecObject.DatumType\r
             # Only fix the value while no value provided in DSC file.\r
@@ -2975,6 +2960,7 @@ class DscBuildData(PlatformBuildClassObject):
                         sku.DefaultStoreDict[default_store]=pcdDecObject.DefaultValue\r
                     pcd.DefaultValue = pcdDecObject.DefaultValue\r
             if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON not in pcd.SkuInfoList:\r
+                SkuInfoObj = list(pcd.SkuInfoList.values())[0]\r
                 valuefromDec = pcdDecObject.DefaultValue\r
                 SkuInfo = SkuInfoClass(TAB_DEFAULT, '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec, VariableAttribute=SkuInfoObj.VariableAttribute, DefaultStore={DefaultStore:valuefromDec})\r
                 pcd.SkuInfoList[TAB_DEFAULT] = SkuInfo\r
@@ -3004,7 +2990,7 @@ class DscBuildData(PlatformBuildClassObject):
             invalidpcd = ",".join(invalidhii)\r
             EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd)\r
 \r
-        map(self.FilterSkuSettings, Pcds.values())\r
+        list(map(self.FilterSkuSettings, Pcds.values()))\r
 \r
         return Pcds\r
 \r
@@ -3102,7 +3088,6 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
             Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = InitialValue\r
         for pcd in Pcds.values():\r
-            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
             pcd.DatumType = pcdDecObject.DatumType\r
             # Only fix the value while no value provided in DSC file.\r
@@ -3110,6 +3095,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if not sku.DefaultValue:\r
                     sku.DefaultValue = pcdDecObject.DefaultValue\r
             if TAB_DEFAULT not in pcd.SkuInfoList and TAB_COMMON not in pcd.SkuInfoList:\r
+                SkuInfoObj = list(pcd.SkuInfoList.values())[0]\r
                 valuefromDec = pcdDecObject.DefaultValue\r
                 SkuInfo = SkuInfoClass(TAB_DEFAULT, '0', '', '', '', '', SkuInfoObj.VpdOffset, valuefromDec)\r
                 pcd.SkuInfoList[TAB_DEFAULT] = SkuInfo\r
@@ -3129,7 +3115,7 @@ class DscBuildData(PlatformBuildClassObject):
                 for sku in pcd.SkuInfoList.values():\r
                     sku.DefaultValue = StringToArray(sku.DefaultValue) if sku.DefaultValue.startswith(('L"',"L'")) else sku.DefaultValue\r
 \r
-        map(self.FilterSkuSettings, Pcds.values())\r
+        list(map(self.FilterSkuSettings, Pcds.values()))\r
         return Pcds\r
 \r
     ## Add external modules\r