summaryrefslogtreecommitdiffstats
path: root/commands/oftree.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-09-11 18:22:13 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-09-14 11:47:42 +0200
commitf4eb95053584b1bd79c02024018e19b7f8813b06 (patch)
tree5f3eacbce81a43a0c24e2c0fa60a730d496dfab9 /commands/oftree.c
parent58f3457f4f03313a7bab58f36382d57048fbe1c1 (diff)
downloadbarebox-f4eb95053584b1bd79c02024018e19b7f8813b06.tar.gz
barebox-f4eb95053584b1bd79c02024018e19b7f8813b06.tar.xz
oftree command: Add devicetree probe support
With this the -p option is no longer for parse, but for probe instead. Using this parses a devicetree given on the command line and probes the devices found in this tree. Devices which already exist are not probed again, but instead their device_node is attached to the existing device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/oftree.c')
-rw-r--r--commands/oftree.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/commands/oftree.c b/commands/oftree.c
index 77afbc5a19..6479fa4e94 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -48,7 +48,8 @@ static int do_oftree(int argc, char *argv[])
char *file = NULL;
const char *node = "/";
int dump = 0;
- int parse = 0;
+ int probe = 0;
+ int ret;
while ((opt = getopt(argc, argv, "dpfn:")) > 0) {
switch (opt) {
@@ -56,7 +57,12 @@ static int do_oftree(int argc, char *argv[])
dump = 1;
break;
case 'p':
- parse = 1;
+ if (IS_ENABLED(CONFIG_CMD_OFTREE_PROBE)) {
+ probe = 1;
+ } else {
+ printf("oftree device probe support disabled\n");
+ return COMMAND_ERROR_USAGE;
+ }
break;
case 'f':
free(barebox_fdt);
@@ -71,7 +77,7 @@ static int do_oftree(int argc, char *argv[])
if (optind < argc)
file = argv[optind];
- if (!dump && !parse)
+ if (!dump && !probe)
return COMMAND_ERROR_USAGE;
if (dump) {
@@ -95,7 +101,7 @@ static int do_oftree(int argc, char *argv[])
return 0;
}
- if (parse) {
+ if (probe) {
if (!file)
return COMMAND_ERROR_USAGE;
@@ -105,17 +111,13 @@ static int do_oftree(int argc, char *argv[])
return 1;
}
- fdt = xrealloc(fdt, size + 0x8000);
- fdt_open_into(fdt, fdt, size + 0x8000);
- if (!fdt) {
- printf("unable to read %s\n", file);
+ ret = of_parse_dtb(fdt);
+ if (ret) {
+ printf("parse oftree: %s\n", strerror(-ret));
return 1;
}
- if (barebox_fdt)
- free(barebox_fdt);
-
- barebox_fdt = fdt;
+ of_probe();
}
return 0;
@@ -123,7 +125,7 @@ static int do_oftree(int argc, char *argv[])
BAREBOX_CMD_HELP_START(oftree)
BAREBOX_CMD_HELP_USAGE("oftree [OPTIONS]\n")
-BAREBOX_CMD_HELP_OPT ("-p <FILE>", "parse and store oftree from <file>\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_END