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>
|
2022-07-31 18:28:48 +00:00
|
|
|
#include <display_options.h>
|
2015-04-29 13:56:43 +00:00
|
|
|
#include <div64.h>
|
2021-08-02 13:18:31 +00:00
|
|
|
#include <version_string.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) {
|
2021-08-05 21:22:58 +00:00
|
|
|
/*
|
|
|
|
* SPL tiny-printf is not capable for printing uint64_t.
|
|
|
|
* We have just checked that the size is small enought to fit
|
|
|
|
* unsigned int safely.
|
|
|
|
*/
|
|
|
|
printf("%u Bytes%s", (unsigned int)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;
|
2022-09-12 19:02:27 +00:00
|
|
|
|
|
|
|
if (n == 1024 && i > 0) {
|
|
|
|
n = 1;
|
|
|
|
m = 0;
|
|
|
|
c = names[i - 1];
|
|
|
|
}
|
2008-07-09 16:09:41 +00:00
|
|
|
}
|
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
|
|
|
|
2021-05-08 13:00:05 +00:00
|
|
|
#define MAX_LINE_LENGTH_BYTES 64
|
|
|
|
#define DEFAULT_LINE_LENGTH_BYTES 16
|
|
|
|
|
|
|
|
int hexdump_line(ulong addr, const void *data, uint width, uint count,
|
|
|
|
uint linelen, char *out, int size)
|
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;
|
2021-05-08 13:00:05 +00:00
|
|
|
uint thislinelen;
|
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
|
|
|
|
2021-05-08 13:00:05 +00:00
|
|
|
if (linelen * width > MAX_LINE_LENGTH_BYTES)
|
|
|
|
linelen = MAX_LINE_LENGTH_BYTES / width;
|
|
|
|
if (linelen < 1)
|
|
|
|
linelen = DEFAULT_LINE_LENGTH_BYTES / width;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the size here so that we don't need to use snprintf(). This
|
|
|
|
* helps to reduce code size
|
|
|
|
*/
|
|
|
|
if (size < HEXDUMP_MAX_BUF_LENGTH(linelen * width))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
thislinelen = linelen;
|
|
|
|
out += sprintf(out, "%08lx:", addr);
|
|
|
|
|
|
|
|
/* check for overflow condition */
|
|
|
|
if (count < thislinelen)
|
|
|
|
thislinelen = count;
|
|
|
|
|
|
|
|
/* Copy from memory into linebuf and print hex values */
|
|
|
|
for (i = 0; i < thislinelen; i++) {
|
|
|
|
if (width == 4)
|
|
|
|
x = lb.ui[i] = *(volatile uint32_t *)data;
|
|
|
|
else if (MEM_SUPPORT_64BIT_DATA && width == 8)
|
|
|
|
x = lb.uq[i] = *(volatile ulong *)data;
|
|
|
|
else if (width == 2)
|
|
|
|
x = lb.us[i] = *(volatile uint16_t *)data;
|
|
|
|
else
|
|
|
|
x = lb.uc[i] = *(volatile uint8_t *)data;
|
|
|
|
if (CONFIG_IS_ENABLED(USE_TINY_PRINTF))
|
|
|
|
out += sprintf(out, " %x", (uint)x);
|
|
|
|
else
|
|
|
|
out += sprintf(out, " %0*lx", width * 2, x);
|
|
|
|
data += width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill line with whitespace for nice ASCII print */
|
|
|
|
for (i = 0; i < (linelen - thislinelen) * (width * 2 + 1); i++)
|
|
|
|
*out++ = ' ';
|
|
|
|
|
|
|
|
/* Print data in ASCII characters */
|
|
|
|
for (i = 0; i < thislinelen * width; i++) {
|
|
|
|
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
|
|
|
|
lb.uc[i] = '.';
|
|
|
|
}
|
|
|
|
lb.uc[i] = '\0';
|
|
|
|
out += sprintf(out, " %s", lb.uc);
|
|
|
|
|
|
|
|
return thislinelen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int print_buffer(ulong addr, const void *data, uint width, uint count,
|
|
|
|
uint linelen)
|
|
|
|
{
|
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) {
|
2021-05-08 13:00:05 +00:00
|
|
|
uint thislinelen;
|
|
|
|
char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
|
2007-02-20 08:05:00 +00:00
|
|
|
|
2021-05-08 13:00:05 +00:00
|
|
|
thislinelen = hexdump_line(addr, data, width, count, linelen,
|
|
|
|
buf, sizeof(buf));
|
|
|
|
assert(thislinelen >= 0);
|
|
|
|
puts(buf);
|
|
|
|
putc('\n');
|
2007-02-20 08:05:00 +00:00
|
|
|
|
|
|
|
/* update references */
|
2021-05-08 13:00:05 +00:00
|
|
|
data += thislinelen * width;
|
2013-02-07 04:58:19 +00:00
|
|
|
addr += thislinelen * width;
|
|
|
|
count -= thislinelen;
|
2007-02-20 08:05:00 +00:00
|
|
|
|
2021-05-08 13:00:05 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())
|
|
|
|
return -EINTR;
|
2007-02-20 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|