Skip to content

Commit

Permalink
Add recovery flash in emulator and extend flash test cases to recover…
Browse files Browse the repository at this point in the history
…y flash
  • Loading branch information
helloxiling committed Jan 10, 2025
1 parent ab8c992 commit cf24629
Show file tree
Hide file tree
Showing 23 changed files with 976 additions and 196 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.

9 changes: 5 additions & 4 deletions emulator/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ strum_macros.workspace = true
strum.workspace = true
tock-registers.workspace = true
zerocopy.workspace = true
tempfile.workspace = true

[features]
default = []
test-i3c-simple = []
test-i3c-constant-writes = ["emulator-periph/test-i3c-constant-writes"]
test-flash-ctrl-init = []
test-flash-ctrl-read-write-page = []
test-flash-ctrl-erase-page = []
test-flash-storage-read-write = []
test-flash-storage-erase = []
test-flash-ctrl-read-write-page = ["emulator-periph/test-flash-ctrl-read-write-page"]
test-flash-ctrl-erase-page = ["emulator-periph/test-flash-ctrl-erase-page"]
test-flash-storage-read-write = ["emulator-periph/test-flash-storage-read-write"]
test-flash-storage-erase = ["emulator-periph/test-flash-storage-erase"]
test-mctp-ctrl-cmds = ["emulator-periph/test-mctp-ctrl-cmds"]
test-mctp-capsule-loopback = ["emulator-periph/test-mctp-capsule-loopback"]
test-mctp-user-loopback = ["emulator-periph/test-mctp-user-loopback"]
63 changes: 51 additions & 12 deletions emulator/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,45 @@ 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-read-write-page",
feature = "test-flash-ctrl-erase-page",
feature = "test-flash-storage-read-write",
feature = "test-flash-storage-erase"
)) {
println!("[xs debug] flash test feature enabled with temp file");
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 {
Expand All @@ -428,7 +458,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,
Expand All @@ -437,9 +468,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
Expand Down
3 changes: 3 additions & 0 deletions emulator/periph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ serde.workspace = true
tock-registers.workspace = true
zerocopy.workspace = true

[dev-dependencies]
tempfile.workspace = true

[features]
default = []
test-i3c-constant-writes = []
Expand Down
Loading

0 comments on commit cf24629

Please sign in to comment.