Skip to content

Commit 6445c7d

Browse files
authored
Merge branch 'main' into hii-bindings
2 parents d855d61 + 9e1b74f commit 6445c7d

File tree

3 files changed

+206
-0
lines changed

3 files changed

+206
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added `HiiStringProtocol`.
99
- Added `HiiPopupProtocol`.
1010
- Added `FormBrowser2Protocol`.
11+
- Added `FirmwareManagementProtocol`.
1112

1213
## Changed
1314

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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+
// Lower 16 bits are reserved for UEFI assignment.
92+
// Other bits are for vendor-specific compatibility checks.
93+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
94+
#[repr(transparent)]
95+
pub struct ImageCompatibilities: u64 {
96+
const CHECK_SUPPORTED = 1 << 0;
97+
const _ = !0;
98+
}
99+
}
100+
101+
bitflags::bitflags! {
102+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
103+
#[repr(transparent)]
104+
pub struct ImageUpdatable: u32 {
105+
const VALID = 1 << 0;
106+
const INVALID = 1 << 1;
107+
const INVALID_TYPE = 1 << 2;
108+
const INVALID_OLD = 1 << 3;
109+
const VALID_WITH_VENDOR_CODE = 1 << 4;
110+
}
111+
}
112+
113+
bitflags::bitflags! {
114+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
115+
#[repr(transparent)]
116+
pub struct PackageAttributes: u64 {
117+
const UPDATABLE = 1 << 0;
118+
const RESET_REQUIRED = 1 << 1;
119+
const AUTHENTICATION_REQUIRED = 1 << 2;
120+
}
121+
}
122+
123+
/// EFI_FIRMWARE_IMAGE_DESCRIPTOR
124+
#[derive(Debug)]
125+
#[repr(C)]
126+
pub struct FirmwareImageDescriptor {
127+
pub image_index: u8,
128+
pub image_type_id: Guid,
129+
pub image_id: u64,
130+
pub image_id_name: *const Char16,
131+
pub version: u32,
132+
pub version_name: *const Char16,
133+
pub size: usize,
134+
pub attributes_supported: ImageAttributes,
135+
pub attributes_setting: ImageAttributes,
136+
pub compatibilities: ImageCompatibilities,
137+
pub lowest_supported_image_version: u32,
138+
pub last_attempt_version: u32,
139+
pub last_attempt_status: u32,
140+
pub hardware_instance: u64,
141+
pub dependencies: *const FirmwareImageDep,
142+
}
143+
144+
impl FirmwareImageDescriptor {
145+
pub const VERSION: u32 = 4;
146+
}
147+
148+
/// EFI_FIRMWARE_MANAGEMENT_PROTOCOL
149+
#[derive(Debug)]
150+
#[repr(C)]
151+
pub struct FirmwareManagementProtocol {
152+
pub get_image_info: unsafe extern "efiapi" fn(
153+
this: *const Self,
154+
image_info_size: *mut usize,
155+
image_info: *mut FirmwareImageDescriptor,
156+
descriptor_version: *mut u32,
157+
descriptor_count: *mut u8,
158+
descriptor_size: *mut usize,
159+
package_version: *mut u32,
160+
package_version_name: *mut *mut Char16,
161+
) -> Status,
162+
pub get_image: unsafe extern "efiapi" fn(
163+
this: *const Self,
164+
image_index: u8,
165+
image: *mut c_void,
166+
image_size: *mut usize,
167+
) -> Status,
168+
pub set_image: unsafe extern "efiapi" fn(
169+
this: *const Self,
170+
image_index: u8,
171+
image: *const c_void,
172+
image_size: usize,
173+
vendor_code: *const c_void,
174+
progress: unsafe extern "efiapi" fn(completion: usize) -> Status,
175+
abort_reason: *mut *mut Char16,
176+
) -> Status,
177+
pub check_image: unsafe extern "efiapi" fn(
178+
this: *const Self,
179+
image_index: u8,
180+
image: *const c_void,
181+
image_size: usize,
182+
image_updatable: *mut ImageUpdatable,
183+
) -> Status,
184+
pub get_package_info: unsafe extern "efiapi" fn(
185+
this: *const Self,
186+
package_version: *mut u32,
187+
package_version_name: *mut *mut Char16,
188+
package_version_name_max_len: *mut u32,
189+
attributes_supported: *mut PackageAttributes,
190+
attributes_setting: *mut PackageAttributes,
191+
) -> Status,
192+
pub set_package_info: unsafe extern "efiapi" fn(
193+
this: *const Self,
194+
image: *const c_void,
195+
image_size: usize,
196+
vendor_code: *const c_void,
197+
package_version: u32,
198+
package_version_name: *const Char16,
199+
) -> Status,
200+
}
201+
202+
impl FirmwareManagementProtocol {
203+
pub const GUID: Guid = guid!("86c77a67-0b97-4633-a187-49104d0685c7");
204+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod device_path;
3131
pub mod disk;
3232
pub mod driver;
3333
pub mod file_system;
34+
pub mod firmware_management;
3435
pub mod firmware_volume;
3536
pub mod hii;
3637
pub mod iommu;

0 commit comments

Comments
 (0)