public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value
@ 2018-01-30 15:20 Yonghong Zhu
  2018-01-31  9:00 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-01-30 15:20 UTC (permalink / raw)
  To: edk2-devel

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>
---
 BaseTools/Source/Python/BPDG/GenVpd.py | 32 ++++++++++++++++++--------------
 BaseTools/Source/Python/Common/Misc.py |  6 +++---
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
index 9861e7d..612400d 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -59,11 +59,11 @@ class PcdEntry:
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
                             "Invalid PCD format(Name: %s File: %s Line: %s), no PcdSize specified!" % (self.PcdCName, self.FileName, self.Lineno))
 
         self._GenOffsetValue ()
 
-    ## Analyze the string value to judge the PCD's datum type euqal to Boolean or not.
+    ## Analyze the string value to judge the PCD's datum type equal to Boolean or not.
     # 
     #  @param   ValueString      PCD's value
     #  @param   Size             PCD's size
     #  
     #  @retval  True   PCD's datum type is Boolean
@@ -162,42 +162,45 @@ class PcdEntry:
                             "Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
 
     ## Pack VOID* type VPD PCD's value form string to binary type.
     #
     #  The VOID* type of string divided into 3 sub-type:
-    #    1:    L"String", Unicode type string.
-    #    2:    "String",  Ascii type string.
+    #    1:    L"String"/L'String', Unicode type string.
+    #    2:    "String"/'String',  Ascii type string.
     #    3:    {bytearray}, only support byte-array.
     #
     #  @param ValueString     The Integer type string for pack.
     #       
     def _PackPtrValue(self, ValueString, Size):
-        if ValueString.startswith('L"'):
+        if ValueString.startswith('L"') or ValueString.startswith("L'"):
             self._PackUnicode(ValueString, Size)
         elif ValueString.startswith('{') and ValueString.endswith('}'):
             self._PackByteArray(ValueString, Size)
-        elif ValueString.startswith('"') and ValueString.endswith('"'):
+        elif (ValueString.startswith('"') and ValueString.endswith('"')) or (ValueString.startswith("'") and ValueString.endswith("'")):
             self._PackString(ValueString, Size)
         else:
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
                             "Invalid VOID* type PCD %s value %s (File: %s Line: %s)" % (self.PcdCName, ValueString, self.FileName, self.Lineno))
 
     ## Pack an Ascii PCD value.
     #  
-    #  An Ascii string for a PCD should be in format as  "".
+    #  An Ascii string for a PCD should be in format as  ""/''.
     #                   
     def _PackString(self, ValueString, Size):
         if (Size < 0):
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
                             "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))
         if (ValueString == ""):
             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))
-        if (len(ValueString) < 2):
-            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))
+
+        QuotedFlag = True
+        if ValueString.startswith("'"):
+            QuotedFlag = False
 
         ValueString = ValueString[1:-1]
-        if len(ValueString) + 1 > Size:
+        # No null-terminator in 'string' 
+        if (QuotedFlag and len(ValueString) + 1 > Size) or (not QuotedFlag and len(ValueString) > Size):
             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,
                             "PCD value string %s is exceed to size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))
         try:
             self.PcdValue = pack('%ds' % Size, ValueString)
         except:
@@ -256,23 +259,24 @@ class PcdEntry:
 
         self.PcdValue = ReturnArray.tolist()
 
     ## Pack a unicode PCD value into byte array.
     #  
-    #  A unicode string for a PCD should be in format as  L"".
+    #  A unicode string for a PCD should be in format as  L""/L''.
     #
     def _PackUnicode(self, UnicodeString, Size):
         if (Size < 0):
             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % \
                              (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))
-        if (len(UnicodeString) < 3):
-            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))
 
+        QuotedFlag = True
+        if UnicodeString.startswith("L'"):
+            QuotedFlag = False 
         UnicodeString = UnicodeString[2:-1]
 
-        if (len(UnicodeString) + 1) * 2 > Size:
+        # No null-terminator in L'string'
+        if (QuotedFlag and (len(UnicodeString) + 1) * 2 > Size) or (not QuotedFlag and len(UnicodeString) * 2 > Size):
             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,
                             "The size of unicode string %s is too larger for size %s(File: %s Line: %s)" % \
                             (UnicodeString, Size, self.FileName, self.Lineno))
 
         ReturnArray = array.array('B')
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index a8ed718..ef52154 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1,9 +1,9 @@
 ## @file
 # Common routines used by all tools
 #
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 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
 #
@@ -1816,14 +1816,14 @@ def AnalyzeVpdPcdData(Setting):
 #
 def CheckPcdDatum(Type, Value):
     if Type == "VOID*":
         ValueRe = re.compile(r'\s*L?\".*\"\s*$')
         if not (((Value.startswith('L"') or Value.startswith('"')) and Value.endswith('"'))
-                or (Value.startswith('{') and Value.endswith('}'))
+                or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))
                ):
             return False, "Invalid value [%s] of type [%s]; must be in the form of {...} for array"\
-                          ", or \"...\" for string, or L\"...\" for unicode string" % (Value, Type)
+                          ", \"...\" or \'...\' for string, L\"...\" or L\'...\' for unicode string" % (Value, Type)
         elif ValueRe.match(Value):
             # Check the chars in UnicodeString or CString is printable
             if Value.startswith("L"):
                 Value = Value[2:-1]
             else:
-- 
2.6.1.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value
  2018-01-30 15:20 [Patch] BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value Yonghong Zhu
@ 2018-01-31  9:00 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2018-01-31  9:00 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org

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 11:20 PM
>To: edk2-devel@lists.01.org
>Subject: [edk2] [Patch] BaseTools: Update BPDG to support L'' and '' format as
>VPD Pcd Value
>
>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>
>---
> BaseTools/Source/Python/BPDG/GenVpd.py | 32 ++++++++++++++++++----
>----------
> BaseTools/Source/Python/Common/Misc.py |  6 +++---
> 2 files changed, 21 insertions(+), 17 deletions(-)
>
>diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py
>b/BaseTools/Source/Python/BPDG/GenVpd.py
>index 9861e7d..612400d 100644
>--- a/BaseTools/Source/Python/BPDG/GenVpd.py
>+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
>@@ -59,11 +59,11 @@ class PcdEntry:
>             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
>                             "Invalid PCD format(Name: %s File: %s Line: %s), no PcdSize
>specified!" % (self.PcdCName, self.FileName, self.Lineno))
>
>         self._GenOffsetValue ()
>
>-    ## Analyze the string value to judge the PCD's datum type euqal to Boolean
>or not.
>+    ## Analyze the string value to judge the PCD's datum type equal to
>Boolean or not.
>     #
>     #  @param   ValueString      PCD's value
>     #  @param   Size             PCD's size
>     #
>     #  @retval  True   PCD's datum type is Boolean
>@@ -162,42 +162,45 @@ class PcdEntry:
>                             "Invalid size or value for PCD %s to pack(File: %s Line: %s)." %
>(self.PcdCName, self.FileName, self.Lineno))
>
>     ## Pack VOID* type VPD PCD's value form string to binary type.
>     #
>     #  The VOID* type of string divided into 3 sub-type:
>-    #    1:    L"String", Unicode type string.
>-    #    2:    "String",  Ascii type string.
>+    #    1:    L"String"/L'String', Unicode type string.
>+    #    2:    "String"/'String',  Ascii type string.
>     #    3:    {bytearray}, only support byte-array.
>     #
>     #  @param ValueString     The Integer type string for pack.
>     #
>     def _PackPtrValue(self, ValueString, Size):
>-        if ValueString.startswith('L"'):
>+        if ValueString.startswith('L"') or ValueString.startswith("L'"):
>             self._PackUnicode(ValueString, Size)
>         elif ValueString.startswith('{') and ValueString.endswith('}'):
>             self._PackByteArray(ValueString, Size)
>-        elif ValueString.startswith('"') and ValueString.endswith('"'):
>+        elif (ValueString.startswith('"') and ValueString.endswith('"')) or
>(ValueString.startswith("'") and ValueString.endswith("'")):
>             self._PackString(ValueString, Size)
>         else:
>             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
>                             "Invalid VOID* type PCD %s value %s (File: %s Line: %s)" %
>(self.PcdCName, ValueString, self.FileName, self.Lineno))
>
>     ## Pack an Ascii PCD value.
>     #
>-    #  An Ascii string for a PCD should be in format as  "".
>+    #  An Ascii string for a PCD should be in format as  ""/''.
>     #
>     def _PackString(self, ValueString, Size):
>         if (Size < 0):
>             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
>                             "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" %
>(self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))
>         if (ValueString == ""):
>             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))
>-        if (len(ValueString) < 2):
>-            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))
>+
>+        QuotedFlag = True
>+        if ValueString.startswith("'"):
>+            QuotedFlag = False
>
>         ValueString = ValueString[1:-1]
>-        if len(ValueString) + 1 > Size:
>+        # No null-terminator in 'string'
>+        if (QuotedFlag and len(ValueString) + 1 > Size) or (not QuotedFlag and
>len(ValueString) > Size):
>             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,
>                             "PCD value string %s is exceed to size %d(File: %s Line: %s)" %
>(ValueString, Size, self.FileName, self.Lineno))
>         try:
>             self.PcdValue = pack('%ds' % Size, ValueString)
>         except:
>@@ -256,23 +259,24 @@ class PcdEntry:
>
>         self.PcdValue = ReturnArray.tolist()
>
>     ## Pack a unicode PCD value into byte array.
>     #
>-    #  A unicode string for a PCD should be in format as  L"".
>+    #  A unicode string for a PCD should be in format as  L""/L''.
>     #
>     def _PackUnicode(self, UnicodeString, Size):
>         if (Size < 0):
>             EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid
>parameter Size %s of PCD %s!(File: %s Line: %s)" % \
>                              (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))
>-        if (len(UnicodeString) < 3):
>-            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))
>
>+        QuotedFlag = True
>+        if UnicodeString.startswith("L'"):
>+            QuotedFlag = False
>         UnicodeString = UnicodeString[2:-1]
>
>-        if (len(UnicodeString) + 1) * 2 > Size:
>+        # No null-terminator in L'string'
>+        if (QuotedFlag and (len(UnicodeString) + 1) * 2 > Size) or (not
>QuotedFlag and len(UnicodeString) * 2 > Size):
>             EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,
>                             "The size of unicode string %s is too larger for size %s(File: %s
>Line: %s)" % \
>                             (UnicodeString, Size, self.FileName, self.Lineno))
>
>         ReturnArray = array.array('B')
>diff --git a/BaseTools/Source/Python/Common/Misc.py
>b/BaseTools/Source/Python/Common/Misc.py
>index a8ed718..ef52154 100644
>--- a/BaseTools/Source/Python/Common/Misc.py
>+++ b/BaseTools/Source/Python/Common/Misc.py
>@@ -1,9 +1,9 @@
> ## @file
> # Common routines used by all tools
> #
>-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
>+# Copyright (c) 2007 - 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
> #
>@@ -1816,14 +1816,14 @@ def AnalyzeVpdPcdData(Setting):
> #
> def CheckPcdDatum(Type, Value):
>     if Type == "VOID*":
>         ValueRe = re.compile(r'\s*L?\".*\"\s*$')
>         if not (((Value.startswith('L"') or Value.startswith('"')) and
>Value.endswith('"'))
>-                or (Value.startswith('{') and Value.endswith('}'))
>+                or (Value.startswith('{') and Value.endswith('}')) or
>(Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))
>                ):
>             return False, "Invalid value [%s] of type [%s]; must be in the form of {...}
>for array"\
>-                          ", or \"...\" for string, or L\"...\" for unicode string" % (Value,
>Type)
>+                          ", \"...\" or \'...\' for string, L\"...\" or L\'...\' for unicode string" %
>(Value, Type)
>         elif ValueRe.match(Value):
>             # Check the chars in UnicodeString or CString is printable
>             if Value.startswith("L"):
>                 Value = Value[2:-1]
>             else:
>--
>2.6.1.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-31  8:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-30 15:20 [Patch] BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value Yonghong Zhu
2018-01-31  9:00 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox