BaseTools/BPDG: Fix the bug to get the PCD Size
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / GenVpd.py
index 003011b709b16d6a0622f7621d4280c372109cd6..4ff464756f20dca1a9dff95ca6af7034356db632 100644 (file)
@@ -2,7 +2,7 @@
 #  This file include GenVpd class for fix the Vpd type PCD offset, and PcdEntry for describe\r
 #  and process each entry of vpd type PCD.\r
 #\r
-#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2016, 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
@@ -409,11 +409,24 @@ class GenVPD :
                 #\r
                 PCD.PcdUnpackValue    =  str(PCD.PcdValue)\r
 \r
+                #\r
+                # Translate PCD size string to an integer value.\r
+                PackSize = None\r
+                try:\r
+                    PackSize = int(PCD.PcdSize, 10)\r
+                    PCD.PcdBinSize = PackSize\r
+                except:\r
+                    try:\r
+                        PackSize = int(PCD.PcdSize, 16)\r
+                        PCD.PcdBinSize = PackSize\r
+                    except:\r
+                        EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid PCD size value %s at file: %s line: %s" % (PCD.PcdSize, self.InputFileName, PCD.Lineno))\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
+                PCD.PcdOccupySize = PCD.PcdBinSize\r
                 if PCD.PcdUnpackValue.startswith("{"):\r
                     Alignment = 8\r
                 elif PCD.PcdUnpackValue.startswith("L"):\r
@@ -431,19 +444,6 @@ class GenVPD :
                     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
-                PackSize = None\r
-                try:\r
-                    PackSize = int(PCD.PcdSize, 10)\r
-                    PCD.PcdBinSize = PackSize\r
-                except:\r
-                    try:\r
-                        PackSize = int(PCD.PcdSize, 16)\r
-                        PCD.PcdBinSize = PackSize\r
-                    except:\r
-                        EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid PCD size value %s at file: %s line: %s" % (PCD.PcdSize, self.InputFileName, PCD.Lineno))\r
-\r
                 if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):\r
                     PCD._PackBooleanValue(PCD.PcdValue)\r
                     self.FileLinesList[count] = PCD\r