Skip to content

Commit

Permalink
Add recovery flash in emulator and extend all flash test cases to rec…
Browse files Browse the repository at this point in the history
…overy flash (#86)
helloxiling authored Jan 27, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d1dab9a commit c9d9264
Showing 25 changed files with 1,089 additions and 264 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -21,5 +21,5 @@ runtime/apps/layout.ld
book

# flash file
dummy_flash.bin
primary_flash
main_flash
recovery_flash
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions emulator/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ strum_macros.workspace = true
strum.workspace = true
tock-registers.workspace = true
zerocopy.workspace = true
tempfile.workspace = true

[features]
default = []
64 changes: 52 additions & 12 deletions emulator/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -405,15 +405,46 @@ fn run(cli: Emulator, capture_uart_output: bool) -> io::Result<Vec<u8>> {
);
}

let flash_ctrl_error_irq = pic.register_irq(CaliptraRootBus::FLASH_CTRL_ERROR_IRQ);
let flash_ctrl_event_irq = pic.register_irq(CaliptraRootBus::FLASH_CTRL_EVENT_IRQ);
let flash_controller = DummyFlashCtrl::new(
&clock.clone(),
Some(PathBuf::from("primary_flash")), // TODO: make this configurable
flash_ctrl_error_irq,
flash_ctrl_event_irq,
)
.unwrap();
let create_flash_controller = |default_path: &str, error_irq: u8, event_irq: u8| {
// Use a temporary file for flash storage if we're running a test
let flash_file = if cfg!(any(
feature = "test-flash-ctrl-init",
feature = "test-flash-ctrl-read-write-page",
feature = "test-flash-ctrl-erase-page",
feature = "test-flash-storage-read-write",
feature = "test-flash-storage-erase",
feature = "test-flash-usermode",
)) {
Some(
tempfile::NamedTempFile::new()
.unwrap()
.into_temp_path()
.to_path_buf(),
)
} else {
Some(PathBuf::from(default_path))
};

DummyFlashCtrl::new(
&clock.clone(),
flash_file,
pic.register_irq(error_irq),
pic.register_irq(event_irq),
)
.unwrap()
};

let main_flash_controller = create_flash_controller(
"main_flash",
CaliptraRootBus::MAIN_FLASH_CTRL_ERROR_IRQ,
CaliptraRootBus::MAIN_FLASH_CTRL_EVENT_IRQ,
);

let recovery_flash_controller = create_flash_controller(
"recovery_flash",
CaliptraRootBus::RECOVERY_FLASH_CTRL_ERROR_IRQ,
CaliptraRootBus::RECOVERY_FLASH_CTRL_EVENT_IRQ,
);

let mut delegates: Vec<Box<dyn Bus>> = vec![Box::new(root_bus)];
let soc_periph = if let Some(soc_to_caliptra) = soc_to_caliptra {
@@ -428,7 +459,8 @@ fn run(cli: Emulator, capture_uart_output: bool) -> io::Result<Vec<u8>> {
let mut auto_root_bus = AutoRootBus::new(
delegates,
Some(Box::new(i3c)),
Some(Box::new(flash_controller)),
Some(Box::new(main_flash_controller)),
Some(Box::new(recovery_flash_controller)),
None,
Some(Box::new(otp)),
None,
@@ -437,9 +469,17 @@ fn run(cli: Emulator, capture_uart_output: bool) -> io::Result<Vec<u8>> {
None,
);

// Set the DMA RAM for the Flash Controller
// Set the DMA RAM for Main Flash Controller
auto_root_bus
.main_flash_periph
.as_mut()
.unwrap()
.periph
.set_dma_ram(dma_ram.clone());

// Set the DMA RAM for Recovery Flash Controller
auto_root_bus
.flash_periph
.recovery_flash_periph
.as_mut()
.unwrap()
.periph
4 changes: 4 additions & 0 deletions emulator/periph/Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,9 +22,13 @@ serde.workspace = true
tock-registers.workspace = true
zerocopy.workspace = true

[dev-dependencies]
tempfile.workspace = true

[features]
default = []
test-i3c-constant-writes = []
test-flash-ctrl-init = []
test-flash-ctrl-read-write-page = []
test-flash-ctrl-erase-page = []
test-flash-storage-read-write = []
Loading

0 comments on commit c9d9264

Please sign in to comment.