pub fn load_bzimage(kernel_image: &mut File) -> Result<RealModeKernelHeader> {
    let mut boot_hdr = RealModeKernelHeader::new();

    kernel_image.seek(SeekFrom::Start(BOOT_HDR_START))?;
    kernel_image
        .read_exact(&mut boot_hdr.as_mut_bytes())
        .chain_err(|| "Failed to read boot_hdr from bzImage kernel")?;
    boot_hdr.type_of_loader = UNDEFINED_ID;

    if let Err(e) = boot_hdr.check_valid_kernel() {
        kernel_image.seek(SeekFrom::Start(0))?;
        return Err(e);
    }

    let mut setup_size = boot_hdr.setup_sects as u64;
    if setup_size == 0 {
        setup_size = 4;
    }
    setup_size = (setup_size + 1) << 9;
    kernel_image.seek(SeekFrom::Start(setup_size as u64))?;

    Ok(boot_hdr)
}
/// Load bzImage linux kernel to Guest Memory.
///
/// # Notes
/// According to Linux `Documentation/x86/boot.txt`, bzImage includes two parts:
/// * the setup
/// * the compressed kernel
/// The setup `RealModeKernelHeader` can be load at offset `0x01f1` in bzImage kernel image.
/// The compressed kernel will be loaded into guest memory at `code32_start` in
/// `RealModeKernelHeader`.
/// The start address of compressed kernel is the loader address + 0x200. It will be
/// set in `kernel_start` in `BootLoader` structure set.
///
/// # Arguments
///
/// * `kernel_image` - Guest kernel image.
///
/// # Errors
///
/// * Invalid BzImage header or version.
/// * Failed to write bzImage linux kernel to guest memory.
Load bzImage linux kernel to Guest Memory.
Load bzImage linux kernel to Guest Memory .
pub fn load_bzimage(kernel_image: &mut File) -> Result<RealModeKernelHeader> {
    let mut boot_hdr = RealModeKernelHeader::new();
    kernel_image.seek(SeekFrom::Start(BOOT_HDR_START))?;
    kernel_image
        .read_exact(&mut boot_hdr.as_mut_bytes())
        .chain_err(|| "Failed to read boot_hdr from bzImage kernel")?;
    boot_hdr.type_of_loader = UNDEFINED_ID;
    if let Err(e) = boot_hdr.check_valid_kernel() {
        kernel_image.seek(SeekFrom::Start(0))?;
        return Err(e);
    }
    let mut setup_size = boot_hdr.setup_sects as u64;
    if setup_size == 0 {
        setup_size = 4;
    }
    setup_size = (setup_size + 1) << 9;
    kernel_image.seek(SeekFrom::Start(setup_size as u64))?;
    Ok(boot_hdr)
}
pub fn load_bzimage ( kernel_image : & mut File ) -> Result < RealModeKernelHeader > { let mut boot_hdr = RealModeKernelHeader :: new ( ) ; kernel_image . seek ( SeekFrom :: Start ( BOOT_HDR_START ) ) ? ; kernel_image . read_exact ( & mut boot_hdr . as_mut_bytes ( ) ) . chain_err ( | | " " ) ? ; boot_hdr . type_of_loader = UNDEFINED_ID ; if let Err ( e ) = boot_hdr . check_valid_kernel ( ) { kernel_image . seek ( SeekFrom :: Start ( 0 ) ) ? ; return Err ( e ) ; } let mut setup_size = boot_hdr . setup_sects as u64 ; if setup_size == 0 { setup_size = 4 ; } setup_size = ( setup_size + 1 ) << 9 ; kernel_image . seek ( SeekFrom :: Start ( setup_size as u64 ) ) ? ; Ok ( boot_hdr ) }
Load bzImage linux kernel to Guest Memory.
Load bzImage linux kernel to Guest Memory .
kernel_image
&mut File
kernel_image
&mut File
notes
According to Linux `Documentation/x86/boot.txt`, bzImage includes two parts:
the setup
the compressed kernel
The setup `RealModeKernelHeader` can be load at offset `0x01f1` in bzImage kernel image.
The compressed kernel will be loaded into guest memory at `code32_start` in
`RealModeKernelHeader`.
The start address of compressed kernel is the loader address + 0x200. It will be
set in `kernel_start` in `BootLoader` structure set.
According to Linux ` Documentation / x86 / boot . txt ` bzImage includes two parts : the setup the compressed kernel The setup ` RealModeKernelHeader ` can be load at offset ` 0x01f1 ` in bzImage kernel image . The compressed kernel will be loaded into guest memory at ` code32_start ` in ` RealModeKernelHeader ` . The start address of compressed kernel is the loader address + 0x200 . It will be set in ` kernel_start ` in ` BootLoader ` structure set .
errors
Invalid BzImage header or version.
Failed to write bzImage linux kernel to guest memory.
Invalid BzImage header or version . Failed to write bzImage linux kernel to guest memory .