1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-30 03:42:34 +00:00

feat(core): improve flexibility of combine script, add combine fw make targets

[no changelog]
This commit is contained in:
tychovrahe 2024-02-22 22:24:56 +01:00 committed by TychoVrahe
parent e7f2d3f6cc
commit 1909d1ebdb
14 changed files with 366 additions and 258 deletions

View File

@ -42,89 +42,59 @@ OPENOCD_INTERFACE ?= stlink
# OpenOCD transport default. Alternative: jtag # OpenOCD transport default. Alternative: jtag
OPENOCD_TRANSPORT ?= hla_swd OPENOCD_TRANSPORT ?= hla_swd
ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T R DISC1)) ifeq ($(TREZOR_MODEL), 1)
OPENOCD_TARGET = target/stm32f4x.cfg MCU = STM32F2
BOARDLOADER_START = 0x08000000 LAYOUT_FILE = embed/models/model_T1B1.h
BOARDLOADER_END = 0x0800C000
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
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
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 OPENOCD_TARGET = target/stm32f2x.cfg
FIRMWARE_START = 0x08010000 else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T))
MCU = STM32F4
LAYOUT_FILE = embed/models/model_T2T1.h
OPENOCD_TARGET = target/stm32f4x.cfg
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),R))
MCU = STM32F4
LAYOUT_FILE = embed/models/model_T2B1.h
OPENOCD_TARGET = target/stm32f4x.cfg
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3T1))
MCU = STM32U5
OPENOCD_TARGET = target/stm32u5x.cfg
LAYOUT_FILE = embed/models/model_T3T1.h
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC1))
MCU = STM32F4
LAYOUT_FILE = embed/models/model_D001.h
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC2))
MCU = STM32U5
LAYOUT_FILE = embed/models/model_D002.h
OPENOCD_TARGET = target/stm32u5x.cfg
else else
$(error Unknown TREZOR_MODEL: $(TREZOR_MODEL)) $(error Unknown TREZOR_MODEL: $(TREZOR_MODEL))
endif endif
FLASH_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FLASH_START)
BOARDLOADER_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOARDLOADER_START)
BOOTLOADER_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOOTLOADER_START)
FIRMWARE_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_START)
STORAGE_1_OFFSET = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_1_OFFSET)
STORAGE_2_OFFSET = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_2_OFFSET)
STORAGE_SIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} NORCOW_SECTOR_SIZE)
BOARDLOADER_MAXSIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOARDLOADER_IMAGE_MAXSIZE)
BOOTLOADER_MAXSIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOOTLOADER_IMAGE_MAXSIZE)
FIRMWARE_MAXSIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_IMAGE_MAXSIZE)
FIRMWARE_P1_MAXSIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_P1_IMAGE_MAXSIZE)
FIRMWARE_P2_MAXSIZE = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_P2_IMAGE_MAXSIZE)
BOARDLOADER_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOARDLOADER_SECTOR_START)
BOARDLOADER_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOARDLOADER_SECTOR_END)
BOOTLOADER_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOOTLOADER_SECTOR_START)
BOOTLOADER_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} BOOTLOADER_SECTOR_END)
FIRMWARE_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_SECTOR_START)
FIRMWARE_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_SECTOR_END)
FIRMWARE_P2_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_P2_SECTOR_START)
FIRMWARE_P2_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} FIRMWARE_P2_SECTOR_END)
STORAGE_1_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_1_SECTOR_START)
STORAGE_1_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_1_SECTOR_END)
STORAGE_2_SECTOR_START = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_2_SECTOR_START)
STORAGE_2_SECTOR_END = $(shell python ./tools/layout_parser.py ${LAYOUT_FILE} STORAGE_2_SECTOR_END)
OPENOCD = openocd -f interface/$(OPENOCD_INTERFACE).cfg -c "transport select $(OPENOCD_TRANSPORT)" -f $(OPENOCD_TARGET) OPENOCD = openocd -f interface/$(OPENOCD_INTERFACE).cfg -c "transport select $(OPENOCD_TRANSPORT)" -f $(OPENOCD_TARGET)
CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"' CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"'
@ -356,10 +326,10 @@ flash_bootloader_ci: $(BOOTLOADER_CI_BUILD_DIR)/bootloader.bin ## flash CI bootl
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOOTLOADER_START); exit" $(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOOTLOADER_START); exit"
flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenOCD flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(PRODTEST_START); exit" $(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD
ifdef FIRMWARE_P2_START ifeq ($(MCU),$(filter $(MCU),STM32F4))
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit" $(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
else else
@ -367,7 +337,7 @@ else
endif endif
flash_combine: $(PRODTEST_BUILD_DIR)/combined.bin ## flash combined using OpenOCD flash_combine: $(PRODTEST_BUILD_DIR)/combined.bin ## flash combined using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOARDLOADER_START); exit" $(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FLASH_START); exit"
flash_erase: ## erase all sectors in flash bank 0 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" $(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 0 last; flash erase_check 0; exit"
@ -376,7 +346,7 @@ flash_erase_bootloader: ## erase bootloader
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(BOOTLOADER_SECTOR_START) $(BOOTLOADER_SECTOR_END); exit" $(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(BOOTLOADER_SECTOR_START) $(BOOTLOADER_SECTOR_END); exit"
flash_erase_firmware: ## erase bootloader flash_erase_firmware: ## erase bootloader
ifdef FIRMWARE_P2_START ifeq ($(MCU),$(filter $(MCU),STM32F4))
$(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" $(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 else
@ -447,14 +417,30 @@ sizecheck: ## check sizes of binary files
combine: ## combine boardloader + bootloader + prodtest into one combined image combine: ## combine boardloader + bootloader + prodtest into one combined image
./tools/combine_firmware \ ./tools/combine_firmware \
$(BOARDLOADER_BUILD_DIR)/boardloader.bin \ $(LAYOUT_FILE) \
$(BOOTLOADER_BUILD_DIR)/bootloader.bin \
$(PRODTEST_BUILD_DIR)/prodtest.bin \
$(PRODTEST_BUILD_DIR)/combined.bin \ $(PRODTEST_BUILD_DIR)/combined.bin \
$(BOARDLOADER_START) \ -b BOARDLOADER $(BOARDLOADER_BUILD_DIR)/boardloader.bin \
$(BOARDLOADER_END) \ -b BOOTLOADER $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
$(BOOTLOADER_START) \ -b FIRMWARE $(PRODTEST_BUILD_DIR)/prodtest.bin
$(PRODTEST_START)
ifeq ($(MCU),$(filter $(MCU),STM32F4))
combine_fw: ## combine boardloader + bootloader + firmware into one combined image
./tools/combine_firmware \
$(LAYOUT_FILE) \
$(PRODTEST_BUILD_DIR)/combined.bin \
-b BOARDLOADER $(BOARDLOADER_BUILD_DIR)/boardloader.bin \
-b BOOTLOADER $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
-b FIRMWARE $(FIRMWARE_BUILD_DIR)/firmware.bin.p1 \
-b FIRMWARE_P2 $(FIRMWARE_BUILD_DIR)/firmware.bin.p2
else ifeq ($(MCU),$(filter $(MCU),STM32U5))
combine_fw: ## combine boardloader + bootloader + firmware into one combined image
./tools/combine_firmware \
$(LAYOUT_FILE) \
$(PRODTEST_BUILD_DIR)/combined.bin \
-b BOARDLOADER $(BOARDLOADER_BUILD_DIR)/boardloader.bin \
-b BOOTLOADER $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
-b FIRMWARE $(FIRMWARE_BUILD_DIR)/firmware.bin
endif
upload: ## upload firmware using trezorctl upload: ## upload firmware using trezorctl
trezorctl firmware_update -s -f $(FIRMWARE_BUILD_DIR)/firmware.bin trezorctl firmware_update -s -f $(FIRMWARE_BUILD_DIR)/firmware.bin

View File

@ -18,15 +18,35 @@
(const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \ (const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \
(const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48", (const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48",
#define BOARDLOADER_START 0x08000000
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define IMAGE_CHUNK_SIZE (128 * 1024) #define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_BLAKE2S #define IMAGE_HASH_BLAKE2S
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB #define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024) // SHARED WITH MAKEFILE
#define FLASH_START 0x08000000
#define BOARDLOADER_START 0x08000000
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define FIRMWARE_P2_START 0x08120000
#define STORAGE_1_OFFSET 0x10000
#define STORAGE_2_OFFSET 0x110000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define BOARDLOADER_IMAGE_MAXSIZE (3 * 16 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (1 * 128 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (13 * 128 * 1024) // 1664 kB
#define FIRMWARE_P1_IMAGE_MAXSIZE (6 * 128 * 1024)
#define FIRMWARE_P2_IMAGE_MAXSIZE (7 * 128 * 1024)
#define BOARDLOADER_SECTOR_START 0
#define BOARDLOADER_SECTOR_END 3
#define BOOTLOADER_SECTOR_START 5
#define BOOTLOADER_SECTOR_END 5
#define FIRMWARE_SECTOR_START 6
#define FIRMWARE_SECTOR_END 11
#define FIRMWARE_P2_SECTOR_START 17
#define FIRMWARE_P2_SECTOR_END 23
#define STORAGE_1_SECTOR_START 4
#define STORAGE_1_SECTOR_END 4
#define STORAGE_2_SECTOR_START 16
#define STORAGE_2_SECTOR_END 16
#endif #endif

View File

@ -1,8 +1,6 @@
#ifndef MODELS_MODEL_DISC2_H_ #ifndef MODELS_MODEL_DISC2_H_
#define MODELS_MODEL_DISC2_H_ #define MODELS_MODEL_DISC2_H_
#include "sizedefs.h"
#define MODEL_NAME "T" #define MODEL_NAME "T"
#define MODEL_FULL_NAME "Trezor Model T" #define MODEL_FULL_NAME "Trezor Model T"
#define MODEL_INTERNAL_NAME "D002" #define MODEL_INTERNAL_NAME "D002"
@ -21,15 +19,30 @@
(const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \ (const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \
(const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48", (const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48",
#define BOARDLOADER_START 0x0C004000
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define BOOTLOADER_START 0x0C010000
#define FIRMWARE_START 0x0C050000
#define IMAGE_CHUNK_SIZE SIZE_256K #define IMAGE_CHUNK_SIZE SIZE_256K
#define IMAGE_HASH_SHA256 #define IMAGE_HASH_SHA256
#define BOOTLOADER_IMAGE_MAXSIZE SIZE_128K #define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define FIRMWARE_IMAGE_MAXSIZE SIZE_3712K
#define NORCOW_SECTOR_SIZE SIZE_64K // SHARED WITH MAKEFILE
#define FLASH_START 0x0C000000
#define BOARDLOADER_START 0x0C004000
#define BOOTLOADER_START 0x0C010000
#define FIRMWARE_START 0x0C050000
#define STORAGE_1_OFFSET 0x30000
#define STORAGE_2_OFFSET 0x50000
#define NORCOW_SECTOR_SIZE (8 * 8 * 1024) // 64 kB
#define BOARDLOADER_IMAGE_MAXSIZE (6 * 8 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (16 * 8 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (464 * 8 * 1024) // 3712 kB
#define BOARDLOADER_SECTOR_START 0x2
#define BOARDLOADER_SECTOR_END 0x7
#define BOOTLOADER_SECTOR_START 0x8
#define BOOTLOADER_SECTOR_END 0x17
#define FIRMWARE_SECTOR_START 0x28
#define FIRMWARE_SECTOR_END 0x1F7
#define STORAGE_1_SECTOR_START 0x18
#define STORAGE_1_SECTOR_END 0x1F
#define STORAGE_2_SECTOR_START 0x20
#define STORAGE_2_SECTOR_END 0x27
#endif #endif

View File

@ -6,16 +6,18 @@ const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x18, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 8, .num_sectors =
STORAGE_1_SECTOR_END - STORAGE_1_SECTOR_START + 1,
}, },
}, },
{ {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x20, .first_sector = STORAGE_2_SECTOR_START,
.num_sectors = 8, .num_sectors =
STORAGE_2_SECTOR_END - STORAGE_2_SECTOR_START + 1,
}, },
}, },
}; };
@ -24,8 +26,9 @@ const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 2, .first_sector = BOARDLOADER_SECTOR_START,
.num_sectors = 6, .num_sectors =
BOARDLOADER_SECTOR_END - BOARDLOADER_SECTOR_START + 1,
}, },
}; };
@ -33,8 +36,8 @@ const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x08, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 16, .num_sectors = BOOTLOADER_SECTOR_END - BOOTLOADER_SECTOR_START + 1,
}, },
}; };
@ -42,8 +45,8 @@ const flash_area_t FIRMWARE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x28, .first_sector = FIRMWARE_SECTOR_START.num_sectors =
.num_sectors = 464, FIRMWARE_SECTOR_END - FIRMWARE_SECTOR_START + 1,
}, },
}; };
@ -78,7 +81,7 @@ const flash_area_t WIPE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x18, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 488, .num_sectors = 488,
}, },
}; };
@ -87,7 +90,7 @@ const flash_area_t ALL_WIPE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x08, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 504, .num_sectors = 504,
}, },
}; };

View File

@ -7,13 +7,24 @@
#define MODEL_INTERNAL_NAME_TOKEN T1B1 #define MODEL_INTERNAL_NAME_TOKEN T1B1
#define MODEL_INTERNAL_NAME_QSTR MP_QSTR_T1B1 #define MODEL_INTERNAL_NAME_QSTR MP_QSTR_T1B1
#define BOOTLOADER_START 0x08000000
#define FIRMWARE_START 0x08010000
#define IMAGE_CHUNK_SIZE (64 * 1024) #define IMAGE_CHUNK_SIZE (64 * 1024)
#define IMAGE_HASH_SHA256 #define IMAGE_HASH_SHA256
#define BOOTLOADER_IMAGE_MAXSIZE (32 * 1024 * 1) // 32 KB
#define FIRMWARE_IMAGE_MAXSIZE (64 * 1024 * 15) // 960 KB // SHARED WITH MAKEFILE
#define NORCOW_SECTOR_SIZE (16 * 1024) #define FLASH_START 0x08000000
#define BOOTLOADER_START 0x08000000
#define FIRMWARE_START 0x08010000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define BOOTLOADER_IMAGE_MAXSIZE (1 * 32 * 1024) // 32 kB
#define FIRMWARE_IMAGE_MAXSIZE (15 * 64 * 1024) // 960 kB
#define BOOTLOADER_SECTOR_START 0
#define BOOTLOADER_SECTOR_END 2
#define FIRMWARE_SECTOR_START 4
#define FIRMWARE_SECTOR_END 11
#define STORAGE_1_SECTOR_START 2
#define STORAGE_1_SECTOR_END 2
#define STORAGE_2_SECTOR_START 3
#define STORAGE_2_SECTOR_END 3
#endif #endif

View File

@ -6,16 +6,18 @@ const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 2, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_1_SECTOR_END - STORAGE_1_SECTOR_START + 1,
}, },
}, },
{ {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 3, .first_sector = STORAGE_2_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_2_SECTOR_END - STORAGE_2_SECTOR_START + 1,
}, },
}, },
}; };
@ -24,8 +26,8 @@ const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 2, .num_sectors = BOOTLOADER_SECTOR_END - BOOTLOADER_SECTOR_START + 1,
}, },
}; };
@ -33,7 +35,7 @@ const flash_area_t FIRMWARE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 4, .first_sector = FIRMWARE_SECTOR_START,
.num_sectors = 8, .num_sectors = FIRMWARE_SECTOR_END - FIRMWARE_SECTOR_START + 1,
}, },
}; };

View File

@ -18,15 +18,35 @@
(const uint8_t *)"\xd2\xde\xf6\x91\xc1\xe9\xd8\x09\xd8\x19\x0c\xf7\xaf\x93\x5c\x10\x68\x8f\x68\x98\x34\x79\xb4\xee\x9a\xba\xc1\x91\x04\x87\x8e\xc1", \ (const uint8_t *)"\xd2\xde\xf6\x91\xc1\xe9\xd8\x09\xd8\x19\x0c\xf7\xaf\x93\x5c\x10\x68\x8f\x68\x98\x34\x79\xb4\xee\x9a\xba\xc1\x91\x04\x87\x8e\xc1", \
(const uint8_t *)"\x07\xc8\x51\x34\x94\x6b\xf8\x9f\xa1\x9b\xdc\x2c\x5e\x5f\xf9\xce\x01\x29\x65\x08\xee\x08\x63\xd0\xff\x6d\x63\x33\x1d\x1a\x25\x16", (const uint8_t *)"\x07\xc8\x51\x34\x94\x6b\xf8\x9f\xa1\x9b\xdc\x2c\x5e\x5f\xf9\xce\x01\x29\x65\x08\xee\x08\x63\xd0\xff\x6d\x63\x33\x1d\x1a\x25\x16",
#define BOARDLOADER_START 0x08000000
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define IMAGE_CHUNK_SIZE (128 * 1024) #define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_BLAKE2S #define IMAGE_HASH_BLAKE2S
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB #define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024) // SHARED WITH MAKEFILE
#define FLASH_START 0x08000000
#define BOARDLOADER_START 0x08000000
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define FIRMWARE_P2_START 0x08120000
#define STORAGE_1_OFFSET 0x10000
#define STORAGE_2_OFFSET 0x110000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define BOARDLOADER_IMAGE_MAXSIZE (3 * 16 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (1 * 128 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (13 * 128 * 1024) // 1664 kB
#define FIRMWARE_P1_IMAGE_MAXSIZE (6 * 128 * 1024)
#define FIRMWARE_P2_IMAGE_MAXSIZE (7 * 128 * 1024)
#define BOARDLOADER_SECTOR_START 0
#define BOARDLOADER_SECTOR_END 3
#define BOOTLOADER_SECTOR_START 5
#define BOOTLOADER_SECTOR_END 5
#define FIRMWARE_SECTOR_START 6
#define FIRMWARE_SECTOR_END 11
#define FIRMWARE_P2_SECTOR_START 17
#define FIRMWARE_P2_SECTOR_END 23
#define STORAGE_1_SECTOR_START 4
#define STORAGE_1_SECTOR_END 4
#define STORAGE_2_SECTOR_START 16
#define STORAGE_2_SECTOR_END 16
#endif #endif

View File

@ -6,16 +6,18 @@ const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 4, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_1_SECTOR_END - STORAGE_1_SECTOR_START + 1,
}, },
}, },
{ {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 16, .first_sector = STORAGE_2_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_2_SECTOR_END - STORAGE_2_SECTOR_START + 1,
}, },
}, },
}; };
@ -24,8 +26,9 @@ const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0, .first_sector = BOARDLOADER_SECTOR_START,
.num_sectors = 3, .num_sectors =
BOARDLOADER_SECTOR_END - BOARDLOADER_SECTOR_START + 1,
}, },
}; };
@ -51,8 +54,8 @@ const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 5, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 1, .num_sectors = BOOTLOADER_SECTOR_END - BOOTLOADER_SECTOR_START + 1,
}, },
}; };
@ -60,13 +63,14 @@ const flash_area_t FIRMWARE_AREA = {
.num_subareas = 2, .num_subareas = 2,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 6, .first_sector = FIRMWARE_SECTOR_START,
.num_sectors = 6, .num_sectors = FIRMWARE_SECTOR_END - FIRMWARE_SECTOR_START + 1,
}, },
.subarea[1] = .subarea[1] =
{ {
.first_sector = 17, .first_sector = FIRMWARE_P2_SECTOR_START,
.num_sectors = 7, .num_sectors =
FIRMWARE_P2_SECTOR_END - FIRMWARE_P2_SECTOR_START + 1,
}, },
}; };

View File

@ -18,15 +18,35 @@
(const uint8_t *)"\x80\xd0\x36\xb0\x87\x39\xb8\x46\xf4\xcb\x77\x59\x30\x78\xde\xb2\x5d\xc9\x48\x7a\xed\xcf\x52\xe3\x0b\x4f\xb7\xcd\x70\x24\x17\x8a", \ (const uint8_t *)"\x80\xd0\x36\xb0\x87\x39\xb8\x46\xf4\xcb\x77\x59\x30\x78\xde\xb2\x5d\xc9\x48\x7a\xed\xcf\x52\xe3\x0b\x4f\xb7\xcd\x70\x24\x17\x8a", \
(const uint8_t *)"\xb8\x30\x7a\x71\xf5\x52\xc6\x0a\x4c\xbb\x31\x7f\xf4\x8b\x82\xcd\xbf\x6b\x6b\xb5\xf0\x4c\x92\x0f\xec\x7b\xad\xf0\x17\x88\x37\x51", (const uint8_t *)"\xb8\x30\x7a\x71\xf5\x52\xc6\x0a\x4c\xbb\x31\x7f\xf4\x8b\x82\xcd\xbf\x6b\x6b\xb5\xf0\x4c\x92\x0f\xec\x7b\xad\xf0\x17\x88\x37\x51",
#define BOARDLOADER_START 0x08000000
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define IMAGE_CHUNK_SIZE (128 * 1024) #define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_BLAKE2S #define IMAGE_HASH_BLAKE2S
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB #define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024) // SHARED WITH MAKEFILE
#define FLASH_START 0x08000000
#define BOARDLOADER_START 0x08000000
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define FIRMWARE_P2_START 0x08120000
#define STORAGE_1_OFFSET 0x10000
#define STORAGE_2_OFFSET 0x110000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define BOARDLOADER_IMAGE_MAXSIZE (3 * 16 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (1 * 128 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (13 * 128 * 1024) // 1664 kB
#define FIRMWARE_P1_IMAGE_MAXSIZE (6 * 128 * 1024)
#define FIRMWARE_P2_IMAGE_MAXSIZE (7 * 128 * 1024)
#define BOARDLOADER_SECTOR_START 0
#define BOARDLOADER_SECTOR_END 3
#define BOOTLOADER_SECTOR_START 5
#define BOOTLOADER_SECTOR_END 5
#define FIRMWARE_SECTOR_START 6
#define FIRMWARE_SECTOR_END 11
#define FIRMWARE_P2_SECTOR_START 17
#define FIRMWARE_P2_SECTOR_END 23
#define STORAGE_1_SECTOR_START 4
#define STORAGE_1_SECTOR_END 4
#define STORAGE_2_SECTOR_START 16
#define STORAGE_2_SECTOR_END 16
#endif #endif

View File

@ -6,16 +6,18 @@ const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 4, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_1_SECTOR_END - STORAGE_1_SECTOR_START + 1,
}, },
}, },
{ {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 16, .first_sector = STORAGE_2_SECTOR_START,
.num_sectors = 1, .num_sectors =
STORAGE_2_SECTOR_END - STORAGE_2_SECTOR_START + 1,
}, },
}, },
}; };
@ -24,8 +26,9 @@ const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0, .first_sector = BOARDLOADER_SECTOR_START,
.num_sectors = 3, .num_sectors =
BOARDLOADER_SECTOR_END - BOARDLOADER_SECTOR_START + 1,
}, },
}; };
@ -42,8 +45,8 @@ const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 5, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 1, .num_sectors = BOOTLOADER_SECTOR_END - BOOTLOADER_SECTOR_START + 1,
}, },
}; };
@ -51,13 +54,14 @@ const flash_area_t FIRMWARE_AREA = {
.num_subareas = 2, .num_subareas = 2,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 6, .first_sector = FIRMWARE_SECTOR_START,
.num_sectors = 6, .num_sectors = FIRMWARE_SECTOR_END - FIRMWARE_SECTOR_START + 1,
}, },
.subarea[1] = .subarea[1] =
{ {
.first_sector = 17, .first_sector = FIRMWARE_P2_SECTOR_START,
.num_sectors = 7, .num_sectors =
FIRMWARE_P2_SECTOR_END - FIRMWARE_P2_SECTOR_START + 1,
}, },
}; };

View File

@ -20,15 +20,30 @@
(const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \ (const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \
(const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48", (const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48",
#define BOARDLOADER_START 0x0C004000
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define BOOTLOADER_START 0x0C010000
#define FIRMWARE_START 0x0C050000
#define IMAGE_CHUNK_SIZE (128 * 1024) #define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_SHA256 #define IMAGE_HASH_SHA256
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB #define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024) // SHARED WITH MAKEFILE
#define FLASH_START 0x0C000000
#define BOARDLOADER_START 0x0C004000
#define BOOTLOADER_START 0x0C010000
#define FIRMWARE_START 0x0C050000
#define STORAGE_1_OFFSET 0x30000
#define STORAGE_2_OFFSET 0x50000
#define NORCOW_SECTOR_SIZE (8 * 8 * 1024) // 64 kB
#define BOARDLOADER_IMAGE_MAXSIZE (6 * 8 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (16 * 8 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (208 * 8 * 1024) // 1664 kB
#define BOARDLOADER_SECTOR_START 0x2
#define BOARDLOADER_SECTOR_END 0x7
#define BOOTLOADER_SECTOR_START 0x8
#define BOOTLOADER_SECTOR_END 0x17
#define FIRMWARE_SECTOR_START 0x28
#define FIRMWARE_SECTOR_END 0xF7
#define STORAGE_1_SECTOR_START 0x18
#define STORAGE_1_SECTOR_END 0x1F
#define STORAGE_2_SECTOR_START 0x20
#define STORAGE_2_SECTOR_END 0x27
#endif #endif

View File

@ -6,16 +6,18 @@ const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x18, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 8, .num_sectors =
STORAGE_1_SECTOR_END - STORAGE_1_SECTOR_START + 1,
}, },
}, },
{ {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x20, .first_sector = STORAGE_2_SECTOR_START,
.num_sectors = 8, .num_sectors =
STORAGE_2_SECTOR_END - STORAGE_2_SECTOR_START + 1,
}, },
}, },
}; };
@ -24,8 +26,9 @@ const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 2, .first_sector = BOARDLOADER_SECTOR_START,
.num_sectors = 6, .num_sectors =
BOARDLOADER_SECTOR_END - BOARDLOADER_SECTOR_START + 1,
}, },
}; };
@ -33,8 +36,8 @@ const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x08, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 16, .num_sectors = BOOTLOADER_SECTOR_END - BOOTLOADER_SECTOR_START + 1,
}, },
}; };
@ -42,8 +45,8 @@ const flash_area_t FIRMWARE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x28, .first_sector = FIRMWARE_SECTOR_START,
.num_sectors = 208, .num_sectors = FIRMWARE_SECTOR_END - FIRMWARE_SECTOR_START + 1,
}, },
}; };
@ -78,7 +81,7 @@ const flash_area_t WIPE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x18, .first_sector = STORAGE_1_SECTOR_START,
.num_sectors = 232, .num_sectors = 232,
}, },
}; };
@ -87,7 +90,7 @@ const flash_area_t ALL_WIPE_AREA = {
.num_subareas = 1, .num_subareas = 1,
.subarea[0] = .subarea[0] =
{ {
.first_sector = 0x08, .first_sector = BOOTLOADER_SECTOR_START,
.num_sectors = 248, .num_sectors = 248,
}, },
}; };

View File

@ -3,99 +3,65 @@ from __future__ import annotations
import datetime import datetime
import io import io
import sys
from pathlib import Path from pathlib import Path
import os
import subprocess
import click import click
def get_layout_params(layout: Path, name: str) -> int:
directory = os.path.dirname(os.path.realpath(__file__))
with subprocess.Popen(args=["python", Path(directory, "layout_parser.py"), str(layout), name],
stdout=subprocess.PIPE) as script:
return int(script.stdout.read().decode().strip())
@click.command() @click.command()
@click.argument( @click.argument(
"boardloader", "layout",
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=Path), type=click.Path(dir_okay=False, writable=True, path_type=Path),
) required=True,
@click.argument(
"bootloader",
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=Path),
)
@click.argument(
"firmware",
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=Path),
) )
@click.argument( @click.argument(
"outfile", "outfile",
type=click.Path(dir_okay=False, writable=True, path_type=Path), type=click.Path(dir_okay=False, writable=True, path_type=Path),
required=False, required=False,
) )
@click.argument( @click.option(
"boardloader_start", "--bin",
type=click.STRING, "-b",
required=False, type=(str, click.Path(exists=True, dir_okay=False, readable=True, path_type=Path)),
default="0x08000000", multiple=True,
)
@click.argument(
"boardloader_end",
type=click.STRING,
required=False,
default="0x0800C000",
)
@click.argument(
"bootloader_start",
type=click.STRING,
required=False,
default="0x08020000",
)
@click.argument(
"firmware_start",
type=click.STRING,
required=False,
default="0x08040000",
) )
def main( def main(
boardloader: Path, layout: Path,
bootloader: Path, bin: List[Tuple[Path, str]],
firmware: Path,
outfile: Path | None, outfile: Path | None,
boardloader_start: str,
boardloader_end: str,
bootloader_start: str,
firmware_start: str,
) -> None: ) -> None:
boardloader_start = int(boardloader_start, 0)
boardloader_end = int(boardloader_end, 0)
bootloader_start = int(bootloader_start, 0)
firmware_start = int(firmware_start, 0)
if outfile is None: if outfile is None:
today = datetime.date.today().strftime(r"%Y-%m-%d") today = datetime.date.today().strftime(r"%Y-%m-%d")
outfile = Path(f"combined-{today}.bin") outfile = Path(f"combined-{today}.bin")
offset = boardloader_start first_bin = bin[0]
(name, bin_path) = first_bin
start_offset = get_layout_params(layout, name+ "_START")
offset = start_offset
out_bytes = io.BytesIO() out_bytes = io.BytesIO()
# write boardloader for (name, bin_path) in bin:
offset += out_bytes.write(boardloader.read_bytes()) bin_start = get_layout_params(layout, name + "_START")
if offset > boardloader_end: # zero-pad until next section:
raise Exception("Boardloader too big") offset += out_bytes.write(b"\x00" * (bin_start - offset))
assert offset == bin_start
# zero-pad until next section: # write binary
offset += out_bytes.write(b"\x00" * (bootloader_start - offset)) offset += out_bytes.write(bin_path.read_bytes())
assert offset == bootloader_start
# write bootlaoder
offset += out_bytes.write(bootloader.read_bytes())
if offset > firmware_start:
raise Exception("Bootloader too big")
# zero-pad until next section:
offset += out_bytes.write(b"\x00" * (firmware_start - offset))
assert offset == firmware_start
# write firmware
offset += out_bytes.write(firmware.read_bytes())
# write out contents # write out contents
click.echo(f"Writing {outfile} ({offset - boardloader_start} bytes)") click.echo(f"Writing {outfile} ({offset - start_offset} bytes)")
outfile.write_bytes(out_bytes.getvalue()) outfile.write_bytes(out_bytes.getvalue())

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python3
from __future__ import annotations
from pathlib import Path
import click
import ast
@click.command()
@click.argument(
"layout",
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=Path),
)
@click.argument(
"name",
type=click.STRING,
)
def main(
layout: Path,
name: str,
) -> None:
search = f'#define {name} '
for line in layout.read_text().splitlines():
if line.startswith(search):
line = line.split(search)[1]
if line.startswith("("):
line = line.split("(")[1].split(")")[-2]
if "//" in line:
line = line.split("//")[0]
line = line.strip()
node = ast.parse(line, mode='eval')
result = eval(compile(node, '<string>', 'eval'))
print(result)
if __name__ == "__main__":
main()