• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #[cfg(any(target_os = "android", target_os = "linux"))]
6 use std::collections::BTreeMap;
7 use std::fs::File;
8 use std::path::PathBuf;
9 
10 use arch::android::create_android_fdt;
11 use arch::apply_device_tree_overlays;
12 use arch::DtbOverlay;
13 use cros_fdt::Error;
14 use cros_fdt::Fdt;
15 
16 use crate::SetupData;
17 use crate::SetupDataType;
18 
19 /// Creates a flattened device tree containing all of the parameters for the
20 /// kernel and returns it as `SetupData`.
21 ///
22 /// # Arguments
23 ///
24 /// * `android_fstab` - the File object for the android fstab
create_fdt( android_fstab: File, dump_device_tree_blob: Option<PathBuf>, device_tree_overlays: Vec<DtbOverlay>, ) -> Result<SetupData, Error>25 pub fn create_fdt(
26     android_fstab: File,
27     dump_device_tree_blob: Option<PathBuf>,
28     device_tree_overlays: Vec<DtbOverlay>,
29 ) -> Result<SetupData, Error> {
30     let mut fdt = Fdt::new(&[]);
31     // The whole thing is put into one giant node with some top level properties
32     create_android_fdt(&mut fdt, android_fstab)?;
33 
34     // Done writing base FDT, now apply DT overlays
35     apply_device_tree_overlays(
36         &mut fdt,
37         device_tree_overlays,
38         #[cfg(any(target_os = "android", target_os = "linux"))]
39         vec![],
40         #[cfg(any(target_os = "android", target_os = "linux"))]
41         &BTreeMap::new(),
42     )?;
43 
44     let fdt_final = fdt.finish()?;
45 
46     if let Some(file_path) = dump_device_tree_blob {
47         std::fs::write(&file_path, &fdt_final)
48             .map_err(|e| Error::FdtDumpIoError(e, file_path.clone()))?;
49     }
50 
51     Ok(SetupData {
52         data: fdt_final,
53         type_: SetupDataType::Dtb,
54     })
55 }
56