-
Notifications
You must be signed in to change notification settings - Fork 747
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fcd3a45
boards: tutorials: add nrf52840dk-process-control and other required …
viswajith-g 24bb712
boards: tutorials: dynamic-apps-and-policies: addressed pr comments
viswajith-g 8df3437
boards: tutorial: dynamic-apps-and-policies: change nvm to isolated n…
viswajith-g 9d93ee2
revert no_mangle removal from main.rs and remove in io.rs
viswajith-g 7f869b2
boards: tutorial: dynamic-apps: working board
viswajith-g 9506151
boards: tut: dyn process: fix SeqProcLoad
bradjc d590be7
components: process info: fix capability
bradjc 895f076
tutorial: dpl: add appid assigner
bradjc 00f3faf
boards: tut: dyn proc: fix screen feature
bradjc a221341
boards: tut: dyn proc: expect unsigned apps
bradjc 9f17748
boards: tut: dyn proc: improve main
bradjc
8000
May 19, 2025
7bcbff6
boards: tut: dyn proc: led/adc already provided
bradjc 6e4ed43
boards: tut: dyn proc: use stop&debug panic policy
bradjc 47f9669
boards: tut: dyn proc: add system call filter template
bradjc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/.cargo/config.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
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). |
6 changes: 6 additions & 0 deletions
6
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/layout.ld
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
73 changes: 73 additions & 0 deletions
73
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/src/app_id_assigner_name_metadata.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | < 9E88 /tr>||
// 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
90
boards/tutorials/nrf52840dk-dynamic-apps-and-policies/src/io.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} |
Oops, something went wrong.
<
3A85
/div>
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)