diff options
| author | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
| commit | 776be79f7bb10b09e795e2ea93bb795a653c9b4c (patch) | |
| tree | 269046d330ee503c84049bb8fc47baf0297ecb80 /embassy-boot/stm32 | |
| parent | 84628d36cf743193cbf0e7d47ef1cfa9fb590890 (diff) | |
Move bootloader main to examples
This should remove some confusion around embassy-boot-* being a library
vs. a binary. The binary is now an example bootloader instead.
Diffstat (limited to 'embassy-boot/stm32')
| -rw-r--r-- | embassy-boot/stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-boot/stm32/build.rs | 32 | ||||
| -rw-r--r-- | embassy-boot/stm32/memory.x | 18 | ||||
| -rw-r--r-- | embassy-boot/stm32/src/main.rs | 46 |
4 files changed, 3 insertions, 97 deletions
diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index 3f198c114..1b6eeef93 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | edition = "2021" | 2 | edition = "2021" |
| 3 | name = "embassy-boot-stm32" | 3 | name = "embassy-boot-stm32" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Bootloader for STM32 chips" | 5 | description = "Bootloader lib for STM32 chips" |
| 6 | |||
| 7 | [lib] | ||
| 6 | 8 | ||
| 7 | [dependencies] | 9 | [dependencies] |
| 8 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "0.3", optional = true } |
diff --git a/embassy-boot/stm32/build.rs b/embassy-boot/stm32/build.rs deleted file mode 100644 index 3997702f6..000000000 --- a/embassy-boot/stm32/build.rs +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | use std::env; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::Write; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | |||
| 6 | fn main() { | ||
| 7 | // Put `memory.x` in our output directory and ensure it's | ||
| 8 | // on the linker search path. | ||
| 9 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 10 | File::create(out.join("memory.x")) | ||
| 11 | .unwrap() | ||
| 12 | .write_all(include_bytes!("memory.x")) | ||
| 13 | .unwrap(); | ||
| 14 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 15 | |||
| 16 | // By default, Cargo will re-run a build script whenever | ||
| 17 | // any file in the project changes. By specifying `memory.x` | ||
| 18 | // here, we ensure the build script is only re-run when | ||
| 19 | // `memory.x` is changed. | ||
| 20 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 21 | |||
| 22 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 23 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 24 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 25 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 26 | } | ||
| 27 | |||
| 28 | let target = env::var("TARGET").unwrap(); | ||
| 29 | if target.starts_with("thumbv6m-") { | ||
| 30 | println!("cargo:rustc-cfg=armv6m"); | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/embassy-boot/stm32/memory.x b/embassy-boot/stm32/memory.x deleted file mode 100644 index 110c23259..000000000 --- a/embassy-boot/stm32/memory.x +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | ||
| 6 | ACTIVE : ORIGIN = 0x08008000, LENGTH = 32K | ||
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); | ||
diff --git a/embassy-boot/stm32/src/main.rs b/embassy-boot/stm32/src/main.rs deleted file mode 100644 index 45c511ced..000000000 --- a/embassy-boot/stm32/src/main.rs +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use cortex_m_rt::{entry, exception}; | ||
| 5 | #[cfg(feature = "defmt")] | ||
| 6 | use defmt_rtt as _; | ||
| 7 | use embassy_boot_stm32::*; | ||
| 8 | use embassy_stm32::flash::{Flash, ERASE_SIZE}; | ||
| 9 | |||
| 10 | #[entry] | ||
| 11 | fn main() -> ! { | ||
| 12 | let p = embassy_stm32::init(Default::default()); | ||
| 13 | |||
| 14 | // Uncomment this if you are debugging the bootloader with debugger/RTT attached, | ||
| 15 | // as it prevents a hard fault when accessing flash 'too early' after boot. | ||
| 16 | /* | ||
| 17 | for i in 0..10000000 { | ||
| 18 | cortex_m::asm::nop(); | ||
| 19 | } | ||
| 20 | */ | ||
| 21 | |||
| 22 | let mut bl: BootLoader<ERASE_SIZE> = BootLoader::default(); | ||
| 23 | let mut flash = Flash::unlock(p.FLASH); | ||
| 24 | let start = bl.prepare(&mut SingleFlashProvider::new(&mut flash)); | ||
| 25 | core::mem::drop(flash); | ||
| 26 | unsafe { bl.load(start) } | ||
| 27 | } | ||
| 28 | |||
| 29 | #[no_mangle] | ||
| 30 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 31 | unsafe extern "C" fn HardFault() { | ||
| 32 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 33 | } | ||
| 34 | |||
| 35 | #[exception] | ||
| 36 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 37 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 38 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 39 | |||
| 40 | panic!("DefaultHandler #{:?}", irqn); | ||
| 41 | } | ||
| 42 | |||
| 43 | #[panic_handler] | ||
| 44 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 45 | cortex_m::asm::udf(); | ||
| 46 | } | ||
