BaseTools: VPD Tool to allocate VPD region be aligned based on value type
authorYonghong Zhu <yonghong.zhu@intel.com>
Mon, 18 Jan 2016 01:47:50 +0000 (01:47 +0000)
committeryzhu52 <yzhu52@Edk2>
Mon, 18 Jan 2016 01:47:50 +0000 (01:47 +0000)
Base on build spec update, ASCII strings(“string”), will be byte aligned,
Unicode strings(L”string”) will be two-byte aligned, Byte arrays,
{0x00, 0x01} will be 8-byte aligned.
This patch is going to update VPD Tool to allocate VOID* PCDs to an offset
value that is aligned based in syntax of the PCD value.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19651 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/Python/BPDG/GenVpd.py

index d1da99fe5faaa8f1175ee3f0d507556491962283..ee7e04295f1245afb0f0e0e50a3a6662cb629204 100644 (file)
@@ -344,7 +344,7 @@ class GenVPD :
                 #\r
                 # Enhanced for support "|" character in the string.\r
                 #\r
-                ValueList = ['', '', '', '','']    \r
+                ValueList = ['', '', '', '','']\r
 \r
                 ValueRe = re.compile(r'\s*L?\".*\|.*\"\s*$')\r
                 PtrValue = ValueRe.findall(line)\r
@@ -359,7 +359,7 @@ class GenVPD :
                 ValueList[0:len(TokenList)] = TokenList\r
 \r
                 if ValueUpdateFlag:\r
-                    ValueList[4] = PtrValue[0]                              \r
+                    ValueList[4] = PtrValue[0]\r
                 self.FileLinesList[count] = ValueList\r
                 # Store the line number\r
                 self.FileLinesList[count].append(str(count + 1))\r
@@ -400,14 +400,28 @@ class GenVPD :
                 PCD.SkuId        = PCD.SkuId.strip(' ')\r
                 PCD.PcdOffset    = PCD.PcdOffset.strip(' ')\r
                 PCD.PcdSize      = PCD.PcdSize.strip(' ')\r
-                PCD.PcdValue     = PCD.PcdValue.strip(' ')               \r
+                PCD.PcdValue     = PCD.PcdValue.strip(' ')\r
                 PCD.Lineno       = PCD.Lineno.strip(' ')\r
-                                      \r
+\r
                 #\r
                 # Store the original pcd value.\r
                 # This information will be useful while generate the output map file.\r
                 #\r
-                PCD.PcdUnpackValue    =  str(PCD.PcdValue)                              \r
+                PCD.PcdUnpackValue    =  str(PCD.PcdValue)\r
+\r
+                #\r
+                # If value is Unicode string (e.g. L""), then use 2-byte alignment\r
+                # If value is byte array (e.g. {}), then use 8-byte alignment\r
+                #\r
+                PCD.PcdOccupySize     =  int(PCD.PcdSize)\r
+                if PCD.PcdUnpackValue.startswith("{"):\r
+                    Alignment = 8\r
+                elif PCD.PcdUnpackValue.startswith("L"):\r
+                    Alignment = 2\r
+                else:\r
+                    Alignment = 1\r
+                if PCD.PcdOccupySize % Alignment != 0:\r
+                    PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 1) * Alignment\r
 \r
                 #\r
                 # Translate PCD size string to an integer value.\r
@@ -490,7 +504,7 @@ class GenVPD :
             for Pcd in self.PcdUnknownOffsetList :\r
                 Pcd.PcdBinOffset = NowOffset\r
                 Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))\r
-                NowOffset       += Pcd.PcdBinSize\r
+                NowOffset       += Pcd.PcdOccupySize\r
                 \r
             self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList\r
             return\r
@@ -514,14 +528,14 @@ class GenVPD :
                                 None)\r
 \r
             # Overlapped   \r
-            if PcdNow.PcdBinOffset + PcdNow.PcdBinSize > PcdNext.PcdBinOffset :\r
+            if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize > PcdNext.PcdBinOffset :\r
                 EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,\r
                                 "The offset of %s at line: %s is overlapped with %s at line: %s in file %s" % \\r
                                 (PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),\r
                                 None)\r
 \r
             # Has free space, raise a warning message   \r
-            if PcdNow.PcdBinOffset + PcdNow.PcdBinSize < PcdNext.PcdBinOffset :\r
+            if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize < PcdNext.PcdBinOffset :\r
                 EdkLogger.warn("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,\r
                                "The offsets have free space of between %s at line: %s and %s at line: %s in file %s" % \\r
                                (PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),\r
@@ -547,7 +561,7 @@ class GenVPD :
                     countOfUnfixedList = 0\r
                     while(countOfUnfixedList < lenOfUnfixedList) :\r
                         eachUnfixedPcd      = self.PcdUnknownOffsetList[countOfUnfixedList]\r
-                        needFixPcdSize      = eachUnfixedPcd.PcdBinSize\r
+                        needFixPcdSize      = eachUnfixedPcd.PcdOccupySize\r
                         # Not been fixed\r
                         if eachUnfixedPcd.PcdOffset == '*' :\r
                             # The offset un-fixed pcd can write into this free space\r
@@ -572,7 +586,7 @@ class GenVPD :
                                 LastOffset              += needFixPcdSize                            \r
                             else :\r
                                 # It can not insert into those two pcds, need to check still has other space can store it.\r
-                                LastOffset             = NowOffset + self.PcdFixedOffsetSizeList[FixOffsetSizeListCount].PcdBinSize\r
+                                LastOffset             = NowOffset + self.PcdFixedOffsetSizeList[FixOffsetSizeListCount].PcdOccupySize\r
                                 FixOffsetSizeListCount += 1\r
                                 break\r
                                                                                  \r
@@ -582,7 +596,7 @@ class GenVPD :
                         \r
             # No free space, smoothly connect with previous pcd. \r
             elif LastOffset == NowOffset :\r
-                LastOffset = NowOffset + eachFixedPcd.PcdBinSize\r
+                LastOffset = NowOffset + eachFixedPcd.PcdOccupySize\r
                 FixOffsetSizeListCount += 1\r
             # Usually it will not enter into this thunk, if so, means it overlapped. \r
             else :\r
@@ -601,7 +615,7 @@ class GenVPD :
             LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]\r
             NeedFixPcd = self.PcdUnknownOffsetList[0]\r
             \r
-            NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdBinSize\r
+            NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize\r
             NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))\r
             \r
             # Insert this pcd into fixed offset pcd list's tail.\r