tools/bg_setenv.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 0429c01..0a2ebce 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -53,6 +53,9 @@ static struct argp_option options_printenv[] = {
{"filepath", 'f', "ENVFILE", 0,
"Read environment from file. Expects a valid EFI Boot Guard "
"environment file."},
+ {"part", 'p', "ENV_PART", 0,
+ "Set environment partition to read from. If no partition is specified, "
+ "all config partitions will be read."},
{"verbose", 'v', 0, 0, "Be verbose"},
{"version", 'V', 0, 0, "Print version"},
{}
@@ -276,7 +279,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
return 1;
}
if (i >= 0 && i < ENV_NUM_CONFIG_PARTS) {
- fprintf(stdout, "Updating config partition #%d\n", i);
+ fprintf(stdout, "Using config partition #%d\n", i);
arguments->which_part = i;
part_specified = true;
} else {
@@ -546,24 +549,32 @@ static void update_environment(BGENV *env)
}
+static bool dump_env_by_index(uint32_t index)
+{
+ if (verbosity) {
+ fprintf(stdout, "\n----------------------------\n");
+ fprintf(stdout, " Config Partition #%d ", index);
+ }
+ BGENV *env = bgenv_open_by_index(index);
+ if (!env) {
+ fprintf(stderr, "Error, could not read environment "
+ "for index %d\n",
+ index);
+ return false;
+ }
+ if (verbosity) {
+ dump_env(env->data);
+ }
+ bgenv_close(env);
+ return true;
+}
+
static void dump_envs(void)
{
for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
- if (verbosity) {
- fprintf(stdout, "\n----------------------------\n");
- fprintf(stdout, " Config Partition #%d ", i);
- }
- BGENV *env = bgenv_open_by_index(i);
- if (!env) {
- fprintf(stderr, "Error, could not read environment "
- "for index %d\n",
- i);
+ if (!dump_env_by_index(i)) {
return;
}
- if (verbosity) {
- dump_env(env->data);
- }
- bgenv_close(env);
}
}
@@ -703,7 +714,11 @@ int main(int argc, char **argv)
return 1;
}
- dump_envs();
+ if (part_specified) {
+ dump_env_by_index(arguments.which_part);
+ } else {
+ dump_envs();
+ }
if (!write_mode) {
bgenv_finalize();
--
2.33.0