Skip to contentSkip to conversation

efi_loader: Add support for logging to a buffer

PATCH Superseded Simon Glass 4 participants 40 messages Oct 28, 2024 – Dec 2, 2024 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover efi_loader: Add support for logging to a buffer

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

This feature makes it possible to add tests to check which EFI calls are made by U-Boot itself. It may also make it easier to figure out what is needed for booting Windows.

Some patches to help with debugging sandbox memory-mapping are included, but for now EFI's use of mapping is not adjusted.

Simon Glass (15):
log: Add a new category for tests
test: Allow saving and restoring the bloblist
bloblist: test: Mark tests with UTF_BLOBLIST
sandbox: Convert sb command to use new macro
doc: sandbox: Add docs for the sb command
sandbox: Add a way to show the sandbox memory-mapping
sandbox: Fix comment for nomap_sysmem() function
lmb: Drop extra 16KB of stack space
efi_loader: Fix free in ..._media_device_boot_option()
efi_loader: Add support for logging EFI calls
efi_loader: Create the log on startup
efi_loader: Add a command to show the EFI log
test: efi_loader: Add a simple test for the EFI log
efi_loader: Use the log with memory-related functions
efi_loader: Add documentation for the EFI log

 MAINTAINERS                    |   7 +
 arch/sandbox/cpu/cpu.c         |  13 +
 arch/sandbox/include/asm/cpu.h |   3 +
 arch/sandbox/include/asm/io.h  |   2 +-
 cmd/efidebug.c                 |  53 +++-
 cmd/sb.c                       |  42 ++--
 common/log.c                   |   1 +
 configs/sandbox_defconfig      |   3 +
 doc/develop/uefi/uefi.rst      |  22 ++
 doc/usage/cmd/efidebug.rst     | 109 ++++++++
 doc/usage/cmd/sb.rst           |  79 ++++++
 doc/usage/index.rst            |   2 +
 include/bloblist.h             |   1 +
 include/efi.h                  |   1 +
 include/efi_log.h              | 316 +++++++++++++++++++++++
 include/log.h                  |   2 +
 include/test/test.h            |   3 +
 lib/efi_loader/Kconfig         |  19 ++
 lib/efi_loader/Makefile        |   1 +
 lib/efi_loader/efi_bootmgr.c   |   3 +-
 lib/efi_loader/efi_log.c       | 444 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c    | 119 ++++++---
 lib/efi_loader/efi_setup.c     |   7 +
 lib/lmb.c                      |   2 -
 test/common/bloblist.c         |  28 +--
 test/lib/Makefile              |   1 +
 test/lib/efi_log.c             |  93 +++++++
 test/test-main.c               |  13 +
 28 files changed, 1305 insertions(+), 84 deletions(-)
 create mode 100644 doc/usage/cmd/efidebug.rst
 create mode 100644 doc/usage/cmd/sb.rst
 create mode 100644 include/efi_log.h
 create mode 100644 lib/efi_loader/efi_log.c
 create mode 100644 test/lib/efi_log.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/15 log: Add a new category for tests

In some core test code, no existing categories make sense. Add a new one for testing.

---

 common/log.c  | 1 +
 include/log.h | 2 ++
 2 files changed, 3 insertions(+)
common/log.c +1 -0
index b83a6618900..c9fe35230d6 100644
@@ -32,6 +32,7 @@ static const char *const log_cat_name[] = {
 	"fs",
 	"expo",
 	"console",
+	"test",
 };
 
 _Static_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE,
include/log.h +2 -0
index bf81a27011f..4f6d6a2c2cf 100644
@@ -106,6 +106,8 @@ enum log_category_t {
 	LOGC_EXPO,
 	/** @LOGC_CONSOLE: Related to the console and stdio */
 	LOGC_CONSOLE,
+	/** @LOGC_TEST: Related to testing */
+	LOGC_TEST,
 	/** @LOGC_COUNT: Number of log categories */
 	LOGC_COUNT,
 	/** @LOGC_END: Sentinel value for lists of log categories */
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/15 test: Allow saving and restoring the bloblist

In reply to Simon Glass

Tests which create a new bloblist overwrite the existing one in sandbox. Provide a flag for tests to declare this behaviour. Save and restore the bloblist pointer so that other tests remain unaffected.

Note that when sandbox is running normally, the bloblist has been relocated to high in memory. The existing bloblist tests create a new bloblist low in memory, so they do not conflict.

---

 include/test/test.h |  3 +++
 test/test-main.c    | 13 +++++++++++++
 2 files changed, 16 insertions(+)
include/test/test.h +3 -0
index 92eec2eb6f9..21c0478befe 100644
@@ -29,6 +29,7 @@
  * @of_other: Live tree for the other FDT
  * @runs_per_test: Number of times to run each test (typically 1)
  * @force_run: true to run tests marked with the UTF_MANUAL flag
+ * @old_bloblist: stores the old gd->bloblist pointer
  * @expect_str: Temporary string used to hold expected string value
  * @actual_str: Temporary string used to hold actual string value
  */
@@ -50,6 +51,7 @@ struct unit_test_state {
 	struct device_node *of_other;
 	int runs_per_test;
 	bool force_run;
+	void *old_bloblist;
 	char expect_str[512];
 	char actual_str[512];
 };
@@ -73,6 +75,7 @@ enum ut_flags {
 	UTF_MANUAL	= BIT(8),
 	UTF_ETH_BOOTDEV	= BIT(9),	/* enable Ethernet bootdevs */
 	UTF_SF_BOOTDEV	= BIT(10),	/* enable SPI flash bootdevs */
+	UFT_BLOBLIST	= BIT(11),	/* test changes gd->bloblist */
 };
 
 /**
test/test-main.c +13 -0
index c825f9c7797..e1e8c6cde4b 100644
@@ -4,6 +4,8 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#define LOG_CATEGORY	LOGC_TEST
+
 #include <blk.h>
 #include <console.h>
 #include <cyclic.h>
@@ -379,6 +381,12 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 			return -EAGAIN;
 		}
 	}
+	if (test->flags & UFT_BLOBLIST) {
+		log_debug("save bloblist %p\n", gd->bloblist);
+		uts->old_bloblist = gd->bloblist;
+		gd->bloblist = NULL;
+	}
+
 	ut_silence_console(uts);
 
 	return 0;
@@ -402,6 +410,11 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
 	free(uts->of_other);
 	uts->of_other = NULL;
 
+	if (test->flags & UFT_BLOBLIST) {
+		gd->bloblist = uts->old_bloblist;
+		log_debug("restore bloblist %p\n", gd->bloblist);
+	}
+
 	blkcache_free();
 
 	return 0;
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/15 bloblist: test: Mark tests with UTF_BLOBLIST

In reply to Simon Glass

Mark bloblist tests with this flag so that other tests which use bloblist remain unaffected.

---

 test/common/bloblist.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
test/common/bloblist.c +14 -14
index dbd174299fd..4ff0234ca00 100644
@@ -87,7 +87,7 @@ static int bloblist_test_init(struct unit_test_state *uts)
 
 	return 1;
 }
-COMMON_TEST(bloblist_test_init, 0);
+COMMON_TEST(bloblist_test_init, UFT_BLOBLIST);
 
 static int bloblist_test_blob(struct unit_test_state *uts)
 {
@@ -127,7 +127,7 @@ static int bloblist_test_blob(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_blob, 0);
+COMMON_TEST(bloblist_test_blob, UFT_BLOBLIST);
 
 /* Check bloblist_ensure_size_ret() */
 static int bloblist_test_blob_ensure(struct unit_test_state *uts)
@@ -161,7 +161,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_blob_ensure, 0);
+COMMON_TEST(bloblist_test_blob_ensure, UFT_BLOBLIST);
 
 static int bloblist_test_bad_blob(struct unit_test_state *uts)
 {
@@ -177,7 +177,7 @@ static int bloblist_test_bad_blob(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_bad_blob, 0);
+COMMON_TEST(bloblist_test_bad_blob, UFT_BLOBLIST);
 
 static int bloblist_test_checksum(struct unit_test_state *uts)
 {
@@ -250,7 +250,7 @@ static int bloblist_test_checksum(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_checksum, 0);
+COMMON_TEST(bloblist_test_checksum, UFT_BLOBLIST);
 
 /* Test the 'bloblist info' command */
 static int bloblist_test_cmd_info(struct unit_test_state *uts)
@@ -271,7 +271,7 @@ static int bloblist_test_cmd_info(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_cmd_info, UTF_CONSOLE);
+COMMON_TEST(bloblist_test_cmd_info, UFT_BLOBLIST | UTF_CONSOLE);
 
 /* Test the 'bloblist list' command */
 static int bloblist_test_cmd_list(struct unit_test_state *uts)
@@ -293,7 +293,7 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_cmd_list, UTF_CONSOLE);
+COMMON_TEST(bloblist_test_cmd_list, UFT_BLOBLIST | UTF_CONSOLE);
 
 /* Test alignment of bloblist blobs */
 static int bloblist_test_align(struct unit_test_state *uts)
@@ -351,7 +351,7 @@ static int bloblist_test_align(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_align, 0);
+COMMON_TEST(bloblist_test_align, UFT_BLOBLIST);
 
 /* Test relocation of a bloblist */
 static int bloblist_test_reloc(struct unit_test_state *uts)
@@ -385,7 +385,7 @@ static int bloblist_test_reloc(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_reloc, 0);
+COMMON_TEST(bloblist_test_reloc, UFT_BLOBLIST);
 
 /* Test expansion of a blob */
 static int bloblist_test_grow(struct unit_test_state *uts)
@@ -438,7 +438,7 @@ static int bloblist_test_grow(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_grow, 0);
+COMMON_TEST(bloblist_test_grow, UFT_BLOBLIST);
 
 /* Test shrinking of a blob */
 static int bloblist_test_shrink(struct unit_test_state *uts)
@@ -488,7 +488,7 @@ static int bloblist_test_shrink(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_shrink, 0);
+COMMON_TEST(bloblist_test_shrink, UFT_BLOBLIST);
 
 /* Test failing to adjust a blob size */
 static int bloblist_test_resize_fail(struct unit_test_state *uts)
@@ -523,7 +523,7 @@ static int bloblist_test_resize_fail(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_resize_fail, 0);
+COMMON_TEST(bloblist_test_resize_fail, UFT_BLOBLIST);
 
 /* Test expanding the last blob in a bloblist */
 static int bloblist_test_resize_last(struct unit_test_state *uts)
@@ -574,7 +574,7 @@ static int bloblist_test_resize_last(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_resize_last, 0);
+COMMON_TEST(bloblist_test_resize_last, UFT_BLOBLIST);
 
 /* Check a completely full bloblist */
 static int bloblist_test_blob_maxsize(struct unit_test_state *uts)
@@ -597,4 +597,4 @@ static int bloblist_test_blob_maxsize(struct unit_test_state *uts)
 
 	return 0;
 }
-COMMON_TEST(bloblist_test_blob_maxsize, 0);
+COMMON_TEST(bloblist_test_blob_maxsize, UFT_BLOBLIST);
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/15 sandbox: Convert sb command to use new macro

In reply to Simon Glass

Ise the new U_BOOT_CMD_WITH_SUBCMDS() macro instead of writing the code out manually.

---

 cmd/sb.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)
cmd/sb.c +6 -25
index db485fddfca..9dbb53275b3 100644
@@ -40,29 +40,10 @@ static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static struct cmd_tbl cmd_sb_sub[] = {
-	U_BOOT_CMD_MKENT(handoff, 1, 0, do_sb_handoff, "", ""),
-	U_BOOT_CMD_MKENT(state, 1, 0, do_sb_state, "", ""),
-};
-
-static int do_sb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-	struct cmd_tbl *c;
-
-	/* Skip past 'sb' */
-	argc--;
-	argv++;
-
-	c = find_cmd_tbl(argv[0], cmd_sb_sub, ARRAY_SIZE(cmd_sb_sub));
-	if (c)
-		return c->cmd(cmdtp, flag, argc, argv);
-	else
-		return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-	sb,	8,	1,	do_sb,
-	"Sandbox status commands",
+U_BOOT_LONGHELP(sb,
 	"handoff     - Show handoff data received from SPL\n"
-	"sb state       - Show sandbox state"
-);
+	"sb state       - Show sandbox state");
+
+U_BOOT_CMD_WITH_SUBCMDS(sb, "Sandbox status commands", sb_help_text,
+	U_BOOT_SUBCMD_MKENT(handoff, 1, 1, do_sb_handoff),
+	U_BOOT_SUBCMD_MKENT(state, 1, 1, do_sb_state));
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/15 doc: sandbox: Add docs for the sb command

In reply to Simon Glass

This command has a few small features, so document it.

---

 doc/usage/cmd/sb.rst | 54 ++++++++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst  |  1 +
 2 files changed, 55 insertions(+)
 create mode 100644 doc/usage/cmd/sb.rst
doc/usage/cmd/sb.rst new file +54 -0
new file mode 100644
index 00000000000..6f54f9d9eb7
@@ -0,0 +1,54 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. index::
+   single: sbi (command)
+
+sbi command
+===========
+
+Synopsis
+--------
+
+::
+
+    sb handoff
+    sb state
+
+Description
+-----------
+
+The *sb* command is used to display information about sandbox's internal
+operation. See :doc:`/arch/sandbox/index` for more information.
+
+sb handoff
+~~~~~~~~~~
+
+This shows information about any handoff information received from SPL. If
+U-Boot is started from an SPL build, it shows a valid magic number.
+
+sb state
+~~~~~~~~
+
+This shows basic information about the sandbox state, currently just the
+command-line with which sandbox was started.
+
+Example
+-------
+
+This shows checking for the presence of SPL-handoff information. For this to
+work, ``u-boot-spl`` must be run, with build that enables ``CONFIG_SPL``, such
+as ``sandbox_spl``::
+
+    => sb handoff
+    SPL handoff magic 14f93c7b
+
+This shows output from the *sb state* subcommand::
+
+    => sb state
+    Arguments:
+    /tmp/b/sandbox/u-boot -D
+
+Configuration
+-------------
+
+The *sb handoff* command is only supported if CONFIG_HANDOFF is enabled.
doc/usage/index.rst +1 -0
index db71711c393..24b2d2637b1 100644
@@ -103,6 +103,7 @@ Shell commands
    cmd/reset
    cmd/rng
    cmd/saves
+   cmd/sb
    cmd/sbi
    cmd/scmi
    cmd/scp03
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 05/15] doc: sandbox: Add docs for the sb command

Quoted 16 lines · Simon Glass

This command has a few small features, so document it.

---

  doc/usage/cmd/sb.rst | 54 ++++++++++++++++++++++++++++++++++++++++++++
  doc/usage/index.rst  |  1 +
  2 files changed, 55 insertions(+)

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

doc/usage/cmd/sb.rst new file +0 -0
new file mode 100644
index 00000000000..6f54f9d9eb7

doc/usage/cmd/sb.rst line 1

Quoted 1 line
doc/usage/cmd/sb.rst new file +1 -0
@@ -0,0 +1,54 @@
+.. SPDX-License-Identifier: GPL-2.0+

Please, use a valid SPDX identifier. See here

https://spdx.org/licenses/GPL-2.0-or-later.html

doc/usage/cmd/sb.rst line 4

Quoted 3 lines
doc/usage/cmd/sb.rst new file +3 -0
+
+.. index::
+   single: sbi (command)

The sbi command is used to show the status of the RISC-V SBI firmware. You wanted to describe the sb command?

doc/usage/cmd/sb.rst line 6

Quoted 2 lines
doc/usage/cmd/sb.rst new file +2 -0
+
+sbi command

ditto

Quoted 5 lines
doc/usage/cmd/sb.rst new file +5 -0
+===========
+
+Synopsis
+--------
+

doc/usage/cmd/sb.rst line 21

Quoted 10 lines
doc/usage/cmd/sb.rst new file +10 -0
+::
+
+    sb handoff
+    sb state
+
+Description
+-----------
+
+The *sb* command is used to display information about sandbox's internal
+operation. See :doc:`/arch/sandbox/index` for more information.

The command can only show states and not any operation.

%s/operation/operational state/ ?

Quoted 12 lines
doc/usage/cmd/sb.rst new file +12 -0
+
+sb handoff
+~~~~~~~~~~
+
+This shows information about any handoff information received from SPL. If
+U-Boot is started from an SPL build, it shows a valid magic number.
+
+sb state
+~~~~~~~~
+
+This shows basic information about the sandbox state, currently just the
+command-line with which sandbox was started.

doc/usage/cmd/sb.rst line 43

Quoted 10 lines
doc/usage/cmd/sb.rst new file +10 -0
+
+Example
+-------
+
+This shows checking for the presence of SPL-handoff information. For this to
+work, ``u-boot-spl`` must be run, with build that enables ``CONFIG_SPL``, such
+as ``sandbox_spl``::
+
+    => sb handoff
+    SPL handoff magic 14f93c7b

As a user I would have no clue what this magic is used for. This needs some explanation. Why should I care for some random number?

Is this really sandbox only information?

I would be much more interested what information is passed in general from SPL.

doc/usage/cmd/sb.rst line 49

Quoted 6 lines
doc/usage/cmd/sb.rst new file +6 -0
+
+This shows output from the *sb state* subcommand::
+
+    => sb state
+    Arguments:
+    /tmp/b/sandbox/u-boot -D

Please, remove /tmp/b/sandbox. I would expect the average user to invoke the sandbox from the build directory:

./u-boot -D

doc/usage/cmd/sb.rst line 54

Quoted 5 lines
doc/usage/cmd/sb.rst new file +5 -0
+
+Configuration
+-------------
+
+The *sb handoff* command is only supported if CONFIG_HANDOFF is enabled.

What enables the sb command?

Why do we need two sub-commands to show so little information?

It would be much easier to simply type 'sb' and get all the information.

If you there is so little information of interest, why don't you simply implement arch_print_bdinfo() like you did on x86?

Best regards

Heinrich

Quoted 12 lines
doc/usage/index.rst +1 -0
index db71711c393..24b2d2637b1 100644
@@ -103,6 +103,7 @@ Shell commands
     cmd/reset
     cmd/rng
     cmd/saves
+   cmd/sb
     cmd/sbi
     cmd/scmi
     cmd/scp03
#7 lore raw

PATCH 6/15 sandbox: Add a way to show the sandbox memory-mapping

In reply to Simon Glass

This is mostly hidden in the background, but it is sometimes useful to look at it. Add a function to allow this.

---

 arch/sandbox/cpu/cpu.c         | 13 +++++++++++++
 arch/sandbox/include/asm/cpu.h |  3 +++
 cmd/sb.c                       | 11 +++++++++++
 doc/usage/cmd/sb.rst           | 25 +++++++++++++++++++++++++
 4 files changed, 52 insertions(+)
arch/sandbox/cpu/cpu.c +13 -0
index 06f8c13fab9..d1c4dcf0764 100644
@@ -253,6 +253,19 @@ phys_addr_t map_to_sysmem(const void *ptr)
 	return mentry->tag;
 }
 
+void sandbox_map_list(void)
+{
+	struct sandbox_mapmem_entry *mentry;
+	struct sandbox_state *state = state_get_current();
+
+	printf("Sandbox memory-mapping\n");
+	printf("%8s  %16s  %6s\n", "Addr", "Mapping", "Refcnt");
+	list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
+		printf("%8lx  %p  %6d\n", mentry->tag, mentry->ptr,
+		       mentry->refcnt);
+	}
+}
+
 unsigned long sandbox_read(const void *addr, enum sandboxio_size_t size)
 {
 	struct sandbox_state *state = state_get_current();
arch/sandbox/include/asm/cpu.h +3 -0
index c97ac7ba95b..682bb3376d1 100644
@@ -8,4 +8,7 @@
 
 void cpu_sandbox_set_current(const char *name);
 
+/* show the mapping of sandbox addresses to pointers */
+void sandbox_map_list(void);
+
 #endif /* __SANDBOX_CPU_H */
cmd/sb.c +11 -0
index 9dbb53275b3..9245052492e 100644
@@ -7,6 +7,7 @@
 #include <command.h>
 #include <dm.h>
 #include <spl.h>
+#include <asm/cpu.h>
 #include <asm/global_data.h>
 #include <asm/state.h>
 
@@ -29,6 +30,14 @@ static int do_sb_handoff(struct cmd_tbl *cmdtp, int flag, int argc,
 #endif
 }
 
+static int do_sb_map(struct cmd_tbl *cmdtp, int flag, int argc,
+		     char *const argv[])
+{
+	sandbox_map_list();
+
+	return 0;
+}
+
 static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
@@ -42,8 +51,10 @@ static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_LONGHELP(sb,
 	"handoff     - Show handoff data received from SPL\n"
+	"sb map         - Show mapped memory\n"
 	"sb state       - Show sandbox state");
 
 U_BOOT_CMD_WITH_SUBCMDS(sb, "Sandbox status commands", sb_help_text,
 	U_BOOT_SUBCMD_MKENT(handoff, 1, 1, do_sb_handoff),
+	U_BOOT_SUBCMD_MKENT(map, 1, 1, do_sb_map),
 	U_BOOT_SUBCMD_MKENT(state, 1, 1, do_sb_state));
doc/usage/cmd/sb.rst +25 -0
index 6f54f9d9eb7..37431aff7c8 100644
@@ -12,6 +12,7 @@ Synopsis
 ::
 
     sb handoff
+    sb map
     sb state
 
 Description
@@ -26,6 +27,24 @@ sb handoff
 This shows information about any handoff information received from SPL. If
 U-Boot is started from an SPL build, it shows a valid magic number.
 
+sb map
+~~~~~~
+
+This shows any mappings between sandbox's emulated RAM and the underlying host
+address-space.
+
+Fields shown are:
+
+Addr
+    Address in emulated RAM
+
+Mapping
+    Equivalent address in the host address-space. While sandbox requests address
+    ``0x10000000`` from the OS, this is not always available.
+
+Refcnt
+    Shows the number of references to this mapping.
+
 sb state
 ~~~~~~~~
 
@@ -42,6 +61,12 @@ as ``sandbox_spl``::
     => sb handoff
     SPL handoff magic 14f93c7b
 
+This shows output from the *sb map* subcommand, with a single mapping::
+
+    Sandbox memory-mapping
+        Addr           Mapping  Refcnt
+    ff000000  000056185b46d6d0       2
+
 This shows output from the *sb state* subcommand::
 
     => sb state
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 06/15] sandbox: Add a way to show the sandbox memory-mapping

Hi Simon

This seems completely unrelated to the series.

Please send it as a separate patch

Thanks
/Ilias

Quoted 140 lines · Simon Glass

This is mostly hidden in the background, but it is sometimes useful to look at it. Add a function to allow this.

---

 arch/sandbox/cpu/cpu.c         | 13 +++++++++++++
 arch/sandbox/include/asm/cpu.h |  3 +++
 cmd/sb.c                       | 11 +++++++++++
 doc/usage/cmd/sb.rst           | 25 +++++++++++++++++++++++++
 4 files changed, 52 insertions(+)
arch/sandbox/cpu/cpu.c +13 -0
index 06f8c13fab9..d1c4dcf0764 100644
@@ -253,6 +253,19 @@ phys_addr_t map_to_sysmem(const void *ptr)
        return mentry->tag;
 }
 
+void sandbox_map_list(void)
+{
+       struct sandbox_mapmem_entry *mentry;
+       struct sandbox_state *state = state_get_current();
+
+       printf("Sandbox memory-mapping\n");
+       printf("%8s  %16s  %6s\n", "Addr", "Mapping", "Refcnt");
+       list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
+               printf("%8lx  %p  %6d\n", mentry->tag, mentry->ptr,
+                      mentry->refcnt);
+       }
+}
+
 unsigned long sandbox_read(const void *addr, enum sandboxio_size_t size)
 {
        struct sandbox_state *state = state_get_current();
arch/sandbox/include/asm/cpu.h +3 -0
index c97ac7ba95b..682bb3376d1 100644
@@ -8,4 +8,7 @@
 
 void cpu_sandbox_set_current(const char *name);
 
+/* show the mapping of sandbox addresses to pointers */
+void sandbox_map_list(void);
+
 #endif /* __SANDBOX_CPU_H */
cmd/sb.c +11 -0
index 9dbb53275b3..9245052492e 100644
@@ -7,6 +7,7 @@
 #include <command.h>
 #include <dm.h>
 #include <spl.h>
+#include <asm/cpu.h>
 #include <asm/global_data.h>
 #include <asm/state.h>
 
@@ -29,6 +30,14 @@ static int do_sb_handoff(struct cmd_tbl *cmdtp, int flag, int argc,
 #endif
 }
 
+static int do_sb_map(struct cmd_tbl *cmdtp, int flag, int argc,
+                    char *const argv[])
+{
+       sandbox_map_list();
+
+       return 0;
+}
+
 static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
                       char *const argv[])
 {
@@ -42,8 +51,10 @@ static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_LONGHELP(sb,
        "handoff     - Show handoff data received from SPL\n"
+       "sb map         - Show mapped memory\n"
        "sb state       - Show sandbox state");
 
 U_BOOT_CMD_WITH_SUBCMDS(sb, "Sandbox status commands", sb_help_text,
        U_BOOT_SUBCMD_MKENT(handoff, 1, 1, do_sb_handoff),
+       U_BOOT_SUBCMD_MKENT(map, 1, 1, do_sb_map),
        U_BOOT_SUBCMD_MKENT(state, 1, 1, do_sb_state));
doc/usage/cmd/sb.rst +25 -1
index 6f54f9d9eb7..37431aff7c8 100644
@@ -12,6 +12,7 @@ Synopsis
 ::
 
     sb handoff
+    sb map
     sb state
 
 Description
@@ -26,6 +27,24 @@ sb handoff
 This shows information about any handoff information received from SPL. If
 U-Boot is started from an SPL build, it shows a valid magic number.
 
+sb map
+~~~~~~
+
+This shows any mappings between sandbox's emulated RAM and the underlying host
+address-space.
+
+Fields shown are:
+
+Addr
+    Address in emulated RAM
+
+Mapping
+    Equivalent address in the host address-space. While sandbox requests address
+    ``0x10000000`` from the OS, this is not always available.
+
+Refcnt
+    Shows the number of references to this mapping.
+
 sb state
 ~~~~~~~~
 
@@ -42,6 +61,12 @@ as ``sandbox_spl``::
     => sb handoff
     SPL handoff magic 14f93c7b
 
+This shows output from the *sb map* subcommand, with a single mapping::
+
+    Sandbox memory-mapping
+        Addr           Mapping  Refcnt
+    ff000000  000056185b46d6d0       2
+
 This shows output from the *sb state* subcommand::
 
     => sb state
--

2.43.0

#9 lore raw

Re: [PATCH 06/15] sandbox: Add a way to show the sandbox memory-mapping

Hi Ilias,

Quoted 6 lines · Ilias Apalodimas

Hi Simon

This seems completely unrelated to the series.

Please send it as a separate patch

I've moved the initial patches in this series to my queue in patchwork, for now.

Regards,
Simon

Quoted 145 lines

Thanks
/Ilias

Quoted 140 lines · Simon Glass

This is mostly hidden in the background, but it is sometimes useful to look at it. Add a function to allow this.

---

 arch/sandbox/cpu/cpu.c         | 13 +++++++++++++
 arch/sandbox/include/asm/cpu.h |  3 +++
 cmd/sb.c                       | 11 +++++++++++
 doc/usage/cmd/sb.rst           | 25 +++++++++++++++++++++++++
 4 files changed, 52 insertions(+)
arch/sandbox/cpu/cpu.c +13 -0
index 06f8c13fab9..d1c4dcf0764 100644
@@ -253,6 +253,19 @@ phys_addr_t map_to_sysmem(const void *ptr)
        return mentry->tag;
 }
 
+void sandbox_map_list(void)
+{
+       struct sandbox_mapmem_entry *mentry;
+       struct sandbox_state *state = state_get_current();
+
+       printf("Sandbox memory-mapping\n");
+       printf("%8s  %16s  %6s\n", "Addr", "Mapping", "Refcnt");
+       list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
+               printf("%8lx  %p  %6d\n", mentry->tag, mentry->ptr,
+                      mentry->refcnt);
+       }
+}
+
 unsigned long sandbox_read(const void *addr, enum sandboxio_size_t size)
 {
        struct sandbox_state *state = state_get_current();
arch/sandbox/include/asm/cpu.h +3 -0
index c97ac7ba95b..682bb3376d1 100644
@@ -8,4 +8,7 @@
 
 void cpu_sandbox_set_current(const char *name);
 
+/* show the mapping of sandbox addresses to pointers */
+void sandbox_map_list(void);
+
 #endif /* __SANDBOX_CPU_H */
cmd/sb.c +11 -0
index 9dbb53275b3..9245052492e 100644
@@ -7,6 +7,7 @@
 #include <command.h>
 #include <dm.h>
 #include <spl.h>
+#include <asm/cpu.h>
 #include <asm/global_data.h>
 #include <asm/state.h>
 
@@ -29,6 +30,14 @@ static int do_sb_handoff(struct cmd_tbl *cmdtp, int flag, int argc,
 #endif
 }
 
+static int do_sb_map(struct cmd_tbl *cmdtp, int flag, int argc,
+                    char *const argv[])
+{
+       sandbox_map_list();
+
+       return 0;
+}
+
 static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
                       char *const argv[])
 {
@@ -42,8 +51,10 @@ static int do_sb_state(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_LONGHELP(sb,
        "handoff     - Show handoff data received from SPL\n"
+       "sb map         - Show mapped memory\n"
        "sb state       - Show sandbox state");
 
 U_BOOT_CMD_WITH_SUBCMDS(sb, "Sandbox status commands", sb_help_text,
        U_BOOT_SUBCMD_MKENT(handoff, 1, 1, do_sb_handoff),
+       U_BOOT_SUBCMD_MKENT(map, 1, 1, do_sb_map),
        U_BOOT_SUBCMD_MKENT(state, 1, 1, do_sb_state));
doc/usage/cmd/sb.rst +25 -1
index 6f54f9d9eb7..37431aff7c8 100644
@@ -12,6 +12,7 @@ Synopsis
 ::
 
     sb handoff
+    sb map
     sb state
 
 Description
@@ -26,6 +27,24 @@ sb handoff
 This shows information about any handoff information received from SPL. If
 U-Boot is started from an SPL build, it shows a valid magic number.
 
+sb map
+~~~~~~
+
+This shows any mappings between sandbox's emulated RAM and the underlying host
+address-space.
+
+Fields shown are:
+
+Addr
+    Address in emulated RAM
+
+Mapping
+    Equivalent address in the host address-space. While sandbox requests address
+    ``0x10000000`` from the OS, this is not always available.
+
+Refcnt
+    Shows the number of references to this mapping.
+
 sb state
 ~~~~~~~~
 
@@ -42,6 +61,12 @@ as ``sandbox_spl``::
     => sb handoff
     SPL handoff magic 14f93c7b
 
+This shows output from the *sb map* subcommand, with a single mapping::
+
+    Sandbox memory-mapping
+        Addr           Mapping  Refcnt
+    ff000000  000056185b46d6d0       2
+
 This shows output from the *sb state* subcommand::
 
     => sb state
--

2.43.0

#10 lore raw

PATCH 7/15 sandbox: Fix comment for nomap_sysmem() function

In reply to Simon Glass

This should say 'cast' rather than 'case', so fix it.

---

 arch/sandbox/include/asm/io.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/include/asm/io.h +1 -1
index a23bd64994a..3d09170063f 100644
@@ -235,7 +235,7 @@ static inline void unmap_sysmem(const void *vaddr)
  * nomap_sysmem() - pass through an address unchanged
  *
  * This is used to indicate an address which should NOT be mapped, e.g. in
- * SMBIOS tables. Using this function instead of a case shows that the sandbox
+ * SMBIOS tables. Using this function instead of a cast shows that the sandbox
  * conversion has been done
  */
 static inline void *nomap_sysmem(phys_addr_t paddr, unsigned long len)
Signature · 1 line
2.43.0
#11 lore raw

PATCH 8/15 lmb: Drop extra 16KB of stack space

In reply to Simon Glass

There is already a defined stack-size which is used to reserve space for the stack. It is confusing to add more in the lmb module, since then the memory map (with meminfo command) seems to have a hole in it.

Drop this unnecessary feature.

---

 lib/lmb.c | 2 --
 1 file changed, 2 deletions(-)
lib/lmb.c +0 -2
index eec99c185ee..9d60865122f 100644
@@ -219,8 +219,6 @@ static void lmb_reserve_uboot_region(void)
 	 */
 	debug("## Current stack ends at 0x%08lx ", (ulong)rsv_start);
 
-	/* adjust sp by 16K to be safe */
-	rsv_start -= SZ_16K;
 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
 		if (!gd->bd->bi_dram[bank].size ||
 		    rsv_start < gd->bd->bi_dram[bank].start)
Signature · 1 line
2.43.0
#12 lore raw

PATCH 9/15 efi_loader: Fix free in ..._media_device_boot_option()

In reply to Simon Glass

Freeing a NULL pointer is an error in EFI, so check the pointer first, before freeing it.

---

 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/efi_bootmgr.c +2 -1
index a3aa2b8d1b9..431a38704e9 100644
@@ -1180,7 +1180,8 @@ out:
 			free(opt[i].lo);
 	}
 	free(opt);
-	efi_free_pool(handles);
+	if (handles)
+		efi_free_pool(handles);
 
 	if (ret == EFI_NOT_FOUND)
 		return EFI_SUCCESS;
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH 09/15] efi_loader: Fix free in ..._media_device_boot_option()

Hi Simon,

Quoted 15 lines · Simon Glass

Freeing a NULL pointer is an error in EFI, so check the pointer first, before freeing it.

---

 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/efi_bootmgr.c +0 -0
index a3aa2b8d1b9..431a38704e9 100644

lib/efi_loader/efi_bootmgr.c out: · line 1184

Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +2 -1
@@ -1180,7 +1180,8 @@ out:
                        free(opt[i].lo);
        }
        free(opt);
-       efi_free_pool(handles);
+       if (handles)
+               efi_free_pool(handles);

We don't need this, efi_free_pool() checks the pointer already.

Thanks
/Ilias

Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +0 -1
        if (ret == EFI_NOT_FOUND)
                return EFI_SUCCESS;
--

2.43.0

#14 lore raw

Re: [PATCH 09/15] efi_loader: Fix free in ..._media_device_boot_option()

Hi Ilias,

Quoted 14 lines · Ilias Apalodimas

Hi Simon,

Quoted 10 lines · Simon Glass

Freeing a NULL pointer is an error in EFI, so check the pointer first, before freeing it.

---

 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

lib/efi_loader/efi_bootmgr.c out: · line 1184

Quoted 11 lines
lib/efi_loader/efi_bootmgr.c +2 -1
index a3aa2b8d1b9..431a38704e9 100644
@@ -1180,7 +1180,8 @@ out:
                        free(opt[i].lo);
        }
        free(opt);
-       efi_free_pool(handles);
+       if (handles)
+               efi_free_pool(handles);

We don't need this, efi_free_pool() checks the pointer already.

Yes, but it then returns an error (EFI_INVALID_PARAMETER), which gets logged, with this series.

Regards,
Simon

#15 lore raw

Re: [PATCH 09/15] efi_loader: Fix free in ..._media_device_boot_option()

Am 29. Oktober 2024 16:45:29 MEZ schrieb Simon Glass <[email protected]>:

Quoted 32 lines

Hi Ilias,

Quoted 14 lines · Ilias Apalodimas

Hi Simon,

Quoted 10 lines · Simon Glass

Freeing a NULL pointer is an error in EFI, so check the pointer first, before freeing it.

---

 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

lib/efi_loader/efi_bootmgr.c out: · line 1184

Quoted 11 lines
lib/efi_loader/efi_bootmgr.c +2 -1
index a3aa2b8d1b9..431a38704e9 100644
@@ -1180,7 +1180,8 @@ out:
                        free(opt[i].lo);
        }
        free(opt);
-       efi_free_pool(handles);
+       if (handles)
+               efi_free_pool(handles);

We don't need this, efi_free_pool() checks the pointer already.

Quoted 2 lines

Yes, but it then returns an error (EFI_INVALID_PARAMETER), which gets logged, with this series.

So this is not a problem of the existing code but of your patch series which creates a superfluous log message.

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

#16 lore raw

Re: [PATCH 09/15] efi_loader: Fix free in ..._media_device_boot_option()

Hi Heinrich,

Quoted 36 lines · Heinrich Schuchardt

Am 29. Oktober 2024 16:45:29 MEZ schrieb Simon Glass <[email protected]>:

Quoted 32 lines

Hi Ilias,

Quoted 27 lines · Ilias Apalodimas

Hi Simon,

Quoted 15 lines · Simon Glass

Freeing a NULL pointer is an error in EFI, so check the pointer first, before freeing it.

---

 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/efi_bootmgr.c +0 -0
index a3aa2b8d1b9..431a38704e9 100644

lib/efi_loader/efi_bootmgr.c out: · line 1184

Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +2 -1
@@ -1180,7 +1180,8 @@ out:
                        free(opt[i].lo);
        }
        free(opt);
-       efi_free_pool(handles);
+       if (handles)
+               efi_free_pool(handles);

We don't need this, efi_free_pool() checks the pointer already.

Quoted 4 lines
Quoted 2 lines

Yes, but it then returns an error (EFI_INVALID_PARAMETER), which gets logged, with this series.

So this is not a problem of the existing code but of your patch series which creates a superfluous log message.

Is it an error to free a zero pointer in EFI?

Regards,
Simon

#17 lore raw

PATCH 10/15 efi_loader: Add support for logging EFI calls

In reply to Simon Glass

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

---

 MAINTAINERS              |   6 +
 include/bloblist.h       |   1 +
 include/efi.h            |   1 +
 include/efi_log.h        | 169 ++++++++++++++++++++++++++
 lib/efi_loader/Kconfig   |  19 +++
 lib/efi_loader/Makefile  |   1 +
 lib/efi_loader/efi_log.c | 256 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 453 insertions(+)
 create mode 100644 include/efi_log.h
 create mode 100644 lib/efi_loader/efi_log.c
MAINTAINERS +6 -0
index 38c714cf46a..9ade0ca4bc3 100644
@@ -1067,6 +1067,12 @@ F:	lib/efi/efi_app.c
 F:	scripts/build-efi.sh
 F:	test/dm/efi_media.c
 
+EFI LOGGING
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	include/efi_log.h
+F:	lib/efi_loader/efi_log.c
+
 EFI PAYLOAD
 M:	Heinrich Schuchardt <[email protected]>
 M:	Ilias Apalodimas <[email protected]>
include/bloblist.h +1 -0
index ff32d3fecfd..1e1ca34aa92 100644
@@ -153,6 +153,7 @@ enum bloblist_tag_t {
 	BLOBLISTT_U_BOOT_SPL_HANDOFF	= 0xfff000, /* Hand-off info from SPL */
 	BLOBLISTT_VBE			= 0xfff001, /* VBE per-phase state */
 	BLOBLISTT_U_BOOT_VIDEO		= 0xfff002, /* Video info from SPL */
+	BLOBLISTT_EFI_LOG		= 0xfff003, /* Log of EFI calls */
 };
 
 /**
include/efi.h +1 -0
index 84640cf7b25..f7419b80d4d 100644
@@ -127,6 +127,7 @@ static inline void *guidcpy(void *dst, const void *src)
 #define EFI_COMPROMISED_DATA		(EFI_ERROR_MASK | 33)
 #define EFI_IP_ADDRESS_CONFLICT		(EFI_ERROR_MASK | 34)
 #define EFI_HTTP_ERROR			(EFI_ERROR_MASK | 35)
+#define EFI_ERROR_COUNT			36
 
 #define EFI_WARN_UNKNOWN_GLYPH		1
 #define EFI_WARN_DELETE_FAILURE		2
include/efi_log.h new file +169 -0

169 lines not on this page · raw message

lib/efi_loader/Kconfig +19 -0
index 69b2c9360d8..37572c82f54 100644
@@ -531,6 +531,25 @@ config EFI_SCROLL_ON_CLEAR_SCREEN
 	  to capture complete boot logs (except for interactive menus etc.)
 	  and can ease debugging related issues.
 
+config EFI_LOG
+	bool "Enable logging of EFI operations"
+	select BLOBLIST
+	help
+	  This enables maintaining a log of EFI boot-time services, useful for
+	  debugging. It keeps track of some of the calls which are made, so far
+	  just those related to memory allocation.
+
+config EFI_LOG_SIZE
+	hex "Size of EFI log"
+	depends on EFI_LOG
+	default 0x4000
+	help
+	   Sets the size of the EFI log in bytes. The log is stored in the
+	   bloblist so if its size is insufficient, U-Boot will raise an error.
+
+	   The amount of space needed depends on the EFI app being run. When
+	   space runes out, further EFI calls will not be logged.
+
 endmenu
 
 menu "EFI bootmanager"
lib/efi_loader/Makefile +1 -0
index 00d18966f9e..8ec240cb864 100644
@@ -38,6 +38,7 @@ obj-y += efi_file.o
 obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o
 obj-y += efi_image_loader.o
 obj-y += efi_load_options.o
+obj-$(CONFIG_EFI_LOG) += efi_log.o
 obj-y += efi_memory.o
 obj-y += efi_root_node.o
 obj-y += efi_runtime.o
lib/efi_loader/efi_log.c new file +256 -0

256 lines not on this page · raw message

Signature · 1 line
2.43.0
#18 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 8 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

We already have log_debug.

We should use it in EFI_ENTRY, EFI_PRINT, EFI_EXIT.

The missing piece might be a log driver to save the log wherever you want it for tests.

Best regards

Heinrich

Quoted 535 lines

---

MAINTAINERS              |   6 +
include/bloblist.h       |   1 +
include/efi.h            |   1 +
include/efi_log.h        | 169 ++++++++++++++++++++++++++
lib/efi_loader/Kconfig   |  19 +++
lib/efi_loader/Makefile  |   1 +
lib/efi_loader/efi_log.c | 256 +++++++++++++++++++++++++++++++++++++++
7 files changed, 453 insertions(+)

create mode 100644 include/efi_log.h
create mode 100644 lib/efi_loader/efi_log.c

MAINTAINERS +0 -0
index 38c714cf46a..9ade0ca4bc3 100644
@@ -1067,6 +1067,12 @@ F:	lib/efi/efi_app.c

F: scripts/build-efi.sh
F: test/dm/efi_media.c

MAINTAINERS +6 -0
+EFI LOGGING
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	include/efi_log.h
+F:	lib/efi_loader/efi_log.c
+

EFI PAYLOAD
M: Heinrich Schuchardt <[email protected]>
M: Ilias Apalodimas <[email protected]>

include/bloblist.h +1 -0
index ff32d3fecfd..1e1ca34aa92 100644
@@ -153,6 +153,7 @@ enum bloblist_tag_t {
 	BLOBLISTT_U_BOOT_SPL_HANDOFF	= 0xfff000, /* Hand-off info from SPL */
 	BLOBLISTT_VBE			= 0xfff001, /* VBE per-phase state */
 	BLOBLISTT_U_BOOT_VIDEO		= 0xfff002, /* Video info from SPL */
+	BLOBLISTT_EFI_LOG		= 0xfff003, /* Log of EFI calls */
 };
 
 /**
include/efi.h +1 -0
index 84640cf7b25..f7419b80d4d 100644
@@ -127,6 +127,7 @@ static inline void *guidcpy(void *dst, const void *src)
 #define EFI_COMPROMISED_DATA		(EFI_ERROR_MASK | 33)
 #define EFI_IP_ADDRESS_CONFLICT		(EFI_ERROR_MASK | 34)
 #define EFI_HTTP_ERROR			(EFI_ERROR_MASK | 35)
+#define EFI_ERROR_COUNT			36
 
 #define EFI_WARN_UNKNOWN_GLYPH		1
 #define EFI_WARN_DELETE_FAILURE		2
include/efi_log.h new file +169 -0
new file mode 100644
index 00000000000..1988e5f9df0
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Logging (to memory) of calls from an EFI app
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __EFI_LOG_H
+#define __EFI_LOG_H
+
+#include <linux/types.h>
+#include <efi.h>
+
+/**
+ * enum efil_tag - Types of logging records which can be created
+ */
+enum efil_tag {
+	EFILT_TESTING,
+
+	EFILT_COUNT,
+};
+
+/**
+ * struct efil_rec_hdr - Header for each logging record
+ *
+ * @tag: Tag which indicates the type of the record
+ * @size: Size of the record in bytes
+ * @ended: true if record has been completed (i.e. the function returned), false
+ *	if it is still pending
+ * @e_ret: Records the return function from the logged function
+ */
+struct efil_rec_hdr {
+	enum efil_tag tag;
+	int size;
+	bool ended;
+	efi_status_t e_ret;
+};
+
+/**
+ * struct efil_hdr - Holds the header for the log
+ *
+ * @upto: Offset at which to store the next log record
+ * @size: Total size of the log in bytes
+ */
+struct efil_hdr {
+	int upto;
+	int size;
+};
+
+enum efil_test_t {
+	EFI_LOG_TEST0,
+	EFI_LOG_TEST1,
+
+	EFI_LOG_TEST_COUNT,
+};
+
+/**
+ * struct efil_testing - used for testing the log
+ */
+struct efil_testing {
+	enum efil_test_t enum_val;
+	efi_uintn_t int_val;
+	u64 *memory;
+	void **buffer;
+	u64 e_memory;
+	void *e_buffer;
+};
+
+/**
+ * struct efil_allocate_pages - holds info from efi_allocate_pages() call
+ *
+ * @e_memory: Contains the value of *@memory on return from the EFI function
+ */
+struct efil_allocate_pages {
+	enum efi_allocate_type type;
+	enum efi_memory_type memory_type;
+	efi_uintn_t pages;
+	u64 *memory;
+	u64 e_memory;
+};
+
+/*
+ * The functions below are in pairs, with a 'start' and 'end' call for each EFI
+ * function. The 'start' function (efi_logs_...) is called when the function is
+ * started. It records all the arguments. The 'end' function (efi_loge_...) is
+ * called when the function is ready to return. It records any output arguments
+ * as well as the return value.
+ *
+ * The start function returns the offset of the log record. This must be passed
+ * to the end function, so it can add the status code and any other useful
+ * information. It is not possible for the end functions to remember the offset
+ * from the associated start function, since EFI functions may be called in a
+ * nested way and there is no obvious way to determine the log record to which
+ * the end function refers.
+ *
+ * If the start function returns an error code (i.e. an offset < 0) then it is
+ * safe to pass that to the end function. It will simply ignore the operation.
+ * Common errors are -ENOENT if there is no log and -ENOSPC if the log is full
+ */
+
+#if CONFIG_IS_ENABLED(EFI_LOG)
+
+/**
+ * efi_logs_testing() - Record a test call to an efi function
+ *
+ * @enum_val:	enum value
+ * @int_val:	integer value
+ * @buffer:	place to write pointer address
+ * @memory:	place to write memory address
+ * Return:	log-offset of this new record, or -ve error code
+ */
+int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_value,
+		     void *buffer, u64 *memory);
+
+/**
+ * efi_loge_testing() - Record a return from a test call
+ *
+ * This stores the value of the pointers also
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_testing(int ofs, efi_status_t efi_ret);
+
+#else /* !EFI_LOG */
+
+static inline int efi_logs_testing(enum efil_test_t enum_val,
+				   efi_uintn_t int_value, void *buffer,
+				   u64 *memory)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_testing(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
+#endif /* EFI_LOG */
+
+/* below are some general functions */
+
+/**
+ * efi_log_show() - Show the EFI log
+ *
+ * Displays the log of EFI boot-services calls which are so-far enabled for
+ * logging
+ *
+ * Return: 0 on success, or -ve error code
+ */
+int efi_log_show(void);
+
+/**
+ * efi_log_reset() - Reset the log, erasing all records
+ *
+ * Return 0 if OK, -ENOENT if the log could not be found
+
+ */
+int efi_log_reset(void);
+
+/**
+ * efi_log_init() - Create a log in the bloblist, then reset it
+ *
+ * Return 0 if OK, -ENOMEM if the bloblist is not large enough
+ */
+int efi_log_init(void);
+
+#endif /* __EFI_LOG_H */
lib/efi_loader/Kconfig +19 -0
index 69b2c9360d8..37572c82f54 100644
@@ -531,6 +531,25 @@ config EFI_SCROLL_ON_CLEAR_SCREEN
 	  to capture complete boot logs (except for interactive menus etc.)
 	  and can ease debugging related issues.
 
+config EFI_LOG
+	bool "Enable logging of EFI operations"
+	select BLOBLIST
+	help
+	  This enables maintaining a log of EFI boot-time services, useful for
+	  debugging. It keeps track of some of the calls which are made, so far
+	  just those related to memory allocation.
+
+config EFI_LOG_SIZE
+	hex "Size of EFI log"
+	depends on EFI_LOG
+	default 0x4000
+	help
+	   Sets the size of the EFI log in bytes. The log is stored in the
+	   bloblist so if its size is insufficient, U-Boot will raise an error.
+
+	   The amount of space needed depends on the EFI app being run. When
+	   space runes out, further EFI calls will not be logged.
+

endmenu

menu "EFI bootmanager"

lib/efi_loader/Makefile +0 -0
index 00d18966f9e..8ec240cb864 100644
@@ -38,6 +38,7 @@ obj-y += efi_file.o

obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o
obj-y += efi_image_loader.o
obj-y += efi_load_options.o
+obj-$(CONFIG_EFI_LOG) += efi_log.o
obj-y += efi_memory.o
obj-y += efi_root_node.o
obj-y += efi_runtime.o

lib/efi_loader/efi_log.c new file +256 -0
new file mode 100644
index 00000000000..01e495d3995
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Logging (to memory) of calls from an EFI app
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+
+#include <bloblist.h>
+#include <efi_log.h>
+#include <errno.h>
+#include <log.h>
+
+/* names for enum efil_tag (abbreviated to keep output to a single line) */
+static const char *tag_name[EFILT_COUNT] = {
+	"testing",
+};
+
+/* names for error codes, trying to keep them short */
+static const char *error_name[EFI_ERROR_COUNT] = {
+	"OK",
+	"load",
+	"inval_param",
+	"unsupported",
+	"bad_buf_sz",
+	"buf_small",
+	"not_ready",
+	"device",
+	"write_prot",
+	"out_of_rsrc",
+	"vol_corrupt",
+	"vol_full",
+	"no_media",
+	"media_chg",
+	"not_found",
+	"no access",
+	"no_response",
+	"no_mapping",
+	"timeout",
+	"not_started",
+	"already",
+	"aborted",
+	"icmp",
+	"tftp",
+	"protocol",
+	"bad version",
+	"sec_violate",
+	"crc_error",
+	"end_media",
+	"end_file",
+	"inval_lang",
+	"compromised",
+	"ipaddr_busy",
+	"http",
+};
+
+static const char *test_enum_name[EFI_LOG_TEST_COUNT] = {
+	"test0",
+	"test1",
+};
+
+/**
+ * prep_rec() - prepare a new record in the log
+ *
+ * This creates a new record at the next available position, setting it up ready
+ * to hold data. The size and tag are set up.
+ *
+ * The log is updated so that the next record will start after this one
+ *
+ * @tag: tag of the EFI call to record
+ * @size: Number of bytes in the caller's struct
+ * @recp: Set to point to where the caller should add its data
+ * Return: Offset of this record (must be passed to finish_rec())
+ */
+static int prep_rec(enum efil_tag tag, uint str_size, void **recp)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+	int ofs, size;
+
+	if (!hdr)
+		return -ENOENT;
+	size = str_size + sizeof(struct efil_rec_hdr);
+	if (hdr->upto + size > hdr->size)
+		return -ENOSPC;
+
+	rec_hdr = (void *)hdr + hdr->upto;
+	rec_hdr->size = size;
+	rec_hdr->tag = tag;
+	rec_hdr->ended = false;
+	*recp = rec_hdr + 1;
+
+	ofs = hdr->upto;
+	hdr->upto += size;
+
+	return ofs;
+}
+
+/**
+ * finish_rec() - Finish a previously started record
+ *
+ * @ofs: Offset of record to finish
+ * @ret: Return code which is to be returned from the EFI function
+ * Return: Pointer to the structure where the caller should add its data
+ */
+static void *finish_rec(int ofs, efi_status_t ret)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+
+	if (!hdr || ofs < 0)
+		return NULL;
+	rec_hdr = (void *)hdr + ofs;
+	rec_hdr->ended = true;
+	rec_hdr->e_ret = ret;
+
+	return rec_hdr + 1;
+}
+
+int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_val,
+		     void *buffer, u64 *memory)
+{
+	struct efil_testing *rec;
+	int ret;
+
+	ret = prep_rec(EFILT_TESTING, sizeof(*rec), (void **)&rec);
+	if (ret < 0)
+		return ret;
+
+	rec->int_val = int_val;
+	rec->buffer = buffer;
+	rec->memory = memory;
+	rec->e_buffer = NULL;
+	rec->e_memory = 0;
+
+	return ret;
+}
+
+int efi_loge_testing(int ofs, efi_status_t efi_ret)
+{
+	struct efil_testing *rec;
+
+	rec = finish_rec(ofs, efi_ret);
+	if (!rec)
+		return -ENOSPC;
+	rec->e_memory = *rec->memory;
+	rec->e_buffer = *rec->buffer;
+
+	return 0;
+}
+
+static void show_enum(const char *type_name[], int type)
+{
+	printf("%s ", type_name[type]);
+}
+
+static void show_ulong(const char *prompt, ulong val)
+{
+	printf("%s %lx", prompt, val);
+	if (val >= 10)
+		printf("/%ld", val);
+	printf(" ");
+}
+
+static void show_addr(const char *prompt, ulong addr)
+{
+	printf("%s %lx ", prompt, addr);
+}
+
+static void show_ret(efi_status_t ret)
+{
+	int code;
+
+	code = ret & ~EFI_ERROR_MASK;
+	if (code < ARRAY_SIZE(error_name))
+		printf("ret %s", error_name[ret]);
+	else
+		printf("ret %lx", ret);
+}
+
+void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
+{
+	void *start = (void *)rec_hdr + sizeof(struct efil_rec_hdr);
+
+	printf("%3d %12s ", seq, tag_name[rec_hdr->tag]);
+	switch (rec_hdr->tag) {
+	case EFILT_TESTING: {
+		struct efil_testing *rec = start;
+
+		show_enum(test_enum_name, (int)rec->enum_val);
+		show_ulong("int", (ulong)rec->int_val);
+		show_addr("buf", map_to_sysmem(rec->buffer));
+		show_addr("mem", map_to_sysmem(rec->memory));
+		if (rec_hdr->ended) {
+			show_addr("*buf",
+				  (ulong)map_to_sysmem((void *)rec->e_buffer));
+			show_addr("*mem",
+				  (ulong)rec->e_memory);
+			show_ret(rec_hdr->e_ret);
+		}
+	}
+	case EFILT_COUNT:
+		break;
+	}
+	printf("\n");
+}
+
+int efi_log_show(void)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+	int i;
+
+	printf("EFI log (size %x)\n", hdr->upto);
+	if (!hdr)
+		return -ENOENT;
+	for (i = 0, rec_hdr = (void *)hdr + sizeof(*hdr);
+	     (void *)rec_hdr - (void *)hdr < hdr->upto;
+	     i++, rec_hdr = (void *)rec_hdr + rec_hdr->size)
+		show_rec(i, rec_hdr);
+	printf("%d records\n", i);
+
+	return 0;
+}
+
+int efi_log_reset(void)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+
+	if (!hdr)
+		return -ENOENT;
+	hdr->upto = sizeof(struct efil_hdr);
+	hdr->size = CONFIG_EFI_LOG_SIZE;
+
+	return 0;
+}
+
+int efi_log_init(void)
+{
+	struct efil_hdr *hdr;
+
+	hdr = bloblist_add(BLOBLISTT_EFI_LOG, CONFIG_EFI_LOG_SIZE, 0);
+	if (!hdr) {
+		/*
+		 * Return -ENOMEM since we use -ENOSPC to mean that the log is
+		 * full
+		 */
+		log_warning("Failed to setup EFI log\n");
+		return log_msg_ret("eli", -ENOMEM);
+	}
+	efi_log_reset();
+
+	return 0;
+}
#19 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

In reply to Simon Glass

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 8 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

An EFI specific solution is not a good approach as it does not scale to other parts of the code. Please, implement a log driver to collect the messages that you are interested in.

Best regards

Heinrich

Quoted 535 lines

---

MAINTAINERS              |   6 +
include/bloblist.h       |   1 +
include/efi.h            |   1 +
include/efi_log.h        | 169 ++++++++++++++++++++++++++
lib/efi_loader/Kconfig   |  19 +++
lib/efi_loader/Makefile  |   1 +
lib/efi_loader/efi_log.c | 256 +++++++++++++++++++++++++++++++++++++++
7 files changed, 453 insertions(+)

create mode 100644 include/efi_log.h
create mode 100644 lib/efi_loader/efi_log.c

MAINTAINERS +0 -0
index 38c714cf46a..9ade0ca4bc3 100644
@@ -1067,6 +1067,12 @@ F:	lib/efi/efi_app.c

F: scripts/build-efi.sh
F: test/dm/efi_media.c

MAINTAINERS +6 -0
+EFI LOGGING
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	include/efi_log.h
+F:	lib/efi_loader/efi_log.c
+

EFI PAYLOAD
M: Heinrich Schuchardt <[email protected]>
M: Ilias Apalodimas <[email protected]>

include/bloblist.h +1 -0
index ff32d3fecfd..1e1ca34aa92 100644
@@ -153,6 +153,7 @@ enum bloblist_tag_t {
 	BLOBLISTT_U_BOOT_SPL_HANDOFF	= 0xfff000, /* Hand-off info from SPL */
 	BLOBLISTT_VBE			= 0xfff001, /* VBE per-phase state */
 	BLOBLISTT_U_BOOT_VIDEO		= 0xfff002, /* Video info from SPL */
+	BLOBLISTT_EFI_LOG		= 0xfff003, /* Log of EFI calls */
 };
 
 /**
include/efi.h +1 -0
index 84640cf7b25..f7419b80d4d 100644
@@ -127,6 +127,7 @@ static inline void *guidcpy(void *dst, const void *src)
 #define EFI_COMPROMISED_DATA		(EFI_ERROR_MASK | 33)
 #define EFI_IP_ADDRESS_CONFLICT		(EFI_ERROR_MASK | 34)
 #define EFI_HTTP_ERROR			(EFI_ERROR_MASK | 35)
+#define EFI_ERROR_COUNT			36
 
 #define EFI_WARN_UNKNOWN_GLYPH		1
 #define EFI_WARN_DELETE_FAILURE		2
include/efi_log.h new file +169 -0
new file mode 100644
index 00000000000..1988e5f9df0
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Logging (to memory) of calls from an EFI app
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __EFI_LOG_H
+#define __EFI_LOG_H
+
+#include <linux/types.h>
+#include <efi.h>
+
+/**
+ * enum efil_tag - Types of logging records which can be created
+ */
+enum efil_tag {
+	EFILT_TESTING,
+
+	EFILT_COUNT,
+};
+
+/**
+ * struct efil_rec_hdr - Header for each logging record
+ *
+ * @tag: Tag which indicates the type of the record
+ * @size: Size of the record in bytes
+ * @ended: true if record has been completed (i.e. the function returned), false
+ *	if it is still pending
+ * @e_ret: Records the return function from the logged function
+ */
+struct efil_rec_hdr {
+	enum efil_tag tag;
+	int size;
+	bool ended;
+	efi_status_t e_ret;
+};
+
+/**
+ * struct efil_hdr - Holds the header for the log
+ *
+ * @upto: Offset at which to store the next log record
+ * @size: Total size of the log in bytes
+ */
+struct efil_hdr {
+	int upto;
+	int size;
+};
+
+enum efil_test_t {
+	EFI_LOG_TEST0,
+	EFI_LOG_TEST1,
+
+	EFI_LOG_TEST_COUNT,
+};
+
+/**
+ * struct efil_testing - used for testing the log
+ */
+struct efil_testing {
+	enum efil_test_t enum_val;
+	efi_uintn_t int_val;
+	u64 *memory;
+	void **buffer;
+	u64 e_memory;
+	void *e_buffer;
+};
+
+/**
+ * struct efil_allocate_pages - holds info from efi_allocate_pages() call
+ *
+ * @e_memory: Contains the value of *@memory on return from the EFI function
+ */
+struct efil_allocate_pages {
+	enum efi_allocate_type type;
+	enum efi_memory_type memory_type;
+	efi_uintn_t pages;
+	u64 *memory;
+	u64 e_memory;
+};
+
+/*
+ * The functions below are in pairs, with a 'start' and 'end' call for each EFI
+ * function. The 'start' function (efi_logs_...) is called when the function is
+ * started. It records all the arguments. The 'end' function (efi_loge_...) is
+ * called when the function is ready to return. It records any output arguments
+ * as well as the return value.
+ *
+ * The start function returns the offset of the log record. This must be passed
+ * to the end function, so it can add the status code and any other useful
+ * information. It is not possible for the end functions to remember the offset
+ * from the associated start function, since EFI functions may be called in a
+ * nested way and there is no obvious way to determine the log record to which
+ * the end function refers.
+ *
+ * If the start function returns an error code (i.e. an offset < 0) then it is
+ * safe to pass that to the end function. It will simply ignore the operation.
+ * Common errors are -ENOENT if there is no log and -ENOSPC if the log is full
+ */
+
+#if CONFIG_IS_ENABLED(EFI_LOG)
+
+/**
+ * efi_logs_testing() - Record a test call to an efi function
+ *
+ * @enum_val:	enum value
+ * @int_val:	integer value
+ * @buffer:	place to write pointer address
+ * @memory:	place to write memory address
+ * Return:	log-offset of this new record, or -ve error code
+ */
+int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_value,
+		     void *buffer, u64 *memory);
+
+/**
+ * efi_loge_testing() - Record a return from a test call
+ *
+ * This stores the value of the pointers also
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_testing(int ofs, efi_status_t efi_ret);
+
+#else /* !EFI_LOG */
+
+static inline int efi_logs_testing(enum efil_test_t enum_val,
+				   efi_uintn_t int_value, void *buffer,
+				   u64 *memory)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_testing(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
+#endif /* EFI_LOG */
+
+/* below are some general functions */
+
+/**
+ * efi_log_show() - Show the EFI log
+ *
+ * Displays the log of EFI boot-services calls which are so-far enabled for
+ * logging
+ *
+ * Return: 0 on success, or -ve error code
+ */
+int efi_log_show(void);
+
+/**
+ * efi_log_reset() - Reset the log, erasing all records
+ *
+ * Return 0 if OK, -ENOENT if the log could not be found
+
+ */
+int efi_log_reset(void);
+
+/**
+ * efi_log_init() - Create a log in the bloblist, then reset it
+ *
+ * Return 0 if OK, -ENOMEM if the bloblist is not large enough
+ */
+int efi_log_init(void);
+
+#endif /* __EFI_LOG_H */
lib/efi_loader/Kconfig +19 -0
index 69b2c9360d8..37572c82f54 100644
@@ -531,6 +531,25 @@ config EFI_SCROLL_ON_CLEAR_SCREEN
 	  to capture complete boot logs (except for interactive menus etc.)
 	  and can ease debugging related issues.
 
+config EFI_LOG
+	bool "Enable logging of EFI operations"
+	select BLOBLIST
+	help
+	  This enables maintaining a log of EFI boot-time services, useful for
+	  debugging. It keeps track of some of the calls which are made, so far
+	  just those related to memory allocation.
+
+config EFI_LOG_SIZE
+	hex "Size of EFI log"
+	depends on EFI_LOG
+	default 0x4000
+	help
+	   Sets the size of the EFI log in bytes. The log is stored in the
+	   bloblist so if its size is insufficient, U-Boot will raise an error.
+
+	   The amount of space needed depends on the EFI app being run. When
+	   space runes out, further EFI calls will not be logged.
+

endmenu

menu "EFI bootmanager"

lib/efi_loader/Makefile +0 -0
index 00d18966f9e..8ec240cb864 100644
@@ -38,6 +38,7 @@ obj-y += efi_file.o

obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o
obj-y += efi_image_loader.o
obj-y += efi_load_options.o
+obj-$(CONFIG_EFI_LOG) += efi_log.o
obj-y += efi_memory.o
obj-y += efi_root_node.o
obj-y += efi_runtime.o

lib/efi_loader/efi_log.c new file +256 -0
new file mode 100644
index 00000000000..01e495d3995
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Logging (to memory) of calls from an EFI app
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+
+#include <bloblist.h>
+#include <efi_log.h>
+#include <errno.h>
+#include <log.h>
+
+/* names for enum efil_tag (abbreviated to keep output to a single line) */
+static const char *tag_name[EFILT_COUNT] = {
+	"testing",
+};
+
+/* names for error codes, trying to keep them short */
+static const char *error_name[EFI_ERROR_COUNT] = {
+	"OK",
+	"load",
+	"inval_param",
+	"unsupported",
+	"bad_buf_sz",
+	"buf_small",
+	"not_ready",
+	"device",
+	"write_prot",
+	"out_of_rsrc",
+	"vol_corrupt",
+	"vol_full",
+	"no_media",
+	"media_chg",
+	"not_found",
+	"no access",
+	"no_response",
+	"no_mapping",
+	"timeout",
+	"not_started",
+	"already",
+	"aborted",
+	"icmp",
+	"tftp",
+	"protocol",
+	"bad version",
+	"sec_violate",
+	"crc_error",
+	"end_media",
+	"end_file",
+	"inval_lang",
+	"compromised",
+	"ipaddr_busy",
+	"http",
+};
+
+static const char *test_enum_name[EFI_LOG_TEST_COUNT] = {
+	"test0",
+	"test1",
+};
+
+/**
+ * prep_rec() - prepare a new record in the log
+ *
+ * This creates a new record at the next available position, setting it up ready
+ * to hold data. The size and tag are set up.
+ *
+ * The log is updated so that the next record will start after this one
+ *
+ * @tag: tag of the EFI call to record
+ * @size: Number of bytes in the caller's struct
+ * @recp: Set to point to where the caller should add its data
+ * Return: Offset of this record (must be passed to finish_rec())
+ */
+static int prep_rec(enum efil_tag tag, uint str_size, void **recp)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+	int ofs, size;
+
+	if (!hdr)
+		return -ENOENT;
+	size = str_size + sizeof(struct efil_rec_hdr);
+	if (hdr->upto + size > hdr->size)
+		return -ENOSPC;
+
+	rec_hdr = (void *)hdr + hdr->upto;
+	rec_hdr->size = size;
+	rec_hdr->tag = tag;
+	rec_hdr->ended = false;
+	*recp = rec_hdr + 1;
+
+	ofs = hdr->upto;
+	hdr->upto += size;
+
+	return ofs;
+}
+
+/**
+ * finish_rec() - Finish a previously started record
+ *
+ * @ofs: Offset of record to finish
+ * @ret: Return code which is to be returned from the EFI function
+ * Return: Pointer to the structure where the caller should add its data
+ */
+static void *finish_rec(int ofs, efi_status_t ret)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+
+	if (!hdr || ofs < 0)
+		return NULL;
+	rec_hdr = (void *)hdr + ofs;
+	rec_hdr->ended = true;
+	rec_hdr->e_ret = ret;
+
+	return rec_hdr + 1;
+}
+
+int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_val,
+		     void *buffer, u64 *memory)
+{
+	struct efil_testing *rec;
+	int ret;
+
+	ret = prep_rec(EFILT_TESTING, sizeof(*rec), (void **)&rec);
+	if (ret < 0)
+		return ret;
+
+	rec->int_val = int_val;
+	rec->buffer = buffer;
+	rec->memory = memory;
+	rec->e_buffer = NULL;
+	rec->e_memory = 0;
+
+	return ret;
+}
+
+int efi_loge_testing(int ofs, efi_status_t efi_ret)
+{
+	struct efil_testing *rec;
+
+	rec = finish_rec(ofs, efi_ret);
+	if (!rec)
+		return -ENOSPC;
+	rec->e_memory = *rec->memory;
+	rec->e_buffer = *rec->buffer;
+
+	return 0;
+}
+
+static void show_enum(const char *type_name[], int type)
+{
+	printf("%s ", type_name[type]);
+}
+
+static void show_ulong(const char *prompt, ulong val)
+{
+	printf("%s %lx", prompt, val);
+	if (val >= 10)
+		printf("/%ld", val);
+	printf(" ");
+}
+
+static void show_addr(const char *prompt, ulong addr)
+{
+	printf("%s %lx ", prompt, addr);
+}
+
+static void show_ret(efi_status_t ret)
+{
+	int code;
+
+	code = ret & ~EFI_ERROR_MASK;
+	if (code < ARRAY_SIZE(error_name))
+		printf("ret %s", error_name[ret]);
+	else
+		printf("ret %lx", ret);
+}
+
+void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
+{
+	void *start = (void *)rec_hdr + sizeof(struct efil_rec_hdr);
+
+	printf("%3d %12s ", seq, tag_name[rec_hdr->tag]);
+	switch (rec_hdr->tag) {
+	case EFILT_TESTING: {
+		struct efil_testing *rec = start;
+
+		show_enum(test_enum_name, (int)rec->enum_val);
+		show_ulong("int", (ulong)rec->int_val);
+		show_addr("buf", map_to_sysmem(rec->buffer));
+		show_addr("mem", map_to_sysmem(rec->memory));
+		if (rec_hdr->ended) {
+			show_addr("*buf",
+				  (ulong)map_to_sysmem((void *)rec->e_buffer));
+			show_addr("*mem",
+				  (ulong)rec->e_memory);
+			show_ret(rec_hdr->e_ret);
+		}
+	}
+	case EFILT_COUNT:
+		break;
+	}
+	printf("\n");
+}
+
+int efi_log_show(void)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+	struct efil_rec_hdr *rec_hdr;
+	int i;
+
+	printf("EFI log (size %x)\n", hdr->upto);
+	if (!hdr)
+		return -ENOENT;
+	for (i = 0, rec_hdr = (void *)hdr + sizeof(*hdr);
+	     (void *)rec_hdr - (void *)hdr < hdr->upto;
+	     i++, rec_hdr = (void *)rec_hdr + rec_hdr->size)
+		show_rec(i, rec_hdr);
+	printf("%d records\n", i);
+
+	return 0;
+}
+
+int efi_log_reset(void)
+{
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
+
+	if (!hdr)
+		return -ENOENT;
+	hdr->upto = sizeof(struct efil_hdr);
+	hdr->size = CONFIG_EFI_LOG_SIZE;
+
+	return 0;
+}
+
+int efi_log_init(void)
+{
+	struct efil_hdr *hdr;
+
+	hdr = bloblist_add(BLOBLISTT_EFI_LOG, CONFIG_EFI_LOG_SIZE, 0);
+	if (!hdr) {
+		/*
+		 * Return -ENOMEM since we use -ENOSPC to mean that the log is
+		 * full
+		 */
+		log_warning("Failed to setup EFI log\n");
+		return log_msg_ret("eli", -ENOMEM);
+	}
+	efi_log_reset();
+
+	return 0;
+}
#20 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

Hi Heinrich,

Quoted 7 lines · Heinrich Schuchardt

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 3 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Quoted 8 lines
Quoted 5 lines

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

An EFI specific solution is not a good approach as it does not scale to other parts of the code. Please, implement a log driver to collect the messages that you are interested in.

I can do that too, but it isn't as easy to programmatically parse. I'd like to track what calls are made and understand better what is going on when Ubuntu boots, etc.

Regards,
Simon

#21 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

Am 31. Oktober 2024 19:01:47 MEZ schrieb Simon Glass <[email protected]>:

Quoted 16 lines

Hi Heinrich,

Quoted 13 lines · Heinrich Schuchardt

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 8 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

Quoted 6 lines
Quoted 2 lines

An EFI specific solution is not a good approach as it does not scale to other parts of the code. Please, implement a log driver to collect the messages that you are interested in.

I can do that too, but it isn't as easy to programmatically parse. I'd like to track what calls are made and understand better what is going on when Ubuntu boots, etc.

What makes calls to log_debug hard to parse? We have __FILE__, __LINE__, __func__, and message text available as individual fields.

What information are you missing?

For tracking function calls we already have a trace capability in U-Boot.

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

#22 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

Quoted 26 lines · Heinrich Schuchardt

Am 31. Oktober 2024 19:01:47 MEZ schrieb Simon Glass <[email protected]>:

Quoted 16 lines

Hi Heinrich,

Quoted 13 lines · Heinrich Schuchardt

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 8 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

Quoted 6 lines
Quoted 2 lines

An EFI specific solution is not a good approach as it does not scale to other parts of the code. Please, implement a log driver to collect the messages that you are interested in.

I can do that too, but it isn't as easy to programmatically parse. I'd like to track what calls are made and understand better what is going on when Ubuntu boots, etc.

Quoted 5 lines

What makes calls to log_debug hard to parse? We have __FILE__, __LINE__, __func__, and message text available as individual fields.

What information are you missing?

For tracking function calls we already have a trace capability in U-Boot.

Integrating EFI_LOADER with existing U-Boot logging / tracing infrastructure sounds like a reasonable path forward to me.

Signature · 1 line
Tom
#23 lore raw

Re: [PATCH 10/15] efi_loader: Add support for logging EFI calls

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 26 lines · Heinrich Schuchardt

Am 31. Oktober 2024 19:01:47 MEZ schrieb Simon Glass <[email protected]>:

Quoted 22 lines

Hi Heinrich,

Quoted 7 lines · Heinrich Schuchardt

Am 28. Oktober 2024 13:48:01 MEZ schrieb Simon Glass <[email protected]>:

Quoted 3 lines

The current logging system suffers from some disadvantages, mainly that it writes its output to the console and cannot be easily reviewed.

Quoted 8 lines
Quoted 5 lines

Add a dedicated log, storing records in a binary format and including the result codes and any return values from each call. The log is built sequentially in memory and can be reviewed after any EFI operation. It could potentially be written to media for later review, but that is not implemented so far.

An EFI specific solution is not a good approach as it does not scale to other parts of the code. Please, implement a log driver to collect the messages that you are interested in.

I can do that too, but it isn't as easy to programmatically parse. I'd like to track what calls are made and understand better what is going on when Ubuntu boots, etc.

Quoted 8 lines
Quoted 5 lines

What makes calls to log_debug hard to parse? We have __FILE__, __LINE__, __func__, and message text available as individual fields.

What information are you missing?

For tracking function calls we already have a trace capability in U-Boot.

Integrating EFI_LOADER with existing U-Boot logging / tracing infrastructure sounds like a reasonable path forward to me.

Yes, we already have that. I replied to Ilias' response elsewhere.

Regards,
Simon

#24 lore raw

PATCH 11/15 efi_loader: Create the log on startup

In reply to Simon Glass

Create an EFI log when the EFI subsystem is first touched. This happens after relocation in board_init_f()

---

 lib/efi_loader/efi_setup.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/efi_loader/efi_setup.c +7 -0
index aa59bc7779d..468156db813 100644
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY LOGC_EFI
 
 #include <efi_loader.h>
+#include <efi_log.h>
 #include <efi_variable.h>
 #include <log.h>
 #include <asm-generic/unaligned.h>
@@ -186,6 +187,12 @@ int efi_init_early(void)
 	/* Allow unaligned memory access */
 	allow_unaligned();
 
+	if (IS_ENABLED(CONFIG_EFI_LOG)) {
+		ret = efi_log_init();
+		if (ret)
+			return -ENOSPC;
+	}
+
 	/* Initialize root node */
 	ret = efi_root_node_register();
 	if (ret != EFI_SUCCESS)
Signature · 1 line
2.43.0
#25 lore raw

PATCH 12/15 efi_loader: Add a command to show the EFI log

In reply to Simon Glass

Add a simple command which lists the log. Avoid creating any new records when this command is invoked.

---

 cmd/efidebug.c             |  53 +++++++++++++++---
 doc/usage/cmd/efidebug.rst | 109 +++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst        |   1 +
 3 files changed, 155 insertions(+), 8 deletions(-)
 create mode 100644 doc/usage/cmd/efidebug.rst
cmd/efidebug.c +45 -8
index e040fe75fa1..bba984b2b75 100644
@@ -10,6 +10,7 @@
 #include <dm/device.h>
 #include <efi_dt_fixup.h>
 #include <efi_load_initrd.h>
+#include <efi_log.h>
 #include <efi_loader.h>
 #include <efi_rng.h>
 #include <efi_variable.h>
@@ -511,6 +512,33 @@ static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag,
 	return CMD_RET_SUCCESS;
 }
 
+/**
+ * do_efi_show_log() - show UEFI log of boot-services calls
+ *
+ * @cmdtp:	Command table
+ * @flag:	Command flag
+ * @argc:	Number of arguments
+ * @argv:	Argument array
+ * Return:	CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "log" sub-command.
+ * Show UEFI log records.
+ */
+static int do_efi_show_log(struct cmd_tbl *cmdtp, int flag,
+			   int argc, char *const argv[])
+{
+	if (!IS_ENABLED(CONFIG_EFI_LOG)) {
+		printf("Please enable CONFIG_EFI_LOG to use the log\n");
+		return CMD_RET_FAILURE;
+	}
+	if (efi_log_show()) {
+		printf("Failed\n");
+		return CMD_RET_FAILURE;
+	}
+
+	return CMD_RET_SUCCESS;
+}
+
 static const char * const efi_mem_type_string[] = {
 	[EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
 	[EFI_LOADER_CODE] = "LOADER CODE",
@@ -1563,6 +1591,7 @@ static struct cmd_tbl cmd_efidebug_sub[] = {
 			 "", ""),
 	U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
 			 "", ""),
+	U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_efi_show_log, "", ""),
 	U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
 			 "", ""),
 	U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables,
@@ -1597,19 +1626,25 @@ static int do_efidebug(struct cmd_tbl *cmdtp, int flag,
 
 	argc--; argv++;
 
-	/* Initialize UEFI drivers */
-	r = efi_init_obj_list();
-	if (r != EFI_SUCCESS) {
-		printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
-		       r & ~EFI_ERROR_MASK);
-		return CMD_RET_FAILURE;
-	}
-
 	cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
 			  ARRAY_SIZE(cmd_efidebug_sub));
 	if (!cp)
 		return CMD_RET_USAGE;
 
+	/*
+	 * Calling efi_init_obj_list() can add log records, so avoid it if just
+	 * showing the log
+	 */
+	if (cp->cmd != do_efi_show_log) {
+		/* Initialize UEFI drivers */
+		r = efi_init_obj_list();
+		if (r != EFI_SUCCESS) {
+			printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
+			       r & ~EFI_ERROR_MASK);
+			return CMD_RET_FAILURE;
+		}
+	}
+
 	return cp->cmd(cmdtp, flag, argc, argv);
 }
 
@@ -1655,6 +1690,8 @@ U_BOOT_LONGHELP(efidebug,
 	"  - show UEFI handles\n"
 	"efidebug images\n"
 	"  - show loaded images\n"
+	"efidebug log\n"
+	"  - show UEFI log\n"
 	"efidebug memmap\n"
 	"  - show UEFI memory map\n"
 	"efidebug tables\n"
doc/usage/cmd/efidebug.rst new file +109 -0

109 lines not on this page · raw message

doc/usage/index.rst +1 -0
index 24b2d2637b1..a2340d9a7e0 100644
@@ -59,6 +59,7 @@ Shell commands
    cmd/echo
    cmd/efi
    cmd/eficonfig
+   cmd/efidebug
    cmd/env
    cmd/event
    cmd/exception
Signature · 1 line
2.43.0
#26 lore raw

PATCH 13/15 test: efi_loader: Add a simple test for the EFI log

In reply to Simon Glass

Create a test which does some sample calls and checks the output.

Expand the size of the sandbox bloblist to accommodate the log.

---

 MAINTAINERS               |  1 +
 configs/sandbox_defconfig |  3 +++
 lib/efi_loader/efi_log.c  |  7 +++---
 test/lib/Makefile         |  1 +
 test/lib/efi_log.c        | 49 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 57 insertions(+), 4 deletions(-)
 create mode 100644 test/lib/efi_log.c
MAINTAINERS +1 -0
index 9ade0ca4bc3..3e571174ad5 100644
@@ -1072,6 +1072,7 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	include/efi_log.h
 F:	lib/efi_loader/efi_log.c
+F:	test/lib/efi_log.c
 
 EFI PAYLOAD
 M:	Heinrich Schuchardt <[email protected]>
configs/sandbox_defconfig +3 -0
index d111858082d..afba6c78e28 100644
@@ -17,6 +17,7 @@ CONFIG_EFI_CAPSULE_ON_DISK=y
 CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
 CONFIG_EFI_CAPSULE_AUTHENTICATE=y
 CONFIG_EFI_CAPSULE_CRT_FILE="board/sandbox/capsule_pub_key_good.crt"
+CONFIG_EFI_LOG=y
 CONFIG_BUTTON_CMD=y
 CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
@@ -50,6 +51,7 @@ CONFIG_LOG_DEFAULT_LEVEL=6
 CONFIG_LOGF_FUNC=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_STACKPROTECTOR=y
+CONFIG_BLOBLIST_SIZE_RELOC=0x5000
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_SMBIOS=y
@@ -72,6 +74,7 @@ CONFIG_CMD_NVEDIT_SELECT=y
 CONFIG_LOOPW=y
 CONFIG_CMD_MD5SUM=y
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_MEM_SEARCH=y
 CONFIG_CMD_MX_CYCLIC=y
 CONFIG_CMD_MEMTEST=y
lib/efi_loader/efi_log.c +3 -4
index 01e495d3995..780860d8b2f 100644
@@ -129,6 +129,7 @@ int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_val,
 	if (ret < 0)
 		return ret;
 
+	rec->enum_val = enum_val;
 	rec->int_val = int_val;
 	rec->buffer = buffer;
 	rec->memory = memory;
@@ -194,10 +195,8 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
 		show_addr("buf", map_to_sysmem(rec->buffer));
 		show_addr("mem", map_to_sysmem(rec->memory));
 		if (rec_hdr->ended) {
-			show_addr("*buf",
-				  (ulong)map_to_sysmem((void *)rec->e_buffer));
-			show_addr("*mem",
-				  (ulong)rec->e_memory);
+			show_addr("*buf", (ulong)map_to_sysmem(rec->e_buffer));
+			show_addr("*mem", (ulong)rec->e_memory);
 			show_ret(rec_hdr->e_ret);
 		}
 	}
test/lib/Makefile +1 -0
index 217c3baf881..050eaef4bb9 100644
@@ -11,6 +11,7 @@ obj-y += abuf.o
 obj-y += alist.o
 obj-$(CONFIG_EFI_LOADER) += efi_device_path.o
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
+obj-$(CONFIG_EFI_LOG) += efi_log.o
 obj-y += hexdump.o
 obj-$(CONFIG_SANDBOX) += kconfig.o
 obj-y += lmb.o
test/lib/efi_log.c new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.43.0
#27 lore raw

PATCH 14/15 efi_loader: Use the log with memory-related functions

In reply to Simon Glass

Update a few memory functions to log their inputs and outputs. To avoid the use of 'goto', etc. the functions are turned into stubs, calling a separate function to do the actual operation.

Add a few tests.

---

 include/efi_log.h           | 147 ++++++++++++++++++++++++++++
 lib/efi_loader/efi_log.c    | 189 ++++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c | 119 ++++++++++++++++-------
 test/lib/efi_log.c          |  44 +++++++++
 4 files changed, 466 insertions(+), 33 deletions(-)
include/efi_log.h +147 -0
index 1988e5f9df0..a4b707e57c5 100644
@@ -16,6 +16,11 @@
  * enum efil_tag - Types of logging records which can be created
  */
 enum efil_tag {
+	EFILT_ALLOCATE_PAGES,
+	EFILT_FREE_PAGES,
+	EFILT_ALLOCATE_POOL,
+	EFILT_FREE_POOL,
+
 	EFILT_TESTING,
 
 	EFILT_COUNT,
@@ -80,6 +85,28 @@ struct efil_allocate_pages {
 	u64 e_memory;
 };
 
+/** struct efil_free_pages - holds info from efi_free_pages() call */
+struct efil_free_pages {
+	u64 memory;
+	efi_uintn_t pages;
+};
+
+/** struct efil_allocate_pool - holds info from efi_allocate_pool() call
+ *
+ * @e_buffer: Contains the value of *@buffer on return from the EFI function
+ */
+struct efil_allocate_pool {
+	enum efi_memory_type pool_type;
+	efi_uintn_t size;
+	void **buffer;
+	void *e_buffer;
+};
+
+/** struct efil_free_pool - holds log-info from efi_free_pool() call */
+struct efil_free_pool {
+	void *buffer;
+};
+
 /*
  * The functions below are in pairs, with a 'start' and 'end' call for each EFI
  * function. The 'start' function (efi_logs_...) is called when the function is
@@ -123,8 +150,128 @@ int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_value,
  */
 int efi_loge_testing(int ofs, efi_status_t efi_ret);
 
+/**
+ * efi_logs_allocate_pages() - Record a call to efi_allocate_pages()
+ *
+ * @type:		type of allocation to be performed
+ * @memory_type:	usage type of the allocated memory
+ * @pages:		number of pages to be allocated
+ * @memory:		place to write address of allocated memory
+ * Return:		log-offset of this new record, or -ve error code
+ */
+int efi_logs_allocate_pages(enum efi_allocate_type type,
+			    enum efi_memory_type memory_type, efi_uintn_t pages,
+			    u64 *memory);
+
+/**
+ * efi_loge_allocate_pages() - Record a return from efi_allocate_pages()
+ *
+ * This stores the value of the memory pointer also
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_allocate_pages(int ofs, efi_status_t efi_ret);
+
+/**
+ * efi_logs_free_pages() - Record a call to efi_free_pages()
+ *
+ * @memory:	start of the memory area to be freed
+ * @pages:	number of pages to be freed
+ * Return:	log-offset of this new record, or -ve error code
+ */
+int efi_logs_free_pages(u64 memory, efi_uintn_t pages);
+
+/**
+ * efi_loge_free_pages() - Record a return from efi_free_pages()
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_free_pages(int ofs, efi_status_t efi_ret);
+
+/**
+ * efi_logs_allocate_pool() - Record a call to efi_allocate_pool()
+ *
+ * @pool_type:	type of the pool from which memory is to be allocated
+ * @size:	number of bytes to be allocated
+ * @buffer:	place to hold pointer to allocated memory
+ * Return:	log-offset of this new record, or -ve error code
+ */
+int efi_logs_allocate_pool(enum efi_memory_type pool_type, efi_uintn_t size,
+			   void **buffer);
+
+/**
+ * efi_loge_allocate_pool() - Record a return from efi_allocate_pool()
+ *
+ * This stores the value of the buffer pointer also
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_allocate_pool(int ofs, efi_status_t efi_ret);
+
+/**
+ * efi_logs_free_pool() - Record a call to efi_free_pool()
+ *
+ * @buffer:	start of memory to be freed
+ * Return:	log-offset of this new record, or -ve error code
+ */
+int efi_logs_free_pool(void *buffer);
+
+/**
+ * efi_loge_free_pool() - Record a return from efi_free_pool()
+ *
+ * ofs: Offset of the record to end
+ * efi_ret: status code to record
+ */
+int efi_loge_free_pool(int ofs, efi_status_t efi_ret);
+
 #else /* !EFI_LOG */
 
+static inline int efi_logs_allocate_pages(enum efi_allocate_type type,
+					  enum efi_memory_type memory_type,
+					  efi_uintn_t pages, u64 *memory)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_allocate_pages(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_logs_free_pages(u64 memory, efi_uintn_t pages)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_free_pages(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_logs_allocate_pool(enum efi_memory_type pool_type,
+					 efi_uintn_t size, void **buffer)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_allocate_pool(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_logs_free_pool(void *buffer)
+{
+	return -ENOSYS;
+}
+
+static inline int efi_loge_free_pool(int ofs, efi_status_t efi_ret)
+{
+	return -ENOSYS;
+}
+
 static inline int efi_logs_testing(enum efil_test_t enum_val,
 				   efi_uintn_t int_value, void *buffer,
 				   u64 *memory)
lib/efi_loader/efi_log.c +189 -0

210 lines not on this page · raw message

lib/efi_loader/efi_memory.c +86 -33

169 lines not on this page · raw message

test/lib/efi_log.c +44 -0

47 lines not on this page · raw message

Signature · 1 line
2.43.0
#28 lore raw

PATCH 15/15 efi_loader: Add documentation for the EFI log

In reply to Simon Glass

Add a note in the documentation about this feature.

---

 doc/develop/uefi/uefi.rst | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
doc/develop/uefi/uefi.rst +22 -0
index 0760ca91d4f..eade13dcfa1 100644
@@ -963,6 +963,28 @@ This driver is only available if U-Boot is configured with::
     CONFIG_BLK=y
     CONFIG_PARTITIONS=y
 
+Logging
+-------
+
+The EFI subsystem supports logging of boot-services calls to a memory area. The
+log can then be shown using the ``efidebug log`` command. Note that only a few
+calls are logged at present.
+
+To enable this feature::
+
+    CONFIG_EFI_LOG=y
+    CONFIG_EFI_LOG_SIZE=0x4000
+    CONFIG_BLOBLIST_SIZE_RELOC=0x5000
+
+The bloblist size must be set to larger than the EFI size. For now the log size
+is fixed at the start.
+
+Logging is performed within the internal U-Boot functions, not at the
+boot-services interface. This makes it possible to log EFI calls made by U-Boot
+itself, such as memory allocations.
+
+See the :doc:`/usage/cmd/efidebug` (*log* subcommand) for more information.
+
 Miscellaneous
 -------------
 
Signature · 1 line
2.43.0
#29 lore raw
In reply to Simon Glass

Hi Simon,

Quoted 9 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Thanks
/Ilias

Quoted 64 lines

This feature makes it possible to add tests to check which EFI calls are made by U-Boot itself. It may also make it easier to figure out what is needed for booting Windows.

Some patches to help with debugging sandbox memory-mapping are included, but for now EFI's use of mapping is not adjusted.

Simon Glass (15):
log: Add a new category for tests
test: Allow saving and restoring the bloblist
bloblist: test: Mark tests with UTF_BLOBLIST
sandbox: Convert sb command to use new macro
doc: sandbox: Add docs for the sb command
sandbox: Add a way to show the sandbox memory-mapping
sandbox: Fix comment for nomap_sysmem() function
lmb: Drop extra 16KB of stack space
efi_loader: Fix free in ..._media_device_boot_option()
efi_loader: Add support for logging EFI calls
efi_loader: Create the log on startup
efi_loader: Add a command to show the EFI log
test: efi_loader: Add a simple test for the EFI log
efi_loader: Use the log with memory-related functions
efi_loader: Add documentation for the EFI log

 MAINTAINERS                    |   7 +
 arch/sandbox/cpu/cpu.c         |  13 +
 arch/sandbox/include/asm/cpu.h |   3 +
 arch/sandbox/include/asm/io.h  |   2 +-
 cmd/efidebug.c                 |  53 +++-
 cmd/sb.c                       |  42 ++--
 common/log.c                   |   1 +
 configs/sandbox_defconfig      |   3 +
 doc/develop/uefi/uefi.rst      |  22 ++
 doc/usage/cmd/efidebug.rst     | 109 ++++++++
 doc/usage/cmd/sb.rst           |  79 ++++++
 doc/usage/index.rst            |   2 +
 include/bloblist.h             |   1 +
 include/efi.h                  |   1 +
 include/efi_log.h              | 316 +++++++++++++++++++++++
 include/log.h                  |   2 +
 include/test/test.h            |   3 +
 lib/efi_loader/Kconfig         |  19 ++
 lib/efi_loader/Makefile        |   1 +
 lib/efi_loader/efi_bootmgr.c   |   3 +-
 lib/efi_loader/efi_log.c       | 444 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c    | 119 ++++++---
 lib/efi_loader/efi_setup.c     |   7 +
 lib/lmb.c                      |   2 -
 test/common/bloblist.c         |  28 +--
 test/lib/Makefile              |   1 +
 test/lib/efi_log.c             |  93 +++++++
 test/test-main.c               |  13 +
 28 files changed, 1305 insertions(+), 84 deletions(-)
 create mode 100644 doc/usage/cmd/efidebug.rst
 create mode 100644 doc/usage/cmd/sb.rst
 create mode 100644 include/efi_log.h
 create mode 100644 lib/efi_loader/efi_log.c
 create mode 100644 test/lib/efi_log.c

--
2.43.0

#30 lore raw

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Regards,
Simon

Quoted 67 lines

Thanks
/Ilias

Quoted 64 lines

This feature makes it possible to add tests to check which EFI calls are made by U-Boot itself. It may also make it easier to figure out what is needed for booting Windows.

Some patches to help with debugging sandbox memory-mapping are included, but for now EFI's use of mapping is not adjusted.

Simon Glass (15):
log: Add a new category for tests
test: Allow saving and restoring the bloblist
bloblist: test: Mark tests with UTF_BLOBLIST
sandbox: Convert sb command to use new macro
doc: sandbox: Add docs for the sb command
sandbox: Add a way to show the sandbox memory-mapping
sandbox: Fix comment for nomap_sysmem() function
lmb: Drop extra 16KB of stack space
efi_loader: Fix free in ..._media_device_boot_option()
efi_loader: Add support for logging EFI calls
efi_loader: Create the log on startup
efi_loader: Add a command to show the EFI log
test: efi_loader: Add a simple test for the EFI log
efi_loader: Use the log with memory-related functions
efi_loader: Add documentation for the EFI log

 MAINTAINERS                    |   7 +
 arch/sandbox/cpu/cpu.c         |  13 +
 arch/sandbox/include/asm/cpu.h |   3 +
 arch/sandbox/include/asm/io.h  |   2 +-
 cmd/efidebug.c                 |  53 +++-
 cmd/sb.c                       |  42 ++--
 common/log.c                   |   1 +
 configs/sandbox_defconfig      |   3 +
 doc/develop/uefi/uefi.rst      |  22 ++
 doc/usage/cmd/efidebug.rst     | 109 ++++++++
 doc/usage/cmd/sb.rst           |  79 ++++++
 doc/usage/index.rst            |   2 +
 include/bloblist.h             |   1 +
 include/efi.h                  |   1 +
 include/efi_log.h              | 316 +++++++++++++++++++++++
 include/log.h                  |   2 +
 include/test/test.h            |   3 +
 lib/efi_loader/Kconfig         |  19 ++
 lib/efi_loader/Makefile        |   1 +
 lib/efi_loader/efi_bootmgr.c   |   3 +-
 lib/efi_loader/efi_log.c       | 444 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c    | 119 ++++++---
 lib/efi_loader/efi_setup.c     |   7 +
 lib/lmb.c                      |   2 -
 test/common/bloblist.c         |  28 +--
 test/lib/Makefile              |   1 +
 test/lib/efi_log.c             |  93 +++++++
 test/test-main.c               |  13 +
 28 files changed, 1305 insertions(+), 84 deletions(-)
 create mode 100644 doc/usage/cmd/efidebug.rst
 create mode 100644 doc/usage/cmd/sb.rst
 create mode 100644 include/efi_log.h
 create mode 100644 lib/efi_loader/efi_log.c
 create mode 100644 test/lib/efi_log.c

--
2.43.0

#31 lore raw
Quoted 19 lines · Simon Glass

Hi Ilias,

Quoted 14 lines · Ilias Apalodimas

Hi Simon,

Quoted 9 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Quoted 6 lines
Quoted 2 lines

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Thanks
/Ilias

/Ilias

Quoted 72 lines

Regards,
Simon

Quoted 67 lines

Thanks
/Ilias

Quoted 64 lines

This feature makes it possible to add tests to check which EFI calls are made by U-Boot itself. It may also make it easier to figure out what is needed for booting Windows.

Some patches to help with debugging sandbox memory-mapping are included, but for now EFI's use of mapping is not adjusted.

Simon Glass (15):
log: Add a new category for tests
test: Allow saving and restoring the bloblist
bloblist: test: Mark tests with UTF_BLOBLIST
sandbox: Convert sb command to use new macro
doc: sandbox: Add docs for the sb command
sandbox: Add a way to show the sandbox memory-mapping
sandbox: Fix comment for nomap_sysmem() function
lmb: Drop extra 16KB of stack space
efi_loader: Fix free in ..._media_device_boot_option()
efi_loader: Add support for logging EFI calls
efi_loader: Create the log on startup
efi_loader: Add a command to show the EFI log
test: efi_loader: Add a simple test for the EFI log
efi_loader: Use the log with memory-related functions
efi_loader: Add documentation for the EFI log

 MAINTAINERS                    |   7 +
 arch/sandbox/cpu/cpu.c         |  13 +
 arch/sandbox/include/asm/cpu.h |   3 +
 arch/sandbox/include/asm/io.h  |   2 +-
 cmd/efidebug.c                 |  53 +++-
 cmd/sb.c                       |  42 ++--
 common/log.c                   |   1 +
 configs/sandbox_defconfig      |   3 +
 doc/develop/uefi/uefi.rst      |  22 ++
 doc/usage/cmd/efidebug.rst     | 109 ++++++++
 doc/usage/cmd/sb.rst           |  79 ++++++
 doc/usage/index.rst            |   2 +
 include/bloblist.h             |   1 +
 include/efi.h                  |   1 +
 include/efi_log.h              | 316 +++++++++++++++++++++++
 include/log.h                  |   2 +
 include/test/test.h            |   3 +
 lib/efi_loader/Kconfig         |  19 ++
 lib/efi_loader/Makefile        |   1 +
 lib/efi_loader/efi_bootmgr.c   |   3 +-
 lib/efi_loader/efi_log.c       | 444 +++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_memory.c    | 119 ++++++---
 lib/efi_loader/efi_setup.c     |   7 +
 lib/lmb.c                      |   2 -
 test/common/bloblist.c         |  28 +--
 test/lib/Makefile              |   1 +
 test/lib/efi_log.c             |  93 +++++++
 test/test-main.c               |  13 +
 28 files changed, 1305 insertions(+), 84 deletions(-)
 create mode 100644 doc/usage/cmd/efidebug.rst
 create mode 100644 doc/usage/cmd/sb.rst
 create mode 100644 include/efi_log.h
 create mode 100644 lib/efi_loader/efi_log.c
 create mode 100644 test/lib/efi_log.c

--
2.43.0

#32 lore raw

Hi Ilias,

Quoted 24 lines · Ilias Apalodimas
Quoted 22 lines · Simon Glass

Hi Ilias,

Quoted 16 lines · Ilias Apalodimas

Hi Simon,

Quoted 9 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Quoted 7 lines
Quoted 3 lines

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

I am hoping to expand this into a debugging tool for figuring out how to boot Windows and perhaps logging detailed information when things go wrong, for later analysis. It might seem like overkill, but we will see.

Regards,
Simon

#33 lore raw

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

Quoted 5 lines

I am hoping to expand this into a debugging tool for figuring out how to boot Windows and perhaps logging detailed information when things go wrong, for later analysis. It might seem like overkill, but we will see.

I've managed to run windows installers on QEMU & U-Boot. It's been more than a year but windows boots and calls EBS(). The something fails down the road.
I think I have a branch somewhere with the changes needed, I'll send it over if I find it.

/Ilias

Quoted 3 lines

Regards,
Simon

#34 lore raw

HI Ilias,

Quoted 44 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

Quoted 6 lines

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Quoted 7 lines
Quoted 6 lines

I am hoping to expand this into a debugging tool for figuring out how to boot Windows and perhaps logging detailed information when things go wrong, for later analysis. It might seem like overkill, but we will see.

Quoted 5 lines

I've managed to run windows installers on QEMU & U-Boot. It's been more than a year but windows boots and calls EBS(). The something fails down the road.
I think I have a branch somewhere with the changes needed, I'll send it over if I find it.

Did you find it?

Regards,
Simon

#35 lore raw

Hi Simon,

Quoted 56 lines · Simon Glass

HI Ilias,

Quoted 44 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

Quoted 6 lines

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

Quoted 4 lines

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Why the EFI_LOADER only? Bootstd is supposed to cover more cases, so why not a generic framework for all boot commands?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

I am hoping to expand this into a debugging tool for figuring out how to boot Windows and perhaps logging detailed information when things go wrong, for later analysis. It might seem like overkill, but we will see.

Quoted 7 lines
Quoted 5 lines

I've managed to run windows installers on QEMU & U-Boot. It's been more than a year but windows boots and calls EBS(). The something fails down the road.
I think I have a branch somewhere with the changes needed, I'll send it over if I find it.

Did you find it?

I didn't but Alexander has a tree on which I based my work on.
https://github.com/u-boot/u-boot/compare/master...agraf:u-boot:qemu-arm-win10

Cheers
/Ilias

Quoted 3 lines

Regards,
Simon

#36 lore raw
Quoted 59 lines · Ilias Apalodimas

Hi Simon,

Quoted 56 lines · Simon Glass

HI Ilias,

Quoted 50 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

Quoted 7 lines
Quoted 4 lines

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Why the EFI_LOADER only? Bootstd is supposed to cover more cases, so why not a generic framework for all boot commands?

This feels similar to the point I've made elsewhere in this overarching series, why not do this at existing common points in the code path?

Signature · 1 line
Tom
#37 lore raw

Am 20. November 2024 19:06:33 MEZ schrieb Tom Rini <[email protected]>:

Quoted 65 lines · Ilias Apalodimas
Quoted 64 lines

Hi Simon,

Quoted 60 lines · Simon Glass

HI Ilias,

Quoted 44 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

Quoted 6 lines

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Quoted 6 lines
Quoted 2 lines

Why the EFI_LOADER only? Bootstd is supposed to cover more cases, so why not a generic framework for all boot commands?

This feels similar to the point I've made elsewhere in this overarching series, why not do this at existing common points in the code path?

The common code point is the log library. Just add an event there for which the test can register a handler.

With a log event you get:

function name
source location
message class
message text
message priority

and all of this with minimal invasiveness.

Best regards

Heinrich

#38 lore raw

Hi,

Quoted 78 lines · Heinrich Schuchardt

Am 20. November 2024 19:06:33 MEZ schrieb Tom Rini <[email protected]>:

Quoted 65 lines · Ilias Apalodimas
Quoted 64 lines

Hi Simon,

Quoted 60 lines · Simon Glass

HI Ilias,

Quoted 44 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

Quoted 6 lines

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Quoted 6 lines
Quoted 2 lines

Why the EFI_LOADER only? Bootstd is supposed to cover more cases, so why not a generic framework for all boot commands?

This feels similar to the point I've made elsewhere in this overarching series, why not do this at existing common points in the code path?

The common code point is the log library. Just add an event there for which the test can register a handler.

With a log event you get:

Quoted 7 lines

function name
source location
message class
message text
message priority

and all of this with minimal invasiveness.

OK guys, I think I got the message :-)

I'm going to apply this to my tree for now. While I'm at it I think it is time to go through my backlog and apply some other things that I'd like in there.

Regards,
Simon

#39 lore raw

Hi,

Quoted 88 lines · Simon Glass

Hi,

Quoted 84 lines · Heinrich Schuchardt

Am 20. November 2024 19:06:33 MEZ schrieb Tom Rini <[email protected]>:

Quoted 65 lines · Ilias Apalodimas
Quoted 64 lines

Hi Simon,

Quoted 60 lines · Simon Glass

HI Ilias,

Quoted 44 lines · Ilias Apalodimas

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Ilias,

Quoted 28 lines · Ilias Apalodimas
Quoted 25 lines · Simon Glass

Hi Ilias,

Quoted 10 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

It is a bit of a pain to log EFI boot-services calls at present. The output goes to the console so cannot easily be inspected later. Also it would be useful to be able to store the log and review it later, perhaps after something has gone wrong.

Quoted 6 lines
Quoted 3 lines

This series makes a start on implementing a log-to-buffer feature. It provides a simple 'efidebug log' command to inspect the buffer. For now, only memory allocations are logged.

Why is this problem specific to EFI and no U-Boot in general? Do we have a similar machinery for malloc()?

Mostly because an app can make EFI calls and we want to know what they are, e.g. to debug them and figure out what might be wrong when something doesn't boot.

Quoted 6 lines
Quoted 3 lines

EFI_PRINT() has been proven pretty useful for this. I don't personally see the point of adding ~1300 lines of code to replace a print. What would make more sense is teach EFI_PRINT to log errors in a buffer.

Is that a NAK? Please be clear if you are reviewing the code or just rejecting the whole idea.

Quoted 6 lines

For the idea, no. But I don't think what's implemented here is what we want.

To track what EFI services are called, we already have EFI_ENTRY and EFI_EXIT. Why don't we instead, add a logging service (and we already have ftrace iirc) and plug it in the macros above?
That would make more sense not to mention way less code.

I am wanting to programmatically log and manage what EFI_LOADER does, so that bootstd can present a high-level view of what is going on, e.g. which protocols are used, how much memory is allocated and where. So this is not just about logging text output.

Quoted 6 lines
Quoted 2 lines

Why the EFI_LOADER only? Bootstd is supposed to cover more cases, so why not a generic framework for all boot commands?

This feels similar to the point I've made elsewhere in this overarching series, why not do this at existing common points in the code path?

The common code point is the log library. Just add an event there for which the test can register a handler.

With a log event you get:

function name
source location
message class
message text
message priority

Quoted 7 lines
Quoted 1 line

and all of this with minimal invasiveness.

OK guys, I think I got the message :-)

I'm going to apply this to my tree for now. While I'm at it I think it is time to go through my backlog and apply some other things that I'd like in there.

One point I didn't mention is that this series allows logging of all calls, not just the ones that come in from the app. At present there are quite a few efi_allocate_pages() calls which are entirely internal.

Regards,
Simon