Skip to content

Update uefi to 0.35+ #184

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
68 changes: 27 additions & 41 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ default-members = [
"framework_tool",
]

# Need latest commit that hasn't been released yet
[patch.crates-io]
uefi = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" }
uefi-services = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" }
uefi = { git = "https://github.com/rust-osdev/uefi-rs", rev = "1fcf4d84d5ed10fe76055469b6df01318eb35af8" }
uefi-raw = { git = "https://github.com/rust-osdev/uefi-rs", rev = "1fcf4d84d5ed10fe76055469b6df01318eb35af8" }

[profile.release]
lto = true
3 changes: 1 addition & 2 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ rusb = { version = "0.9.4", optional = true }
guid-create = { git = "https://github.com/FrameworkComputer/guid-create", branch = "no-rand", default-features = false }

[target.'cfg(target_os = "uefi")'.dependencies]
uefi = { version = "0.20", features = ["alloc"] }
uefi-services = "0.17"
uefi = { version = "0.35", features = ["alloc", "global_allocator", "panic_handler", "logger"] }
plain = "0.2.3"
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn dump_winux_image(data: &[u8], header: &DisplayCapsule, filename: &str) {
}
#[cfg(feature = "uefi")]
{
let ret = crate::uefi::fs::shell_write_file(filename, image);
let ret = crate::fw_uefi::fs::shell_write_file(filename, image);
if let Err(err) = ret {
println!("Failed to dump winux image: {:?}", err);
}
Expand Down
4 changes: 2 additions & 2 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
//! - `windows` - It uses [DHowett's Windows driver](https://github.com/DHowett/FrameworkWindowsUtils)

use crate::ec_binary;
#[cfg(feature = "uefi")]
use crate::fw_uefi::shell_get_execution_break_flag;
use crate::os_specific;
use crate::power;
use crate::smbios;
#[cfg(feature = "uefi")]
use crate::uefi::shell_get_execution_break_flag;
use crate::util::{self, Platform};

use log::Level;
Expand Down
22 changes: 11 additions & 11 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ use crate::chromium_ec::{EcError, EcResult};
use crate::csme;
use crate::ec_binary;
use crate::esrt;
#[cfg(feature = "uefi")]
use crate::fw_uefi::enable_page_break;
#[cfg(feature = "rusb")]
use crate::inputmodule::check_inputmodule_version;
use crate::power;
Expand All @@ -57,8 +59,6 @@ use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
use crate::touchpad::print_touchpad_fw_ver;
#[cfg(feature = "hidapi")]
use crate::touchscreen;
#[cfg(feature = "uefi")]
use crate::uefi::enable_page_break;
use crate::util::{self, Config, Platform, PlatformFamily};
#[cfg(feature = "hidapi")]
use hidapi::HidApi;
Expand Down Expand Up @@ -639,7 +639,7 @@ fn print_esrt() {

fn flash_ec(ec: &CrosEc, ec_bin_path: &str, flash_type: EcFlashType, dry_run: bool) {
#[cfg(feature = "uefi")]
let data = crate::uefi::fs::shell_read_file(ec_bin_path);
let data = crate::fw_uefi::fs::shell_read_file(ec_bin_path);
#[cfg(not(feature = "uefi"))]
let data: Option<Vec<u8>> = {
match fs::read(ec_bin_path) {
Expand Down Expand Up @@ -674,7 +674,7 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
}
#[cfg(feature = "uefi")]
{
let ret = crate::uefi::fs::shell_write_file(dump_path, &flash_bin);
let ret = crate::fw_uefi::fs::shell_write_file(dump_path, &flash_bin);
if ret.is_err() {
println!("Failed to dump EC FW image.");
}
Expand All @@ -691,7 +691,7 @@ fn dump_dgpu_eeprom(ec: &CrosEc, dump_path: &str) {
}
#[cfg(feature = "uefi")]
{
let ret = crate::uefi::fs::shell_write_file(dump_path, &flash_bin);
let ret = crate::fw_uefi::fs::shell_write_file(dump_path, &flash_bin);
if ret.is_err() {
println!("Failed to dump EC FW image.");
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
// raw_command(&args[1..]);
} else if let Some(pd_bin_path) = &args.pd_bin {
#[cfg(feature = "uefi")]
let data: Option<Vec<u8>> = crate::uefi::fs::shell_read_file(pd_bin_path);
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(pd_bin_path);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(pd_bin_path) {
Ok(data) => Some(data),
Expand All @@ -1136,7 +1136,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
}
} else if let Some(ec_bin_path) = &args.ec_bin {
#[cfg(feature = "uefi")]
let data: Option<Vec<u8>> = crate::uefi::fs::shell_read_file(ec_bin_path);
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(ec_bin_path);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(ec_bin_path) {
Ok(data) => Some(data),
Expand All @@ -1155,7 +1155,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
}
} else if let Some(capsule_path) = &args.capsule {
#[cfg(feature = "uefi")]
let data: Option<Vec<u8>> = crate::uefi::fs::shell_read_file(capsule_path);
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(capsule_path);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(capsule_path) {
Ok(data) => Some(data),
Expand Down Expand Up @@ -1184,7 +1184,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
}
} else if let Some(capsule_path) = &args.h2o_capsule {
#[cfg(feature = "uefi")]
let data = crate::uefi::fs::shell_read_file(capsule_path);
let data = crate::fw_uefi::fs::shell_read_file(capsule_path);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(capsule_path) {
Ok(data) => Some(data),
Expand Down Expand Up @@ -1237,7 +1237,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
} else if let Some(hash_file) = &args.hash {
println!("Hashing file: {}", hash_file);
#[cfg(feature = "uefi")]
let data = crate::uefi::fs::shell_read_file(hash_file);
let data = crate::fw_uefi::fs::shell_read_file(hash_file);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(hash_file) {
Ok(data) => Some(data),
Expand Down Expand Up @@ -1266,7 +1266,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
Some(PlatformFamily::Framework16) | None
) {
#[cfg(feature = "uefi")]
let data: Option<Vec<u8>> = crate::uefi::fs::shell_read_file(gpu_descriptor_file);
let data: Option<Vec<u8>> = crate::fw_uefi::fs::shell_read_file(gpu_descriptor_file);
#[cfg(not(feature = "uefi"))]
let data = match fs::read(gpu_descriptor_file) {
Ok(data) => Some(data),
Expand Down
51 changes: 14 additions & 37 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use alloc::vec::Vec;

#[allow(unused_imports)]
use log::{debug, error, info, trace};
use uefi::prelude::BootServices;
use uefi::proto::shell_params::*;
use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams, SearchType};
use uefi::Identify;
use uefi::boot;
use uefi::proto::shell_params::ShellParameters;

use crate::chromium_ec::commands::SetGpuSerialMagic;
use crate::chromium_ec::{CrosEcDriverType, HardwareDeviceType};
Expand All @@ -16,40 +14,19 @@ use crate::commandline::Cli;
use super::{ConsoleArg, FpBrightnessArg, InputDeckModeArg, RebootEcArg, TabletModeArg};

/// Get commandline arguments from UEFI environment
pub fn get_args(boot_services: &BootServices) -> Vec<String> {
// TODO: I think i should open this from the ImageHandle?
let shell_params_h =
boot_services.locate_handle_buffer(SearchType::ByProtocol(&ShellParameters::GUID));
let shell_params_h = if let Ok(shell_params_h) = shell_params_h {
shell_params_h
} else {
error!("ShellParameters protocol not found");
return vec![];
};

for handle in &*shell_params_h {
let params_handle = unsafe {
boot_services
.open_protocol::<ShellParameters>(
OpenProtocolParams {
handle: *handle,
agent: boot_services.image_handle(),
controller: None,
},
OpenProtocolAttributes::GetProtocol,
)
.expect("Failed to open ShellParameters handle")
};

// Ehm why are there two and one has no args?
// Maybe one is the shell itself?
if params_handle.argc == 0 {
continue;
pub fn get_args() -> Vec<String> {
let shell_params = uefi::boot::open_protocol_exclusive::<ShellParameters>(boot::image_handle());
let shell_params = match shell_params {
Ok(s) => s,
Err(e) => {
error!("Failed to get ShellParameters protocol");
// TODO: Return result
// return e.status();
return vec![];
}

return params_handle.get_args();
}
vec![]
};
let args: Vec<String> = shell_params.args().map(|x| x.to_string()).collect();
args
}

pub fn parse(args: &[String]) -> Cli {
Expand Down
Loading
Loading