From 932924ea8586d56cadca113035ca2c0f6a09d4a0 Mon Sep 17 00:00:00 2001 From: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com> Date: Mon, 29 Aug 2022 12:05:58 +0200 Subject: [PATCH] removes metadata storage type (#538) --- .../nordic/nrf52840_dongle_opensk/src/main.rs | 4 +-- boards/nordic/nrf52840_mdk_dfu/src/main.rs | 4 +-- boards/nordic/nrf52840dk_opensk/build.rs | 4 +-- boards/nordic/nrf52840dk_opensk_a/build.rs | 18 +++++------ boards/nordic/nrf52840dk_opensk_b/build.rs | 18 +++++------ patches/tock/06-upgrade-partitions.patch | 9 +++--- .../09-add-vendor-hid-usb-interface.patch | 2 +- patches/tock/10-avoid-app-reentry.patch | 2 +- .../11-connect-vendor-hid-usb-interface.patch | 2 +- src/env/tock/storage.rs | 30 ++++++++----------- 10 files changed, 43 insertions(+), 50 deletions(-) diff --git a/boards/nordic/nrf52840_dongle_opensk/src/main.rs b/boards/nordic/nrf52840_dongle_opensk/src/main.rs index 63ad6df..a71f3ec 100644 --- a/boards/nordic/nrf52840_dongle_opensk/src/main.rs +++ b/boards/nordic/nrf52840_dongle_opensk/src/main.rs @@ -69,12 +69,12 @@ static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [ kernel::StorageLocation { address: 0xC0000, size: 0x10000, // 16 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, kernel::StorageLocation { address: 0xD0000, size: 0x4000, // 4 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, ]; diff --git a/boards/nordic/nrf52840_mdk_dfu/src/main.rs b/boards/nordic/nrf52840_mdk_dfu/src/main.rs index 29926f8..f3d2922 100644 --- a/boards/nordic/nrf52840_mdk_dfu/src/main.rs +++ b/boards/nordic/nrf52840_mdk_dfu/src/main.rs @@ -63,12 +63,12 @@ static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [ kernel::StorageLocation { address: 0xC0000, size: 0x10000, // 16 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, kernel::StorageLocation { address: 0xD0000, size: 0x4000, // 4 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, ]; diff --git a/boards/nordic/nrf52840dk_opensk/build.rs b/boards/nordic/nrf52840dk_opensk/build.rs index e872190..7207fab 100644 --- a/boards/nordic/nrf52840dk_opensk/build.rs +++ b/boards/nordic/nrf52840dk_opensk/build.rs @@ -16,12 +16,12 @@ static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [ kernel::StorageLocation { address: 0xC0000, size: 0x10000, // 16 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, kernel::StorageLocation { address: 0xD0000, size: 0x4000, // 4 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, ]; " diff --git a/boards/nordic/nrf52840dk_opensk_a/build.rs b/boards/nordic/nrf52840dk_opensk_a/build.rs index 25935d6..d30899a 100644 --- a/boards/nordic/nrf52840dk_opensk_a/build.rs +++ b/boards/nordic/nrf52840dk_opensk_a/build.rs @@ -16,28 +16,28 @@ static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 5] = [ kernel::StorageLocation { address: 0xC0000, size: 0x10000, // 16 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, kernel::StorageLocation { address: 0xD0000, size: 0x4000, // 4 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, // Partitions can also be split to maximize MPU happiness. + kernel::StorageLocation { + address: 0x5000, + size: 0x1000, + storage_type: kernel::StorageType::Partition, + }, kernel::StorageLocation { address: 0x60000, size: 0x20000, - storage_type: kernel::StorageType::PARTITION, + storage_type: kernel::StorageType::Partition, }, kernel::StorageLocation { address: 0x80000, size: 0x20000, - storage_type: kernel::StorageType::PARTITION, - }, - kernel::StorageLocation { - address: 0x5000, - size: 0x1000, - storage_type: kernel::StorageType::METADATA, + storage_type: kernel::StorageType::Partition, }, ]; " diff --git a/boards/nordic/nrf52840dk_opensk_b/build.rs b/boards/nordic/nrf52840dk_opensk_b/build.rs index ee44cb1..400b25b 100644 --- a/boards/nordic/nrf52840dk_opensk_b/build.rs +++ b/boards/nordic/nrf52840dk_opensk_b/build.rs @@ -16,28 +16,28 @@ static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 5] = [ kernel::StorageLocation { address: 0xC0000, size: 0x10000, // 16 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, kernel::StorageLocation { address: 0xD0000, size: 0x4000, // 4 pages - storage_type: kernel::StorageType::STORE, + storage_type: kernel::StorageType::Store, }, // Partitions can also be split to maximize MPU happiness. + kernel::StorageLocation { + address: 0x4000, + size: 0x1000, + storage_type: kernel::StorageType::Partition, + }, kernel::StorageLocation { address: 0x20000, size: 0x20000, - storage_type: kernel::StorageType::PARTITION, + storage_type: kernel::StorageType::Partition, }, kernel::StorageLocation { address: 0x40000, size: 0x20000, - storage_type: kernel::StorageType::PARTITION, - }, - kernel::StorageLocation { - address: 0x4000, - size: 0x1000, - storage_type: kernel::StorageType::METADATA, + storage_type: kernel::StorageType::Partition, }, ]; " diff --git a/patches/tock/06-upgrade-partitions.patch b/patches/tock/06-upgrade-partitions.patch index d94e835..41367f0 100644 --- a/patches/tock/06-upgrade-partitions.patch +++ b/patches/tock/06-upgrade-partitions.patch @@ -31,19 +31,18 @@ index 5465c95f4..e596648f7 100644 } } diff --git a/kernel/src/sched.rs b/kernel/src/sched.rs -index 8844bc6c3..692bad2d3 100644 +index 8844bc6c3..00c13a7c6 100644 --- a/kernel/src/sched.rs +++ b/kernel/src/sched.rs -@@ -118,10 +118,19 @@ pub enum SchedulingDecision { +@@ -118,10 +118,18 @@ pub enum SchedulingDecision { TrySleep, } +/// Represents the type of a storage slice. +#[derive(Copy, Clone)] +pub enum StorageType { -+ STORE = 1, -+ PARTITION = 2, -+ METADATA = 3, ++ Store = 1, ++ Partition = 2, +} + /// Represents a storage location in flash. diff --git a/patches/tock/09-add-vendor-hid-usb-interface.patch b/patches/tock/09-add-vendor-hid-usb-interface.patch index d04b790..2681b07 100644 --- a/patches/tock/09-add-vendor-hid-usb-interface.patch +++ b/patches/tock/09-add-vendor-hid-usb-interface.patch @@ -156,7 +156,7 @@ index f7899d8c5..6956523c6 100644 hil::usb::CtrlSetupResult::ErrGeneric } diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs -index 642039120..adb7fde14 100644 +index 642039120..abf224f97 100644 --- a/capsules/src/usb/usbc_ctap_hid.rs +++ b/capsules/src/usb/usbc_ctap_hid.rs @@ -44,21 +44,59 @@ static CTAP_REPORT_DESCRIPTOR: &'static [u8] = &[ diff --git a/patches/tock/10-avoid-app-reentry.patch b/patches/tock/10-avoid-app-reentry.patch index c8b5136..fdf3132 100644 --- a/patches/tock/10-avoid-app-reentry.patch +++ b/patches/tock/10-avoid-app-reentry.patch @@ -262,7 +262,7 @@ index da3d16d85..e8f1a87a4 100644 if !app.waiting { // The call to receive_packet() collected a pending packet. diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs -index adb7fde14..f6762b4b9 100644 +index abf224f97..d47e5f644 100644 --- a/capsules/src/usb/usbc_ctap_hid.rs +++ b/capsules/src/usb/usbc_ctap_hid.rs @@ -11,6 +11,7 @@ use super::descriptors::HIDSubordinateDescriptor; diff --git a/patches/tock/11-connect-vendor-hid-usb-interface.patch b/patches/tock/11-connect-vendor-hid-usb-interface.patch index b8ed84f..d18d0b0 100644 --- a/patches/tock/11-connect-vendor-hid-usb-interface.patch +++ b/patches/tock/11-connect-vendor-hid-usb-interface.patch @@ -108,7 +108,7 @@ index e8f1a87a4..2c91c0968 100644 } else { // Cannot cancel now because the transaction is already in process. diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs -index f6762b4b9..16b80cb10 100644 +index d47e5f644..76f6af73b 100644 --- a/capsules/src/usb/usbc_ctap_hid.rs +++ b/capsules/src/usb/usbc_ctap_hid.rs @@ -18,13 +18,27 @@ use core::cell::Cell; diff --git a/src/env/tock/storage.rs b/src/env/tock/storage.rs index c2a5f03..9c28459 100644 --- a/src/env/tock/storage.rs +++ b/src/env/tock/storage.rs @@ -52,7 +52,6 @@ mod memop_nr { mod storage_type { pub const STORE: usize = 1; pub const PARTITION: usize = 2; - pub const METADATA: usize = 3; } fn get_info(nr: usize, arg: usize) -> StorageResult { @@ -225,6 +224,9 @@ pub struct TockUpgradeStorage { } impl TockUpgradeStorage { + const METADATA_ADDRESS_A: usize = 0x4000; + const METADATA_ADDRESS_B: usize = 0x5000; + /// Provides access to the other upgrade partition and metadata if available. /// /// The implementation assumes that storage locations returned by the kernel through @@ -250,9 +252,8 @@ impl TockUpgradeStorage { } for i in 0..memop(memop_nr::STORAGE_CNT, 0)? { let storage_type = memop(memop_nr::STORAGE_TYPE, i)?; - match storage_type { - storage_type::PARTITION | storage_type::METADATA => (), - _ => continue, + if !matches!(storage_type, storage_type::PARTITION) { + continue; }; let storage_ptr = memop(memop_nr::STORAGE_PTR, i)?; let storage_len = memop(memop_nr::STORAGE_LEN, i)?; @@ -260,27 +261,20 @@ impl TockUpgradeStorage { return Err(StorageError::CustomError); } let range = ModRange::new(storage_ptr, storage_len); - match storage_type { - storage_type::PARTITION => { + match range.start() { + Self::METADATA_ADDRESS_A | Self::METADATA_ADDRESS_B => locations.metadata = range, + _ => { locations.partition = locations .partition .append(range) .ok_or(StorageError::NotAligned)? } - storage_type::METADATA => { - locations.metadata = locations - .metadata - .append(range) - .ok_or(StorageError::NotAligned)? - } - _ => (), - }; + } } - if locations.partition.is_empty() || locations.metadata.is_empty() { - Err(StorageError::CustomError) - } else { - Ok(locations) + if locations.partition.is_empty() { + return Err(StorageError::CustomError); } + Ok(locations) } fn is_page_aligned(&self, x: usize) -> bool {