arch: x86_64: Update linux-loader crate

The linux-loader crate has been updated with a regnerated bootparams.rs
which has changed the API slightly. Update to the latest linux-loader
and adapt the code to reflect the changes:

* e820_map is renamed to e820_table (and all similar variables updated)
* e820entry is renamed to boot_e820_entry
* The E820 type constants are not no longer included

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2019-08-14 17:31:10 +01:00 committed by Samuel Ortiz
parent 76e3a30c31
commit 513d2fdcf6
2 changed files with 20 additions and 18 deletions

2
Cargo.lock generated
View File

@ -421,7 +421,7 @@ dependencies = [
[[package]] [[package]]
name = "linux-loader" name = "linux-loader"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rust-vmm/linux-loader#891ea4f0af62b2f80f5a3ddbbb6be588b19a78da" source = "git+https://github.com/rust-vmm/linux-loader#b2700818add982aa361842a0b8da776b3d1b5cb3"
dependencies = [ dependencies = [
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)", "vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
] ]

View File

@ -12,12 +12,14 @@ mod mptable;
pub mod regs; pub mod regs;
use crate::RegionType; use crate::RegionType;
use linux_loader::loader::bootparam::{boot_params, setup_header, E820_RAM}; use linux_loader::loader::bootparam::{boot_params, setup_header};
use std::mem; use std::mem;
use vm_memory::{ use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap, GuestUsize, Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap, GuestUsize,
}; };
const E820_RAM: u32 = 1;
// This is a workaround to the Rust enforcement specifying that any implementation of a foreign // This is a workaround to the Rust enforcement specifying that any implementation of a foreign
// trait (in this case `DataInit`) where: // trait (in this case `DataInit`) where:
// * the type that is implementing the trait is foreign or // * the type that is implementing the trait is foreign or
@ -198,13 +200,13 @@ fn add_e820_entry(
size: u64, size: u64,
mem_type: u32, mem_type: u32,
) -> Result<(), Error> { ) -> Result<(), Error> {
if params.e820_entries >= params.e820_map.len() as u8 { if params.e820_entries >= params.e820_table.len() as u8 {
return Err(Error::E820Configuration); return Err(Error::E820Configuration);
} }
params.e820_map[params.e820_entries as usize].addr = addr; params.e820_table[params.e820_entries as usize].addr = addr;
params.e820_map[params.e820_entries as usize].size = size; params.e820_table[params.e820_entries as usize].size = size;
params.e820_map[params.e820_entries as usize].type_ = mem_type; params.e820_table[params.e820_entries as usize].type_ = mem_type;
params.e820_entries += 1; params.e820_entries += 1;
Ok(()) Ok(())
@ -213,7 +215,7 @@ fn add_e820_entry(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use linux_loader::loader::bootparam::e820entry; use linux_loader::loader::bootparam::boot_e820_entry;
#[test] #[test]
fn regions_lt_4gb() { fn regions_lt_4gb() {
@ -290,14 +292,14 @@ mod tests {
#[test] #[test]
fn test_add_e820_entry() { fn test_add_e820_entry() {
let e820_map = [(e820entry { let e820_table = [(boot_e820_entry {
addr: 0x1, addr: 0x1,
size: 4, size: 4,
type_: 1, type_: 1,
}); 128]; }); 128];
let expected_params = boot_params { let expected_params = boot_params {
e820_map, e820_table,
e820_entries: 1, e820_entries: 1,
..Default::default() ..Default::default()
}; };
@ -305,25 +307,25 @@ mod tests {
let mut params: boot_params = Default::default(); let mut params: boot_params = Default::default();
add_e820_entry( add_e820_entry(
&mut params, &mut params,
e820_map[0].addr, e820_table[0].addr,
e820_map[0].size, e820_table[0].size,
e820_map[0].type_, e820_table[0].type_,
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
format!("{:?}", params.e820_map[0]), format!("{:?}", params.e820_table[0]),
format!("{:?}", expected_params.e820_map[0]) format!("{:?}", expected_params.e820_table[0])
); );
assert_eq!(params.e820_entries, expected_params.e820_entries); assert_eq!(params.e820_entries, expected_params.e820_entries);
// Exercise the scenario where the field storing the length of the e820 entry table is // Exercise the scenario where the field storing the length of the e820 entry table is
// is bigger than the allocated memory. // is bigger than the allocated memory.
params.e820_entries = params.e820_map.len() as u8 + 1; params.e820_entries = params.e820_table.len() as u8 + 1;
assert!(add_e820_entry( assert!(add_e820_entry(
&mut params, &mut params,
e820_map[0].addr, e820_table[0].addr,
e820_map[0].size, e820_table[0].size,
e820_map[0].type_ e820_table[0].type_
) )
.is_err()); .is_err());
} }