2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/ctype.h>
14 int display_options (void)
16 #if defined(BUILD_TAG)
17 printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
19 printf ("\n\n%s\n\n", version_string);
25 * print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
26 * xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string
29 void print_size(unsigned long long size, const char *s)
31 unsigned long m = 0, n;
33 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
34 unsigned long d = 10 * ARRAY_SIZE(names);
38 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
46 printf("%llu Bytes%s", size, s);
51 f = size & ((1ULL << d) - 1);
53 /* If there's a remainder, deal with it */
55 m = (10ULL * f + (1ULL << (d - 1))) >> d;
67 printf (" %ciB%s", c, s);
71 * Print data buffer in hex and ascii form to the terminal.
73 * data reads are buffered so that each memory address is only read once.
74 * Useful when displaying the contents of volatile registers.
77 * addr: Starting address to display at start of line
78 * data: pointer to data buffer
79 * width: data value width. May be 1, 2, or 4.
80 * count: number of values to display
81 * linelen: Number of values to print per line; specify 0 for default length
83 #define MAX_LINE_LENGTH_BYTES (64)
84 #define DEFAULT_LINE_LENGTH_BYTES (16)
85 int print_buffer(ulong addr, const void *data, uint width, uint count,
88 /* linebuf as a union causes proper alignment */
90 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
91 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
93 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
94 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
95 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
98 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
104 if (linelen*width > MAX_LINE_LENGTH_BYTES)
105 linelen = MAX_LINE_LENGTH_BYTES / width;
107 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
110 uint thislinelen = linelen;
111 printf("%08lx:", addr);
113 /* check for overflow condition */
114 if (count < thislinelen)
117 /* Copy from memory into linebuf and print hex values */
118 for (i = 0; i < thislinelen; i++) {
120 x = lb.ui[i] = *(volatile uint32_t *)data;
121 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
123 x = lb.uq[i] = *(volatile uint64_t *)data;
126 x = lb.us[i] = *(volatile uint16_t *)data;
128 x = lb.uc[i] = *(volatile uint8_t *)data;
129 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
130 printf(" %0*llx", width * 2, x);
132 printf(" %0*x", width * 2, x);
137 while (thislinelen < linelen) {
138 /* fill line with whitespace for nice ASCII print */
139 for (i=0; i<width*2+1; i++)
144 /* Print data in ASCII characters */
145 for (i = 0; i < thislinelen * width; i++) {
146 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
150 printf(" %s\n", lb.uc);
152 /* update references */
153 addr += thislinelen * width;
154 count -= thislinelen;