-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign_hex.py
More file actions
21 lines (17 loc) · 809 Bytes
/
align_hex.py
File metadata and controls
21 lines (17 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python
import argparse
parser = argparse.ArgumentParser(description = 'Align hex file to memory addresses')
parser.add_argument('-i', '--input', help = 'Input hex file name', default = 'diag.hex')
parser.add_argument('-o', '--output', help = 'Output hex file name', default = 'diag.hex')
parser.add_argument('-s', '--start', help = 'Start address', default = 0x40000000, type = hex)
parser.add_argument('-n', '--increment', help = 'Increment value', default = 0x4, type = hex)
args = parser.parse_args()
with open(args.input,'r') as file:
lines = file.readlines()
with open(args.output, 'w') as file:
start = args.start
for line in lines:
line = "@" + hex(start)[2:] + " " + line
start = start + args.increment
file.write(line)
print(line, end = "")