From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 12/16] oftree command: refactor
Date: Fri, 11 Jan 2013 14:24:32 +0100 [thread overview]
Message-ID: <1357910676-4231-13-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1357910676-4231-1-git-send-email-s.hauer@pengutronix.de>
This has several improvements for the oftree command:
- loading a devicetree (-l) and actually probing (-p) it now is separated
- the command now can dump the internal devicetree or a dtb given on the
command line.
- The -f option now actually frees the internal devicetree
With this the usage pattern for this command is:
oftree -l /env/oftree
oftree -d -n /sound
oftree -d /env/oftree
oftree -f
oftree -p
oftree -l -p /env/oftree
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/oftree.c | 99 ++++++++++++++++++++++++++++++++++++-----------------
common/oftree.c | 11 ++++--
2 files changed, 76 insertions(+), 34 deletions(-)
diff --git a/commands/oftree.c b/commands/oftree.c
index 17af9eb..c5239eb 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -39,17 +39,23 @@
static int do_oftree(int argc, char *argv[])
{
- struct fdt_header *fdt;
+ struct fdt_header *fdt = NULL;
+ void *fdt_free = NULL;
int size;
int opt;
char *file = NULL;
const char *node = "/";
int dump = 0;
int probe = 0;
+ int load = 0;
+ int free_of = 0;
int ret;
- while ((opt = getopt(argc, argv, "dpfn:")) > 0) {
+ while ((opt = getopt(argc, argv, "dpfn:l")) > 0) {
switch (opt) {
+ case 'l':
+ load = 1;
+ break;
case 'd':
dump = 1;
break;
@@ -62,66 +68,97 @@ static int do_oftree(int argc, char *argv[])
}
break;
case 'f':
- return 0;
+ free_of = 1;
+ break;
case 'n':
node = optarg;
break;
}
}
+ if (free_of) {
+ struct device_node *root = of_get_root_node();
+
+ if (root)
+ of_free(root);
+
+ return 0;
+ }
+
if (optind < argc)
file = argv[optind];
- if (!dump && !probe)
+ if (!dump && !probe && !load)
return COMMAND_ERROR_USAGE;
- if (dump) {
- if (file) {
- fdt = read_file(file, &size);
- if (!fdt) {
- printf("unable to read %s\n", file);
- return 1;
- }
-
- fdt_print(fdt, node);
- free(fdt);
- } else {
+ if (file) {
+ fdt = read_file(file, &size);
+ if (!fdt) {
+ printf("unable to read %s\n", file);
return 1;
}
- return 0;
- }
- if (probe) {
- if (!file)
- return COMMAND_ERROR_USAGE;
+ fdt_free = fdt;
+ }
- fdt = read_file(file, &size);
+ if (load) {
if (!fdt) {
- perror("open");
- return 1;
+ printf("no fdt given\n");
+ ret = -ENOENT;
+
+ goto out;
}
ret = of_unflatten_dtb(fdt);
if (ret) {
printf("parse oftree: %s\n", strerror(-ret));
- return 1;
+ goto out;
}
+ }
- of_probe();
+ if (dump) {
+ if (fdt) {
+ ret = fdt_print(fdt, node);
+ } else {
+ struct device_node *n = of_find_node_by_path(node);
+
+ if (!n) {
+ ret = -ENOENT;
+ goto out;
+ }
+
+ of_print_nodes(n, 0);
+
+ ret = 0;
+ }
+
+ goto out;
}
- return 0;
+ if (probe) {
+ ret = of_probe();
+ if (ret)
+ goto out;
+ }
+
+ ret = 0;
+out:
+ free(fdt_free);
+
+ return ret;
}
BAREBOX_CMD_HELP_START(oftree)
-BAREBOX_CMD_HELP_USAGE("oftree [OPTIONS]\n")
-BAREBOX_CMD_HELP_OPT ("-p <FILE>", "probe devices in oftree from <file>\n")
-BAREBOX_CMD_HELP_OPT ("-d [FILE]", "dump oftree from [FILE] or the parsed tree if no file is given\n")
-BAREBOX_CMD_HELP_OPT ("-f", "free stored oftree\n")
+BAREBOX_CMD_HELP_USAGE("oftree [OPTIONS] [DTB]\n")
+BAREBOX_CMD_HELP_OPT ("-l", "Load [DTB] to internal devicetree\n")
+BAREBOX_CMD_HELP_OPT ("-p", "probe devices from stored devicetree\n")
+BAREBOX_CMD_HELP_OPT ("-d", "dump oftree from [DTB] or the parsed tree if no dtb is given\n")
+BAREBOX_CMD_HELP_OPT ("-f", "free stored devicetree\n")
+BAREBOX_CMD_HELP_OPT ("-n <node>", "specify root devicenode to dump for -d\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(oftree)
.cmd = do_oftree,
- .usage = "handle oftrees",
+ .usage = "handle devicetrees",
BAREBOX_CMD_HELP(cmd_oftree_help)
BAREBOX_CMD_END
diff --git a/common/oftree.c b/common/oftree.c
index d699cb6..0df5209 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -325,11 +325,14 @@ int of_fix_tree(struct fdt_header *fdt)
struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
{
int ret;
- void *fixfdt;
+ void *fixfdt, *internalfdt = NULL;
int size, align;
- if (!fdt)
- return NULL;
+ if (!fdt) {
+ fdt = internalfdt = of_flatten_dtb();
+ if (!fdt)
+ return NULL;
+ }
size = fdt_totalsize(fdt);
@@ -343,6 +346,8 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
fixfdt = xmemalign(align, size + OFTREE_SIZE_INCREASE);
ret = fdt_open_into(fdt, fixfdt, size + OFTREE_SIZE_INCREASE);
+ free(internalfdt);
+
if (ret)
goto out_free;
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-01-11 13:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-11 13:24 [PATCH] devicetree improvements Sascha Hauer
2013-01-11 13:24 ` [PATCH 01/16] of: make of_get_fixed_tree more universally usable Sascha Hauer
2013-01-11 13:24 ` [PATCH 02/16] of: Fix invalid path for of_find_node_by_path Sascha Hauer
2013-01-11 13:24 ` [PATCH 03/16] ARM android image: remove double of_fix_tree Sascha Hauer
2013-01-11 13:24 ` [PATCH 04/16] of: of_free fixes Sascha Hauer
2013-01-11 13:24 ` [PATCH 05/16] of of_free: remove old node from allnodes list Sascha Hauer
2013-01-11 13:24 ` [PATCH 06/16] of: return root node when looking for a node with path / Sascha Hauer
2013-01-11 13:24 ` [PATCH 07/16] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 08/16] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 09/16] of: remove unused barebox_fdt Sascha Hauer
2013-01-11 13:24 ` [PATCH 10/16] ARM bootm: only use concatenated oftree when no other is available Sascha Hauer
2013-01-11 13:24 ` [PATCH 11/16] of: unflatten: allow overlay dtbs Sascha Hauer
2013-01-11 13:24 ` Sascha Hauer [this message]
2013-01-11 13:24 ` [PATCH 13/16] of: add of_delete_property Sascha Hauer
2013-01-11 13:24 ` [PATCH 14/16] of: rename new_device_node to of_new_node and export it Sascha Hauer
2013-01-11 13:24 ` [PATCH 15/16] commands: Add of_property command Sascha Hauer
2013-01-11 13:24 ` [PATCH 16/16] commands: Add of_node command Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357910676-4231-13-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox