From e10efa3a037c78c831a2b94c75eb0ab862412acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Niew=C3=B6hner?= Date: Tue, 25 Aug 2020 19:38:14 +0200 Subject: util/apcb_edit: fix handling of binary SPD files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passing binary SPD files to apcb_edit can lead to an encoding error, since the files were read in text mode. To fix this, read SPD files always in binary mode and only decode them, when `--hex` is set. Tested by comparing output files from the same SPDs in both, binary and hex mode. Change-Id: I6b75a9e1234e71667bdc8cb4eb10daf8c0ac3c17 Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/44778 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi Reviewed-by: Angel Pons Reviewed-by: Rob Barnes Reviewed-by: Nico Huber --- util/apcb/apcb_edit.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'util/apcb') diff --git a/util/apcb/apcb_edit.py b/util/apcb/apcb_edit.py index 388b18ad73..599ef35d16 100755 --- a/util/apcb/apcb_edit.py +++ b/util/apcb/apcb_edit.py @@ -40,19 +40,19 @@ def parseargs(): help='APCB output file') parser.add_argument( '--spd_0_0', - type=argparse.FileType('r'), + type=argparse.FileType('rb'), help='SPD input file for channel 0, dimm 0') parser.add_argument( '--spd_0_1', - type=argparse.FileType('r'), + type=argparse.FileType('rb'), help='SPD input file for channel 0, dimm 1') parser.add_argument( '--spd_1_0', - type=argparse.FileType('r'), + type=argparse.FileType('rb'), help='SPD input file for channel 1, dimm 0') parser.add_argument( '--spd_1_1', - type=argparse.FileType('r'), + type=argparse.FileType('rb'), help='SPD input file for channel 1, dimm 1') parser.add_argument( '--hex', @@ -150,11 +150,10 @@ def main(): if spd: if args.hex: + spd = spd.decode() spd = re.sub(r'#.*', '', spd) spd = re.sub(r'\s+', '', spd) spd = bytes.fromhex(spd) - else: - spd = spd.encode() assert len(spd) == 512, \ "Expected SPD to be 512 bytes, got %d" % len(spd) -- cgit v1.2.3