summaryrefslogtreecommitdiff
path: root/util/rockchip
diff options
context:
space:
mode:
authorYilin Yang <kerker@google.com>2020-09-16 16:01:40 +0800
committerHung-Te Lin <hungte@chromium.org>2020-09-18 13:30:05 +0000
commit46eaa5a1bac3c1fbd7c84bd2f609736eb6aa50fb (patch)
tree7c9773e58710180c2956ec2ae440be3d9ded31fa /util/rockchip
parent12beaea5e21e0e4db2608840cc78b8bee04320c8 (diff)
util/rockchip: Port make_idb.py to python3
BUG=chromium:1023662 TEST=buildbot pass TEST=1. Use python2 script 2. Run `emerge-kevin coreboot` twice, so we get bootblock.bin.1 and bootblock.bin.2 3. Run `xxd` on these two bootblock so we get bootblock.bin.1.hex and bootblock.bin.2.hex 4. `diff bootblock.bin.1.hex bootblock.bin.2.hex` and record the difference. (at least, the time info changes) 5. Migrate to python3 6. Similar steps, we get bootblock.bin.py3.hex 7. `diff bootblock.bin.1.hex bootblock.bin.py3.hex`, the difference is similar. (time info, git hash changes) Signed-off-by: Yilin Yang <kerker@google.com> Change-Id: I04253084ec9b65310c52598b629390051cd2172b Reviewed-on: https://review.coreboot.org/c/coreboot/+/45447 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/rockchip')
-rw-r--r--util/rockchip/description.md2
-rwxr-xr-xutil/rockchip/make_idb.py47
2 files changed, 25 insertions, 24 deletions
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