aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-07-19 16:49:44 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2017-07-21 05:14:20 -0700
commite3c217f47dcfff0967bf48cdd9efa3e3e4f07d50 (patch)
tree8a124a9f1e79f7a263c9c7434658d9cc8a867ed7
parent41a3cde484b21c24c9a5f88461591c4a42603960 (diff)
device tree: try harder to find device-tree root
Signed-off-by: Burt P <pburt0@gmail.com>
-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) {