Skip to content

Commit 256060e

Browse files
xypronagraf
authored andcommitted
vsprintf.c: add EFI device path printing
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) This enhancement is not available when building without EFI support and neither in the SPL nor in the API example. A test is provided. It can be executed in the sandbox with command ut_print. The development for EFI support in the sandbox is currently in branch u-boot-dm/efi-working. The branch currently lacks commit 6ea8b58 ("efi_loader: correct DeviceNodeToText for media types"). Ater rebasing the aforementioned branch on U-Boot v2018.01 the test is executed successfully. Without EFI support in the sandbox the test is simply skipped. Suggested-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
1 parent 3c950b3 commit 256060e

3 files changed

Lines changed: 81 additions & 6 deletions

File tree

examples/api/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# SPDX-License-Identifier: GPL-2.0+
55
#
66

7+
# Provide symbol API_BUILD to signal that the API example is being built.
8+
KBUILD_CPPFLAGS += -DAPI_BUILD
9+
710
ifeq ($(ARCH),powerpc)
811
LOAD_ADDR = 0x40000
912
endif

lib/vsprintf.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
* from hush: simple_itoa() was lifted from boa-0.93.15
1212
*/
1313

14-
#include <stdarg.h>
15-
#include <linux/types.h>
16-
#include <linux/string.h>
17-
#include <linux/ctype.h>
18-
1914
#include <common.h>
2015
#include <charset.h>
16+
#include <efi_loader.h>
17+
#include <div64.h>
2118
#include <uuid.h>
19+
#include <stdarg.h>
20+
#include <linux/ctype.h>
21+
#include <linux/err.h>
22+
#include <linux/types.h>
23+
#include <linux/string.h>
2224

23-
#include <div64.h>
2425
#define noinline __attribute__((noinline))
2526

2627
/* we use this so that we can do without the ctype library */
@@ -292,6 +293,26 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
292293
return buf;
293294
}
294295

296+
#if defined(CONFIG_EFI_LOADER) && \
297+
!defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
298+
static char *device_path_string(char *buf, char *end, void *dp, int field_width,
299+
int precision, int flags)
300+
{
301+
u16 *str;
302+
303+
if (!dp)
304+
return "<NULL>";
305+
306+
str = efi_dp_str((struct efi_device_path *)dp);
307+
if (!str)
308+
return ERR_PTR(-ENOMEM);
309+
310+
buf = string16(buf, end, str, field_width, precision, flags);
311+
efi_free_pool(str);
312+
return buf;
313+
}
314+
#endif
315+
295316
#ifdef CONFIG_CMD_NET
296317
static const char hex_asc[] = "0123456789abcdef";
297318
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
@@ -435,6 +456,12 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
435456
#endif
436457

437458
switch (*fmt) {
459+
#if defined(CONFIG_EFI_LOADER) && \
460+
!defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
461+
case 'D':
462+
return device_path_string(buf, end, ptr, field_width,
463+
precision, flags);
464+
#endif
438465
#ifdef CONFIG_CMD_NET
439466
case 'a':
440467
flags |= SPECIAL | ZEROPAD;
@@ -604,6 +631,8 @@ static int vsnprintf_internal(char *buf, size_t size, const char *fmt,
604631
str = pointer(fmt + 1, str, end,
605632
va_arg(args, void *),
606633
field_width, precision, flags);
634+
if (IS_ERR(str))
635+
return PTR_ERR(str);
607636
/* Skip all alphanumeric pointer suffixes */
608637
while (isalnum(fmt[1]))
609638
fmt++;
@@ -768,6 +797,9 @@ int printf(const char *fmt, ...)
768797
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
769798
va_end(args);
770799

800+
/* Handle error */
801+
if (i <= 0)
802+
return i;
771803
/* Print the string */
772804
puts(printbuffer);
773805
return i;
@@ -784,6 +816,9 @@ int vprintf(const char *fmt, va_list args)
784816
*/
785817
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
786818

819+
/* Handle error */
820+
if (i <= 0)
821+
return i;
787822
/* Print the string */
788823
puts(printbuffer);
789824
return i;

test/print_ut.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,46 @@
77
#define DEBUG
88

99
#include <common.h>
10+
#if defined(CONFIG_EFI_LOADER) && \
11+
!defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
12+
#include <efi_api.h>
13+
#endif
1014
#include <display_options.h>
1115
#include <version.h>
1216

1317
#define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
1418
"and a lot more text to come"
1519

20+
/* Test efi_loader specific printing */
21+
static void efi_ut_print(void)
22+
{
23+
#if defined(CONFIG_EFI_LOADER) && \
24+
!defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
25+
char str[10];
26+
u8 buf[sizeof(struct efi_device_path_sd_mmc_path) +
27+
sizeof(struct efi_device_path)];
28+
u8 *pos = buf;
29+
struct efi_device_path *dp_end;
30+
struct efi_device_path_sd_mmc_path *dp_sd =
31+
(struct efi_device_path_sd_mmc_path *)pos;
32+
33+
/* Create a device path for an SD card */
34+
dp_sd->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
35+
dp_sd->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SD;
36+
dp_sd->dp.length = sizeof(struct efi_device_path_sd_mmc_path);
37+
dp_sd->slot_number = 3;
38+
pos += sizeof(struct efi_device_path_sd_mmc_path);
39+
/* Append end node */
40+
dp_end = (struct efi_device_path *)pos;
41+
dp_end->type = DEVICE_PATH_TYPE_END;
42+
dp_end->sub_type = DEVICE_PATH_SUB_TYPE_END;
43+
dp_end->length = sizeof(struct efi_device_path);
44+
45+
snprintf(str, sizeof(str), "_%pD_", buf);
46+
assert(!strcmp("_/SD(3)_", str));
47+
#endif
48+
}
49+
1650
static int do_ut_print(cmd_tbl_t *cmdtp, int flag, int argc,
1751
char *const argv[])
1852
{
@@ -75,6 +109,9 @@ static int do_ut_print(cmd_tbl_t *cmdtp, int flag, int argc,
75109
assert(!strncmp(FAKE_BUILD_TAG, s + 9 + len, 12));
76110
assert(!strcmp("\n\n", s + big_str_len - 3));
77111

112+
/* Test efi_loader specific printing */
113+
efi_ut_print();
114+
78115
printf("%s: Everything went swimmingly\n", __func__);
79116
return 0;
80117
}

0 commit comments

Comments
 (0)