Skip to content

Commit

Permalink
arm: use BootConfigurator to write fdt in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra Iordache committed Apr 9, 2020
1 parent 7f77e10 commit 83cc093
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 24 deletions.
72 changes: 72 additions & 0 deletions src/configurator/aarch64/fdt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

//! Traits and structs for loading the device tree.

use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemory};

use std::error::Error as StdError;
use std::fmt;

use super::super::{BootConfigurator, Error as BootConfiguratorError, Result};

/// Errors specific to the device tree boot protocol configuration.
#[derive(Debug, PartialEq)]
pub enum Error {
/// Error writing FDT in memory.
WriteFDTToMemory,
}

impl StdError for Error {
fn description(&self) -> &str {
use Error::*;
match self {
WriteFDTToMemory => "Error writing FDT in guest memory.",
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Device Tree Boot Configurator Error: {}",
StdError::description(self)
)
}
}

impl From<Error> for BootConfiguratorError {
fn from(err: Error) -> Self {
BootConfiguratorError::Fdt(err)
}
}

/// Boot configurator for device tree.
pub struct FdtBootConfigurator {}

impl BootConfigurator for FdtBootConfigurator {
/// Writes the boot parameters (configured elsewhere) into guest memory.
///
/// # Arguments
///
/// * `fdt` - flattened device tree.
/// * `sections` - unused.
/// * `guest_memory` - guest's physical memory.
fn write_bootparams<T, S, M>(
fdt: (T, GuestAddress),
_sections: Option<(Vec<S>, GuestAddress)>,
guest_memory: &M,
) -> Result<()>
where
T: ByteValued,
S: ByteValued,
M: GuestMemory,
{
// The VMM has filled an FDT and passed it as a `ByteValued` object.
guest_memory
.write_obj(fdt.0, fdt.1)
.map_err(|_| Error::WriteFDTToMemory.into())
}
}
22 changes: 1 addition & 21 deletions src/configurator/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,4 @@

#![cfg(target_arch = "aarch64")]

use std::error::Error as StdError;
use std::fmt;

/// Placeholder error type.
#[derive(Debug, PartialEq)]
pub enum Error {
/// Placeholder error value.
Placeholder,
}

impl StdError for Error {
fn description(&self) -> &str {
unimplemented!()
}
}

impl fmt::Display for Error {
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
pub mod fdt;
6 changes: 3 additions & 3 deletions src/configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use x86_64::*;
#[cfg(target_arch = "aarch64")]
mod aarch64;
#[cfg(target_arch = "aarch64")]
pub use aarch64::Error as ArmError;
pub use aarch64::*;

/// Errors specific to boot protocol configuration.
#[derive(Debug, PartialEq)]
Expand All @@ -42,7 +42,7 @@ pub enum Error {
Pvh(pvh::Error),
/// Errors specific to device tree boot configuration.
#[cfg(target_arch = "aarch64")]
Arm(ArmError),
Fdt(fdt::Error),
}

impl StdError for Error {
Expand All @@ -54,7 +54,7 @@ impl StdError for Error {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Pvh(ref e) => e.description(),
#[cfg(target_arch = "aarch64")]
Arm(ref e) => e.description(),
Fdt(ref e) => e.description(),
}
}
}
Expand Down

0 comments on commit 83cc093

Please sign in to comment.