Skip to content

Commit 462de06

Browse files
Merge pull request #1680 from RenTrieu/enhancement/efi_shell_protocol_uefi_raw
Updating Uefi Raw for EFI Shell Protocol
2 parents 9602a88 + a02420e commit 462de06

File tree

6 files changed

+212
-1
lines changed

6 files changed

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn test() {
4242
target_arch = "aarch64"
4343
))]
4444
shim::test();
45+
shell::test();
4546
tcg::test();
4647
}
4748

@@ -89,13 +90,14 @@ mod pci;
8990
mod pi;
9091
mod rng;
9192
mod scsi;
92-
mod shell_params;
9393
#[cfg(any(
9494
target_arch = "x86",
9595
target_arch = "x86_64",
9696
target_arch = "arm",
9797
target_arch = "aarch64"
9898
))]
99+
mod shell;
100+
mod shell_params;
99101
mod shim;
100102
mod string;
101103
mod tcg;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use uefi::boot;
4+
use uefi::proto::shell::Shell;
5+
6+
pub fn test() {
7+
info!("Running shell protocol tests");
8+
9+
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles");
10+
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 & 0 deletions
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;

uefi/src/proto/shell/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! EFI Shell Protocol v2.2
4+
5+
use crate::proto::unsafe_protocol;
6+
7+
pub use uefi_raw::protocol::shell::ShellProtocol;
8+
9+
/// Shell Protocol
10+
#[derive(Debug)]
11+
#[repr(transparent)]
12+
#[unsafe_protocol(uefi_raw::protocol::shell::ShellProtocol::GUID)]
13+
pub struct Shell(uefi_raw::protocol::shell::ShellProtocol);

0 commit comments

Comments
 (0)