summaryrefslogtreecommitdiffstats
path: root/commands/of_dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands/of_dump.c')
-rw-r--r--commands/of_dump.c100
1 files changed, 36 insertions, 64 deletions
diff --git a/commands/of_dump.c b/commands/of_dump.c
index 06b8e9fcda..2508d4ce11 100644
--- a/commands/of_dump.c
+++ b/commands/of_dump.c
@@ -1,21 +1,7 @@
-/*
- * of_dump.c - dump devicetrees to the console
- *
- * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: © 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+
+/* of_dump.c - dump devicetrees to the console */
#include <common.h>
#include <libfile.h>
@@ -35,10 +21,13 @@ static void of_print_nodenames(struct device_node *node)
{
struct device_node *n;
- printf("%s\n", node->full_name);
+ printf("%pOF\n", node);
- list_for_each_entry(n, &node->children, parent_list)
+ list_for_each_entry(n, &node->children, parent_list) {
+ if (ctrlc())
+ return;
of_print_nodenames(n);
+ }
}
static int do_of_dump(int argc, char *argv[])
@@ -48,11 +37,11 @@ static int do_of_dump(int argc, char *argv[])
int fix = 0;
struct device_node *root = NULL, *node, *of_free = NULL;
char *dtbfile = NULL;
- size_t size;
const char *nodename;
- int names_only = 0;
+ unsigned maxpropsize = ~0;
+ int names_only = 0, properties_only = 0;
- while ((opt = getopt(argc, argv, "Ff:n")) > 0) {
+ while ((opt = getopt(argc, argv, "Ff:npP:")) > 0) {
switch (opt) {
case 'f':
dtbfile = optarg;
@@ -63,6 +52,14 @@ static int do_of_dump(int argc, char *argv[])
case 'n':
names_only = 1;
break;
+ case 'p':
+ properties_only = 1;
+ break;
+ case 'P':
+ ret = kstrtouint(optarg, 0, &maxpropsize);
+ if (ret)
+ return ret;
+ break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -74,49 +71,21 @@ static int do_of_dump(int argc, char *argv[])
nodename = argv[optind];
if (dtbfile) {
- void *fdt;
-
- fdt = read_file(dtbfile, &size);
- if (!fdt) {
- printf("unable to read %s: %s\n", dtbfile, strerror(errno));
- return -errno;
- }
-
- root = of_unflatten_dtb(fdt);
-
- free(fdt);
-
- if (IS_ERR(root)) {
- ret = PTR_ERR(root);
- goto out;
- }
+ root = of_read_file(dtbfile);
+ if (IS_ERR(root))
+ return PTR_ERR(root);
of_free = root;
} else {
root = of_get_root_node();
- if (fix) {
- /* create a copy of internal devicetree */
- void *fdt;
- fdt = of_flatten_dtb(root);
- root = of_unflatten_dtb(fdt);
-
- free(fdt);
-
- if (IS_ERR(root)) {
- ret = PTR_ERR(root);
- goto out;
- }
-
- of_free = root;
- }
+ /* copy internal device tree to apply fixups onto it */
+ if (fix)
+ root = of_free = of_dup(root);
}
- if (fix) {
- ret = of_fix_tree(root);
- if (ret)
- goto out;
- }
+ if (fix)
+ of_fix_tree(root);
node = of_find_node_by_path_or_alias(root, nodename);
if (!node) {
@@ -125,14 +94,15 @@ static int do_of_dump(int argc, char *argv[])
goto out;
}
- if (names_only)
+ if (names_only && !properties_only)
of_print_nodenames(node);
+ else if (properties_only && !names_only)
+ of_print_properties(node, maxpropsize);
else
- of_print_nodes(node, 0);
+ of_print_nodes(node, 0, maxpropsize);
out:
- if (of_free)
- of_delete_node(of_free);
+ of_delete_node(of_free);
return ret;
}
@@ -142,12 +112,14 @@ BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-f dtb", "work on dtb instead of internal devicetree")
BAREBOX_CMD_HELP_OPT ("-F", "return fixed devicetree")
BAREBOX_CMD_HELP_OPT ("-n", "Print node names only, no properties")
+BAREBOX_CMD_HELP_OPT ("-p", "Print properties only, no child nodes")
+BAREBOX_CMD_HELP_OPT ("-P len", "print only len property bytes")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(of_dump)
.cmd = do_of_dump,
BAREBOX_CMD_DESC("dump devicetree nodes")
- BAREBOX_CMD_OPTS("[-fFn] [NODE]")
+ BAREBOX_CMD_OPTS("[-fFnpP] [NODE]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_COMPLETE(devicetree_file_complete)
BAREBOX_CMD_HELP(cmd_of_dump_help)