From: Andreas Reichel <[email protected]>
From: Reichel Andreas <[email protected]>
If user specifies --filepath option it's now possible to specify an
output directory, where BGENV.DAT is created.
Signed-off-by: Andreas Reichel <[email protected]>
---
docs/TODO.md | 1 -
docs/USAGE.md | 12 ++++++------
tools/bg_setenv.c | 15 +++++++++++----
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/docs/TODO.md b/docs/TODO.md
index 40d5ba8..832f76b 100644
--- a/docs/TODO.md
+++ b/docs/TODO.md
@@ -6,7 +6,6 @@
the current working environment to the (latest-1) environment, so
that if the current environment breaks, there is a backup with the
latest values.
- * Make `bg_setenv -f` take a path to where the `BGENV.DAT` is stored.
* Application specific variables
* applications may need to store their own variables into the
diff --git a/docs/USAGE.md b/docs/USAGE.md
index 7dd89ce..97a25cb 100644
--- a/docs/USAGE.md
+++ b/docs/USAGE.md
@@ -98,13 +98,13 @@ This step first creates a custom label contained in
`EFILABEL`, which is later
used to specify the kernel location.
```
-# mount /dev/sdX2 /mnt && cd /mnt
-# echo -n "KERNEL1" | iconv -f ascii -t UTF-16LE > EFILABEL
-# bg_setenv -f -r 1 --kernel="C:KERNEL1:vmlinuz-linux" --args="root=/dev/sdX4
noinitrd"
+# mount /dev/sdX2 /mnt
+# echo -n "KERNEL1" | iconv -f ascii -t UTF-16LE > /mnt/EFILABEL
+# bg_setenv -f /mnt -r 1 --kernel="C:KERNEL1:vmlinuz-linux" --args="root=/dev/sdX4
noinitrd"
# umount /mnt
-# mount /dev/sdX3 /mnt && cd /mnt
-# echo -n "KERNEL2" | iconv -f ascii -t UTF-16LE > EFILABEL
-# bg_setenv -f -r 2 --kernel="C:KERNEL2:vmlinuz-linux" --args="root=/dev/sdX5
noinitrd"
+# mount /dev/sdX3 /mnt
+# echo -n "KERNEL2" | iconv -f ascii -t UTF-16LE > /mnt/EFILABEL
+# bg_setenv -f /mnt -r 2 --kernel="C:KERNEL2:vmlinuz-linux" --args="root=/dev/sdX5
noinitrd"
# umount /mnt
```
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 5c313cf..07f6610 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -24,7 +24,9 @@ static struct argp_option options_setenv[] = {
"above zero is updated."},
{"revision", 'r', "REVISION", 0, "Set revision value"},
{"testing", 't', "TESTING", 0, "Set test mode for environment"},
- {"file", 'f', 0, 0, "Output environment to file"},
+ {"filepath", 'f', "ENVFILE_DIR", 0, "Output environment to file. Please "
+ "only provide an output path. The "
+ "file name is automatically appended."},
{"watchdog", 'w', "WATCHDOG_TIMEOUT", 0, "Watchdog timeout in seconds"},
{"confirm", 'c', 0, 0, "Confirm working environment"},
{"update", 'u', 0, 0, "Automatically update oldest revision"},
@@ -58,6 +60,8 @@ static bool part_specified = false;
static bool verbosity = false;
+static char *envfilepath = NULL;
+
static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input;
@@ -138,6 +142,7 @@ static error_t parse_opt(int key, char *arg, struct
argp_state *state)
break;
case 'f':
arguments->output_to_file = true;
+ asprintf(&envfilepath, "%s/%s", arg, FAT_ENV_FILENAME);
break;
case 'c':
VERBOSE(stdout,
@@ -363,7 +368,7 @@ int main(int argc, char **argv)
if (verbosity) {
dump_env(&data);
}
- FILE *of = fopen(FAT_ENV_FILENAME, "wb");
+ FILE *of = fopen(envfilepath, "wb");
if (of) {
if (fwrite(&data, sizeof(BG_ENVDATA), 1, of) != 1) {
fprintf(stderr,
@@ -374,11 +379,13 @@ int main(int argc, char **argv)
fprintf(stderr, "Error closing output file.\n");
result = 1;
};
- printf("Output written to %s.\n", FAT_ENV_FILENAME);
+ printf("Output written to %s.\n", envfilepath);
} else {
- fprintf(stderr, "Error opening output file.\n");
+ fprintf(stderr, "Error opening output file %s.\n",
+ envfilepath);