Skip to content

Commit

Permalink
rom: Populate fuses from OTP controller (#80)
Browse files Browse the repository at this point in the history
We had to shave a few yaks.

First, we added an autogenerator that takes the OTP memory map hjson
file and uses it to generate a list of fuses (partitions, offsets,
sizes) and some simple data structures for manipulating them, since
doing so is fiddly and error-prone.

Plus, this memory map is in the process of changing quite a lot, so this
helps us avoid having to reprogram everything manually later.

Then, we updated the emulator to use the autogenerated peripheral trait
and the autogenerated fuse data, which will also help keep it
up-to-date.

Finally, we added in a section of ROM code to read the non-secret fuses
from the OTP controller and write them to Calipta Core's SoC interface.

(There is a hardware state machine that will write the secret fuses, so
we don't have to worry about.)

For now, I've checked in a copy of the latest `otp_ctrl_mmap.hjson` file
from `caliptra-ss` because that repository does not have a single branch
that contains both it and the I3C RDL that we need at the moment.
  • Loading branch information
swenson authored Jan 10, 2025
1 parent a7181f8 commit ab8c992
Show file tree
Hide file tree
Showing 20 changed files with 1,079 additions and 449 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ rand = "0.8.5"
semver = "1.0.23"
serde = { version = "1.0.209", features = ["alloc", "derive", "serde_derive"] }
serde_json = { version = "1.0.127", features = ["alloc"] }
serde-hjson = "1.1.0"
strum = "0.24"
strum_macros = "0.24"
syn = "1.0.107"
Expand All @@ -105,6 +106,7 @@ toml = "0.8.19"
uuid = { version = "1.10.0", features = ["serde"]}
walkdir = "2.5.0"
zerocopy = { version = "0.8.7", features = ["derive"] }
zeroize = { version = "1.6.0", default-features = false, features = ["zeroize_derive"] }

# local dependencies
capsules-runtime = { path = "runtime/capsules" }
Expand Down
8 changes: 5 additions & 3 deletions emulator/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use crossterm::event::{Event, KeyCode, KeyEvent};
use emulator_bus::{Bus, BusConverter, Clock, Timer};
use emulator_caliptra::{start_caliptra, StartCaliptraArgs};
use emulator_cpu::{Cpu, Pic, RvInstr, StepAction};
use emulator_periph::{CaliptraRootBus, CaliptraRootBusArgs, DummyFlashCtrl, I3c, I3cController};
use emulator_periph::{
CaliptraRootBus, CaliptraRootBusArgs, DummyFlashCtrl, I3c, I3cController, Otp,
};
use emulator_registers_generated::root_bus::AutoRootBus;
use emulator_registers_generated::soc::SocPeripheral;
use emulator_types::ROM_SIZE;
Expand Down Expand Up @@ -331,7 +333,6 @@ fn run(cli: Emulator, capture_uart_output: bool) -> io::Result<Vec<u8>> {
firmware: firmware_buffer,
log_dir: args_log_dir.clone(),
uart_output: uart_output.clone(),
otp_file: cli.otp,
uart_rx: stdin_uart.clone(),
pic: pic.clone(),
clock: clock.clone(),
Expand Down Expand Up @@ -423,12 +424,13 @@ fn run(cli: Emulator, capture_uart_output: bool) -> io::Result<Vec<u8>> {
Some(Box::new(FakeSoc {}) as Box<dyn SocPeripheral>)
};

let otp = Otp::new(&clock.clone(), cli.otp)?;
let mut auto_root_bus = AutoRootBus::new(
delegates,
Some(Box::new(i3c)),
Some(Box::new(flash_controller)),
None,
None,
Some(Box::new(otp)),
None,
None,
soc_periph,
Expand Down
6 changes: 6 additions & 0 deletions emulator/bus/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ impl<T: UIntLike + RvDataConverter<T>, R: RegisterLongName> Register for ReadWri
}
}

impl<T: UIntLike, R: RegisterLongName> From<T> for ReadWriteRegister<T, R> {
fn from(value: T) -> Self {
Self::new(value)
}
}

/// Read Only Register
pub struct ReadOnlyRegister<T: UIntLike, R: RegisterLongName = ()> {
/// Register
Expand Down
Loading

0 comments on commit ab8c992

Please sign in to comment.