]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: VOID* PCDs in VPD region must be aligned based on value type
authorYonghong Zhu <yonghong.zhu@intel.com>
Mon, 18 Jan 2016 01:46:25 +0000 (01:46 +0000)
committeryzhu52 <yzhu52@Edk2>
Mon, 18 Jan 2016 01:46:25 +0000 (01:46 +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 halt with an error message if a VOID* PCD has an
offset value that is not aligned based on the 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@19650 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/Python/AutoGen/AutoGen.py

index 4c627dfb555a1c5d2287b8d2f0063441a5950e03..abac47758d36dea5692dbc26d883b3c75d22d634 100644 (file)
@@ -317,6 +317,11 @@ class WorkspaceAutoGen(AutoGen):
             GlobalData.gFdfParser = Fdf\r
             GlobalData.gAutoGenPhase = False\r
             PcdSet = Fdf.Profile.PcdDict\r
+            FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
+            for FdRegion in FdDict.RegionList:\r
+                if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
+                    if int(FdRegion.Offset) % 8 != 0:\r
+                        EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
             ModuleList = Fdf.Profile.InfList\r
             self.FdfProfile = Fdf.Profile\r
             for fvname in self.FvTargetList:\r
@@ -1138,6 +1143,18 @@ class PlatformAutoGen(AutoGen):
                     Pcd = VpdPcdDict[PcdKey]\r
                     for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
                         Sku.VpdOffset = Sku.VpdOffset.strip()\r
+                        PcdValue = Sku.DefaultValue\r
+                        if PcdValue == "":\r
+                            PcdValue  = Pcd.DefaultValue\r
+                        if Sku.VpdOffset != '*':\r
+                            if PcdValue.startswith("{"):\r
+                                Alignment = 8\r
+                            elif PcdValue.startswith("L"):\r
+                                Alignment = 2\r
+                            else:\r
+                                Alignment = 1\r
+                            if int(Sku.VpdOffset) % Alignment != 0:\r
+                                EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
                         VpdFile.Add(Pcd, Sku.VpdOffset)\r
                         # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
                         if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
@@ -1193,6 +1210,17 @@ class PlatformAutoGen(AutoGen):
 #                                Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]\r
                                 Sku.VpdOffset = Sku.VpdOffset.strip()\r
                                 PcdValue = Sku.DefaultValue\r
+                                if PcdValue == "":\r
+                                    PcdValue  = DscPcdEntry.DefaultValue\r
+                                if Sku.VpdOffset != '*':\r
+                                    if PcdValue.startswith("{"):\r
+                                        Alignment = 8\r
+                                    elif PcdValue.startswith("L"):\r
+                                        Alignment = 2\r
+                                    else:\r
+                                        Alignment = 1\r
+                                    if int(Sku.VpdOffset) % Alignment != 0:\r
+                                        EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
                                 VpdFile.Add(DscPcdEntry, Sku.VpdOffset)\r
                                 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
                                     NeedProcessVpdMapFile = True \r