Skip to content

Commit 2b4f7f0

Browse files
[rescue,test] Enhance rescue error handling tests
This commit expands the end-to-end tests for rescue error handling: - Adds a rescue_image_too_big test for Xmodem to check the handling of oversized firmware images during rescue, ensuring the device correctly cancels the operation and remains functional. - Modifies the `usb_dfu_out_chunk_too_big` test to first perform a successful chunk download before attempting an oversized one, improving test robustness. Signed-off-by: Anthony Chen <[email protected]>
1 parent 382e702 commit 2b4f7f0

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ opentitan_test(
777777
"//hw/top_earlgrey:fpga_cw340_rom_ext": None,
778778
},
779779
fpga = fpga_params(
780+
timeout = "long",
780781
assemble = "{romext}@{rom_ext_slot_a} {firmware}@{owner_slot_a}",
781782
binaries = {
782783
"//sw/device/silicon_creator/rom_ext:rom_ext_dice_x509_slot_a": "romext",

sw/host/tests/rescue/dfu_rescue_error_handling.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ fn invalid_spi_flash_transaction(
311311
fn usb_dfu_out_chunk_too_big(params: &RescueParams, transport: &TransportWrapper) -> Result<()> {
312312
let rescue = UsbDfu::new(params.clone());
313313
rescue.enter(transport, EntryMode::Reset)?;
314-
rescue.set_mode(RescueMode::Rescue)?;
315-
let data = vec![0u8; 4096];
316-
let result = rescue.download(&data);
314+
rescue.set_mode(RescueMode::RescueB)?;
315+
let chunk = vec![0u8; 2048];
316+
let chunk_too_big = vec![0u8; 4096];
317+
318+
rescue.download(&chunk)?;
319+
let result = rescue.download(&chunk_too_big);
317320

318321
if result.is_ok() {
319322
return Err(anyhow!("USB transaction should fail"));

sw/host/tests/rescue/xmodem_rescue_error_handling.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#![allow(clippy::bool_assert_comparison)]
6-
use anyhow::Result;
6+
use anyhow::{anyhow, Result};
77
use clap::Parser;
88

99
use std::rc::Rc;
1010
use std::time::Duration;
1111

1212
use opentitanlib::app::TransportWrapper;
13+
use opentitanlib::chip::boot_svc::BootSlot;
1314
use opentitanlib::io::uart::Uart;
1415
use opentitanlib::rescue::xmodem::XmodemError;
1516
use opentitanlib::rescue::{EntryMode, Rescue, RescueMode, RescueSerial};
@@ -343,6 +344,32 @@ fn recv_finish_nak(
343344
Ok(())
344345
}
345346

347+
fn rescue_image_too_big(
348+
transport: &TransportWrapper,
349+
uart: &dyn Uart,
350+
rescue: &RescueSerial,
351+
) -> Result<()> {
352+
rescue.enter(transport, EntryMode::Reset)?;
353+
let image_too_big = [0u8; 1026*1024];
354+
match rescue.update_firmware(BootSlot::SlotB, &image_too_big) {
355+
Ok(_) => {
356+
return Err(anyhow!("Expects cancel during firmware rescue, but got OK."));
357+
}
358+
Err(e) => {
359+
if e.to_string().contains("Cancelled") {
360+
log::info!("Operation cancelled by device as expected");
361+
} else {
362+
return Err(e);
363+
}
364+
}
365+
};
366+
// Check for kErrorRescueImageTooBig.
367+
UartConsole::wait_for(uart, r"BFV:02525309", Duration::from_secs(5))?;
368+
// Ensure we can still boot into Owner SW.
369+
UartConsole::wait_for(uart, r"Finished", Duration::from_secs(5))?;
370+
Ok(())
371+
}
372+
346373
fn main() -> Result<()> {
347374
let opts = Opts::parse();
348375
opts.init.init_logging();
@@ -361,5 +388,6 @@ fn main() -> Result<()> {
361388
recv_data_cancel(&transport, &*uart, &rescue)?;
362389
recv_data_nak(&transport, &*uart, &rescue)?;
363390
recv_finish_nak(&transport, &*uart, &rescue)?;
391+
rescue_image_too_big(&transport, &*uart, &rescue)?;
364392
Ok(())
365393
}

0 commit comments

Comments
 (0)