diff options
Diffstat (limited to 'embassy-boot/rp/src/lib.rs')
| -rw-r--r-- | embassy-boot/rp/src/lib.rs | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/embassy-boot/rp/src/lib.rs b/embassy-boot/rp/src/lib.rs deleted file mode 100644 index 07a5b3f4d..000000000 --- a/embassy-boot/rp/src/lib.rs +++ /dev/null | |||
| @@ -1,90 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![warn(missing_docs)] | ||
| 3 | #![doc = include_str!("../README.md")] | ||
| 4 | mod fmt; | ||
| 5 | |||
| 6 | pub use embassy_boot::{ | ||
| 7 | AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater, | ||
| 8 | FirmwareUpdaterConfig, State, | ||
| 9 | }; | ||
| 10 | use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE}; | ||
| 11 | use embassy_rp::peripherals::{FLASH, WATCHDOG}; | ||
| 12 | use embassy_rp::watchdog::Watchdog; | ||
| 13 | use embassy_time::Duration; | ||
| 14 | use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; | ||
| 15 | |||
| 16 | /// A bootloader for RP2040 devices. | ||
| 17 | pub struct BootLoader<const BUFFER_SIZE: usize = ERASE_SIZE>; | ||
| 18 | |||
| 19 | impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { | ||
| 20 | /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware | ||
| 21 | pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | ||
| 22 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, | ||
| 23 | ) -> Self { | ||
| 24 | let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); | ||
| 25 | let mut boot = embassy_boot::BootLoader::new(config); | ||
| 26 | boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error"); | ||
| 27 | Self | ||
| 28 | } | ||
| 29 | |||
| 30 | /// Boots the application. | ||
| 31 | /// | ||
| 32 | /// # Safety | ||
| 33 | /// | ||
| 34 | /// This modifies the stack pointer and reset vector and will run code placed in the active partition. | ||
| 35 | pub unsafe fn load(self, start: u32) -> ! { | ||
| 36 | trace!("Loading app at 0x{:x}", start); | ||
| 37 | #[allow(unused_mut)] | ||
| 38 | let mut p = cortex_m::Peripherals::steal(); | ||
| 39 | #[cfg(not(armv6m))] | ||
| 40 | p.SCB.invalidate_icache(); | ||
| 41 | p.SCB.vtor.write(start); | ||
| 42 | |||
| 43 | cortex_m::asm::bootload(start as *const u32) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | /// A flash implementation that will feed a watchdog when touching flash. | ||
| 48 | pub struct WatchdogFlash<'d, const SIZE: usize> { | ||
| 49 | flash: Flash<'d, FLASH, Blocking, SIZE>, | ||
| 50 | watchdog: Watchdog, | ||
| 51 | } | ||
| 52 | |||
| 53 | impl<'d, const SIZE: usize> WatchdogFlash<'d, SIZE> { | ||
| 54 | /// Start a new watchdog with a given flash and watchdog peripheral and a timeout | ||
| 55 | pub fn start(flash: FLASH, watchdog: WATCHDOG, timeout: Duration) -> Self { | ||
| 56 | let flash = Flash::<_, Blocking, SIZE>::new_blocking(flash); | ||
| 57 | let mut watchdog = Watchdog::new(watchdog); | ||
| 58 | watchdog.start(timeout); | ||
| 59 | Self { flash, watchdog } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | impl<'d, const SIZE: usize> ErrorType for WatchdogFlash<'d, SIZE> { | ||
| 64 | type Error = <Flash<'d, FLASH, Blocking, SIZE> as ErrorType>::Error; | ||
| 65 | } | ||
| 66 | |||
| 67 | impl<'d, const SIZE: usize> NorFlash for WatchdogFlash<'d, SIZE> { | ||
| 68 | const WRITE_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as NorFlash>::WRITE_SIZE; | ||
| 69 | const ERASE_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as NorFlash>::ERASE_SIZE; | ||
| 70 | |||
| 71 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | ||
| 72 | self.watchdog.feed(); | ||
| 73 | self.flash.blocking_erase(from, to) | ||
| 74 | } | ||
| 75 | fn write(&mut self, offset: u32, data: &[u8]) -> Result<(), Self::Error> { | ||
| 76 | self.watchdog.feed(); | ||
| 77 | self.flash.blocking_write(offset, data) | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | impl<'d, const SIZE: usize> ReadNorFlash for WatchdogFlash<'d, SIZE> { | ||
| 82 | const READ_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as ReadNorFlash>::READ_SIZE; | ||
| 83 | fn read(&mut self, offset: u32, data: &mut [u8]) -> Result<(), Self::Error> { | ||
| 84 | self.watchdog.feed(); | ||
| 85 | self.flash.blocking_read(offset, data) | ||
| 86 | } | ||
| 87 | fn capacity(&self) -> usize { | ||
| 88 | self.flash.capacity() | ||
| 89 | } | ||
| 90 | } | ||
