Skip to content

Commit

Permalink
emualtor: Recovery control fifo register 1 should be pass-through
Browse files Browse the repository at this point in the history
instead of duplicating the length.
  • Loading branch information
swenson committed Feb 6, 2025
1 parent a8766ca commit 0e91c77
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion drivers/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl<'a> DmaRecovery<'a> {
})?;

// Loop on the 'payload_available' signal for the recovery image details to be available.
cprintln!("[fwproc] Waiting for payload available signal...");
cprintln!("[dma_recovery] Waiting for payload available signal...");
while !self.dma.payload_available()? {}
let image_size_bytes = self.with_regs_mut(|regs_mut| {
let recovery = regs_mut.sec_fw_recovery_if();
Expand Down
4 changes: 2 additions & 2 deletions fmc/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Licensed under the Apache-2.0 license

#!/bin/bash
# Licensed under the Apache-2.0 license

cd "$(dirname "${BASH_SOURCE[0]}")"

Expand All @@ -9,4 +8,5 @@ cargo build \
--target riscv32imc-unknown-none-elf \
--profile=firmware \
--no-default-features \
--features riscv \
--bin=caliptra-fmc
45 changes: 44 additions & 1 deletion rom/dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ build-emu:
--no-default-features \
--features "emu no-cfi"

build-fmc:
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
build \
--profile firmware \
--manifest-path ../../fmc/Cargo.toml \
--target=riscv32imc-unknown-none-elf \
--no-default-features \
--features emu,riscv \
--bin caliptra-fmc

build-test-fmc:
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
Expand All @@ -49,6 +60,17 @@ build-test-fmc:
--no-default-features \
--features emu

build-rt:
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
build \
--profile firmware \
--manifest-path ../../runtime/Cargo.toml \
--target=riscv32imc-unknown-none-elf \
--no-default-features \
--features emu,riscv \
--bin caliptra-runtime

build-test-rt:
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
Expand All @@ -63,7 +85,7 @@ gen-certs:
$(shell bash $(CURRENT_DIR)/tools/scripts/gen_test_certs.sh $(TARGET_DIR))
$(shell cp $(CURRENT_DIR)/tools/keys.toml $(TARGET_DIR))

build-fw-image: gen-certs build-test-fmc build-test-rt
build-fw-test-image: gen-certs build-test-fmc build-test-rt
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
run \
Expand All @@ -84,6 +106,27 @@ build-fw-image: gen-certs build-test-fmc build-test-rt
--out $(TARGET_DIR)/caliptra-rom-test-fw \
--print-hashes

build-fw-image: gen-certs build-test-fmc build-rt
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
run \
--manifest-path ../../image/app/Cargo.toml \
-- \
create \
--pqc-key-type $(PQC_KEY_TYPE) \
--key-config $(TARGET_DIR)/keys.toml \
--ecc-pk-idx 1 \
--pqc-pk-idx 0 \
--fmc $(TARGET_DIR)/caliptra-rom-test-fmc \
--fmc-version 0 \
--fmc-rev $(GIT_REV) \
--rt $(TARGET_DIR)/caliptra-runtime \
--rt-version 0 \
--rt-rev $(GIT_REV) \
--fw-svn 0 \
--out $(TARGET_DIR)/caliptra-fw \
--print-hashes

bloat: build
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
Expand Down
4 changes: 2 additions & 2 deletions runtime/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Licensed under the Apache-2.0 license

#!/bin/bash
# Licensed under the Apache-2.0 license

cd "$(dirname "${BASH_SOURCE[0]}")"

Expand All @@ -9,4 +8,5 @@ cargo build \
--target riscv32imc-unknown-none-elf \
--profile=firmware \
--no-default-features \
--features riscv \
--bin=caliptra-runtime
22 changes: 6 additions & 16 deletions sw-emulator/lib/periph/src/dma/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use caliptra_emu_bus::{
};
use caliptra_emu_derive::Bus;
use caliptra_emu_types::{RvData, RvSize};
use std::mem;
use std::rc::Rc;
use std::sync::mpsc;
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
Expand Down Expand Up @@ -150,8 +149,8 @@ pub struct RecoveryRegisterInterface {
// Indirect FIFO registers
#[register(offset = 0x48, write_fn = indirect_fifo_ctrl_0_write)]
pub indirect_fifo_ctrl_0: ReadWriteRegister<u32, IndirectCtrl0::Register>,
#[register(offset = 0x4c, read_fn = indirect_fifo_ctrl_1_read)]
pub indirect_fifo_ctrl_1: ReadWriteRegister<u32, IndirectCtrl1::Register>,
#[register(offset = 0x4c)]
pub indirect_fifo_ctrl_1: ReadOnlyRegister<u32, IndirectCtrl1::Register>,
#[register(offset = 0x50)]
pub indirect_fifo_status_0: ReadOnlyRegister<u32, IndirectStatus::Register>,
#[register(offset = 0x54)]
Expand Down Expand Up @@ -206,7 +205,7 @@ impl RecoveryRegisterInterface {

// Indirect FIFO registers
indirect_fifo_ctrl_0: ReadWriteRegister::new(0),
indirect_fifo_ctrl_1: ReadWriteRegister::new(0),
indirect_fifo_ctrl_1: ReadOnlyRegister::new(0),
indirect_fifo_status_0: ReadOnlyRegister::new(0x1), // EMPTY=1
indirect_fifo_status_1: ReadOnlyRegister::new(0),
indirect_fifo_status_2: ReadOnlyRegister::new(0),
Expand Down Expand Up @@ -280,6 +279,9 @@ impl RecoveryRegisterInterface {
} else {
let len_dwords = image.len() as u32 / 4;
// [TODO][CAP2]: verify endianness of this matches the hardware
self.indirect_fifo_ctrl_0
.reg
.modify(IndirectCtrl0::CMS.val(cms));
self.indirect_fifo_ctrl_0
.reg
.modify(IndirectCtrl0::RESET::CLEAR);
Expand Down Expand Up @@ -308,18 +310,6 @@ impl RecoveryRegisterInterface {
Ok(())
}

pub fn indirect_fifo_ctrl_1_read(&mut self, size: RvSize) -> Result<RvData, BusError> {
if size != RvSize::Word {
Err(BusError::LoadAccessFault)?
}

let image_index = ((self.recovery_status.reg.get() >> 4) & 0xf) as usize;
match self.cms_data.get(image_index) {
Some(d) => Ok((d.len() / mem::size_of::<u32>()) as u32),
None => Ok(0),
}
}

pub fn register_outgoing_events(&mut self, sender: mpsc::Sender<Event>) {
self.event_sender = Some(sender);
}
Expand Down

0 comments on commit 0e91c77

Please sign in to comment.