Previously, the command

bg_setenv -f files/BGENV.DAT --args "root=/dev/sdb"

would correctly update the kernelargs, but all other key/value pairs are
lost (actually, memset to zero). In particular, BGENV.DAT no longer
stores a reference to the kernel file and thus, the device is unable to
boot from the updated BGENV.

The new behavior is as follows:

* if BGENV.DAT already exists, load it before applying the k/v updates
* otherwise fall back to the previous behavior, i.e. create a new
  BGENV.DAT and apply the k/v updates to it

Signed-off-by: Michael Adler <[email protected]>
---
 tools/bg_setenv.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index d26eeed..522fd83 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -601,13 +601,18 @@ static int printenv_from_file(char *envfilepath) {
 static int dumpenv_to_file(char *envfilepath) {
        /* execute journal and write to file */
        int result = 0;
+       int success = 0;
        BGENV env;
        BG_ENVDATA data;
 
        memset(&env, 0, sizeof(BGENV));
-       memset(&data, 0, sizeof(BG_ENVDATA));
        env.data = &data;
 
+       success = get_env(envfilepath, &data);
+       if (!success) {
+               memset(&data, 0, sizeof(BG_ENVDATA));
+       }
+
        update_environment(&env);
        if (verbosity) {
                dump_env(env.data);
-- 
2.33.0

-- 
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/20211005073709.1019435-2-michael.adler%40siemens.com.

Reply via email to