2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/ctype.h>
15 int display_options (void)
17 #if defined(BUILD_TAG)
18 printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
20 printf ("\n\n%s\n\n", version_string);
25 void print_size(uint64_t size, const char *s)
27 unsigned long m = 0, n;
29 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
30 unsigned long d = 10 * ARRAY_SIZE(names);
34 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
42 printf("%" PRIu64 " Bytes%s", size, s);
47 f = size & ((1ULL << d) - 1);
49 /* If there's a remainder, deal with it */
51 m = (10ULL * f + (1ULL << (d - 1))) >> d;
63 printf (" %ciB%s", c, s);
67 * Print data buffer in hex and ascii form to the terminal.
69 * data reads are buffered so that each memory address is only read once.
70 * Useful when displaying the contents of volatile registers.
73 * addr: Starting address to display at start of line
74 * data: pointer to data buffer
75 * width: data value width. May be 1, 2, or 4.
76 * count: number of values to display
77 * linelen: Number of values to print per line; specify 0 for default length
79 #define MAX_LINE_LENGTH_BYTES (64)
80 #define DEFAULT_LINE_LENGTH_BYTES (16)
81 int print_buffer(ulong addr, const void *data, uint width, uint count,
84 /* linebuf as a union causes proper alignment */
86 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
87 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
89 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
90 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
91 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
94 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
100 if (linelen*width > MAX_LINE_LENGTH_BYTES)
101 linelen = MAX_LINE_LENGTH_BYTES / width;
103 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
106 uint thislinelen = linelen;
107 printf("%08lx:", addr);
109 /* check for overflow condition */
110 if (count < thislinelen)
113 /* Copy from memory into linebuf and print hex values */
114 for (i = 0; i < thislinelen; i++) {
116 x = lb.ui[i] = *(volatile uint32_t *)data;
117 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
119 x = lb.uq[i] = *(volatile uint64_t *)data;
122 x = lb.us[i] = *(volatile uint16_t *)data;
124 x = lb.uc[i] = *(volatile uint8_t *)data;
125 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
126 printf(" %0*" PRIx64, width * 2, x);
128 printf(" %0*x", width * 2, x);
133 while (thislinelen < linelen) {
134 /* fill line with whitespace for nice ASCII print */
135 for (i=0; i<width*2+1; i++)
140 /* Print data in ASCII characters */
141 for (i = 0; i < thislinelen * width; i++) {
142 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
146 printf(" %s\n", lb.uc);
148 /* update references */
149 addr += thislinelen * width;
150 count -= thislinelen;