mirror of
https://github.com/olofk/serv.git
synced 2025-04-20 03:47:09 -04:00
Improve makehex.py
This commit is contained in:
parent
2bb988b553
commit
7d08abb92d
3 changed files with 21 additions and 2060 deletions
|
@ -5,7 +5,7 @@ TOOLCHAIN_PREFIX=riscv64-unknown-elf-
|
|||
%.bin: %.elf
|
||||
$(TOOLCHAIN_PREFIX)objcopy -O binary $< $@
|
||||
%.hex: %.bin
|
||||
python3 makehex.py $< 2048 > $@
|
||||
python3 makehex.py $< > $@
|
||||
|
||||
clean:
|
||||
rm -f *.elf *.bin *.hex
|
||||
|
|
2047
sw/blinky.hex
2047
sw/blinky.hex
File diff suppressed because it is too large
Load diff
|
@ -7,21 +7,19 @@
|
|||
# binary, for any purpose, commercial or non-commercial, and by any
|
||||
# means.
|
||||
|
||||
from sys import argv
|
||||
|
||||
binfile = argv[1]
|
||||
nwords = int(argv[2])
|
||||
|
||||
with open(binfile, "rb") as f:
|
||||
bindata = f.read()
|
||||
|
||||
assert len(bindata) < 4*nwords
|
||||
assert len(bindata) % 4 == 0
|
||||
|
||||
for i in range(nwords):
|
||||
if i < len(bindata) // 4:
|
||||
w = bindata[4*i : 4*i+4]
|
||||
print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]))
|
||||
else:
|
||||
print("0")
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1], "rb") as f:
|
||||
cnt = 3
|
||||
s = ["00"]*4
|
||||
while True:
|
||||
data = f.read(1)
|
||||
if not data:
|
||||
print(''.join(s))
|
||||
exit(0)
|
||||
s[cnt] = "{:02X}".format(data[0])
|
||||
if cnt == 0:
|
||||
print(''.join(s))
|
||||
s = ["00"]*4
|
||||
cnt = 4
|
||||
cnt -= 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue