rockchip: make_fit_atf: make python3 compatible

Make script python3 compatible. No functional changes intended.

Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
lime2-spi
Mian Yousaf Kaukab 6 years ago committed by Philipp Tomsich
parent e4011e8daa
commit 7009eae890
  1. 89
      arch/arm/mach-rockchip/make_fit_atf.py

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
"""
A script to generate FIT image source for rockchip boards
with ARM Trusted Firmware
@ -43,6 +43,7 @@ DT_HEADER="""// SPDX-License-Identifier: GPL-2.0+ OR X11
compression = "none";
load = <0x%08x>;
};
"""
DT_IMAGES_NODE_END="""
@ -58,18 +59,18 @@ def append_atf_node(file, atf_index, phy_addr, elf_entry):
Append ATF DT node to input FIT dts file.
"""
data = 'bl31_0x%08x.bin' % phy_addr
print >> file, '\t\tatf_%d {' % atf_index
print >> file, '\t\t\tdescription = \"ARM Trusted Firmware\";'
print >> file, '\t\t\tdata = /incbin/("%s");' % data
print >> file, '\t\t\ttype = "firmware";'
print >> file, '\t\t\tarch = "arm64";'
print >> file, '\t\t\tos = "arm-trusted-firmware";'
print >> file, '\t\t\tcompression = "none";'
print >> file, '\t\t\tload = <0x%08x>;' % phy_addr
file.write('\t\tatf_%d {\n' % atf_index)
file.write('\t\t\tdescription = \"ARM Trusted Firmware\";\n')
file.write('\t\t\tdata = /incbin/("%s");\n' % data)
file.write('\t\t\ttype = "firmware";\n')
file.write('\t\t\tarch = "arm64";\n')
file.write('\t\t\tos = "arm-trusted-firmware";\n')
file.write('\t\t\tcompression = "none";\n')
file.write('\t\t\tload = <0x%08x>;\n' % phy_addr)
if atf_index == 1:
print >> file, '\t\t\tentry = <0x%08x>;' % elf_entry
print >> file, '\t\t};'
print >> file, ''
file.write('\t\t\tentry = <0x%08x>;\n' % elf_entry)
file.write('\t\t};\n')
file.write('\n')
def append_fdt_node(file, dtbs):
"""
@ -78,43 +79,43 @@ def append_fdt_node(file, dtbs):
cnt = 1
for dtb in dtbs:
dtname = os.path.basename(dtb)
print >> file, '\t\tfdt_%d {' % cnt
print >> file, '\t\t\tdescription = "%s";' % dtname
print >> file, '\t\t\tdata = /incbin/("%s");' % dtb
print >> file, '\t\t\ttype = "flat_dt";'
print >> file, '\t\t\tcompression = "none";'
print >> file, '\t\t};'
print >> file, ''
file.write('\t\tfdt_%d {\n' % cnt)
file.write('\t\t\tdescription = "%s";\n' % dtname)
file.write('\t\t\tdata = /incbin/("%s");\n' % dtb)
file.write('\t\t\ttype = "flat_dt";\n')
file.write('\t\t\tcompression = "none";\n')
file.write('\t\t};\n')
file.write('\n')
cnt = cnt + 1
def append_conf_section(file, cnt, dtname, atf_cnt):
print >> file, '\t\tconfig_%d {' % cnt
print >> file, '\t\t\tdescription = "%s";' % dtname
print >> file, '\t\t\tfirmware = "atf_1";'
print >> file, '\t\t\tloadables = "uboot",',
file.write('\t\tconfig_%d {\n' % cnt)
file.write('\t\t\tdescription = "%s";\n' % dtname)
file.write('\t\t\tfirmware = "atf_1";\n')
file.write('\t\t\tloadables = "uboot",')
for i in range(1, atf_cnt):
print >> file, '"atf_%d"' % (i+1),
file.write('"atf_%d"' % (i+1))
if i != (atf_cnt - 1):
print >> file, ',',
file.write(',')
else:
print >> file, ';'
print >> file, '\t\t\tfdt = "fdt_1";'
print >> file, '\t\t};'
print >> file, ''
file.write(';\n')
file.write('\t\t\tfdt = "fdt_1";\n')
file.write('\t\t};\n')
file.write('\n')
def append_conf_node(file, dtbs, atf_cnt):
"""
Append configeration nodes.
"""
cnt = 1
print >> file, '\tconfigurations {'
print >> file, '\t\tdefault = "config_1";'
file.write('\tconfigurations {\n')
file.write('\t\tdefault = "config_1";\n')
for dtb in dtbs:
dtname = os.path.basename(dtb)
append_conf_section(file, cnt, dtname, atf_cnt)
cnt = cnt + 1
print >> file, '\t};'
print >> file, ''
file.write('\t};\n')
file.write('\n')
def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_file_name):
"""
@ -127,7 +128,7 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi
num_load_seg = 0
p_paddr = 0xFFFFFFFF
with open(uboot_file_name) as uboot_file:
with open(uboot_file_name, 'rb') as uboot_file:
uboot = ELFFile(uboot_file)
for i in range(uboot.num_segments()):
seg = uboot.get_segment(i)
@ -137,9 +138,9 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi
assert (p_paddr != 0xFFFFFFFF and num_load_seg == 1)
print >> fit_file, DT_HEADER % p_paddr
fit_file.write(DT_HEADER % p_paddr)
with open(bl31_file_name) as bl31_file:
with open(bl31_file_name, 'rb') as bl31_file:
bl31 = ELFFile(bl31_file)
elf_entry = bl31.header['e_entry']
for i in range(bl31.num_segments()):
@ -150,15 +151,15 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi
append_atf_node(fit_file, i+1, paddr, elf_entry)
atf_cnt = i+1
append_fdt_node(fit_file, dtbs_file_name)
print >> fit_file, '%s' % DT_IMAGES_NODE_END
fit_file.write('%s\n' % DT_IMAGES_NODE_END)
append_conf_node(fit_file, dtbs_file_name, atf_cnt)
print >> fit_file, '%s' % DT_END
fit_file.write('%s\n' % DT_END)
if fit_file_name != sys.stdout:
fit_file.close()
def generate_atf_binary(bl31_file_name):
with open(bl31_file_name) as bl31_file:
with open(bl31_file_name, 'rb') as bl31_file:
bl31 = ELFFile(bl31_file)
num = bl31.num_segments()
@ -179,17 +180,17 @@ def get_bl31_segments_info(bl31_file_name):
bl31 = ELFFile(bl31_file)
num = bl31.num_segments()
print 'Number of Segments : %d' % bl31.num_segments()
print('Number of Segments : %d' % bl31.num_segments())
for i in range(num):
print 'Segment %d' % i
print('Segment %d' % i)
seg = bl31.get_segment(i)
ptype = seg[ELF_SEG_P_TYPE]
poffset = seg[ELF_SEG_P_OFFSET]
pmemsz = seg[ELF_SEG_P_MEMSZ]
pfilesz = seg[ELF_SEG_P_FILESZ]
print 'type: %s\nfilesz: %08x\nmemsz: %08x\noffset: %08x' % (ptype, pfilesz, pmemsz, poffset)
print('type: %s\nfilesz: %08x\nmemsz: %08x\noffset: %08x' % (ptype, pfilesz, pmemsz, poffset))
paddr = seg[ELF_SEG_P_PADDR]
print 'paddr: %08x' % paddr
print('paddr: %08x' % paddr)
def main():
uboot_elf="./u-boot"
@ -205,7 +206,7 @@ def main():
elif opt == "-b":
bl31_elf=val
elif opt == "-h":
print __doc__
print(__doc__)
sys.exit(2)
dtbs = args

Loading…
Cancel
Save