Skip to content

Commit

Permalink
Moved more flash access from DPL to ProcessLoadingAsync
Browse files Browse the repository at this point in the history
Moved the binary header validity check to process_loading, eliminating the need to track process flash slice in DPL.
  • Loading branch information
viswajith-g committed Feb 1, 2025
1 parent 968ab04 commit 99423b0
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 238 deletions.
2 changes: 1 addition & 1 deletion boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub mod dac;
pub mod date_time;
pub mod debug_queue;
pub mod debug_writer;
pub mod dyn_process_loader;
pub mod dfrobot_rainfall_sensor;
pub mod dyn_process_loader;
pub mod eui64;
pub mod flash;
pub mod fm25cl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ components = { path = "../../../components" }
cortexm4 = { path = "../../../../arch/cortex-m4" }
kernel = { path = "../../../../kernel" }
nrf52840 = { path = "../../../../chips/nrf52840" }
segger = { path = "../../../../chips/segger" }
nrf52_components = { path = "../../../nordic/nrf52_components" }

capsules-core = { path = "../../../../capsules/core" }
capsules-extra = { path = "../../../../capsules/extra" }
capsules-system = { path = "../../../../capsules/system" }

[build-dependencies]
tock_build_scripts = { path = "../../../build_scripts" }

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright Tock Contributors 2024.

TARGET=thumbv7em-none-eabi
PLATFORM=nrf52840dk-test-dynamic-app-load
# TARGET=thumbv7em-none-eabi
# PLATFORM=nrf52840dk-test-dynamic-app-load

include ../../../Makefile.common
include ../nrf52840dk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/* Copyright Tock Contributors 2023. */

INCLUDE ../../../nordic/nrf52840_chip_layout.ld
INCLUDE ../../../kernel_layout.ld
INCLUDE tock_kernel_layout.ld

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct Platform {
alarm: &'static AlarmDriver,
scheduler: &'static RoundRobinSched<'static>,
systick: cortexm4::systick::SysTick,
processes: &'static [Option<&'static dyn kernel::process::Process>],
dynamic_app_loader: &'static capsules_extra::app_loader::AppLoader<'static>,
}

Expand Down Expand Up @@ -159,15 +160,12 @@ impl kernel::process::ProcessLoadingAsyncClient for Platform {
fn process_loading_finished(&self) {
kernel::debug!("Processes Loaded:");

unsafe {
for (i, proc) in PROCESSES.iter().enumerate() {
proc.map(|p| {
kernel::debug!("[{}] {}", i, p.get_process_name());
kernel::debug!(" ShortId: {}", p.short_app_id());
});
}
for (i, proc) in self.processes.iter().enumerate() {
proc.map(|p| {
kernel::debug!("[{}] {}", i, p.get_process_name());
kernel::debug!(" ShortId: {}", p.short_app_id());
});
}
// loader.set_client(dynamic_process_loader);
}
}

Expand All @@ -189,13 +187,15 @@ pub unsafe fn main() {
nrf52840_peripherals.init();
let base_peripherals = &nrf52840_peripherals.nrf52;

let processes = &*addr_of!(PROCESSES);

// Choose the channel for serial output. This board can be configured to use
// either the Segger RTT channel or via UART with traditional TX/RX GPIO
// pins.
let uart_channel = UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD));

// Setup space to store the core kernel data structure.
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes));

// Create (and save for panic debugging) a chip object to setup low-level
// resources (e.g. MPU, systick).
Expand Down Expand Up @@ -235,66 +235,6 @@ pub unsafe fn main() {
LedLow::new(&nrf52840_peripherals.gpio_port[LED4_PIN]),
));

//--------------------------------------------------------------------------
// BUTTONS
//--------------------------------------------------------------------------

let button = components::button::ButtonComponent::new(
board_kernel,
capsules_core::button::DRIVER_NUM,
components::button_component_helper!(
nrf52840::gpio::GPIOPin,
(
&nrf52840_peripherals.gpio_port[BUTTON1_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON2_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON3_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON4_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
)
),
)
.finalize(components::button_component_static!(
nrf52840::gpio::GPIOPin
));

//--------------------------------------------------------------------------
// ADC
//--------------------------------------------------------------------------

let adc_channels = static_init!(
[nrf52840::adc::AdcChannelSetup; 6],
[
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput1),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput2),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput4),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput5),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput6),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput7),
]
);
let adc = components::adc::AdcDedicatedComponent::new(
&base_peripherals.adc,
adc_channels,
board_kernel,
capsules_core::adc::DRIVER_NUM,
)
.finalize(components::adc_dedicated_component_static!(
nrf52840::adc::Adc
));

//--------------------------------------------------------------------------
// TIMER
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -356,6 +296,66 @@ pub unsafe fn main() {
components::debug_writer::DebugWriterComponent::new(uart_mux)
.finalize(components::debug_writer_component_static!());

//--------------------------------------------------------------------------
// BUTTONS
//--------------------------------------------------------------------------

let button = components::button::ButtonComponent::new(
board_kernel,
capsules_core::button::DRIVER_NUM,
components::button_component_helper!(
nrf52840::gpio::GPIOPin,
(
&nrf52840_peripherals.gpio_port[BUTTON1_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON2_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON3_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
),
(
&nrf52840_peripherals.gpio_port[BUTTON4_PIN],
kernel::hil::gpio::ActivationMode::ActiveLow,
kernel::hil::gpio::FloatingState::PullUp
)
),
)
.finalize(components::button_component_static!(
nrf52840::gpio::GPIOPin
));

//--------------------------------------------------------------------------
// ADC
//--------------------------------------------------------------------------

let adc_channels = static_init!(
[nrf52840::adc::AdcChannelSetup; 6],
[
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput1),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput2),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput4),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput5),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput6),
nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput7),
]
);
let adc = components::adc::AdcDedicatedComponent::new(
&base_peripherals.adc,
adc_channels,
board_kernel,
capsules_core::adc::DRIVER_NUM,
)
.finalize(components::adc_dedicated_component_static!(
nrf52840::adc::Adc
));

//--------------------------------------------------------------------------
// NRF CLOCK SETUP
//--------------------------------------------------------------------------
Expand All @@ -378,6 +378,18 @@ pub unsafe fn main() {
let checker = components::appid::checker::ProcessCheckerMachineComponent::new(checking_policy)
.finalize(components::process_checker_machine_component_static!());

//--------------------------------------------------------------------------
// STORAGE PERMISSIONS
//--------------------------------------------------------------------------

let storage_permissions_policy =
components::storage_permissions::null::StoragePermissionsNullComponent::new().finalize(
components::storage_permissions_null_component_static!(
nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>,
kernel::process::ProcessStandardDebugFull,
),
);

// Create and start the asynchronous process loader.
let loader = components::loader::sequential::ProcessLoaderSequentialComponent::new(
checker,
Expand All @@ -386,9 +398,11 @@ pub unsafe fn main() {
chip,
&FAULT_RESPONSE,
assigner,
storage_permissions_policy,
)
.finalize(components::process_loader_sequential_component_static!(
nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>,
kernel::process::ProcessStandardDebugFull,
NUM_PROCS
));

Expand Down Expand Up @@ -435,7 +449,7 @@ pub unsafe fn main() {
// PLATFORM SETUP, SCHEDULER, AND START KERNEL LOOP
//--------------------------------------------------------------------------

let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
.finalize(components::round_robin_component_static!(NUM_PROCS));

let platform = static_init!(
Expand All @@ -448,6 +462,7 @@ pub unsafe fn main() {
alarm,
scheduler,
systick: cortexm4::systick::SysTick::new_with_calibration(64000000),
processes,
dynamic_app_loader,
}
);
Expand Down
2 changes: 1 addition & 1 deletion capsules/core/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum NUM {

// Kernel
Ipc = 0x10000,
AppLoader = 0x10001,

// HW Buses
Spi = 0x20001,
Expand Down Expand Up @@ -57,7 +58,6 @@ pub enum NUM {
NvmStorage = 0x50001,
SdCard = 0x50002,
Kv = 0x50003,
AppLoader = 0x50004,

// Sensors
Temperature = 0x60000,
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/app_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a> AppLoader<'a> {
buffer: &'static mut [u8],
) -> AppLoader<'a> {
AppLoader {
driver: driver,
driver,
apps: grant,
buffer: TakeCell::new(buffer),
current_process: OptionalCell::empty(),
Expand Down
Loading

0 comments on commit 99423b0

Please sign in to comment.