[RFC,2/2] EXAMPLE: Print full DT path when adding a node

Message ID 20171006053029.1118-2-oohall@gmail.com
State New
Headers show
Series
  • [RFC,1/2] libc: Add custom printf specifiers
Related show

Commit Message

Oliver Oct. 6, 2017, 5:30 a.m.
An example of how to use the custom printf specifiers. In this case it
will print out the full node path when adding a node to
the device-tree, like so:

[    0.001493894,3] Added /ibm,opal to tree
[    0.001504982,3] Added /ibm,opal/event to tree
[    0.001512892,3] Added /ibm,opal/firmware to tree
[    0.001521920,3] Added /ibm,opal/firmware/exports to tree
[    0.001535936,3] Added /ibm,opal/power-mgt to tree

Not-signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/device.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch

diff --git a/core/device.c b/core/device.c
index fc1db5689a73..44463a9398a5 100644
--- a/core/device.c
+++ b/core/device.c
@@ -153,6 +153,8 @@  struct dt_node *dt_new(struct dt_node *parent, const char *name)
 		dt_destroy(new);
 		return NULL;
 	}
+
+	prerror("Added %pD to tree\n", new);
 	return new;
 }
 
@@ -1107,3 +1109,24 @@  void dt_adjust_subtree_phandle(struct dt_node *dev,
 
        set_last_phandle(max_phandle);
 }
+
+static int print_dt_node_path(char **buffer, size_t bufsize, const void *value)
+{
+	char *path = dt_get_path(value);
+	char *into = *buffer;
+	int i;
+
+	for (i = 0; path[i] && i < bufsize; i++)
+		into[i] = path[i];
+
+	*buffer += i;
+	free(path);
+
+	/* return the number of characters added to the buffer */
+	return i;
+}
+
+DECLARE_PRINTFMT(dt_node_path) = {
+	.specifier	= "D",
+	.func	 	= &print_dt_node_path,
+};