Skip to content

Commit 8ad34d1

Browse files
committed
write fdt to memory in configure_system
- removes writing to memory in create_fdt - add functionality of writing to memory in configure_system - uses previously unused return value of create_fdt to write fdt to memory Signed-off-by: jackabald <[email protected]>
1 parent ef3900f commit 8ad34d1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/vmm/src/arch/aarch64/fdt.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ use vm_memory::GuestMemoryError;
1414

1515
use super::super::{DeviceType, InitrdConfig};
1616
use super::cache_info::{read_cache_config, CacheEntry};
17-
use super::get_fdt_addr;
1817
use super::gic::GICDevice;
1918
use crate::devices::acpi::vmgenid::{VmGenId, VMGENID_MEM_SIZE};
20-
use crate::vstate::memory::{Address, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap};
19+
use crate::vstate::memory::{Address, GuestMemory, GuestMemoryMmap};
2120

2221
// This is a value for uniquely identifying the FDT node declaring the interrupt controller.
2322
const GIC_PHANDLE: u32 = 1;
@@ -106,10 +105,6 @@ pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug, S: std::hash::BuildHasher
106105

107106
// Allocate another buffer so we can format and then write fdt to guest.
108107
let fdt_final = fdt_writer.finish()?;
109-
110-
// Write FDT to memory.
111-
let fdt_address = GuestAddress(get_fdt_addr(guest_mem));
112-
guest_mem.write_slice(fdt_final.as_slice(), fdt_address)?;
113108
Ok(fdt_final)
114109
}
115110

src/vmm/src/arch/aarch64/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ use std::collections::HashMap;
1717
use std::ffi::CString;
1818
use std::fmt::Debug;
1919

20+
use vm_memory::GuestMemoryError;
21+
2022
pub use self::fdt::DeviceInfoForFDT;
2123
use self::gic::GICDevice;
2224
use crate::arch::DeviceType;
2325
use crate::devices::acpi::vmgenid::VmGenId;
24-
use crate::vstate::memory::{Address, GuestAddress, GuestMemory, GuestMemoryMmap};
26+
use crate::vstate::memory::{Address, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap};
2527

2628
/// Errors thrown while configuring aarch64 system.
2729
#[derive(Debug, thiserror::Error, displaydoc::Display)]
@@ -30,6 +32,8 @@ pub enum ConfigurationError {
3032
SetupFDT(#[from] fdt::FdtError),
3133
/// Failed to compute the initrd address.
3234
InitrdAddress,
35+
/// Failed to write to guest memory.
36+
MemoryError(GuestMemoryError),
3337
}
3438

3539
/// The start of the memory area reserved for MMIO devices.
@@ -64,7 +68,7 @@ pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug, S: std::hash::Build
6468
vmgenid: &Option<VmGenId>,
6569
initrd: &Option<super::InitrdConfig>,
6670
) -> Result<(), ConfigurationError> {
67-
fdt::create_fdt(
71+
let fdt = fdt::create_fdt(
6872
guest_mem,
6973
vcpu_mpidr,
7074
cmdline_cstring,
@@ -73,6 +77,10 @@ pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug, S: std::hash::Build
7377
vmgenid,
7478
initrd,
7579
)?;
80+
let fdt_address = GuestAddress(get_fdt_addr(guest_mem));
81+
guest_mem
82+
.write_slice(fdt.as_slice(), fdt_address)
83+
.map_err(ConfigurationError::MemoryError)?;
7684
Ok(())
7785
}
7886

0 commit comments

Comments
 (0)