diff --git a/platforms/emulator/runtime/kernel/drivers/mcu_mbox/src/lib.rs b/platforms/emulator/runtime/kernel/drivers/mcu_mbox/src/lib.rs index 10ae09195..8dc86ab4e 100644 --- a/platforms/emulator/runtime/kernel/drivers/mcu_mbox/src/lib.rs +++ b/platforms/emulator/runtime/kernel/drivers/mcu_mbox/src/lib.rs @@ -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; @@ -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, @@ -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(); @@ -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 @@ -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; } @@ -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(); } diff --git a/romtime/src/mci.rs b/romtime/src/mci.rs index 4e6d015d6..3675453ea 100644 --- a/romtime/src/mci.rs +++ b/romtime/src/mci.rs @@ -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 { diff --git a/runtime/kernel/capsules/src/mcu_mbox.rs b/runtime/kernel/capsules/src/mcu_mbox.rs index 73204ff86..6f268c94a 100644 --- a/runtime/kernel/capsules/src/mcu_mbox.rs +++ b/runtime/kernel/capsules/src/mcu_mbox.rs @@ -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!( @@ -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() { diff --git a/runtime/kernel/veer/src/chip.rs b/runtime/kernel/veer/src/chip.rs index 4997b50d5..0e3f6a62b 100644 --- a/runtime/kernel/veer/src/chip.rs +++ b/runtime/kernel/veer/src/chip.rs @@ -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 } } diff --git a/runtime/kernel/veer/src/pic.rs b/runtime/kernel/veer/src/pic.rs index 412e82d01..1dec5c45b 100644 --- a/runtime/kernel/veer/src/pic.rs +++ b/runtime/kernel/veer/src/pic.rs @@ -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); } diff --git a/runtime/userspace/api/mcu-mbox-lib/src/daemon.rs b/runtime/userspace/api/mcu-mbox-lib/src/daemon.rs index 92688df7b..9345802cb 100644 --- a/runtime/userspace/api/mcu-mbox-lib/src/daemon.rs +++ b/runtime/userspace/api/mcu-mbox-lib/src/daemon.rs @@ -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::::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 diff --git a/runtime/userspace/syscall/src/mcu_mbox.rs b/runtime/userspace/syscall/src/mcu_mbox.rs index 59c27c863..935a27a26 100644 --- a/runtime/userspace/syscall/src/mcu_mbox.rs +++ b/runtime/userspace/syscall/src/mcu_mbox.rs @@ -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; @@ -82,6 +84,8 @@ impl McuMbox { if data.is_empty() { return Err(ErrorCode::Invalid); } + let mut c = Console::::writer(); + writeln!(c, "McuMbox.receive_command").unwrap(); let mutex = MCU_MBOX_MUTEX.lock().await; let (command, recv_len, _) = share::scope::<(), _, _>(|_handle| { @@ -92,12 +96,14 @@ impl McuMbox { 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)) })? @@ -105,6 +111,7 @@ impl McuMbox { black_box(*mutex); // Ensure the mutex is not optimized away + writeln!(c, "McuMbox Done").unwrap(); Ok((command, recv_len as usize)) } diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 1993358ae..e309e3aeb 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -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; diff --git a/tests/integration/src/runtime/mod.rs b/tests/integration/src/runtime/mod.rs new file mode 100644 index 000000000..fae530a24 --- /dev/null +++ b/tests/integration/src/runtime/mod.rs @@ -0,0 +1,3 @@ +// Licensed under the Apache-2.0 license + +mod test_hek_provisioning; diff --git a/tests/integration/src/runtime/test_hek_provisioning.rs b/tests/integration/src/runtime/test_hek_provisioning.rs new file mode 100644 index 000000000..dd83e886e --- /dev/null +++ b/tests/integration/src/runtime/test_hek_provisioning.rs @@ -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(()) +}