2002-09-08 16:09:41 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-09-08 16:09:41 +00:00
|
|
|
*/
|
|
|
|
|
2007-02-20 08:05:00 +00:00
|
|
|
#include <config.h>
|
2002-09-08 16:09:41 +00:00
|
|
|
#include <common.h>
|
2011-07-18 18:24:04 +00:00
|
|
|
#include <version.h>
|
2007-02-20 08:05:00 +00:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <asm/io.h>
|
2002-09-08 16:09:41 +00:00
|
|
|
|
|
|
|
int display_options (void)
|
|
|
|
{
|
|
|
|
#if defined(BUILD_TAG)
|
|
|
|
printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
|
|
|
|
#else
|
|
|
|
printf ("\n\n%s\n\n", version_string);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-04-13 18:16:03 +00:00
|
|
|
* print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
|
|
|
|
* xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string
|
2008-07-09 16:09:41 +00:00
|
|
|
* (like "\n")
|
2002-09-08 16:09:41 +00:00
|
|
|
*/
|
2010-04-13 18:16:03 +00:00
|
|
|
void print_size(unsigned long long size, const char *s)
|
2002-09-08 16:09:41 +00:00
|
|
|
{
|
2010-04-13 18:16:02 +00:00
|
|
|
unsigned long m = 0, n;
|
2010-05-11 10:29:52 +00:00
|
|
|
unsigned long long f;
|
2010-04-13 18:16:03 +00:00
|
|
|
static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
|
2010-05-11 10:29:52 +00:00
|
|
|
unsigned long d = 10 * ARRAY_SIZE(names);
|
2010-04-13 18:16:03 +00:00
|
|
|
char c = 0;
|
|
|
|
unsigned int i;
|
2002-09-08 16:09:41 +00:00
|
|
|
|
2010-05-11 10:29:52 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
|
|
|
|
if (size >> d) {
|
2010-04-13 18:16:03 +00:00
|
|
|
c = names[i];
|
|
|
|
break;
|
2008-07-09 16:09:41 +00:00
|
|
|
}
|
2002-09-08 16:09:41 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 18:16:03 +00:00
|
|
|
if (!c) {
|
|
|
|
printf("%llu Bytes%s", size, s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:29:52 +00:00
|
|
|
n = size >> d;
|
|
|
|
f = size & ((1ULL << d) - 1);
|
2002-09-08 16:09:41 +00:00
|
|
|
|
2008-07-09 16:09:41 +00:00
|
|
|
/* If there's a remainder, deal with it */
|
2010-05-11 10:29:52 +00:00
|
|
|
if (f) {
|
|
|
|
m = (10ULL * f + (1ULL << (d - 1))) >> d;
|
2002-09-08 16:09:41 +00:00
|
|
|
|
2008-07-09 16:09:41 +00:00
|
|
|
if (m >= 10) {
|
|
|
|
m -= 10;
|
|
|
|
n += 1;
|
|
|
|
}
|
2003-07-01 21:06:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 18:16:03 +00:00
|
|
|
printf ("%lu", n);
|
2002-09-08 16:09:41 +00:00
|
|
|
if (m) {
|
|
|
|
printf (".%ld", m);
|
|
|
|
}
|
2010-04-13 18:16:03 +00:00
|
|
|
printf (" %ciB%s", c, s);
|
2002-09-08 16:09:41 +00:00
|
|
|
}
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print data buffer in hex and ascii form to the terminal.
|
|
|
|
*
|
|
|
|
* data reads are buffered so that each memory address is only read once.
|
|
|
|
* Useful when displaying the contents of volatile registers.
|
|
|
|
*
|
|
|
|
* parameters:
|
|
|
|
* addr: Starting address to display at start of line
|
|
|
|
* data: pointer to data buffer
|
|
|
|
* width: data value width. May be 1, 2, or 4.
|
|
|
|
* count: number of values to display
|
|
|
|
* linelen: Number of values to print per line; specify 0 for default length
|
|
|
|
*/
|
|
|
|
#define MAX_LINE_LENGTH_BYTES (64)
|
|
|
|
#define DEFAULT_LINE_LENGTH_BYTES (16)
|
2013-02-24 17:33:12 +00:00
|
|
|
int print_buffer(ulong addr, const void *data, uint width, uint count,
|
|
|
|
uint linelen)
|
2007-02-20 08:05:00 +00:00
|
|
|
{
|
2010-09-08 10:25:40 +00:00
|
|
|
/* linebuf as a union causes proper alignment */
|
|
|
|
union linebuf {
|
2014-02-27 01:03:19 +00:00
|
|
|
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
|
|
|
|
uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
|
|
|
|
#endif
|
2010-09-08 10:25:40 +00:00
|
|
|
uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
|
|
|
|
uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
|
|
|
|
uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
|
|
|
|
} lb;
|
2007-02-20 08:05:00 +00:00
|
|
|
int i;
|
2014-02-27 01:03:19 +00:00
|
|
|
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
|
|
|
|
uint64_t x;
|
|
|
|
#else
|
|
|
|
uint32_t x;
|
|
|
|
#endif
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
if (linelen*width > MAX_LINE_LENGTH_BYTES)
|
|
|
|
linelen = MAX_LINE_LENGTH_BYTES / width;
|
|
|
|
if (linelen < 1)
|
|
|
|
linelen = DEFAULT_LINE_LENGTH_BYTES / width;
|
|
|
|
|
|
|
|
while (count) {
|
2013-02-07 04:58:19 +00:00
|
|
|
uint thislinelen = linelen;
|
2007-02-20 08:05:00 +00:00
|
|
|
printf("%08lx:", addr);
|
|
|
|
|
|
|
|
/* check for overflow condition */
|
2013-02-07 04:58:19 +00:00
|
|
|
if (count < thislinelen)
|
|
|
|
thislinelen = count;
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
/* Copy from memory into linebuf and print hex values */
|
2013-02-07 04:58:19 +00:00
|
|
|
for (i = 0; i < thislinelen; i++) {
|
2010-07-23 10:17:30 +00:00
|
|
|
if (width == 4)
|
2010-09-08 10:25:40 +00:00
|
|
|
x = lb.ui[i] = *(volatile uint32_t *)data;
|
2014-02-27 01:03:19 +00:00
|
|
|
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
|
|
|
|
else if (width == 8)
|
|
|
|
x = lb.uq[i] = *(volatile uint64_t *)data;
|
|
|
|
#endif
|
2010-07-23 10:17:30 +00:00
|
|
|
else if (width == 2)
|
2010-09-08 10:25:40 +00:00
|
|
|
x = lb.us[i] = *(volatile uint16_t *)data;
|
2010-07-23 10:17:30 +00:00
|
|
|
else
|
2010-09-08 10:25:40 +00:00
|
|
|
x = lb.uc[i] = *(volatile uint8_t *)data;
|
2014-02-27 01:03:19 +00:00
|
|
|
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
|
|
|
|
printf(" %0*llx", width * 2, x);
|
|
|
|
#else
|
2010-07-23 10:17:30 +00:00
|
|
|
printf(" %0*x", width * 2, x);
|
2014-02-27 01:03:19 +00:00
|
|
|
#endif
|
2007-02-20 08:05:00 +00:00
|
|
|
data += width;
|
|
|
|
}
|
|
|
|
|
2013-02-07 04:58:19 +00:00
|
|
|
while (thislinelen < linelen) {
|
|
|
|
/* fill line with whitespace for nice ASCII print */
|
|
|
|
for (i=0; i<width*2+1; i++)
|
|
|
|
puts(" ");
|
|
|
|
linelen--;
|
|
|
|
}
|
|
|
|
|
2007-02-20 08:05:00 +00:00
|
|
|
/* Print data in ASCII characters */
|
2013-02-07 04:58:19 +00:00
|
|
|
for (i = 0; i < thislinelen * width; i++) {
|
2010-09-08 10:25:40 +00:00
|
|
|
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
|
|
|
|
lb.uc[i] = '.';
|
|
|
|
}
|
|
|
|
lb.uc[i] = '\0';
|
|
|
|
printf(" %s\n", lb.uc);
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
/* update references */
|
2013-02-07 04:58:19 +00:00
|
|
|
addr += thislinelen * width;
|
|
|
|
count -= thislinelen;
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
if (ctrlc())
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|