2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <linux/ctype.h>
29 int display_options (void)
31 extern char version_string[];
33 #if defined(BUILD_TAG)
34 printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
36 printf ("\n\n%s\n\n", version_string);
42 * print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
43 * xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string
46 void print_size(unsigned long long size, const char *s)
48 unsigned long m = 0, n;
50 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
51 unsigned long d = 10 * ARRAY_SIZE(names);
55 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
63 printf("%llu Bytes%s", size, s);
68 f = size & ((1ULL << d) - 1);
70 /* If there's a remainder, deal with it */
72 m = (10ULL * f + (1ULL << (d - 1))) >> d;
84 printf (" %ciB%s", c, s);
88 * Print data buffer in hex and ascii form to the terminal.
90 * data reads are buffered so that each memory address is only read once.
91 * Useful when displaying the contents of volatile registers.
94 * addr: Starting address to display at start of line
95 * data: pointer to data buffer
96 * width: data value width. May be 1, 2, or 4.
97 * count: number of values to display
98 * linelen: Number of values to print per line; specify 0 for default length
100 #define MAX_LINE_LENGTH_BYTES (64)
101 #define DEFAULT_LINE_LENGTH_BYTES (16)
102 int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen)
104 uint8_t linebuf[MAX_LINE_LENGTH_BYTES];
105 uint32_t *uip = (void*)linebuf;
106 uint16_t *usp = (void*)linebuf;
107 uint8_t *ucp = (void*)linebuf;
110 if (linelen*width > MAX_LINE_LENGTH_BYTES)
111 linelen = MAX_LINE_LENGTH_BYTES / width;
113 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
116 printf("%08lx:", addr);
118 /* check for overflow condition */
122 /* Copy from memory into linebuf and print hex values */
123 for (i = 0; i < linelen; i++) {
125 uip[i] = *(volatile uint32_t *)data;
126 printf(" %08x", uip[i]);
127 } else if (width == 2) {
128 usp[i] = *(volatile uint16_t *)data;
129 printf(" %04x", usp[i]);
131 ucp[i] = *(volatile uint8_t *)data;
132 printf(" %02x", ucp[i]);
137 /* Print data in ASCII characters */
139 for (i = 0; i < linelen * width; i++)
140 putc(isprint(ucp[i]) && (ucp[i] < 0x80) ? ucp[i] : '.');
143 /* update references */
144 addr += linelen * width;