Skip to content

Commit

Permalink
Move back storage changes to their patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Aug 15, 2021
1 parent ed28941 commit e851606
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 143 deletions.
46 changes: 1 addition & 45 deletions boards/nordic/nrf52840_dongle_opensk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS];

static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
address: 0xC0000,
size: 0x40000,
}];

// Static reference to chip for panic dumps
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;

Expand Down Expand Up @@ -83,7 +78,6 @@ pub struct Platform {
'static,
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
>,
nvmc: &'static nrf52840::nvmc::SyscallDriver,
}

impl kernel::Platform for Platform {
Expand All @@ -99,30 +93,10 @@ impl kernel::Platform for Platform {
capsules::button::DRIVER_NUM => f(Some(self.button)),
capsules::rng::DRIVER_NUM => f(Some(self.rng)),
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
_ => f(None),
}
}

fn filter_syscall(
&self,
process: &dyn kernel::procs::ProcessType,
syscall: &kernel::syscall::Syscall,
) -> Result<(), kernel::ReturnCode> {
use kernel::syscall::Syscall;
match *syscall {
Syscall::COMMAND {
driver_number: nrf52840::nvmc::DRIVER_NUM,
subdriver_number: cmd,
arg0: ptr,
arg1: len,
} if (cmd == 2 || cmd == 3) && !process.fits_in_storage_location(ptr, len) => {
Err(kernel::ReturnCode::EINVAL)
}
_ => Ok(()),
}
}
}

/// Entry point in the vector table called on hard reset.
Expand All @@ -131,10 +105,7 @@ pub unsafe fn reset_handler() {
// Loads relocations and clears BSS
nrf52840::init();

let board_kernel = static_init!(
kernel::Kernel,
kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
);
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));

// GPIOs
let gpio = components::gpio::GpioComponent::new(
Expand Down Expand Up @@ -278,20 +249,6 @@ pub unsafe fn reset_handler() {
nrf52840::acomp::Comparator
));

let nvmc = static_init!(
nrf52840::nvmc::SyscallDriver,
nrf52840::nvmc::SyscallDriver::new(
&nrf52840::nvmc::NVMC,
board_kernel.create_grant(&memory_allocation_capability),
dynamic_deferred_caller,
)
);
nvmc.set_deferred_handle(
dynamic_deferred_caller
.register(nvmc)
.expect("no deferred call slot available for nvmc"),
);

nrf52_components::NrfClockComponent::new().finalize(());

let platform = Platform {
Expand All @@ -303,7 +260,6 @@ pub unsafe fn reset_handler() {
rng,
alarm,
analog_comparator,
nvmc,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
};

Expand Down
60 changes: 8 additions & 52 deletions boards/nordic/nrf52840_mdk_dfu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState};
use kernel::component::Component;
use kernel::hil::usb::UsbController;
#[allow(unused_imports)]
use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init};
use kernel::hil::usb::UsbController;
use nrf52840::gpio::Pin;
use nrf52_components::{self, UartChannel, UartPins};

Expand Down Expand Up @@ -56,11 +56,6 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS];

static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
address: 0xC0000,
size: 0x40000,
}];

// Static reference to chip for panic dumps
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;

Expand Down Expand Up @@ -89,7 +84,6 @@ pub struct Platform {
'static,
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
>,
nvmc: &'static nrf52840::nvmc::SyscallDriver,
usb: &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver<
'static,
'static,
Expand All @@ -110,31 +104,11 @@ impl kernel::Platform for Platform {
capsules::button::DRIVER_NUM => f(Some(self.button)),
capsules::rng::DRIVER_NUM => f(Some(self.rng)),
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)),
capsules::usb::usb_ctap::DRIVER_NUM => f(Some(self.usb)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
_ => f(None),
}
}

fn filter_syscall(
&self,
process: &dyn kernel::procs::ProcessType,
syscall: &kernel::syscall::Syscall,
) -> Result<(), kernel::ReturnCode> {
use kernel::syscall::Syscall;
match *syscall {
Syscall::COMMAND {
driver_number: nrf52840::nvmc::DRIVER_NUM,
subdriver_number: cmd,
arg0: ptr,
arg1: len,
} if (cmd == 2 || cmd == 3) && !process.fits_in_storage_location(ptr, len) => {
Err(kernel::ReturnCode::EINVAL)
}
_ => Ok(()),
}
}
}

/// Entry point in the vector table called on hard reset.
Expand All @@ -143,10 +117,7 @@ pub unsafe fn reset_handler() {
// Loads relocations and clears BSS
nrf52840::init();

let board_kernel = static_init!(
kernel::Kernel,
kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
);
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
// GPIOs
let gpio = components::gpio::GpioComponent::new(
board_kernel,
Expand All @@ -159,7 +130,8 @@ pub unsafe fn reset_handler() {
3 => &nrf52840::gpio::PORT[Pin::P0_07],
4 => &nrf52840::gpio::PORT[Pin::P0_08]
),
).finalize(components::gpio_component_buf!(nrf52840::gpio::GPIOPin));
)
.finalize(components::gpio_component_buf!(nrf52840::gpio::GPIOPin));

let button = components::button::ButtonComponent::new(
board_kernel,
Expand Down Expand Up @@ -263,26 +235,11 @@ pub unsafe fn reset_handler() {
nrf52840::acomp::Comparator
));

let nvmc = static_init!(
nrf52840::nvmc::SyscallDriver,
nrf52840::nvmc::SyscallDriver::new(
&nrf52840::nvmc::NVMC,
board_kernel.create_grant(&memory_allocation_capability),
dynamic_deferred_caller,
)
);
nvmc.set_deferred_handle(
dynamic_deferred_caller
.register(nvmc)
.expect("no deferred call slot available for nvmc"),
);

// Configure USB controller
let usb:
&'static capsules::usb::usb_ctap::CtapUsbSyscallDriver<
'static,
'static,
nrf52840::usbd::Usbd<'static>,
let usb: &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver<
'static,
'static,
nrf52840::usbd::Usbd<'static>,
> = {
let usb_ctap = static_init!(
capsules::usb::usbc_ctap_hid::ClientCtapHID<
Expand Down Expand Up @@ -331,7 +288,6 @@ pub unsafe fn reset_handler() {
rng,
alarm,
analog_comparator,
nvmc,
usb,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
};
Expand Down
46 changes: 1 addition & 45 deletions boards/nordic/nrf52840dk_opensk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
[None; NUM_PROCS];

static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation {
address: 0xC0000,
size: 0x40000,
}];

static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;

/// Dummy buffer that causes the linker to reserve enough space for the stack.
Expand Down Expand Up @@ -146,7 +141,6 @@ pub struct Platform {
'static,
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
>,
nvmc: &'static nrf52840::nvmc::SyscallDriver,
}

impl kernel::Platform for Platform {
Expand All @@ -162,30 +156,10 @@ impl kernel::Platform for Platform {
capsules::button::DRIVER_NUM => f(Some(self.button)),
capsules::rng::DRIVER_NUM => f(Some(self.rng)),
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
_ => f(None),
}
}

fn filter_syscall(
&self,
process: &dyn kernel::procs::ProcessType,
syscall: &kernel::syscall::Syscall,
) -> Result<(), kernel::ReturnCode> {
use kernel::syscall::Syscall;
match *syscall {
Syscall::COMMAND {
driver_number: nrf52840::nvmc::DRIVER_NUM,
subdriver_number: cmd,
arg0: ptr,
arg1: len,
} if (cmd == 2 || cmd == 3) && !process.fits_in_storage_location(ptr, len) => {
Err(kernel::ReturnCode::EINVAL)
}
_ => Ok(()),
}
}
}

/// Entry point in the vector table called on hard reset.
Expand All @@ -209,10 +183,7 @@ pub unsafe fn reset_handler() {
UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD))
};

let board_kernel = static_init!(
kernel::Kernel,
kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS)
);
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));

let gpio = components::gpio::GpioComponent::new(
board_kernel,
Expand Down Expand Up @@ -363,20 +334,6 @@ pub unsafe fn reset_handler() {
nrf52840::acomp::Comparator
));

let nvmc = static_init!(
nrf52840::nvmc::SyscallDriver,
nrf52840::nvmc::SyscallDriver::new(
&nrf52840::nvmc::NVMC,
board_kernel.create_grant(&memory_allocation_capability),
dynamic_deferred_caller,
)
);
nvmc.set_deferred_handle(
dynamic_deferred_caller
.register(nvmc)
.expect("no deferred call slot available for nvmc"),
);

nrf52_components::NrfClockComponent::new().finalize(());

let platform = Platform {
Expand All @@ -388,7 +345,6 @@ pub unsafe fn reset_handler() {
rng,
alarm,
analog_comparator,
nvmc,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
};

Expand Down
Loading

0 comments on commit e851606

Please sign in to comment.