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/nrf | |
| 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/nrf')
| -rw-r--r-- | embassy-boot/nrf/.cargo/config.toml | 20 | ||||
| -rw-r--r-- | embassy-boot/nrf/Cargo.toml | 37 | ||||
| -rw-r--r-- | embassy-boot/nrf/README.md | 11 | ||||
| -rw-r--r-- | embassy-boot/nrf/build.rs | 37 | ||||
| -rw-r--r-- | embassy-boot/nrf/memory-bm.x | 18 | ||||
| -rw-r--r-- | embassy-boot/nrf/memory-s140.x | 31 | ||||
| -rw-r--r-- | embassy-boot/nrf/memory.x | 18 | ||||
| -rw-r--r-- | embassy-boot/nrf/src/main.rs | 48 |
8 files changed, 3 insertions, 217 deletions
diff --git a/embassy-boot/nrf/.cargo/config.toml b/embassy-boot/nrf/.cargo/config.toml deleted file mode 100644 index 1060800a3..000000000 --- a/embassy-boot/nrf/.cargo/config.toml +++ /dev/null | |||
| @@ -1,20 +0,0 @@ | |||
| 1 | [unstable] | ||
| 2 | build-std = ["core"] | ||
| 3 | build-std-features = ["panic_immediate_abort"] | ||
| 4 | |||
| 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 6 | #runner = "./fruitrunner" | ||
| 7 | runner = "probe-run --chip nrf52840_xxAA" | ||
| 8 | |||
| 9 | rustflags = [ | ||
| 10 | # Code-size optimizations. | ||
| 11 | "-Z", "trap-unreachable=no", | ||
| 12 | #"-C", "no-vectorize-loops", | ||
| 13 | "-C", "force-frame-pointers=yes", | ||
| 14 | ] | ||
| 15 | |||
| 16 | [build] | ||
| 17 | target = "thumbv7em-none-eabi" | ||
| 18 | |||
| 19 | [env] | ||
| 20 | DEFMT_LOG = "trace" | ||
diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml index b5cc9c4fe..ea5794836 100644 --- a/embassy-boot/nrf/Cargo.toml +++ b/embassy-boot/nrf/Cargo.toml | |||
| @@ -2,11 +2,12 @@ | |||
| 2 | edition = "2021" | 2 | edition = "2021" |
| 3 | name = "embassy-boot-nrf" | 3 | name = "embassy-boot-nrf" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Bootloader for nRF chips" | 5 | description = "Bootloader lib for nRF chips" |
| 6 | |||
| 7 | [lib] | ||
| 6 | 8 | ||
| 7 | [dependencies] | 9 | [dependencies] |
| 8 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "0.3", optional = true } |
| 9 | defmt-rtt = { version = "0.3", optional = true } | ||
| 10 | 11 | ||
| 11 | embassy = { path = "../../embassy", default-features = false } | 12 | embassy = { path = "../../embassy", default-features = false } |
| 12 | embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } | 13 | embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } |
| @@ -28,35 +29,3 @@ defmt = [ | |||
| 28 | softdevice = [ | 29 | softdevice = [ |
| 29 | "nrf-softdevice-mbr", | 30 | "nrf-softdevice-mbr", |
| 30 | ] | 31 | ] |
| 31 | debug = ["defmt-rtt"] | ||
| 32 | |||
| 33 | [profile.dev] | ||
| 34 | debug = 2 | ||
| 35 | debug-assertions = true | ||
| 36 | incremental = false | ||
| 37 | opt-level = 'z' | ||
| 38 | overflow-checks = true | ||
| 39 | |||
| 40 | [profile.release] | ||
| 41 | codegen-units = 1 | ||
| 42 | debug = 2 | ||
| 43 | debug-assertions = false | ||
| 44 | incremental = false | ||
| 45 | lto = 'fat' | ||
| 46 | opt-level = 'z' | ||
| 47 | overflow-checks = false | ||
| 48 | |||
| 49 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 50 | [profile.dev.build-override] | ||
| 51 | codegen-units = 8 | ||
| 52 | debug = false | ||
| 53 | debug-assertions = false | ||
| 54 | opt-level = 0 | ||
| 55 | overflow-checks = false | ||
| 56 | |||
| 57 | [profile.release.build-override] | ||
| 58 | codegen-units = 8 | ||
| 59 | debug = false | ||
| 60 | debug-assertions = false | ||
| 61 | opt-level = 0 | ||
| 62 | overflow-checks = false | ||
diff --git a/embassy-boot/nrf/README.md b/embassy-boot/nrf/README.md deleted file mode 100644 index 23497a038..000000000 --- a/embassy-boot/nrf/README.md +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # Bootloader for nRF | ||
| 2 | |||
| 3 | The bootloader uses `embassy-boot` to interact with the flash. | ||
| 4 | |||
| 5 | # Usage | ||
| 6 | |||
| 7 | Flash the bootloader | ||
| 8 | |||
| 9 | ``` | ||
| 10 | cargo flash --features embassy-nrf/nrf52832 --release --chip nRF52832_xxAA | ||
| 11 | ``` | ||
diff --git a/embassy-boot/nrf/build.rs b/embassy-boot/nrf/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/embassy-boot/nrf/build.rs +++ /dev/null | |||
| @@ -1,37 +0,0 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
| 37 | } | ||
diff --git a/embassy-boot/nrf/memory-bm.x b/embassy-boot/nrf/memory-bm.x deleted file mode 100644 index 8a32b905f..000000000 --- a/embassy-boot/nrf/memory-bm.x +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x00000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K | ||
| 6 | ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K | ||
| 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); | ||
diff --git a/embassy-boot/nrf/memory-s140.x b/embassy-boot/nrf/memory-s140.x deleted file mode 100644 index 105db9972..000000000 --- a/embassy-boot/nrf/memory-s140.x +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | MBR : ORIGIN = 0x00000000, LENGTH = 4K | ||
| 5 | SOFTDEVICE : ORIGIN = 0x00001000, LENGTH = 155648 | ||
| 6 | ACTIVE : ORIGIN = 0x00027000, LENGTH = 425984 | ||
| 7 | DFU : ORIGIN = 0x0008F000, LENGTH = 430080 | ||
| 8 | FLASH : ORIGIN = 0x000f9000, LENGTH = 24K | ||
| 9 | BOOTLOADER_STATE : ORIGIN = 0x000ff000, LENGTH = 4K | ||
| 10 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x2fff8 | ||
| 11 | uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4 | ||
| 12 | } | ||
| 13 | |||
| 14 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); | ||
| 15 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); | ||
| 16 | |||
| 17 | __bootloader_active_start = ORIGIN(ACTIVE); | ||
| 18 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); | ||
| 19 | |||
| 20 | __bootloader_dfu_start = ORIGIN(DFU); | ||
| 21 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); | ||
| 22 | |||
| 23 | __bootloader_start = ORIGIN(FLASH); | ||
| 24 | |||
| 25 | SECTIONS | ||
| 26 | { | ||
| 27 | .uicr_bootloader_start_address : | ||
| 28 | { | ||
| 29 | LONG(__bootloader_start) | ||
| 30 | } > uicr_bootloader_start_address | ||
| 31 | } | ||
diff --git a/embassy-boot/nrf/memory.x b/embassy-boot/nrf/memory.x deleted file mode 100644 index 8a32b905f..000000000 --- a/embassy-boot/nrf/memory.x +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x00000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K | ||
| 6 | ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K | ||
| 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); | ||
diff --git a/embassy-boot/nrf/src/main.rs b/embassy-boot/nrf/src/main.rs deleted file mode 100644 index bc7e0755f..000000000 --- a/embassy-boot/nrf/src/main.rs +++ /dev/null | |||
| @@ -1,48 +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_nrf::*; | ||
| 8 | use embassy_nrf::nvmc::Nvmc; | ||
| 9 | |||
| 10 | #[entry] | ||
| 11 | fn main() -> ! { | ||
| 12 | let p = embassy_nrf::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::default(); | ||
| 23 | let start = bl.prepare(&mut SingleFlashProvider::new(&mut WatchdogFlash::start( | ||
| 24 | Nvmc::new(p.NVMC), | ||
| 25 | p.WDT, | ||
| 26 | 5, | ||
| 27 | ))); | ||
| 28 | unsafe { bl.load(start) } | ||
| 29 | } | ||
| 30 | |||
| 31 | #[no_mangle] | ||
| 32 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 33 | unsafe extern "C" fn HardFault() { | ||
| 34 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 35 | } | ||
| 36 | |||
| 37 | #[exception] | ||
| 38 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 39 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 40 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 41 | |||
| 42 | panic!("DefaultHandler #{:?}", irqn); | ||
| 43 | } | ||
| 44 | |||
| 45 | #[panic_handler] | ||
| 46 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 47 | cortex_m::asm::udf(); | ||
| 48 | } | ||
