diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 82d6c253..1ab55307 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -6,8 +6,7 @@ use alloc::vec::Vec; 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::Handle; use crate::chromium_ec::commands::SetGpuSerialMagic; use crate::chromium_ec::{CrosEcDriverType, HardwareDeviceType}; @@ -16,40 +15,13 @@ 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 { - // 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 +pub fn get_args(bs: &BootServices, image_handle: Handle) -> Vec { + if let Ok(shell_params) = bs.open_protocol_exclusive::(image_handle) { + shell_params.get_args() } else { - error!("ShellParameters protocol not found"); - return vec![]; - }; - - for handle in &*shell_params_h { - let params_handle = unsafe { - boot_services - .open_protocol::( - 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; - } - - return params_handle.get_args(); + // No protocol found if the application wasn't executed by the shell + vec![] } - vec![] } pub fn parse(args: &[String]) -> Cli { diff --git a/framework_uefi/Makefile b/framework_uefi/Makefile index a571ba17..76b03e5d 100644 --- a/framework_uefi/Makefile +++ b/framework_uefi/Makefile @@ -38,6 +38,9 @@ $(BUILD)/efi.img: $(BUILD)/boot.efi mkfs.vfat $@.tmp mmd -i $@.tmp efi mmd -i $@.tmp efi/boot + echo 'efi\boot\bootx64.efi --version' > startup.nsh + mcopy -i $@.tmp startup.nsh ::efi/boot/startup.nsh + rm -f startup.nsh mcopy -i $@.tmp $< ::efi/boot/bootx64.efi mv $@.tmp $@ diff --git a/framework_uefi/src/main.rs b/framework_uefi/src/main.rs index b81cbe63..caeeee2e 100644 --- a/framework_uefi/src/main.rs +++ b/framework_uefi/src/main.rs @@ -12,11 +12,11 @@ extern crate alloc; use framework_lib::commandline; #[entry] -fn main(_handle: Handle, mut system_table: SystemTable) -> Status { +fn main(image_handle: Handle, mut system_table: SystemTable) -> Status { uefi_services::init(&mut system_table).unwrap(); let bs = system_table.boot_services(); - let args = commandline::uefi::get_args(bs); + let args = commandline::uefi::get_args(bs, image_handle); let args = commandline::parse(&args); if commandline::run_with_args(&args, false) == 0 { return Status::SUCCESS;