basic_info.rs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. static MY_FDT: &[u8] = include_bytes!("../test.dtb");
  2. fn main() {
  3. let fdt = fdt::Fdt::new(MY_FDT).unwrap();
  4. println!("This is a devicetree representation of a {}", fdt.root().model());
  5. println!("...which is compatible with at least: {}", fdt.root().compatible().first());
  6. println!("...and has {} CPU(s)", fdt.cpus().count());
  7. println!(
  8. "...and has at least one memory location at: {:#X}\n",
  9. fdt.memory().regions().next().unwrap().starting_address as usize
  10. );
  11. let chosen = fdt.chosen();
  12. if let Some(bootargs) = chosen.bootargs() {
  13. println!("The bootargs are: {:?}", bootargs);
  14. }
  15. if let Some(stdout) = chosen.stdout() {
  16. println!("It would write stdout to: {}", stdout.name);
  17. }
  18. let soc = fdt.find_node("/soc");
  19. println!("Does it have a `/soc` node? {}", if soc.is_some() { "yes" } else { "no" });
  20. if let Some(soc) = soc {
  21. println!("...and it has the following children:");
  22. for child in soc.children() {
  23. println!(" {}", child.name);
  24. }
  25. }
  26. }