]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: avoid adding variables twice
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Thu, 29 Dec 2022 08:13:22 +0000 (10:13 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 29 Dec 2022 09:51:50 +0000 (10:51 +0100)
When the efi subsystem starts we restore variables that are both in a
file or stored into the .efi_runtime section of U-Boot.  However once
a variable gets created or changed the preseeded entries will end up in
the file.  As a consequence on the next boot we will end up adding
identical variable entries twice.

Fix this by checking if the to be inserted variable already exists.
Also swap the restoration order and start with the file instead of the
builtin variables,  so a user can replace the preseeded ones if needed.

Tested-by: Leo Yan <leo.yan@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_loader/efi_var_file.c
lib/efi_loader/efi_variable.c

index de9ba8de996799e1acff43479fc3be6978cb1ef8..62e071bd834111af1953dbd300252b23ff6d46e2 100644 (file)
@@ -187,6 +187,8 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
                        continue;
                if (!var->length)
                        continue;
+               if (efi_var_mem_find(&var->guid, var->name, NULL))
+                       continue;
                ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
                                      var->length, data, 0, NULL,
                                      var->time);
index 8ca2d85694c87ab8bc81ac05ae6b960450392074..503a33ed65c555a69157c0b0879b1a673d77ac25 100644 (file)
@@ -425,6 +425,9 @@ efi_status_t efi_init_variables(void)
        if (ret != EFI_SUCCESS)
                return ret;
 
+       ret = efi_var_from_file();
+       if (ret != EFI_SUCCESS)
+               return ret;
        if (IS_ENABLED(CONFIG_EFI_VARIABLES_PRESEED)) {
                ret = efi_var_restore((struct efi_var_file *)
                                      __efi_var_file_begin, true);
@@ -432,9 +435,6 @@ efi_status_t efi_init_variables(void)
                        log_err("Invalid EFI variable seed\n");
        }
 
-       ret = efi_var_from_file();
-       if (ret != EFI_SUCCESS)
-               return ret;
 
        return efi_init_secure_state();
 }