aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/dt_util.h4
-rw-r--r--modules/devices/devicetree/dt_util.c16
2 files changed, 19 insertions, 1 deletions
diff --git a/includes/dt_util.h b/includes/dt_util.h
index 4f4daac1..bf56c293 100644
--- a/includes/dt_util.h
+++ b/includes/dt_util.h
@@ -9,7 +9,7 @@
#define DTEX_MTUP 0
#ifndef DTR_ROOT
-#define DTR_ROOT "/proc/device-tree"
+#define DTR_ROOT dtr_find_device_tree_root()
#endif
enum {
@@ -70,4 +70,6 @@ char *dtr_list_hex(dt_uint *list, unsigned long count);
char *dtr_maps_info(dtr *); /* returns hardinfo shell section */
+const char *dtr_find_device_tree_root(void);
+
#endif
diff --git a/modules/devices/devicetree/dt_util.c b/modules/devices/devicetree/dt_util.c
index dbeda3a6..845ea8da 100644
--- a/modules/devices/devicetree/dt_util.c
+++ b/modules/devices/devicetree/dt_util.c
@@ -192,6 +192,22 @@ void _dtr_read_aliases(dtr *);
void _dtr_read_symbols(dtr *);
void _dtr_map_phandles(dtr *, char *np);
+const char *dtr_find_device_tree_root() {
+ char *candidates[] = {
+ "/proc/device-tree",
+ "/sys/firmware/devicetree/base",
+ /* others? */
+ NULL
+ };
+ int i = 0;
+ while (candidates[i] != NULL) {
+ if(access(candidates[i], F_OK) != -1)
+ return candidates[i];
+ i++;
+ }
+ return "/did/not/find/device-tree";
+}
+
dtr *dtr_new_x(char *base_path, int fast) {
dtr *dt = malloc(sizeof(dtr));
if (dt != NULL) {