Skip to content
Open
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
80 changes: 61 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions uefi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository.workspace = true
bootloader_api = { workspace = true }
bootloader-x86_64-common = { workspace = true }
bootloader-boot-config = { workspace = true }
log = "0.4.14"
x86_64 = "0.15.2"
serde-json-core = "0.5.0"
uefi = "0.38.0"
log = "0.4.35"
x86_64 = "0.15.5"
serde-json-core = "0.7.0"
uefi = "0.41.0"
82 changes: 82 additions & 0 deletions uefi/src/graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use bootloader_api::info::FrameBufferInfo;
use bootloader_boot_config::BootConfig;
use bootloader_x86_64_common::RawFrameBufferInfo;
use core::slice;
use uefi::boot::SearchType;
use uefi::proto::console::serial::Serial;
use uefi::{
Identify, boot,
proto::console::gop::{GraphicsOutput, PixelFormat},
};
use x86_64::PhysAddr;

pub fn init_logger(config: &BootConfig) -> Option<RawFrameBufferInfo> {
let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>().ok()?;
let mut gop = boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle).ok()?;

let mode = {
let modes = gop.modes();
match (
config
.frame_buffer
.minimum_framebuffer_height
.map(|v| usize::try_from(v).unwrap()),
config
.frame_buffer
.minimum_framebuffer_width
.map(|v| usize::try_from(v).unwrap()),
) {
(Some(height), Some(width)) => modes
.filter(|m| {
let res = m.info().resolution();
res.1 >= height && res.0 >= width
})
.last(),
(Some(height), None) => modes.filter(|m| m.info().resolution().1 >= height).last(),
(None, Some(width)) => modes.filter(|m| m.info().resolution().0 >= width).last(),
_ => None,
}
};
if let Some(mode) = mode {
gop.set_mode(&mode)
.expect("Failed to apply the desired display mode");
}

let mode_info = gop.current_mode_info();
let mut framebuffer = gop.frame_buffer();
let slice = unsafe { slice::from_raw_parts_mut(framebuffer.as_mut_ptr(), framebuffer.size()) };
let info = FrameBufferInfo {
byte_len: framebuffer.size(),
width: mode_info.resolution().0,
height: mode_info.resolution().1,
pixel_format: match mode_info.pixel_format() {
PixelFormat::Rgb => bootloader_api::info::PixelFormat::Rgb,
PixelFormat::Bgr => bootloader_api::info::PixelFormat::Bgr,
PixelFormat::Bitmask | PixelFormat::BltOnly => {
panic!("Bitmask and BltOnly framebuffers are not supported")
}
},
bytes_per_pixel: 4,
stride: mode_info.stride(),
};

// Disconnect the UEFI console from the serial device.
// Our own logger takes full ownership of the serial device.
if let Ok(handles) = boot::locate_handle_buffer(SearchType::ByProtocol(&Serial::GUID)) {
for handle in handles.iter() {
let _ = boot::disconnect_controller(*handle, None, None);
}
}
bootloader_x86_64_common::init_logger(
slice,
info,
config.log_level,
config.frame_buffer_logging,
config.serial_logging,
);

Some(RawFrameBufferInfo {
addr: PhysAddr::new(framebuffer.as_mut_ptr() as u64),
info,
})
}
Loading
Loading