Skip to content

Commit 4dd71d5

Browse files
committed
uefi: LoadImageSource: use BootPolicy
This adds the new `BootPolicy` type into `LoadImageSource`.
1 parent a7f0189 commit 4dd71d5

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
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+
boot_policy: BootPolicy::ExactMatch,
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};
@@ -122,7 +123,7 @@ fn test_load_image(bt: &BootServices) {
122123
{
123124
let load_source = LoadImageSource::FromDevicePath {
124125
device_path: image_device_path,
125-
from_boot_manager: false,
126+
boot_policy: BootPolicy::ExactMatch,
126127
};
127128
let _ = bt
128129
.load_image(bt.image_handle(), load_source)

uefi/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ details of a significant change to the API in this release.
4343
> use uefi::mem::memory_map::{MemoryMap, MemoryMapMut, MemoryType};
4444
> use uefi::table::boot::BootServices;
4545
```
46+
- **Breaking:** Added a new `BootPolicy` type which breaks existing usages
47+
of `LoadImageSource`.
4648

4749
[funcmigrate]: ../docs/funcs_migration.md
4850

uefi/src/boot.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use core::{mem, slice};
2121
use uefi::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
2222
use uefi_raw::table::boot::InterfaceType;
2323

24-
#[cfg(feature = "alloc")]
25-
use {alloc::vec::Vec, uefi::ResultExt};
26-
2724
#[cfg(doc)]
2825
use crate::proto::device_path::LoadedImageDevicePath;
26+
use uefi::proto::BootPolicy;
27+
#[cfg(feature = "alloc")]
28+
use {alloc::vec::Vec, uefi::ResultExt};
2929

3030
pub use uefi::table::boot::{
3131
AllocateType, EventNotifyFn, LoadImageSource, OpenProtocolAttributes, OpenProtocolParams,
@@ -1002,17 +1002,17 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> Resul
10021002
match source {
10031003
LoadImageSource::FromBuffer { buffer, file_path } => {
10041004
// Boot policy is ignored when loading from source buffer.
1005-
boot_policy = 0;
1005+
boot_policy = BootPolicy::ExactMatch;
10061006

10071007
device_path = file_path.map(|p| p.as_ffi_ptr()).unwrap_or(ptr::null());
10081008
source_buffer = buffer.as_ptr();
10091009
source_size = buffer.len();
10101010
}
10111011
LoadImageSource::FromDevicePath {
10121012
device_path: file_path,
1013-
from_boot_manager,
1013+
boot_policy: new_boot_policy,
10141014
} => {
1015-
boot_policy = u8::from(from_boot_manager);
1015+
boot_policy = new_boot_policy;
10161016
device_path = file_path.as_ffi_ptr();
10171017
source_buffer = ptr::null();
10181018
source_size = 0;
@@ -1022,7 +1022,7 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> Resul
10221022
let mut image_handle = ptr::null_mut();
10231023
unsafe {
10241024
(bt.load_image)(
1025-
boot_policy,
1025+
boot_policy.into(),
10261026
parent_image_handle.as_ptr(),
10271027
device_path.cast(),
10281028
source_buffer,

uefi/src/table/boot.rs

+11-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::ExactMatch;
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+
boot_policy: new_boot_policy,
860860
} => {
861-
boot_policy = u8::from(from_boot_manager);
861+
boot_policy = new_boot_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,10 @@ 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::BootSelection`],
1407+
/// attempt to load via the `LoadFile` protocol. If
1408+
/// [`BootPolicy::ExactMatch`], attempt to load via the `LoadFile2`
1409+
/// protocol, then fall back to `LoadFile`.
14091410
FromDevicePath {
14101411
/// The full device path from which to load the image.
14111412
///
@@ -1416,12 +1417,8 @@ pub enum LoadImageSource<'a> {
14161417
/// and not just `\\EFI\\BOOT\\BOOTX64.EFI`.
14171418
device_path: &'a DevicePath,
14181419

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,
1420+
/// The [`BootPolicy`] to use.
1421+
boot_policy: BootPolicy,
14251422
},
14261423
}
14271424

0 commit comments

Comments
 (0)