Commit 1eebd14b79024f34925b79cb264242fac1bdc1b9

Authored by Thierry Reding
Committed by Tom Rini
1 parent 59e890ef7b

vsprintf: Add modifier for phys_addr_t

Provide a new modifier to vsprintf() to print phys_addr_t variables to
avoid having to cast or #ifdef when printing them out. The %pa modifier
is used for this purpose, so phys_addr_t variables need to be passed by
reference, like so:

	phys_addr_t start = 0;

	printf("start: %pa\n", &start);

Depending on the size of phys_addr_t this will print out the address
with 8 or 16 hexadecimal digits following a 0x prefix.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 14 additions and 2 deletions Side-by-side Diff

... ... @@ -515,6 +515,8 @@
515 515 static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
516 516 int field_width, int precision, int flags)
517 517 {
  518 + u64 num = (uintptr_t)ptr;
  519 +
518 520 /*
519 521 * Being a boot loader, we explicitly allow pointers to
520 522 * (physical) address null.
... ... @@ -527,6 +529,17 @@
527 529  
528 530 #ifdef CONFIG_CMD_NET
529 531 switch (*fmt) {
  532 + case 'a':
  533 + flags |= SPECIAL | ZEROPAD;
  534 +
  535 + switch (fmt[1]) {
  536 + case 'p':
  537 + default:
  538 + field_width = sizeof(phys_addr_t) * 2 + 2;
  539 + num = *(phys_addr_t *)ptr;
  540 + break;
  541 + }
  542 + break;
530 543 case 'm':
531 544 flags |= SPECIAL;
532 545 /* Fallthrough */
... ... @@ -552,8 +565,7 @@
552 565 field_width = 2*sizeof(void *);
553 566 flags |= ZEROPAD;
554 567 }
555   - return number(buf, end, (unsigned long)ptr, 16, field_width,
556   - precision, flags);
  568 + return number(buf, end, num, 16, field_width, precision, flags);
557 569 }
558 570  
559 571 static int vsnprintf_internal(char *buf, size_t size, const char *fmt,