Skip to content

Commit

Permalink
scripts: convert remainging scripts to python3
Browse files Browse the repository at this point in the history
Convert the remaining scripts to python3. Mostly done with 2to3 and
manual adjustements to the code afterwards.

Signed-off-by: Rouven Czerwinski <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
Tested-by: Jerome Forissier <[email protected]> (QEMU, QEMUv8)
  • Loading branch information
Emantor authored and jforissier committed Sep 25, 2019
1 parent 909c706 commit bbaeed4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions scripts/arm32_sysreg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2018, Linaro Limited
#
from __future__ import print_function


import argparse
import sys
Expand Down
10 changes: 5 additions & 5 deletions scripts/gen_hashed_bin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2014-2017, Linaro Limited
Expand Down Expand Up @@ -75,7 +75,7 @@ def append_hashes(outf, in_fname):
elif len(page) == 0:
break
else:
print("Error: short read, got " + repr(len(page)))
print("Error: short read, got {}".format(len(page)))
sys.exit(1)

inf.close()
Expand All @@ -88,7 +88,7 @@ def int_parse(str):
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--arch', required=True,
choices=arch_id.keys(),
choices=list(arch_id.keys()),
help='Architecture')

parser.add_argument('--flags',
Expand Down Expand Up @@ -149,8 +149,8 @@ def main():
hashlib.sha256().digest_size

if paged_input_size % (4 * 1024) != 0:
print("Error: pageable size not a multiple of 4K:" +
repr(paged_input_size))
print("Error: pageable size not a multiple of 4K: {}".format(
paged_input_size))
sys.exit(1)

init_size = pager_input_size + \
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_ld_sects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2017, Linaro Limited
Expand Down
2 changes: 1 addition & 1 deletion scripts/pem_to_pub_c.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2015, Linaro Limited
Expand Down
2 changes: 1 addition & 1 deletion scripts/sign.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2015, 2017, Linaro Limited
#
Expand Down
18 changes: 10 additions & 8 deletions scripts/symbolize.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2017, Linaro Limited
#


import argparse
import errno
import glob
import os
import re
Expand Down Expand Up @@ -103,11 +104,12 @@ def __init__(self, out, dirs, strip_path):
def my_Popen(self, cmd):
try:
return subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout=subprocess.PIPE, text=True,
bufsize=1)
except OSError as e:
if e.errno == os.errno.ENOENT:
print >> sys.stderr, "*** Error:", cmd[0] + \
": command not found"
if e.errno == errno.ENOENT:
print("*** Error:{}: command not found".format(cmd[0]),
file=sys.stderr)
sys.exit(1)

def get_elf(self, elf_or_uuid):
Expand All @@ -133,9 +135,9 @@ def set_arch(self):
stdout=subprocess.PIPE)
output = p.stdout.readlines()
p.terminate()
if 'ARM aarch64,' in output[0]:
if b'ARM aarch64,' in output[0]:
self._arch = 'aarch64-linux-gnu-'
elif 'ARM,' in output[0]:
elif b'ARM,' in output[0]:
self._arch = 'arm-linux-gnueabihf-'

def arch_prefix(self, cmd):
Expand Down Expand Up @@ -205,7 +207,7 @@ def resolve(self, addr):
if not reladdr or not self._addr2line:
return '???'
try:
print >> self._addr2line.stdin, reladdr
print(reladdr, file=self._addr2line.stdin)
ret = self._addr2line.stdout.readline().rstrip('\n')
except IOError:
ret = '!!!'
Expand Down
20 changes: 10 additions & 10 deletions scripts/tee_bin_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2016, Linaro Limited
Expand All @@ -9,39 +9,39 @@ def main():
with open("../out/arm/core/tee.bin", "rb") as f:
data = f.read(4)
magic = struct.unpack('<I', data)
print("Magic: \t\t0x%08x" % magic)
print("Magic: \t\t0x{:08x}".format(magic))

data = f.read(1)
version = struct.unpack('<B', data)
print("Version: \t0x%02x" % version)
print("Version: \t0x{:02x}".format(version))

data = f.read(1)
arch_id = struct.unpack('<B', data)
print("ArchID: \t0x%02x" % arch_id)
print("ArchID: \t0x{:02x}".format(arch_id))

data = f.read(2)
flags = struct.unpack('<H', data)
print("Arch Flags: \t0x%04x" % arch_id)
print("Arch Flags: \t0x{:04x}".format(arch_id))

data = f.read(4)
init_size = struct.unpack('<I', data)
print("Init size: \t0x%04x" % init_size)
print("Init size: \t0x{:04x}".format(init_size))

data = f.read(4)
laddr_h = struct.unpack('<I', data)
print("Load addr high:\t0x%04x" % laddr_h)
print("Load addr high:\t0x{:04x}".format(laddr_h))

data = f.read(4)
laddr_l = struct.unpack('<I', data)
print("Load addr low: \t0x%04x" % laddr_l)
print("Load addr low: \t0x{:04x}".format(laddr_l))

data = f.read(4)
mem_usage = struct.unpack('<I', data)
print("Mem usage: \t0x%04x" % mem_usage)
print("Mem usage: \t0x{:04x}".format(mem_usage))

data = f.read(4)
pgd_size = struct.unpack('<I', data)
print("Pages size: \t0x%04x" % pgd_size)
print("Pages size: \t0x{:04x}".format(pgd_size))


if __name__ == "__main__":
Expand Down

0 comments on commit bbaeed4

Please sign in to comment.