diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2020-10-03 13:12:03 +0200 |
---|---|---|
committer | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2020-10-06 07:43:56 +0200 |
commit | 9487683821e59d0156b8f0697d669ef62534a867 (patch) | |
tree | 98edb70ac93651345aee761d334828b9e3bcb86a /lib | |
parent | e2aff337ed53ada0abdbc38d0afa8d6f209bf4ab (diff) | |
download | u-boot-9487683821e59d0156b8f0697d669ef62534a867.zip u-boot-9487683821e59d0156b8f0697d669ef62534a867.tar.gz u-boot-9487683821e59d0156b8f0697d669ef62534a867.tar.bz2 |
efi_selftest: enable printing hexadecimal numbers
Add code to use %x in efi_st_print().
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/efi_selftest/efi_selftest_console.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c index 13f3ee6..0219bd7 100644 --- a/lib/efi_selftest/efi_selftest_console.c +++ b/lib/efi_selftest/efi_selftest_console.c @@ -44,25 +44,28 @@ static void mac(void *pointer, u16 **buf) } /* - * Print a pointer to an u16 string + * printx() - print hexadecimal number to an u16 string * - * @pointer: pointer - * @buf: pointer to buffer address - * on return position of terminating zero word + * @pointer: pointer + * @prec: minimum number of digits to print + * @buf: pointer to buffer address, + * on return position of terminating zero word + * @size: size of value to be printed in bytes */ -static void pointer(void *pointer, u16 **buf) +static void printx(u64 p, int prec, u16 **buf) { int i; u16 c; - uintptr_t p = (uintptr_t)pointer; u16 *pos = *buf; - for (i = 8 * sizeof(p) - 4; i >= 0; i -= 4) { - c = (p >> i) & 0x0f; - c += '0'; - if (c > '9') - c += 'a' - '9' - 1; - *pos++ = c; + for (i = 2 * sizeof(p) - 1; i >= 0; --i) { + c = (p >> (4 * i)) & 0x0f; + if (c || pos != *buf || !i || i < prec) { + c += '0'; + if (c > '9') + c += 'a' - '9' - 1; + *pos++ = c; + } } *pos = 0; *buf = pos; @@ -212,7 +215,9 @@ void efi_st_printc(int color, const char *fmt, ...) break; default: --c; - pointer(va_arg(args, void*), &pos); + printx((uintptr_t)va_arg(args, void *), + 2 * sizeof(void *), &pos); + break; } break; case 's': @@ -223,6 +228,10 @@ void efi_st_printc(int color, const char *fmt, ...) case 'u': uint2dec(va_arg(args, u32), prec, &pos); break; + case 'x': + printx((u64)va_arg(args, unsigned int), + prec, &pos); + break; default: break; } |