Skip to content

Commit

Permalink
sp_measure: Remove unnecessary loop in main.
Browse files Browse the repository at this point in the history
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)`
  • Loading branch information
flihp committed Aug 8, 2023
1 parent 08c4134 commit 4bad7f0
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions task/sp_measure/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,52 @@ 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!();
}
}

Expand Down

0 comments on commit 4bad7f0

Please sign in to comment.