Skip to content

Commit 632781a

Browse files
committed
chore(code): split much of the efi support code to crates/eficore
1 parent 4849770 commit 632781a

39 files changed

+440
-378
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"crates/config",
4+
"crates/eficore",
45
"crates/sprout",
56
]
67
resolver = "3"
@@ -16,7 +17,6 @@ edition = "2024"
1617
bitflags = "2.10.0"
1718
log = "0.4.28"
1819
spin = "0.10.0"
19-
uefi = "0.36.0"
2020
uefi-raw = "0.12.0"
2121

2222
[workspace.dependencies.anyhow]
@@ -46,6 +46,11 @@ version = "0.9.8"
4646
default-features = false
4747
features = ["serde", "parse"]
4848

49+
[workspace.dependencies.uefi]
50+
version = "0.36.0"
51+
default-features = false
52+
features = ["alloc", "global_allocator", "panic_handler"]
53+
4954
# Common build profiles
5055
# NOTE: We have to compile everything for opt-level = 2 due to optimization passes
5156
# which don't handle the UEFI target properly.

DEVELOPMENT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ We currently only support `x86_64-unknown-uefi` and `aarch64-unknown-uefi` targe
1111
To test your changes in QEMU, please run `./hack/dev/boot.sh`, you can specify `x86_64` or `aarch64`
1212
as an argument to boot.sh to boot the specified architecture.
1313

14+
## Crate Structure
15+
16+
Sprout is split into multiple crates:
17+
18+
- `edera-sprout-config` at `crates/config`: Serialization structures for the Sprout configuration file.
19+
- `edera-sprout-eficore` at `crates/eficore`: Core library for Sprout EFI code.
20+
- `edera-sprout` as `crates/sprout`: Sprout's main crate that contains bootloader logic.
21+
22+
It is intended that overtime Sprout will be split into even more crates.
23+
1424
## Hack Scripts
1525

1626
You can use the `./hack` scripts to run common development tasks:

crates/config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ default-features = false
1313

1414
[lib]
1515
name = "edera_sprout_config"
16+
path = "src/lib.rs"

crates/eficore/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "edera-sprout-eficore"
3+
description = "Sprout EFI Core"
4+
license.workspace = true
5+
version.workspace = true
6+
homepage.workspace = true
7+
repository.workspace = true
8+
edition.workspace = true
9+
10+
[dependencies]
11+
anyhow.workspace = true
12+
bitflags.workspace = true
13+
log.workspace = true
14+
spin.workspace = true
15+
uefi.workspace = true
16+
uefi-raw.workspace = true
17+
18+
[lib]
19+
name = "eficore"
20+
path = "src/lib.rs"

crates/sprout/src/integrations/bootloader_interface.rs renamed to crates/eficore/src/bootloader_interface.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::integrations::bootloader_interface::bitflags::LoaderFeatures;
1+
use crate::bootloader_interface::bitflags::LoaderFeatures;
22
use crate::platform::timer::PlatformTimer;
3-
use crate::utils::device_path_subpath;
4-
use crate::utils::variables::{VariableClass, VariableController};
3+
use crate::variables::{VariableClass, VariableController};
54
use alloc::format;
65
use alloc::string::{String, ToString};
76
use alloc::vec::Vec;
@@ -103,7 +102,8 @@ impl BootloaderInterface {
103102

104103
/// Tell the system the relative path to the partition root of the current bootloader.
105104
pub fn set_loader_path(path: &DevicePath) -> Result<()> {
106-
let subpath = device_path_subpath(path).context("unable to get loader path subpath")?;
105+
let subpath =
106+
crate::path::device_path_subpath(path).context("unable to get loader path subpath")?;
107107
Self::VENDOR.set_cstr16(
108108
"LoaderImageIdentifier",
109109
&subpath,

crates/sprout/src/integrations/bootloader_interface/bitflags.rs renamed to crates/eficore/src/bootloader_interface/bitflags.rs

File renamed without changes.

crates/eficore/src/handle.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use anyhow::{Context, Result};
2+
use uefi::boot::SearchType;
3+
use uefi::{Guid, Handle};
4+
use uefi_raw::Status;
5+
6+
/// Find a handle that provides the specified `protocol`.
7+
pub fn find_handle(protocol: &Guid) -> Result<Option<Handle>> {
8+
// Locate the requested protocol handle.
9+
match uefi::boot::locate_handle_buffer(SearchType::ByProtocol(protocol)) {
10+
// If a handle is found, the protocol is available.
11+
Ok(handles) => Ok(if handles.is_empty() {
12+
None
13+
} else {
14+
Some(handles[0])
15+
}),
16+
// If an error occurs, check if it is because the protocol is not available.
17+
// If so, return false. Otherwise, return the error.
18+
Err(error) => {
19+
if error.status() == Status::NOT_FOUND {
20+
Ok(None)
21+
} else {
22+
Err(error).context("unable to determine if the protocol is available")
23+
}
24+
}
25+
}
26+
}

crates/eficore/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Sprout EFI Core.
2+
//! This crate provides tools for working with the EFI environment.
3+
#![no_std]
4+
extern crate alloc;
5+
6+
/// EFI handle helpers.
7+
pub mod handle;
8+
9+
/// Logging support for EFI applications.
10+
pub mod logger;
11+
12+
/// Disk partitioning support infrastructure.
13+
pub mod partition;
14+
15+
/// Path handling for UEFI.
16+
pub mod path;
17+
18+
/// platform: Integration or support code for specific hardware platforms.
19+
pub mod platform;
20+
21+
/// Secure Boot support.
22+
pub mod secure;
23+
24+
/// Support for the shim loader application that enables Secure Boot.
25+
pub mod shim;
26+
27+
/// String utilities.
28+
pub mod strings;
29+
30+
/// Implements support for the bootloader interface specification.
31+
pub mod bootloader_interface;
32+
/// Support code for the EFI framebuffer.
33+
pub mod framebuffer;
34+
/// Support code for the media loader protocol.
35+
pub mod media_loader;
36+
/// setup: Code that initializes the UEFI environment for Sprout.
37+
pub mod setup;
38+
/// Support code for EFI variables.
39+
pub mod variables;

0 commit comments

Comments
 (0)