8000 boards: tutorials: add nrf52840dk-dynamic-apps-and-policies by viswajith-g · Pull Request #4420 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

boards: tutorials: add nrf52840dk-dynamic-apps-and-policies #4420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ members = [
"boards/configurations/nrf52840dk/nrf52840dk-test-kernel",
"boards/configurations/nrf52840dk/nrf52840dk-test-dynamic-app-load",
"boards/configurations/microbit_v2/microbit_v2-test-dynamic-app-load",
"boards/tutorials/nrf52840dk-dynamic-apps-and-policies",
"boards/tutorials/nrf52840dk-hotp-tutorial",
"boards/tutorials/nrf52840dk-thread-tutorial",
"capsules/aes_gcm",
Expand Down
8 changes: 4 additions & 4 deletions boards/components/src/process_info_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use kernel::create_capability;

#[macro_export]
macro_rules! process_info_component_static {
() => {{
($C:ty $(,)?) => {{
let process_info = kernel::static_buf!(
capsules_extra::process_info_driver::ProcessInfo<
components::process_info_driver::Capability,
$C,
>
);

Expand All @@ -43,13 +43,13 @@ impl<C: ProcessManagementCapability + ProcessStartCapability> ProcessInfoCompone
impl<C: ProcessManagementCapability + ProcessStartCapability + 'static> Component
for ProcessInfoComponent<C>
{
type StaticInput = (&'static mut MaybeUninit<ProcessInfo<C>>,);
type StaticInput = &'static mut MaybeUninit<ProcessInfo<C>>;
type Output = &'static process_info_driver::ProcessInfo<C>;

fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);

let process_info = static_buffer.0.write(ProcessInfo::new(
let process_info = static_buffer.write(ProcessInfo::new(
self.board_kernel,
self.board_kernel.create_grant(self.driver_num, &grant_cap),
self.capability,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Licensed under the Apache License, Version 2.0 or the MIT License.
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright Tock Contributors 2024.

include = [
"../../../cargo/tock_flags.toml",
"../../../cargo/unstable_flags.toml",
]

[build]
target = "thumbv7em-none-eabi"

[unstable]
config-include = true
34 changes: 34 additions & 0 deletions boards/tutorials/nrf52840dk-dynamic-apps-and-policies/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed under the Apache License, Version 2.0 or the MIT License.
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright Tock Contributors 2022.

[package]
name = "nrf52840dk-dynamic-apps-and-policies"
version.workspace = true
authors.workspace = true
build = "../../build.rs"
edition.workspace = true

[features]
default = ["screen_ssd1306"]
screen_ssd1306 = []
screen_sh1106 = []

[dependencies]
kernel = { path = "../../../kernel" }

components = { path = "../../components" }
segger = { path = "../../../chips/segger" }
cortexm4 = { path = "../../../arch/cortex-m4" }
nrf52840 = { path = "../../../chips/nrf52840" }
nrf52840dk = { path = "../../nordic/nrf52840dk" }
capsules-core = { path = "../../../capsules/core" }
capsules-extra = { path = "../../../capsules/extra" }
capsules-system = { path = "../../../capsules/system" }
nrf52_components = { path = "../../nordic/nrf52_components" }

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

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Licensed under the Apache License, Version 2.0 or the MIT License.
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright Tock Contributors 2022.

include ../../Makefile.common
include ../../configurations/nrf52840dk/nrf52840dk.mk
10 changes: 10 additions & 0 deletions boards/tutorials/nrf52840dk-dynamic-apps-and-policies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
nRF52840DK Board Definition for the Tock Dynamic Apps and Secure Policies Tutorial
==================================================================================

This is the board definition for the nRF52840DK target used in the
[Dynamic App Loading and Secure Policies]
(https://github.com/tock/book/pull/60/files).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unfortunate chicken-and-egg situation; fine for the moment, just make sure you have a note somewhere to update this when tock/book#60 lands

(non-blocking comment)


Please follow the instructions in that tutorial. You may also want to look at
the documentation of the base nRF52840DK board definition
[here](../../nordic/nrf52840dk/README.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Licensed under the Apache License, Version 2.0 or the MIT License. */
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
/* Copyright Tock Contributors 2023. */

INCLUDE ../../nordic/nrf52840_chip_layout.ld
INCLUDE tock_kernel_layout.ld
< 9E88 /tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2025.

//! AppID assigner based on name and credential check metadata.
//!
//! This assigns a short ID where the most significant four bits are from the
//! credential checking metadata and the remaining bits are a CRC of the name.
//!
//! ```text
//! 32 28 0 bits
//! +----------+------------------------+
//! | metadata | CRC(name) |
//! +----------+------------------------+
//! ```
//!
//! The intention is that the CRC makes the short ID generally unique, and the
//! 4-bit metadata indicates the key that was used to verify the app's signing
//! credential.

use kernel::process::{Process, ProcessBinary, ShortId};
use kernel::process_checker::Compress;

pub struct AppIdAssignerNameMetadata {}

impl AppIdAssignerNameMetadata {
pub fn new() -> Self {
Self {}
}
}

impl kernel::process_checker::Compress for AppIdAssignerNameMetadata {
fn to_short_id(&self, process: &ProcessBinary) -> ShortId {
// Get the stored metadata returned when this process had its credential
// checked.
let metadata = process.credential.get().map_or(0xF, |accepted_credential| {
accepted_credential
.metadata
.map_or(0xF, |metadata| metadata.metadata) as u32
});

let name = process.header.get_package_name().unwrap_or("");
let sum = kernel::utilities::helpers::crc32_posix(name.as_bytes());

// Combine the metadata and CRC into the short id.
let sid = ((metadata & 0xF) << 28) | (sum & 0xFFFFFFF);

core::num::NonZeroU32::new(sid).into()
}
}

// We just use the generic version which compares Short IDs.
impl kernel::process_checker::AppUniqueness for AppIdAssignerNameMetadata {
fn different_identifier(&self, process_a: &ProcessBinary, process_b: &ProcessBinary) -> bool {
self.to_short_id(process_a) != self.to_short_id(process_b)
}

fn different_identifier_process(
&self,
process_a: &ProcessBinary,
process_b: &dyn Process,
) -> bool {
self.to_short_id(process_a) != process_b.short_app_id()
}

fn different_identifier_processes(
&self,
process_a: &dyn Process,
process_b: &dyn Process,
) -> bool {
process_a.short_app_id() != process_b.short_app_id()
}
}
90 changes: 90 additions & 0 deletions boards/tutorials/nrf52840dk-dynamic-apps-and-policies/src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2024.

use core::fmt::Write;
use kernel::debug::IoWrite;
use kernel::hil::uart;
use kernel::hil::uart::Configure;

use nrf52840::uart::{Uarte, UARTE0_BASE};

enum Writer {
WriterUart(/* initialized */ bool),
WriterRtt(&'static segger::rtt::SeggerRttMemory<'static>),
}

static mut WRITER: Writer = Writer::WriterUart(false);

/// Set the RTT memory buffer used to output panic messages.
pub unsafe fn set_rtt_memory(rtt_memory: &'static segger::rtt::SeggerRttMemory<'static>) {
WRITER = Writer::WriterRtt(rtt_memory);
}

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
match self {
Writer::WriterUart(ref mut initialized) => {
// Here, we create a second instance of the Uarte struct.
// This is okay because we only call this during a panic, and
// we will never actually process the interrupts
let uart = Uarte::new(UARTE0_BASE);
if !*initialized {
*initialized = true;
let _ = uart.configure(uart::Parameters {
baud_rate: 115200,
stop_bits: uart::StopBits::One,
parity: uart::Parity::None,
hw_flow_control: false,
width: uart::Width::Eight,
});
}
for &c in buf {
unsafe {
uart.send_byte(c);
}
while !uart.tx_ready() {}
}
}
Writer::WriterRtt(rtt_memory) => {
rtt_memory.write_sync(buf);
}
}
buf.len()
}
}

#[cfg(not(test))]
#[panic_handler]
/// Panic handler
pub unsafe fn panic_fmt(pi: &core::panic::PanicInfo) -> ! {
use core::ptr::{addr_of, addr_of_mut};
use kernel::debug;
use kernel::hil::led;
use nrf52840::gpio::Pin;

use crate::CHIP;
use crate::PROCESSES;
use crate::PROCESS_PRINTER;

// The nRF52840DK LEDs (see back of board)
let led_kernel_pin = &nrf52840::gpio::GPIOPin::new(Pin::P0_13);
let led = &mut led::LedLow::new(led_kernel_pin);
let writer = &mut *addr_of_mut!(WRITER);
debug::panic(
&mut [led],
writer,
pi,
&cortexm4::support::nop,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}
Loading
0