Skip to contentSkip to conversation

efi: Improvements to booting and debugging

PATCH Superseded Simon Glass 2 participants 25 messages Mar 10, 2023 – Mar 19, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover efi: Improvements to booting and debugging

This series provides support for booting a kernel from the EFI app. So far this is pretty basic, since it only supports the actual booting, not providing ACPI tables, etc. But it is a start.

It also includes an enhancement to the 'efi' command and a few other clean-ups.

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID
- Add new patch to enable GUID names with EFI app and payload
- Add new patch to split out table-listing code into a new file
- Make use of common code
- Fix typos in commit message

Simon Glass (12):
efi: Set RUN_64BIT correctly for the EFI app
x86: Adjust bootparam.h to be more like linux
x86: Add return-value comment to cpu_jump_to_64bit()
x86: Support booting a 64-bit kernel from 64-bit U-Boot
x86: Exit EFI boot services before starting kernel
x86: Support zboot and bootm in the EFI app
efi: Add another tranch of GUIDs
efi: Include GUID names with EFI app and payload
doc: Add help for the efi command
efi: Split out table-listing code into a new file
efi: Support showing tables
efI: Allow packaging a kernel in the debugging script

 arch/x86/Kconfig                 |   4 +-
 arch/x86/include/asm/bootm.h     |  12 +-
 arch/x86/include/asm/bootparam.h |  70 ++++++----
 arch/x86/include/asm/cpu.h       |   1 +
 arch/x86/lib/bootm.c             |  43 ++++--
 arch/x86/lib/zimage.c            |  17 ++-
 cmd/Makefile                     |   4 +-
 cmd/efi.c                        |  33 ++++-
 cmd/efi_common.c                 |  26 ++++
 cmd/efidebug.c                   |   6 +-
 configs/efi-x86_app32_defconfig  |   2 +-
 configs/efi-x86_app64_defconfig  |   3 +-
 doc/usage/cmd/efi.rst            | 219 +++++++++++++++++++++++++++++++
 doc/usage/index.rst              |   1 +
 include/efi.h                    |   9 ++
 include/efi_api.h                |  22 ++++
 lib/uuid.c                       |   9 +-
 scripts/build-efi.sh             |  14 +-
 18 files changed, 440 insertions(+), 55 deletions(-)
 create mode 100644 cmd/efi_common.c
 create mode 100644 doc/usage/cmd/efi.rst
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#1 lore raw

PATCH v2 1/12 efi: Set RUN_64BIT correctly for the EFI app

The U-Boot EFI app can run as a 64-bit program, so set the Kconfig correctly in that case. Make sure it doesn't build SPL, since there is no need to switch from 32 to 64 bit when running.

---

(no changes since v1)

 arch/x86/Kconfig                | 4 ++--
 configs/efi-x86_app64_defconfig | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/Kconfig +2 -2
index 07be5cd05ec..99e59d94c60 100644
@@ -32,8 +32,8 @@ config X86_RUN_32BIT
 config X86_RUN_64BIT
 	bool "64-bit"
 	select X86_64
-	select SPL
-	select SPL_SEPARATE_BSS
+	select SPL if !EFI_APP
+	select SPL_SEPARATE_BSS if !EFI_APP
 	help
 	  Build U-Boot as a 64-bit binary with a 32-bit SPL. This is
 	  experimental and many features are missing. U-Boot SPL starts up,
configs/efi-x86_app64_defconfig +1 -0
index dae48840493..f1cf43c1ef6 100644
@@ -4,6 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0
 CONFIG_DEBUG_UART_CLOCK=0
+CONFIG_X86_RUN_64BIT=y
 CONFIG_VENDOR_EFI=y
 CONFIG_TARGET_EFI_APP64=y
 CONFIG_DEBUG_UART=y
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#2 lore raw

PATCH v2 2/12 x86: Adjust bootparam.h to be more like linux

In reply to Simon Glass

This likely came from Linux originally, so update it to match v6.2 more. This has no functional change.

---

(no changes since v1)

 arch/x86/include/asm/bootparam.h | 70 +++++++++++++++++++++-----------
 arch/x86/lib/zimage.c            |  2 +-
 2 files changed, 47 insertions(+), 25 deletions(-)
arch/x86/include/asm/bootparam.h +46 -24
index 7a3c1f51554..ea816ca7469 100644
@@ -9,19 +9,54 @@
 #include <asm/ist.h>
 #include <asm/video/edid.h>
 
-/* setup data types */
-enum {
-	SETUP_NONE = 0,
-	SETUP_E820_EXT,
-	SETUP_DTB,
-};
+/* setup_data/setup_indirect types */
+#define SETUP_NONE			0
+#define SETUP_E820_EXT			1
+#define SETUP_DTB			2
+#define SETUP_PCI			3
+#define SETUP_EFI			4
+#define SETUP_APPLE_PROPERTIES		5
+#define SETUP_JAILHOUSE			6
+#define SETUP_CC_BLOB			7
+#define SETUP_IMA			8
+#define SETUP_RNG_SEED			9
+#define SETUP_ENUM_MAX			SETUP_RNG_SEED
+
+#define SETUP_INDIRECT			BIT(31)
+#define SETUP_TYPE_MAX			(SETUP_ENUM_MAX | SETUP_INDIRECT)
+
+/* ram_size flags */
+#define RAMDISK_IMAGE_START_MASK	0x07FF
+#define RAMDISK_PROMPT_FLAG		0x8000
+#define RAMDISK_LOAD_FLAG		0x4000
+
+/* loadflags */
+#define LOADED_HIGH	BIT(0)
+#define KASLR_FLAG	BIT(1)
+#define QUIET_FLAG	BIT(5)
+#define KEEP_SEGMENTS	BIT(6)
+#define CAN_USE_HEAP	BIT(7)
+
+#define XLF_KERNEL_64			BIT(0)
+#define XLF_CAN_BE_LOADED_ABOVE_4G	BIT(1)
+#define XLF_EFI_HANDOVER_32		BIT(2)
+#define XLF_EFI_HANDOVER_64		BIT(3)
+#define XLF_EFI_KEXEC			BIT(4)
 
 /* extensible setup data list node */
 struct setup_data {
 	__u64 next;
 	__u32 type;
 	__u32 len;
-	__u8 data[0];
+	__u8 data[];
+};
+
+/* extensible setup indirect data node */
+struct setup_indirect {
+	__u32 type;
+	__u32 reserved;  /* Reserved, must be set to zero. */
+	__u64 len;
+	__u64 addr;
 };
 
 /**
@@ -34,9 +69,6 @@ struct setup_header {
 	__u16	root_flags;
 	__u32	syssize;
 	__u16	ram_size;
-#define RAMDISK_IMAGE_START_MASK	0x07FF
-#define RAMDISK_PROMPT_FLAG		0x8000
-#define RAMDISK_LOAD_FLAG		0x4000
 	__u16	vid_mode;
 	__u16	root_dev;
 	__u16	boot_flag;
@@ -44,15 +76,10 @@ struct setup_header {
 	__u32	header;
 	__u16	version;
 	__u32	realmode_swtch;
-	__u16	start_sys;
+	__u16	start_sys_seg;
 	__u16	kernel_version;
 	__u8	type_of_loader;
 	__u8	loadflags;
-#define LOADED_HIGH	BIT(0)
-#define KASLR_FLAG	BIT(1)
-#define QUIET_FLAG	BIT(5)
-#define KEEP_SEGMENTS	BIT(6)		/* Obsolete */
-#define CAN_USE_HEAP	BIT(7)
 	__u16	setup_move_size;
 	__u32	code32_start;
 	__u32	ramdisk_image;
@@ -65,13 +92,8 @@ struct setup_header {
 	__u32	initrd_addr_max;
 	__u32	kernel_alignment;
 	__u8	relocatable_kernel;
-	u8	min_alignment;
-#define XLF_KERNEL_64			BIT(0)
-#define XLF_CAN_BE_LOADED_ABOVE_4G	BIT(1)
-#define XLF_EFI_HANDOVER_32		BIT(2)
-#define XLF_EFI_HANDOVER_64		BIT(3)
-#define XLF_EFI_KEXEC			BIT(4)
-	u16	xloadflags;
+	__u8	min_alignment;
+	__u16	xloadflags;
 	__u32	cmdline_size;
 	__u32	hardware_subarch;
 	__u64	hardware_subarch_data;
@@ -81,7 +103,7 @@ struct setup_header {
 	__u64	pref_address;
 	__u32	init_size;
 	__u32	handover_offset;
-	u32	kernel_info_offset;
+	__u32	kernel_info_offset;
 } __attribute__((packed));
 
 struct sys_desc_table {
arch/x86/lib/zimage.c +1 -1
index 9cc04490307..a6d9151c324 100644
@@ -655,7 +655,7 @@ void zimage_dump(struct boot_params *base_ptr)
 		printf("%-20s  %s\n", "", "Ancient kernel, using version 100");
 	print_num("Version", hdr->version);
 	print_num("Real mode switch", hdr->realmode_swtch);
-	print_num("Start sys", hdr->start_sys);
+	print_num("Start sys seg", hdr->start_sys_seg);
 	print_num("Kernel version", hdr->kernel_version);
 	version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
 	if (version)
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#3 lore raw

PATCH v2 3/12 x86: Add return-value comment to cpu_jump_to_64bit()

In reply to Simon Glass

This does not mention what it returns. Add the missing documentation.

---

(no changes since v1)

 arch/x86/include/asm/cpu.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpu.h +1 -0
index 3346012d335..aa03ef598e1 100644
@@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong table);
  *
  * @setup_base:	Pointer to the setup.bin information for the kernel
  * @target:	Pointer to the start of the kernel image
+ * Returns: -EFAULT if the kernel returned; otherwise does not return
  */
 int cpu_jump_to_64bit(ulong setup_base, ulong target);
 
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#4 lore raw

Re: [PATCH v2 03/12] x86: Add return-value comment to cpu_jump_to_64bit()

Quoted 15 lines · Simon Glass

This does not mention what it returns. Add the missing documentation.

---

(no changes since v1)

  arch/x86/include/asm/cpu.h | 1 +
  1 file changed, 1 insertion(+)
arch/x86/include/asm/cpu.h +0 -0
index 3346012d335..aa03ef598e1 100644

arch/x86/include/asm/cpu.h void cpu_call32(ulong code_seg32, ulong target, ulong table); · line 265

Quoted 4 lines
arch/x86/include/asm/cpu.h +1 -0
@@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong table);
   *
   * @setup_base:	Pointer to the setup.bin information for the kernel
   * @target:	Pointer to the start of the kernel image
+ * Returns: -EFAULT if the kernel returned; otherwise does not return

%s/Returns:/Return:/

See https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation

Best regards

Heinrich

Quoted 3 lines
arch/x86/include/asm/cpu.h +0 -0
   */
  int cpu_jump_to_64bit(ulong setup_base, ulong target);
 
#5 lore raw

Re: [PATCH v2 03/12] x86: Add return-value comment to cpu_jump_to_64bit()

Hi Heinrich,

Quoted 24 lines · Heinrich Schuchardt
Quoted 15 lines · Simon Glass

This does not mention what it returns. Add the missing documentation.

---

(no changes since v1)

  arch/x86/include/asm/cpu.h | 1 +
  1 file changed, 1 insertion(+)
arch/x86/include/asm/cpu.h +0 -0
index 3346012d335..aa03ef598e1 100644

arch/x86/include/asm/cpu.h void cpu_call32(ulong code_seg32, ulong target, ulong table); · line 265

Quoted 4 lines
arch/x86/include/asm/cpu.h +1 -0
@@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong table);
   *
   * @setup_base:     Pointer to the setup.bin information for the kernel
   * @target: Pointer to the start of the kernel image
+ * Returns: -EFAULT if the kernel returned; otherwise does not return

%s/Returns:/Return:/

Quoted 1 line

See https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation

Returns is more natural I think, in many contexts. It seems to support both from my testing.

Regards,
Simon

#6 lore raw

PATCH v2 4/12 x86: Support booting a 64-bit kernel from 64-bit U-Boot

In reply to Simon Glass

Add the missing code to handle this. For a 64-bit kernel the entry address is 0x200 bytes after the normal entry.

Rename the parameter to boot_linux_kernel() accordingly. Update the comments to indicate that these are addresses, not pointers.

---

(no changes since v1)

 arch/x86/include/asm/bootm.h | 12 ++++++------
 arch/x86/lib/bootm.c         | 25 +++++++++++++++++--------
 arch/x86/lib/zimage.c        | 15 +++++++++++++--
 3 files changed, 36 insertions(+), 16 deletions(-)
arch/x86/include/asm/bootm.h +6 -6
index 109f686f740..3b641783b9c 100644
@@ -14,14 +14,14 @@ void bootm_announce_and_cleanup(void);
  * This boots a kernel image, either 32-bit or 64-bit. It will also work with
  * a self-extracting kernel, if you set @image_64bit to false.
  *
- * @setup_base:		Pointer to the setup.bin information for the kernel
- * @load_address:	Pointer to the start of the kernel image
- * @image_64bit:	true if the image is a raw 64-bit kernel, false if it
- *			is raw 32-bit or any type of self-extracting kernel
- *			such as a bzImage.
+ * @setup_base:		Address of the setup.bin information for the kernel
+ * @entry:		Address of the kernel entry point
+ * @image_64bit:	true if the image is a raw 64-bit kernel, or a kernel
+ * which supports booting in 64-bit mode; false if it is raw 32-bit or any type
+ * of self-extracting kernel such as a bzImage.
  * Return: -ve error code. This function does not return if the kernel was
  * booted successfully.
  */
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit);
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit);
 
 #endif
arch/x86/lib/bootm.c +17 -8
index 873e2bc176f..9beb376bb9c 100644
@@ -149,7 +149,7 @@ error:
 	return 1;
 }
 
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
 {
 	bootm_announce_and_cleanup();
 
@@ -161,14 +161,23 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
 			puts("Cannot boot 64-bit kernel on 32-bit machine\n");
 			return -EFAULT;
 		}
-		/* At present 64-bit U-Boot does not support booting a
+		/*
+		 * At present 64-bit U-Boot only supports booting a 64-bit
 		 * kernel.
-		 * TODO([email protected]): Support booting both 32-bit and
-		 * 64-bit kernels from 64-bit U-Boot.
+		 *
+		 * TODO([email protected]): Support booting 32-bit kernels from
+		 * 64-bit U-Boot
 		 */
-#if !CONFIG_IS_ENABLED(X86_64)
-		return cpu_jump_to_64bit(setup_base, load_address);
-#endif
+		if (CONFIG_IS_ENABLED(X86_64)) {
+			typedef void (*h_func)(ulong zero, ulong setup);
+			h_func func;
+
+			/* jump to Linux with rdi=0, rsi=setup_base */
+			func = (h_func)entry;
+			func(0, setup_base);
+		} else {
+			return cpu_jump_to_64bit(setup_base, entry);
+		}
 	} else {
 		/*
 		* Set %ebx, %ebp, and %edi to 0, %esi to point to the
@@ -190,7 +199,7 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
 		"movl $0, %%ebp\n"
 		"cli\n"
 		"jmp *%[kernel_entry]\n"
-		:: [kernel_entry]"a"(load_address),
+		:: [kernel_entry]"a"(entry),
 		[boot_params] "S"(setup_base),
 		"b"(0), "D"(0)
 		);
arch/x86/lib/zimage.c +13 -2
index a6d9151c324..e5ea5129c1e 100644
@@ -504,13 +504,24 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
+	struct boot_params *params = state.base_ptr;
+	struct setup_header *hdr = &params->hdr;
+	bool image_64bit;
+	ulong entry;
 	int ret;
 
 	disable_interrupts();
 
+	entry = state.load_address;
+	image_64bit = false;
+	if (IS_ENABLED(CONFIG_X86_RUN_64BIT) &&
+	    (hdr->xloadflags & XLF_KERNEL_64)) {
+		entry += 0x200;
+		image_64bit = true;
+	}
+
 	/* we assume that the kernel is in place */
-	ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
-				false);
+	ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit);
 	printf("Kernel returned! (err=%d)\n", ret);
 
 	return CMD_RET_FAILURE;
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#7 lore raw

PATCH v2 5/12 x86: Exit EFI boot services before starting kernel

In reply to Simon Glass

When running the EFI app, we need to exit boot services before jumping to Linux.

At some point it may be possible to jump to Linux and pass on the boot services, so that the Linux efistub can be used. For now, this is not implemented.

---

(no changes since v1)

 arch/x86/lib/bootm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/x86/lib/bootm.c +18 -0
index 9beb376bb9c..61cb7bc6116 100644
@@ -10,6 +10,7 @@
 #include <common.h>
 #include <bootstage.h>
 #include <command.h>
+#include <efi.h>
 #include <hang.h>
 #include <log.h>
 #include <asm/global_data.h>
@@ -156,6 +157,23 @@ int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
 #ifdef CONFIG_SYS_COREBOOT
 	timestamp_add_now(TS_U_BOOT_START_KERNEL);
 #endif
+
+	/*
+	 * Exit EFI boot services just before jumping, after all console
+	 * output, since the console won't be available afterwards.
+	 */
+	if (IS_ENABLED(CONFIG_EFI_APP)) {
+		int ret;
+
+		ret = efi_store_memory_map(efi_get_priv());
+		if (ret)
+			return ret;
+		printf("Exiting EFI boot services\n");
+		ret = efi_call_exit_boot_services();
+		if (ret)
+			return ret;
+	}
+
 	if (image_64bit) {
 		if (!cpu_has_64bit()) {
 			puts("Cannot boot 64-bit kernel on 32-bit machine\n");
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#8 lore raw

Re: [PATCH v2 05/12] x86: Exit EFI boot services before starting kernel

Quoted 6 lines · Simon Glass

When running the EFI app, we need to exit boot services before jumping to Linux.

At some point it may be possible to jump to Linux and pass on the boot services, so that the Linux efistub can be used. For now, this is not implemented.

The EFI entry point expects the handle and system table. The system table contains more then a pointer to boot services. If you respin the series, consider updating the comment.

If you are running with CONFIG_EFI_API=y, you would have to

* install the device-tree as configuration table
* use LoadImage() to load the kernel image (e.g. from memory)
* start the image with StartImage().

Best regards

Heinrich

Quoted 45 lines

---

(no changes since v1)

  arch/x86/lib/bootm.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
arch/x86/lib/bootm.c +18 -0
index 9beb376bb9c..61cb7bc6116 100644
@@ -10,6 +10,7 @@
  #include <common.h>
  #include <bootstage.h>
  #include <command.h>
+#include <efi.h>
  #include <hang.h>
  #include <log.h>
  #include <asm/global_data.h>
@@ -156,6 +157,23 @@ int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
  #ifdef CONFIG_SYS_COREBOOT
  	timestamp_add_now(TS_U_BOOT_START_KERNEL);
  #endif
+
+	/*
+	 * Exit EFI boot services just before jumping, after all console
+	 * output, since the console won't be available afterwards.
+	 */
+	if (IS_ENABLED(CONFIG_EFI_APP)) {
+		int ret;
+
+		ret = efi_store_memory_map(efi_get_priv());
+		if (ret)
+			return ret;
+		printf("Exiting EFI boot services\n");
+		ret = efi_call_exit_boot_services();
+		if (ret)
+			return ret;
+	}
+
  	if (image_64bit) {
  		if (!cpu_has_64bit()) {
  			puts("Cannot boot 64-bit kernel on 32-bit machine\n");
#9 lore raw

PATCH v2 6/12 x86: Support zboot and bootm in the EFI app

In reply to Simon Glass

These have been disabled due to the rudimentary support available. It is a little better now, so enable these options.

---

(no changes since v1)

 configs/efi-x86_app32_defconfig | 2 +-
 configs/efi-x86_app64_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configs/efi-x86_app32_defconfig +1 -1
index 905f375a3ef..50975dbfaaf 100644
@@ -19,7 +19,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_TIME=y
configs/efi-x86_app64_defconfig +1 -1
index f1cf43c1ef6..0fc358ddcdf 100644
@@ -20,7 +20,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_CACHE=y
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
Reviewed-by on v2 6/12
#10 lore raw

Re: [PATCH v2 06/12] x86: Support zboot and bootm in the EFI app

Quoted 4 lines · Simon Glass

These have been disabled due to the rudimentary support available. It is a little better now, so enable these options.

Quoted 34 lines

---

(no changes since v1)

  configs/efi-x86_app32_defconfig | 2 +-
  configs/efi-x86_app64_defconfig | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
configs/efi-x86_app32_defconfig +1 -1
index 905f375a3ef..50975dbfaaf 100644
@@ -19,7 +19,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_LAST_STAGE_INIT=y
  CONFIG_HUSH_PARSER=y
  CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
  CONFIG_CMD_PART=y
  # CONFIG_CMD_NET is not set
  CONFIG_CMD_TIME=y
configs/efi-x86_app64_defconfig +1 -1
index f1cf43c1ef6..0fc358ddcdf 100644
@@ -20,7 +20,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_LAST_STAGE_INIT=y
  CONFIG_HUSH_PARSER=y
  CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
  CONFIG_CMD_PART=y
  # CONFIG_CMD_NET is not set
  CONFIG_CMD_CACHE=y
#11 lore raw

PATCH v2 7/12 efi: Add another tranch of GUIDs

In reply to Simon Glass

Provide information about the GUIDs supplied by QEMU, so far as it is known.

These values are used in the 'efi table' command as well as the printf format string %sU

---

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID

 include/efi_api.h | 22 ++++++++++++++++++++++
 lib/uuid.c        |  7 +++++++
 2 files changed, 29 insertions(+)
include/efi_api.h +22 -0
index 2d18d25a713..3dd48195885 100644
@@ -1909,6 +1909,28 @@ struct efi_system_resource_table {
 	EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
 		 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
 
+#define EFI_LZMA_COMPRESSED \
+	EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
+		 0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
+#define EFI_DXE_SERVICES \
+	EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
+		 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
+#define EFI_HOB_LIST \
+	EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEMORY_TYPE \
+	EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
+		 0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
+#define EFI_SMBIOS \
+	EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16,  \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEM_STATUS_CODE_REC \
+	EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
+		 0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
+#define EFI_GUID_EFI_ACPI1 \
+	EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
 /**
  * struct win_certificate_uefi_guid - A certificate that encapsulates
  * a GUID-specific signature
lib/uuid.c +7 -0
index 465e1ac38f5..d86fab72626 100644
@@ -255,6 +255,13 @@ static const struct {
 		EFI_CERT_TYPE_PKCS7_GUID,
 	},
 #endif
+	{ "EFI_LZMA_COMPRESSED", EFI_LZMA_COMPRESSED },
+	{ "EFI_DXE_SERVICES", EFI_DXE_SERVICES },
+	{ "EFI_HOB_LIST", EFI_HOB_LIST },
+	{ "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
+	{ "EFI_SMBIOS", EFI_SMBIOS },
+	{ "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
+	{ "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
 };
 
 /*
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#12 lore raw

Re: [PATCH v2 07/12] efi: Add another tranch of GUIDs

Quoted 57 lines · Simon Glass

Provide information about the GUIDs supplied by QEMU, so far as it is known.

These values are used in the 'efi table' command as well as the printf format string %sU

---

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID

  include/efi_api.h | 22 ++++++++++++++++++++++
  lib/uuid.c        |  7 +++++++
  2 files changed, 29 insertions(+)
include/efi_api.h +22 -0
index 2d18d25a713..3dd48195885 100644
@@ -1909,6 +1909,28 @@ struct efi_system_resource_table {
  	EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
  		 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
 
+#define EFI_LZMA_COMPRESSED \
+	EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
+		 0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
+#define EFI_DXE_SERVICES \
+	EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
+		 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
+#define EFI_HOB_LIST \
+	EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEMORY_TYPE \
+	EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
+		 0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
+#define EFI_SMBIOS \
+	EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16,  \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEM_STATUS_CODE_REC \
+	EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
+		 0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
+#define EFI_GUID_EFI_ACPI1 \
+	EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
+		 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
  /**
   * struct win_certificate_uefi_guid - A certificate that encapsulates
   * a GUID-specific signature
lib/uuid.c +0 -0
index 465e1ac38f5..d86fab72626 100644

lib/uuid.c static const struct { · line 264

Quoted 10 lines
lib/uuid.c +7 -0
@@ -255,6 +255,13 @@ static const struct {
  		EFI_CERT_TYPE_PKCS7_GUID,
  	},
  #endif
+	{ "EFI_LZMA_COMPRESSED", EFI_LZMA_COMPRESSED },
+	{ "EFI_DXE_SERVICES", EFI_DXE_SERVICES },
+	{ "EFI_HOB_LIST", EFI_HOB_LIST },
+	{ "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
+	{ "EFI_SMBIOS", EFI_SMBIOS },
+	{ "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
+	{ "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },

As we do not want to unnecessarily increase the size of U-Boot for all boards, please, consider adding #ifdef CONFIG_EFI_APP.

Best regards

Heinrich

Quoted 3 lines
lib/uuid.c +0 -0
  };
 
  /*
#13 lore raw

PATCH v2 8/12 efi: Include GUID names with EFI app and payload

In reply to Simon Glass

These are currently only available when running with EFI_LOADER. Expand this to include the app and payload, since it is useful to be able to decode things there.

---

Changes in v2:
- Add new patch to enable GUID names with EFI app and payload

 lib/uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/uuid.c +1 -1
index d86fab72626..09793fb62bc 100644
@@ -102,7 +102,7 @@ static const struct {
 	{"lvm",		PARTITION_LINUX_LVM_GUID},
 	{"u-boot-env",	PARTITION_U_BOOT_ENVIRONMENT},
 #endif
-#ifdef CONFIG_CMD_EFIDEBUG
+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)
 	{
 		"Device Path",
 		EFI_DEVICE_PATH_PROTOCOL_GUID,
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#14 lore raw

Re: [PATCH v2 08/12] efi: Include GUID names with EFI app and payload

Quoted 18 lines · Simon Glass

These are currently only available when running with EFI_LOADER. Expand this to include the app and payload, since it is useful to be able to decode things there.

---

Changes in v2:
- Add new patch to enable GUID names with EFI app and payload

  lib/uuid.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/uuid.c +0 -0
index d86fab72626..09793fb62bc 100644

lib/uuid.c static const struct { · line 105

Quoted 5 lines
lib/uuid.c +1 -1
@@ -102,7 +102,7 @@ static const struct {
  	{"lvm",		PARTITION_LINUX_LVM_GUID},
  	{"u-boot-env",	PARTITION_U_BOOT_ENVIRONMENT},
  #endif
-#ifdef CONFIG_CMD_EFIDEBUG
+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)

%s/CONFIG_EFI/CONFIG_EFI_APP)/

We don't need these when running EFI_STUB=y without EFI_LOADER).

Best regards

Heinrich

Quoted 3 lines
lib/uuid.c +0 -0
  	{
  		"Device Path",
  		EFI_DEVICE_PATH_PROTOCOL_GUID,
#15 lore raw

Re: [PATCH v2 08/12] efi: Include GUID names with EFI app and payload

Hi Heinrich,

Quoted 28 lines · Heinrich Schuchardt
Quoted 18 lines · Simon Glass

These are currently only available when running with EFI_LOADER. Expand this to include the app and payload, since it is useful to be able to decode things there.

---

Changes in v2:
- Add new patch to enable GUID names with EFI app and payload

  lib/uuid.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/uuid.c +0 -0
index d86fab72626..09793fb62bc 100644

lib/uuid.c static const struct { · line 105

Quoted 5 lines
lib/uuid.c +1 -1
@@ -102,7 +102,7 @@ static const struct {
      {"lvm",         PARTITION_LINUX_LVM_GUID},
      {"u-boot-env",  PARTITION_U_BOOT_ENVIRONMENT},
  #endif
-#ifdef CONFIG_CMD_EFIDEBUG
+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)

%s/CONFIG_EFI/CONFIG_EFI_APP)/

Quoted 1 line

We don't need these when running EFI_STUB=y without EFI_LOADER).

Actually in that case they are needed, so that the 'efi tables' command can work. Otherwise it just shows thes hex values.

Regards,
Simon

#16 lore raw

PATCH v2 9/12 doc: Add help for the efi command

In reply to Simon Glass

This command currently has no help. Add some.

---

(no changes since v1)

 doc/usage/cmd/efi.rst | 197 ++++++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst   |   1 +
 2 files changed, 198 insertions(+)
 create mode 100644 doc/usage/cmd/efi.rst
doc/usage/cmd/efi.rst new file +197 -0
new file mode 100644
index 00000000000..c029c423879
@@ -0,0 +1,197 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2020, Heinrich Schuchardt <[email protected]>
+
+efi command
+===========
+
+Synopsis
+--------
+
+::
+
+    efi mem [all]
+
+Description
+-----------
+
+The *efi* command provides information about the EFI environment U-Boot is
+running in, when it is started from EFI.
+
+When running as an EFI app, this command queries EFI boot services for the
+information. When running as an EFI payload, EFI boot services have been
+stopped, so it uses the information collected by the boot stub before that
+happened.
+
+efi mem
+~~~~~~~
+
+This shows the EFI memory map, sorted in order of physical address.
+
+This is normally a very large table. To help reduce the amount of detritus,
+boot-time memory is normally merged with conventional memory. Use the 'all'
+argument to show everything.
+
+The fields are as follows:
+
+#
+    Entry number (sequentially from 0)
+
+Type
+    Memory type. EFI has a large number of memory types. The type is shown in
+    the format <n>:<name> where in is the format number in hex and <name> is the
+    name.
+
+Physical
+    Physical address
+
+Virtual
+    Virtual address
+
+Size
+    Size of memory area in bytes
+
+Attributes
+    Shows a code for memory attributes. The key for this is shown below the
+    table.
+
+Example
+-------
+
+::
+
+    => efi mem
+    EFI table at 0, memory map 000000001ad38b60, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  7:conv          0000000000  0000000000  00000a0000  f
+        <gap>           00000a0000              0000060000
+     1  7:conv          0000100000  0000000000  0000700000  f
+     2  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     3  7:conv          0000808000  0000000000  0000008000  f
+     4  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     5  7:conv          0000900000  0000000000  001efef000  f
+     6  6:rt_data       001f8ef000  0000000000  0000100000  rf
+     7  5:rt_code       001f9ef000  0000000000  0000100000  rf
+     8  0:reserved      001faef000  0000000000  0000080000  f
+     9  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    10  a:acpi_nvs      001fb7f000  0000000000  0000080000  f
+    11  7:conv          001fbff000  0000000000  0000359000  f
+    12  6:rt_data       001ff58000  0000000000  0000020000  rf
+    13  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    14  0:reserved      00b0000000  0000000000  0010000000  1
+
+    Attributes key:
+     f: uncached, write-coalescing, write-through, write-back
+    rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
+     1: uncached
+    *Some areas are merged (use 'all' to see)
+
+
+    => efi mem  all
+    EFI table at 0, memory map 000000001ad38bb0, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  3:bs_code       0000000000  0000000000  0000001000  f
+     1  7:conv          0000001000  0000000000  000009f000  f
+        <gap>           00000a0000              0000060000
+     2  7:conv          0000100000  0000000000  0000700000  f
+     3  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     4  7:conv          0000808000  0000000000  0000008000  f
+     5  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     6  4:bs_data       0000900000  0000000000  0000c00000  f
+     7  7:conv          0001500000  0000000000  000aa36000  f
+     8  2:loader_data   000bf36000  0000000000  0010000000  f
+     9  4:bs_data       001bf36000  0000000000  0000020000  f
+    10  7:conv          001bf56000  0000000000  00021e1000  f
+    11  1:loader_code   001e137000  0000000000  00000c4000  f
+    12  7:conv          001e1fb000  0000000000  000009b000  f
+    13  1:loader_code   001e296000  0000000000  00000e2000  f
+    14  7:conv          001e378000  0000000000  000005b000  f
+    15  4:bs_data       001e3d3000  0000000000  000001e000  f
+    16  7:conv          001e3f1000  0000000000  0000016000  f
+    17  4:bs_data       001e407000  0000000000  0000016000  f
+    18  2:loader_data   001e41d000  0000000000  0000002000  f
+    19  4:bs_data       001e41f000  0000000000  0000828000  f
+    20  3:bs_code       001ec47000  0000000000  0000045000  f
+    21  4:bs_data       001ec8c000  0000000000  0000001000  f
+    22  3:bs_code       001ec8d000  0000000000  000000e000  f
+    23  4:bs_data       001ec9b000  0000000000  0000001000  f
+    24  3:bs_code       001ec9c000  0000000000  000002c000  f
+    25  4:bs_data       001ecc8000  0000000000  0000001000  f
+    26  3:bs_code       001ecc9000  0000000000  000000c000  f
+    27  4:bs_data       001ecd5000  0000000000  0000006000  f
+    28  3:bs_code       001ecdb000  0000000000  0000014000  f
+    29  4:bs_data       001ecef000  0000000000  0000001000  f
+    30  3:bs_code       001ecf0000  0000000000  000005b000  f
+    31  4:bs_data       001ed4b000  0000000000  000000b000  f
+    32  3:bs_code       001ed56000  0000000000  0000024000  f
+    33  4:bs_data       001ed7a000  0000000000  0000006000  f
+    34  3:bs_code       001ed80000  0000000000  0000010000  f
+    35  4:bs_data       001ed90000  0000000000  0000002000  f
+    36  3:bs_code       001ed92000  0000000000  0000025000  f
+    37  4:bs_data       001edb7000  0000000000  0000003000  f
+    38  3:bs_code       001edba000  0000000000  0000011000  f
+    39  4:bs_data       001edcb000  0000000000  0000008000  f
+    40  3:bs_code       001edd3000  0000000000  000002d000  f
+    41  4:bs_data       001ee00000  0000000000  0000201000  f
+    42  3:bs_code       001f001000  0000000000  0000024000  f
+    43  4:bs_data       001f025000  0000000000  0000002000  f
+    44  3:bs_code       001f027000  0000000000  0000009000  f
+    45  4:bs_data       001f030000  0000000000  0000005000  f
+    46  3:bs_code       001f035000  0000000000  000002f000  f
+    47  4:bs_data       001f064000  0000000000  0000001000  f
+    48  3:bs_code       001f065000  0000000000  0000005000  f
+    49  4:bs_data       001f06a000  0000000000  0000005000  f
+    50  3:bs_code       001f06f000  0000000000  0000007000  f
+    51  4:bs_data       001f076000  0000000000  0000007000  f
+    52  3:bs_code       001f07d000  0000000000  000000d000  f
+    53  4:bs_data       001f08a000  0000000000  0000001000  f
+    54  3:bs_code       001f08b000  0000000000  0000006000  f
+    55  4:bs_data       001f091000  0000000000  0000004000  f
+    56  3:bs_code       001f095000  0000000000  000000d000  f
+    57  4:bs_data       001f0a2000  0000000000  0000003000  f
+    58  3:bs_code       001f0a5000  0000000000  0000026000  f
+    59  4:bs_data       001f0cb000  0000000000  0000005000  f
+    60  3:bs_code       001f0d0000  0000000000  0000019000  f
+    61  4:bs_data       001f0e9000  0000000000  0000004000  f
+    62  3:bs_code       001f0ed000  0000000000  0000024000  f
+    63  4:bs_data       001f111000  0000000000  0000008000  f
+    64  3:bs_code       001f119000  0000000000  000000b000  f
+    65  4:bs_data       001f124000  0000000000  0000001000  f
+    66  3:bs_code       001f125000  0000000000  0000002000  f
+    67  4:bs_data       001f127000  0000000000  0000002000  f
+    68  3:bs_code       001f129000  0000000000  0000009000  f
+    69  4:bs_data       001f132000  0000000000  0000003000  f
+    70  3:bs_code       001f135000  0000000000  0000005000  f
+    71  4:bs_data       001f13a000  0000000000  0000003000  f
+    72  3:bs_code       001f13d000  0000000000  0000005000  f
+    73  4:bs_data       001f142000  0000000000  0000003000  f
+    74  3:bs_code       001f145000  0000000000  0000011000  f
+    75  4:bs_data       001f156000  0000000000  000000b000  f
+    76  3:bs_code       001f161000  0000000000  0000009000  f
+    77  4:bs_data       001f16a000  0000000000  0000400000  f
+    78  3:bs_code       001f56a000  0000000000  0000006000  f
+    79  4:bs_data       001f570000  0000000000  0000001000  f
+    80  3:bs_code       001f571000  0000000000  0000001000  f
+    81  4:bs_data       001f572000  0000000000  0000002000  f
+    82  3:bs_code       001f574000  0000000000  0000017000  f
+    83  4:bs_data       001f58b000  0000000000  0000364000  f
+    84  6:rt_data       001f8ef000  0000000000  0000100000  rf
+    85  5:rt_code       001f9ef000  0000000000  0000100000  rf
+    86  0:reserved      001faef000  0000000000  0000080000  f
+    87  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    88  a:acpi_nvs      001fb7f000  0000000000  0000080000  f
+    89  4:bs_data       001fbff000  0000000000  0000201000  f
+    90  7:conv          001fe00000  0000000000  00000e8000  f
+    91  4:bs_data       001fee8000  0000000000  0000020000  f
+    92  3:bs_code       001ff08000  0000000000  0000026000  f
+    93  4:bs_data       001ff2e000  0000000000  0000009000  f
+    94  3:bs_code       001ff37000  0000000000  0000021000  f
+    95  6:rt_data       001ff58000  0000000000  0000020000  rf
+    96  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    97  0:reserved      00b0000000  0000000000  0010000000  1
+
+    Attributes key:
+     f: uncached, write-coalescing, write-through, write-back
+    rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
+     1: uncached
doc/usage/index.rst +1 -0
index 840c20c934d..9f7a80e3bfe 100644
@@ -43,6 +43,7 @@ Shell commands
    cmd/dm
    cmd/ebtupdate
    cmd/echo
+   cmd/efi
    cmd/eficonfig
    cmd/env
    cmd/event
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#17 lore raw

Re: [PATCH v2 09/12] doc: Add help for the efi command

Quoted 200 lines · Simon Glass

This command currently has no help. Add some.

---

(no changes since v1)

  doc/usage/cmd/efi.rst | 197 ++++++++++++++++++++++++++++++++++++++++++
  doc/usage/index.rst   |   1 +
  2 files changed, 198 insertions(+)

create mode 100644 doc/usage/cmd/efi.rst

doc/usage/cmd/efi.rst new file +182 -0
new file mode 100644
index 00000000000..c029c423879
@@ -0,0 +1,197 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2020, Heinrich Schuchardt <[email protected]>
+
+efi command
+===========
+
+Synopsis
+--------
+
+::
+
+    efi mem [all]
+
+Description
+-----------
+
+The *efi* command provides information about the EFI environment U-Boot is
+running in, when it is started from EFI.
+
+When running as an EFI app, this command queries EFI boot services for the
+information. When running as an EFI payload, EFI boot services have been
+stopped, so it uses the information collected by the boot stub before that
+happened.
+
+efi mem
+~~~~~~~
+
+This shows the EFI memory map, sorted in order of physical address.
+
+This is normally a very large table. To help reduce the amount of detritus,
+boot-time memory is normally merged with conventional memory. Use the 'all'
+argument to show everything.
+
+The fields are as follows:
+
+#
+    Entry number (sequentially from 0)
+
+Type
+    Memory type. EFI has a large number of memory types. The type is shown in
+    the format <n>:<name> where in is the format number in hex and <name> is the
+    name.
+
+Physical
+    Physical address
+
+Virtual
+    Virtual address
+
+Size
+    Size of memory area in bytes
+
+Attributes
+    Shows a code for memory attributes. The key for this is shown below the
+    table.
+
+Example
+-------
+
+::
+
+    => efi mem
+    EFI table at 0, memory map 000000001ad38b60, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  7:conv          0000000000  0000000000  00000a0000  f
+        <gap>           00000a0000              0000060000
+     1  7:conv          0000100000  0000000000  0000700000  f
+     2  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     3  7:conv          0000808000  0000000000  0000008000  f
+     4  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     5  7:conv          0000900000  0000000000  001efef000  f
+     6  6:rt_data       001f8ef000  0000000000  0000100000  rf
+     7  5:rt_code       001f9ef000  0000000000  0000100000  rf
+     8  0:reserved      001faef000  0000000000  0000080000  f
+     9  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    10  a:acpi_nvs      001fb7f000  0000000000  0000080000  f
+    11  7:conv          001fbff000  0000000000  0000359000  f
+    12  6:rt_data       001ff58000  0000000000  0000020000  rf
+    13  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    14  0:reserved      00b0000000  0000000000  0010000000  1
+
+    Attributes key:
+     f: uncached, write-coalescing, write-through, write-back
+    rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
+     1: uncached
+    *Some areas are merged (use 'all' to see)
+
+
+    => efi mem  all
+    EFI table at 0, memory map 000000001ad38bb0, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  3:bs_code       0000000000  0000000000  0000001000  f
+     1  7:conv          0000001000  0000000000  000009f000  f
+        <gap>           00000a0000              0000060000
+     2  7:conv          0000100000  0000000000  0000700000  f
+     3  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     4  7:conv          0000808000  0000000000  0000008000  f
+     5  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     6  4:bs_data       0000900000  0000000000  0000c00000  f
+     7  7:conv          0001500000  0000000000  000aa36000  f
+     8  2:loader_data   000bf36000  0000000000  0010000000  f
+     9  4:bs_data       001bf36000  0000000000  0000020000  f
+    10  7:conv          001bf56000  0000000000  00021e1000  f
+    11  1:loader_code   001e137000  0000000000  00000c4000  f
+    12  7:conv          001e1fb000  0000000000  000009b000  f
+    13  1:loader_code   001e296000  0000000000  00000e2000  f
+    14  7:conv          001e378000  0000000000  000005b000  f
+    15  4:bs_data       001e3d3000  0000000000  000001e000  f
+    16  7:conv          001e3f1000  0000000000  0000016000  f
+    17  4:bs_data       001e407000  0000000000  0000016000  f
+    18  2:loader_data   001e41d000  0000000000  0000002000  f
+    19  4:bs_data       001e41f000  0000000000  0000828000  f
+    20  3:bs_code       001ec47000  0000000000  0000045000  f
+    21  4:bs_data       001ec8c000  0000000000  0000001000  f
+    22  3:bs_code       001ec8d000  0000000000  000000e000  f
+    23  4:bs_data       001ec9b000  0000000000  0000001000  f
+    24  3:bs_code       001ec9c000  0000000000  000002c000  f
+    25  4:bs_data       001ecc8000  0000000000  0000001000  f
+    26  3:bs_code       001ecc9000  0000000000  000000c000  f
+    27  4:bs_data       001ecd5000  0000000000  0000006000  f
+    28  3:bs_code       001ecdb000  0000000000  0000014000  f
+    29  4:bs_data       001ecef000  0000000000  0000001000  f
+    30  3:bs_code       001ecf0000  0000000000  000005b000  f
+    31  4:bs_data       001ed4b000  0000000000  000000b000  f
+    32  3:bs_code       001ed56000  0000000000  0000024000  f
+    33  4:bs_data       001ed7a000  0000000000  0000006000  f
+    34  3:bs_code       001ed80000  0000000000  0000010000  f
+    35  4:bs_data       001ed90000  0000000000  0000002000  f
+    36  3:bs_code       001ed92000  0000000000  0000025000  f
+    37  4:bs_data       001edb7000  0000000000  0000003000  f
+    38  3:bs_code       001edba000  0000000000  0000011000  f
+    39  4:bs_data       001edcb000  0000000000  0000008000  f
+    40  3:bs_code       001edd3000  0000000000  000002d000  f
+    41  4:bs_data       001ee00000  0000000000  0000201000  f
+    42  3:bs_code       001f001000  0000000000  0000024000  f
+    43  4:bs_data       001f025000  0000000000  0000002000  f
+    44  3:bs_code       001f027000  0000000000  0000009000  f
+    45  4:bs_data       001f030000  0000000000  0000005000  f
+    46  3:bs_code       001f035000  0000000000  000002f000  f
+    47  4:bs_data       001f064000  0000000000  0000001000  f
+    48  3:bs_code       001f065000  0000000000  0000005000  f
+    49  4:bs_data       001f06a000  0000000000  0000005000  f
+    50  3:bs_code       001f06f000  0000000000  0000007000  f
+    51  4:bs_data       001f076000  0000000000  0000007000  f
+    52  3:bs_code       001f07d000  0000000000  000000d000  f
+    53  4:bs_data       001f08a000  0000000000  0000001000  f
+    54  3:bs_code       001f08b000  0000000000  0000006000  f
+    55  4:bs_data       001f091000  0000000000  0000004000  f
+    56  3:bs_code       001f095000  0000000000  000000d000  f
+    57  4:bs_data       001f0a2000  0000000000  0000003000  f
+    58  3:bs_code       001f0a5000  0000000000  0000026000  f
+    59  4:bs_data       001f0cb000  0000000000  0000005000  f
+    60  3:bs_code       001f0d0000  0000000000  0000019000  f
+    61  4:bs_data       001f0e9000  0000000000  0000004000  f
+    62  3:bs_code       001f0ed000  0000000000  0000024000  f
+    63  4:bs_data       001f111000  0000000000  0000008000  f
+    64  3:bs_code       001f119000  0000000000  000000b000  f
+    65  4:bs_data       001f124000  0000000000  0000001000  f
+    66  3:bs_code       001f125000  0000000000  0000002000  f
+    67  4:bs_data       001f127000  0000000000  0000002000  f
+    68  3:bs_code       001f129000  0000000000  0000009000  f
+    69  4:bs_data       001f132000  0000000000  0000003000  f
+    70  3:bs_code       001f135000  0000000000  0000005000  f
+    71  4:bs_data       001f13a000  0000000000  0000003000  f
+    72  3:bs_code       001f13d000  0000000000  0000005000  f
+    73  4:bs_data       001f142000  0000000000  0000003000  f
+    74  3:bs_code       001f145000  0000000000  0000011000  f
+    75  4:bs_data       001f156000  0000000000  000000b000  f
+    76  3:bs_code       001f161000  0000000000  0000009000  f
+    77  4:bs_data       001f16a000  0000000000  0000400000  f
+    78  3:bs_code       001f56a000  0000000000  0000006000  f
+    79  4:bs_data       001f570000  0000000000  0000001000  f
+    80  3:bs_code       001f571000  0000000000  0000001000  f
+    81  4:bs_data       001f572000  0000000000  0000002000  f
+    82  3:bs_code       001f574000  0000000000  0000017000  f
+    83  4:bs_data       001f58b000  0000000000  0000364000  f
+    84  6:rt_data       001f8ef000  0000000000  0000100000  rf
+    85  5:rt_code       001f9ef000  0000000000  0000100000  rf
+    86  0:reserved      001faef000  0000000000  0000080000  f
+    87  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    88  a:acpi_nvs      001fb7f000  0000000000  0000080000  f

doc/usage/cmd/efi.rst line 192

Quoted 10 lines
doc/usage/cmd/efi.rst new file +10 -0
+    89  4:bs_data       001fbff000  0000000000  0000201000  f
+    90  7:conv          001fe00000  0000000000  00000e8000  f
+    91  4:bs_data       001fee8000  0000000000  0000020000  f
+    92  3:bs_code       001ff08000  0000000000  0000026000  f
+    93  4:bs_data       001ff2e000  0000000000  0000009000  f
+    94  3:bs_code       001ff37000  0000000000  0000021000  f
+    95  6:rt_data       001ff58000  0000000000  0000020000  rf
+    96  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    97  0:reserved      00b0000000  0000000000  0010000000  1

Why should we use a different output format then in efi_debug memmap= We should avoid duplicate code.

Best regrads

Heinrich

Quoted 17 lines
doc/usage/cmd/efi.rst new file +5 -0
+
+    Attributes key:
+     f: uncached, write-coalescing, write-through, write-back
+    rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
+     1: uncached
doc/usage/index.rst +1 -0
index 840c20c934d..9f7a80e3bfe 100644
@@ -43,6 +43,7 @@ Shell commands
     cmd/dm
     cmd/ebtupdate
     cmd/echo
+   cmd/efi
     cmd/eficonfig
     cmd/env
     cmd/event
#18 lore raw

Re: [PATCH v2 09/12] doc: Add help for the efi command

Hi Heinrich,

Quoted 207 lines · Heinrich Schuchardt
Quoted 205 lines · Simon Glass

This command currently has no help. Add some.

---

(no changes since v1)

  doc/usage/cmd/efi.rst | 197 ++++++++++++++++++++++++++++++++++++++++++
  doc/usage/index.rst   |   1 +
  2 files changed, 198 insertions(+)

create mode 100644 doc/usage/cmd/efi.rst

doc/usage/cmd/efi.rst new file +187 -0
new file mode 100644
index 00000000000..c029c423879
@@ -0,0 +1,197 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2020, Heinrich Schuchardt <[email protected]>
+
+efi command
+===========
+
+Synopsis
+--------
+
+::
+
+    efi mem [all]
+
+Description
+-----------
+
+The *efi* command provides information about the EFI environment U-Boot is
+running in, when it is started from EFI.
+
+When running as an EFI app, this command queries EFI boot services for the
+information. When running as an EFI payload, EFI boot services have been
+stopped, so it uses the information collected by the boot stub before that
+happened.
+
+efi mem
+~~~~~~~
+
+This shows the EFI memory map, sorted in order of physical address.
+
+This is normally a very large table. To help reduce the amount of detritus,
+boot-time memory is normally merged with conventional memory. Use the 'all'
+argument to show everything.
+
+The fields are as follows:
+
+#
+    Entry number (sequentially from 0)
+
+Type
+    Memory type. EFI has a large number of memory types. The type is shown in
+    the format <n>:<name> where in is the format number in hex and <name> is the
+    name.
+
+Physical
+    Physical address
+
+Virtual
+    Virtual address
+
+Size
+    Size of memory area in bytes
+
+Attributes
+    Shows a code for memory attributes. The key for this is shown below the
+    table.
+
+Example
+-------
+
+::
+
+    => efi mem
+    EFI table at 0, memory map 000000001ad38b60, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  7:conv          0000000000  0000000000  00000a0000  f
+        <gap>           00000a0000              0000060000
+     1  7:conv          0000100000  0000000000  0000700000  f
+     2  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     3  7:conv          0000808000  0000000000  0000008000  f
+     4  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     5  7:conv          0000900000  0000000000  001efef000  f
+     6  6:rt_data       001f8ef000  0000000000  0000100000  rf
+     7  5:rt_code       001f9ef000  0000000000  0000100000  rf
+     8  0:reserved      001faef000  0000000000  0000080000  f
+     9  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    10  a:acpi_nvs      001fb7f000  0000000000  0000080000  f
+    11  7:conv          001fbff000  0000000000  0000359000  f
+    12  6:rt_data       001ff58000  0000000000  0000020000  rf
+    13  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    14  0:reserved      00b0000000  0000000000  0010000000  1
+
+    Attributes key:
+     f: uncached, write-coalescing, write-through, write-back
+    rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
+     1: uncached
+    *Some areas are merged (use 'all' to see)
+
+
+    => efi mem  all
+    EFI table at 0, memory map 000000001ad38bb0, size 1260, key a79, version 1, descr. size 0x30
+     #  Type              Physical     Virtual        Size  Attributes
+     0  3:bs_code       0000000000  0000000000  0000001000  f
+     1  7:conv          0000001000  0000000000  000009f000  f
+        <gap>           00000a0000              0000060000
+     2  7:conv          0000100000  0000000000  0000700000  f
+     3  a:acpi_nvs      0000800000  0000000000  0000008000  f
+     4  7:conv          0000808000  0000000000  0000008000  f
+     5  a:acpi_nvs      0000810000  0000000000  00000f0000  f
+     6  4:bs_data       0000900000  0000000000  0000c00000  f
+     7  7:conv          0001500000  0000000000  000aa36000  f
+     8  2:loader_data   000bf36000  0000000000  0010000000  f
+     9  4:bs_data       001bf36000  0000000000  0000020000  f
+    10  7:conv          001bf56000  0000000000  00021e1000  f
+    11  1:loader_code   001e137000  0000000000  00000c4000  f
+    12  7:conv          001e1fb000  0000000000  000009b000  f
+    13  1:loader_code   001e296000  0000000000  00000e2000  f
+    14  7:conv          001e378000  0000000000  000005b000  f
+    15  4:bs_data       001e3d3000  0000000000  000001e000  f
+    16  7:conv          001e3f1000  0000000000  0000016000  f
+    17  4:bs_data       001e407000  0000000000  0000016000  f
+    18  2:loader_data   001e41d000  0000000000  0000002000  f
+    19  4:bs_data       001e41f000  0000000000  0000828000  f
+    20  3:bs_code       001ec47000  0000000000  0000045000  f
+    21  4:bs_data       001ec8c000  0000000000  0000001000  f
+    22  3:bs_code       001ec8d000  0000000000  000000e000  f
+    23  4:bs_data       001ec9b000  0000000000  0000001000  f
+    24  3:bs_code       001ec9c000  0000000000  000002c000  f
+    25  4:bs_data       001ecc8000  0000000000  0000001000  f
+    26  3:bs_code       001ecc9000  0000000000  000000c000  f
+    27  4:bs_data       001ecd5000  0000000000  0000006000  f
+    28  3:bs_code       001ecdb000  0000000000  0000014000  f
+    29  4:bs_data       001ecef000  0000000000  0000001000  f
+    30  3:bs_code       001ecf0000  0000000000  000005b000  f
+    31  4:bs_data       001ed4b000  0000000000  000000b000  f
+    32  3:bs_code       001ed56000  0000000000  0000024000  f
+    33  4:bs_data       001ed7a000  0000000000  0000006000  f
+    34  3:bs_code       001ed80000  0000000000  0000010000  f
+    35  4:bs_data       001ed90000  0000000000  0000002000  f
+    36  3:bs_code       001ed92000  0000000000  0000025000  f
+    37  4:bs_data       001edb7000  0000000000  0000003000  f
+    38  3:bs_code       001edba000  0000000000  0000011000  f
+    39  4:bs_data       001edcb000  0000000000  0000008000  f
+    40  3:bs_code       001edd3000  0000000000  000002d000  f
+    41  4:bs_data       001ee00000  0000000000  0000201000  f
+    42  3:bs_code       001f001000  0000000000  0000024000  f
+    43  4:bs_data       001f025000  0000000000  0000002000  f
+    44  3:bs_code       001f027000  0000000000  0000009000  f
+    45  4:bs_data       001f030000  0000000000  0000005000  f
+    46  3:bs_code       001f035000  0000000000  000002f000  f
+    47  4:bs_data       001f064000  0000000000  0000001000  f
+    48  3:bs_code       001f065000  0000000000  0000005000  f
+    49  4:bs_data       001f06a000  0000000000  0000005000  f
+    50  3:bs_code       001f06f000  0000000000  0000007000  f
+    51  4:bs_data       001f076000  0000000000  0000007000  f
+    52  3:bs_code       001f07d000  0000000000  000000d000  f
+    53  4:bs_data       001f08a000  0000000000  0000001000  f
+    54  3:bs_code       001f08b000  0000000000  0000006000  f
+    55  4:bs_data       001f091000  0000000000  0000004000  f
+    56  3:bs_code       001f095000  0000000000  000000d000  f
+    57  4:bs_data       001f0a2000  0000000000  0000003000  f
+    58  3:bs_code       001f0a5000  0000000000  0000026000  f
+    59  4:bs_data       001f0cb000  0000000000  0000005000  f
+    60  3:bs_code       001f0d0000  0000000000  0000019000  f
+    61  4:bs_data       001f0e9000  0000000000  0000004000  f
+    62  3:bs_code       001f0ed000  0000000000  0000024000  f
+    63  4:bs_data       001f111000  0000000000  0000008000  f
+    64  3:bs_code       001f119000  0000000000  000000b000  f
+    65  4:bs_data       001f124000  0000000000  0000001000  f
+    66  3:bs_code       001f125000  0000000000  0000002000  f
+    67  4:bs_data       001f127000  0000000000  0000002000  f
+    68  3:bs_code       001f129000  0000000000  0000009000  f
+    69  4:bs_data       001f132000  0000000000  0000003000  f
+    70  3:bs_code       001f135000  0000000000  0000005000  f
+    71  4:bs_data       001f13a000  0000000000  0000003000  f
+    72  3:bs_code       001f13d000  0000000000  0000005000  f
+    73  4:bs_data       001f142000  0000000000  0000003000  f
+    74  3:bs_code       001f145000  0000000000  0000011000  f
+    75  4:bs_data       001f156000  0000000000  000000b000  f
+    76  3:bs_code       001f161000  0000000000  0000009000  f
+    77  4:bs_data       001f16a000  0000000000  0000400000  f
+    78  3:bs_code       001f56a000  0000000000  0000006000  f
+    79  4:bs_data       001f570000  0000000000  0000001000  f
+    80  3:bs_code       001f571000  0000000000  0000001000  f
+    81  4:bs_data       001f572000  0000000000  0000002000  f
+    82  3:bs_code       001f574000  0000000000  0000017000  f
+    83  4:bs_data       001f58b000  0000000000  0000364000  f
+    84  6:rt_data       001f8ef000  0000000000  0000100000  rf
+    85  5:rt_code       001f9ef000  0000000000  0000100000  rf
+    86  0:reserved      001faef000  0000000000  0000080000  f
+    87  9:acpi_reclaim  001fb6f000  0000000000  0000010000  f
+    88  a:acpi_nvs      001fb7f000  0000000000  0000080000  f
+    89  4:bs_data       001fbff000  0000000000  0000201000  f
+    90  7:conv          001fe00000  0000000000  00000e8000  f
+    91  4:bs_data       001fee8000  0000000000  0000020000  f
+    92  3:bs_code       001ff08000  0000000000  0000026000  f
+    93  4:bs_data       001ff2e000  0000000000  0000009000  f
Quoted 8 lines

doc/usage/cmd/efi.rst line 192

Quoted 5 lines
doc/usage/cmd/efi.rst new file +5 -0
+    94  3:bs_code       001ff37000  0000000000  0000021000  f
+    95  6:rt_data       001ff58000  0000000000  0000020000  rf
+    96  a:acpi_nvs      001ff78000  0000000000  0000088000  f
+        <gap>           0020000000              0090000000
+    97  0:reserved      00b0000000  0000000000  0010000000  1

Why should we use a different output format then in efi_debug memmap= We should avoid duplicate code.

I'm adding docs for an existing command. Changing the code should be the subject of a different patch.

Further, this functionality was added in 2015 in:

f1a0bafb5802 efi: Add a command to display the memory map

The 'efidebug memmap' was added over 3 years later, in:

00358bb804e9 cmd: efidebug: add memmap command

It looks like you reviewed it. Should we ask Takahiro-san to try to link these up, as I have done in this series with the 'tables' command?

The data comes from different places for the three cases (EFI_LOADER, app, stub) but I believe it is the same data. For example, efi_get_memory_map_alloc() is used to get the memmap with EFI_LOADER, but the app and stub have a different way.

Regards,
Simon

#19 lore raw

PATCH v2 10/12 efi: Split out table-listing code into a new file

In reply to Simon Glass

This code is used with EFI_LOADER but is also useful (with some modifications) for the EFI app and payload. Move it into a shared file.

Show the address of the table so it can be examined if needed. Also show the table name as unknown if necessary. Our list of GUIDs is fairly small.

---

Changes in v2:
- Add new patch to split out table-listing code into a new file

 cmd/Makefile     |  2 +-
 cmd/efi_common.c | 26 ++++++++++++++++++++++++++
 cmd/efidebug.c   |  6 +-----
 include/efi.h    |  9 +++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 cmd/efi_common.c
cmd/Makefile +1 -1
index 2d8bb4fc052..1c5c6f3c00c 100644
@@ -63,7 +63,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
 obj-$(CONFIG_EFI) += efi.o
-obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
+obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
 ifdef CONFIG_EFI_MM_COMM_TEE
cmd/efi_common.c new file +26 -0
new file mode 100644
index 00000000000..7eedf0726a7
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for EFI commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <efi.h>
+#include <efi_api.h>
+#include <uuid.h>
+
+void efi_show_tables(struct efi_system_table *systab)
+{
+	int i;
+
+	for (i = 0; i < systab->nr_tables; i++) {
+		struct efi_configuration_table *tab = &systab->tables[i];
+		char guid_str[37];
+
+		uuid_bin_to_str(tab->guid.b, guid_str, 1);
+		printf("%p  %s  %s\n", tab->table, guid_str,
+		       uuid_guid_get_str(tab->guid.b) ?: "(unknown)");
+	}
+}
cmd/efidebug.c +1 -5
index e6959ede930..9622430c475 100644
@@ -649,11 +649,7 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag,
 static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
 			      int argc, char *const argv[])
 {
-	efi_uintn_t i;
-
-	for (i = 0; i < systab.nr_tables; ++i)
-		printf("%pUl (%pUs)\n",
-		       &systab.tables[i].guid, &systab.tables[i].guid);
+	efi_show_tables(&systab);
 
 	return CMD_RET_SUCCESS;
 }
include/efi.h +9 -0
index c3087d3da28..342dd52fed9 100644
@@ -637,4 +637,13 @@ int efi_call_exit_boot_services(void);
 int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
 		 int *desc_sizep, uint *versionp);
 
+/**
+ * efi_show_tables() - Show a list of available tables
+ *
+ * Shows the address, GUID (and name where known) for each table
+ *
+ * @systab: System table containing the list of tables
+ */
+void efi_show_tables(struct efi_system_table *systab);
+
 #endif /* _LINUX_EFI_H */
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#20 lore raw

Re: [PATCH v2 10/12] efi: Split out table-listing code into a new file

Quoted 54 lines · Simon Glass

This code is used with EFI_LOADER but is also useful (with some modifications) for the EFI app and payload. Move it into a shared file.

Show the address of the table so it can be examined if needed. Also show the table name as unknown if necessary. Our list of GUIDs is fairly small.

---

Changes in v2:
- Add new patch to split out table-listing code into a new file

  cmd/Makefile     |  2 +-
  cmd/efi_common.c | 26 ++++++++++++++++++++++++++
  cmd/efidebug.c   |  6 +-----
  include/efi.h    |  9 +++++++++
  4 files changed, 37 insertions(+), 6 deletions(-)

create mode 100644 cmd/efi_common.c

cmd/Makefile +1 -1
index 2d8bb4fc052..1c5c6f3c00c 100644
@@ -63,7 +63,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
  obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
  obj-$(CONFIG_CMD_EEPROM) += eeprom.o
  obj-$(CONFIG_EFI) += efi.o
-obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
+obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
  obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
  ifdef CONFIG_CMD_EFICONFIG
  ifdef CONFIG_EFI_MM_COMM_TEE
cmd/efi_common.c new file +14 -0
new file mode 100644
index 00000000000..7eedf0726a7
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for EFI commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <efi.h>
+#include <efi_api.h>
+#include <uuid.h>
+
+void efi_show_tables(struct efi_system_table *systab)

cmd/efi_common.c line 24

Quoted 10 lines
cmd/efi_common.c new file +10 -0
+{
+	int i;
+
+	for (i = 0; i < systab->nr_tables; i++) {
+		struct efi_configuration_table *tab = &systab->tables[i];
+		char guid_str[37];
+
+		uuid_bin_to_str(tab->guid.b, guid_str, 1);
+		printf("%p  %s  %s\n", tab->table, guid_str,
+		       uuid_guid_get_str(tab->guid.b) ?: "(unknown)");

Please, use %pUl to print the UUID string.

Best regards

Heinrich

Quoted 37 lines
cmd/efi_common.c new file +2 -0
+	}
+}
cmd/efidebug.c +1 -5
index e6959ede930..9622430c475 100644
@@ -649,11 +649,7 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag,
  static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
  			      int argc, char *const argv[])
  {
-	efi_uintn_t i;
-
-	for (i = 0; i < systab.nr_tables; ++i)
-		printf("%pUl (%pUs)\n",
-		       &systab.tables[i].guid, &systab.tables[i].guid);
+	efi_show_tables(&systab);
 
  	return CMD_RET_SUCCESS;
  }
include/efi.h +9 -0
index c3087d3da28..342dd52fed9 100644
@@ -637,4 +637,13 @@ int efi_call_exit_boot_services(void);
  int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
  		 int *desc_sizep, uint *versionp);
 
+/**
+ * efi_show_tables() - Show a list of available tables
+ *
+ * Shows the address, GUID (and name where known) for each table
+ *
+ * @systab: System table containing the list of tables
+ */
+void efi_show_tables(struct efi_system_table *systab);
+
  #endif /* _LINUX_EFI_H */
#21 lore raw

PATCH v2 11/12 efi: Support showing tables

In reply to Simon Glass

Add a command (for the app and payload) to display the tables provided by EFI.

---

Changes in v2:
- Make use of common code

 cmd/Makefile          |  2 +-
 cmd/efi.c             | 33 ++++++++++++++++++++++++++++++++-
 doc/usage/cmd/efi.rst | 22 ++++++++++++++++++++++
 3 files changed, 55 insertions(+), 2 deletions(-)
cmd/Makefile +1 -1
index 1c5c6f3c00c..a0bfa2acefe 100644
@@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_EFI) += efi.o efi_common.o
 obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
cmd/efi.c +32 -1
index c0384e0db28..4d0edfa7f27 100644
@@ -7,10 +7,12 @@
 #include <common.h>
 #include <command.h>
 #include <efi.h>
+#include <efi_api.h>
 #include <errno.h>
 #include <log.h>
 #include <malloc.h>
 #include <sort.h>
+#include <uuid.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -273,8 +275,36 @@ done:
 	return ret ? CMD_RET_FAILURE : 0;
 }
 
+static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	struct efi_system_table *systab;
+
+	if (IS_ENABLED(CONFIG_EFI_APP)) {
+		systab = efi_get_sys_table();
+		if (!systab) {
+			printf("Cannot read system table\n");
+			return CMD_RET_FAILURE;
+		}
+	} else {
+		int size;
+		int ret;
+
+		ret = efi_info_get(EFIET_SYS_TABLE, (void **)&systab, &size);
+		if (ret) {
+			printf("Cannot find EFI system table (err=%d)\n", ret);
+			return CMD_RET_FAILURE;
+		}
+	}
+
+	efi_show_tables(systab);
+
+	return 0;
+}
+
 static struct cmd_tbl efi_commands[] = {
 	U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
+	U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""),
 };
 
 static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -298,5 +328,6 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 U_BOOT_CMD(
 	efi,     3,      1,      do_efi,
 	"EFI access",
-	"mem [all]        Dump memory information [include boot services]"
+	"mem [all]        Dump memory information [include boot services]\n"
+	"tables               Dump tables"
 );
doc/usage/cmd/efi.rst +22 -0
index c029c423879..ef37ff2f4c1 100644
@@ -10,6 +10,7 @@ Synopsis
 ::
 
     efi mem [all]
+    efi tables
 
 Description
 -----------
@@ -54,6 +55,14 @@ Attributes
     Shows a code for memory attributes. The key for this is shown below the
     table.
 
+efi tables
+~~~~~~~~~~
+
+This shows a list of the EFI tables provided in the system table. These use
+GUIDs so it is not possible in general to show the name of a table. But some
+effort is made to provide a useful table, where the GUID is known by U-Boot.
+
+
 Example
 -------
 
@@ -195,3 +204,16 @@ Example
      f: uncached, write-coalescing, write-through, write-back
     rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
      1: uncached
+
+
+    => efi tables
+    000000001f8edf98  ee4e5898-3914-4259-9d6e-dc7bd79403cf  EFI_LZMA_COMPRESSED
+    000000001ff2ace0  05ad34ba-6f02-4214-952e-4da0398e2bb9  EFI_DXE_SERVICES
+    000000001f8ea018  7739f24c-93d7-11d4-9a3a-0090273fc14d  EFI_HOB_LIST
+    000000001ff2bac0  4c19049f-4137-4dd3-9c10-8b97a83ffdfa  EFI_MEMORY_TYPE
+    000000001ff2cb10  49152e77-1ada-4764-b7a2-7afefed95e8b  (unknown)
+    000000001f9ac018  060cc026-4c0d-4dda-8f41-595fef00a502  EFI_MEM_STATUS_CODE_REC
+    000000001f9ab000  eb9d2d31-2d88-11d3-9a16-0090273fc14d  SMBIOS table
+    000000001fb7e000  eb9d2d30-2d88-11d3-9a16-0090273fc14d  EFI_GUID_EFI_ACPI1
+    000000001fb7e014  8868e871-e4f1-11d3-bc22-0080c73c8881  ACPI table
+    000000001e654018  dcfa911d-26eb-469f-a220-38b7dc461220  (unknown)
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
#22 lore raw

Re: [PATCH v2 11/12] efi: Support showing tables

Quoted 57 lines · Simon Glass

Add a command (for the app and payload) to display the tables provided by EFI.

---

Changes in v2:
- Make use of common code

  cmd/Makefile          |  2 +-
  cmd/efi.c             | 33 ++++++++++++++++++++++++++++++++-
  doc/usage/cmd/efi.rst | 22 ++++++++++++++++++++++
  3 files changed, 55 insertions(+), 2 deletions(-)
cmd/Makefile +1 -1
index 1c5c6f3c00c..a0bfa2acefe 100644
@@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
  obj-$(CONFIG_CMD_ECHO) += echo.o
  obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
  obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_EFI) += efi.o efi_common.o
  obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
  obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
  ifdef CONFIG_CMD_EFICONFIG
cmd/efi.c +11 -0
index c0384e0db28..4d0edfa7f27 100644
@@ -7,10 +7,12 @@
  #include <common.h>
  #include <command.h>
  #include <efi.h>
+#include <efi_api.h>
  #include <errno.h>
  #include <log.h>
  #include <malloc.h>
  #include <sort.h>
+#include <uuid.h>
  #include <asm/global_data.h>
 
  DECLARE_GLOBAL_DATA_PTR;
@@ -273,8 +275,36 @@ done:
  	return ret ? CMD_RET_FAILURE : 0;
  }
 
+static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	struct efi_system_table *systab;
+
+	if (IS_ENABLED(CONFIG_EFI_APP)) {
+		systab = efi_get_sys_table();
+		if (!systab) {
+			printf("Cannot read system table\n");

cmd/efi.c done: · line 296

Quoted 10 lines
cmd/efi.c +10 -0
+			return CMD_RET_FAILURE;
+		}
+	} else {
+		int size;
+		int ret;
+
+		ret = efi_info_get(EFIET_SYS_TABLE, (void **)&systab, &size);
+		if (ret) {
+			printf("Cannot find EFI system table (err=%d)\n", ret);
+			return CMD_RET_FAILURE;

Wouldn't U-Boot have failed earlier if there is no system table?

Best regards

Heinrich

Quoted 66 lines
cmd/efi.c +11 -1
+		}
+	}
+
+	efi_show_tables(systab);
+
+	return 0;
+}
+
  static struct cmd_tbl efi_commands[] = {
  	U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
+	U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""),
  };
 
  static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -298,5 +328,6 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  U_BOOT_CMD(
  	efi,     3,      1,      do_efi,
  	"EFI access",
-	"mem [all]        Dump memory information [include boot services]"
+	"mem [all]        Dump memory information [include boot services]\n"
+	"tables               Dump tables"
  );
doc/usage/cmd/efi.rst +22 -0
index c029c423879..ef37ff2f4c1 100644
@@ -10,6 +10,7 @@ Synopsis
  ::
 
      efi mem [all]
+    efi tables
 
  Description
  -----------
@@ -54,6 +55,14 @@ Attributes
      Shows a code for memory attributes. The key for this is shown below the
      table.
 
+efi tables
+~~~~~~~~~~
+
+This shows a list of the EFI tables provided in the system table. These use
+GUIDs so it is not possible in general to show the name of a table. But some
+effort is made to provide a useful table, where the GUID is known by U-Boot.
+
+
  Example
  -------
 
@@ -195,3 +204,16 @@ Example
       f: uncached, write-coalescing, write-through, write-back
      rf: uncached, write-coalescing, write-through, write-back, needs runtime mapping
       1: uncached
+
+
+    => efi tables
+    000000001f8edf98  ee4e5898-3914-4259-9d6e-dc7bd79403cf  EFI_LZMA_COMPRESSED
+    000000001ff2ace0  05ad34ba-6f02-4214-952e-4da0398e2bb9  EFI_DXE_SERVICES
+    000000001f8ea018  7739f24c-93d7-11d4-9a3a-0090273fc14d  EFI_HOB_LIST
+    000000001ff2bac0  4c19049f-4137-4dd3-9c10-8b97a83ffdfa  EFI_MEMORY_TYPE
+    000000001ff2cb10  49152e77-1ada-4764-b7a2-7afefed95e8b  (unknown)
+    000000001f9ac018  060cc026-4c0d-4dda-8f41-595fef00a502  EFI_MEM_STATUS_CODE_REC
+    000000001f9ab000  eb9d2d31-2d88-11d3-9a16-0090273fc14d  SMBIOS table
+    000000001fb7e000  eb9d2d30-2d88-11d3-9a16-0090273fc14d  EFI_GUID_EFI_ACPI1
+    000000001fb7e014  8868e871-e4f1-11d3-bc22-0080c73c8881  ACPI table
+    000000001e654018  dcfa911d-26eb-469f-a220-38b7dc461220  (unknown)
#23 lore raw

Re: [PATCH v2 11/12] efi: Support showing tables

Hi Heinrich,

Quoted 63 lines · Heinrich Schuchardt
Quoted 61 lines · Simon Glass

Add a command (for the app and payload) to display the tables provided by EFI.

---

Changes in v2:
- Make use of common code

  cmd/Makefile          |  2 +-
  cmd/efi.c             | 33 ++++++++++++++++++++++++++++++++-
  doc/usage/cmd/efi.rst | 22 ++++++++++++++++++++++
  3 files changed, 55 insertions(+), 2 deletions(-)
cmd/Makefile +1 -1
index 1c5c6f3c00c..a0bfa2acefe 100644
@@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
  obj-$(CONFIG_CMD_ECHO) += echo.o
  obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
  obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_EFI) += efi.o efi_common.o
  obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
  obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
  ifdef CONFIG_CMD_EFICONFIG
cmd/efi.c +15 -0
index c0384e0db28..4d0edfa7f27 100644
@@ -7,10 +7,12 @@
  #include <common.h>
  #include <command.h>
  #include <efi.h>
+#include <efi_api.h>
  #include <errno.h>
  #include <log.h>
  #include <malloc.h>
  #include <sort.h>
+#include <uuid.h>
  #include <asm/global_data.h>
 
  DECLARE_GLOBAL_DATA_PTR;
@@ -273,8 +275,36 @@ done:
      return ret ? CMD_RET_FAILURE : 0;
  }
 
+static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+     struct efi_system_table *systab;
+
+     if (IS_ENABLED(CONFIG_EFI_APP)) {
+             systab = efi_get_sys_table();
+             if (!systab) {
+                     printf("Cannot read system table\n");
+                     return CMD_RET_FAILURE;
+             }
+     } else {
+             int size;
Quoted 8 lines

cmd/efi.c done: · line 296

Quoted 6 lines
cmd/efi.c +6 -0
+             int ret;
+
+             ret = efi_info_get(EFIET_SYS_TABLE, (void **)&systab, &size);
+             if (ret) {
+                     printf("Cannot find EFI system table (err=%d)\n", ret);
+                     return CMD_RET_FAILURE;

Wouldn't U-Boot have failed earlier if there is no system table?

This is catching the case where we didn't add it to the list by calling add_entry_addr() in the stub. I agree it can't happen with the current code. How about I just drop the message, but still return failure?

Regards,
Simon

#24 lore raw

PATCH v2 12/12 efI: Allow packaging a kernel in the debugging script

In reply to Simon Glass

Add an option to package a kernel into the debugging script used for EFI.

The name of the kernel must be added to the script. By default it is assumed that the kernel is built in the /tmp/kernel directory.

---

Changes in v2:
- Fix typos in commit message

 scripts/build-efi.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
scripts/build-efi.sh +13 -1
index 46c28807ef1..6b7df2e9bfe 100755
@@ -18,12 +18,15 @@
 # OVMF-pure-efi.x64.fd at
 # https://drive.google.com/file/d/1c39YI9QtpByGQ4V0UNNQtGqttEzS-eFV/view?usp=sharing
 
+bzimage_fname=/tmp/kernel/arch/x86/boot/bzImage
+
 set -e
 
 usage() {
 	echo "Usage: $0 [-a | -p] [other opts]" 1>&2
 	echo 1>&2
 	echo "   -a   - Package up the app" 1>&2
+	echo "   -k   - Add a kernel" 1>&2
 	echo "   -o   - Use old EFI app build (before 32/64 split)" 1>&2
 	echo "   -p   - Package up the payload" 1>&2
 	echo "   -P   - Create a partition table" 1>&2
@@ -52,11 +55,14 @@ serial=
 # before the 32/64 split of the app
 old=
 
+# package up a kernel as well
+kernel=
+
 # Set ubdir to the build directory where you build U-Boot out-of-tree
 # We avoid in-tree build because it gets confusing trying different builds
 ubdir=/tmp/b/
 
-while getopts "aopPrsw" opt; do
+while getopts "akopPrsw" opt; do
 	case "${opt}" in
 	a)
 		type=app
@@ -64,6 +70,9 @@ while getopts "aopPrsw" opt; do
 	p)
 		type=payload
 		;;
+	k)
+		kernel=1
+		;;
 	r)
 		run=1
 		;;
@@ -124,6 +133,9 @@ EOF
 # Copy files into the filesystem
 copy_files() {
 	sudo cp $TMP/* $MNT
+	if [[ -n "${kernel}" ]]; then
+		sudo cp ${bzimage_fname} $MNT/vmlinuz
+	fi
 }
 
 # Create a filesystem on a raw device and copy in the files
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog