Skip to content

Commit 5680887

Browse files
committed
Reimplement BiosBoot and UefiBoot as wrappers around DiskImageBuilder
1 parent 6c2079f commit 5680887

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/bios/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::path::Path;
2+
3+
use crate::DiskImageBuilder;
4+
5+
const BIOS_STAGE_3: &str = "boot-stage-3";
6+
const BIOS_STAGE_4: &str = "boot-stage-4";
7+
8+
/// Create disk images for booting on legacy BIOS systems.
9+
pub struct BiosBoot {
10+
image_builder: DiskImageBuilder
11+
}
12+
13+
impl BiosBoot {
14+
/// Start creating a disk image for the given bootloader ELF executable.
15+
pub fn new(kernel_path: &Path) -> Self {
16+
Self {
17+
image_builder: DiskImageBuilder::new(kernel_path)
18+
}
19+
}
20+
21+
/// Add a ramdisk file to the image
22+
pub fn set_ramdisk(&mut self, ramdisk_path: &Path) -> &mut Self {
23+
self.image_builder.set_ramdisk(ramdisk_path);
24+
self
25+
}
26+
27+
/// Create a bootable BIOS disk image at the given path.
28+
pub fn create_disk_image(&self, out_path: &Path) -> anyhow::Result<()> {
29+
self.image_builder.create_bios_image(out_path)
30+
}
31+
}

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ An experimental x86_64 bootloader that works on both BIOS and UEFI systems.
88
mod gpt;
99
#[cfg(feature = "bios")]
1010
mod mbr;
11+
#[cfg(feature = "bios")]
12+
mod bios;
13+
#[cfg(feature = "uefi")]
14+
mod uefi;
1115

1216
mod fat;
1317

src/uefi/mod.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::path::Path;
2+
3+
use crate::DiskImageBuilder;
4+
5+
const BIOS_STAGE_3: &str = "boot-stage-3";
6+
const BIOS_STAGE_4: &str = "boot-stage-4";
7+
8+
/// Create disk images for booting on legacy BIOS systems.
9+
pub struct UefiBoot {
10+
image_builder: DiskImageBuilder
11+
}
12+
13+
impl UefiBoot {
14+
/// Start creating a disk image for the given bootloader ELF executable.
15+
pub fn new(kernel_path: &Path) -> Self {
16+
Self {
17+
image_builder: DiskImageBuilder::new(kernel_path)
18+
}
19+
}
20+
21+
/// Add a ramdisk file to the image
22+
pub fn set_ramdisk(&mut self, ramdisk_path: &Path) -> &mut Self {
23+
self.image_builder.set_ramdisk(ramdisk_path);
24+
self
25+
}
26+
27+
/// Create a bootable UEFI disk image at the given path.
28+
pub fn create_disk_image(&self, out_path: &Path) -> anyhow::Result<()> {
29+
self.image_builder.create_uefi_image(out_path)
30+
}
31+
32+
/// Prepare a folder for use with booting over UEFI_PXE.
33+
///
34+
/// This places the bootloader executable under the path "bootloader". The
35+
/// DHCP server should set the filename option to that path, otherwise the
36+
/// bootloader won't be found.
37+
pub fn create_pxe_tftp_folder(&self, out_path: &Path) -> anyhow::Result<()> {
38+
self.image_builder.create_uefi_tftp_folder(out_path)
39+
}
40+
}

0 commit comments

Comments
 (0)