|
@@ -89,21 +89,11 @@ pub fn get_num_harts(dtb_addr: usize) -> usize {
|
|
|
fdt::Fdt::from_ptr(dtb_addr as *const u8)
|
|
fdt::Fdt::from_ptr(dtb_addr as *const u8)
|
|
|
.expect("Failed to parse device tree from dtb_addr")
|
|
.expect("Failed to parse device tree from dtb_addr")
|
|
|
};
|
|
};
|
|
|
|
|
+ let dtb_cpus = fdt.cpus();
|
|
|
let mut num_harts = 0;
|
|
let mut num_harts = 0;
|
|
|
- if let Some(cpus_node) = fdt.find_node("/cpus") {
|
|
|
|
|
- for cpu_node in cpus_node.children() {
|
|
|
|
|
- if let Some(compatible_prop) = cpu_node
|
|
|
|
|
- .properties()
|
|
|
|
|
- .find(|p| p.name == "compatible")
|
|
|
|
|
- {
|
|
|
|
|
- if let Some(s) = compatible_prop.as_str() {
|
|
|
|
|
- if s.starts_with("riscv,") {
|
|
|
|
|
- // 找到一个 RISC-V CPU 节点,增加计数。
|
|
|
|
|
- num_harts += 1;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for _cpu in dtb_cpus {
|
|
|
|
|
+ num_harts += 1;
|
|
|
}
|
|
}
|
|
|
num_harts
|
|
num_harts
|
|
|
}
|
|
}
|