Skip to content

Commit fc55458

Browse files
author
Thomas Barrett
committed
fdt: enumerate all memory nodes present
It is possible for the device tree to have multiple memory nodes. Iterate through all regions defined by all memory nodes. Signed-off-by: Thomas Barrett <tbarrett@crusoe.ai>
1 parent 4c33124 commit fc55458

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/fdt.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,16 @@ impl Info for StartInfo<'_> {
7878
}
7979

8080
fn num_entries(&self) -> usize {
81-
self.fdt.memory().regions().count()
81+
let nodes = self.fdt.find_all_nodes("/memory");
82+
let regions = nodes.flat_map(|n| n.reg().unwrap());
83+
regions.count()
84+
// self.fdt.memory().regions().count()
8285
}
8386

8487
fn entry(&self, idx: usize) -> MemoryEntry {
85-
for (i, region) in self.fdt.memory().regions().enumerate() {
88+
let nodes = self.fdt.find_all_nodes("/memory");
89+
let regions = nodes.flat_map(|n| n.reg().unwrap());
90+
for (i, region) in regions.enumerate() {
8691
if i == idx {
8792
return MemoryEntry {
8893
addr: region.starting_address as u64,

src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ pub extern "C" fn rust64_start(#[cfg(not(feature = "coreboot"))] pvh_info: &pvh:
202202
#[cfg(target_arch = "aarch64")]
203203
#[no_mangle]
204204
pub extern "C" fn rust64_start(x0: *const u8) -> ! {
205+
use bootinfo::Info;
206+
205207
arch::aarch64::simd::setup_simd();
206208
arch::aarch64::paging::setup();
207209

@@ -217,6 +219,15 @@ pub extern "C" fn rust64_start(x0: *const u8) -> ! {
217219
None,
218220
);
219221

222+
for i in 0..info.num_entries() {
223+
let region = info.entry(i);
224+
info!(
225+
"Memory region {}MiB@0x{:x}",
226+
region.size / 1024 / 1024,
227+
region.addr
228+
);
229+
}
230+
220231
if let Some((base, length)) = info.find_compatible_region(&["pci-host-ecam-generic"]) {
221232
pci::init(base as u64, length as u64);
222233
}

0 commit comments

Comments
 (0)