Thanks to visit codestin.com
Credit goes to docs.rs

bootloader/uefi/
mod.rs

1use std::path::Path;
2
3use bootloader_boot_config::BootConfig;
4
5use crate::DiskImageBuilder;
6
7/// Create disk images for booting on UEFI systems.
8pub struct UefiBoot {
9    image_builder: DiskImageBuilder,
10}
11
12impl UefiBoot {
13    /// Start creating a disk image for the given bootloader ELF executable.
14    pub fn new(kernel_path: &Path) -> Self {
15        Self {
16            image_builder: DiskImageBuilder::new(kernel_path.to_owned()),
17        }
18    }
19
20    /// Add a ramdisk file to the image
21    pub fn set_ramdisk(&mut self, ramdisk_path: &Path) -> &mut Self {
22        self.image_builder.set_ramdisk(ramdisk_path.to_owned());
23        self
24    }
25
26    /// Creates a configuration file (boot.json) that configures the runtime behavior of the bootloader.
27    pub fn set_boot_config(&mut self, config: &BootConfig) -> &mut Self {
28        self.image_builder.set_boot_config(config);
29        self
30    }
31
32    /// Create a bootable UEFI disk image at the given path.
33    pub fn create_disk_image(&self, out_path: &Path) -> anyhow::Result<()> {
34        self.image_builder.create_uefi_image(out_path)
35    }
36
37    /// Prepare a folder for use with booting over UEFI_PXE.
38    ///
39    /// This places the bootloader executable under the path "bootloader". The
40    /// DHCP server should set the filename option to that path, otherwise the
41    /// bootloader won't be found.
42    pub fn create_pxe_tftp_folder(&self, out_path: &Path) -> anyhow::Result<()> {
43        self.image_builder.create_uefi_tftp_folder(out_path)
44    }
45}