Skip to content

Commit

Permalink
Move application flash region into storage volume
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann authored and tyler-potyondy committed May 7, 2024
1 parent d1339ff commit 86987da
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions boards/nordic/nrf52840dk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ pub struct Platform {
kv_driver: &'static KVDriver,
scheduler: &'static RoundRobinSched<'static>,
systick: cortexm4::systick::SysTick,
nonvolatile_storage: &'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
nonvolatile_storage:
&'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
}

impl SyscallDriverLookup for Platform {
Expand All @@ -276,7 +277,9 @@ impl SyscallDriverLookup for Platform {
capsules_core::spi_controller::DRIVER_NUM => f(Some(self.spi_controller)),
capsules_extra::net::thread::driver::DRIVER_NUM => f(Some(self.thread_driver)),
capsules_extra::kv_driver::DRIVER_NUM => f(Some(self.kv_driver)),
capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => f(Some(self.nonvolatile_storage)),
capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => {
f(Some(self.nonvolatile_storage))
}
_ => f(None),
}
}
Expand Down Expand Up @@ -652,33 +655,19 @@ pub unsafe fn start() -> (
//--------------------------------------------------------------------------
// NONVOLATILE STORAGE
//--------------------------------------------------------------------------

// Kernel storage region, allocated with the storage_volume!
// macro in common/utils.rs
extern "C" {
/// Beginning on the ROM region containing app images.
static _sstorage: u8;
static _estorage: u8;
static _etext: u8;
}

// Using the linker script symbols, we define the region we provide
// to the nonvolatile storage capsule to be read and written to. Note
// this region does not possess protection and is readable and writeable
// by all applications.
let rw_app_flash_len = 0x2000;
let rw_app_flash_start_addr = &_etext as *const u8 as usize - rw_app_flash_len;
let kernel_start_addr = &_sstorage as *const u8 as usize;
let kernel_len = &_estorage as *const u8 as usize - &_sstorage as *const u8 as usize;

// 32kB of userspace-accessible storage, page aligned:
kernel::storage_volume!(APP_STORAGE, 32);

let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
board_kernel,
capsules_extra::nonvolatile_storage_driver::DRIVER_NUM,
&nrf52840_peripherals.nrf52.nvmc,
rw_app_flash_start_addr,
rw_app_flash_len,
kernel_start_addr,
kernel_len,
core::ptr::addr_of!(APP_STORAGE) as usize,
APP_STORAGE.len(),
// No kernel-writeable flash:
core::ptr::null::<()>() as usize,
0,
)
.finalize(components::nonvolatile_storage_component_static!(
nrf52840::nvmc::Nvmc
Expand Down

0 comments on commit 86987da

Please sign in to comment.