Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add active flow in sw-emulator app #1738

Draft
wants to merge 1 commit into
base: Dma_driver_2
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions rom/dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ run: build-emu build-fw-image build-rom
--recovery-image-fw $(TARGET_DIR)/caliptra-rom-test-fw \
--device-lifecycle unprovisioned \

run-active: build-emu build-fw-image build-rom
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
run \
-p caliptra-emu \
-- \
--req-idevid-csr \
--idevid-key-id-algo sha1 \
--rom $(TARGET_DIR)/caliptra-rom.bin \
--recovery-image-fw $(TARGET_DIR)/caliptra-rom-test-fw \
--device-lifecycle unprovisioned \
--active-mode \

run-update: build-emu build-fw-image build-rom
cargo \
"--config=$(EXTRA_CARGO_CONFIG)" \
Expand Down
56 changes: 49 additions & 7 deletions sw-emulator/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ use tock_registers::register_bitfields;
/// Firmware Load Command Opcode
const FW_LOAD_CMD_OPCODE: u32 = 0x4657_4C44;

/// Recovery register interface download Command Opcode
const RI_DOWNLOAD_FIRMWARE: u32 = 0x5249_4644;

/// The number of CPU clock cycles it takes to write the firmware to the mailbox.
const FW_WRITE_TICKS: u64 = 1000;

Expand Down Expand Up @@ -162,6 +165,11 @@ fn main() -> io::Result<()> {
.value_parser(value_parser!(u64))
.default_value(&(EXPECTED_CALIPTRA_BOOT_TIME_IN_CYCLES.to_string()))
)
.arg(
arg!(--"active-mode" ... "Active mode: get image update via recovery register interface")
.required(false)
.action(ArgAction::SetTrue)
)
.get_matches();

let args_rom = args.get_one::<PathBuf>("rom").unwrap();
Expand Down Expand Up @@ -267,6 +275,11 @@ fn main() -> io::Result<()> {
},
);

let active_mode = args.get_flag("active-mode");

// Clippy seems wrong about this clone not being necessary
#[allow(clippy::redundant_clone)]
let firmware_buffer = current_fw_buf.clone();
let bus_args = CaliptraRootBusArgs {
rom: rom_buffer,
log_dir: args_log_dir.clone(),
Expand All @@ -275,12 +288,20 @@ fn main() -> io::Result<()> {
0xFF => exit(0x00),
_ => print!("{}", val as char),
}),
ready_for_fw_cb: ReadyForFwCb::new(move |args| {
let firmware_buffer = current_fw_buf.clone();
args.schedule_later(FW_WRITE_TICKS, move |mailbox: &mut MailboxInternal| {
upload_fw_to_mailbox(mailbox, firmware_buffer);
});
}),
ready_for_fw_cb: if active_mode {
ReadyForFwCb::new(move |args| {
args.schedule_later(FW_WRITE_TICKS, move |mailbox: &mut MailboxInternal| {
rri_download(mailbox)
})
})
} else {
ReadyForFwCb::new(move |args| {
let firmware_buffer = firmware_buffer.clone();
args.schedule_later(FW_WRITE_TICKS, move |mailbox: &mut MailboxInternal| {
upload_fw_to_mailbox(mailbox, firmware_buffer)
});
})
},
security_state,
upload_update_fw: UploadUpdateFwCb::new(move |mailbox: &mut MailboxInternal| {
upload_fw_to_mailbox(mailbox, update_fw_buf.clone());
Expand All @@ -297,7 +318,12 @@ fn main() -> io::Result<()> {
..Default::default()
};

let root_bus = CaliptraRootBus::new(&clock, bus_args);
let mut root_bus = CaliptraRootBus::new(&clock, bus_args);
// Populate the RRI data
if active_mode {
root_bus.recovery.cms_data = Some(current_fw_buf);
}

let soc_ifc = unsafe {
caliptra_registers::soc_ifc::RegisterBlock::new_with_mmio(
0x3003_0000 as *mut u32,
Expand Down Expand Up @@ -457,6 +483,22 @@ fn upload_fw_to_mailbox(mailbox: &mut MailboxInternal, firmware_buffer: Rc<Vec<u
soc_mbox.execute().write(|w| w.execute(true));
}

fn rri_download(mailbox: &mut MailboxInternal) {
let soc_mbox = mailbox.as_external().regs();
// Write the cmd to mailbox.

assert!(!soc_mbox.lock().read().lock());

// Set command
soc_mbox.cmd().write(|_| RI_DOWNLOAD_FIRMWARE);

// No data to send so set len to 0
soc_mbox.dlen().write(|_| 0);

// Execute
soc_mbox.execute().write(|w| w.execute(true));
}

fn download_idev_id_csr(
mailbox: &mut MailboxInternal,
path: Rc<PathBuf>,
Expand Down
Loading