Revert the MPU hack by splitting the store in 2

This commit is contained in:
Julien Cretin
2021-09-15 19:36:35 +02:00
committed by Julien Cretin
parent 596b47886c
commit 18ba4368e4
4 changed files with 62 additions and 42 deletions

View File

@@ -64,11 +64,19 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS]; [None; NUM_PROCS];
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [
address: 0xC0000, // We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
size: 0x14000, // NUM_PAGES = 20 kernel::StorageLocation {
storage_type: kernel::StorageType::STORE, address: 0xC0000,
}]; size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
];
// Static reference to chip for panic dumps // Static reference to chip for panic dumps
static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None; static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;

View File

@@ -58,11 +58,19 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS]; [None; NUM_PROCS];
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [
address: 0xC0000, // We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
size: 0x14000, // NUM_PAGES = 20 kernel::StorageLocation {
storage_type: kernel::StorageType::STORE, address: 0xC0000,
}]; size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
];
// Static reference to chip for panic dumps // Static reference to chip for panic dumps
static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None; static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;

View File

@@ -128,11 +128,19 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS]; [None; NUM_PROCS];
static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 2] = [
address: 0xC0000, // We implement NUM_PAGES = 20 as 16 + 4 to satisfy the MPU.
size: 0x14000, // NUM_PAGES = 20 kernel::StorageLocation {
storage_type: kernel::StorageType::STORE, address: 0xC0000,
}]; size: 0x10000, // 16 pages
storage_type: kernel::StorageType::STORE,
},
kernel::StorageLocation {
address: 0xD0000,
size: 0x4000, // 4 pages
storage_type: kernel::StorageType::STORE,
},
];
static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None; static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;

View File

@@ -349,7 +349,7 @@ index 348c746a5..5465c95f4 100644
} }
} }
diff --git a/kernel/src/process.rs b/kernel/src/process.rs diff --git a/kernel/src/process.rs b/kernel/src/process.rs
index c52754be3..f5c833ea7 100644 index c52754be3..ae6a58341 100644
--- a/kernel/src/process.rs --- a/kernel/src/process.rs
+++ b/kernel/src/process.rs +++ b/kernel/src/process.rs
@@ -359,6 +359,15 @@ pub trait ProcessType { @@ -359,6 +359,15 @@ pub trait ProcessType {
@@ -404,37 +404,33 @@ index c52754be3..f5c833ea7 100644
fn update_stack_start_pointer(&self, stack_pointer: *const u8) { fn update_stack_start_pointer(&self, stack_pointer: *const u8) {
if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() { if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() {
self.debug.map(|debug| { self.debug.map(|debug| {
@@ -1751,6 +1789,37 @@ impl<C: 'static + Chip> Process<'_, C> { @@ -1751,6 +1789,33 @@ impl<C: 'static + Chip> Process<'_, C> {
return Err(ProcessLoadError::MpuInvalidFlashLength); return Err(ProcessLoadError::MpuInvalidFlashLength);
} }
+ // Allocate MPU region for the storage locations. The storage locations are currently + // Allocate MPU region for the storage locations. The storage locations are currently
+ // readable by all processes due to lack of stable app id. + // readable by all processes due to lack of stable app id.
+ 'storage_location: for storage_location in kernel.storage_locations() { + for storage_location in kernel.storage_locations() {
+ // We work around MPU limitations on Nordic by also trying unallocated_size = 0x40000. + if chip
+ // Note that just using the next power of 2 doesn't work. + .mpu()
+ for &unallocated_size in &[storage_location.size, 0x40000] { + .allocate_region(
+ if chip + storage_location.address as *const u8,
+ .mpu() + storage_location.size,
+ .allocate_region( + storage_location.size,
+ storage_location.address as *const u8, + mpu::Permissions::ReadOnly,
+ unallocated_size, + &mut mpu_config,
+ storage_location.size, + )
+ mpu::Permissions::ReadOnly, + .is_some()
+ &mut mpu_config, + {
+ ) + continue;
+ .is_some() + }
+ { + if config::CONFIG.debug_load_processes {
+ continue 'storage_location; + debug!(
+ } + "[!] flash=[{:#010X}:{:#010X}] process={:?} - couldn't allocate flash region",
+ if config::CONFIG.debug_load_processes { + storage_location.address,
+ debug!( + storage_location.address + storage_location.size,
+ "[!] flash=[{:#010X}:{:#010X}] process={:?} - couldn't allocate flash region", + process_name
+ storage_location.address, + );
+ storage_location.address + unallocated_size,
+ process_name
+ );
+ }
+ } + }
+ return Ok((None, remaining_memory)); + return Ok((None, remaining_memory));
+ } + }