crosvm/arch/src/android.rs
Daniel Verkamp 1cc1d5e6ee arch: check property_string result in create_android_fdt
Add the missing '?' to check the result of the newly-added
property_string call to match the rest in this function.

Fixes clippy warning about an unused result.

BUG=None
TEST=docker/wrapped_smoke_test.sh

Change-Id: I428b377e1a4f15e0ee96c8e96540f2fc8edce560
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216400
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-27 04:46:32 +00:00

58 lines
2.1 KiB
Rust

// 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")?;
let (dtprop, fstab): (_, Vec<_>) = vecs.into_iter().partition(|x| x[0] == "#dt-vendor");
begin_node(fdt, "vendor")?;
for vec in dtprop {
let content = std::fs::read_to_string(&vec[2]).map_err(Error::FdtIoError)?;
property_string(fdt, &vec[1], &content)?;
}
end_node(fdt)?; // vendor
begin_node(fdt, "fstab")?;
property_string(fdt, "compatible", "android,fstab")?;
for vec in fstab {
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(())
}