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/src/android.rs | |
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/src/android.rs')
-rw-r--r-- | arch/src/android.rs | 50 |
1 files changed, 50 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(()) +} |