-
-
Notifications
You must be signed in to change notification settings - Fork 170
Make UEFI shell protocols testable #793
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
nicholasbishop
merged 1 commit into
rust-osdev:main
from
nicholasbishop:bishop-shell-runner
Jun 9, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//! This application launches the UEFI shell app and runs the main | ||
//! uefi-test-running app inside that shell. This allows testing of protocols | ||
//! that require the shell. | ||
//! | ||
//! Launching the shell this way (rather than directly making it the boot | ||
//! executable) makes it possible to avoid the shell's built-in five second | ||
//! startup delay. | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::vec::Vec; | ||
use log::info; | ||
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::table::boot::LoadImageSource; | ||
use uefi::Status; | ||
|
||
/// 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. | ||
fn get_shell_app_device_path<'a>( | ||
boot_services: &BootServices, | ||
storage: &'a mut Vec<u8>, | ||
) -> &'a DevicePath { | ||
let loaded_image_device_path = boot_services | ||
.open_protocol_exclusive::<LoadedImageDevicePath>(boot_services.image_handle()) | ||
.expect("failed to open LoadedImageDevicePath protocol"); | ||
|
||
let mut builder = DevicePathBuilder::with_vec(storage); | ||
for node in loaded_image_device_path.node_iter() { | ||
if node.full_type() == (DeviceType::MEDIA, DeviceSubType::MEDIA_FILE_PATH) { | ||
break; | ||
} | ||
builder = builder.push(&node).unwrap(); | ||
} | ||
builder = builder | ||
.push(&build::media::FilePath { | ||
path_name: cstr16!(r"efi\boot\shell.efi"), | ||
}) | ||
.unwrap(); | ||
builder.finalize().unwrap() | ||
} | ||
|
||
#[entry] | ||
fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status { | ||
uefi_services::init(&mut st).unwrap(); | ||
let boot_services = st.boot_services(); | ||
|
||
let mut storage = Vec::new(); | ||
let shell_image_path = get_shell_app_device_path(boot_services, &mut storage); | ||
|
||
// Load the shell app. | ||
let shell_image_handle = boot_services | ||
.load_image( | ||
image, | ||
LoadImageSource::FromFilePath { | ||
file_path: shell_image_path, | ||
from_boot_manager: false, | ||
}, | ||
) | ||
.expect("failed to load shell app"); | ||
|
||
// Set the command line passed to the shell app so that it will run the | ||
// test-runner app. This automatically turns off the five-second delay. | ||
let mut shell_loaded_image = boot_services | ||
.open_protocol_exclusive::<LoadedImage>(shell_image_handle) | ||
.expect("failed to open LoadedImage protocol"); | ||
let load_options = cstr16!(r"shell.efi test_runner.efi"); | ||
unsafe { | ||
shell_loaded_image.set_load_options( | ||
load_options.as_ptr().cast(), | ||
load_options.num_bytes() as u32, | ||
); | ||
} | ||
|
||
info!("launching the shell app"); | ||
boot_services | ||
.start_image(shell_image_handle) | ||
.expect("failed to launch the shell app"); | ||
|
||
Status::SUCCESS | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.