]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: installation of EFI_RNG_PROTOCOL
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 25 Sep 2020 10:50:19 +0000 (12:50 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 27 Sep 2020 14:10:45 +0000 (16:10 +0200)
Having an EFI_RNG_PROTOCOL without a backing RNG device leads to failure
to boot Linux 5.8.

Only install the EFI_RNG_PROTOCOL if we have a RNG device.

Reported-by: Scott K Logan <logans@cottsay.net>
Cc: Neil Armstrong <narmstrong@baylibre.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/efi_loader.h
lib/efi_loader/efi_rng.c
lib/efi_loader/efi_root_node.c
lib/efi_loader/efi_setup.c

index 0baa1d2324c88f51c6f51a09c98feea25f920846..7eea5566fdc974fd5b9b58b6841ccfee076559af 100644 (file)
@@ -154,7 +154,6 @@ extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
 extern const struct efi_hii_config_access_protocol efi_hii_config_access;
 extern const struct efi_hii_database_protocol efi_hii_database;
 extern const struct efi_hii_string_protocol efi_hii_string;
-extern const struct efi_rng_protocol efi_rng_protocol;
 
 uint16_t *efi_dp_str(struct efi_device_path *dp);
 
@@ -404,6 +403,8 @@ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition,
 efi_status_t efi_console_register(void);
 /* Called by bootefi to make all disk storage accessible as EFI objects */
 efi_status_t efi_disk_register(void);
+/* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */
+efi_status_t efi_rng_register(void);
 /* Create handles and protocols for the partitions of a block device */
 int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
                               const char *if_typename, int diskid,
index caef4085b077c1bf22fc173a92eecdd7cd25537a..a8a87007b65fb4f98b101ae4c0bb00f9e494db99 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright (c) 2019, Linaro Limited
  */
 
+#define LOG_CATEGORY LOGC_EFI
+
 #include <common.h>
 #include <dm.h>
 #include <efi_loader.h>
@@ -144,7 +146,33 @@ back:
        return EFI_EXIT(status);
 }
 
-const struct efi_rng_protocol efi_rng_protocol = {
+static const struct efi_rng_protocol efi_rng_protocol = {
        .get_info = rng_getinfo,
        .get_rng = getrng,
 };
+
+/**
+ * efi_rng_register() - register EFI_RNG_PROTOCOL
+ *
+ * If a RNG device is available, the Random Number Generator Protocol is
+ * registered.
+ *
+ * Return:     An error status is only returned if adding the protocol fails.
+ */
+efi_status_t efi_rng_register(void)
+{
+       efi_status_t ret;
+       struct udevice *dev;
+
+       ret = platform_get_rng_device(&dev);
+       if (ret != EFI_SUCCESS) {
+               log_warning("Missing RNG device for EFI_RNG_PROTOCOL");
+               return EFI_SUCCESS;
+       }
+       ret = efi_add_protocol(efi_root, &efi_guid_rng_protocol,
+                              (void *)&efi_rng_protocol);
+       if (ret != EFI_SUCCESS)
+               log_err("Cannot install EFI_RNG_PROTOCOL");
+
+       return ret;
+}
index 76d18fb1a4adeeefe3f14684c5644c11347feda4..f68b0fdc610fc9577923c305cfb70cca3b8f0035 100644 (file)
@@ -80,10 +80,6 @@ efi_status_t efi_root_node_register(void)
                         /* HII configuration routing protocol */
                         &efi_guid_hii_config_routing_protocol,
                         (void *)&efi_hii_config_routing,
-#endif
-#if CONFIG_IS_ENABLED(EFI_RNG_PROTOCOL)
-                        &efi_guid_rng_protocol,
-                        (void *)&efi_rng_protocol,
 #endif
                         NULL));
        efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE;
index 6196c0a06cd7712ebc20f7b0d7374e7a6ece427e..45226c5c1a53df33b6bff51409947ec9db858f50 100644 (file)
@@ -151,6 +151,11 @@ efi_status_t efi_init_obj_list(void)
        if (ret != EFI_SUCCESS)
                goto out;
 #endif
+       if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) {
+               ret = efi_rng_register();
+               if (ret != EFI_SUCCESS)
+                       goto out;
+       }
        /* Initialize variable services */
        ret = efi_init_variables();
        if (ret != EFI_SUCCESS)