diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
| commit | 36e00caf4dc70905b735531c0d5634addd026954 (patch) | |
| tree | 01d3bbb3b7f1ab522f9a1fc651f48197ce355927 /examples/boot/bootloader | |
| parent | c2aca45b8d3785007da20ce007d6a6e352fac1a0 (diff) | |
Align examples
Diffstat (limited to 'examples/boot/bootloader')
| -rw-r--r-- | examples/boot/bootloader/nrf/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/nrf/src/main.rs | 21 | ||||
| -rw-r--r-- | examples/boot/bootloader/rp/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/rp/src/main.rs | 16 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32/src/main.rs | 19 |
6 files changed, 40 insertions, 19 deletions
diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index 8c2fb4c5f..40656f359 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml | |||
| @@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] } | 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] } |
| 13 | embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } | 13 | embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 15 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
| 16 | cfg-if = "1.0.0" | 17 | cfg-if = "1.0.0" |
| 17 | 18 | ||
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 8818a23b8..72c95c02a 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -1,12 +1,15 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_nrf::*; | 9 | use embassy_boot_nrf::*; |
| 8 | use embassy_nrf::nvmc::Nvmc; | 10 | use embassy_nrf::nvmc::Nvmc; |
| 9 | use embassy_nrf::wdt; | 11 | use embassy_nrf::wdt; |
| 12 | use embassy_sync::blocking_mutex::Mutex; | ||
| 10 | 13 | ||
| 11 | #[entry] | 14 | #[entry] |
| 12 | fn main() -> ! { | 15 | fn main() -> ! { |
| @@ -20,19 +23,21 @@ fn main() -> ! { | |||
| 20 | } | 23 | } |
| 21 | */ | 24 | */ |
| 22 | 25 | ||
| 23 | let mut bl = BootLoader::default(); | ||
| 24 | |||
| 25 | let mut wdt_config = wdt::Config::default(); | 26 | let mut wdt_config = wdt::Config::default(); |
| 26 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds | 27 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds |
| 27 | wdt_config.run_during_sleep = true; | 28 | wdt_config.run_during_sleep = true; |
| 28 | wdt_config.run_during_debug_halt = false; | 29 | wdt_config.run_during_debug_halt = false; |
| 29 | 30 | ||
| 30 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::new(WatchdogFlash::start( | 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); |
| 31 | Nvmc::new(p.NVMC), | 32 | let flash = Mutex::new(RefCell::new(flash)); |
| 32 | p.WDT, | 33 | |
| 33 | wdt_config, | 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 34 | )))); | 35 | let active_offset = config.active.offset(); |
| 35 | unsafe { bl.load(start) } | 36 | let mut bl: BootLoader<_, _, _> = BootLoader::new(config); |
| 37 | |||
| 38 | bl.prepare(); | ||
| 39 | |||
| 40 | unsafe { bl.load(active_offset) } | ||
| 36 | } | 41 | } |
| 37 | 42 | ||
| 38 | #[no_mangle] | 43 | #[no_mangle] |
diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index bf9226993..8d60f18be 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml | |||
| @@ -11,6 +11,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 11 | 11 | ||
| 12 | embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] } | 12 | embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] } |
| 13 | embassy-boot-rp = { path = "../../../../embassy-boot/rp" } | 13 | embassy-boot-rp = { path = "../../../../embassy-boot/rp" } |
| 14 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 14 | embassy-time = { path = "../../../../embassy-time", features = ["nightly"] } | 15 | embassy-time = { path = "../../../../embassy-time", features = ["nightly"] } |
| 15 | 16 | ||
| 16 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 17 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs index 8129591fa..6a81db804 100644 --- a/examples/boot/bootloader/rp/src/main.rs +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_rp::*; | 9 | use embassy_boot_rp::*; |
| 10 | use embassy_sync::blocking_mutex::Mutex; | ||
| 8 | use embassy_time::Duration; | 11 | use embassy_time::Duration; |
| 9 | 12 | ||
| 10 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | 13 | const FLASH_SIZE: usize = 2 * 1024 * 1024; |
| @@ -21,13 +24,16 @@ fn main() -> ! { | |||
| 21 | } | 24 | } |
| 22 | */ | 25 | */ |
| 23 | 26 | ||
| 24 | let mut bl: BootLoader = BootLoader::default(); | ||
| 25 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); | 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); |
| 26 | let mut flash = BootFlash::new(flash); | 28 | let flash = Mutex::new(RefCell::new(flash)); |
| 27 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); | 29 | |
| 28 | core::mem::drop(flash); | 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 31 | let active_offset = config.active.offset(); | ||
| 32 | let mut bl: BootLoader<_, _, _> = BootLoader::new(config); | ||
| 33 | |||
| 34 | bl.prepare(); | ||
| 29 | 35 | ||
| 30 | unsafe { bl.load(start) } | 36 | unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) } |
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | #[no_mangle] | 39 | #[no_mangle] |
diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index fbc80b34c..6436f2fee 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml | |||
| @@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] } | 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } | 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 15 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
| 16 | embedded-storage = "0.3.0" | 17 | embedded-storage = "0.3.0" |
| 17 | embedded-storage-async = "0.4.0" | 18 | embedded-storage-async = "0.4.0" |
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index f81fdbc5f..262eed200 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -1,11 +1,14 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_stm32::*; | 9 | use embassy_boot_stm32::*; |
| 8 | use embassy_stm32::flash::Flash; | 10 | use embassy_stm32::flash::{Flash, BANK1_REGION}; |
| 11 | use embassy_sync::blocking_mutex::Mutex; | ||
| 9 | 12 | ||
| 10 | #[entry] | 13 | #[entry] |
| 11 | fn main() -> ! { | 14 | fn main() -> ! { |
| @@ -19,12 +22,16 @@ fn main() -> ! { | |||
| 19 | } | 22 | } |
| 20 | */ | 23 | */ |
| 21 | 24 | ||
| 22 | let mut bl: BootLoader<2048> = BootLoader::default(); | ||
| 23 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); |
| 24 | let mut flash = BootFlash::new(layout.bank1_region); | 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); |
| 25 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); | 27 | |
| 26 | core::mem::drop(flash); | 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 27 | unsafe { bl.load(start) } | 29 | let active_offset = config.active.offset(); |
| 30 | let mut bl: BootLoader<_, _, _, 2048> = BootLoader::new(config); | ||
| 31 | |||
| 32 | bl.prepare(); | ||
| 33 | |||
| 34 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | #[no_mangle] | 37 | #[no_mangle] |
