]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value
authorYonghong Zhu <yonghong.zhu@intel.com>
Tue, 30 Jan 2018 15:01:31 +0000 (23:01 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 31 Jan 2018 09:50:01 +0000 (17:50 +0800)
Current Pcd value support flexible format, this patch add support for
BPDG Tool to support L'' and '' format.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/BPDG/GenVpd.py
BaseTools/Source/Python/Common/Misc.py

index ec4da230a4b2bf25704cade0f627e7073d716112..cdfc420c66f73fbb5d2f64ff409e58432832c102 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
@@ -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
index a8ed718aa5d8008717d61f2ea81f1aa6e0f179ac..ef52154f47a197739cce467876506cf61904767d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Common routines used by all tools\r
 #\r
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -1818,10 +1818,10 @@ def CheckPcdDatum(Type, Value):
     if Type == "VOID*":\r
         ValueRe = re.compile(r'\s*L?\".*\"\s*$')\r
         if not (((Value.startswith('L"') or Value.startswith('"')) and Value.endswith('"'))\r
-                or (Value.startswith('{') and Value.endswith('}'))\r
+                or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))\r
                ):\r
             return False, "Invalid value [%s] of type [%s]; must be in the form of {...} for array"\\r
-                          ", or \"...\" for string, or L\"...\" for unicode string" % (Value, Type)\r
+                          ", \"...\" or \'...\' for string, L\"...\" or L\'...\' for unicode string" % (Value, Type)\r
         elif ValueRe.match(Value):\r
             # Check the chars in UnicodeString or CString is printable\r
             if Value.startswith("L"):\r