diff options
-rw-r--r-- | scripts/ubootenv.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/ubootenv.c b/scripts/ubootenv.c index af5efd0b54..eb62123faf 100644 --- a/scripts/ubootenv.c +++ b/scripts/ubootenv.c @@ -56,17 +56,18 @@ void usage(char *prgname) "\n" "options:\n" " -s save (directory -> environment sector)\n" - " -l load (environment sector -> directory)\n", + " -l load (environment sector -> directory)\n" + " -p <size> pad output file to given size\n", prgname); } int main(int argc, char *argv[]) { int opt; - int save = 0, load = 0; + int save = 0, load = 0, pad = 0, fd; char *filename = NULL, *dirname = NULL; - while((opt = getopt(argc, argv, "sl")) != -1) { + while((opt = getopt(argc, argv, "slp:")) != -1) { switch (opt) { case 's': save = 1; @@ -74,6 +75,9 @@ int main(int argc, char *argv[]) case 'l': load = 1; break; + case 'p': + pad = strtoul(optarg, NULL, 0); + break; } } @@ -90,6 +94,22 @@ int main(int argc, char *argv[]) exit(1); } + if (save) { + fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644); + if (fd < 0) { + perror("open"); + exit(1); + } + close(fd); + } + + if (save && pad) { + if (truncate(filename, pad)) { + perror("truncate"); + exit(1); + } + } + if (load) { printf("loading env from file %s to %s\n", filename, dirname); envfs_load(filename, dirname); |