Skip to content

Commit 4772497

Browse files
RenTrieuphip1611
andcommitted
uefi-raw: Add EFI Shell Protocol
Co-authored-by: Philipp Schuster <phip1611@gmail.com>
1 parent 5f75bed commit 4772497

File tree

6 files changed

+191
-426
lines changed

6 files changed

+191
-426
lines changed

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod nvme;
2424
pub mod pci;
2525
pub mod rng;
2626
pub mod scsi;
27+
pub mod shell;
2728
pub mod shell_params;
2829
pub mod string;
2930
pub mod tcg;

uefi-raw/src/protocol/shell.rs

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! EFI Shell Protocol v2.2
4+
5+
use core::ffi::c_void;
6+
7+
use crate::{Char8, Char16, Event, Guid, Handle, Status, guid};
8+
9+
use super::device_path::DevicePathProtocol;
10+
use super::file_system::FileInfo;
11+
use super::shell_params::ShellFileHandle;
12+
13+
/// List Entry for File Lists
14+
#[derive(Debug)]
15+
#[repr(C)]
16+
pub struct ListEntry<'a> {
17+
pub f_link: *mut ListEntry<'a>,
18+
pub b_link: *mut ListEntry<'a>,
19+
}
20+
21+
/// ShellFileInfo for File Lists
22+
#[derive(Debug)]
23+
#[repr(C)]
24+
pub struct ShellFileInfo<'a> {
25+
pub link: ListEntry<'a>,
26+
pub status: Status,
27+
pub full_name: *mut Char16,
28+
pub file_name: *mut Char16,
29+
pub shell_file_handle: Handle,
30+
pub file_info: FileInfo,
31+
}
32+
33+
/// Used to specify where component names should be taken from
34+
pub type ShellDeviceNameFlags = u32;
35+
pub const DEVICE_NAME_USE_COMPONENT_NAME: u32 = 0x0000001;
36+
pub const DEVICE_NAME_USE_DEVICE_PATH: u32 = 0x0000002;
37+
38+
/// Shell Protocol
39+
#[derive(Debug)]
40+
#[repr(C)]
41+
pub struct ShellProtocol {
42+
pub execute: unsafe extern "efiapi" fn(
43+
parent_image_handle: *const Handle,
44+
command_line: *const Char16,
45+
environment: *const *const Char16,
46+
status_code: *mut Status,
47+
) -> Status,
48+
pub get_env: unsafe extern "efiapi" fn(name: *const Char16) -> *const Char16,
49+
pub set_env: unsafe extern "efiapi" fn(
50+
name: *const Char16,
51+
value: *const Char16,
52+
volatile: bool,
53+
) -> Status,
54+
pub get_alias: unsafe extern "efiapi" fn(alias: *const Char16, volatile: bool) -> *const Char16,
55+
pub set_alias: unsafe extern "efiapi" fn(
56+
command: *const Char16,
57+
alias: *const Char16,
58+
replace: bool,
59+
volatile: bool,
60+
) -> Status,
61+
pub get_help_text: unsafe extern "efiapi" fn(
62+
command: *const Char16,
63+
sections: *const Char16,
64+
help_text: *mut *mut Char16,
65+
) -> Status,
66+
pub get_device_path_from_map:
67+
unsafe extern "efiapi" fn(mapping: *const Char16) -> DevicePathProtocol,
68+
pub get_map_from_device_path:
69+
unsafe extern "efiapi" fn(device_path: *mut *mut DevicePathProtocol) -> *const Char16,
70+
pub get_device_path_from_file_path:
71+
unsafe extern "efiapi" fn(path: *const Char16) -> DevicePathProtocol,
72+
pub get_file_path_from_device_path:
73+
unsafe extern "efiapi" fn(path: *const DevicePathProtocol) -> *const Char16,
74+
pub set_map: unsafe extern "efiapi" fn(
75+
device_path: DevicePathProtocol,
76+
mapping: *const Char16,
77+
) -> Status,
78+
79+
pub get_cur_dir: unsafe extern "efiapi" fn(file_system_mapping: *const Char16) -> *const Char16,
80+
pub set_cur_dir:
81+
unsafe extern "efiapi" fn(file_system: *const Char16, dir: *const Char16) -> Status,
82+
pub open_file_list: unsafe extern "efiapi" fn(
83+
path: Char16,
84+
open_mode: u64,
85+
file_list: *mut *mut ShellFileInfo,
86+
) -> Status,
87+
pub free_file_list: unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status,
88+
pub remove_dup_in_file_list:
89+
unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status,
90+
91+
pub batch_is_active: unsafe extern "efiapi" fn() -> bool,
92+
pub is_root_shell: unsafe extern "efiapi" fn() -> bool,
93+
pub enable_page_break: unsafe extern "efiapi" fn(),
94+
pub disable_page_break: unsafe extern "efiapi" fn(),
95+
pub get_page_break: unsafe extern "efiapi" fn() -> bool,
96+
pub get_device_name: unsafe extern "efiapi" fn(
97+
device_handle: Handle,
98+
flags: ShellDeviceNameFlags,
99+
language: *const Char8,
100+
best_device_name: *mut *mut Char16,
101+
) -> Status,
102+
103+
pub get_file_info: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> FileInfo,
104+
pub set_file_info: unsafe extern "efiapi" fn(
105+
file_handle: ShellFileHandle,
106+
file_info: *const FileInfo,
107+
) -> Status,
108+
pub open_file_by_name: unsafe extern "efiapi" fn(
109+
file_name: *const Char16,
110+
file_handle: *mut ShellFileHandle,
111+
open_mode: u64,
112+
) -> Status,
113+
pub close_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status,
114+
pub create_file: unsafe extern "efiapi" fn(
115+
file_name: *const Char16,
116+
file_attribs: u64,
117+
file_handle: *mut ShellFileHandle,
118+
) -> Status,
119+
pub read_file: unsafe extern "efiapi" fn(
120+
file_handle: ShellFileHandle,
121+
read_size: *mut usize,
122+
buffer: *mut c_void,
123+
) -> Status,
124+
pub write_file: unsafe extern "efiapi" fn(
125+
file_handle: ShellFileHandle,
126+
buffer_size: *mut usize,
127+
buffer: *mut c_void,
128+
) -> Status,
129+
pub delete_file: unsafe extern "efiapi" fn(file_name: *const Char16) -> Status,
130+
pub delete_file_by_name: unsafe extern "efiapi" fn(file_name: *const Char16) -> Status,
131+
pub get_file_position:
132+
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: *mut u64) -> Status,
133+
pub set_file_position:
134+
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: u64) -> Status,
135+
pub flush_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status,
136+
pub find_files: unsafe extern "efiapi" fn(
137+
file_pattern: *const Char16,
138+
file_list: *mut *mut ShellFileInfo,
139+
) -> Status,
140+
pub find_files_in_dir: unsafe extern "efiapi" fn(
141+
file_dir_handle: ShellFileHandle,
142+
file_list: *mut *mut ShellFileInfo,
143+
) -> Status,
144+
pub get_file_size:
145+
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, size: *mut u64) -> Status,
146+
147+
pub open_root: unsafe extern "efiapi" fn(
148+
device_path: *const DevicePathProtocol,
149+
file_handle: *mut ShellFileHandle,
150+
) -> Status,
151+
pub open_root_by_handle: unsafe extern "efiapi" fn(
152+
device_handle: Handle,
153+
file_handle: *mut ShellFileHandle,
154+
) -> Status,
155+
156+
pub execution_break: Event,
157+
158+
pub major_version: u32,
159+
pub minor_version: u32,
160+
pub register_guid_name:
161+
unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *const Char16) -> Status,
162+
pub get_guid_name:
163+
unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *mut *mut Char16) -> Status,
164+
pub get_guid_from_name:
165+
unsafe extern "efiapi" fn(guid_name: *const Char16, guid: *mut Guid) -> Status,
166+
pub get_env_ex:
167+
unsafe extern "efiapi" fn(name: *const Char16, attributes: *mut u32) -> *const Char16,
168+
}
169+
170+
impl ShellProtocol {
171+
pub const GUID: Guid = guid!("6302d008-7f9b-4f30-87ac-60c9fef5da4e");
172+
}

uefi-test-runner/src/proto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ mod pci;
9090
mod pi;
9191
mod rng;
9292
mod scsi;
93-
mod shell_params;
9493
#[cfg(any(
9594
target_arch = "x86",
9695
target_arch = "x86_64",
9796
target_arch = "arm",
9897
target_arch = "aarch64"
9998
))]
10099
mod shell;
100+
mod shell_params;
101101
mod shim;
102102
mod string;
103103
mod tcg;

uefi-test-runner/src/proto/shell.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
use uefi::CStr16;
2-
use uefi::prelude::BootServices;
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use uefi::boot;
34
use uefi::proto::shell::Shell;
45

5-
pub fn test(bt: &BootServices) {
6+
pub fn test() {
67
info!("Running shell protocol tests");
78

8-
let handle = bt.get_handle_for_protocol::<Shell>().expect("No Shell handles");
9-
10-
let mut shell = bt
11-
.open_protocol_exclusive::<Shell>(handle)
12-
.expect("Failed to open Shell protocol");
13-
14-
// create some files
15-
let mut test_buf = [0u16; 12];
16-
let test_str = CStr16::from_str_with_buf("test", &mut test_buf).unwrap();
17-
shell.create_file(test_str, 0);
18-
19-
// get file tree
20-
let mut str_buf = [0u16; 12];
21-
let str_str = CStr16::from_str_with_buf(r"fs0:\*", &mut str_buf).unwrap();
22-
let res = shell.find_files(str_str);
23-
let list = res.unwrap();
24-
let list = list.unwrap();
25-
let first = list.first();
9+
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles");
2610

27-
info!("filetree test successful")
28-
}
11+
let mut _shell =
12+
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol");
13+
}

uefi/src/proto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub mod rng;
2828
#[cfg(feature = "alloc")]
2929
pub mod scsi;
3030
pub mod security;
31+
pub mod shell;
3132
pub mod shell_params;
3233
pub mod shim;
3334
pub mod string;
@@ -101,4 +102,3 @@ where
101102
ptr.cast::<Self>()
102103
}
103104
}
104-

0 commit comments

Comments
 (0)