dtb: make dtb struct more useful

This commit is contained in:
2025-03-18 09:51:41 +02:00
parent 3f79177839
commit a668443bea
2 changed files with 31 additions and 8 deletions
-8
View File
@@ -1,8 +0,0 @@
Hello, dtb is at 0x48000000
Memory: 'memory@40000000', base 0x40000000, size 0x10000000
Reserved: 'kernel', base 0x40080000, size 0x1d000
Reserved: 'fdt', base 0x48000000, size 0x100000
Reserved: 'page-array', base 0x4009d000, size 0x100000
Available memory: 253 MiB, page array mem.phys.Page@4009d000
QEMU: Terminated
+31
View File
@@ -88,6 +88,11 @@ pub const FdtNodeProp = struct {
return .{ .prop = self };
}
pub inline fn getString(self: *const @This()) []const u8 {
var sa = self.getStringArray();
return sa.next() orelse "";
}
pub inline fn lenU32(self: *const @This()) usize {
return self.value.len / @sizeOf(u32);
}
@@ -382,6 +387,32 @@ pub const Fdt = struct {
}
}
pub fn find(self: *const @This(), path: []const u8) ?FdtNode {
const trimmedPath = std.mem.trimLeft(u8, path, "/");
var pathElements = std.mem.splitScalar(u8, trimmedPath, '/');
var currentNode = self.rootNode();
if (trimmedPath.len == 0) {
return currentNode;
}
while (pathElements.next()) |element| {
var found: ?FdtNode = null;
var children = currentNode.children();
while (children.next()) |child| {
if (std.mem.eql(u8, child.name, element)) {
found = child;
break;
}
}
if (found) |f| {
log.info("{s}", .{ element });
currentNode = f;
} else {
return null;
}
}
return currentNode;
}
fn dump_property(property: *const FdtNodeProp, depth: usize, allStrings: bool) void {
for (0..depth) |_| {
log.writeRaw(" ");