summaryrefslogtreecommitdiffstats
path: root/commands/oftree.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-19 14:46:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-22 08:09:13 +0200
commit4d1ebec9dac6b8b6b10fc1b3ce1a899df1fca1a1 (patch)
tree343ce38141a0e4f2a944ead053b04cb1bc9d2e05 /commands/oftree.c
parentd384b5639fc1a3cff60610e375a2096de413b71f (diff)
downloadbarebox-4d1ebec9dac6b8b6b10fc1b3ce1a899df1fca1a1.tar.gz
barebox-4d1ebec9dac6b8b6b10fc1b3ce1a899df1fca1a1.tar.xz
oftree command: make devicetree file optargs to -l/-s
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>
Diffstat (limited to 'commands/oftree.c')
-rw-r--r--commands/oftree.c54
1 files changed, 16 insertions, 38 deletions
diff --git a/commands/oftree.c b/commands/oftree.c
index 2c45b935d2..a3b0e04861 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