chore(core): add makefile commands for erasing bootloader and firmware, fix read/erase storage commands

[no changelog]
pull/3474/head
tychovrahe 5 months ago committed by TychoVrahe
parent 8c1425edd5
commit 61b3273baa

@ -50,11 +50,27 @@ BOOTLOADER_START = 0x08020000
FIRMWARE_START = 0x08040000
FIRMWARE_P2_START = 0x08120000
PRODTEST_START = 0x08040000
STORAGE_1_OFFSET = 0x10000
STORAGE_2_OFFSET = 0x110000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_P1_MAXSIZE = 786432
FIRMWARE_P2_MAXSIZE = 917504
FIRMWARE_MAXSIZE = 1703936
BOARDLOADER_SECTOR_START = 0
BOARDLOADER_SECTOR_END = 3
BOOTLOADER_SECTOR_START = 5
BOOTLOADER_SECTOR_END = 5
FIRMWARE_SECTOR_START = 6
FIRMWARE_SECTOR_END = 11
FIRMWARE_P2_SECTOR_START = 17
FIRMWARE_P2_SECTOR_END = 23
STORAGE_1_SECTOR_START = 4
STORAGE_1_SECTOR_END = 4
STORAGE_2_SECTOR_START = 16
STORAGE_2_SECTOR_END = 16
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3T1))
OPENOCD_TARGET = target/stm32u5x.cfg
BOARDLOADER_START = 0x0C004000
@ -62,9 +78,22 @@ BOARDLOADER_END = 0x0C010000
BOOTLOADER_START = 0x0C010000
FIRMWARE_START = 0x0C050000
PRODTEST_START = 0x0C050000
STORAGE_1_OFFSET = 0x30000
STORAGE_2_OFFSET = 0x50000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_MAXSIZE = 1703936
BOARDLOADER_SECTOR_START = 0x2
BOARDLOADER_SECTOR_END = 0x7
BOOTLOADER_SECTOR_START = 0x8
BOOTLOADER_SECTOR_END = 0x17
FIRMWARE_SECTOR_START = 0x28
FIRMWARE_SECTOR_END = 0xF8
STORAGE_1_SECTOR_START = 0x18
STORAGE_1_SECTOR_END = 0x1F
STORAGE_2_SECTOR_START = 0x20
STORAGE_2_SECTOR_END = 0x27
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC2))
OPENOCD_TARGET = target/stm32u5x.cfg
BOARDLOADER_START = 0x0C004000
@ -72,9 +101,22 @@ BOARDLOADER_END = 0x0C010000
BOOTLOADER_START = 0x0C010000
FIRMWARE_START = 0x0C050000
PRODTEST_START = 0x0C050000
STORAGE_1_OFFSET = 0x30000
STORAGE_2_OFFSET = 0x50000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_MAXSIZE = 3735552
BOARDLOADER_SECTOR_START = 0x2
BOARDLOADER_SECTOR_END = 0x7
BOOTLOADER_SECTOR_START = 0x8
BOOTLOADER_SECTOR_END = 0x17
FIRMWARE_SECTOR_START = 0x28
FIRMWARE_SECTOR_END = 0x1F8
STORAGE_1_SECTOR_START = 0x18
STORAGE_1_SECTOR_END = 0x1F
STORAGE_2_SECTOR_START = 0x20
STORAGE_2_SECTOR_END = 0x27
else ifeq ($(TREZOR_MODEL), 1)
OPENOCD_TARGET = target/stm32f2x.cfg
FIRMWARE_START = 0x08010000
@ -330,11 +372,22 @@ flash_combine: $(PRODTEST_BUILD_DIR)/combined.bin ## flash combined using OpenOC
flash_erase: ## erase all sectors in flash bank 0
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 0 last; flash erase_check 0; exit"
flash_erase_bootloader: ## erase bootloader
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(BOOTLOADER_SECTOR_START) $(BOOTLOADER_SECTOR_END); exit"
flash_erase_firmware: ## erase bootloader
ifdef FIRMWARE_P2_START
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(FIRMWARE_SECTOR_START) $(FIRMWARE_SECTOR_END); flash erase_sector 0 $(FIRMWARE_P2_SECTOR_START) $(FIRMWARE_P2_SECTOR_END); exit"
else
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(FIRMWARE_SECTOR_START) $(FIRMWARE_SECTOR_END); exit"
endif
flash_read_storage: ## read storage sectors from flash
$(OPENOCD) -c "init; flash read_bank 0 storage1.data 0x10000 65536; flash read_bank 0 storage2.data 0x110000 65536; exit"
$(OPENOCD) -c "init; reset halt; flash read_bank 0 storage1.data $(STORAGE_1_OFFSET) $(STORAGE_SIZE); flash read_bank 0 storage2.data $(STORAGE_2_OFFSET) $(STORAGE_SIZE); exit"
flash_erase_storage: ## erase storage sectors from flash
$(OPENOCD) -c "init; flash erase_sector 0 4 4; flash erase_sector 0 16 16; exit"
$(OPENOCD) -c "init; reset halt; flash erase_sector 0 $(STORAGE_1_SECTOR_START) $(STORAGE_1_SECTOR_END); flash erase_sector 0 $(STORAGE_2_SECTOR_START) $(STORAGE_2_SECTOR_END); exit"
flash_bootloader_jlink: $(BOOTLOADER_BUILD_DIR)/bootloader.bin ## flash bootloader using JLink
JLinkExe -nogui 1 -commanderscript embed/bootloader/bootloader_flash.jlink

Loading…
Cancel
Save