-/* $OpenBSD: fdt.c,v 1.30 2022/08/21 12:52:10 jasper Exp $ */
+/* $OpenBSD: fdt.c,v 1.31 2022/09/11 08:33:03 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
OF_getnodebyname(int handle, const char *name)
{
void *node = (char *)tree.header + handle;
+ void *child;
+ char *data;
+ int len;
if (handle == 0)
node = fdt_find_node("/");
- for (node = fdt_child_node(node); node; node = fdt_next_node(node)) {
- if (strcmp(name, fdt_node_name(node)) == 0)
+ for (child = fdt_child_node(node); child;
+ child = fdt_next_node(child)) {
+ if (strcmp(name, fdt_node_name(child)) == 0)
break;
}
+ if (child)
+ return (char *)child - (char *)tree.header;
+
+ len = strlen(name);
+ for (child = fdt_child_node(node); child;
+ child = fdt_next_node(node)) {
+ data = fdt_node_name(child);
+ if (strncmp(name, data, len) == 0 &&
+ strlen(data) > len && data[len] == '@')
+ break;
+ }
+ if (child)
+ return (char *)child - (char *)tree.header;
- return node ? ((char *)node - (char *)tree.header) : 0;
+ return 0;
}
int