@@ -8,12 +8,7 @@ use log::error;
8
8
// ANCHOR: use
9
9
//use log::info;
10
10
use uefi:: CStr16 ;
11
- use uefi:: {
12
- prelude:: * ,
13
- proto:: shell_params:: ShellParameters ,
14
- table:: boot:: { OpenProtocolAttributes , OpenProtocolParams , SearchType } ,
15
- Identify ,
16
- } ;
11
+ use uefi:: { prelude:: * , proto:: shell_params:: ShellParameters } ;
17
12
use uefi_services:: println;
18
13
19
14
extern crate alloc;
@@ -23,55 +18,34 @@ use alloc::vec::Vec;
23
18
24
19
// ANCHOR: entry
25
20
#[ entry]
26
- fn main ( _image_handle : Handle , mut system_table : SystemTable < Boot > ) -> Status {
21
+ fn main ( image_handle : Handle , mut system_table : SystemTable < Boot > ) -> Status {
27
22
// ANCHOR_END: entry
28
23
// ANCHOR: services
29
24
uefi_services:: init ( & mut system_table) . unwrap ( ) ;
30
25
let boot_services = system_table. boot_services ( ) ;
31
26
// ANCHOR_END: services
32
27
33
28
// ANCHOR: params
34
- let shell_params_h = boot_services
35
- . locate_handle_buffer ( SearchType :: ByProtocol ( & ShellParameters :: GUID ) ) ;
36
- let shell_params_h = match shell_params_h {
29
+ let shell_params =
30
+ boot_services . open_protocol_exclusive :: < ShellParameters > ( image_handle ) ;
31
+ let shell_params = match shell_params {
37
32
Ok ( s) => s,
38
33
Err ( e) => {
39
34
error ! ( "Failed to get ShellParameters protocol" ) ;
40
35
return e. status ( ) ;
41
36
}
42
37
} ;
43
- println ! ( "Found {} ShellParams handles" , ( * shell_params_h) . len( ) ) ;
44
- for handle in & * shell_params_h {
45
- let params_handle = unsafe {
46
- boot_services
47
- . open_protocol :: < ShellParameters > (
48
- OpenProtocolParams {
49
- handle : * handle,
50
- agent : boot_services. image_handle ( ) ,
51
- controller : None ,
52
- } ,
53
- OpenProtocolAttributes :: GetProtocol ,
54
- )
55
- . expect ( "Failed to open ShellParams handle" )
56
- } ;
57
38
58
- // TODO: Ehm why are there two and one has no args?
59
- // Maybe one is the shell itself?
60
- if params_handle. argc == 0 {
61
- continue ;
62
- }
63
-
64
- // Get as Vec of String, only with alloc feature
65
- let args: Vec < String > = params_handle. get_args ( ) . collect ( ) ;
66
- println ! ( "Args: {:?}" , args) ;
39
+ // Get as Vec of String, only with alloc feature
40
+ let args: Vec < String > = shell_params. get_args ( ) . collect ( ) ;
41
+ println ! ( "Args: {:?}" , args) ;
67
42
68
- // Or without allocating, get a slice of the pointers
69
- let args = params_handle. get_args_slice ( ) ;
70
- println ! ( "Num args: {}" , args. len( ) ) ;
71
- if args. len ( ) > 1 {
72
- unsafe {
73
- println ! ( "First real arg: '{}'" , CStr16 :: from_ptr( args[ 1 ] ) ) ;
74
- }
43
+ // Or without allocating, get a slice of the pointers
44
+ let args = shell_params. get_args_slice ( ) ;
45
+ println ! ( "Num args: {}" , args. len( ) ) ;
46
+ if args. len ( ) > 1 {
47
+ unsafe {
48
+ println ! ( "First real arg: '{}'" , CStr16 :: from_ptr( args[ 1 ] ) ) ;
75
49
}
76
50
}
77
51
// ANCHOR_END: params
0 commit comments