aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorÁlvaro Fernández Rojas <noltari@gmail.com>2020-05-14 18:19:35 +0200
committerÁlvaro Fernández Rojas <noltari@gmail.com>2020-05-18 18:24:06 +0200
commite575a7f777ef8af1f7916333f9d812cd0c46e505 (patch)
tree15dba2911a1e19d948848b5ac5fb72fbd48d3673 /scripts
parent8339f8d95ebb9b6ca8084d8979948107bcf5411c (diff)
downloadupstream-e575a7f777ef8af1f7916333f9d812cd0c46e505.tar.gz
upstream-e575a7f777ef8af1f7916333f9d812cd0c46e505.tar.bz2
upstream-e575a7f777ef8af1f7916333f9d812cd0c46e505.zip
scripts: support tags for CFE binaries
CFE loads binaries based on a 12 byte header which corresponds to: - u32: Load Address - u32: Entry Address - u32: Size Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cfe-bin-header.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/cfe-bin-header.py b/scripts/cfe-bin-header.py
new file mode 100755
index 0000000000..476a36d8dd
--- /dev/null
+++ b/scripts/cfe-bin-header.py
@@ -0,0 +1,72 @@
+#!/bin/env python3
+
+import argparse
+import os
+import struct
+
+def auto_int(x):
+ return int(x, 0)
+
+def create_header(args, size):
+ header = struct.pack('>III', args.entry_addr, args.load_addr, size)
+ return header
+
+def create_output(args):
+ in_st = os.stat(args.input_file)
+ in_size = in_st.st_size
+
+ header = create_header(args, in_size)
+ print(header)
+
+ in_f = open(args.input_file, 'r+b')
+ in_bytes = in_f.read(in_size)
+ in_f.close()
+
+ out_f = open(args.output_file, 'w+b')
+ out_f.write(header)
+ out_f.write(in_bytes)
+ out_f.close()
+
+def main():
+ global args
+
+ parser = argparse.ArgumentParser(description='')
+
+ parser.add_argument('--entry-addr',
+ dest='entry_addr',
+ action='store',
+ type=auto_int,
+ help='Entry Address')
+
+ parser.add_argument('--input-file',
+ dest='input_file',
+ action='store',
+ type=str,
+ help='Input file')
+
+ parser.add_argument('--load-addr',
+ dest='load_addr',
+ action='store',
+ type=auto_int,
+ help='Load Address')
+
+ parser.add_argument('--output-file',
+ dest='output_file',
+ action='store',
+ type=str,
+ help='Output file')
+
+ args = parser.parse_args()
+
+ if (not args.input_file) or (not args.output_file):
+ parser.print_help()
+
+ if not args.entry_addr:
+ args.entry_addr = 0x80010000
+
+ if not args.load_addr:
+ args.load_addr = 0x80010000
+
+ create_output(args)
+
+main()