Skip to content

uefi: add BootPolicy type #1326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
uefi: LoadImageSource: use BootPolicy
This adds the new `BootPolicy` type into `LoadImageSource`.
  • Loading branch information
phip1611 committed Aug 13, 2024
commit 19b20cf5f2e36177ea82a93644a3925d713d8aab
3 changes: 2 additions & 1 deletion uefi-test-runner/src/bin/shell_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use uefi::prelude::*;
use uefi::proto::device_path::build::{self, DevicePathBuilder};
use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath};
use uefi::proto::loaded_image::LoadedImage;
use uefi::proto::BootPolicy;

/// Get the device path of the shell app. This is the same as the
/// currently-loaded image's device path, but with the file path part changed.
Expand Down Expand Up @@ -53,7 +54,7 @@ fn efi_main() -> Status {
boot::image_handle(),
LoadImageSource::FromDevicePath {
device_path: shell_image_path,
from_boot_manager: false,
boot_policy: BootPolicy::ExactMatch,
},
)
.expect("failed to load shell app");
Expand Down
3 changes: 2 additions & 1 deletion uefi-test-runner/src/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use uefi::fs::FileSystem;
use uefi::proto::console::text::Output;
use uefi::proto::device_path::media::FilePath;
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
use uefi::proto::BootPolicy;
use uefi::table::boot::{BootServices, LoadImageSource, SearchType};
use uefi::table::{Boot, SystemTable};
use uefi::{boot, CString16, Identify};
Expand Down Expand Up @@ -122,7 +123,7 @@ fn test_load_image(bt: &BootServices) {
{
let load_source = LoadImageSource::FromDevicePath {
device_path: image_device_path,
from_boot_manager: false,
boot_policy: BootPolicy::ExactMatch,
};
let _ = bt
.load_image(bt.image_handle(), load_source)
Expand Down
2 changes: 2 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ details of a significant change to the API in this release.
> use uefi::mem::memory_map::{MemoryMap, MemoryMapMut, MemoryType};
> use uefi::table::boot::BootServices;
```
- **Breaking:** Added a new `BootPolicy` type which breaks existing usages
of `LoadImageSource`.

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

Expand Down
14 changes: 7 additions & 7 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use core::{mem, slice};
use uefi::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
use uefi_raw::table::boot::InterfaceType;

#[cfg(feature = "alloc")]
use {alloc::vec::Vec, uefi::ResultExt};

#[cfg(doc)]
use crate::proto::device_path::LoadedImageDevicePath;
use uefi::proto::BootPolicy;
#[cfg(feature = "alloc")]
use {alloc::vec::Vec, uefi::ResultExt};

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

device_path = file_path.map(|p| p.as_ffi_ptr()).unwrap_or(ptr::null());
source_buffer = buffer.as_ptr();
source_size = buffer.len();
}
LoadImageSource::FromDevicePath {
device_path: file_path,
from_boot_manager,
boot_policy: new_boot_policy,
} => {
boot_policy = u8::from(from_boot_manager);
boot_policy = new_boot_policy;
device_path = file_path.as_ffi_ptr();
source_buffer = ptr::null();
source_size = 0;
Expand All @@ -1022,7 +1022,7 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> Resul
let mut image_handle = ptr::null_mut();
unsafe {
(bt.load_image)(
boot_policy,
boot_policy.into(),
parent_image_handle.as_ptr(),
device_path.cast(),
source_buffer,
Expand Down
25 changes: 11 additions & 14 deletions uefi/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::mem::memory_map::*;
use crate::proto::device_path::DevicePath;
use crate::proto::loaded_image::LoadedImage;
use crate::proto::media::fs::SimpleFileSystem;
use crate::proto::{Protocol, ProtocolPointer};
use crate::proto::{BootPolicy, Protocol, ProtocolPointer};
use crate::util::opt_nonnull_to_ptr;
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -848,17 +848,17 @@ impl BootServices {
match source {
LoadImageSource::FromBuffer { buffer, file_path } => {
// Boot policy is ignored when loading from source buffer.
boot_policy = 0;
boot_policy = BootPolicy::ExactMatch;

device_path = file_path.map(|p| p.as_ffi_ptr()).unwrap_or(ptr::null());
source_buffer = buffer.as_ptr();
source_size = buffer.len();
}
LoadImageSource::FromDevicePath {
device_path: file_path,
from_boot_manager,
boot_policy: new_boot_policy,
} => {
boot_policy = u8::from(from_boot_manager);
boot_policy = new_boot_policy;
device_path = file_path.as_ffi_ptr();
source_buffer = ptr::null();
source_size = 0;
Expand All @@ -868,7 +868,7 @@ impl BootServices {
let mut image_handle = ptr::null_mut();
unsafe {
(self.0.load_image)(
boot_policy,
boot_policy.into(),
parent_image_handle.as_ptr(),
device_path.cast(),
source_buffer,
Expand Down Expand Up @@ -1403,9 +1403,10 @@ pub enum LoadImageSource<'a> {

/// Load an image via the [`SimpleFileSystem`] protocol. If there is
/// no instance of that protocol associated with the path then the
/// behavior depends on `from_boot_manager`. If `true`, attempt to
/// load via the `LoadFile` protocol. If `false`, attempt to load
/// via the `LoadFile2` protocol, then fall back to `LoadFile`.
/// behavior depends on [`BootPolicy`]. If [`BootPolicy::BootSelection`],
/// attempt to load via the `LoadFile` protocol. If
/// [`BootPolicy::ExactMatch`], attempt to load via the `LoadFile2`
/// protocol, then fall back to `LoadFile`.
FromDevicePath {
/// The full device path from which to load the image.
///
Expand All @@ -1416,12 +1417,8 @@ pub enum LoadImageSource<'a> {
/// and not just `\\EFI\\BOOT\\BOOTX64.EFI`.
device_path: &'a DevicePath,

/// If there is no instance of [`SimpleFileSystem`] protocol associated
/// with the given device path, then this function will attempt to use
/// `LoadFileProtocol` (`from_boot_manager` is `true`) or
/// `LoadFile2Protocol`, and then `LoadFileProtocol`
/// (`from_boot_manager` is `false`).
from_boot_manager: bool,
/// The [`BootPolicy`] to use.
boot_policy: BootPolicy,
},
}

Expand Down