[edk2] [Patch] BaseTools: Fix the bug to align VPD PCD based on value type

Yonghong Zhu posted 1 patch 6 years, 9 months ago
Failed in applying to current master (apply log)
BaseTools/Source/Python/BPDG/GenVpd.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
[edk2] [Patch] BaseTools: Fix the bug to align VPD PCD based on value type
Posted by Yonghong Zhu 6 years, 9 months ago
Spec required for VOID* VPD Pcd, Ascii string use byte alignment, byte
array use 8-byte alignment, unicode string use 2-byte alignment.
while when the VPD pcd offset use *, the offset generated in the .map
file not follow this rule.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
---
 BaseTools/Source/Python/BPDG/GenVpd.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
index 9861e7d..ec4da23 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -1,10 +1,10 @@
 ## @file
 #  This file include GenVpd class for fix the Vpd type PCD offset, and PcdEntry for describe
 #  and process each entry of vpd type PCD.
 #
-#  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
 #  which accompanies this distribution.  The full text of the license may be found at
 #  http://opensource.org/licenses/bsd-license.php
@@ -33,21 +33,22 @@ _FORMAT_CHAR = {1: 'B',
 #
 #  This class contain method to format and pack pcd's value.          
 #
 class PcdEntry:
     def __init__(self, PcdCName, SkuId,PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None, 
-                 PcdBinOffset=None, PcdBinSize=None):
+                 PcdBinOffset=None, PcdBinSize=None, Alignment=None):
         self.PcdCName       = PcdCName.strip()
         self.SkuId          = SkuId.strip()
         self.PcdOffset      = PcdOffset.strip()
         self.PcdSize        = PcdSize.strip()
         self.PcdValue       = PcdValue.strip()
         self.Lineno         = Lineno.strip()
         self.FileName       = FileName.strip()
         self.PcdUnpackValue = PcdUnpackValue
         self.PcdBinOffset   = PcdBinOffset
         self.PcdBinSize     = PcdBinSize
+        self.Alignment       = Alignment
         
         if self.PcdValue == '' :
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
                             "Invalid PCD format(Name: %s File: %s line: %s) , no Value specified!" % (self.PcdCName, self.FileName, self.Lineno))
 
@@ -432,20 +433,22 @@ class GenVPD :
                 elif PCD.PcdUnpackValue.startswith("L"):
                     Alignment = 2
                 else:
                     Alignment = 1
 
+                PCD.Alignment = Alignment
                 if PCD.PcdOffset != '*':
                     if PCD.PcdOccupySize % Alignment != 0:
                         if PCD.PcdUnpackValue.startswith("{"):
                             EdkLogger.warn("BPDG", "The offset value of PCD %s is not 8-byte aligned!" %(PCD.PcdCName), File=self.InputFileName)
                         else:
                             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, 'The offset value of PCD %s should be %s-byte aligned.' % (PCD.PcdCName, Alignment))
                 else:
                     if PCD.PcdOccupySize % Alignment != 0:
                         PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 1) * Alignment
 
+                PackSize = PCD.PcdOccupySize
                 if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):
                     PCD._PackBooleanValue(PCD.PcdValue)
                     self.FileLinesList[count] = PCD
                     count += 1
                     continue
@@ -516,10 +519,12 @@ class GenVPD :
         #
         if (len(self.PcdFixedOffsetSizeList) == 0) and (len(self.PcdUnknownOffsetList) != 0) :
             # The offset start from 0
             NowOffset = 0
             for Pcd in self.PcdUnknownOffsetList :
+                if NowOffset % Pcd.Alignment != 0:
+                    NowOffset = (NowOffset/ Pcd.Alignment + 1) * Pcd.Alignment
                 Pcd.PcdBinOffset = NowOffset
                 Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))
                 NowOffset       += Pcd.PcdOccupySize
                 
             self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList
@@ -578,10 +583,12 @@ class GenVPD :
                     while(countOfUnfixedList < lenOfUnfixedList) :
                         eachUnfixedPcd      = self.PcdUnknownOffsetList[countOfUnfixedList]
                         needFixPcdSize      = eachUnfixedPcd.PcdOccupySize
                         # Not been fixed
                         if eachUnfixedPcd.PcdOffset == '*' :
+                            if LastOffset % eachUnfixedPcd.Alignment != 0:
+                                LastOffset = (LastOffset / eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment
                             # The offset un-fixed pcd can write into this free space
                             if needFixPcdSize <= (NowOffset - LastOffset) :
                                 # Change the offset value of un-fixed pcd
                                 eachUnfixedPcd.PcdOffset    = str(hex(LastOffset))
                                 eachUnfixedPcd.PcdBinOffset = LastOffset
@@ -630,10 +637,13 @@ class GenVPD :
             # The last pcd instance
             LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]
             NeedFixPcd = self.PcdUnknownOffsetList[0]
             
             NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize
+            if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:
+                NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
+
             NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))
             
             # Insert this pcd into fixed offset pcd list's tail.
             self.PcdFixedOffsetSizeList.insert(lenOfList, NeedFixPcd)
             # Delete the item's offset that has been fixed and added into fixed offset list
-- 
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] BaseTools: Fix the bug to align VPD PCD based on value type
Posted by Gao, Liming 6 years, 9 months ago
Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Yonghong Zhu
>Sent: Tuesday, January 30, 2018 2:57 PM
>To: edk2-devel@lists.01.org
>Subject: [edk2] [Patch] BaseTools: Fix the bug to align VPD PCD based on
>value type
>
>Spec required for VOID* VPD Pcd, Ascii string use byte alignment, byte
>array use 8-byte alignment, unicode string use 2-byte alignment.
>while when the VPD pcd offset use *, the offset generated in the .map
>file not follow this rule.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
>---
> BaseTools/Source/Python/BPDG/GenVpd.py | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
>diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py
>b/BaseTools/Source/Python/BPDG/GenVpd.py
>index 9861e7d..ec4da23 100644
>--- a/BaseTools/Source/Python/BPDG/GenVpd.py
>+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
>@@ -1,10 +1,10 @@
> ## @file
> #  This file include GenVpd class for fix the Vpd type PCD offset, and PcdEntry
>for describe
> #  and process each entry of vpd type PCD.
> #
>-#  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
>+#  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
> #
> #  This program and the accompanying materials
> #  are licensed and made available under the terms and conditions of the BSD
>License
> #  which accompanies this distribution.  The full text of the license may be
>found at
> #  http://opensource.org/licenses/bsd-license.php
>@@ -33,21 +33,22 @@ _FORMAT_CHAR = {1: 'B',
> #
> #  This class contain method to format and pack pcd's value.
> #
> class PcdEntry:
>     def __init__(self, PcdCName, SkuId,PcdOffset, PcdSize, PcdValue,
>Lineno=None, FileName=None, PcdUnpackValue=None,
>-                 PcdBinOffset=None, PcdBinSize=None):
>+                 PcdBinOffset=None, PcdBinSize=None, Alignment=None):
>         self.PcdCName       = PcdCName.strip()
>         self.SkuId          = SkuId.strip()
>         self.PcdOffset      = PcdOffset.strip()
>         self.PcdSize        = PcdSize.strip()
>         self.PcdValue       = PcdValue.strip()
>         self.Lineno         = Lineno.strip()
>         self.FileName       = FileName.strip()
>         self.PcdUnpackValue = PcdUnpackValue
>         self.PcdBinOffset   = PcdBinOffset
>         self.PcdBinSize     = PcdBinSize
>+        self.Alignment       = Alignment
>
>         if self.PcdValue == '' :
>             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
>                             "Invalid PCD format(Name: %s File: %s line: %s) , no Value
>specified!" % (self.PcdCName, self.FileName, self.Lineno))
>
>@@ -432,20 +433,22 @@ class GenVPD :
>                 elif PCD.PcdUnpackValue.startswith("L"):
>                     Alignment = 2
>                 else:
>                     Alignment = 1
>
>+                PCD.Alignment = Alignment
>                 if PCD.PcdOffset != '*':
>                     if PCD.PcdOccupySize % Alignment != 0:
>                         if PCD.PcdUnpackValue.startswith("{"):
>                             EdkLogger.warn("BPDG", "The offset value of PCD %s is not 8-
>byte aligned!" %(PCD.PcdCName), File=self.InputFileName)
>                         else:
>                             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
>'The offset value of PCD %s should be %s-byte aligned.' % (PCD.PcdCName,
>Alignment))
>                 else:
>                     if PCD.PcdOccupySize % Alignment != 0:
>                         PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 1) *
>Alignment
>
>+                PackSize = PCD.PcdOccupySize
>                 if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):
>                     PCD._PackBooleanValue(PCD.PcdValue)
>                     self.FileLinesList[count] = PCD
>                     count += 1
>                     continue
>@@ -516,10 +519,12 @@ class GenVPD :
>         #
>         if (len(self.PcdFixedOffsetSizeList) == 0) and
>(len(self.PcdUnknownOffsetList) != 0) :
>             # The offset start from 0
>             NowOffset = 0
>             for Pcd in self.PcdUnknownOffsetList :
>+                if NowOffset % Pcd.Alignment != 0:
>+                    NowOffset = (NowOffset/ Pcd.Alignment + 1) * Pcd.Alignment
>                 Pcd.PcdBinOffset = NowOffset
>                 Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))
>                 NowOffset       += Pcd.PcdOccupySize
>
>             self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList
>@@ -578,10 +583,12 @@ class GenVPD :
>                     while(countOfUnfixedList < lenOfUnfixedList) :
>                         eachUnfixedPcd      =
>self.PcdUnknownOffsetList[countOfUnfixedList]
>                         needFixPcdSize      = eachUnfixedPcd.PcdOccupySize
>                         # Not been fixed
>                         if eachUnfixedPcd.PcdOffset == '*' :
>+                            if LastOffset % eachUnfixedPcd.Alignment != 0:
>+                                LastOffset = (LastOffset / eachUnfixedPcd.Alignment + 1) *
>eachUnfixedPcd.Alignment
>                             # The offset un-fixed pcd can write into this free space
>                             if needFixPcdSize <= (NowOffset - LastOffset) :
>                                 # Change the offset value of un-fixed pcd
>                                 eachUnfixedPcd.PcdOffset    = str(hex(LastOffset))
>                                 eachUnfixedPcd.PcdBinOffset = LastOffset
>@@ -630,10 +637,13 @@ class GenVPD :
>             # The last pcd instance
>             LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]
>             NeedFixPcd = self.PcdUnknownOffsetList[0]
>
>             NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset +
>LastPcd.PcdOccupySize
>+            if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:
>+                NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset /
>NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
>+
>             NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))
>
>             # Insert this pcd into fixed offset pcd list's tail.
>             self.PcdFixedOffsetSizeList.insert(lenOfList, NeedFixPcd)
>             # Delete the item's offset that has been fixed and added into fixed
>offset list
>--
>2.6.1.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel