dtb: make dtb struct more useful
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
[1;36mHello, dtb is at 0x48000000[0m
|
||||
[1;36mMemory: 'memory@40000000', base 0x40000000, size 0x10000000[0m
|
||||
[1;36mReserved: 'kernel', base 0x40080000, size 0x1d000[0m
|
||||
[1;36mReserved: 'fdt', base 0x48000000, size 0x100000[0m
|
||||
[1;36mReserved: 'page-array', base 0x4009d000, size 0x100000[0m
|
||||
[1;36mAvailable memory: 253 MiB, page array mem.phys.Page@4009d000[0m
|
||||
QEMU: Terminated
|
||||
|
||||
@@ -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(" ");
|
||||
|
||||
Reference in New Issue
Block a user