2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/ctype.h>
16 char *display_options_get_banner_priv(bool newlines, const char *build_tag,
21 len = snprintf(buf, size, "%s%s", newlines ? "\n\n" : "",
23 if (build_tag && len < size)
24 len += snprintf(buf + len, size - len, ", Build: %s",
28 strcpy(buf + len, "\n\n");
34 #define BUILD_TAG NULL
37 char *display_options_get_banner(bool newlines, char *buf, int size)
39 return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size);
42 int display_options(void)
44 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
46 display_options_get_banner(true, buf, sizeof(buf));
52 void print_freq(uint64_t freq, const char *s)
56 static const char names[] = {'G', 'M', 'K'};
57 unsigned long d = 1e9;
61 for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) {
69 printf("%" PRIu64 " Hz%s", freq, s);
75 /* If there's a remainder, show the first few digits */
80 while (m && !(m % 10))
83 m = (m / 10) + (m % 100 >= 50);
86 printf("%lu", (unsigned long) freq);
89 printf(" %cHz%s", c, s);
92 void print_size(uint64_t size, const char *s)
94 unsigned long m = 0, n;
96 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
97 unsigned long d = 10 * ARRAY_SIZE(names);
101 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
109 printf("%" PRIu64 " Bytes%s", size, s);
114 f = size & ((1ULL << d) - 1);
116 /* If there's a remainder, deal with it */
118 m = (10ULL * f + (1ULL << (d - 1))) >> d;
130 printf (" %ciB%s", c, s);
133 #define MAX_LINE_LENGTH_BYTES (64)
134 #define DEFAULT_LINE_LENGTH_BYTES (16)
135 int print_buffer(ulong addr, const void *data, uint width, uint count,
138 /* linebuf as a union causes proper alignment */
140 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
141 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
143 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
144 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
145 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
148 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
149 uint64_t __maybe_unused x;
151 uint32_t __maybe_unused x;
154 if (linelen*width > MAX_LINE_LENGTH_BYTES)
155 linelen = MAX_LINE_LENGTH_BYTES / width;
157 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
160 uint thislinelen = linelen;
161 printf("%08lx:", addr);
163 /* check for overflow condition */
164 if (count < thislinelen)
167 /* Copy from memory into linebuf and print hex values */
168 for (i = 0; i < thislinelen; i++) {
170 x = lb.ui[i] = *(volatile uint32_t *)data;
171 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
173 x = lb.uq[i] = *(volatile uint64_t *)data;
176 x = lb.us[i] = *(volatile uint16_t *)data;
178 x = lb.uc[i] = *(volatile uint8_t *)data;
179 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
180 printf(" %0*llx", width * 2, (long long)x);
182 printf(" %0*x", width * 2, x);
187 while (thislinelen < linelen) {
188 /* fill line with whitespace for nice ASCII print */
189 for (i=0; i<width*2+1; i++)
194 /* Print data in ASCII characters */
195 for (i = 0; i < thislinelen * width; i++) {
196 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
200 printf(" %s\n", lb.uc);
202 /* update references */
203 addr += thislinelen * width;
204 count -= thislinelen;