summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMichael Niewöhner <foss@mniewoehner.de>2020-08-25 19:38:14 +0200
committerPatrick Georgi <pgeorgi@google.com>2020-09-08 05:44:28 +0000
commite10efa3a037c78c831a2b94c75eb0ab862412acf (patch)
tree8af3859afa32d019652f613c5a926d0ba64e62b8 /util
parent9da0279e1a99babe81a064441b97f6a93dd518bf (diff)
downloadcoreboot-e10efa3a037c78c831a2b94c75eb0ab862412acf.tar.xz
util/apcb_edit: fix handling of binary SPD files
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 <foss@mniewoehner.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/44778 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Rob Barnes <robbarnes@google.com> Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'util')
-rwxr-xr-xutil/apcb/apcb_edit.py11
1 files changed, 5 insertions, 6 deletions
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)