summaryrefslogtreecommitdiffstats
path: root/commands/of_dump.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-19 13:58:35 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-22 08:09:09 +0200
commit9cd128d6bea2152ee2152543f688fff3be13db52 (patch)
treecdd45dbabb7c73874974edb1753896880671dd0f /commands/of_dump.c
parente275b2653f87dc6969b3c0baf6f0e7460c62a8db (diff)
downloadbarebox-9cd128d6bea2152ee2152543f688fff3be13db52.tar.gz
barebox-9cd128d6bea2152ee2152543f688fff3be13db52.tar.xz
commands: add of_dump command
The oftree command is overloaded. This adds a dedicated command which only dumps devicetrees to the console so that the corresponding functionality in the oftree command can be removed in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/of_dump.c')
-rw-r--r--commands/of_dump.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/commands/of_dump.c b/commands/of_dump.c
new file mode 100644
index 0000000000..62140a8111
--- /dev/null
+++ b/commands/of_dump.c
@@ -0,0 +1,108 @@
+/*
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <fdt.h>
+#include <of.h>
+#include <command.h>
+#include <fs.h>
+#include <malloc.h>
+#include <complete.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <errno.h>
+#include <getopt.h>
+#include <linux/err.h>
+
+static int do_of_dump(int argc, char *argv[])
+{
+ int opt;
+ int ret;
+ struct device_node *root = NULL, *node, *of_free = NULL;
+ char *dtbfile = NULL;
+ size_t size;
+ const char *nodename;
+
+ while ((opt = getopt(argc, argv, "f:")) > 0) {
+ switch (opt) {
+ case 'f':
+ dtbfile = optarg;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind == argc)
+ nodename = "/";
+ else
+ 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(NULL, fdt);
+
+ free(fdt);
+
+ if (IS_ERR(root)) {
+ ret = PTR_ERR(root);
+ goto out;
+ }
+
+ of_free = root;
+ } else {
+ root = of_get_root_node();
+ }
+
+ node = of_find_node_by_path_or_alias(root, nodename);
+ if (!node) {
+ printf("Cannot find nodepath %s\n", nodename);
+ ret = -ENOENT;
+ goto out;
+ }
+
+ of_print_nodes(node, 0);
+
+out:
+ if (of_free)
+ of_delete_node(of_free);
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(of_dump)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-f dtb", "work on dtb instead of internal devicetree\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_dump)
+ .cmd = do_of_dump,
+ BAREBOX_CMD_DESC("dump devicetree nodes")
+ BAREBOX_CMD_OPTS("[-f]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_COMPLETE(devicetree_file_complete)
+ BAREBOX_CMD_HELP(cmd_of_dump_help)
+BAREBOX_CMD_END