diff options
| author | Mehmet Ali Anil <[email protected]> | 2023-03-07 10:46:59 +0100 |
|---|---|---|
| committer | Mehmet Ali Anil <[email protected]> | 2023-03-07 23:16:54 +0100 |
| commit | 935633c90b817b15c6c2cf180e107992ad5dd9a6 (patch) | |
| tree | 5e4c33aa5992a7eb941a0920b0c080a624cd15a5 /embassy-boot | |
| parent | bc0cb43307c2a46330ce253505203dbc607bcc6c (diff) | |
| parent | 18fe398673f55b07159d01a230910bb9689c1525 (diff) | |
Merge upstream
Diffstat (limited to 'embassy-boot')
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index b5dad5046..4dd1ebe06 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #![feature(type_alias_impl_trait)] | 1 | #![feature(async_fn_in_trait)] |
| 2 | #![allow(incomplete_features)] | ||
| 2 | #![no_std] | 3 | #![no_std] |
| 3 | #![warn(missing_docs)] | 4 | #![warn(missing_docs)] |
| 4 | #![doc = include_str!("../README.md")] | 5 | #![doc = include_str!("../README.md")] |
| @@ -1196,8 +1197,6 @@ impl FirmwareWriter { | |||
| 1196 | #[cfg(test)] | 1197 | #[cfg(test)] |
| 1197 | mod tests { | 1198 | mod tests { |
| 1198 | use core::convert::Infallible; | 1199 | use core::convert::Infallible; |
| 1199 | use core::future::Future; | ||
| 1200 | |||
| 1201 | use embedded_storage::nor_flash::ErrorType; | 1200 | use embedded_storage::nor_flash::ErrorType; |
| 1202 | use embedded_storage_async::nor_flash::ReadNorFlash as AsyncReadNorFlash; | 1201 | use embedded_storage_async::nor_flash::ReadNorFlash as AsyncReadNorFlash; |
| 1203 | use futures::executor::block_on; | 1202 | use futures::executor::block_on; |
| @@ -1424,7 +1423,7 @@ mod tests { | |||
| 1424 | } | 1423 | } |
| 1425 | 1424 | ||
| 1426 | #[test] | 1425 | #[test] |
| 1427 | #[cfg(feature = "_verify")] | 1426 | #[cfg(feature="_verify")] |
| 1428 | fn test_verify() { | 1427 | fn test_verify() { |
| 1429 | // The following key setup is based on: | 1428 | // The following key setup is based on: |
| 1430 | // https://docs.rs/ed25519-dalek/latest/ed25519_dalek/#example | 1429 | // https://docs.rs/ed25519-dalek/latest/ed25519_dalek/#example |
| @@ -1535,13 +1534,10 @@ mod tests { | |||
| 1535 | { | 1534 | { |
| 1536 | const READ_SIZE: usize = 1; | 1535 | const READ_SIZE: usize = 1; |
| 1537 | 1536 | ||
| 1538 | type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a; | 1537 | async fn read(&mut self, offset: u32, buf: &mut [u8]) -> Result<(), Self::Error> { |
| 1539 | fn read<'a>(&'a mut self, offset: u32, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { | ||
| 1540 | async move { | ||
| 1541 | let len = buf.len(); | 1538 | let len = buf.len(); |
| 1542 | buf[..].copy_from_slice(&self.0[offset as usize..offset as usize + len]); | 1539 | buf[..].copy_from_slice(&self.0[offset as usize..offset as usize + len]); |
| 1543 | Ok(()) | 1540 | Ok(()) |
| 1544 | } | ||
| 1545 | } | 1541 | } |
| 1546 | 1542 | ||
| 1547 | fn capacity(&self) -> usize { | 1543 | fn capacity(&self) -> usize { |
| @@ -1555,38 +1551,32 @@ mod tests { | |||
| 1555 | const WRITE_SIZE: usize = WRITE_SIZE; | 1551 | const WRITE_SIZE: usize = WRITE_SIZE; |
| 1556 | const ERASE_SIZE: usize = ERASE_SIZE; | 1552 | const ERASE_SIZE: usize = ERASE_SIZE; |
| 1557 | 1553 | ||
| 1558 | type EraseFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a; | 1554 | async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 1559 | fn erase(&mut self, from: u32, to: u32) -> Self::EraseFuture<'_> { | 1555 | let from = from as usize; |
| 1560 | async move { | 1556 | let to = to as usize; |
| 1561 | let from = from as usize; | 1557 | assert!(from % ERASE_SIZE == 0); |
| 1562 | let to = to as usize; | 1558 | assert!(to % ERASE_SIZE == 0); |
| 1563 | assert!(from % ERASE_SIZE == 0); | 1559 | for i in from..to { |
| 1564 | assert!(to % ERASE_SIZE == 0); | 1560 | self.0[i] = 0xFF; |
| 1565 | for i in from..to { | ||
| 1566 | self.0[i] = 0xFF; | ||
| 1567 | } | ||
| 1568 | Ok(()) | ||
| 1569 | } | 1561 | } |
| 1562 | Ok(()) | ||
| 1570 | } | 1563 | } |
| 1571 | 1564 | ||
| 1572 | type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a; | 1565 | async fn write(&mut self, offset: u32, data: &[u8]) -> Result<(), Self::Error> { |
| 1573 | fn write<'a>(&'a mut self, offset: u32, data: &'a [u8]) -> Self::WriteFuture<'a> { | ||
| 1574 | info!("Writing {} bytes to 0x{:x}", data.len(), offset); | 1566 | info!("Writing {} bytes to 0x{:x}", data.len(), offset); |
| 1575 | async move { | 1567 | assert!(data.len() % WRITE_SIZE == 0); |
| 1576 | assert!(data.len() % WRITE_SIZE == 0); | 1568 | assert!(offset as usize % WRITE_SIZE == 0); |
| 1577 | assert!(offset as usize % WRITE_SIZE == 0); | 1569 | assert!( |
| 1578 | assert!( | 1570 | offset as usize + data.len() <= SIZE, |
| 1579 | offset as usize + data.len() <= SIZE, | 1571 | "OFFSET: {}, LEN: {}, FLASH SIZE: {}", |
| 1580 | "OFFSET: {}, LEN: {}, FLASH SIZE: {}", | 1572 | offset, |
| 1581 | offset, | 1573 | data.len(), |
| 1582 | data.len(), | 1574 | SIZE |
| 1583 | SIZE | 1575 | ); |
| 1584 | ); | ||
| 1585 | |||
| 1586 | self.0[offset as usize..offset as usize + data.len()].copy_from_slice(data); | ||
| 1587 | 1576 | ||
| 1588 | Ok(()) | 1577 | self.0[offset as usize..offset as usize + data.len()].copy_from_slice(data); |
| 1589 | } | 1578 | |
| 1579 | Ok(()) | ||
| 1590 | } | 1580 | } |
| 1591 | } | 1581 | } |
| 1592 | } | 1582 | } |
