From 5b336a2b41374c2d9aa2a0e160fac8dd0fa16709 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 Sep 2024 12:07:07 +0200 Subject: [PATCH 1/2] calculate most bootloader properties --- bootloader/Cargo.toml | 2 ++ bootloader/README.md | 8 ++++---- bootloader/src/main.rs | 27 +++++++++++++++++---------- flashloader/slot-a-blinky/Cargo.toml | 2 +- flashloader/slot-b-blinky/Cargo.toml | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/bootloader/Cargo.toml b/bootloader/Cargo.toml index 692eaa2..018e85e 100644 --- a/bootloader/Cargo.toml +++ b/bootloader/Cargo.toml @@ -11,9 +11,11 @@ panic-rtt-target = { version = "0.1.3" } panic-halt = { version = "0.2" } rtt-target = { version = "0.5" } crc = "3" +static_assertions = "1" [dependencies.va416xx-hal] path = "../va416xx-hal" +features = ["va41630"] [features] default = [] diff --git a/bootloader/README.md b/bootloader/README.md index 387675a..da85dc9 100644 --- a/bootloader/README.md +++ b/bootloader/README.md @@ -12,11 +12,11 @@ The bootloader uses the following memory map: | 0x0 | Bootloader start | code up to 0x3FFC bytes | | 0x3FFC | Bootloader CRC | word | | 0x4000 | App image A start | code up to 0x1DFFC (~120K) bytes | -| 0x21FFC | App image A CRC check length | word | -| 0x21FFE | App image A CRC check value | word | +| 0x21FF8 | App image A CRC check length | word | +| 0x21FFC | App image A CRC check value | word | | 0x22000 | App image B start | code up to 0x1DFFC (~120K) bytes | -| 0x3FFFC | App image B CRC check length | word | -| 0x3FFFE | App image B CRC check value | word | +| 0x3FFF8 | App image B CRC check length | word | +| 0x3FFFC | App image B CRC check value | word | | 0x40000 | End of NVM | end | ## Additional Information diff --git a/bootloader/src/main.rs b/bootloader/src/main.rs index af0ba40..1997222 100644 --- a/bootloader/src/main.rs +++ b/bootloader/src/main.rs @@ -39,20 +39,27 @@ const RTT_PRINTOUT: bool = true; // Important bootloader addresses and offsets, vector table information. +const NVM_SIZE: u32 = 0x40000; + const BOOTLOADER_START_ADDR: u32 = 0x0; +const BOOTLOADER_CRC_ADDR: u32 = BOOTLOADER_END_ADDR - 4; const BOOTLOADER_END_ADDR: u32 = 0x4000; -const BOOTLOADER_CRC_ADDR: u32 = 0x3FFC; -const APP_A_START_ADDR: u32 = 0x4000; -pub const APP_A_END_ADDR: u32 = 0x22000; + +const APP_A_START_ADDR: u32 = BOOTLOADER_END_ADDR; // 0x4000 // The actual size of the image which is relevant for CRC calculation. -const APP_A_SIZE_ADDR: u32 = 0x21FF8; -const APP_A_CRC_ADDR: u32 = 0x21FFC; -const APP_B_START_ADDR: u32 = 0x22000; -pub const APP_B_END_ADDR: u32 = 0x40000; +const APP_A_SIZE_ADDR: u32 = APP_B_END_ADDR - 8; // 0x21FF8 +const APP_A_CRC_ADDR: u32 = APP_B_END_ADDR - 4; // 0x21FFC +pub const APP_A_END_ADDR: u32 = APP_B_END_ADDR - BOOTLOADER_END_ADDR / 2; + +const APP_B_START_ADDR: u32 = APP_A_END_ADDR; // 0x22000 // The actual size of the image which is relevant for CRC calculation. -const APP_B_SIZE_ADDR: u32 = 0x3FFF8; -const APP_B_CRC_ADDR: u32 = 0x3FFFC; -pub const APP_IMG_SZ: u32 = 0x1E000; +const APP_B_SIZE_ADDR: u32 = APP_B_END_ADDR - 8; // 0x3FFF8 +const APP_B_CRC_ADDR: u32 = APP_B_END_ADDR - 4; // 0x3FFFC +pub const APP_B_END_ADDR: u32 = NVM_SIZE; // 0x40000 + +pub const APP_IMG_SZ: u32 = APP_B_END_ADDR - APP_A_END_ADDR / 2; + +static_assertions::const_assert!((APP_B_END_ADDR - BOOTLOADER_END_ADDR) % 2 == 0); pub const VECTOR_TABLE_OFFSET: u32 = 0x0; pub const VECTOR_TABLE_LEN: u32 = 0x350; diff --git a/flashloader/slot-a-blinky/Cargo.toml b/flashloader/slot-a-blinky/Cargo.toml index 89ea213..5e7e23e 100644 --- a/flashloader/slot-a-blinky/Cargo.toml +++ b/flashloader/slot-a-blinky/Cargo.toml @@ -7,11 +7,11 @@ edition = "2021" [dependencies] cortex-m-rt = "0.7" -va416xx-hal = { path = "../../va416xx-hal" } panic-rtt-target = { version = "0.1.3" } rtt-target = { version = "0.5" } cortex-m = { version = "0.7", features = ["critical-section-single-core"] } embedded-hal = "1" +va416xx-hal = { path = "../../va416xx-hal", features = ["va41630"] } [profile.dev] codegen-units = 1 diff --git a/flashloader/slot-b-blinky/Cargo.toml b/flashloader/slot-b-blinky/Cargo.toml index c60bdb4..1b5c3d0 100644 --- a/flashloader/slot-b-blinky/Cargo.toml +++ b/flashloader/slot-b-blinky/Cargo.toml @@ -7,11 +7,11 @@ edition = "2021" [dependencies] cortex-m-rt = "0.7" -va416xx-hal = { path = "../../va416xx-hal" } panic-rtt-target = { version = "0.1.3" } rtt-target = { version = "0.5" } cortex-m = { version = "0.7", features = ["critical-section-single-core"] } embedded-hal = "1" +va416xx-hal = { path = "../../va416xx-hal", features = ["va41630"] } [profile.dev] codegen-units = 1 From 5eb38f9c2a1720e9cba421aed8c57b07625e9ce5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 23 Sep 2024 10:02:51 +0200 Subject: [PATCH 2/2] fix --- bootloader/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootloader/src/main.rs b/bootloader/src/main.rs index 1997222..40dbdf5 100644 --- a/bootloader/src/main.rs +++ b/bootloader/src/main.rs @@ -57,7 +57,7 @@ const APP_B_SIZE_ADDR: u32 = APP_B_END_ADDR - 8; // 0x3FFF8 const APP_B_CRC_ADDR: u32 = APP_B_END_ADDR - 4; // 0x3FFFC pub const APP_B_END_ADDR: u32 = NVM_SIZE; // 0x40000 -pub const APP_IMG_SZ: u32 = APP_B_END_ADDR - APP_A_END_ADDR / 2; +pub const APP_IMG_SZ: u32 = APP_B_END_ADDR - APP_A_START_ADDR / 2; static_assertions::const_assert!((APP_B_END_ADDR - BOOTLOADER_END_ADDR) % 2 == 0);