Skip to content

Commit 1b64d90

Browse files
committed
uefi: Fix shell args when run from a script
The UEFI tool wouldn't get any arugments when run from a UEFI shell script. Manually runnning from the shell would work, but not from e.g. startup.nsh Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 67043cc commit 1b64d90

2 files changed

Lines changed: 8 additions & 36 deletions

File tree

framework_lib/src/commandline/uefi.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use alloc::vec::Vec;
66
use log::{debug, error, info, trace};
77
use uefi::prelude::BootServices;
88
use uefi::proto::shell_params::*;
9-
use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams, SearchType};
10-
use uefi::Identify;
9+
use uefi::Handle;
1110

1211
use crate::chromium_ec::commands::SetGpuSerialMagic;
1312
use crate::chromium_ec::{CrosEcDriverType, HardwareDeviceType};
@@ -16,40 +15,13 @@ use crate::commandline::Cli;
1615
use super::{ConsoleArg, FpBrightnessArg, InputDeckModeArg, RebootEcArg, TabletModeArg};
1716

1817
/// Get commandline arguments from UEFI environment
19-
pub fn get_args(boot_services: &BootServices) -> Vec<String> {
20-
// TODO: I think i should open this from the ImageHandle?
21-
let shell_params_h =
22-
boot_services.locate_handle_buffer(SearchType::ByProtocol(&ShellParameters::GUID));
23-
let shell_params_h = if let Ok(shell_params_h) = shell_params_h {
24-
shell_params_h
18+
pub fn get_args(bs: &BootServices, image_handle: Handle) -> Vec<String> {
19+
if let Ok(shell_params) = bs.open_protocol_exclusive::<ShellParameters>(image_handle) {
20+
shell_params.get_args()
2521
} else {
26-
error!("ShellParameters protocol not found");
27-
return vec![];
28-
};
29-
30-
for handle in &*shell_params_h {
31-
let params_handle = unsafe {
32-
boot_services
33-
.open_protocol::<ShellParameters>(
34-
OpenProtocolParams {
35-
handle: *handle,
36-
agent: boot_services.image_handle(),
37-
controller: None,
38-
},
39-
OpenProtocolAttributes::GetProtocol,
40-
)
41-
.expect("Failed to open ShellParameters handle")
42-
};
43-
44-
// Ehm why are there two and one has no args?
45-
// Maybe one is the shell itself?
46-
if params_handle.argc == 0 {
47-
continue;
48-
}
49-
50-
return params_handle.get_args();
22+
// No protocol found if the application wasn't executed by the shell
23+
vec![]
5124
}
52-
vec![]
5325
}
5426

5527
pub fn parse(args: &[String]) -> Cli {

framework_uefi/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ extern crate alloc;
1212
use framework_lib::commandline;
1313

1414
#[entry]
15-
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
15+
fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
1616
uefi_services::init(&mut system_table).unwrap();
1717
let bs = system_table.boot_services();
1818

19-
let args = commandline::uefi::get_args(bs);
19+
let args = commandline::uefi::get_args(bs, image_handle);
2020
let args = commandline::parse(&args);
2121
if commandline::run_with_args(&args, false) == 0 {
2222
return Status::SUCCESS;

0 commit comments

Comments
 (0)