From efe847d733efd489776c75ca7dbcea01bc60f8ae Mon Sep 17 00:00:00 2001 From: Nick Rirush Date: Sun, 4 Nov 2018 18:07:31 +0800 Subject: [PATCH] Successfully read first three bytes of bootloader file from vfs --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c3cb4e..469b6a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "coonboot" version = "0.1.0" dependencies = [ + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "uefi 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)", "uefi-alloc 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)", "uefi-exts 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)", diff --git a/Cargo.toml b/Cargo.toml index c211d58..b88e219 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ uefi-alloc = { git = "https://github.com/GabrielMajeri/uefi-rs" } uefi-exts = { git = "https://github.com/GabrielMajeri/uefi-rs" } uefi-logger = { git = "https://github.com/GabrielMajeri/uefi-rs" } uefi-services = { git = "https://github.com/GabrielMajeri/uefi-rs" } +log = { version = "0.4", default-features = false } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 64a35e8..5d28717 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,48 @@ #![no_std] #![no_main] +#![feature(alloc)] extern crate uefi; extern crate uefi_alloc; -extern crate uefi_services; extern crate uefi_exts; extern crate uefi_logger; +extern crate uefi_services; +#[macro_use] +extern crate log; +extern crate alloc; use uefi::prelude::*; +use uefi::proto::media::file::{FileAttribute, FileMode}; +use uefi::proto::media::fs::SimpleFileSystem; +use uefi_exts::BootServicesExt; #[no_mangle] -pub extern "win64" fn uefi_start(image: uefi::Handle, table: SystemTable) -> Status { - uefi_services::init(&table).expect_success("Unable to initialize utilities"); - table.stdout().reset(false).expect_success("Failed to reset stdout"); +pub extern "win64" fn uefi_start(_image: uefi::Handle, table: SystemTable) -> Status { + uefi_services::init(&table).expect_success("Failed to initialize utilities"); + table + .stdout() + .reset(false) + .expect_success("Failed to reset stdout"); + + let fs = table + .boot_services() + .find_protocol::() + .expect("Failed to resolve filesystem") + .get(); + unsafe { + let mut file = (*fs).open_volume().expect("Failed to open root").unwrap(); + let mut file = file + .open( + "\\EFI\\coonboot.efi", + FileMode::READ, + FileAttribute::empty(), + ) + .unwrap() + .unwrap(); + let mut buf: [u8; 3] = [0, 0, 0]; + file.read(&mut buf).unwrap().unwrap(); + info!("First three bytes of coonboot.efi: {:?}", buf); + } Status::SUCCESS }