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>
This commit is contained in:
parent
9da0279e1a
commit
e10efa3a03
|
@ -40,19 +40,19 @@ def parseargs():
|
||||||
help='APCB output file')
|
help='APCB output file')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--spd_0_0',
|
'--spd_0_0',
|
||||||
type=argparse.FileType('r'),
|
type=argparse.FileType('rb'),
|
||||||
help='SPD input file for channel 0, dimm 0')
|
help='SPD input file for channel 0, dimm 0')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--spd_0_1',
|
'--spd_0_1',
|
||||||
type=argparse.FileType('r'),
|
type=argparse.FileType('rb'),
|
||||||
help='SPD input file for channel 0, dimm 1')
|
help='SPD input file for channel 0, dimm 1')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--spd_1_0',
|
'--spd_1_0',
|
||||||
type=argparse.FileType('r'),
|
type=argparse.FileType('rb'),
|
||||||
help='SPD input file for channel 1, dimm 0')
|
help='SPD input file for channel 1, dimm 0')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--spd_1_1',
|
'--spd_1_1',
|
||||||
type=argparse.FileType('r'),
|
type=argparse.FileType('rb'),
|
||||||
help='SPD input file for channel 1, dimm 1')
|
help='SPD input file for channel 1, dimm 1')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--hex',
|
'--hex',
|
||||||
|
@ -150,11 +150,10 @@ def main():
|
||||||
|
|
||||||
if spd:
|
if spd:
|
||||||
if args.hex:
|
if args.hex:
|
||||||
|
spd = spd.decode()
|
||||||
spd = re.sub(r'#.*', '', spd)
|
spd = re.sub(r'#.*', '', spd)
|
||||||
spd = re.sub(r'\s+', '', spd)
|
spd = re.sub(r'\s+', '', spd)
|
||||||
spd = bytes.fromhex(spd)
|
spd = bytes.fromhex(spd)
|
||||||
else:
|
|
||||||
spd = spd.encode()
|
|
||||||
|
|
||||||
assert len(spd) == 512, \
|
assert len(spd) == 512, \
|
||||||
"Expected SPD to be 512 bytes, got %d" % len(spd)
|
"Expected SPD to be 512 bytes, got %d" % len(spd)
|
||||||
|
|
Loading…
Reference in New Issue