Merge tag 'efi-2023-04-rc2' of https://source.denx.de/u-boot/custodians/u-boot-efi

Pull request for efi-2023-04-rc2

Documentation:

* Provide page with links to talks on U-Boot

UEFI:

* Enable CTRL+S to save the boot order in eficonfig command
* Run attribute check for QueryVariableInfo() only for the file store
* Bug fixes

Others:

* Improve output formatting of the coninfo command

# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 10 Feb 2023 12:15:45 PM EST
# gpg:                using RSA key 6DC4F9C71F29A6FA06B76D33C481DBBC2C051AC4
# gpg: Good signature from "Heinrich Schuchardt <xypron.glpk@gmx.de>" [unknown]
# gpg:                 aka "[jpeg image of size 1389]" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 6DC4 F9C7 1F29 A6FA 06B7  6D33 C481 DBBC 2C05 1AC4
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c7344ee..2caa4af 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2000,7 +2000,9 @@
 
 config CMD_EFICONFIG
 	bool "eficonfig - provide menu-driven uefi variables maintenance interface"
+	default y if !HAS_BOARD_SIZE_LIMIT
 	depends on CMD_BOOTEFI_BOOTMGR
+	select MENU
 	help
 	  Enable the 'eficonfig' command which provides the menu-driven UEFI
 	  variable maintenance interface.
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index ef196bd..6baeedc 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -437,7 +437,7 @@
 	printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
 	puts(ANSI_CLEAR_LINE);
 	printf(ANSI_CURSOR_POSITION, menu->count + 6, 3);
-	puts("Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit");
+	puts("Press UP/DOWN to move, ENTER to select, ESC to quit");
 	puts(ANSI_CLEAR_LINE_TO_END);
 	printf(ANSI_CURSOR_POSITION, menu->count + 7, 1);
 	puts(ANSI_CLEAR_LINE);
diff --git a/cmd/console.c b/cmd/console.c
index 9a1db83..620a961 100644
--- a/cmd/console.c
+++ b/cmd/console.c
@@ -22,23 +22,21 @@
 
 	/* Scan for valid output and input devices */
 
-	puts ("List of available devices:\n");
+	puts("List of available devices\n");
 
 	list_for_each(pos, list) {
 		dev = list_entry(pos, struct stdio_dev, list);
 
-		printf ("%-8s %08x %c%c ",
-			dev->name,
-			dev->flags,
-			(dev->flags & DEV_FLAGS_INPUT) ? 'I' : '.',
-			(dev->flags & DEV_FLAGS_OUTPUT) ? 'O' : '.');
+		printf("|-- %s (%s%s)\n",
+		       dev->name,
+		       (dev->flags & DEV_FLAGS_INPUT) ? "I" : "",
+		       (dev->flags & DEV_FLAGS_OUTPUT) ? "O" : "");
 
 		for (l = 0; l < MAX_FILES; l++) {
 			if (stdio_devices[l] == dev) {
-				printf ("%s ", stdio_names[l]);
+				printf("|   |-- %s\n", stdio_names[l]);
 			}
 		}
-		putc ('\n');
 	}
 	return 0;
 }
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 5b1f2a7..720f52b 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -23,12 +23,12 @@
 
 static struct efi_simple_text_input_protocol *cin;
 const char *eficonfig_menu_desc =
-	"  Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit";
+	"  Press UP/DOWN to move, ENTER to select, ESC to quit";
 
 static const char *eficonfig_change_boot_order_desc =
 	"  Press UP/DOWN to move, +/- to change orde\n"
 	"  Press SPACE to activate or deactivate the entry\n"
-	"  Select [Save] to complete, ESC/CTRL+C to quit";
+	"  CTRL+S to save, ESC to quit";
 
 static struct efi_simple_text_output_protocol *cout;
 static int avail_row;
@@ -927,7 +927,7 @@
 	       ANSI_CURSOR_POSITION
 	       "%s"
 	       ANSI_CURSOR_POSITION
-	       "  Press ENTER to complete, ESC/CTRL+C to quit",
+	       "  Press ENTER to complete, ESC to quit",
 	       0, 1, msg, 8, 1);
 
 	/* tmp is used to accept user cancel */
@@ -1983,6 +1983,10 @@
 				eficonfig_menu_down(efi_menu);
 
 			return NULL;
+		case BKEY_SAVE:
+			/* force to select "Save" entry */
+			efi_menu->active = efi_menu->count - 2;
+			fallthrough;
 		case BKEY_SELECT:
 			/* "Save" */
 			if (efi_menu->active == efi_menu->count - 2) {
diff --git a/common/menu.c b/common/menu.c
index cdcdbb2..9451417 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -503,6 +503,9 @@
 	case CTL_CH('n'):
 		key = BKEY_DOWN;
 		break;
+	case CTL_CH('s'):
+		key = BKEY_SAVE;
+		break;
 	case '+':
 		key = BKEY_PLUS;
 		break;
diff --git a/doc/index.rst b/doc/index.rst
index 02de1d4..57b42c6 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -25,6 +25,7 @@
    :maxdepth: 2
 
    build/index
+   learn/index
    usage/index
 
 Developer-oriented documentation
diff --git a/doc/learn/index.rst b/doc/learn/index.rst
new file mode 100644
index 0000000..8075c01
--- /dev/null
+++ b/doc/learn/index.rst
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Learn about U-Boot
+==================
+
+.. toctree::
+   :maxdepth: 1
+
+   talks
diff --git a/doc/learn/talks.rst b/doc/learn/talks.rst
new file mode 100644
index 0000000..33bac48
--- /dev/null
+++ b/doc/learn/talks.rst
@@ -0,0 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+U-Boot Talks
+============
+
+U-Boot is a topic at various conferences each year. These talkes might help you
+learn a bit about U-Boot.
+
+See elinux_talks_ for a list.
+
+.. _elinux_talks: https://elinux.org/Boot_Loaders#U-Boot
diff --git a/doc/usage/cmd/bootmenu.rst b/doc/usage/cmd/bootmenu.rst
index cb3c8d2..684a18d 100644
--- a/doc/usage/cmd/bootmenu.rst
+++ b/doc/usage/cmd/bootmenu.rst
@@ -122,7 +122,7 @@
 Default behavior when user exits from the bootmenu
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 User can exit from bootmenu by selecting the last entry
-"U-Boot console"/"Quit" or ESC/CTRL+C key.
+"U-Boot console"/"Quit" or ESC key.
 
 When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is disabled,
 user exits from the bootmenu and returns to the U-Boot console.
diff --git a/doc/usage/cmd/setexpr.rst b/doc/usage/cmd/setexpr.rst
index 2e511b1..4d19fa3 100644
--- a/doc/usage/cmd/setexpr.rst
+++ b/doc/usage/cmd/setexpr.rst
@@ -138,7 +138,10 @@
 Configuration
 -------------
 
-The setexpr gsub and sub operations are only available if CONFIG_REGEX=y.
+* The *setexpr* command is only available if CMD_SETEXPR=y.
+* The *setexpr fmt* sub-command is only available if CMD_SETEXPR_FMT=y.
+* The *setexpr gsub* and *setexpr sub* sub-commands are only available if
+  CONFIG_REGEX=y.
 
 Return value
 ------------
diff --git a/include/efi.h b/include/efi.h
index 42f4e58..c3087d3 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -54,9 +54,18 @@
 
 struct efi_device_path;
 
+/*
+ * The EFI spec defines the EFI_GUID as
+ * "128-bit buffer containing a unique identifier value. Unless otherwise specified,
+ * aligned on a 64-bit boundary".
+ * Page 163 of the UEFI specification v2.10 and
+ * EDK2 reference implementation both define EFI_GUID as
+ * struct { u32 a; u16; b; u16 c; u8 d[8]; }; which is 4-byte
+ * aligned.
+ */
 typedef struct {
 	u8 b[16];
-} efi_guid_t __attribute__((aligned(8)));
+} efi_guid_t __attribute__((aligned(4)));
 
 #define EFI_BITS_PER_LONG	(sizeof(long) * 8)
 
diff --git a/include/efi_api.h b/include/efi_api.h
index 9bd70b0..2d18d25 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -513,6 +513,16 @@
 	struct efi_configuration_table *tables;
 };
 
+/**
+ * efi_main() - entry point of EFI applications
+ *
+ * @image_handle:	handle with the Loaded Image Protocol
+ * @systab:		pointer to the system table
+ * Return:		status code
+ */
+efi_status_t EFIAPI efi_main(efi_handle_t image_handle,
+			     struct efi_system_table *systab);
+
 #define EFI_LOADED_IMAGE_PROTOCOL_GUID \
 	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
 		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
@@ -817,7 +827,7 @@
 
 struct efi_input_key {
 	u16 scan_code;
-	s16 unicode_char;
+	u16 unicode_char;
 };
 
 #define EFI_SHIFT_STATE_INVALID		0x00000000
diff --git a/include/efi_config.h b/include/efi_config.h
index e5edbb5..01ce9b2 100644
--- a/include/efi_config.h
+++ b/include/efi_config.h
@@ -11,7 +11,7 @@
 #include <efi_loader.h>
 #include <menu.h>
 
-#define EFICONFIG_ENTRY_NUM_MAX INT_MAX
+#define EFICONFIG_ENTRY_NUM_MAX (INT_MAX - 1)
 #define EFICONFIG_VOLUME_PATH_MAX 512
 #define EFICONFIG_FILE_PATH_MAX 512
 #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16))
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 4560b0d..c664d6c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -1137,4 +1137,11 @@
 
 efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size);
 
+/**
+ * efi_add_known_memory() - add memory banks to EFI memory map
+ *
+ * This weak function may be overridden for specific architectures.
+ */
+void efi_add_known_memory(void);
+
 #endif /* _EFI_LOADER_H */
diff --git a/include/menu.h b/include/menu.h
index 1e88141..64ce89b 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -53,6 +53,7 @@
 	BKEY_PLUS,
 	BKEY_MINUS,
 	BKEY_SPACE,
+	BKEY_SAVE,
 
 	BKEY_COUNT,
 };
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index ba28989..caaab68 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -264,7 +264,7 @@
  * @tpl:		TPL level to check
  * Return:		status code
  */
-efi_status_t is_valid_tpl(efi_uintn_t tpl)
+static efi_status_t is_valid_tpl(efi_uintn_t tpl)
 {
 	switch (tpl) {
 	case TPL_APPLICATION:
@@ -592,7 +592,7 @@
  *
  * Return: status code
  */
-efi_status_t efi_remove_all_protocols(const efi_handle_t handle)
+static efi_status_t efi_remove_all_protocols(const efi_handle_t handle)
 {
 	struct efi_object *efiobj;
 	struct efi_handler *protocol;
@@ -728,6 +728,7 @@
 
 /*
  * efi_create_event_ex() - create an event in a group
+ *
  * @type:            type of the event to create
  * @notify_tpl:      task priority level of the event
  * @notify_function: notification function of the event
@@ -742,6 +743,7 @@
  *
  * Return: status code
  */
+static
 efi_status_t EFIAPI efi_create_event_ex(uint32_t type, efi_uintn_t notify_tpl,
 					void (EFIAPI *notify_function) (
 							struct efi_event *event,
diff --git a/lib/efi_loader/efi_conformance.c b/lib/efi_loader/efi_conformance.c
index 3036d46..0ca26f5 100644
--- a/lib/efi_loader/efi_conformance.c
+++ b/lib/efi_loader/efi_conformance.c
@@ -22,7 +22,7 @@
  */
 efi_status_t efi_ecpt_register(void)
 {
-	int num_entries = 0;
+	u16 num_entries = 0;
 	struct efi_conformance_profiles_table *ecpt;
 	efi_status_t ret;
 	size_t ecpt_size;
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index 1ed8c7a..4317630 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -669,7 +669,7 @@
  * @mod:	Xterm shift mask
  * @key_state:  receives the state of the shift, alt, control, and logo keys
  */
-void set_shift_mask(int mod, struct efi_key_state *key_state)
+static void set_shift_mask(int mod, struct efi_key_state *key_state)
 {
 	key_state->key_shift_state = EFI_SHIFT_STATE_VALID;
 	if (mod) {
diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
index d1dc2f2..778b693 100644
--- a/lib/efi_loader/efi_gop.c
+++ b/lib/efi_loader/efi_gop.c
@@ -400,11 +400,12 @@
  * @delta:	length in bytes of a line in the pixel buffer (optional)
  * Return:	status code
  */
-efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer,
-			    u32 operation, efi_uintn_t sx,
-			    efi_uintn_t sy, efi_uintn_t dx,
-			    efi_uintn_t dy, efi_uintn_t width,
-			    efi_uintn_t height, efi_uintn_t delta)
+static efi_status_t EFIAPI gop_blt(struct efi_gop *this,
+				   struct efi_gop_pixel *buffer,
+				   u32 operation, efi_uintn_t sx,
+				   efi_uintn_t sy, efi_uintn_t dx,
+				   efi_uintn_t dy, efi_uintn_t width,
+				   efi_uintn_t height, efi_uintn_t delta)
 {
 	efi_status_t ret = EFI_INVALID_PARAMETER;
 	efi_uintn_t vid_bpp;
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index ad2ab82..cee96bf 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -462,7 +462,7 @@
  * @scatter_gather_list:	pointer to array of physical pointers
  * Returns:			status code
  */
-efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
+static efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
 			struct efi_capsule_header **capsule_header_array,
 			efi_uintn_t capsule_count,
 			u64 scatter_gather_list)
@@ -484,7 +484,7 @@
  * @reset_type:			type of reset needed for capsule update
  * Returns:			status code
  */
-efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported(
+static efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported(
 			struct efi_capsule_header **capsule_header_array,
 			efi_uintn_t capsule_count,
 			u64 *maximum_capsule_size,
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index f0f01d3..69aaefa 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -11,6 +11,7 @@
 #include <efi_loader.h>
 #include <efi_variable.h>
 #include <log.h>
+#include <asm-generic/unaligned.h>
 
 #define OBJ_LIST_NOT_INITIALIZED 1
 
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index eb83702..ad50bff 100644
--- a/lib/efi_loader/efi_var_common.c
+++ b/lib/efi_loader/efi_var_common.c
@@ -165,17 +165,9 @@
 
 	if (!maximum_variable_storage_size ||
 	    !remaining_variable_storage_size ||
-	    !maximum_variable_size ||
-	    !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS))
+	    !maximum_variable_size)
 		return EFI_EXIT(EFI_INVALID_PARAMETER);
 
-	if ((attributes & ~(u32)EFI_VARIABLE_MASK) ||
-	    (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
-	    (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) ||
-	    (!IS_ENABLED(CONFIG_EFI_SECURE_BOOT) &&
-	     (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)))
-		return EFI_EXIT(EFI_UNSUPPORTED);
-
 	ret = efi_query_variable_info_int(attributes,
 					  maximum_variable_storage_size,
 					  remaining_variable_storage_size,
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 7c32adf..4c85cfa 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -349,6 +349,29 @@
 					 u64 *remaining_variable_storage_size,
 					 u64 *maximum_variable_size)
 {
+	if (attributes == 0)
+		return EFI_INVALID_PARAMETER;
+
+	/* EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated */
+	if ((attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
+	    ((attributes & EFI_VARIABLE_MASK) == 0))
+		return EFI_UNSUPPORTED;
+
+	if ((attributes & EFI_VARIABLE_MASK) == EFI_VARIABLE_NON_VOLATILE)
+		return EFI_INVALID_PARAMETER;
+
+	/* Make sure if runtime bit is set, boot service bit is set also. */
+	if ((attributes &
+	     (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) ==
+	    EFI_VARIABLE_RUNTIME_ACCESS)
+		return EFI_INVALID_PARAMETER;
+
+	if (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD)
+		return EFI_UNSUPPORTED;
+
+	if (attributes & ~(u32)EFI_VARIABLE_MASK)
+		return EFI_INVALID_PARAMETER;
+
 	*maximum_variable_storage_size = EFI_VAR_BUF_SIZE -
 					 sizeof(struct efi_var_file);
 	*remaining_variable_storage_size = efi_var_mem_free();
@@ -372,7 +395,7 @@
  *					selected type
  * Returns:				status code
  */
-efi_status_t __efi_runtime EFIAPI efi_query_variable_info_runtime(
+static efi_status_t __efi_runtime EFIAPI efi_query_variable_info_runtime(
 			u32 attributes,
 			u64 *maximum_variable_storage_size,
 			u64 *remaining_variable_storage_size,
diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
index d565f32..49fa8cc 100644
--- a/lib/efi_loader/helloworld.c
+++ b/lib/efi_loader/helloworld.c
@@ -125,7 +125,7 @@
  * @systable:	system table
  * @con_out:	simple text output protocol
  */
-void print_load_options(struct efi_loaded_image *loaded_image)
+static void print_load_options(struct efi_loaded_image *loaded_image)
 {
 	/* Output the load options */
 	con_out->output_string(con_out, u"Load options: ");
@@ -143,6 +143,7 @@
  * @device_path:	device path to print
  * @dp2txt:		device path to text protocol
  */
+static
 efi_status_t print_device_path(struct efi_device_path *device_path,
 			       struct efi_device_path_to_text_protocol *dp2txt)
 {
diff --git a/lib/efi_loader/initrddump.c b/lib/efi_loader/initrddump.c
index 9872106..971a3b6 100644
--- a/lib/efi_loader/initrddump.c
+++ b/lib/efi_loader/initrddump.c
@@ -439,7 +439,7 @@
  *
  * Return:	load options or NULL
  */
-u16 *get_load_options(void)
+static u16 *get_load_options(void)
 {
 	efi_status_t ret;
 	struct efi_loaded_image *loaded_image;
diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index 38b0dea..ea1ad1b 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -265,7 +265,7 @@
             print(("Warning: No tool chains. Please run 'buildman "
                    "--fetch-arch all' to download all available toolchains, or "
                    "add a [toolchain] section to your buildman config file "
-                   "%s. See README for details" %
+                   "%s. See buildman.rst for details" %
                    bsettings.config_fname))
 
         paths = []