2025-10-19 20:23:55 -07:00
|
|
|
#![doc = include_str!("../README.md")]
|
2025-10-01 16:45:04 -07:00
|
|
|
#![feature(uefi_std)]
|
2025-10-04 23:12:01 -07:00
|
|
|
|
2025-10-30 15:26:44 -04:00
|
|
|
/// The delay to wait for when an error occurs in Sprout.
|
|
|
|
|
const DELAY_ON_ERROR: Duration = Duration::from_secs(10);
|
|
|
|
|
|
2025-10-27 02:38:40 -04:00
|
|
|
use crate::config::RootConfiguration;
|
2025-10-11 14:35:29 -07:00
|
|
|
use crate::context::{RootContext, SproutContext};
|
2025-10-24 16:32:48 -07:00
|
|
|
use crate::entries::BootableEntry;
|
2025-11-01 17:47:41 -04:00
|
|
|
use crate::integrations::bootloader_interface::{BootloaderInterface, BootloaderInterfaceTimeout};
|
2025-10-21 19:12:16 -07:00
|
|
|
use crate::options::SproutOptions;
|
|
|
|
|
use crate::options::parser::OptionsRepresentable;
|
2025-10-14 12:47:33 -07:00
|
|
|
use crate::phases::phase;
|
2025-10-30 02:36:14 -04:00
|
|
|
use crate::platform::timer::PlatformTimer;
|
2025-10-31 01:30:07 -04:00
|
|
|
use crate::platform::tpm::PlatformTpm;
|
2025-10-30 18:57:26 -04:00
|
|
|
use crate::secure::SecureBoot;
|
2025-10-28 21:05:22 -04:00
|
|
|
use crate::utils::PartitionGuidForm;
|
2025-10-27 03:37:09 -04:00
|
|
|
use anyhow::{Context, Result, bail};
|
2025-10-30 21:38:49 -04:00
|
|
|
use log::{error, info, warn};
|
2025-10-13 00:55:11 -07:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
use std::ops::Deref;
|
2025-10-26 23:59:50 -04:00
|
|
|
use std::time::Duration;
|
2025-10-13 00:55:11 -07:00
|
|
|
use uefi::proto::device_path::LoadedImageDevicePath;
|
2025-10-04 23:12:01 -07:00
|
|
|
|
2025-10-20 00:06:46 -07:00
|
|
|
/// actions: Code that can be configured and executed by Sprout.
|
2025-10-04 23:12:01 -07:00
|
|
|
pub mod actions;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
2025-10-27 02:38:40 -04:00
|
|
|
/// autoconfigure: Autoconfigure Sprout based on the detected environment.
|
|
|
|
|
pub mod autoconfigure;
|
|
|
|
|
|
2025-10-20 00:06:46 -07:00
|
|
|
/// config: Sprout configuration mechanism.
|
2025-10-01 18:25:49 -07:00
|
|
|
pub mod config;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
|
|
|
|
/// context: Stored values that can be cheaply forked and cloned.
|
2025-10-04 23:12:01 -07:00
|
|
|
pub mod context;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
|
|
|
|
/// drivers: EFI drivers to load and provide extra functionality.
|
2025-10-12 22:39:56 -07:00
|
|
|
pub mod drivers;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
|
|
|
|
/// entries: Boot menu entries that have a title and can execute actions.
|
2025-10-14 12:47:33 -07:00
|
|
|
pub mod entries;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
|
|
|
|
/// extractors: Runtime code that can extract values into the Sprout context.
|
2025-10-13 00:55:11 -07:00
|
|
|
pub mod extractors;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
|
|
|
|
/// generators: Runtime code that can generate entries with specific values.
|
2025-10-04 23:12:01 -07:00
|
|
|
pub mod generators;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
2025-10-30 02:36:14 -04:00
|
|
|
/// platform: Integration or support code for specific hardware platforms.
|
|
|
|
|
pub mod platform;
|
|
|
|
|
|
2025-10-26 23:59:50 -04:00
|
|
|
/// menu: Display a boot menu to select an entry to boot.
|
|
|
|
|
pub mod menu;
|
|
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
/// integrations: Code that interacts with other systems.
|
|
|
|
|
pub mod integrations;
|
|
|
|
|
|
2025-10-20 00:06:46 -07:00
|
|
|
/// phases: Hooks into specific parts of the boot process.
|
2025-10-14 12:47:33 -07:00
|
|
|
pub mod phases;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
2025-10-31 15:49:00 -04:00
|
|
|
/// sbat: Secure Boot Attestation section.
|
|
|
|
|
pub mod sbat;
|
|
|
|
|
|
2025-10-30 18:57:26 -04:00
|
|
|
/// secure: Secure Boot support.
|
|
|
|
|
pub mod secure;
|
|
|
|
|
|
2025-10-20 00:06:46 -07:00
|
|
|
/// setup: Code that initializes the UEFI environment for Sprout.
|
2025-10-01 16:45:04 -07:00
|
|
|
pub mod setup;
|
2025-10-20 00:06:46 -07:00
|
|
|
|
2025-10-20 18:17:29 -07:00
|
|
|
/// options: Parse the options of the Sprout executable.
|
|
|
|
|
pub mod options;
|
|
|
|
|
|
2025-10-20 00:06:46 -07:00
|
|
|
/// utils: Utility functions that are used by other parts of Sprout.
|
2025-10-01 21:30:43 -07:00
|
|
|
pub mod utils;
|
2025-10-01 16:45:04 -07:00
|
|
|
|
2025-10-27 15:41:29 -04:00
|
|
|
/// Run Sprout, returning an error if one occurs.
|
|
|
|
|
fn run() -> Result<()> {
|
2025-10-30 22:56:01 -04:00
|
|
|
// For safety reasons, we will note that Secure Boot is in beta on Sprout.
|
2025-10-30 18:57:26 -04:00
|
|
|
if SecureBoot::enabled().context("unable to determine Secure Boot status")? {
|
2025-10-30 22:56:01 -04:00
|
|
|
warn!("Secure Boot is enabled. Sprout Secure Boot is in beta.");
|
2025-10-30 18:57:26 -04:00
|
|
|
}
|
|
|
|
|
|
2025-10-30 02:36:14 -04:00
|
|
|
// Start the platform timer.
|
|
|
|
|
let timer = PlatformTimer::start();
|
|
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Mark the initialization of Sprout in the bootloader interface.
|
2025-10-30 02:51:52 -04:00
|
|
|
BootloaderInterface::mark_init(&timer)
|
2025-10-28 21:05:22 -04:00
|
|
|
.context("unable to mark initialization in bootloader interface")?;
|
|
|
|
|
|
2025-10-30 11:47:35 -04:00
|
|
|
// Tell the bootloader interface what firmware we are running on.
|
|
|
|
|
BootloaderInterface::set_firmware_info()
|
|
|
|
|
.context("unable to set firmware info in bootloader interface")?;
|
|
|
|
|
|
2025-10-30 12:50:36 -04:00
|
|
|
// Tell the bootloader interface what loader is being used.
|
|
|
|
|
BootloaderInterface::set_loader_info()
|
|
|
|
|
.context("unable to set loader info in bootloader interface")?;
|
|
|
|
|
|
2025-10-31 01:30:07 -04:00
|
|
|
// Acquire the number of active PCR banks on the TPM.
|
|
|
|
|
// If no TPM is available, this will return zero.
|
|
|
|
|
let active_pcr_banks = PlatformTpm::active_pcr_banks()?;
|
|
|
|
|
// Tell the bootloader interface what the number of active PCR banks is.
|
|
|
|
|
BootloaderInterface::set_tpm2_active_pcr_banks(active_pcr_banks)
|
|
|
|
|
.context("unable to set tpm2 active PCR banks in bootloader interface")?;
|
|
|
|
|
|
2025-10-20 18:17:29 -07:00
|
|
|
// Parse the options to the sprout executable.
|
2025-10-21 19:12:16 -07:00
|
|
|
let options = SproutOptions::parse().context("unable to parse options")?;
|
2025-10-20 18:17:29 -07:00
|
|
|
|
2025-10-27 02:38:40 -04:00
|
|
|
// If --autoconfigure is specified, we use a stub configuration.
|
|
|
|
|
let mut config = if options.autoconfigure {
|
|
|
|
|
info!("autoconfiguration enabled, configuration file will be ignored");
|
|
|
|
|
RootConfiguration::default()
|
|
|
|
|
} else {
|
|
|
|
|
// Load the configuration of sprout.
|
|
|
|
|
// At this point, the configuration has been validated and the specified
|
|
|
|
|
// version is checked to ensure compatibility.
|
|
|
|
|
config::loader::load(&options)?
|
|
|
|
|
};
|
2025-10-05 00:09:53 -07:00
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Grab the sprout.efi loaded image path.
|
2025-10-19 20:23:55 -07:00
|
|
|
// This is done in a block to ensure the release of the LoadedImageDevicePath protocol.
|
2025-10-28 21:05:22 -04:00
|
|
|
let loaded_image_path = {
|
2025-10-13 00:55:11 -07:00
|
|
|
let current_image_device_path_protocol = uefi::boot::open_protocol_exclusive::<
|
|
|
|
|
LoadedImageDevicePath,
|
|
|
|
|
>(uefi::boot::image_handle())
|
2025-10-14 12:47:33 -07:00
|
|
|
.context("unable to get loaded image device path")?;
|
2025-10-28 21:05:22 -04:00
|
|
|
current_image_device_path_protocol.deref().to_boxed()
|
2025-10-13 00:55:11 -07:00
|
|
|
};
|
|
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Grab the partition GUID of the ESP that sprout was loaded from.
|
|
|
|
|
let loaded_image_partition_guid =
|
|
|
|
|
utils::partition_guid(&loaded_image_path, PartitionGuidForm::Partition)
|
|
|
|
|
.context("unable to retrieve loaded image partition guid")?;
|
|
|
|
|
|
|
|
|
|
// Set the partition GUID of the ESP that sprout was loaded from in the bootloader interface.
|
|
|
|
|
if let Some(loaded_image_partition_guid) = loaded_image_partition_guid {
|
|
|
|
|
// Tell the system about the partition GUID.
|
|
|
|
|
BootloaderInterface::set_partition_guid(&loaded_image_partition_guid)
|
|
|
|
|
.context("unable to set partition guid in bootloader interface")?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-30 12:44:07 -04:00
|
|
|
// Tell the bootloader interface what the loaded image path is.
|
|
|
|
|
BootloaderInterface::set_loader_path(&loaded_image_path)
|
|
|
|
|
.context("unable to set loader path in bootloader interface")?;
|
|
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Create the root context.
|
2025-10-30 02:36:14 -04:00
|
|
|
let mut root = RootContext::new(loaded_image_path, timer, options);
|
2025-10-28 21:05:22 -04:00
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Insert the configuration actions into the root context.
|
2025-10-04 23:12:01 -07:00
|
|
|
root.actions_mut().extend(config.actions.clone());
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Create a new sprout context with the root context.
|
2025-10-11 14:35:29 -07:00
|
|
|
let mut context = SproutContext::new(root);
|
2025-10-19 20:23:55 -07:00
|
|
|
|
|
|
|
|
// Insert the configuration values into the sprout context.
|
2025-10-04 23:12:01 -07:00
|
|
|
context.insert(&config.values);
|
2025-10-19 20:23:55 -07:00
|
|
|
|
|
|
|
|
// Freeze the sprout context so it can be shared and cheaply cloned.
|
2025-10-04 23:12:01 -07:00
|
|
|
let context = context.freeze();
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Execute the early phase.
|
2025-10-14 12:47:33 -07:00
|
|
|
phase(context.clone(), &config.phases.early).context("unable to execute early phase")?;
|
2025-10-13 16:23:08 -07:00
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Load all configured drivers.
|
2025-10-14 12:47:33 -07:00
|
|
|
drivers::load(context.clone(), &config.drivers).context("unable to load drivers")?;
|
2025-10-12 22:39:56 -07:00
|
|
|
|
2025-10-27 02:38:40 -04:00
|
|
|
// If --autoconfigure is specified or the loaded configuration has autoconfigure enabled,
|
|
|
|
|
// trigger the autoconfiguration mechanism.
|
2025-10-27 17:56:38 -04:00
|
|
|
if context.root().options().autoconfigure || config.options.autoconfigure {
|
2025-10-27 02:38:40 -04:00
|
|
|
autoconfigure::autoconfigure(&mut config).context("unable to autoconfigure")?;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 03:37:09 -04:00
|
|
|
// Unload the context so that it can be modified.
|
|
|
|
|
let Some(mut context) = context.unload() else {
|
|
|
|
|
bail!("context safety violation while trying to unload context");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Perform root context modification in a block to release the modification when complete.
|
|
|
|
|
{
|
|
|
|
|
// Modify the root context to include the autoconfigured actions.
|
|
|
|
|
let Some(root) = context.root_mut() else {
|
|
|
|
|
bail!("context safety violation while trying to modify root context");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Extend the root context with the autoconfigured actions.
|
|
|
|
|
root.actions_mut().extend(config.actions);
|
2025-10-27 22:43:37 -04:00
|
|
|
|
|
|
|
|
// Insert any modified root values.
|
|
|
|
|
context.insert(&config.values);
|
2025-10-27 03:37:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Refreeze the context to ensure that further operations can share the context.
|
|
|
|
|
let context = context.freeze();
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Run all the extractors declared in the configuration.
|
2025-10-13 00:55:11 -07:00
|
|
|
let mut extracted = BTreeMap::new();
|
|
|
|
|
for (name, extractor) in &config.extractors {
|
|
|
|
|
let value = extractors::extract(context.clone(), extractor)
|
2025-10-14 12:47:33 -07:00
|
|
|
.context(format!("unable to extract value {}", name))?;
|
2025-10-27 00:20:42 -04:00
|
|
|
info!("extracted value {}: {}", name, value);
|
2025-10-13 00:55:11 -07:00
|
|
|
extracted.insert(name.clone(), value);
|
|
|
|
|
}
|
|
|
|
|
let mut context = context.fork();
|
2025-10-19 20:23:55 -07:00
|
|
|
// Insert the extracted values into the sprout context.
|
2025-10-13 00:55:11 -07:00
|
|
|
context.insert(&extracted);
|
|
|
|
|
let context = context.freeze();
|
|
|
|
|
|
2025-10-24 19:28:38 -07:00
|
|
|
// Execute the startup phase.
|
2025-10-14 12:47:33 -07:00
|
|
|
phase(context.clone(), &config.phases.startup).context("unable to execute startup phase")?;
|
2025-10-04 23:12:01 -07:00
|
|
|
|
2025-10-24 16:32:48 -07:00
|
|
|
let mut entries = Vec::new();
|
2025-10-04 23:12:01 -07:00
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Insert all the static entries from the configuration into the entry list.
|
2025-10-24 16:32:48 -07:00
|
|
|
for (name, entry) in config.entries {
|
2025-10-19 20:23:55 -07:00
|
|
|
// Associate the main context with the static entry.
|
2025-10-24 16:32:48 -07:00
|
|
|
entries.push(BootableEntry::new(
|
|
|
|
|
name,
|
2025-10-24 17:16:42 -07:00
|
|
|
entry.title.clone(),
|
2025-10-24 16:32:48 -07:00
|
|
|
context.clone(),
|
|
|
|
|
entry,
|
|
|
|
|
));
|
2025-10-04 23:12:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Run all the generators declared in the configuration.
|
2025-10-24 16:32:48 -07:00
|
|
|
for (name, generator) in config.generators {
|
2025-10-04 23:12:01 -07:00
|
|
|
let context = context.fork().freeze();
|
|
|
|
|
|
2025-10-28 23:23:12 -04:00
|
|
|
// We will prefix all entries with [name]-, provided the name is not pinned.
|
2025-10-24 16:32:48 -07:00
|
|
|
let prefix = format!("{}-", name);
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Add all the entries generated by the generator to the entry list.
|
|
|
|
|
// The generator specifies the context associated with the entry.
|
2025-10-24 16:32:48 -07:00
|
|
|
for mut entry in generators::generate(context.clone(), &generator)? {
|
2025-10-28 23:23:12 -04:00
|
|
|
// If the entry name is not pinned, prepend the name prefix.
|
|
|
|
|
if !entry.is_pin_name() {
|
|
|
|
|
entry.prepend_name_prefix(&prefix);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-24 16:32:48 -07:00
|
|
|
entries.push(entry);
|
2025-10-04 23:12:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-24 16:32:48 -07:00
|
|
|
for entry in &mut entries {
|
2025-10-24 17:16:42 -07:00
|
|
|
let mut context = entry.context().fork();
|
2025-10-19 20:23:55 -07:00
|
|
|
// Insert the values from the entry configuration into the
|
|
|
|
|
// sprout context to use with the entry itself.
|
2025-10-24 16:32:48 -07:00
|
|
|
context.insert(&entry.declaration().values);
|
2025-10-24 18:44:28 -07:00
|
|
|
let context = context
|
|
|
|
|
.finalize()
|
|
|
|
|
.context("unable to finalize context")?
|
|
|
|
|
.freeze();
|
2025-10-24 16:32:48 -07:00
|
|
|
// Provide the new context to the bootable entry.
|
|
|
|
|
entry.swap_context(context);
|
|
|
|
|
// Restamp the title with any values.
|
|
|
|
|
entry.restamp_title();
|
2025-10-26 23:59:50 -04:00
|
|
|
|
|
|
|
|
// Mark this entry as the default entry if it is declared as such.
|
2025-10-27 17:56:38 -04:00
|
|
|
if let Some(ref default_entry) = config.options.default_entry {
|
2025-10-26 23:59:50 -04:00
|
|
|
// If the entry matches the default entry, mark it as the default entry.
|
|
|
|
|
if entry.is_match(default_entry) {
|
|
|
|
|
entry.mark_default();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-04 23:12:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-26 23:59:50 -04:00
|
|
|
// If no entries were the default, pick the first entry as the default entry.
|
|
|
|
|
if entries.iter().all(|entry| !entry.is_default())
|
|
|
|
|
&& let Some(entry) = entries.first_mut()
|
|
|
|
|
{
|
|
|
|
|
entry.mark_default();
|
2025-10-04 23:33:23 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Tell the bootloader interface what entries are available.
|
|
|
|
|
BootloaderInterface::set_entries(entries.iter().map(|entry| entry.name()))
|
|
|
|
|
.context("unable to set entries in bootloader interface")?;
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Execute the late phase.
|
2025-10-14 12:47:33 -07:00
|
|
|
phase(context.clone(), &config.phases.late).context("unable to execute late phase")?;
|
2025-10-13 16:23:08 -07:00
|
|
|
|
2025-11-01 17:47:41 -04:00
|
|
|
// Acquire the timeout setting from the bootloader interface.
|
|
|
|
|
let bootloader_interface_timeout =
|
|
|
|
|
BootloaderInterface::get_timeout().context("unable to get bootloader interface timeout")?;
|
|
|
|
|
|
2025-10-26 23:59:50 -04:00
|
|
|
// If --boot is specified, boot that entry immediately.
|
|
|
|
|
let force_boot_entry = context.root().options().boot.as_ref();
|
|
|
|
|
// If --force-menu is specified, show the boot menu regardless of the value of --boot.
|
2025-11-01 17:47:41 -04:00
|
|
|
let mut force_boot_menu = context.root().options().force_menu;
|
2025-10-26 23:59:50 -04:00
|
|
|
|
|
|
|
|
// Determine the menu timeout in seconds based on the options or configuration.
|
|
|
|
|
// We prefer the options over the configuration to allow for overriding.
|
2025-11-01 17:47:41 -04:00
|
|
|
let mut menu_timeout = context
|
2025-10-24 21:19:38 -07:00
|
|
|
.root()
|
|
|
|
|
.options()
|
2025-10-26 23:59:50 -04:00
|
|
|
.menu_timeout
|
2025-10-27 17:56:38 -04:00
|
|
|
.unwrap_or(config.options.menu_timeout);
|
2025-11-01 17:47:41 -04:00
|
|
|
|
|
|
|
|
// Apply bootloader interface timeout settings.
|
|
|
|
|
match bootloader_interface_timeout {
|
|
|
|
|
BootloaderInterfaceTimeout::MenuForce => {
|
|
|
|
|
// Force the boot menu.
|
|
|
|
|
force_boot_menu = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BootloaderInterfaceTimeout::MenuHidden => {
|
|
|
|
|
// Hide the boot menu by setting the timeout to zero.
|
|
|
|
|
menu_timeout = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BootloaderInterfaceTimeout::MenuDisabled => {
|
|
|
|
|
// Disable the boot menu by setting the timeout to zero.
|
|
|
|
|
menu_timeout = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BootloaderInterfaceTimeout::Timeout(timeout) => {
|
|
|
|
|
// Configure the timeout to the specified value.
|
|
|
|
|
menu_timeout = timeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BootloaderInterfaceTimeout::Unspecified => {
|
|
|
|
|
// Do nothing.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert the menu timeout to a duration.
|
2025-10-26 23:59:50 -04:00
|
|
|
let menu_timeout = Duration::from_secs(menu_timeout);
|
|
|
|
|
|
|
|
|
|
// Use the forced boot entry if possible, otherwise pick the first entry using a boot menu.
|
|
|
|
|
let entry = if !force_boot_menu && let Some(ref force_boot_entry) = force_boot_entry {
|
|
|
|
|
BootableEntry::find(force_boot_entry, entries.iter())
|
|
|
|
|
.context(format!("unable to find entry: {force_boot_entry}"))?
|
2025-10-20 18:17:29 -07:00
|
|
|
} else {
|
2025-10-26 23:59:50 -04:00
|
|
|
// Delegate to the menu to select an entry to boot.
|
2025-10-30 13:27:58 -04:00
|
|
|
menu::select(&timer, menu_timeout, &entries)
|
|
|
|
|
.context("unable to select entry via boot menu")?
|
2025-10-19 02:25:55 -07:00
|
|
|
};
|
2025-10-04 23:33:23 -07:00
|
|
|
|
2025-10-28 21:05:22 -04:00
|
|
|
// Tell the bootloader interface what the selected entry is.
|
|
|
|
|
BootloaderInterface::set_selected_entry(entry.name().to_string())
|
|
|
|
|
.context("unable to set selected entry in bootloader interface")?;
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Execute all the actions for the selected entry.
|
2025-10-24 16:32:48 -07:00
|
|
|
for action in &entry.declaration().actions {
|
2025-10-24 17:16:42 -07:00
|
|
|
let action = entry.context().stamp(action);
|
|
|
|
|
actions::execute(entry.context().clone(), &action)
|
2025-10-14 12:47:33 -07:00
|
|
|
.context(format!("unable to execute action '{}'", action))?;
|
2025-10-01 21:30:43 -07:00
|
|
|
}
|
2025-10-19 20:23:55 -07:00
|
|
|
|
2025-10-27 15:41:29 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The main entrypoint of sprout.
|
|
|
|
|
/// It is possible this function will not return if actions that are executed
|
|
|
|
|
/// exit boot services or do not return control to sprout.
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
|
// Initialize the basic UEFI environment.
|
|
|
|
|
setup::init()?;
|
|
|
|
|
|
|
|
|
|
// Run Sprout, then handle the error.
|
|
|
|
|
let result = run();
|
|
|
|
|
if let Err(ref error) = result {
|
|
|
|
|
// Print an error trace.
|
|
|
|
|
error!("sprout encountered an error");
|
|
|
|
|
for (index, stack) in error.chain().enumerate() {
|
|
|
|
|
error!("[{}]: {}", index, stack);
|
|
|
|
|
}
|
2025-10-30 15:26:44 -04:00
|
|
|
// Sleep to allow the user to read the error.
|
|
|
|
|
uefi::boot::stall(DELAY_ON_ERROR);
|
2025-10-27 15:41:29 -04:00
|
|
|
}
|
|
|
|
|
|
2025-10-19 20:23:55 -07:00
|
|
|
// Sprout doesn't necessarily guarantee anything was booted.
|
|
|
|
|
// If we reach here, we will exit back to whoever called us.
|
2025-10-11 14:35:29 -07:00
|
|
|
Ok(())
|
2025-10-01 16:45:04 -07:00
|
|
|
}
|