summaryrefslogtreecommitdiffstats
path: root/commands/oftree.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-01-11 17:38:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-01-19 11:48:17 +0100
commit9a554f8ff25685e44431079e73887b061d6f4a41 (patch)
tree9cd7ccaf97ecf3b29fa1aec7cf97e5bd4dcf8b33 /commands/oftree.c
parenta886dac94e8466c640e4aa23e1629467a941f439 (diff)
downloadbarebox-9a554f8ff25685e44431079e73887b061d6f4a41.tar.gz
barebox-9a554f8ff25685e44431079e73887b061d6f4a41.tar.xz
oftree command: Add -s option to save internal oftree to file
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/oftree.c')
-rw-r--r--commands/oftree.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/commands/oftree.c b/commands/oftree.c
index c5239eb8eb..ddbff3e374 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -36,6 +36,7 @@
#include <errno.h>
#include <getopt.h>
#include <init.h>
+#include <fcntl.h>
static int do_oftree(int argc, char *argv[])
{
@@ -48,10 +49,11 @@ static int do_oftree(int argc, char *argv[])
int dump = 0;
int probe = 0;
int load = 0;
+ int save = 0;
int free_of = 0;
int ret;
- while ((opt = getopt(argc, argv, "dpfn:l")) > 0) {
+ while ((opt = getopt(argc, argv, "dpfn:ls")) > 0) {
switch (opt) {
case 'l':
load = 1;
@@ -73,6 +75,9 @@ static int do_oftree(int argc, char *argv[])
case 'n':
node = optarg;
break;
+ case 's':
+ save = 1;
+ break;
}
}
@@ -88,9 +93,30 @@ static int do_oftree(int argc, char *argv[])
if (optind < argc)
file = argv[optind];
- if (!dump && !probe && !load)
+ if (!dump && !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");
+ ret = -EINVAL;
+
+ goto out;
+ }
+
+ ret = write_file(file, fdt, fdt_totalsize(fdt));
+
+ goto out;
+ }
+
if (file) {
fdt = read_file(file, &size);
if (!fdt) {