Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion framework_lib/src/fw_uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Shell>().expect("No Shell handles");

Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion framework_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down