aboutsummaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-07-19 00:55:42 -0500
committerLeandro Pereira <leandro@hardinfo.org>2017-07-19 07:20:40 -0700
commit9b2982813bdb1241e2149bd48893d03e139d24bb (patch)
tree613fb1becf462956dace385c60294a8e816714f2 /includes
parentaf68d862d46e0bdc2d3d32a2fe5fba53456072cb (diff)
device tree: reworked and cleaned up
* Moved device tree functions to modules/devices/devicetree/dt_util.c * The dtr_* functions usable from outside devicetree.c, for example in get_motherboard(). Must #include "dt_util.h" * Now possible to use an alternate device tree root for testing -DOVRDTRROOT=\"/some/path\" * Alternately, pass dtr_new() an alternate base path. * Abandoned the tuple grouping and inherited properties stuff for now. Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'includes')
-rw-r--r--includes/dt_util.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/includes/dt_util.h b/includes/dt_util.h
new file mode 100644
index 00000000..e044def7
--- /dev/null
+++ b/includes/dt_util.h
@@ -0,0 +1,61 @@
+
+#ifndef _DT_UTIL_H_
+#define _DT_UTIL_H_
+
+#include <stdint.h>
+
+/* some not-quite-complete stuff that can be disabled */
+#define DTEX_PHREFS 0
+
+#ifndef DTR_ROOT
+#define DTR_ROOT "/proc/device-tree"
+#endif
+
+enum {
+ DT_TYPE_ERR,
+
+ DT_NODE,
+ DTP_UNK, /* arbitrary-length byte sequence */
+ DTP_EMPTY, /* empty property */
+ DTP_STR, /* null-delimited list of strings */
+ DTP_HEX, /* list of 32-bit values displayed in hex */
+ DTP_UINT,
+ /* DTP_INT, */
+ DTP_PH, /* phandle */
+ DTP_PH_REF, /* reference to phandle */
+};
+
+/* simplest, no aliases.
+ * use dtr_get_prop_str() for complete. */
+char* dtr_get_string(const char *p);
+
+typedef uint32_t dt_uint; /* big-endian */
+
+typedef struct _dtr dtr;
+typedef struct _dtr_obj dtr_obj;
+
+dtr *dtr_new(char *base_path); /* NULL for DTR_ROOT */
+void dtr_free(dtr *);
+const char *dtr_base_path(dtr *);
+
+dtr_obj *dtr_obj_read(dtr *, const char *dtp);
+void dtr_obj_free(dtr_obj *);
+int dtr_obj_type(dtr_obj *);
+char *dtr_obj_alias(dtr_obj *);
+char *dtr_obj_path(dtr_obj *);
+char *dtr_obj_full_path(dtr_obj *);
+
+char* dtr_str(dtr *, dtr_obj *obj);
+dtr_obj *dtr_get_prop_obj(dtr *, dtr_obj *node, const char *name);
+char *dtr_get_prop_str(dtr *, dtr_obj *node, const char *name);
+uint32_t dtr_get_prop_u32(dtr *, dtr_obj *node, const char *name);
+
+static int dtr_guess_type(dtr_obj *obj);
+char *dtr_elem_phref(dtr *, dt_uint e);
+char *dtr_elem_hex(dt_uint e);
+char *dtr_elem_byte(uint8_t e);
+char *dtr_elem_uint(dt_uint e);
+char *dtr_list_byte(uint8_t *bytes, unsigned long count);
+char *dtr_list_hex(dt_uint *list, unsigned long count);
+
+#endif