X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=lib%2Fvsprintf.c;h=dd572d2868a5453c8cd99326a944f3ee4e20cd25;hb=2a92080d8c4463f2ddbf4e3110c25ab55ef6ca3f;hp=874a2951f7053ef395cfee8ffe78464eee855039;hpb=45fe3809b9923b92f221d70eb45ae071059fd5e0;p=u-boot diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 874a2951f7..dd572d2868 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -17,6 +17,8 @@ #include #include +#include +#include #include #define noinline __attribute__((noinline)) @@ -270,6 +272,26 @@ static char *string(char *buf, char *end, char *s, int field_width, return buf; } +static char *string16(char *buf, char *end, u16 *s, int field_width, + int precision, int flags) +{ + u16 *str = s ? s : L""; + int utf16_len = utf16_strnlen(str, precision); + u8 utf8[utf16_len * MAX_UTF8_PER_UTF16]; + int utf8_len, i; + + utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8; + + if (!(flags & LEFT)) + while (utf8_len < field_width--) + ADDCH(buf, ' '); + for (i = 0; i < utf8_len; ++i) + ADDCH(buf, utf8[i]); + while (utf8_len < field_width--) + ADDCH(buf, ' '); + return buf; +} + #ifdef CONFIG_CMD_NET static const char hex_asc[] = "0123456789abcdef"; #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] @@ -345,6 +367,40 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width, } #endif +#ifdef CONFIG_LIB_UUID +/* + * 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 + */ +static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, + int precision, int flags, const char *fmt) +{ + char uuid[UUID_STR_LEN + 1]; + int str_format = UUID_STR_FORMAT_STD; + + switch (*(++fmt)) { + case 'L': + case 'l': + str_format = UUID_STR_FORMAT_GUID; + break; + case 'B': + case 'b': + /* this is the default */ + break; + default: + break; + } + + uuid_bin_to_str(addr, uuid, str_format); + + return string(buf, end, uuid, field_width, precision, flags); +} +#endif + /* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format @@ -378,8 +434,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, flags); #endif -#ifdef CONFIG_CMD_NET switch (*fmt) { +#ifdef CONFIG_CMD_NET case 'a': flags |= SPECIAL | ZEROPAD; @@ -409,8 +465,15 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, precision, flags); flags &= ~SPECIAL; break; - } #endif +#ifdef CONFIG_LIB_UUID + case 'U': + return uuid_string(buf, end, ptr, field_width, precision, + flags, fmt); +#endif + default: + break; + } flags |= SMALL; if (field_width == -1) { field_width = 2*sizeof(void *); @@ -528,8 +591,13 @@ repeat: continue; case 's': - str = string(str, end, va_arg(args, char *), - field_width, precision, flags); + if (qualifier == 'l' && !IS_ENABLED(CONFIG_SPL_BUILD)) { + str = string16(str, end, va_arg(args, u16 *), + field_width, precision, flags); + } else { + str = string(str, end, va_arg(args, char *), + field_width, precision, flags); + } continue; case 'p':