qualcomm: qgpt: Fixes for python3

* Binary strings should be joined with a binary string
* Binary files should be opened in binary mode.
* Division that wants truncation should make it explicit.

I have tested that these changes let me compile.

Change-Id: I7c41b80688a9c6bdb3c66561ff531311cc7ebb13
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37024
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Douglas Anderson 2019-11-20 11:18:52 -08:00 committed by Patrick Georgi
parent 436296b9bd
commit 1bdfe8c280
1 changed files with 4 additions and 4 deletions

View File

@ -167,7 +167,7 @@ def UpdateGPTHeader(options, GPTBlobBuffer):
# CRC of Partition Entry # CRC of Partition Entry
PartEntry = GPTBlobBuffer[options.sector_size*2:options.sector_size*2 + 128] PartEntry = GPTBlobBuffer[options.sector_size*2:options.sector_size*2 + 128]
CalcEntryCRC = crc32(''.join(struct.pack("B", x) for x in PartEntry)) CalcEntryCRC = crc32(b''.join(struct.pack("B", x) for x in PartEntry))
GPTBlobBuffer[i] = CalcEntryCRC & 0xFF GPTBlobBuffer[i] = CalcEntryCRC & 0xFF
GPTBlobBuffer[i+1] = (CalcEntryCRC>>8) & 0xFF GPTBlobBuffer[i+1] = (CalcEntryCRC>>8) & 0xFF
@ -177,7 +177,7 @@ def UpdateGPTHeader(options, GPTBlobBuffer):
# CRC of Partition Table Header # CRC of Partition Table Header
GPTHeader = GPTBlobBuffer[options.sector_size:options.sector_size + 92] GPTHeader = GPTBlobBuffer[options.sector_size:options.sector_size + 92]
CalcEntryCRC = crc32(''.join(struct.pack("B", x) for x in GPTHeader)) CalcEntryCRC = crc32(b''.join(struct.pack("B", x) for x in GPTHeader))
i = options.sector_size + 16 i = options.sector_size + 16
GPTBlobBuffer[i] = CalcEntryCRC & 0xFF GPTBlobBuffer[i] = CalcEntryCRC & 0xFF
@ -209,11 +209,11 @@ if __name__ == '__main__':
options.inputfile = args[0] options.inputfile = args[0]
options.outputfile = args[1] options.outputfile = args[1]
with open(options.inputfile, 'r+') as fin: with open(options.inputfile, 'rb+') as fin:
bb_buffer = fin.read() bb_buffer = fin.read()
# Round up to next sector if bootblock size not evenly divisible # Round up to next sector if bootblock size not evenly divisible
options.end_lba = ((len(bb_buffer) + options.sector_size - 1) / options.end_lba = ((len(bb_buffer) + options.sector_size - 1) //
options.sector_size) options.sector_size)
# Add 3 sectors for MBR, GPT header and GPT partition entry # Add 3 sectors for MBR, GPT header and GPT partition entry
options.end_lba += 3 options.end_lba += 3