Skip to content
Draft
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
6 changes: 6 additions & 0 deletions platforms/emulator/runtime/kernel/drivers/mcu_mbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use mcu_mbox_comm::hil::{Mailbox, MailboxClient, MailboxStatus};
use registers_generated::mci;
use registers_generated::mci::bits::{MboxCmdStatus, Notif0IntrEnT, Notif0IntrT};
use romtime::StaticRef;
use romtime::println;

pub const MCU_MBOX0_SRAM_OFFSET: u32 = 0x40_0000;
pub const MCU_MBOX1_SRAM_OFFSET: u32 = 0x80_0000;
Expand Down Expand Up @@ -52,6 +53,7 @@ impl<'a, A: Alarm<'a>> McuMailbox<'a, A> {
sram_base: u32,
alarm: &'a MuxAlarm<'a, A>,
) -> Self {
println!("MCU_MBOX_DRIVER: new");
let dw_len = registers.mcu_mbox0_csr_mbox_sram.len();
McuMailbox {
registers,
Expand All @@ -72,6 +74,7 @@ impl<'a, A: Alarm<'a>> McuMailbox<'a, A> {
}

fn reset_before_use(&self) {
println!("MCU_MBOX_DRIVER: Resetting mbox");
let mbox_sram_size = (self.registers.mcu_mbox0_csr_mbox_sram.len() * 4) as u32;
// MCU acquires the lock to allow SRAM clearing.
self.registers.mcu_mbox0_csr_mbox_lock.get();
Expand All @@ -80,6 +83,7 @@ impl<'a, A: Alarm<'a>> McuMailbox<'a, A> {
}

pub fn handle_interrupt(&self) {
println!("MCU_MBOX_DRIVER: handle interrupt");
let intr_status = self
.registers
.intr_block_rf_notif0_internal_intr_r
Expand All @@ -105,6 +109,7 @@ impl<'a, A: Alarm<'a>> McuMailbox<'a, A> {
}

fn handle_incoming_request(&self) {
println!("MCU_MBOX_DRIVER: handle request");
if self.state.get() != McuMboxState::RxWait {
return;
}
Expand Down Expand Up @@ -239,6 +244,7 @@ impl<'a, A: Alarm<'a>> Mailbox<'a> for McuMailbox<'a, A> {
}

fn enable(&self) {
println!("MCU_MBOX_DRIVER: enabled interrupts");
self.enable_interrupts();
}

Expand Down
1 change: 1 addition & 0 deletions romtime/src/mci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl Mci {
/// The interrupt handler is responsible for clearing the interrupt
/// and performing the necessary actions based on the interrupt type.
pub fn handle_interrupt(&self) {
crate::println!("Mci::handle_interrupt()");
const NOTIF_CPTRA_MCU_RESET_REQ_STS_MASK: u32 = 0x2;
let intr_status = self.registers.intr_block_rf_notif0_internal_intr_r.get();
if intr_status & NOTIF_CPTRA_MCU_RESET_REQ_STS_MASK != 0 {
Expand Down
2 changes: 2 additions & 0 deletions runtime/kernel/capsules/src/mcu_mbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl<'a, T: hil::Mailbox<'a>> McuMboxDriver<'a, T> {

impl<'a, T: hil::Mailbox<'a>> hil::MailboxClient for McuMboxDriver<'a, T> {
fn request_received(&self, command: u32, rx_buf: &'static mut [u32], dlen: usize) {
println!("Kernel syscall: MCU_MBOX_CAPSULE: request_received");
let dw_len = dlen.div_ceil(4);
if dw_len > rx_buf.len() {
println!(
Expand Down Expand Up @@ -333,6 +334,7 @@ impl<'a, T: hil::Mailbox<'a>> SyscallDriver for McuMboxDriver<'a, T> {
match command_num {
0 => CommandReturn::success(),
1 => {
println!("Kernel syscall: MCU_MBOX_CAPSULE: receive_request");
// Receive request message
let res = self.apps.enter(process_id, |app, kernel_data| {
if app.waiting_rx.get() {
Expand Down
3 changes: 2 additions & 1 deletion runtime/kernel/veer/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ impl<'a> InterruptService for VeeRDefaultPeripherals<'a> {
self.i3c.handle_interrupt();
return true;
} else if interrupt == MCI_IRQ as u32 {
romtime::println!("[mcu-runtime] MCI interrupt");
self.mci.handle_interrupt();
self.mcu_mbox0.handle_interrupt();
return true;
}
debug!("Unhandled interrupt {}", interrupt);
romtime::println!("Unhandled interrupt {}", interrupt);
false
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/kernel/veer/src/pic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ impl Pic {

/// Enable all interrupts.
pub fn enable_all(&self) {
romtime::println!("[mcu-runtime-veer] Enabling all interrupts");
for enable in self.registers.meie.iter().skip(1) {
enable.write(Meie::Inten::SET);
}
}
/// Disable all interrupts.
pub fn disable_all(&self) {
romtime::println!("[mcu-runtime-veer] Disabling all interrupts");
for enable in self.registers.meie.iter().skip(1) {
enable.write(Meie::Inten::CLEAR);
}
Expand Down
5 changes: 5 additions & 0 deletions runtime/userspace/api/mcu-mbox-lib/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ pub async fn mcu_mbox_responder(
running: &'static AtomicBool,
) {
let mut msg_buffer = [0; MAX_MCU_MBOX_MSG_SIZE];
writeln!(
Console::<DefaultSyscalls>::writer(),
"mcu_mbox_responder start"
)
.unwrap();
while running.load(Ordering::SeqCst) {
if let Err(e) = cmd_interface.handle_responder_msg(&mut msg_buffer).await {
// Debug print on error
Expand Down
7 changes: 7 additions & 0 deletions runtime/userspace/syscall/src/mcu_mbox.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed under the Apache-2.0 license

use crate::DefaultSyscalls;
use core::fmt::Write;
use core::{hint::black_box, marker::PhantomData};
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
use libtock_console::Console;
use libtock_platform::{share, DefaultConfig, ErrorCode, Syscalls};
use libtockasync::TockSubscribe;

Expand Down Expand Up @@ -82,6 +84,8 @@ impl<S: Syscalls> McuMbox<S> {
if data.is_empty() {
return Err(ErrorCode::Invalid);
}
let mut c = Console::<DefaultSyscalls>::writer();
writeln!(c, "McuMbox.receive_command").unwrap();

let mutex = MCU_MBOX_MUTEX.lock().await;
let (command, recv_len, _) = share::scope::<(), _, _>(|_handle| {
Expand All @@ -92,19 +96,22 @@ impl<S: Syscalls> McuMbox<S> {
data,
);

writeln!(c, "McuMbox Subscribed").unwrap();
if let Err(e) = S::command(self.driver_num, command::RECEIVE_REQUEST, 0, 0)
.to_result::<(), ErrorCode>()
{
sub.cancel();
Err(e)?;
}
writeln!(c, "McuMbox Syscall sent").unwrap();

Ok(TockSubscribe::subscribe_finish(sub))
})?
.await?;

black_box(*mutex); // Ensure the mutex is not optimized away

writeln!(c, "McuMbox Done").unwrap();
Ok((command, recv_len as usize))
}

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod i3c_socket;
mod jtag;
#[cfg(test)]
mod rom;
#[cfg(test)]
mod runtime;
mod test_dot;
mod test_exception_handler;
mod test_firmware_update;
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Licensed under the Apache-2.0 license

mod test_hek_provisioning;
28 changes: 28 additions & 0 deletions tests/integration/src/runtime/test_hek_provisioning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed under the Apache-2.0 license

use crate::test::{start_runtime_hw_model, TestParams};
use anyhow::Result;
use mcu_hw_model::McuHwModel;
use mcu_rom_common::McuBootMilestones;

const BOOT_CYCLES: u64 = 25_000_000;

#[test]
fn test_provision_first_hek() -> Result<()> {
let mut hw = start_runtime_hw_model(TestParams {
feature: Some("test-mcu-mbox-cmds"),
..Default::default()
});

assert!(hw
.mci_boot_milestones()
.contains(McuBootMilestones::FIRMWARE_BOOT_FLOW_COMPLETE));

// This is to ensure the command happens after the mailbox responder is initialized, but it
// doesn't change anything.
hw.step_until(|hw| hw.cycle_count() >= BOOT_CYCLES);

// This should get an error that says it is an unknown command, but it times out.
let _resp = hw.mailbox_execute(0x0, &[0xaa; 8])?.unwrap();
Ok(())
}
Loading