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