Skip to content

Commit b5a3806

Browse files
committed
uefi-raw: Add bindings for FMP
Ref: UEFI 2.11: 23 Firmware Update and Reporting Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent 7a7d4ab commit b5a3806

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Added
44
- Added `Tcpv4Protocol`.
55
- Added `StorageSecurityCommandProtocol`.
6+
- Added `FirmwareManagementProtocol`.
67

78
## Changed
89

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! Firmware update and reporting
4+
5+
use crate::{Char16, Guid, Status, guid, newtype_enum};
6+
use core::ffi::c_void;
7+
8+
bitflags::bitflags! {
9+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
10+
#[repr(transparent)]
11+
pub struct CapsuleSupport: u64 {
12+
const AUTHENTICATION = 1 << 0;
13+
const DEPENDENCY = 1 << 1;
14+
}
15+
}
16+
17+
/// EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER
18+
#[derive(Debug)]
19+
#[repr(C, packed)]
20+
pub struct FirmwareManagementCapsuleHeader {
21+
pub version: u32,
22+
pub embedded_driver_count: u16,
23+
pub payload_item_count: u16,
24+
pub item_offset_list: [u64; 0],
25+
}
26+
27+
impl FirmwareManagementCapsuleHeader {
28+
pub const INIT_VERSION: u32 = 1;
29+
}
30+
31+
/// EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER
32+
#[derive(Debug)]
33+
#[repr(C, packed)]
34+
pub struct FirmwareManagementCapsuleImageHeader {
35+
pub version: u32,
36+
pub update_image_type_id: Guid,
37+
pub update_image_index: u8,
38+
pub reserved_bytes: [u8; 3],
39+
pub update_image_size: u32,
40+
pub update_vendor_code_size: u32,
41+
pub update_hardware_instance: u64,
42+
pub image_capsule_support: CapsuleSupport,
43+
}
44+
45+
impl FirmwareManagementCapsuleImageHeader {
46+
pub const INIT_VERSION: u32 = 3;
47+
}
48+
49+
newtype_enum! {
50+
/// FMP dependency expression opcodes (`EFI_FMP_DEP_*`)
51+
pub enum FmpDep: u8 => {
52+
PUSH_GUID = 0x00,
53+
PUSH_VERSION = 0x01,
54+
VERSION_STR = 0x02,
55+
AND = 0x03,
56+
OR = 0x04,
57+
NOT = 0x05,
58+
TRUE = 0x06,
59+
FALSE = 0x07,
60+
EQ = 0x08,
61+
GT = 0x09,
62+
GTE = 0x0A,
63+
LT = 0x0B,
64+
LTE = 0x0C,
65+
END = 0x0D,
66+
DECLARE_LENGTH = 0x0E,
67+
}
68+
}
69+
70+
/// EFI_FIRMWARE_IMAGE_DEP
71+
#[derive(Debug)]
72+
#[repr(C)]
73+
pub struct FirmwareImageDep {
74+
pub dependencies: [u8; 0],
75+
}
76+
77+
bitflags::bitflags! {
78+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
79+
#[repr(transparent)]
80+
pub struct ImageAttributes: u64 {
81+
const IMAGE_UPDATABLE = 1 << 0;
82+
const RESET_REQUIRED = 1 << 1;
83+
const AUTHENTICATION_REQUIRED = 1 << 2;
84+
const IN_USE = 1 << 3;
85+
const UEFI_IMAGE = 1 << 4;
86+
const DEPENDENCY = 1 << 5;
87+
}
88+
}
89+
90+
bitflags::bitflags! {
91+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
92+
#[repr(transparent)]
93+
pub struct ImageUpdatable: u32 {
94+
const VALID = 1 << 0;
95+
const INVALID = 1 << 1;
96+
const INVALID_TYPE = 1 << 2;
97+
const INVALID_OLD = 1 << 3;
98+
const VALID_WITH_VENDOR_CODE = 1 << 4;
99+
}
100+
}
101+
102+
bitflags::bitflags! {
103+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
104+
#[repr(transparent)]
105+
pub struct PackageAttributes: u64 {
106+
const UPDATABLE = 1 << 0;
107+
const RESET_REQUIRED = 1 << 1;
108+
const AUTHENTICATION_REQUIRED = 1 << 2;
109+
}
110+
}
111+
112+
/// EFI_FIRMWARE_IMAGE_DESCRIPTOR
113+
#[derive(Debug)]
114+
#[repr(C)]
115+
pub struct FirmwareImageDescriptor {
116+
pub image_index: u8,
117+
pub image_type_id: Guid,
118+
pub image_id: u64,
119+
pub image_id_name: *const Char16,
120+
pub version: u32,
121+
pub version_name: *const Char16,
122+
pub size: usize,
123+
pub attributes_supported: ImageAttributes,
124+
pub attributes_setting: ImageAttributes,
125+
pub compatibilities: u64,
126+
pub lowest_supported_image_version: u32,
127+
pub last_attempt_version: u32,
128+
pub last_attempt_status: u32,
129+
pub hardware_instance: u64,
130+
pub dependencies: *const FirmwareImageDep,
131+
}
132+
133+
impl FirmwareImageDescriptor {
134+
pub const VERSION: u32 = 4;
135+
}
136+
137+
/// EFI_FIRMWARE_MANAGEMENT_PROTOCOL
138+
#[derive(Debug)]
139+
#[repr(C)]
140+
pub struct FirmwareManagementProtocol {
141+
pub get_image_info: unsafe extern "efiapi" fn(
142+
this: *const Self,
143+
image_info_size: *mut usize,
144+
image_info: *mut FirmwareImageDescriptor,
145+
descriptor_version: *mut u32,
146+
descriptor_count: *mut u8,
147+
descriptor_size: *mut usize,
148+
package_version: *mut u32,
149+
package_version_name: *mut *mut Char16,
150+
) -> Status,
151+
pub get_image: unsafe extern "efiapi" fn(
152+
this: *const Self,
153+
image_index: u8,
154+
image: *mut c_void,
155+
image_size: *mut usize,
156+
) -> Status,
157+
pub set_image: unsafe extern "efiapi" fn(
158+
this: *const Self,
159+
image_index: u8,
160+
image: *const c_void,
161+
image_size: usize,
162+
vendor_code: *const c_void,
163+
progress: unsafe extern "efiapi" fn(completion: usize) -> Status,
164+
abort_reason: *mut *mut Char16,
165+
) -> Status,
166+
pub check_image: unsafe extern "efiapi" fn(
167+
this: *const Self,
168+
image_index: u8,
169+
image: *const c_void,
170+
image_size: usize,
171+
image_updatable: *mut ImageUpdatable,
172+
) -> Status,
173+
pub get_package_info: unsafe extern "efiapi" fn(
174+
this: *const Self,
175+
package_version: *mut u32,
176+
package_version_name: *mut *mut Char16,
177+
package_version_name_max_len: *mut u32,
178+
attributes_supported: *mut PackageAttributes,
179+
attributes_setting: *mut PackageAttributes,
180+
) -> Status,
181+
pub set_package_info: unsafe extern "efiapi" fn(
182+
this: *const Self,
183+
image: *const c_void,
184+
image_size: usize,
185+
vendor_code: *const c_void,
186+
package_version: u32,
187+
package_version_name: *const Char16,
188+
) -> Status,
189+
}
190+
191+
impl FirmwareManagementProtocol {
192+
pub const GUID: Guid = guid!("86c77a67-0b97-4633-a187-49104d0685c7");
193+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod disk;
3232
pub mod driver;
3333
pub mod file_system;
3434
pub mod firmware_volume;
35+
pub mod firmware_management;
3536
pub mod hii;
3637
pub mod iommu;
3738
pub mod loaded_image;

0 commit comments

Comments
 (0)