diff options
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 24 | ||||
| -rw-r--r-- | examples/boot/bootloader/nrf/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32/src/main.rs | 7 |
3 files changed, 16 insertions, 17 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 4a2b112a9..015dd58db 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -447,24 +447,24 @@ where | |||
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | /// A flash wrapper implementing the Flash and embedded_storage traits. | 449 | /// A flash wrapper implementing the Flash and embedded_storage traits. |
| 450 | pub struct BootFlash<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8 = 0xFF> | 450 | pub struct BootFlash<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8 = 0xFF> |
| 451 | where | 451 | where |
| 452 | F: NorFlash + ReadNorFlash, | 452 | F: NorFlash + ReadNorFlash, |
| 453 | { | 453 | { |
| 454 | flash: &'a mut F, | 454 | flash: F, |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE> | 457 | impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> BootFlash<F, BLOCK_SIZE, ERASE_VALUE> |
| 458 | where | 458 | where |
| 459 | F: NorFlash + ReadNorFlash, | 459 | F: NorFlash + ReadNorFlash, |
| 460 | { | 460 | { |
| 461 | /// Create a new instance of a bootable flash | 461 | /// Create a new instance of a bootable flash |
| 462 | pub fn new(flash: &'a mut F) -> Self { | 462 | pub fn new(flash: F) -> Self { |
| 463 | Self { flash } | 463 | Self { flash } |
| 464 | } | 464 | } |
| 465 | } | 465 | } |
| 466 | 466 | ||
| 467 | impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> Flash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE> | 467 | impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> Flash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE> |
| 468 | where | 468 | where |
| 469 | F: NorFlash + ReadNorFlash, | 469 | F: NorFlash + ReadNorFlash, |
| 470 | { | 470 | { |
| @@ -472,14 +472,14 @@ where | |||
| 472 | const ERASE_VALUE: u8 = ERASE_VALUE; | 472 | const ERASE_VALUE: u8 = ERASE_VALUE; |
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ErrorType for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE> | 475 | impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ErrorType for BootFlash<F, BLOCK_SIZE, ERASE_VALUE> |
| 476 | where | 476 | where |
| 477 | F: ReadNorFlash + NorFlash, | 477 | F: ReadNorFlash + NorFlash, |
| 478 | { | 478 | { |
| 479 | type Error = F::Error; | 479 | type Error = F::Error; |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> NorFlash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE> | 482 | impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> NorFlash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE> |
| 483 | where | 483 | where |
| 484 | F: ReadNorFlash + NorFlash, | 484 | F: ReadNorFlash + NorFlash, |
| 485 | { | 485 | { |
| @@ -487,26 +487,26 @@ where | |||
| 487 | const ERASE_SIZE: usize = F::ERASE_SIZE; | 487 | const ERASE_SIZE: usize = F::ERASE_SIZE; |
| 488 | 488 | ||
| 489 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | 489 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 490 | F::erase(self.flash, from, to) | 490 | F::erase(&mut self.flash, from, to) |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | 493 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { |
| 494 | F::write(self.flash, offset, bytes) | 494 | F::write(&mut self.flash, offset, bytes) |
| 495 | } | 495 | } |
| 496 | } | 496 | } |
| 497 | 497 | ||
| 498 | impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ReadNorFlash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE> | 498 | impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ReadNorFlash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE> |
| 499 | where | 499 | where |
| 500 | F: ReadNorFlash + NorFlash, | 500 | F: ReadNorFlash + NorFlash, |
| 501 | { | 501 | { |
| 502 | const READ_SIZE: usize = F::READ_SIZE; | 502 | const READ_SIZE: usize = F::READ_SIZE; |
| 503 | 503 | ||
| 504 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | 504 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { |
| 505 | F::read(self.flash, offset, bytes) | 505 | F::read(&mut self.flash, offset, bytes) |
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | fn capacity(&self) -> usize { | 508 | fn capacity(&self) -> usize { |
| 509 | F::capacity(self.flash) | 509 | F::capacity(&self.flash) |
| 510 | } | 510 | } |
| 511 | } | 511 | } |
| 512 | 512 | ||
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 9031997c2..8266206b3 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -21,7 +21,7 @@ fn main() -> ! { | |||
| 21 | 21 | ||
| 22 | let mut bl = BootLoader::default(); | 22 | let mut bl = BootLoader::default(); |
| 23 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::<_, 4096>::new( | 23 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::<_, 4096>::new( |
| 24 | &mut WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5), | 24 | WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5), |
| 25 | ))); | 25 | ))); |
| 26 | unsafe { bl.load(start) } | 26 | unsafe { bl.load(start) } |
| 27 | } | 27 | } |
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index bb5d3e531..294464d1c 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -20,10 +20,9 @@ fn main() -> ! { | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | let mut bl: BootLoader<ERASE_SIZE, WRITE_SIZE> = BootLoader::default(); | 22 | let mut bl: BootLoader<ERASE_SIZE, WRITE_SIZE> = BootLoader::default(); |
| 23 | let mut flash = Flash::unlock(p.FLASH); | 23 | let flash = Flash::unlock(p.FLASH); |
| 24 | let start = bl.prepare(&mut SingleFlashConfig::new( | 24 | let mut flash = BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(flash); |
| 25 | &mut BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(&mut flash), | 25 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); |
| 26 | )); | ||
| 27 | core::mem::drop(flash); | 26 | core::mem::drop(flash); |
| 28 | unsafe { bl.load(start) } | 27 | unsafe { bl.load(start) } |
| 29 | } | 28 | } |
