From 8e965809998bfb674515e9d13d93a4fcec0f95c5 Mon Sep 17 00:00:00 2001 From: "Kinney, Michael D" Date: Fri, 8 Jun 2018 21:15:26 -0700 Subject: [PATCH] BaseTools/BinToPcd: --offset must be 8-byte aligned 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 Cc: Yonghong Zhu Cc: Liming Gao Signed-off-by: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Yonghong Zhu --- 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'