On 16.10.23 04:48, Felix Moessbauer wrote:
> With the recent change in libebgenv to only search on the current boot
> device (default), the provided tools could no longer be used for
> recovery. To solve this, we add a command line option to all tools to
> explicitly enable the system-wide search for ebg environments.
>
> Signed-off-by: Felix Moessbauer <[email protected]>
> ---
> docs/API.md | 3 +++
> tools/bg_envtools.c | 4 ++++
> tools/bg_envtools.h | 4 ++++
> tools/bg_printenv.c | 4 ++++
> tools/bg_setenv.c | 5 +++++
> 5 files changed, 20 insertions(+)
>
> diff --git a/docs/API.md b/docs/API.md
> index 42e2963..cde4cef 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -50,6 +50,7 @@ and sets it to the testing state:
> int main(void)
> {
> ebgenv_t e;
> + memset(&e, 0, sizeof(ebgenv_t));
>
> ebg_env_create_new(&e);
> ebg_env_set(&e, "kernelfile", "vmlinux-new");
> @@ -76,6 +77,7 @@ modifies the kernel file name:
> int main(void)
> {
> ebgenv_t e;
> + memset(&e, 0, sizeof(ebgenv_t));
>
> ebg_env_open_current(&e);
> ebg_env_set(&e, "kernelfile", "vmlinux-new");
> @@ -93,6 +95,7 @@ int main(void)
> int main(void)
> {
> ebgenv_t e;
> + memset(&e, 0, sizeof(ebgenv_t));
>
> ebg_env_open_current(&e);
>
> diff --git a/tools/bg_envtools.c b/tools/bg_envtools.c
> index 2d29e46..5c8128f 100644
> --- a/tools/bg_envtools.c
> +++ b/tools/bg_envtools.c
> @@ -67,6 +67,10 @@ error_t parse_common_opt(int key, char *arg, bool
> compat_mode,
> bool found = false;
> int i;
> switch (key) {
> + case 'A':
> + found = true;
> + arguments->search_all_devices = true;
> + break;
> case 'f':
> found = true;
> free(arguments->envfilepath);
> diff --git a/tools/bg_envtools.h b/tools/bg_envtools.h
> index 8081d86..376041c 100644
> --- a/tools/bg_envtools.h
> +++ b/tools/bg_envtools.h
> @@ -35,6 +35,8 @@
> "Set environment partition to use. If no partition is " \
> "specified, the one with the smallest revision value above " \
> "zero is selected.") \
> + , OPT("all", 'A', 0, 0, \
> + "search on all devices instead of root device only") \
> , OPT("verbose", 'v', 0, 0, "Be verbose") \
> , OPT("version", 'V', 0, 0, "Print version")
>
> @@ -46,6 +48,8 @@ struct arguments_common {
> * was specified. */
> int which_part;
> bool part_specified;
> + /* inspect all devices for bootenvs instead of current root only */
> + bool search_all_devices;
> };
>
> int parse_int(char *arg);
> diff --git a/tools/bg_printenv.c b/tools/bg_printenv.c
> index abf745b..db37826 100644
> --- a/tools/bg_printenv.c
> +++ b/tools/bg_printenv.c
> @@ -345,6 +345,10 @@ error_t bg_printenv(int argc, char **argv)
>
> /* not in file mode */
> ebgenv_t ebgenv;
> + memset(&ebgenv, 0, sizeof(ebgenv_t));
> + if (arguments.common.search_all_devices) {
> + ebg_set_opt(&ebgenv, EBG_OPT_SEARCH_ALL_DEVICES, (void *)1);
> + }
> if (!bgenv_init(&ebgenv)) {
This is really a weird API: Calling ebg_set_opt on an env that has not
been initialized. Another reason to pass search-all-devices as option ov
bgenv_init.
Jan
> fprintf(stderr, "Error initializing FAT environment.\n");
> return 1;
> diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
> index 27706ac..0024e9c 100644
> --- a/tools/bg_setenv.c
> +++ b/tools/bg_setenv.c
> @@ -115,6 +115,7 @@ newaction_nomem:
> static void journal_process_action(BGENV *env, struct env_action *action)
> {
> ebgenv_t e;
> + memset(&e, 0, sizeof(ebgenv_t));
>
> switch (action->task) {
> case ENV_TASK_SET:
> @@ -419,6 +420,10 @@ error_t bg_setenv(int argc, char **argv)
>
> /* not in file mode */
> ebgenv_t ebgenv;
> + memset(&ebgenv, 0, sizeof(ebgenv_t));
> + if (arguments.common.search_all_devices) {
> + ebg_set_opt(&ebgenv, EBG_OPT_SEARCH_ALL_DEVICES, (void *)1);
> + }
> if (!bgenv_init(&ebgenv)) {
> fprintf(stderr, "Error initializing FAT environment.\n");
> return 1;
--
Siemens AG, Technology
Linux Expert Center
--
You received this message because you are subscribed to the Google Groups "EFI
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/efibootguard-dev/fc9c626a-e73e-490e-8aa9-42337bf5b68b%40siemens.com.