[edk2] [Patch 3/5] BaseTools/BinToPcd: --offset must be 8-byte aligned

Kinney, Michael D posted 5 patches 6 years, 11 months ago
[edk2] [Patch 3/5] BaseTools/BinToPcd: --offset must be 8-byte aligned
Posted by Kinney, Michael D 6 years, 11 months ago
https://bugzilla.tianocore.org/show_bug.cgi?id=974
https://bugzilla.tianocore.org/show_bug.cgi?id=965

Update help to state that --offset must be 8-byte aligned.
Verify that --offset is 8-byte aligned and print an error
message if it is not 8-byte aligned.

Cc: Yanyan Sun <yanyan.sun@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
---
 BaseTools/Scripts/BinToPcd.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Scripts/BinToPcd.py b/BaseTools/Scripts/BinToPcd.py
index 7e3380190e..54cb844d68 100644
--- a/BaseTools/Scripts/BinToPcd.py
+++ b/BaseTools/Scripts/BinToPcd.py
@@ -89,7 +89,7 @@ if __name__ == '__main__':
   parser.add_argument("-m", "--max-size", dest = 'MaxSize', type = ValidateUnsignedInteger,
                       help = "Maximum size of the PCD.  Ignored with --type HII.")
   parser.add_argument("-f", "--offset", dest = 'Offset', type = ValidateUnsignedInteger,
-                      help = "VPD offset if --type is VPD.  UEFI Variable offset if --type is HII.")
+                      help = "VPD offset if --type is VPD.  UEFI Variable offset if --type is HII.  Must be 8-byte aligned.")
   parser.add_argument("-n", "--variable-name", dest = 'VariableName',
                       help = "UEFI variable name.  Only used with --type HII.")
   parser.add_argument("-g", "--variable-guid", type = ValidateGuidName, dest = 'VariableGuid',
@@ -178,6 +178,12 @@ if __name__ == '__main__':
       Pcd = '  %s|*|%d|%s' % (args.PcdName, args.MaxSize, PcdValue)
     else:
       #
+      # --offset value must be 8-byte aligned
+      #
+      if (args.Offset % 8) != 0:
+        print 'BinToPcd: error: argument --offset must be 8-byte aligned.'
+        sys.exit()
+      #
       # Use the --offset value provided.
       #
       Pcd = '  %s|%d|%d|%s' % (args.PcdName, args.Offset, args.MaxSize, PcdValue)
@@ -194,6 +200,12 @@ if __name__ == '__main__':
       # Use UEFI Variable offset of 0 if --offset is not provided
       #
       args.Offset = 0
+    #
+    # --offset value must be 8-byte aligned
+    #
+    if (args.Offset % 8) != 0:
+      print 'BinToPcd: error: argument --offset must be 8-byte aligned.'
+      sys.exit()
     Pcd = '  %s|L"%s"|%s|%d|%s' % (args.PcdName, args.VariableName, args.VariableGuid, args.Offset, PcdValue)
     if args.Verbose:
       print 'BinToPcd: Convert binary file to PCD statement compatible with PCD sections'
-- 
2.14.2.windows.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel