diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:15:44 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:22:31 +0200 |
| commit | a8703b75988e1e700af701116464025679d2feb8 (patch) | |
| tree | f4ec5de70ec05e793a774049e010935ac45853ed /embassy-boot/boot/src/lib.rs | |
| parent | 6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff) | |
Run rustfmt.
Diffstat (limited to 'embassy-boot/boot/src/lib.rs')
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 87bb973a7..b18c88a6b 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -202,8 +202,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 202 | // Ensure we have enough progress pages to store copy progress | 202 | // Ensure we have enough progress pages to store copy progress |
| 203 | assert!( | 203 | assert!( |
| 204 | self.active.len() / PAGE_SIZE | 204 | self.active.len() / PAGE_SIZE |
| 205 | <= (self.state.len() | 205 | <= (self.state.len() - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE) |
| 206 | - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE) | ||
| 207 | / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE | 206 | / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE |
| 208 | ); | 207 | ); |
| 209 | 208 | ||
| @@ -226,15 +225,12 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 226 | // Overwrite magic and reset progress | 225 | // Overwrite magic and reset progress |
| 227 | let fstate = p.state().flash(); | 226 | let fstate = p.state().flash(); |
| 228 | let aligned = Aligned( | 227 | let aligned = Aligned( |
| 229 | [!P::STATE::ERASE_VALUE; | 228 | [!P::STATE::ERASE_VALUE; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], |
| 230 | <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], | ||
| 231 | ); | 229 | ); |
| 232 | fstate.write(self.state.from as u32, &aligned.0)?; | 230 | fstate.write(self.state.from as u32, &aligned.0)?; |
| 233 | fstate.erase(self.state.from as u32, self.state.to as u32)?; | 231 | fstate.erase(self.state.from as u32, self.state.to as u32)?; |
| 234 | let aligned = Aligned( | 232 | let aligned = |
| 235 | [BOOT_MAGIC; | 233 | Aligned([BOOT_MAGIC; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE]); |
| 236 | <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE], | ||
| 237 | ); | ||
| 238 | fstate.write(self.state.from as u32, &aligned.0)?; | 234 | fstate.write(self.state.from as u32, &aligned.0)?; |
| 239 | } | 235 | } |
| 240 | } | 236 | } |
| @@ -262,10 +258,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 262 | let flash = p.flash(); | 258 | let flash = p.flash(); |
| 263 | let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); | 259 | let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); |
| 264 | for i in 0..max_index { | 260 | for i in 0..max_index { |
| 265 | flash.read( | 261 | flash.read((self.state.from + write_size + i * write_size) as u32, &mut aligned.0)?; |
| 266 | (self.state.from + write_size + i * write_size) as u32, | ||
| 267 | &mut aligned.0, | ||
| 268 | )?; | ||
| 269 | if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { | 262 | if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { |
| 270 | return Ok(i); | 263 | return Ok(i); |
| 271 | } | 264 | } |
| @@ -311,9 +304,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 311 | offset += chunk.len(); | 304 | offset += chunk.len(); |
| 312 | } | 305 | } |
| 313 | 306 | ||
| 314 | p.active() | 307 | p.active().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; |
| 315 | .flash() | ||
| 316 | .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; | ||
| 317 | 308 | ||
| 318 | let mut offset = to_page; | 309 | let mut offset = to_page; |
| 319 | for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { | 310 | for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { |
| @@ -343,9 +334,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { | |||
| 343 | offset += chunk.len(); | 334 | offset += chunk.len(); |
| 344 | } | 335 | } |
| 345 | 336 | ||
| 346 | p.dfu() | 337 | p.dfu().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; |
| 347 | .flash() | ||
| 348 | .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; | ||
| 349 | 338 | ||
| 350 | let mut offset = to_page; | 339 | let mut offset = to_page; |
| 351 | for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { | 340 | for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { |
| @@ -609,9 +598,7 @@ impl FirmwareUpdater { | |||
| 609 | aligned[i] = 0; | 598 | aligned[i] = 0; |
| 610 | } | 599 | } |
| 611 | flash.write(self.state.from as u32, aligned).await?; | 600 | flash.write(self.state.from as u32, aligned).await?; |
| 612 | flash | 601 | flash.erase(self.state.from as u32, self.state.to as u32).await?; |
| 613 | .erase(self.state.from as u32, self.state.to as u32) | ||
| 614 | .await?; | ||
| 615 | 602 | ||
| 616 | for i in 0..aligned.len() { | 603 | for i in 0..aligned.len() { |
| 617 | aligned[i] = magic; | 604 | aligned[i] = magic; |
| @@ -677,13 +664,15 @@ impl FirmwareUpdater { | |||
| 677 | 664 | ||
| 678 | #[cfg(test)] | 665 | #[cfg(test)] |
| 679 | mod tests { | 666 | mod tests { |
| 680 | use super::*; | ||
| 681 | use core::convert::Infallible; | 667 | use core::convert::Infallible; |
| 682 | use core::future::Future; | 668 | use core::future::Future; |
| 669 | |||
| 683 | use embedded_storage::nor_flash::ErrorType; | 670 | use embedded_storage::nor_flash::ErrorType; |
| 684 | use embedded_storage_async::nor_flash::AsyncReadNorFlash; | 671 | use embedded_storage_async::nor_flash::AsyncReadNorFlash; |
| 685 | use futures::executor::block_on; | 672 | use futures::executor::block_on; |
| 686 | 673 | ||
| 674 | use super::*; | ||
| 675 | |||
| 687 | /* | 676 | /* |
| 688 | #[test] | 677 | #[test] |
| 689 | fn test_bad_magic() { | 678 | fn test_bad_magic() { |
| @@ -810,11 +799,7 @@ mod tests { | |||
| 810 | assert_eq!( | 799 | assert_eq!( |
| 811 | State::Swap, | 800 | State::Swap, |
| 812 | bootloader | 801 | bootloader |
| 813 | .prepare_boot(&mut MultiFlashProvider::new( | 802 | .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) |
| 814 | &mut active, | ||
| 815 | &mut state, | ||
| 816 | &mut dfu, | ||
| 817 | )) | ||
| 818 | .unwrap() | 803 | .unwrap() |
| 819 | ); | 804 | ); |
| 820 | 805 | ||
| @@ -858,11 +843,7 @@ mod tests { | |||
| 858 | assert_eq!( | 843 | assert_eq!( |
| 859 | State::Swap, | 844 | State::Swap, |
| 860 | bootloader | 845 | bootloader |
| 861 | .prepare_boot(&mut MultiFlashProvider::new( | 846 | .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) |
| 862 | &mut active, | ||
| 863 | &mut state, | ||
| 864 | &mut dfu, | ||
| 865 | )) | ||
| 866 | .unwrap() | 847 | .unwrap() |
| 867 | ); | 848 | ); |
| 868 | 849 | ||
| @@ -876,9 +857,7 @@ mod tests { | |||
| 876 | } | 857 | } |
| 877 | } | 858 | } |
| 878 | 859 | ||
| 879 | struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>( | 860 | struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]); |
| 880 | [u8; SIZE], | ||
| 881 | ); | ||
| 882 | 861 | ||
| 883 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash | 862 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash |
| 884 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> | 863 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> |
| @@ -889,12 +868,7 @@ mod tests { | |||
| 889 | let from = from as usize; | 868 | let from = from as usize; |
| 890 | let to = to as usize; | 869 | let to = to as usize; |
| 891 | assert!(from % ERASE_SIZE == 0); | 870 | assert!(from % ERASE_SIZE == 0); |
| 892 | assert!( | 871 | assert!(to % ERASE_SIZE == 0, "To: {}, erase size: {}", to, ERASE_SIZE); |
| 893 | to % ERASE_SIZE == 0, | ||
| 894 | "To: {}, erase size: {}", | ||
| 895 | to, | ||
| 896 | ERASE_SIZE | ||
| 897 | ); | ||
| 898 | for i in from..to { | 872 | for i in from..to { |
| 899 | self.0[i] = 0xFF; | 873 | self.0[i] = 0xFF; |
| 900 | } | 874 | } |
