Skip to content

Commit c3fc9e0

Browse files
committed
uefi-raw: Add FirmwareVolume{,Block}2Protocol
Ref: UEFI-PI 1.9: III-3.4.1 Firmware Volume2 Protocol Ref: UEFI-PI 1.9: III-3.4.2 Firmware Volume Block2 Protocol Signed-off-by: Tim Crawford <[email protected]>
1 parent 1e5380e commit c3fc9e0

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Added `protocol::string::UnicodeCollationProtocol`.
66
- Added `protocol::tcg` module, containing the TCG v1 and v2 protocols.
77
- Added `DriverBindingProtocol`.
8+
- Added `FirmwareVolume2Protocol`.
9+
- Added `FirmwareVolumeBlock2Protocol`.
810

911

1012
# uefi-raw - 0.9.0 (2024-10-23)
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
use crate::firmware_storage::FirmwareVolumeAttributes;
2+
use crate::protocol::block::Lba;
3+
use crate::{guid, Guid, Handle, PhysicalAddress, Status};
4+
use core::ffi::c_void;
5+
6+
// EFI_FV_ATTRIBUTES
7+
bitflags::bitflags! {
8+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
9+
#[repr(transparent)]
10+
pub struct FvAttributes: u64 {
11+
const READ_DISABLE_CAP = 1 << 0;
12+
const READ_ENABLE_CAP = 1 << 1;
13+
const READ_STATUS = 1 << 2;
14+
15+
const WRITE_DISABLE_CAP = 1 << 3;
16+
const WRITE_ENABLE_CAP = 1 << 4;
17+
const WRITE_STATUS = 1 << 5;
18+
19+
const LOCK_CAP = 1 << 6;
20+
const LOCK_STATUS = 1 << 7;
21+
const WRITE_POLICY_RELIABLE = 1 << 8;
22+
const READ_LOCK_CAP = 1 << 12;
23+
const READ_LOCK_STATUS = 1 << 13;
24+
const WRITE_LOCK_CAP = 1 << 14;
25+
const WRITE_LOCK_STATUS = 1 << 15;
26+
27+
const ALIGNMENT = 0x1F << 16;
28+
const ALIGNMENT_1 = 0x00 << 16;
29+
const ALIGNMENT_2 = 0x01 << 16;
30+
const ALIGNMENT_4 = 0x02 << 16;
31+
const ALIGNMENT_8 = 0x03 << 16;
32+
const ALIGNMENT_16 = 0x04 << 16;
33+
const ALIGNMENT_32 = 0x05 << 16;
34+
const ALIGNMENT_64 = 0x06 << 16;
35+
const ALIGNMENT_128 = 0x07 << 16;
36+
const ALIGNMENT_256 = 0x08 << 16;
37+
const ALIGNMENT_512 = 0x09 << 16;
38+
const ALIGNMENT_1K = 0x0A << 16;
39+
const ALIGNMENT_2K = 0x0B << 16;
40+
const ALIGNMENT_4K = 0x0C << 16;
41+
const ALIGNMENT_8K = 0x0D << 16;
42+
const ALIGNMENT_16K = 0x0E << 16;
43+
const ALIGNMENT_32K = 0x0F << 16;
44+
const ALIGNMENT_64K = 0x10 << 16;
45+
const ALIGNMENT_128K = 0x11 << 16;
46+
const ALIGNMENT_256K = 0x12 << 16;
47+
const ALIGNMENT_512K = 0x13 << 16;
48+
const ALIGNMENT_1M = 0x14 << 16;
49+
const ALIGNMENT_2M = 0x15 << 16;
50+
const ALIGNMENT_4M = 0x16 << 16;
51+
const ALIGNMENT_8M = 0x17 << 16;
52+
const ALIGNMENT_16M = 0x18 << 16;
53+
const ALIGNMENT_32M = 0x19 << 16;
54+
const ALIGNMENT_64M = 0x1A << 16;
55+
const ALIGNMENT_128M = 0x1B << 16;
56+
const ALIGNMENT_256M = 0x1C << 16;
57+
const ALIGNMENT_512M = 0x1D << 16;
58+
const ALIGNMENT_1G = 0x1E << 16;
59+
const ALIGNMENT_2G = 0x1F << 16;
60+
}
61+
}
62+
63+
// EFI_FV_FILE_ATTRIBUTES
64+
bitflags::bitflags! {
65+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
66+
#[repr(transparent)]
67+
pub struct FvFileAttributes: u32 {
68+
const ALIGNMENT = 0x1F;
69+
const FIXED = 1 << 8;
70+
const MEMORY_MAPPED = 1 << 9;
71+
}
72+
}
73+
74+
// EFI_FV_WRITE_POLICY
75+
newtype_enum! {
76+
pub enum FvWritePolicy: u32 => {
77+
EFI_FV_UNRELIABLE_WRITE = 0,
78+
EFI_FV_RELIABLE_WRITE = 1,
79+
}
80+
}
81+
82+
// EFI_FV_FILETYPE
83+
pub type FvFiletype = u8;
84+
85+
// EFI_SECTION_TYPE
86+
newtype_enum! {
87+
pub enum SectionType: u8 => {
88+
ALL = 0x00,
89+
COMPRESSION = 0x01,
90+
GUID_DEFINED = 0x02,
91+
DISPOSABLE = 0x03,
92+
PE32 = 0x10,
93+
PIC = 0x11,
94+
TE = 0x12,
95+
DXE_DEPEX = 0x13,
96+
VERSION = 0x14,
97+
USER_INTERFACE = 0x15,
98+
COMPATIBILITY16 = 0x16,
99+
FIRMWARE_VOLUME_IMAGE = 0x17,
100+
FREEFORM_SUBTYPE_GUID = 0x18,
101+
RAW = 0x19,
102+
PEI_DEPEX = 0x1B,
103+
MM_DEPEX = 0x1C,
104+
}
105+
}
106+
107+
// EFI_FV_WRITE_FILE_DATA
108+
#[derive(Debug)]
109+
#[repr(C)]
110+
pub struct FvWriteFileData {
111+
pub name_guid: *const Guid,
112+
pub r#type: FvFiletype,
113+
pub file_attributes: FvFileAttributes,
114+
pub buffer: *const u8,
115+
pub buffer_size: u32,
116+
}
117+
118+
// EFI_FIRMWARE_VOLUME2_PROTOCOL
119+
#[derive(Debug)]
120+
#[repr(C)]
121+
pub struct FirmwareVolume2Protocol {
122+
pub get_volume_attributes:
123+
unsafe extern "efiapi" fn(this: *const Self, fv_attributes: *mut FvAttributes) -> Status,
124+
pub set_volume_attributes:
125+
unsafe extern "efiapi" fn(this: *const Self, fv_attributes: *mut FvAttributes) -> Status,
126+
pub read_file: unsafe extern "efiapi" fn(
127+
this: *const Self,
128+
name_guid: *const Guid,
129+
buffer: *mut *mut c_void,
130+
buffer_size: *mut usize,
131+
found_type: *mut FvFiletype,
132+
file_attributes: *mut FvFileAttributes,
133+
authentication_status: *mut u32,
134+
) -> Status,
135+
pub read_section: unsafe extern "efiapi" fn(
136+
this: *const Self,
137+
name_guid: *const Guid,
138+
section_type: SectionType,
139+
section_instance: usize,
140+
buffer: *mut *mut c_void,
141+
buffer_size: *mut usize,
142+
authentication_status: *mut u32,
143+
) -> Status,
144+
pub write_file: unsafe extern "efiapi" fn(
145+
this: *const Self,
146+
number_of_files: u32,
147+
write_policy: FvWritePolicy,
148+
file_data: *const FvWriteFileData,
149+
) -> Status,
150+
pub get_next_file: unsafe extern "efiapi" fn(
151+
this: *const Self,
152+
key: *mut c_void,
153+
file_type: *mut FvFiletype,
154+
name_guid: *mut Guid,
155+
attributes: *mut FvFileAttributes,
156+
size: *mut usize,
157+
) -> Status,
158+
pub key_size: u32,
159+
pub parent_handle: Handle,
160+
pub get_info: unsafe extern "efiapi" fn(
161+
this: *const Self,
162+
information_type: *const Guid,
163+
buffer_size: *mut usize,
164+
buffer: *mut c_void,
165+
) -> Status,
166+
pub set_info: unsafe extern "efiapi" fn(
167+
this: *const Self,
168+
information_type: *const Guid,
169+
buffer_size: usize,
170+
buffer: *const c_void,
171+
) -> Status,
172+
}
173+
174+
impl FirmwareVolume2Protocol {
175+
pub const GUID: Guid = guid!("220e73b6-6bdb-4413-8405-b974b108619a");
176+
}
177+
178+
// EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
179+
#[derive(Debug)]
180+
#[repr(C)]
181+
pub struct FirmwareVolumeBlock2Protocol {
182+
pub get_attributes: unsafe extern "efiapi" fn(
183+
this: *const Self,
184+
attributes: *mut FirmwareVolumeAttributes,
185+
) -> Status,
186+
pub set_attributes: unsafe extern "efiapi" fn(
187+
this: *const Self,
188+
attributes: *mut FirmwareVolumeAttributes,
189+
) -> Status,
190+
pub get_physical_address:
191+
unsafe extern "efiapi" fn(this: *const Self, address: *mut PhysicalAddress) -> Status,
192+
pub get_block_size: unsafe extern "efiapi" fn(
193+
this: *const Self,
194+
lba: Lba,
195+
block_size: *mut usize,
196+
number_of_blocks: *mut usize,
197+
) -> Status,
198+
pub read: unsafe extern "efiapi" fn(
199+
this: *const Self,
200+
lba: Lba,
201+
offset: usize,
202+
num_bytes: *mut usize,
203+
buffer: *mut u8,
204+
) -> Status,
205+
pub write: unsafe extern "efiapi" fn(
206+
this: *const Self,
207+
lba: Lba,
208+
offset: usize,
209+
num_bytes: *mut usize,
210+
buffer: *mut u8,
211+
) -> Status,
212+
// TODO: Change to efiapi (https://github.com/rust-lang/rust/issues/100189)
213+
pub erase_blocks: unsafe extern "C" fn(this: *const Self, ...) -> Status,
214+
}
215+
216+
impl FirmwareVolumeBlock2Protocol {
217+
pub const GUID: Guid = guid!("8f644fa9-e850-4db1-9ce2-0b44698e8da4");
218+
pub const LBA_LIST_TERMINATOR: u64 = u64::MAX;
219+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod device_path;
1010
pub mod disk;
1111
pub mod driver;
1212
pub mod file_system;
13+
pub mod firmware_volume;
1314
pub mod loaded_image;
1415
pub mod media;
1516
pub mod memory_protection;

0 commit comments

Comments
 (0)