Skip to content

Commit e5bec42

Browse files
Alexandra Iordacheandreeaflorescu
authored andcommitted
arm: use BootConfigurator to write fdt in memory
1 parent b446c4a commit e5bec42

File tree

3 files changed

+76
-24
lines changed

3 files changed

+76
-24
lines changed

src/configurator/aarch64/fdt.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
4+
5+
//! Traits and structs for loading the device tree.
6+
7+
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemory};
8+
9+
use std::error::Error as StdError;
10+
use std::fmt;
11+
12+
use super::super::{BootConfigurator, Error as BootConfiguratorError, Result};
13+
14+
/// Errors specific to the device tree boot protocol configuration.
15+
#[derive(Debug, PartialEq)]
16+
pub enum Error {
17+
/// Error writing FDT in memory.
18+
WriteFDTToMemory,
19+
}
20+
21+
impl StdError for Error {
22+
fn description(&self) -> &str {
23+
use Error::*;
24+
match self {
25+
WriteFDTToMemory => "Error writing FDT in guest memory.",
26+
}
27+
}
28+
}
29+
30+
impl fmt::Display for Error {
31+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32+
write!(
33+
f,
34+
"Device Tree Boot Configurator Error: {}",
35+
StdError::description(self)
36+
)
37+
}
38+
}
39+
40+
impl From<Error> for BootConfiguratorError {
41+
fn from(err: Error) -> Self {
42+
BootConfiguratorError::Fdt(err)
43+
}
44+
}
45+
46+
/// Boot configurator for device tree.
47+
pub struct FdtBootConfigurator {}
48+
49+
impl BootConfigurator for FdtBootConfigurator {
50+
/// Writes the boot parameters (configured elsewhere) into guest memory.
51+
///
52+
/// # Arguments
53+
///
54+
/// * `fdt` - flattened device tree.
55+
/// * `sections` - unused.
56+
/// * `guest_memory` - guest's physical memory.
57+
fn write_bootparams<T, S, M>(
58+
fdt: (T, GuestAddress),
59+
_sections: Option<(Vec<S>, GuestAddress)>,
60+
guest_memory: &M,
61+
) -> Result<()>
62+
where
63+
T: ByteValued,
64+
S: ByteValued,
65+
M: GuestMemory,
66+
{
67+
// The VMM has filled an FDT and passed it as a `ByteValued` object.
68+
guest_memory
69+
.write_obj(fdt.0, fdt.1)
70+
.map_err(|_| Error::WriteFDTToMemory.into())
71+
}
72+
}

src/configurator/aarch64/mod.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,4 @@
66
77
#![cfg(target_arch = "aarch64")]
88

9-
use std::error::Error as StdError;
10-
use std::fmt;
11-
12-
/// Placeholder error type.
13-
#[derive(Debug, PartialEq)]
14-
pub enum Error {
15-
/// Placeholder error value.
16-
Placeholder,
17-
}
18-
19-
impl StdError for Error {
20-
fn description(&self) -> &str {
21-
unimplemented!()
22-
}
23-
}
24-
25-
impl fmt::Display for Error {
26-
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
27-
unimplemented!()
28-
}
29-
}
9+
pub mod fdt;

src/configurator/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use x86_64::*;
2929
#[cfg(target_arch = "aarch64")]
3030
mod aarch64;
3131
#[cfg(target_arch = "aarch64")]
32-
pub use aarch64::Error as ArmError;
32+
pub use aarch64::*;
3333

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

4848
impl StdError for Error {
@@ -54,7 +54,7 @@ impl StdError for Error {
5454
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5555
Pvh(ref e) => e.description(),
5656
#[cfg(target_arch = "aarch64")]
57-
Arm(ref e) => e.description(),
57+
Fdt(ref e) => e.description(),
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)