From 6d2dbc12df46f73333866403601cfbb53e309f45 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 5 May 2025 14:04:23 +0800 Subject: [PATCH 1/3] uefi: Handle break in --console recent Otherwise if you run `framework_tool.efi --console recent -b` and then stop at one of the screens, the app never exits. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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); + } } } From 946f74b67131c846bcf0825d6dab8f4d49a360d4 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 9 Mar 2026 01:27:03 +0800 Subject: [PATCH 2/3] uefi: Fix shell_get_execution_break_flag() to check execution_break event get_page_break only returns whether page break mode is enabled, not whether the user requested an execution break (e.g. by pressing 'q' during pagination or Ctrl+C). Use boot::check_event on the execution_break Event instead, matching the edk2 ShellGetExecutionBreakFlag implementation. Signed-off-by: Daniel Schaefer --- framework_lib/src/fw_uefi/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework_lib/src/fw_uefi/mod.rs b/framework_lib/src/fw_uefi/mod.rs index 82f823a4..6742022f 100644 --- a/framework_lib/src/fw_uefi/mod.rs +++ b/framework_lib/src/fw_uefi/mod.rs @@ -39,7 +39,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 From 00dc62782a86aac17cde376ad2015e1cc5654d9b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 9 Mar 2026 01:31:47 +0800 Subject: [PATCH 3/3] uefi: Fix crash when pressing 'q' during -b pagination The uefi crate's println! macro calls .expect() on write results. When the user presses 'q' during -b page break mode, the UEFI shell's ConsoleLogger disables output and returns EFI_DEVICE_ERROR for all subsequent writes. This causes the .expect() to panic, resulting in a page fault crash. Replace the uefi crate's print!/println! macros with non-panicking versions that silently ignore write errors, allowing the application to exit cleanly after the user breaks out of pagination. Signed-off-by: Daniel Schaefer --- framework_lib/src/fw_uefi/mod.rs | 13 +++++++++++++ framework_lib/src/lib.rs | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/framework_lib/src/fw_uefi/mod.rs b/framework_lib/src/fw_uefi/mod.rs index 6742022f..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"); 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;