From 72bfa85af4768d37723e4a03880dc450f66fad90 Mon Sep 17 00:00:00 2001 From: Philip Tricca Date: Tue, 8 Aug 2023 09:41:00 -0700 Subject: [PATCH] sp_measure: Remove unnecessary loop in main. This task is intended to run once when the system boots and the task it performs should not be repeated. Jefe will no longer restart this task and so we could remove the final call to `sys_recv_closed` as well, however tasks that return from their `main` function are reported as having executed an illegal instruction. So we leave this call in place to prevent a scary message from showing up in the task list: `FAULT: illegal instruction (was: ready)` --- task/sp_measure/src/main.rs | 74 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/task/sp_measure/src/main.rs b/task/sp_measure/src/main.rs index bd55088a1..6f8f0cdeb 100644 --- a/task/sp_measure/src/main.rs +++ b/task/sp_measure/src/main.rs @@ -30,54 +30,50 @@ enum Trace { ringbuf!(Trace, 16, Trace::None); #[export_name = "main"] -fn main() -> ! { - loop { - let mut sha = Sha3_256::new(); - let sp_ctrl = SpCtrl::from(SP_CTRL.get_task_id()); +fn main() { + let mut sha = Sha3_256::new(); + let sp_ctrl = SpCtrl::from(SP_CTRL.get_task_id()); - if sp_ctrl.setup().is_err() { + if sp_ctrl.setup().is_err() { + panic!(); + } + + let mut data: [u8; READ_SIZE] = [0; READ_SIZE]; + + let start = sys_get_timer().now; + ringbuf_entry!(Trace::Start(start)); + for addr in (FLASH_START..FLASH_END).step_by(READ_SIZE) { + if addr % TRANSACTION_SIZE == 0 + && sp_ctrl + .read_transaction_start(addr, addr + TRANSACTION_SIZE) + .is_err() + { panic!(); } - let mut data: [u8; READ_SIZE] = [0; READ_SIZE]; - - let start = sys_get_timer().now; - ringbuf_entry!(Trace::Start(start)); - for addr in (FLASH_START..FLASH_END).step_by(READ_SIZE) { - if addr % TRANSACTION_SIZE == 0 - && sp_ctrl - .read_transaction_start(addr, addr + TRANSACTION_SIZE) - .is_err() - { - panic!(); - } - - data.fill(0); - if sp_ctrl.read_transaction(&mut data).is_err() { - panic!(); - } - - sha.update(&data); + data.fill(0); + if sp_ctrl.read_transaction(&mut data).is_err() { + panic!(); } - let sha_out = sha.finalize(); + sha.update(&data); + } - let end = sys_get_timer().now; - ringbuf_entry!(Trace::End(end)); + let sha_out = sha.finalize(); - let attest = Attest::from(ATTEST.get_task_id()); - if let Err(e) = - attest.record(HashAlgorithm::Sha3_256, sha_out.as_bytes()) - { - ringbuf_entry!(Trace::RecordFail(e)); - panic!(); - }; + let end = sys_get_timer().now; + ringbuf_entry!(Trace::End(end)); - // Wait for a notification that will never come, politer than - // busy looping forever - if sys_recv_closed(&mut [], 1, TaskId::KERNEL).is_err() { - panic!(); - } + let attest = Attest::from(ATTEST.get_task_id()); + if let Err(e) = attest.record(HashAlgorithm::Sha3_256, sha_out.as_bytes()) { + ringbuf_entry!(Trace::RecordFail(e)); + panic!(); + }; + + // Wait for a notification that will never come, politer than + // busy looping forever + if sys_recv_closed(&mut [], 1, TaskId::KERNEL).is_err() { + panic!(); } }