Allow building with Python 3.x
Allow the scripts to run with both python 2.x and 3.x
Change-Id: I911118bcf370d09bdb2fb46afa21af64257f1ffb
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
diff --git a/mkbootimg/mkbootimg b/mkbootimg/mkbootimg
index aea2585..f95d703 100755
--- a/mkbootimg/mkbootimg
+++ b/mkbootimg/mkbootimg
@@ -19,6 +19,7 @@
from os import fstat
from struct import pack
from hashlib import sha1
+import sys
def filesize(f):
if f is None:
@@ -133,8 +134,10 @@
img_id = write_header(args)
write_data(args)
if args.id:
- print('0x' + ''.join('{:02x}'.format(ord(c)) for c in img_id))
-
+ if isinstance(img_id, str):
+ # Python 2's struct.pack returns a string, but py3 returns bytes.
+ img_id = [ord(x) for x in img_id]
+ print('0x' + ''.join('{:02x}'.format(c) for c in img_id))
if __name__ == '__main__':
main()