diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/README.md | 2 | ||||
-rw-r--r-- | util/rockchip/description.md | 2 | ||||
-rwxr-xr-x | util/rockchip/make_idb.py | 47 |
3 files changed, 26 insertions, 25 deletions
diff --git a/util/README.md b/util/README.md index 4b2fe385e3..778c83efda 100644 --- a/util/README.md +++ b/util/README.md @@ -83,7 +83,7 @@ devices on the board such as dGPU. `C` can be passed to SPIKE, the RISC-V reference emulator.`Bash` * _sifive-gpt.py_ - Wraps the bootblock in a GPT partition for SiFive's bootrom. `Python3` -* __rockchip__ - Generate Rockchip idblock bootloader. `Python2` +* __rockchip__ - Generate Rockchip idblock bootloader. `Python3` * __sconfig__ - coreboot device tree compiler `Lex` `Yacc` * __scripts__ * _config_ - Manipulate options in a .config file from the diff --git a/util/rockchip/description.md b/util/rockchip/description.md index 3eed7a6899..e482d1eb1e 100644 --- a/util/rockchip/description.md +++ b/util/rockchip/description.md @@ -1 +1 @@ -Generate Rockchip idblock bootloader. `Python2` +Generate Rockchip idblock bootloader. `Python3` diff --git a/util/rockchip/make_idb.py b/util/rockchip/make_idb.py index 12cd130bc5..ff82e7325a 100755 --- a/util/rockchip/make_idb.py +++ b/util/rockchip/make_idb.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # SPDX-License-Identifier: BSD-2-Clause import struct @@ -7,7 +7,7 @@ from io import SEEK_SET, SEEK_END class IDBTool: def __init__(self): - print "Initialize IDBTool" + print("Initialize IDBTool") def p_rc4(self, buf, length): key = (124,78,3,4,85,5,9,7,45,44,123,56,23,13,23,17) @@ -25,7 +25,7 @@ class IDBTool: j = (j + S[i]) % 256 temp = S[i]; S[i] = S[j]; S[j] = temp k = (S[i] + S[j]) % 256 - buf[x] = struct.pack('B', ord(buf[x]) ^ S[k]) + buf[x] = struct.pack('B', buf[x] ^ S[k])[0] def makeIDB(self, chip, from_file, to_file, rc4_flag = False, align_flag = False): try: @@ -45,17 +45,18 @@ class IDBTool: data_len = len(data) SECTOR_SIZE = 512 PAGE_ALIGN = 4 - sectors = (data_len + 4 - 1) / SECTOR_SIZE + 1 - pages = (sectors - 1) / PAGE_ALIGN + 1 - sectors = pages * PAGE_ALIGN; + sectors = (data_len + 4 - 1) // SECTOR_SIZE + 1 + pages = (sectors - 1) // PAGE_ALIGN + 1 + sectors = pages * PAGE_ALIGN - buf = [B'\0'] * sectors * SECTOR_SIZE - buf[:4] = chip + buf = bytearray(sectors * SECTOR_SIZE) + assert len(chip) == 4 + buf[:4] = chip.encode('ascii') buf[4 : 4+data_len] = data - idblock = [B'\0'] * 4 * SECTOR_SIZE - blank = [B'\0'] * 4 * SECTOR_SIZE - idblock[:4] = ['\x55', '\xAA', '\xF0', '\x0F'] + idblock = bytearray(4 * SECTOR_SIZE) + blank = bytearray(4 * SECTOR_SIZE) + idblock[:4] = b'\x55\xAA\xF0\x0F' if (not rc4_flag): idblock[8:12] = struct.pack("<I", 1) @@ -65,8 +66,8 @@ class IDBTool: self.p_rc4(list_tmp, SECTOR_SIZE) buf[SECTOR_SIZE*i : SECTOR_SIZE*(i+1)] = list_tmp - idblock[12:16] = struct.pack("<HH", 4, 4); - idblock[506:510] = struct.pack("<HH", sectors, sectors); + idblock[12:16] = struct.pack("<HH", 4, 4) + idblock[506:510] = struct.pack("<HH", sectors, sectors) self.p_rc4(idblock, SECTOR_SIZE) try: @@ -76,25 +77,25 @@ class IDBTool: try: if (align_flag): - fout.write(''.join(idblock)) - fout.write(''.join(blank)) + fout.write(idblock) + fout.write(blank) - for s in xrange(0, sectors * SECTOR_SIZE, PAGE_ALIGN * SECTOR_SIZE): - fout.write(''.join(buf[s : s + PAGE_ALIGN * SECTOR_SIZE])) - fout.write(''.join(blank)) + for s in range(0, sectors * SECTOR_SIZE, PAGE_ALIGN * SECTOR_SIZE): + fout.write(buf[s : s + PAGE_ALIGN * SECTOR_SIZE]) + fout.write(blank) else: - fout.write(''.join(idblock)) - fout.write(''.join(buf)) + fout.write(idblock) + fout.write(buf) fout.flush() except: sys.exit("Failed to write data to : " + to_file) finally: fout.close() - print "DONE" + print("DONE") def usage(): - print "Usage: make_idb.py [--chip=RKXX] [--enable-rc4] [--enable-align] [--to=out] --from=in" - print " --chip: default is RK32" + print("Usage: make_idb.py [--chip=RKXX] [--enable-rc4] [--enable-align] [--to=out] --from=in") + print(" --chip: default is RK32") if __name__ == '__main__': rc4_flag = align_flag = False |