2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-09-08 16:09:41 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-06-08 02:33:00 +00:00
|
|
|
#include <compiler.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2015-04-29 13:56:43 +00:00
|
|
|
#include <div64.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
|
|
|
|
2017-06-16 18:51:42 +00:00
|
|
|
char *display_options_get_banner_priv(bool newlines, const char *build_tag,
|
|
|
|
char *buf, int size)
|
2002-09-08 16:09:41 +00:00
|
|
|
{
|
2017-06-16 18:51:42 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(buf, size, "%s%s", newlines ? "\n\n" : "",
|
|
|
|
version_string);
|
|
|
|
if (build_tag && len < size)
|
|
|
|
len += snprintf(buf + len, size - len, ", Build: %s",
|
|
|
|
build_tag);
|
|
|
|
if (len > size - 3)
|
|
|
|
len = size - 3;
|
2019-04-26 16:39:00 +00:00
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
|
|
|
snprintf(buf + len, size - len, "\n\n");
|
2017-06-16 18:51:42 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef BUILD_TAG
|
|
|
|
#define BUILD_TAG NULL
|
2002-09-08 16:09:41 +00:00
|
|
|
#endif
|
2017-06-16 18:51:42 +00:00
|
|
|
|
|
|
|
char *display_options_get_banner(bool newlines, char *buf, int size)
|
|
|
|
{
|
|
|
|
return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_options(void)
|
|
|
|
{
|
|
|
|
char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
|
|
|
|
|
|
|
|
display_options_get_banner(true, buf, sizeof(buf));
|
|
|
|
printf("%s", buf);
|
|
|
|
|
2002-09-08 16:09:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-29 13:56:43 +00:00
|
|
|
void print_freq(uint64_t freq, const char *s)
|
|
|
|
{
|
2015-06-29 07:10:46 +00:00
|
|
|
unsigned long m = 0;
|
2015-04-29 13:56:43 +00:00
|
|
|
uint32_t f;
|
2020-10-08 20:23:23 +00:00
|
|
|
static const char names[] = {'G', 'M', 'k'};
|
2015-04-29 13:56:43 +00:00
|
|
|
unsigned long d = 1e9;
|
|
|
|
char c = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) {
|
|
|
|
if (freq >= d) {
|
|
|
|
c = names[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!c) {
|
2018-08-06 11:47:40 +00:00
|
|
|
printf("%llu Hz%s", freq, s);
|
2015-04-29 13:56:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
f = do_div(freq, d);
|
|
|
|
|
|
|
|
/* If there's a remainder, show the first few digits */
|
|
|
|
if (f) {
|
|
|
|
m = f;
|
|
|
|
while (m > 1000)
|
|
|
|
m /= 10;
|
|
|
|
while (m && !(m % 10))
|
|
|
|
m /= 10;
|
|
|
|
if (m >= 100)
|
|
|
|
m = (m / 10) + (m % 100 >= 50);
|
|
|
|
}
|
|
|
|
|
2015-08-18 16:25:33 +00:00
|
|
|
printf("%lu", (unsigned long) freq);
|
2015-04-29 13:56:43 +00:00
|
|
|
if (m)
|
|
|
|
printf(".%ld", m);
|
|
|
|
printf(" %cHz%s", c, s);
|
|
|
|
}
|
|
|
|
|
2014-10-15 10:38:35 +00:00
|
|
|
void print_size(uint64_t 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;
|
2014-10-15 10:38:35 +00:00
|
|
|
uint64_t 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) {
|
2018-08-06 11:47:40 +00:00
|
|
|
printf("%llu Bytes%s", size, s);
|
2010-04-13 18:16:03 +00:00
|
|
|
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
|
|
|
|
|
|
|
#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
|
|
|
uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
|
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;
|
2020-06-03 01:26:47 +00:00
|
|
|
ulong x;
|
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;
|
2020-06-03 01:26:47 +00:00
|
|
|
else if (MEM_SUPPORT_64BIT_DATA && width == 8)
|
|
|
|
x = lb.uq[i] = *(volatile ulong *)data;
|
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;
|
2019-01-21 21:53:18 +00:00
|
|
|
#if defined(CONFIG_SPL_BUILD)
|
|
|
|
printf(" %x", (uint)x);
|
2014-02-27 01:03:19 +00:00
|
|
|
#else
|
2020-06-03 01:26:47 +00:00
|
|
|
printf(" %0*lx", 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
|
|
|
|
2019-09-25 14:11:16 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2007-02-20 08:05:00 +00:00
|
|
|
if (ctrlc())
|
|
|
|
return -1;
|
2019-09-25 14:11:16 +00:00
|
|
|
#endif
|
2007-02-20 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|