Skip to content

Commit 3ba410f

Browse files
committed
uefi: use new BootPolicy type
1 parent 2d2c1b7 commit 3ba410f

File tree

8 files changed

+41
-35
lines changed

8 files changed

+41
-35
lines changed

uefi-test-runner/src/bin/shell_launcher.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use uefi::prelude::*;
1818
use uefi::proto::device_path::build::{self, DevicePathBuilder};
1919
use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath};
2020
use uefi::proto::loaded_image::LoadedImage;
21+
use uefi::proto::BootPolicy;
2122

2223
/// Get the device path of the shell app. This is the same as the
2324
/// currently-loaded image's device path, but with the file path part changed.
@@ -53,7 +54,7 @@ fn efi_main() -> Status {
5354
boot::image_handle(),
5455
LoadImageSource::FromDevicePath {
5556
device_path: shell_image_path,
56-
from_boot_manager: false,
57+
bool_policy: BootPolicy::FALSE,
5758
},
5859
)
5960
.expect("failed to load shell app");

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use uefi::fs::FileSystem;
33
use uefi::proto::console::text::Output;
44
use uefi::proto::device_path::media::FilePath;
55
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
6+
use uefi::proto::BootPolicy;
67
use uefi::table::boot::{BootServices, LoadImageSource, SearchType};
78
use uefi::table::{Boot, SystemTable};
89
use uefi::{boot, CString16, Identify};
@@ -117,7 +118,7 @@ fn test_load_image(bt: &BootServices) {
117118
{
118119
let load_source = LoadImageSource::FromDevicePath {
119120
device_path: image_device_path,
120-
from_boot_manager: false,
121+
bool_policy: BootPolicy::FALSE,
121122
};
122123
let _ = bt
123124
.load_image(bt.image_handle(), load_source)

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use core::ptr::addr_of;
88
use uefi::prelude::BootServices;
99
use uefi::proto::device_path::build::DevicePathBuilder;
1010
use uefi::proto::media::load_file::{LoadFile, LoadFile2};
11+
use uefi::proto::BootPolicy;
1112
use uefi::{Guid, Handle};
1213
use uefi_raw::protocol::device_path::DevicePathProtocol;
1314
use uefi_raw::protocol::media::{LoadFile2Protocol, LoadFileProtocol};
@@ -108,7 +109,9 @@ pub fn test(bt: &BootServices) {
108109
let dvp = dvp.finalize().unwrap();
109110

110111
let mut opened_load_file_protocol = bt.open_protocol_exclusive::<LoadFile>(image).unwrap();
111-
let loadfile_file = opened_load_file_protocol.load_file(dvp, true).unwrap();
112+
let loadfile_file = opened_load_file_protocol
113+
.load_file(dvp, BootPolicy::TRUE)
114+
.unwrap();
112115
let loadfile_file_string = String::from_utf8(loadfile_file.to_vec()).unwrap();
113116

114117
let mut opened_load_file2_protocol = bt.open_protocol_exclusive::<LoadFile2>(image).unwrap();

uefi/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
> use uefi::mem::memory_map::{MemoryMap, MemoryMapMut, MemoryType};
4343
> use uefi::table::boot::BootServices;
4444
```
45+
- **Breaking:** Added a new `BootPolicy` type which breaks existing usages
46+
of `LoadImageSource`.
4547

4648

4749
# uefi - 0.30.0 (2024-08-02)

uefi/src/boot.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ use core::{mem, slice};
1414
use uefi::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
1515
use uefi_raw::table::boot::InterfaceType;
1616

17+
use crate::proto::BootPolicy;
18+
pub use crate::table::boot::{
19+
AllocateType, EventNotifyFn, LoadImageSource, OpenProtocolAttributes, OpenProtocolParams,
20+
SearchType, TimerTrigger,
21+
};
22+
pub use uefi_raw::table::boot::{EventType, MemoryType, Tpl};
1723
#[cfg(doc)]
1824
use {
1925
crate::proto::device_path::LoadedImageDevicePath, crate::proto::loaded_image::LoadedImage,
2026
crate::proto::media::fs::SimpleFileSystem,
2127
};
2228

23-
pub use uefi::table::boot::{
24-
AllocateType, EventNotifyFn, LoadImageSource, OpenProtocolAttributes, OpenProtocolParams,
25-
SearchType, TimerTrigger,
26-
};
27-
pub use uefi_raw::table::boot::{EventType, MemoryType, Tpl};
28-
2929
/// Global image handle. This is only set by [`set_image_handle`], and it is
3030
/// only read by [`image_handle`].
3131
static IMAGE_HANDLE: AtomicPtr<c_void> = AtomicPtr::new(ptr::null_mut());
@@ -681,17 +681,17 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> Resul
681681
match source {
682682
LoadImageSource::FromBuffer { buffer, file_path } => {
683683
// Boot policy is ignored when loading from source buffer.
684-
boot_policy = 0;
684+
boot_policy = BootPolicy::FALSE;
685685

686686
device_path = file_path.map(|p| p.as_ffi_ptr()).unwrap_or(ptr::null());
687687
source_buffer = buffer.as_ptr();
688688
source_size = buffer.len();
689689
}
690690
LoadImageSource::FromDevicePath {
691691
device_path: file_path,
692-
from_boot_manager,
692+
bool_policy,
693693
} => {
694-
boot_policy = u8::from(from_boot_manager);
694+
boot_policy = bool_policy;
695695
device_path = file_path.as_ffi_ptr();
696696
source_buffer = ptr::null();
697697
source_size = 0;
@@ -701,7 +701,7 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> Resul
701701
let mut image_handle = ptr::null_mut();
702702
unsafe {
703703
(bt.load_image)(
704-
boot_policy,
704+
boot_policy.into(),
705705
parent_image_handle.as_ptr(),
706706
device_path.cast(),
707707
source_buffer,

uefi/src/proto/media/load_file.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use uefi_raw::protocol::media::{LoadFile2Protocol, LoadFileProtocol};
88
use {
99
crate::{mem::make_boxed, proto::device_path::DevicePath, Result, StatusExt},
1010
alloc::boxed::Box,
11+
uefi::proto::BootPolicy,
1112
};
1213

1314
/// Load File Protocol.
@@ -37,10 +38,7 @@ impl LoadFile {
3738
///
3839
/// # Parameters
3940
/// - `file_path` The device specific path of the file to load.
40-
/// - `boot_policy` If TRUE, indicates that the request originates from the
41-
/// boot manager, and that the boot manager is attempting to load FilePath
42-
/// as a boot selection. If FALSE, then FilePath must match an exact file
43-
/// to be loaded.
41+
/// - `boot_policy` The [`BootPolicy`] to use.
4442
///
4543
/// # Errors
4644
/// - `uefi::status::EFI_SUCCESS` The file was loaded.
@@ -60,12 +58,14 @@ impl LoadFile {
6058
/// size needed to complete the request.
6159
/// - `uefi::status::EFI_WARN_FILE_SYSTEM` The resulting Buffer contains
6260
/// UEFI-compliant file system.
61+
///
62+
/// [`BootPolicy`]: uefi::proto::BootPolicy
6363
#[cfg(feature = "alloc")]
6464
#[allow(clippy::extra_unused_lifetimes)] // false positive, it is used
6565
pub fn load_file<'a>(
6666
&mut self,
6767
file_path: &DevicePath,
68-
boot_policy: bool,
68+
boot_policy: BootPolicy,
6969
) -> Result<Box<[u8]>> {
7070
let this = core::ptr::addr_of_mut!(*self).cast();
7171

@@ -75,7 +75,7 @@ impl LoadFile {
7575
(self.0.load_file)(
7676
this,
7777
file_path.as_ffi_ptr().cast(),
78-
boot_policy,
78+
boot_policy.into(),
7979
&mut size,
8080
buf.as_mut_ptr().cast(),
8181
)

uefi/src/proto/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ impl From<u8> for BootPolicy {
130130
fn from(value: u8) -> Self {
131131
match value {
132132
0 => Self::FALSE,
133-
1 => Self::TRUE ,
134-
_ => panic!("Invalid variant")
133+
1 => Self::TRUE,
134+
_ => panic!("Invalid variant"),
135135
}
136136
}
137137
}

uefi/src/table/boot.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::mem::memory_map::*;
1010
use crate::proto::device_path::DevicePath;
1111
use crate::proto::loaded_image::LoadedImage;
1212
use crate::proto::media::fs::SimpleFileSystem;
13-
use crate::proto::{Protocol, ProtocolPointer};
13+
use crate::proto::{BootPolicy, Protocol, ProtocolPointer};
1414
use crate::util::opt_nonnull_to_ptr;
1515
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
1616
#[cfg(feature = "alloc")]
@@ -848,17 +848,17 @@ impl BootServices {
848848
match source {
849849
LoadImageSource::FromBuffer { buffer, file_path } => {
850850
// Boot policy is ignored when loading from source buffer.
851-
boot_policy = 0;
851+
boot_policy = BootPolicy::FALSE;
852852

853853
device_path = file_path.map(|p| p.as_ffi_ptr()).unwrap_or(ptr::null());
854854
source_buffer = buffer.as_ptr();
855855
source_size = buffer.len();
856856
}
857857
LoadImageSource::FromDevicePath {
858858
device_path: file_path,
859-
from_boot_manager,
859+
bool_policy,
860860
} => {
861-
boot_policy = u8::from(from_boot_manager);
861+
boot_policy = bool_policy;
862862
device_path = file_path.as_ffi_ptr();
863863
source_buffer = ptr::null();
864864
source_size = 0;
@@ -868,7 +868,7 @@ impl BootServices {
868868
let mut image_handle = ptr::null_mut();
869869
unsafe {
870870
(self.0.load_image)(
871-
boot_policy,
871+
boot_policy.into(),
872872
parent_image_handle.as_ptr(),
873873
device_path.cast(),
874874
source_buffer,
@@ -1403,9 +1403,12 @@ pub enum LoadImageSource<'a> {
14031403

14041404
/// Load an image via the [`SimpleFileSystem`] protocol. If there is
14051405
/// no instance of that protocol associated with the path then the
1406-
/// behavior depends on `from_boot_manager`. If `true`, attempt to
1407-
/// load via the `LoadFile` protocol. If `false`, attempt to load
1408-
/// via the `LoadFile2` protocol, then fall back to `LoadFile`.
1406+
/// behavior depends on [`BootPolicy`]. If [`BootPolicy::TRUE`], attempt to
1407+
/// load via the [`LoadFile`] protocol. If [`BootPolicy::FALSE`], attempt to
1408+
/// load via the [`LoadFile2`] protocol, then fall back to [`LoadFile`].
1409+
///
1410+
/// [`LoadFile`]: crate::proto::media::load_file::LoadFile
1411+
/// [`LoadFile2`]: crate::proto::media::load_file::LoadFile2
14091412
FromDevicePath {
14101413
/// The full device path from which to load the image.
14111414
///
@@ -1416,12 +1419,8 @@ pub enum LoadImageSource<'a> {
14161419
/// and not just `\\EFI\\BOOT\\BOOTX64.EFI`.
14171420
device_path: &'a DevicePath,
14181421

1419-
/// If there is no instance of [`SimpleFileSystem`] protocol associated
1420-
/// with the given device path, then this function will attempt to use
1421-
/// `LoadFileProtocol` (`from_boot_manager` is `true`) or
1422-
/// `LoadFile2Protocol`, and then `LoadFileProtocol`
1423-
/// (`from_boot_manager` is `false`).
1424-
from_boot_manager: bool,
1422+
/// The [`BootPolicy`] to use.
1423+
bool_policy: BootPolicy,
14251424
},
14261425
}
14271426

0 commit comments

Comments
 (0)