mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 6/6] oftree command: make devicetree file optargs to -l/-s
Date: Mon, 19 May 2014 22:59:44 +0200	[thread overview]
Message-ID: <1400533184-668-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1400533184-668-1-git-send-email-s.hauer@pengutronix.de>

When loading or saving a devicetree it seems logical to add the
filename to the option specifying the command. This is also slightly
easier to parse.
While at it add missing documentation for the -s option.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/oftree.c | 54 ++++++++++++++++--------------------------------------
 1 file changed, 16 insertions(+), 38 deletions(-)

diff --git a/commands/oftree.c b/commands/oftree.c
index 2c45b93..a3b0e04 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -42,13 +42,11 @@
 static int do_oftree(int argc, char *argv[])
 {
 	struct fdt_header *fdt = NULL;
-	void *fdt_free = NULL;
 	int size;
 	int opt;
-	char *file = NULL;
 	int probe = 0;
-	int load = 0;
-	int save = 0;
+	char *load = NULL;
+	char *save = NULL;
 	int free_of = 0;
 	int ret;
 	struct device_node *root;
@@ -56,7 +54,7 @@ static int do_oftree(int argc, char *argv[])
 	while ((opt = getopt(argc, argv, "pfl:s:")) > 0) {
 		switch (opt) {
 		case 'l':
-			load = 1;
+			load = optarg;
 			break;
 		case 'p':
 			if (IS_ENABLED(CONFIG_OFDEVICE)) {
@@ -70,7 +68,7 @@ static int do_oftree(int argc, char *argv[])
 			free_of = 1;
 			break;
 		case 's':
-			save = 1;
+			save = optarg;
 			break;
 		}
 	}
@@ -85,20 +83,10 @@ static int do_oftree(int argc, char *argv[])
 			return 0;
 	}
 
-	if (optind < argc)
-		file = argv[optind];
-
 	if (!probe && !load && !save)
 		return COMMAND_ERROR_USAGE;
 
 	if (save) {
-		if (!file) {
-			printf("no file given\n");
-			ret = -ENOENT;
-
-			goto out;
-		}
-
 		fdt = of_get_fixed_tree(NULL);
 		if (!fdt) {
 			printf("no devicetree available\n");
@@ -107,39 +95,29 @@ static int do_oftree(int argc, char *argv[])
 			goto out;
 		}
 
-		ret = write_file(file, fdt, fdt32_to_cpu(fdt->totalsize));
+		ret = write_file(save, fdt, fdt32_to_cpu(fdt->totalsize));
 
 		goto out;
 	}
 
-	if (file) {
-		fdt = read_file(file, &size);
+	if (load) {
+		fdt = read_file(load, &size);
 		if (!fdt) {
-			printf("unable to read %s\n", file);
+			printf("unable to read %s\n", load);
 			return 1;
 		}
 
-		fdt_free = fdt;
-	}
-
-	if (load) {
-		if (!fdt) {
-			printf("no fdt given\n");
-			ret = -ENOENT;
+		root = of_unflatten_dtb(fdt);
 
-			goto out;
-		}
+		free(fdt);
 
-		root = of_unflatten_dtb(fdt);
 		if (IS_ERR(root))
-			ret = PTR_ERR(root);
-		else
-			ret = 0;
+			return PTR_ERR(root);
 
 		ret = of_set_root_node(root);
-
 		if (ret) {
-			printf("parse oftree: %s\n", strerror(-ret));
+			printf("setting root node failed: %s\n", strerror(-ret));
+			of_delete_node(root);
 			goto out;
 		}
 	}
@@ -152,14 +130,14 @@ static int do_oftree(int argc, char *argv[])
 
 	ret = 0;
 out:
-	free(fdt_free);
 
 	return ret;
 }
 
 BAREBOX_CMD_HELP_START(oftree)
 BAREBOX_CMD_HELP_TEXT("Options:")
-BAREBOX_CMD_HELP_OPT ("-l",  "Load DTB to internal device tree")
+BAREBOX_CMD_HELP_OPT ("-l <DTB>",  "Load <DTB> to internal devicetree\n")
+BAREBOX_CMD_HELP_OPT ("-s <DTB>",  "save internal devicetree to <DTB>\n")
 BAREBOX_CMD_HELP_OPT ("-p",  "probe devices from stored device tree")
 BAREBOX_CMD_HELP_OPT ("-f",  "free stored device tree")
 BAREBOX_CMD_HELP_END
@@ -167,7 +145,7 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(oftree)
 	.cmd		= do_oftree,
 	BAREBOX_CMD_DESC("handle device trees")
-	BAREBOX_CMD_OPTS("[-lpf] [DTB]")
+	BAREBOX_CMD_OPTS("[-lpfs]")
 	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
 	BAREBOX_CMD_HELP(cmd_oftree_help)
 BAREBOX_CMD_END
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2014-05-19 21:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19 20:59 [PATCH] devicetree command changes Sascha Hauer
2014-05-19 20:59 ` [PATCH 1/6] complete: Fix completion after options Sascha Hauer
2014-05-19 20:59 ` [PATCH 2/6] complete: Add devicetree completion Sascha Hauer
2014-05-19 20:59 ` [PATCH 3/6] commands: add of_dump command Sascha Hauer
2014-05-21 13:17   ` Holger Schurig
2014-05-22  6:10     ` Sascha Hauer
2014-05-19 20:59 ` [PATCH 4/6] oftree: remove dump support Sascha Hauer
2014-05-20  8:01   ` Alexander Aring
2014-05-20  8:03     ` Alexander Aring
2014-05-20  9:08       ` Sascha Hauer
2014-05-19 20:59 ` [PATCH 5/6] of: Drop devicetree merge support Sascha Hauer
2014-05-20 15:08   ` Sebastian Hesselbarth
2014-05-21  6:13     ` Sascha Hauer
2014-05-21  6:35     ` Esben Haabendal
2014-05-21 12:39       ` Sascha Hauer
2014-05-21 13:24   ` Holger Schurig
2014-05-19 20:59 ` Sascha Hauer [this message]

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=1400533184-668-7-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