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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Heinrich Schuchardt
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 <[hidden email]>
Suggested-by: Rob Clark <[hidden email]>
Signed-off-by: Heinrich Schuchardt <[hidden email]>
---
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

_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 1/1] vsprintf.c: add EFI device path printing

Wolfgang Denk
Dear Heinrich,

In message <[hidden email]> you wrote:

>
> +#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;
> +}

I think this would be much clearer if you wrote:

        u16 *str;

        if (dp == NULL)
                return "<NULL>";

        str = efi_dp_str((struct efi_device_path *)dp);

        if (str == NULL)
                panic("device_path_string(): out of memory");

        buf = string16(buf, end, str, field_width, precision, flags);
        efi_free_pool(str);
        return buf;

Thanks.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [hidden email]
grep me no patterns and I'll tell you no lines.
_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot