[U-Boot] [PATCH v2 1/1] vsprintf.c: add EFI device path printing

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Nov 23 21:59:01 UTC 2017


For debugging efi_loader we need the capability to print EFI
device paths. With this patch we can write:

    debug("device path: %pD", dp);

A possible output would be

    device path: /MemoryMapped(0x0,0x3ff93a82,0x3ff93a82)

Cc: Wolfgang Denk <wd at denx.de>
Suggested-by: Rob Clark <robdclark at gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
I propose Alex picks up this patch for the EFI tree.

v2
	Panic if out of memory.
	Wolfgang suggested not to silently ignore an out of memory
	situation.
---
 lib/vsprintf.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+), 0 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index dd572d2868..1135817fd8 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -18,6 +18,7 @@
 
 #include <common.h>
 #include <charset.h>
+#include <efi_loader.h>
 #include <uuid.h>
 
 #include <div64.h>
@@ -292,6 +293,22 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
 	return buf;
 }
 
+#ifdef CONFIG_EFI_LOADER
+static char *device_path_string(char *buf, char *end, void *dp, int field_width,
+				int precision, int flags)
+{
+	u16 *str = efi_dp_str((struct efi_device_path *)dp);
+
+	/* Do not silently ignore out of memory situation */
+	if (!str && dp)
+		panic("efi_dp_str: out of memory");
+
+	buf = string16(buf, end, str, field_width, precision, flags);
+	efi_free_pool(str);
+	return buf;
+}
+#endif
+
 #ifdef CONFIG_CMD_NET
 static const char hex_asc[] = "0123456789abcdef";
 #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
@@ -435,6 +452,11 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 #endif
 
 	switch (*fmt) {
+#ifdef CONFIG_EFI_LOADER
+	case 'D':
+		return device_path_string(buf, end, ptr, field_width,
+					  precision, flags);
+#endif
 #ifdef CONFIG_CMD_NET
 	case 'a':
 		flags |= SPECIAL | ZEROPAD;
-- 
2.14.2



More information about the U-Boot mailing list