Skip to main content

cargo_image_runner/bootloader/
none.rs

1use super::{Bootloader, BootloaderFiles, ConfigFile};
2use crate::config::BootType;
3use crate::core::context::Context;
4use crate::core::error::Result;
5
6/// No bootloader - direct boot of the executable.
7///
8/// This bootloader is suitable for UEFI executables that can be booted directly
9/// by placing them in the correct EFI directory structure.
10pub struct NoneBootloader;
11
12impl NoneBootloader {
13    /// Create a new direct boot (no bootloader) instance.
14    pub fn new() -> Self {
15        Self
16    }
17}
18
19impl Default for NoneBootloader {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl Bootloader for NoneBootloader {
26    fn prepare(&self, ctx: &Context) -> Result<BootloaderFiles> {
27        let mut files = BootloaderFiles::new();
28
29        // For UEFI direct boot, copy the executable to EFI/BOOT/BOOTX64.EFI
30        if ctx.config.boot.boot_type.needs_uefi() {
31            files = files.add_uefi_file(
32                ctx.executable.clone(),
33                "efi/boot/bootx64.efi".into(),
34            );
35        }
36
37        Ok(files)
38    }
39
40    fn config_files(&self, _ctx: &Context) -> Result<Vec<ConfigFile>> {
41        // No config files needed for direct boot
42        Ok(Vec::new())
43    }
44
45    fn boot_type(&self) -> BootType {
46        // Direct boot supports UEFI only by default
47        BootType::Uefi
48    }
49
50    fn name(&self) -> &str {
51        "Direct Boot (no bootloader)"
52    }
53}