Merge tag 'efi-2020-04-rc1-2' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi

Pull request for UEFI sub-system for efi-2020-04-rc1-2

Bug fixes for the UEFI sub-system are provided:

* imply VIDEO_ANSI for correct cursor positioning and colors
* fix issues in the UEFI block device driver
* add missing documentation
diff --git a/doc/api/efi.rst b/doc/api/efi.rst
index 2ca3449..bc59382 100644
--- a/doc/api/efi.rst
+++ b/doc/api/efi.rst
@@ -131,6 +131,12 @@
 .. kernel-doc:: lib/efi_loader/efi_net.c
    :internal:
 
+Random number generator protocol
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc:: lib/efi_loader/efi_rng.c
+   :internal:
+
 Text IO protocols
 ~~~~~~~~~~~~~~~~~
 
diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
index b14746e..25b27ec 100644
--- a/lib/efi_driver/efi_uclass.c
+++ b/lib/efi_driver/efi_uclass.c
@@ -112,7 +112,7 @@
 	struct efi_driver_binding_extended_protocol *bp =
 			(struct efi_driver_binding_extended_protocol *)this;
 
-	EFI_ENTRY("%p, %pUl, %ls", this, controller_handle,
+	EFI_ENTRY("%p, %p, %ls", this, controller_handle,
 		  efi_dp_str(remaining_device_path));
 
 	/* Attach driver to controller */
@@ -197,9 +197,10 @@
 	efi_status_t ret;
 	efi_uintn_t count;
 	struct efi_open_protocol_info_entry *entry_buffer;
-	efi_guid_t *guid_controller = NULL;
+	struct efi_driver_binding_extended_protocol *bp =
+			(struct efi_driver_binding_extended_protocol *)this;
 
-	EFI_ENTRY("%p, %pUl, %zu, %p", this, controller_handle,
+	EFI_ENTRY("%p, %p, %zu, %p", this, controller_handle,
 		  number_of_children, child_handle_buffer);
 
 	/* Destroy provided child controllers */
@@ -217,7 +218,7 @@
 
 	/* Destroy all children */
 	ret = EFI_CALL(systab.boottime->open_protocol_information(
-					controller_handle, guid_controller,
+					controller_handle, bp->ops->protocol,
 					&entry_buffer, &count));
 	if (ret != EFI_SUCCESS)
 		goto out;
@@ -237,7 +238,7 @@
 
 	/* Detach driver from controller */
 	ret = EFI_CALL(systab.boottime->close_protocol(
-			controller_handle, guid_controller,
+			controller_handle, bp->ops->protocol,
 			this->driver_binding_handle, controller_handle));
 out:
 	return EFI_EXIT(ret);
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 6727336..a7afa3f 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -16,6 +16,7 @@
 	select REGEX
 	imply CFB_CONSOLE_ANSI
 	imply USB_KEYBOARD_FN_KEYS
+	imply VIDEO_ANSI
 	help
 	  Select this option if you want to run UEFI applications (like GNU
 	  GRUB or iPXE) on top of U-Boot. If this option is enabled, U-Boot
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 3103a50..1f598b3 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -2933,10 +2933,10 @@
 	ret = EFI_CALL(image_obj->entry(image_handle, &systab));
 
 	/*
-	 * Usually UEFI applications call Exit() instead of returning.
-	 * But because the world doesn't consist of ponies and unicorns,
-	 * we're happy to emulate that behavior on behalf of a payload
-	 * that forgot.
+	 * Control is returned from a started UEFI image either by calling
+	 * Exit() (where exit data can be provided) or by simply returning from
+	 * the entry point. In the latter case call Exit() on behalf of the
+	 * image.
 	 */
 	return EFI_CALL(systab.boottime->exit(image_handle, ret, 0, NULL));
 }
diff --git a/lib/efi_loader/efi_rng.c b/lib/efi_loader/efi_rng.c
index 432c986..a1d0ec8 100644
--- a/lib/efi_loader/efi_rng.c
+++ b/lib/efi_loader/efi_rng.c
@@ -13,6 +13,17 @@
 
 const efi_guid_t efi_guid_rng_protocol = EFI_RNG_PROTOCOL_GUID;
 
+/**
+ * platform_get_rng_device() - retrieve random number generator
+ *
+ * This function retrieves the udevice implementing a hardware random
+ * number generator.
+ *
+ * This function may be overridden if special initialization is needed.
+ *
+ * @dev:	udevice
+ * Return:	status code
+ */
 __weak efi_status_t platform_get_rng_device(struct udevice **dev)
 {
 	int ret;
@@ -29,6 +40,18 @@
 	return EFI_SUCCESS;
 }
 
+/**
+ * rng_getinfo() - get information about random number generation
+ *
+ * This function implement the GetInfo() service of the EFI random number
+ * generator protocol. See the UEFI spec for details.
+ *
+ * @this:			random number generator protocol instance
+ * @rng_algorithm_list_size:	number of random number generation algorithms
+ * @rng_algorithm_list:		descriptions of random number generation
+ *				algorithms
+ * Return:			status code
+ */
 static efi_status_t EFIAPI rng_getinfo(struct efi_rng_protocol *this,
 				       efi_uintn_t *rng_algorithm_list_size,
 				       efi_guid_t *rng_algorithm_list)
@@ -64,6 +87,18 @@
 	return EFI_EXIT(ret);
 }
 
+/**
+ * rng_getrng() - get random value
+ *
+ * This function implement the GetRng() service of the EFI random number
+ * generator protocol. See the UEFI spec for details.
+ *
+ * @this:		random number generator protocol instance
+ * @rng_algorithm:	random number generation algorithm
+ * @rng_value_length:	number of random bytes to generate, buffer length
+ * @rng_value:		buffer to receive random bytes
+ * Return:		status code
+ */
 static efi_status_t EFIAPI getrng(struct efi_rng_protocol *this,
 				  efi_guid_t *rng_algorithm,
 				  efi_uintn_t rng_value_length,
diff --git a/lib/efi_selftest/Kconfig b/lib/efi_selftest/Kconfig
index d20f589..4781403 100644
--- a/lib/efi_selftest/Kconfig
+++ b/lib/efi_selftest/Kconfig
@@ -3,6 +3,7 @@
 	depends on CMD_BOOTEFI
 	imply FAT
 	imply FAT_WRITE
+	imply CMD_POWEROFF if PSCI_RESET || SYSRESET_PSCI
 	help
 	  This adds a UEFI test application to U-Boot that can be executed
 	  via the 'bootefi selftest' command. It provides extended tests of
diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c
index 644c5ad..d98a854 100644
--- a/lib/efi_selftest/efi_selftest_block_device.c
+++ b/lib/efi_selftest/efi_selftest_block_device.c
@@ -257,9 +257,9 @@
 				disk_handle, &block_io_protocol_guid,
 				&block_io);
 		if (r != EFI_SUCCESS) {
-			efi_st_todo(
+			efi_st_error(
 				"Failed to uninstall block I/O protocol\n");
-			return EFI_ST_SUCCESS;
+			return EFI_ST_FAILURE;
 		}
 	}