Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: uefi support #896

Open
joholl opened this issue May 27, 2024 · 0 comments
Open

Feature request: uefi support #896

joholl opened this issue May 27, 2024 · 0 comments

Comments

@joholl
Copy link

joholl commented May 27, 2024

Problem

This crate is great! It would be even greater, if it supported uefi. Rust nightly contains much of std already, see this example in the official docs.

In the end, I would love to use ratatui on Linux/Windows/UEFI with crossterm as a backend.

Solution

What we already have:

Open questions:

  • I have not found features to enable alternate screen and raw mode (but I also lack deeper understanding of UEFI and what these modes do exactly)
  • I have not had a closer look at input/events

I do not know if this feature request makes sense because I have not a full understanding of UEFI, crossterm, ratatui and terminals in general.

Development

If you quickly want to spin up a Rust application using stdout on UEFI (qemu):

sudo apt install ovmf  # for qemu uefi image
rustup target add x86_64-unknown-uefi  # install cross-compile toolchain

cargo init
cargo add r-efi
# copy this example into main.rs: https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/unknown-uefi.md#example-hello-world-with-std
cargo build --target=x86_64-unknown-uefi
qemu-system-x86_64 -m 4G -cpu max -smp 4 -bios /usr/share/ovmf/OVMF.fd -nographic -no-reboot -nic none -drive file=fat:rw:./target/x86_64-unknown-uefi/debug,format=raw,media=disk
# type "<ESC>" to drop into shell
# type "fs0:" to change drive
# type "ls" to find your binary name: <...>.efi
# type "<...>.efi" to run application

PoC code for getting the terminal dimensions via query_mode:

let mut columns: usize = 0;
let mut rows: usize = 0;
let r = unsafe {
    let con_out: *mut simple_text_output::Protocol = (*system_table).con_out;
    let query_mode: extern "efiapi" fn(
        _: *mut simple_text_output::Protocol,
        usize,
        *mut usize,
        *mut usize,
    ) -> efi::Status = (*con_out).query_mode;

    let mode_number = 0;

    query_mode(
        con_out,
        mode_number,
        &mut columns as *mut _,
        &mut rows as *mut _,
    )
};
assert!(!r.is_error());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant