mirror of
https://github.com/andreili/katapult.git
synced 2025-08-23 19:34:06 +02:00
rp2040: added option to force bootloader before new application flashed
Signed-off-by: Alex Malishev <malishev@gmail.com>
This commit is contained in:
parent
c1ae0b4f1e
commit
0a24cd4502
48
scripts/uf2_append_boot_signature.py
Executable file
48
scripts/uf2_append_boot_signature.py
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
# Add boot signature (one page of zeros) at gived address.
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import sys, argparse, struct
|
||||
|
||||
def renumerate(content):
|
||||
result = bytearray()
|
||||
total = len(content) // 512
|
||||
for current in range(total):
|
||||
block = content[current * 512 : (current + 1) * 512]
|
||||
result.extend(block[ : 20])
|
||||
result.extend(struct.pack("<II", current, total))
|
||||
result.extend(block[ 28 : ])
|
||||
# print("address " + hex(int.from_bytes(block[12:16], "little")))
|
||||
return result
|
||||
|
||||
def add_signature(content, address):
|
||||
block = content[:512]
|
||||
nblock = bytearray()
|
||||
nblock.extend(block[:12])
|
||||
nblock.extend(struct.pack("<I", address))
|
||||
nblock.extend(block[16:32])
|
||||
nblock.extend(bytearray(476))
|
||||
nblock.extend(block[508:512])
|
||||
result = bytearray()
|
||||
result.extend(content)
|
||||
result.extend(nblock)
|
||||
return result
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Merge multiple uf2")
|
||||
parser.add_argument("-o", "--output", required=True, help="Output file")
|
||||
parser.add_argument("-i", "--input", required=True, help="Input files")
|
||||
parser.add_argument("-a", "--address", required=True, help="Address to put signature")
|
||||
|
||||
args = parser.parse_args()
|
||||
address = int(args.address,0)
|
||||
with open(args.input, 'rb') as f:
|
||||
content = f.read()
|
||||
content = add_signature(content, address)
|
||||
content = renumerate(content)
|
||||
with open(args.output, 'wb') as f:
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -60,6 +60,15 @@ config BLOCK_SIZE
|
||||
# Bootloader options
|
||||
######################################################################
|
||||
|
||||
config RP2040_ADD_BOOT_SIGNATURE
|
||||
bool
|
||||
default y
|
||||
help
|
||||
Add boot signature (zero page at application start)
|
||||
into resulting uf2.
|
||||
This is used to force bootloader entry
|
||||
before application is updated.
|
||||
|
||||
choice
|
||||
prompt "Flash chip" if LOW_LEVEL_OPTIONS
|
||||
config RP2040_FLASH_W25Q080
|
||||
|
@ -45,6 +45,9 @@ $(OUT)lib/rp2040/elf2uf2/elf2uf2: lib/rp2040/elf2uf2/main.cpp
|
||||
$(OUT)canboot.uf2: $(OUT)canboot.elf $(OUT)lib/rp2040/elf2uf2/elf2uf2
|
||||
@echo " Creating uf2 file $@"
|
||||
$(Q)$(OUT)lib/rp2040/elf2uf2/elf2uf2 $(OUT)canboot.elf $(OUT)canboot.uf2
|
||||
ifeq ($(CONFIG_RP2040_ADD_BOOT_SIGNATURE), y)
|
||||
$(Q)$(PYTHON) ./scripts/uf2_append_boot_signature.py --address $(CONFIG_APPLICATION_START) --input $(OUT)canboot.uf2 --output $(OUT)canboot.uf2
|
||||
endif
|
||||
|
||||
lib/rp2040_flash/rp2040_flash:
|
||||
@echo " Building rp2040_flash"
|
||||
|
Loading…
x
Reference in New Issue
Block a user