diff options
author | Greg Hartman <ghartman@google.com> | 2019-04-24 02:03:29 +0000 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-05-02 21:02:36 -0700 |
commit | 5dd8694d77f001f581a3f839621df55f357ca1eb (patch) | |
tree | 5355230d7cd13634c3a412e104939073d0cb5a6c /arch | |
parent | e23231ccffb149108bb9f80d0b467b24153fcbfa (diff) | |
download | crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar.gz crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar.bz2 crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar.lz crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar.xz crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.tar.zst crosvm-5dd8694d77f001f581a3f839621df55f357ca1eb.zip |
Add Android fstab support to aarch64, based on x86_64 version
Test: cargo test on x86_64 and aarch64, boot on aarch64 Change-Id: I29fb269abedaaca4168581aa7f92d413d51e9232 Reviewed-on: https://chromium-review.googlesource.com/1585279 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Greg Hartman <ghartman@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Greg Hartman <ghartman@google.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/src/android.rs | 50 | ||||
-rw-r--r-- | arch/src/fdt.rs | 5 | ||||
-rw-r--r-- | arch/src/lib.rs | 1 |
3 files changed, 56 insertions, 0 deletions
diff --git a/arch/src/android.rs b/arch/src/android.rs new file mode 100644 index 0000000..3d459d4 --- /dev/null +++ b/arch/src/android.rs @@ -0,0 +1,50 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +use std::fs::File; +use std::io::BufRead; +use std::io::BufReader; + +use crate::fdt::{begin_node, end_node, property_string, Error, Result}; + +fn parse_fstab_line(line: &str) -> Result<Vec<String>> { + let vec: Vec<&str> = line.split_whitespace().collect(); + if vec.len() != 5 { + return Err(Error::FdtFileParseError); + } + Ok(vec.iter().map(|s| s.to_string()).collect()) +} + +/// Creates a flattened device tree containing all of the parameters used +/// by Android. +/// +/// # Arguments +/// +/// * `fdt` - The DTB to modify. The top-most node should be open. +/// * `android-fstab` - A text file of Android fstab entries to add to the DTB +pub fn create_android_fdt(fdt: &mut Vec<u8>, fstab: File) -> Result<()> { + let vecs = BufReader::new(fstab) + .lines() + .map(|l| parse_fstab_line(&l.map_err(Error::FdtIoError)?)) + .collect::<Result<Vec<Vec<String>>>>()?; + begin_node(fdt, "firmware")?; + begin_node(fdt, "android")?; + property_string(fdt, "compatible", "android,firmware")?; + begin_node(fdt, "fstab")?; + property_string(fdt, "compatible", "android,fstab")?; + for vec in vecs { + let partition = &vec[1][1..]; + begin_node(fdt, partition)?; + property_string(fdt, "compatible", &("android,".to_owned() + partition))?; + property_string(fdt, "dev", &vec[0])?; + property_string(fdt, "type", &vec[2])?; + property_string(fdt, "mnt_flags", &vec[3])?; + property_string(fdt, "fsmgr_flags", &vec[4])?; + end_node(fdt)?; + } + end_node(fdt)?; // fstab + end_node(fdt)?; // android + end_node(fdt)?; // firmware + Ok(()) +} diff --git a/arch/src/fdt.rs b/arch/src/fdt.rs index 0f77754..71c791d 100644 --- a/arch/src/fdt.rs +++ b/arch/src/fdt.rs @@ -6,6 +6,7 @@ use byteorder::{BigEndian, ByteOrder}; use libc::{c_char, c_int, c_void}; use std::ffi::{CStr, CString}; use std::fmt::{self, Display}; +use std::io; use std::ptr::null; // This links to libfdt which handles the creation of the binary blob @@ -35,6 +36,8 @@ pub enum Error { FdtFinishError(c_int), FdtPackError(c_int), FdtGuestMemoryWriteError, + FdtFileParseError, + FdtIoError(io::Error), } impl Display for Error { @@ -53,6 +56,8 @@ impl Display for Error { FdtFinishError(ret) => write!(f, "error performing FDT finish, code={}", ret), FdtPackError(ret) => write!(f, "error packing FDT, code={}", ret), FdtGuestMemoryWriteError => write!(f, "error writing FDT to guest memory"), + FdtFileParseError => write!(f, "parse error reading FDT parameters"), + FdtIoError(ret) => write!(f, "I/O error reading FDT parameters code={}", ret), } } } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 26967d3..31a0e19 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +pub mod android; pub mod fdt; use std::collections::BTreeMap; |