From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v1 12/54] efi: loader: add support for tracing calls back into UEFI
Date: Thu, 18 Dec 2025 11:37:32 +0100 [thread overview]
Message-ID: <20251218111242.1527495-13-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251218111242.1527495-1-a.fatoum@pengutronix.de>
This will be very verbose, but when trying to pinpoint what operation
is bothering an EFI payload, it's very useful to know every entry and
exit into barebox-provided services.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Kconfig.debug | 7 +++
efi/loader/Makefile | 1 +
efi/loader/trace.c | 44 +++++++++++++++
include/efi/loader/trace.h | 111 +++++++++++++++++++++++++++++++++++++
4 files changed, 163 insertions(+)
create mode 100644 efi/loader/trace.c
create mode 100644 include/efi/loader/trace.h
diff --git a/common/Kconfig.debug b/common/Kconfig.debug
index 2de885ebb3f8..64127143a5d6 100644
--- a/common/Kconfig.debug
+++ b/common/Kconfig.debug
@@ -77,6 +77,13 @@ config DEBUG_PROBES
Most consoles do not implement a remove callback to remain operable until
the very end. Consoles using DMA, however, must be removed.
+config DEBUG_EFI_LOADER_ENTRY
+ bool "Debug EFI loader entry/exit"
+ depends on EFI_LOADER
+ help
+ If enabled, this will print whenever an EFI payload/app calls
+ into barebox or is returned to before ExitBootServices.
+
config DMA_API_DEBUG
bool "Enable debugging of DMA-API usage"
depends on HAS_DMA
diff --git a/efi/loader/Makefile b/efi/loader/Makefile
index 0475cfc7452f..1f07cf6005b9 100644
--- a/efi/loader/Makefile
+++ b/efi/loader/Makefile
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-y += memory.o pool_alloc.o
+obj-y += trace.o
diff --git a/efi/loader/trace.c b/efi/loader/trace.c
new file mode 100644
index 000000000000..9eb22805e12e
--- /dev/null
+++ b/efi/loader/trace.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <efi/loader/trace.h>
+#include <linux/minmax.h>
+
+/* 1 if inside barebox code, 0 if inside EFI payload code */
+static int nesting_level = 1;
+
+/**
+ * indent_string() - returns a string for indenting with two spaces per level
+ * @level: indent level
+ *
+ * A maximum of ten indent levels is supported. Higher indent levels will be
+ * truncated.
+ *
+ * Return: A string for indenting with two spaces per level is
+ * returned.
+ */
+static const char *indent_string(int level)
+{
+ const char *indent = " ";
+ const int max = strlen(indent);
+
+ if (level < 0)
+ return "!!EFI_EXIT called without matching EFI_ENTRY!! ";
+
+ level = min(max, level * 2);
+ return &indent[max - level];
+}
+
+const char *__efi_nesting(void)
+{
+ return indent_string(nesting_level);
+}
+
+const char *__efi_nesting_inc(void)
+{
+ return indent_string(nesting_level++);
+}
+
+const char *__efi_nesting_dec(void)
+{
+ return indent_string(--nesting_level);
+}
diff --git a/include/efi/loader/trace.h b/include/efi/loader/trace.h
new file mode 100644
index 000000000000..93bba7bb88c7
--- /dev/null
+++ b/include/efi/loader/trace.h
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef __EFI_LOADER_TRACE_H__
+#define __EFI_LOADER_TRACE_H__
+
+#include <efi/error.h>
+#include <linux/printk.h>
+
+#ifndef __EFI_PRINT
+#ifdef CONFIG_DEBUG_EFI_LOADER_ENTRY
+#define __EFI_PRINT(...) pr_info(__VA_ARGS__)
+#define __EFI_WARN(...) pr_warning(__VA_ARGS__)
+#else
+#define __EFI_PRINT(...) pr_debug(__VA_ARGS__)
+#define __EFI_WARN(...) pr_debug(__VA_ARGS__)
+#endif
+#endif
+
+const char *__efi_nesting(void);
+const char *__efi_nesting_inc(void);
+const char *__efi_nesting_dec(void);
+
+/*
+ * Enter the barebox world from UEFI:
+ */
+#ifndef EFI_ENTRY
+#define EFI_ENTRY(format, ...) do { \
+ __EFI_PRINT("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
+ __func__, ##__VA_ARGS__); \
+ } while(0)
+#endif
+
+/*
+ * Exit the barebox world back to UEFI:
+ */
+#ifndef EFI_EXIT
+#define EFI_EXIT(ret) ({ \
+ typeof(ret) _r = ret; \
+ __EFI_PRINT("%sEFI: Exit: %s: %s (%u)\n", __efi_nesting_dec(), \
+ __func__, efi_strerror((uintptr_t)_r), (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
+ _r; \
+ })
+#endif
+
+#ifndef EFI_EXIT2
+#define EFI_EXIT2(ret, val) ({ \
+ typeof(ret) _r = ret; \
+ __EFI_PRINT("%sEFI: Exit: %s: %s (%u) = 0x%llx\n", __efi_nesting_dec(), \
+ __func__, efi_strerror((uintptr_t)_r), (u32)((uintptr_t) _r & ~EFI_ERROR_MASK), \
+ (u64)(uintptr_t)(val)); \
+ _r; \
+ })
+#endif
+
+/*
+ * Call non-void UEFI function from barebox and retrieve return value:
+ */
+#ifndef EFI_CALL
+#define EFI_CALL(exp) ({ \
+ __EFI_PRINT("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
+ typeof(exp) _r = exp; \
+ __EFI_PRINT("%sEFI: %lu returned by %s\n", __efi_nesting_dec(), \
+ (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK), #exp); \
+ _r; \
+})
+#endif
+
+/**
+ * define EFI_RETURN() - return from EFI_CALL in efi_start_image()
+ *
+ * @ret: status code
+ */
+#ifndef EFI_RETURN
+#define EFI_RETURN(ret) ({ \
+ typeof(ret) _r = ret; \
+ __EFI_PRINT("%sEFI: %lu returned by started image", __efi_nesting_dec(), \
+ (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK)); \
+})
+#endif
+
+/*
+ * Call void UEFI function from barebox:
+ */
+#ifndef EFI_CALL_VOID
+#define EFI_CALL_VOID(exp) do { \
+ __EFI_PRINT("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
+ exp; \
+ __EFI_PRINT("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
+ } while(0)
+#endif
+
+/*
+ * Write an indented message with EFI prefix
+ */
+#ifndef EFI_PRINT
+#define EFI_PRINT(format, ...) ({ \
+ __EFI_PRINT("%sEFI: " format, __efi_nesting(), \
+ ##__VA_ARGS__); \
+ })
+#endif
+
+/*
+ * Write an indented warning with EFI prefix
+ */
+#ifndef EFI_WARN
+#define EFI_WARN(format, ...) ({ \
+ __EFI_WARN("%sEFI: " format, __efi_nesting(), \
+ ##__VA_ARGS__); \
+ })
+#endif
+
+#endif
--
2.47.3
next prev parent reply other threads:[~2025-12-18 11:41 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 10:37 [PATCH v1 00/54] efi: implement EFI loader support in barebox Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 01/54] efi: payload: initrd: fix type mismatch on 32-bit Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 02/54] efi: loader: switch over event/memory key type to efi_uintn_t Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 03/54] lib: vsprintf: print human-readable EFI GUIDs with %pUs Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 04/54] fs: fat: don't duplicate dentries when resolving differently cased paths Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 05/54] efi: loader: add memory accounting Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 06/54] efi: loader: add pool allocator Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 07/54] efi: types: add EFI_RUNTIME_SECTION Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 08/54] resource: assign memory banks a default type and attr Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 09/54] ARM: lds: add EFI runtime service section Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 10/54] ARM: move needed assembly routines into EFI runtime section Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 11/54] crypto: crc32: implement position independent CRC32 Ahmad Fatoum
2025-12-18 10:37 ` Ahmad Fatoum [this message]
2025-12-18 10:37 ` [PATCH v1 13/54] efi: loader: add table utility functions Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 14/54] lib: add charset helpers Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 15/54] efi: loader: add object handling API Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 16/54] efi: loader: add devicepath support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 17/54] efi: loader: add debug support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 18/54] efi: loader: add boot services support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 19/54] efi: loader: add support for runtime services before ExitBootServices Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 20/54] efi: loader: setup root node Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 21/54] efi: loader: add watchdog support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 22/54] efi: loader: move PE implementation out of common code Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 23/54] efi: loader: protocol: add file protocol support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 24/54] efi: loader: protocol: add Block IO support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 25/54] efi: loader: protocol: implement efi_file_from_path Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 26/54] efi: loader: boot: implement LoadImage BootService Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 27/54] efi: loader: add EFI load option handling Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 28/54] efi: loader: protocol: add graphical output protocol support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 29/54] efi: loader: protocol: add console support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 30/54] efi: loader: protocol: add HII support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 31/54] efi: loader: protocol: add unicode collation support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 32/54] efi: loader: protocol: add random number generator protocol Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 33/54] efi: loader: protocol: add device_path_utilities Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 34/54] efi: loader: support formatting only first device path node to text Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 35/54] efi: loader: protocol: add efi_device_path_to_text support Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 36/54] restart: allow drivers to register runtime restart handler Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 37/54] poweroff: allow drivers to register runtime poweroff handler Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 38/54] ARM: psci: client: register runtime service " Ahmad Fatoum
2025-12-18 10:37 ` [PATCH v1 39/54] ARM: psci: client: register runtime service restart handler Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 40/54] hardening: disable some features when EFI runtime support is enabled Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 41/54] filetype: add new filetype for efi-stubbed ARM zImages Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 42/54] bootm: add global.bootm.efi toggle Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 43/54] efi: loader: add ESP boot entry provider Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 44/54] efi: loader: add rudimentary EFI boot manager Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 45/54] efi: loader: implement bootm handler Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 46/54] efi: runtime: add EFI variable support Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 47/54] efi: loader: populate OsIndicationsSupported/PlatformLang variables Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 48/54] ARM: don't disable MMU when EFI booting Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 49/54] efi: runtime: add runtime service support after ExitBootServices Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 50/54] efi: runtime: add relocation check Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 51/54] efi: loader: CONFIG_EFI_RT_VOLATILE_STORE Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 52/54] efi: loader: support ExitBootServices Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 53/54] efi: loader: pass along SMBIOS table Ahmad Fatoum
2025-12-18 10:38 ` [PATCH v1 54/54] ARM: configs: add multi_v7/8_efiloader_defconfig Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251218111242.1527495-13-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox