[][src]Trait linux_loader::configurator::BootConfigurator

pub trait BootConfigurator {
    fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>
    where
        M: GuestMemory
; }

Trait that defines interfaces for building (TBD) and configuring boot parameters.

Currently, this trait exposes a single function which writes user-provided boot parameters into guest memory at the user-specified addresses. It's meant to be called after the kernel is loaded and after the boot parameters are built externally (in the VMM).

This trait will be extended with additional functionality to build boot parameters.

Required methods

fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()> where
    M: GuestMemory

Writes the boot parameters (configured elsewhere) into guest memory.

The arguments are split into header and sections to accommodate different boot protocols like Linux boot and PVH. In Linux boot, the e820 map could be considered as sections, but it's already encapsulated in the boot_params and thus all the boot parameters are passed through a single struct. In PVH, the memory map table is separated from the hvm_start_info struct, therefore it's passed separately.

Arguments

  • params - struct containing the header section of the boot parameters, additional sections and modules, and their associated addresses in guest memory. These vary with the boot protocol used.
  • guest_memory - guest's physical memory.
Loading content...

Implementors

impl BootConfigurator for LinuxBootConfigurator[src]

fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()> where
    M: GuestMemory
[src]

Writes the boot parameters (configured elsewhere) into guest memory.

Arguments

  • params - boot parameters. The header contains a boot_params struct. The sections and modules are unused.
  • guest_memory - guest's physical memory.

Examples

fn build_bootparams() -> boot_params {
    let mut params = boot_params::default();
    params.hdr.boot_flag = KERNEL_BOOT_FLAG_MAGIC;
    params.hdr.header = KERNEL_HDR_MAGIC;
    params.hdr.kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES;
    params.hdr.type_of_loader = KERNEL_LOADER_OTHER;
    params
}

fn main() {
    let guest_memory = create_guest_memory();
    let params = build_bootparams();
    let mut bootparams = BootParams::new::<boot_params>(&params, zero_page_addr);
    LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(
        &bootparams,
        &guest_memory,
    ).unwrap();
}

impl BootConfigurator for PvhBootConfigurator[src]

fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()> where
    M: GuestMemory
[src]

Writes the boot parameters (configured elsewhere) into guest memory.

Arguments

Examples

fn create_guest_memory() -> GuestMemoryMmap {
    GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), (MEM_SIZE as usize))]).unwrap()
}

fn build_boot_params() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
    let mut start_info = hvm_start_info::default();
    let memmap_entry = hvm_memmap_table_entry {
        addr: 0x7000,
        size: 0,
        type_: E820_RAM,
        reserved: 0,
  };
  start_info.magic = XEN_HVM_START_MAGIC_VALUE;
  start_info.version = 1;
  start_info.nr_modules = 0;
  start_info.memmap_entries = 0;
  (start_info, vec![memmap_entry])
}

fn main() {
    let guest_mem = create_guest_memory();
    let (mut start_info, memmap_entries) = build_boot_params();
    let start_info_addr = GuestAddress(0x6000);
    let memmap_addr = GuestAddress(0x7000);
    start_info.memmap_paddr = memmap_addr.raw_value();

    let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
    boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
    PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
}
Loading content...