]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: set CapsuleMax from CONFIG_EFI_CAPSULE_MAX
authorEtienne Carriere <etienne.carriere@linaro.org>
Thu, 16 Feb 2023 17:21:41 +0000 (18:21 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 19 Feb 2023 20:15:15 +0000 (21:15 +0100)
Adds CONFIG_EFI_CAPSULE_MAX to configure the max index value used in
EFI capsule reports. Prior to this change is the hard coded value was
65535 which would exceed available storage for variables. Now the
default value is 15 which should work fine with most systems.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
lib/efi_loader/Kconfig
lib/efi_loader/efi_capsule.c
lib/efi_loader/efi_setup.c

index c05a54df16a044b036949c819ff4fce868f64dd4..c5835e6ef61a15a1d19d896c14409957504d6547 100644 (file)
@@ -226,6 +226,14 @@ config EFI_CAPSULE_AUTHENTICATE
          Select this option if you want to enable capsule
          authentication
 
+config EFI_CAPSULE_MAX
+       int "Max value for capsule index"
+       default 15
+       range 0 65535
+       help
+         Select the max capsule index value used for capsule report
+         variables. This value is used to create CapsuleMax variable.
+
 config EFI_DEVICE_PATH_TO_TEXT
        bool "Device path to text protocol"
        default y
index 0997cd248fe353e46354bff70adb062f2a7ab098..d5d3ede7ae66ab1f02fb996e1afba46f5edc6001 100644 (file)
@@ -45,17 +45,7 @@ const efi_guid_t fwu_guid_os_request_fw_accept =
 static struct efi_file_handle *bootdev_root;
 #endif
 
-/**
- * get_last_capsule - get the last capsule index
- *
- * Retrieve the index of the capsule invoked last time from "CapsuleLast"
- * variable.
- *
- * Return:
- * * > 0       - the last capsule index invoked
- * * 0xffff    - on error, or no capsule invoked yet
- */
-static __maybe_unused unsigned int get_last_capsule(void)
+static __maybe_unused unsigned int get_capsule_index(const u16 *variable_name)
 {
        u16 value16[11]; /* "CapsuleXXXX": non-null-terminated */
        char value[5];
@@ -65,7 +55,7 @@ static __maybe_unused unsigned int get_last_capsule(void)
        int i;
 
        size = sizeof(value16);
-       ret = efi_get_variable_int(u"CapsuleLast", &efi_guid_capsule_report,
+       ret = efi_get_variable_int(variable_name, &efi_guid_capsule_report,
                                   NULL, &size, value16, NULL);
        if (ret != EFI_SUCCESS || size != 22 ||
            u16_strncmp(value16, u"Capsule", 7))
@@ -84,6 +74,35 @@ err:
        return index;
 }
 
+/**
+ * get_last_capsule - get the last capsule index
+ *
+ * Retrieve the index of the capsule invoked last time from "CapsuleLast"
+ * variable.
+ *
+ * Return:
+ * * > 0       - the last capsule index invoked
+ * * 0xffff    - on error, or no capsule invoked yet
+ */
+static __maybe_unused unsigned int get_last_capsule(void)
+{
+       return get_capsule_index(u"CapsuleLast");
+}
+
+/**
+ * get_max_capsule - get the max capsule index
+ *
+ * Retrieve the max capsule index value from "CapsuleMax" variable.
+ *
+ * Return:
+ * * > 0       - the max capsule index
+ * * 0xffff    - on error, or "CapsuleMax" variable does not exist
+ */
+static __maybe_unused unsigned int get_max_capsule(void)
+{
+       return get_capsule_index(u"CapsuleMax");
+}
+
 /**
  * set_capsule_result - set a result variable
  * @capsule:           Capsule
@@ -1290,7 +1309,7 @@ efi_status_t efi_launch_capsules(void)
 {
        struct efi_capsule_header *capsule = NULL;
        u16 **files;
-       unsigned int nfiles, index, i;
+       unsigned int nfiles, index, index_max, i;
        efi_status_t ret;
        bool capsule_update = true;
        bool update_status = true;
@@ -1299,6 +1318,7 @@ efi_status_t efi_launch_capsules(void)
        if (check_run_capsules() != EFI_SUCCESS)
                return EFI_SUCCESS;
 
+       index_max = get_max_capsule();
        index = get_last_capsule();
 
        /*
@@ -1317,7 +1337,7 @@ efi_status_t efi_launch_capsules(void)
        /* Launch capsules */
        for (i = 0, ++index; i < nfiles; i++, index++) {
                log_debug("Applying %ls\n", files[i]);
-               if (index > 0xffff)
+               if (index > index_max)
                        index = 0;
                ret = efi_capsule_read_file(files[i], &capsule);
                if (ret == EFI_SUCCESS) {
index 69aaefab633344d9dd8b824470ac0228faaef4f5..58d4e1340233b7d3c9929c69a8f9118bcbb310e3 100644 (file)
@@ -130,12 +130,17 @@ static efi_status_t efi_init_capsule(void)
        efi_status_t ret = EFI_SUCCESS;
 
        if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) {
+               u16 var_name16[12];
+
+               efi_create_indexed_name(var_name16, sizeof(var_name16),
+                                       "Capsule", CONFIG_EFI_CAPSULE_MAX);
+
                ret = efi_set_variable_int(u"CapsuleMax",
                                           &efi_guid_capsule_report,
                                           EFI_VARIABLE_READ_ONLY |
                                           EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                           EFI_VARIABLE_RUNTIME_ACCESS,
-                                          22, u"CapsuleFFFF", false);
+                                          22, var_name16, false);
                if (ret != EFI_SUCCESS)
                        printf("EFI: cannot initialize CapsuleMax variable\n");
        }