1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

build: add combine and flash_combine make targets

This commit is contained in:
Pavol Rusnak 2017-05-30 17:48:19 +02:00
parent 5a41b4497b
commit cd7ee79c67
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 34 additions and 0 deletions

View File

@ -102,6 +102,9 @@ flash_bootloader: ## flash bootloader using st-flash
flash_firmware: ## flash firmware using st-flash
st-flash write $(FIRMWARE_BUILD_DIR)/firmware.bin 0x08020000
flash_combine: ## flash combined image using st-flash
st-flash write $(FIRMWARE_BUILD_DIR)/combined.bin 0x08000000
## openocd debug commands:
openocd: ## start openocd which connects to the device
@ -129,3 +132,10 @@ sizecheck: ## check sizes of binary files
test 32768 -ge $(shell stat -c%s $(BOARDLOADER_BUILD_DIR)/boardloader.bin)
test 65536 -ge $(shell stat -c%s $(BOOTLOADER_BUILD_DIR)/bootloader.bin)
test 917504 -ge $(shell stat -c%s $(FIRMWARE_BUILD_DIR)/firmware.bin)
combine: ## combine boardloader + bootloader + firmware into one combined image
./tools/combine_firmware \
0x08000000 $(BOARDLOADER_BUILD_DIR)/boardloader.bin \
0x08010000 $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
0x08020000 $(FIRMWARE_BUILD_DIR)/firmware.bin \
> $(FIRMWARE_BUILD_DIR)/combined.bin \

24
tools/combine_firmware Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import sys
def pairwise(iterable):
a = iter(iterable)
return zip(a, a)
files = sys.argv[1:]
files = list(pairwise(files))
offset = int(files[0][0], 16)
out = bytearray()
for addr, fn in files:
addr = int(addr, 16) - offset
data = open(fn, 'rb').read()
if len(out) < addr:
out += b'\x00' * (addr - len(out))
if len(out) != addr:
raise Exception('Alignment failed')
out += data
sys.stdout.buffer.write(out)