Skip to content

Commit

Permalink
fdt: enumerate all memory nodes present
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Thomas Barrett authored and retrage committed Aug 24, 2024
1 parent ab7bd76 commit c6d6d39
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ impl Info for StartInfo<'_> {
}

fn num_entries(&self) -> usize {
self.fdt.memory().regions().count()
let nodes = self.fdt.find_all_nodes("/memory");
let regions = nodes.flat_map(|n| n.reg().expect("should contain valid memory regions"));
regions.count()
}

fn entry(&self, idx: usize) -> MemoryEntry {
for (i, region) in self.fdt.memory().regions().enumerate() {
let nodes = self.fdt.find_all_nodes("/memory");
let regions = nodes.flat_map(|n| n.reg().expect("should contain valid memory regions"));
for (i, region) in regions.enumerate() {
if i == idx {
return MemoryEntry {
addr: region.starting_address as u64,
Expand Down

0 comments on commit c6d6d39

Please sign in to comment.