diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 94e32b0b..ffa3766d 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -1508,6 +1508,12 @@ impl CrosEc { return Err(err); } }; + + // Need to explicitly handle CTRL-C termination on UEFI Shell + #[cfg(feature = "uefi")] + if shell_get_execution_break_flag() { + return Ok(console); + } } } diff --git a/framework_lib/src/fw_uefi/mod.rs b/framework_lib/src/fw_uefi/mod.rs index 82f823a4..872962a2 100644 --- a/framework_lib/src/fw_uefi/mod.rs +++ b/framework_lib/src/fw_uefi/mod.rs @@ -11,6 +11,19 @@ use uefi_raw::protocol::shell::ShellProtocol; pub mod fs; +/// Non-panicking print helper for UEFI. +/// +/// The uefi crate's `println!` calls `.expect()` on write results, which +/// panics when the UEFI shell's ConsoleLogger returns an error (e.g. after +/// the user presses 'q' during `-b` page break mode). This version silently +/// ignores write errors to avoid crashing. +#[doc(hidden)] +pub fn _print_safe(args: core::fmt::Arguments) { + uefi::system::with_stdout(|stdout| { + let _ = core::fmt::Write::write_fmt(stdout, args); + }); +} + fn get_shell_protocol() -> &'static ShellProtocol { let handle = boot::get_handle_for_protocol::().expect("No Shell handles"); @@ -39,7 +52,13 @@ fn get_shell_protocol() -> &'static ShellProtocol { /// Returns true when the execution break was requested, false otherwise pub fn shell_get_execution_break_flag() -> bool { let shell = get_shell_protocol(); - unsafe { (shell.get_page_break)().into() } + let raw_event = shell.execution_break; + // SAFETY: The execution_break event is created by the shell and remains valid + if let Some(event) = unsafe { uefi::Event::from_ptr(raw_event) } { + boot::check_event(event).unwrap_or(false) + } else { + false + } } /// Enable pagination in UEFI shell diff --git a/framework_lib/src/lib.rs b/framework_lib/src/lib.rs index 92764319..5da49205 100644 --- a/framework_lib/src/lib.rs +++ b/framework_lib/src/lib.rs @@ -31,9 +31,23 @@ pub mod touchscreen_win; pub mod usbhub; #[cfg(feature = "uefi")] -#[macro_use] extern crate uefi; +// Override uefi crate's print!/println! macros with non-panicking versions. +// The uefi crate's versions call .expect() on write results, which crashes +// when the UEFI shell returns an error after 'q' is pressed during -b pagination. +#[cfg(feature = "uefi")] +macro_rules! print { + ($($arg:tt)*) => ($crate::fw_uefi::_print_safe(core::format_args!($($arg)*))); +} +#[cfg(feature = "uefi")] +macro_rules! println { + () => ($crate::fw_uefi::_print_safe(core::format_args!("\n"))); + ($($arg:tt)*) => ($crate::fw_uefi::_print_safe( + core::format_args!("{}\n", core::format_args!($($arg)*)) + )); +} + pub mod capsule; pub mod capsule_content; pub mod ccgx;