Commit 22ada0c8e6d50281af72176eecdfc356c794639c
Committed by
Tom Rini
1 parent
274325c509
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
vsprintf.c: add GUID printing
This works (roughly) the same way as linux's, but we currently always print lower-case (ie. we just keep %pUB and %pUL for compat with linux), mostly just because that is what uuid_bin_to_str() supports. %pUb: 01020304-0506-0708-090a-0b0c0d0e0f10 %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 It will be used by a later efi_loader paths for efi variables and for device-path-to-text protocol, and also quite useful for debug prints of protocol GUIDs. Signed-off-by: Rob Clark <robdclark@gmail.com> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 3 changed files with 46 additions and 2 deletions Side-by-side Diff
examples/api/Makefile
... | ... | @@ -35,6 +35,7 @@ |
35 | 35 | EXT_COBJ-y += lib/time.o |
36 | 36 | EXT_COBJ-y += lib/vsprintf.o |
37 | 37 | EXT_COBJ-y += lib/charset.o |
38 | +EXT_COBJ-$(CONFIG_LIB_UUID) += lib/uuid.o | |
38 | 39 | EXT_SOBJ-$(CONFIG_PPC) += arch/powerpc/lib/ppcstring.o |
39 | 40 | ifeq ($(ARCH),arm) |
40 | 41 | EXT_SOBJ-$(CONFIG_USE_ARCH_MEMSET) += arch/arm/lib/memset.o |
include/config_fallbacks.h
lib/vsprintf.c
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | |
19 | 19 | #include <common.h> |
20 | 20 | #include <charset.h> |
21 | +#include <uuid.h> | |
21 | 22 | |
22 | 23 | #include <div64.h> |
23 | 24 | #define noinline __attribute__((noinline)) |
24 | 25 | |
... | ... | @@ -366,7 +367,41 @@ |
366 | 367 | } |
367 | 368 | #endif |
368 | 369 | |
370 | +#ifdef CONFIG_LIB_UUID | |
369 | 371 | /* |
372 | + * This works (roughly) the same way as linux's, but we currently always | |
373 | + * print lower-case (ie. we just keep %pUB and %pUL for compat with linux), | |
374 | + * mostly just because that is what uuid_bin_to_str() supports. | |
375 | + * | |
376 | + * %pUb: 01020304-0506-0708-090a-0b0c0d0e0f10 | |
377 | + * %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 | |
378 | + */ | |
379 | +static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, | |
380 | + int precision, int flags, const char *fmt) | |
381 | +{ | |
382 | + char uuid[UUID_STR_LEN + 1]; | |
383 | + int str_format = UUID_STR_FORMAT_STD; | |
384 | + | |
385 | + switch (*(++fmt)) { | |
386 | + case 'L': | |
387 | + case 'l': | |
388 | + str_format = UUID_STR_FORMAT_GUID; | |
389 | + break; | |
390 | + case 'B': | |
391 | + case 'b': | |
392 | + /* this is the default */ | |
393 | + break; | |
394 | + default: | |
395 | + break; | |
396 | + } | |
397 | + | |
398 | + uuid_bin_to_str(addr, uuid, str_format); | |
399 | + | |
400 | + return string(buf, end, uuid, field_width, precision, flags); | |
401 | +} | |
402 | +#endif | |
403 | + | |
404 | +/* | |
370 | 405 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
371 | 406 | * by an extra set of alphanumeric characters that are extended format |
372 | 407 | * specifiers. |
373 | 408 | |
... | ... | @@ -399,8 +434,8 @@ |
399 | 434 | flags); |
400 | 435 | #endif |
401 | 436 | |
402 | -#ifdef CONFIG_CMD_NET | |
403 | 437 | switch (*fmt) { |
438 | +#ifdef CONFIG_CMD_NET | |
404 | 439 | case 'a': |
405 | 440 | flags |= SPECIAL | ZEROPAD; |
406 | 441 | |
407 | 442 | |
... | ... | @@ -430,8 +465,15 @@ |
430 | 465 | precision, flags); |
431 | 466 | flags &= ~SPECIAL; |
432 | 467 | break; |
433 | - } | |
434 | 468 | #endif |
469 | +#ifdef CONFIG_LIB_UUID | |
470 | + case 'U': | |
471 | + return uuid_string(buf, end, ptr, field_width, precision, | |
472 | + flags, fmt); | |
473 | +#endif | |
474 | + default: | |
475 | + break; | |
476 | + } | |
435 | 477 | flags |= SMALL; |
436 | 478 | if (field_width == -1) { |
437 | 479 | field_width = 2*sizeof(void *); |