Skip to content

Commit

Permalink
✨ Feat: Update rust toolchain and uefi-rs dependency versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbings committed Dec 25, 2024
1 parent e6183b4 commit 4becd76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion canicula-efi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ path = "src/efi.rs"
[dependencies]
log = "0.4"
xmas-elf = "0.9.1"
uefi = { version = "0.28.0", features = ["logger", "panic_handler"] }
uefi = { version = "0.33.0", features = ["logger", "panic_handler"] }
35 changes: 16 additions & 19 deletions canicula-efi/src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,36 @@

mod config;

use boot::{AllocateType, MemoryType};
use log::info;
use uefi::{
prelude::*,
proto::media::{
file::{File, FileAttribute, FileInfo, FileMode, FileType},
fs::SimpleFileSystem,
},
table::boot::{AllocateType, MemoryType},
CStr16,
};
use xmas_elf::ElfFile;

use crate::config::x86_64::{FILE_BUFFER_SIZE, KERNEL_PATH, PAGE_SIZE};

#[entry]
fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
uefi::helpers::init(&mut system_table).unwrap();
fn main() -> Status {
uefi::helpers::init().unwrap();
info!("Canicula: Starting the UEFI bootloader...");
info!(
"config: file_buffer_size = {}, page_size = {}, kernel_path = {}",
FILE_BUFFER_SIZE, PAGE_SIZE, KERNEL_PATH
);

// load boot table
let boot_services = system_table.boot_services();

// load simple file system protocol
let simple_file_system_handle = boot_services
.get_handle_for_protocol::<SimpleFileSystem>()
let simple_file_system_handle = uefi::boot::get_handle_for_protocol::<SimpleFileSystem>()
.expect("Cannot get protocol handle");

let mut simple_file_system_protocol = boot_services
.open_protocol_exclusive::<SimpleFileSystem>(simple_file_system_handle)
.expect("Cannot get simple file system protocol");
let mut simple_file_system_protocol =
uefi::boot::open_protocol_exclusive::<SimpleFileSystem>(simple_file_system_handle)
.expect("Cannot get simple file system protocol");

// open volume
let mut root = simple_file_system_protocol
Expand Down Expand Up @@ -67,13 +63,14 @@ fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
info!("Kernel file size: {:?}", kernel_file_size);

// load kernel file into memory
let kernel_file_address = boot_services
.allocate_pages(
AllocateType::AnyPages,
MemoryType::LOADER_DATA,
kernel_file_size / PAGE_SIZE + 1,
)
.expect("Cannot allocate memory in the RAM!") as *mut u8;
let mut kernel_file_address = uefi::boot::allocate_pages(
AllocateType::AnyPages,
MemoryType::LOADER_DATA,
kernel_file_size / PAGE_SIZE + 1,
)
.expect("Cannot allocate memory in the RAM!");

let kernel_file_address = unsafe { kernel_file_address.as_mut() as *mut u8 };

let kernel_file_in_memory = unsafe {
core::ptr::write_bytes(kernel_file_address, 0, kernel_file_size);
Expand All @@ -100,6 +97,6 @@ fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
core::arch::asm!("jmp {}", in(reg) kernel_entry_address);
}

boot_services.stall(10_000_000);
uefi::boot::stall(10_000_000);
Status::SUCCESS
}
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
profile = "default"
# use the nightly version of the last stable toolchain, see <https://forge.rust-lang.org/>
channel = "nightly-2024-12-17"
components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"]

0 comments on commit 4becd76

Please sign in to comment.