Yilin Yang has uploaded this change for review.

View Change

util/rockchip: Port make_idb.py to python3

BUG=chromium:1023662

Signed-off-by: Yilin Yang <kerker@google.com>
Change-Id: I04253084ec9b65310c52598b629390051cd2172b
---
M util/rockchip/make_idb.py
1 file changed, 26 insertions(+), 19 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/47/45447/1
diff --git a/util/rockchip/make_idb.py b/util/rockchip/make_idb.py
index 12cd130..c633d4d 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 @@

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)
@@ -27,6 +27,13 @@
k = (S[i] + S[j]) % 256
buf[x] = struct.pack('B', ord(buf[x]) ^ S[k])

+ def bytesToList(self, byte_string):
+ ret = []
+ for ch in byte_string:
+ ret.append(bytes((ch,)))
+
+ return ret
+
def makeIDB(self, chip, from_file, to_file, rc4_flag = False, align_flag = False):
try:
fin = open(from_file, 'rb')
@@ -50,23 +57,23 @@
sectors = pages * PAGE_ALIGN;

buf = [B'\0'] * sectors * SECTOR_SIZE
- buf[:4] = chip
- buf[4 : 4+data_len] = data
+ buf[:4] = self.bytesToList(chip)
+ buf[4 : 4+data_len] = self.bytesToList(data)

idblock = [B'\0'] * 4 * SECTOR_SIZE
blank = [B'\0'] * 4 * SECTOR_SIZE
- idblock[:4] = ['\x55', '\xAA', '\xF0', '\x0F']
+ idblock[:4] = [b'\x55', b'\xAA', b'\xF0', b'\x0F']

if (not rc4_flag):
- idblock[8:12] = struct.pack("<I", 1)
+ idblock[8:12] = self.bytesToList(struct.pack("<I", 1))
else:
for i in range(sectors):
list_tmp = buf[SECTOR_SIZE*i : SECTOR_SIZE*(i+1)]
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] = self.bytesToList(struct.pack("<HH", 4, 4))
+ idblock[506:510] = self.bytesToList(struct.pack("<HH", sectors, sectors))
self.p_rc4(idblock, SECTOR_SIZE)

try:
@@ -76,25 +83,25 @@

try:
if (align_flag):
- fout.write(''.join(idblock))
- fout.write(''.join(blank))
+ fout.write(b''.join(idblock))
+ fout.write(b''.join(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(b''.join(buf[s : s + PAGE_ALIGN * SECTOR_SIZE]))
+ fout.write(b''.join(blank))
else:
- fout.write(''.join(idblock))
- fout.write(''.join(buf))
+ fout.write(b''.join(idblock))
+ fout.write(b''.join(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
@@ -123,4 +130,4 @@
sys.exit()

idbtool = IDBTool()
- idbtool.makeIDB(chip, from_file, to_file, rc4_flag, align_flag)
+ idbtool.makeIDB(chip.encode('utf-8'), from_file, to_file, rc4_flag, align_flag)

To view, visit change 45447. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I04253084ec9b65310c52598b629390051cd2172b
Gerrit-Change-Number: 45447
Gerrit-PatchSet: 1
Gerrit-Owner: Yilin Yang <kerker@google.com>
Gerrit-MessageType: newchange