]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/BPDG/GenVpd.py
BaseTools: AutoGen - GenVar refactor static methods
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / GenVpd.py
index ec4da230a4b2bf25704cade0f627e7073d716112..69a9665f5a761f3a38f2acac022359d545b6c446 100644 (file)
@@ -62,7 +62,7 @@ class PcdEntry:
 \r
         self._GenOffsetValue ()\r
 \r
-    ## Analyze the string value to judge the PCD's datum type euqal to Boolean or not.\r
+    ## Analyze the string value to judge the PCD's datum type equal to Boolean or not.\r
     # \r
     #  @param   ValueString      PCD's value\r
     #  @param   Size             PCD's size\r
@@ -120,7 +120,7 @@ class PcdEntry:
     # \r
     #                                \r
     def _PackIntValue(self, IntValue, Size):\r
-        if Size not in _FORMAT_CHAR.keys():\r
+        if Size not in _FORMAT_CHAR:\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
                             "Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno))\r
 \r
@@ -165,18 +165,18 @@ class PcdEntry:
     ## Pack VOID* type VPD PCD's value form string to binary type.\r
     #\r
     #  The VOID* type of string divided into 3 sub-type:\r
-    #    1:    L"String", Unicode type string.\r
-    #    2:    "String",  Ascii type string.\r
+    #    1:    L"String"/L'String', Unicode type string.\r
+    #    2:    "String"/'String',  Ascii type string.\r
     #    3:    {bytearray}, only support byte-array.\r
     #\r
     #  @param ValueString     The Integer type string for pack.\r
     #       \r
     def _PackPtrValue(self, ValueString, Size):\r
-        if ValueString.startswith('L"'):\r
+        if ValueString.startswith('L"') or ValueString.startswith("L'"):\r
             self._PackUnicode(ValueString, Size)\r
         elif ValueString.startswith('{') and ValueString.endswith('}'):\r
             self._PackByteArray(ValueString, Size)\r
-        elif ValueString.startswith('"') and ValueString.endswith('"'):\r
+        elif (ValueString.startswith('"') and ValueString.endswith('"')) or (ValueString.startswith("'") and ValueString.endswith("'")):\r
             self._PackString(ValueString, Size)\r
         else:\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
@@ -184,7 +184,7 @@ class PcdEntry:
 \r
     ## Pack an Ascii PCD value.\r
     #  \r
-    #  An Ascii string for a PCD should be in format as  "".\r
+    #  An Ascii string for a PCD should be in format as  ""/''.\r
     #                   \r
     def _PackString(self, ValueString, Size):\r
         if (Size < 0):\r
@@ -192,11 +192,14 @@ class PcdEntry:
                             "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))\r
         if (ValueString == ""):\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter ValueString %s of PCD %s!(File: %s Line: %s)" % (self.PcdUnpackValue, self.PcdCName, self.FileName, self.Lineno))\r
-        if (len(ValueString) < 2):\r
-            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "For PCD: %s ,ASCII string %s at least contains two!(File: %s Line: %s)" % (self.PcdCName, self.PcdUnpackValue, self.FileName, self.Lineno))\r
+\r
+        QuotedFlag = True\r
+        if ValueString.startswith("'"):\r
+            QuotedFlag = False\r
 \r
         ValueString = ValueString[1:-1]\r
-        if len(ValueString) + 1 > Size:\r
+        # No null-terminator in 'string' \r
+        if (QuotedFlag and len(ValueString) + 1 > Size) or (not QuotedFlag and len(ValueString) > Size):\r
             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,\r
                             "PCD value string %s is exceed to size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))\r
         try:\r
@@ -259,19 +262,20 @@ class PcdEntry:
 \r
     ## Pack a unicode PCD value into byte array.\r
     #  \r
-    #  A unicode string for a PCD should be in format as  L"".\r
+    #  A unicode string for a PCD should be in format as  L""/L''.\r
     #\r
     def _PackUnicode(self, UnicodeString, Size):\r
         if (Size < 0):\r
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % \\r
                              (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))\r
-        if (len(UnicodeString) < 3):\r
-            EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "For PCD: %s ,ASCII string %s at least contains two!(File: %s Line: %s)" % \\r
-                            (self.PcdCName, self.PcdUnpackValue, self.FileName, self.Lineno))\r
 \r
+        QuotedFlag = True\r
+        if UnicodeString.startswith("L'"):\r
+            QuotedFlag = False \r
         UnicodeString = UnicodeString[2:-1]\r
 \r
-        if (len(UnicodeString) + 1) * 2 > Size:\r
+        # No null-terminator in L'string'\r
+        if (QuotedFlag and (len(UnicodeString) + 1) * 2 > Size) or (not QuotedFlag and len(UnicodeString) * 2 > Size):\r
             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,\r
                             "The size of unicode string %s is too larger for size %s(File: %s Line: %s)" % \\r
                             (UnicodeString, Size, self.FileName, self.Lineno))\r
@@ -377,7 +381,7 @@ class GenVPD :
         # Delete useless lines\r
         while (True) :\r
             try :\r
-                if (self.FileLinesList[count] == None) :\r
+                if (self.FileLinesList[count] is None) :\r
                     del(self.FileLinesList[count])\r
                 else :\r
                     count += 1\r
@@ -394,7 +398,7 @@ class GenVPD :
         # Process the pcds one by one base on the pcd's value and size\r
         count = 0\r
         for line in self.FileLinesList:\r
-            if line != None :\r
+            if line is not None :\r
                 PCD = PcdEntry(line[0], line[1], line[2], line[3], line[4],line[5], self.InputFileName)   \r
                 # Strip the space char\r
                 PCD.PcdCName     = PCD.PcdCName.strip(' ')\r