-
Notifications
You must be signed in to change notification settings - Fork 215
Add bios and uefi cargo features (closes #287) #304
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
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e4160e
Add bios and uefi features
AlexJMohr eb9081e
move bios and uefi specific code into submodules gated by features
AlexJMohr c639622
merge BOOTLOADER_*_VERSION contants into BOOTLOADER_VERSION
AlexJMohr fb59bc9
build: check features in main instead of conditional definition
AlexJMohr 0417bbd
Allow running tests only with uefi or bios
phil-opp 1a42f8e
Test the feature gates on CI
phil-opp ef907ff
Avoid creating implicit dependency features
phil-opp 2e4a544
Use `dep:` prefix for runner features too
phil-opp caf05fb
Merge branch 'main' into cargo-features
phil-opp 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
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
File renamed without changes.
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,67 @@ | ||
use crate::fat; | ||
use anyhow::Context; | ||
use std::{ | ||
collections::BTreeMap, | ||
path::{Path, PathBuf}, | ||
}; | ||
use tempfile::NamedTempFile; | ||
|
||
mod mbr; | ||
|
||
const BIOS_STAGE_3: &str = "boot-stage-3"; | ||
const BIOS_STAGE_4: &str = "boot-stage-4"; | ||
|
||
/// Create disk images for booting on legacy BIOS systems. | ||
pub struct BiosBoot { | ||
kernel: PathBuf, | ||
} | ||
|
||
impl BiosBoot { | ||
/// Start creating a disk image for the given bootloader ELF executable. | ||
pub fn new(kernel_path: &Path) -> Self { | ||
Self { | ||
kernel: kernel_path.to_owned(), | ||
} | ||
} | ||
|
||
/// Create a bootable UEFI disk image at the given path. | ||
pub fn create_disk_image(&self, out_path: &Path) -> anyhow::Result<()> { | ||
let bootsector_path = Path::new(env!("BIOS_BOOT_SECTOR_PATH")); | ||
let stage_2_path = Path::new(env!("BIOS_STAGE_2_PATH")); | ||
|
||
let fat_partition = self | ||
.create_fat_partition() | ||
.context("failed to create FAT partition")?; | ||
|
||
mbr::create_mbr_disk( | ||
bootsector_path, | ||
stage_2_path, | ||
fat_partition.path(), | ||
out_path, | ||
) | ||
.context("failed to create BIOS MBR disk image")?; | ||
|
||
fat_partition | ||
.close() | ||
.context("failed to delete FAT partition after disk image creation")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Creates an BIOS-bootable FAT partition with the kernel. | ||
fn create_fat_partition(&self) -> anyhow::Result<NamedTempFile> { | ||
let stage_3_path = Path::new(env!("BIOS_STAGE_3_PATH")); | ||
let stage_4_path = Path::new(env!("BIOS_STAGE_4_PATH")); | ||
|
||
let mut files = BTreeMap::new(); | ||
files.insert(crate::KERNEL_FILE_NAME, self.kernel.as_path()); | ||
files.insert(BIOS_STAGE_3, stage_3_path); | ||
files.insert(BIOS_STAGE_4, stage_4_path); | ||
|
||
let out_file = NamedTempFile::new().context("failed to create temp file")?; | ||
fat::create_fat_filesystem(files, out_file.path()) | ||
.context("failed to create BIOS FAT filesystem")?; | ||
|
||
Ok(out_file) | ||
} | ||
} |
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
File renamed without changes.
Oops, something went wrong.
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.