1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 #include <linux/ctype.h>
15 char *display_options_get_banner_priv(bool newlines, const char *build_tag,
20 len = snprintf(buf, size, "%s%s", newlines ? "\n\n" : "",
22 if (build_tag && len < size)
23 len += snprintf(buf + len, size - len, ", Build: %s",
29 snprintf(buf + len, size - len, "\n\n");
35 #define BUILD_TAG NULL
38 char *display_options_get_banner(bool newlines, char *buf, int size)
40 return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size);
43 int display_options(void)
45 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
47 display_options_get_banner(true, buf, sizeof(buf));
53 void print_freq(uint64_t freq, const char *s)
57 static const char names[] = {'G', 'M', 'K'};
58 unsigned long d = 1e9;
62 for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) {
70 printf("%llu Hz%s", freq, s);
76 /* If there's a remainder, show the first few digits */
81 while (m && !(m % 10))
84 m = (m / 10) + (m % 100 >= 50);
87 printf("%lu", (unsigned long) freq);
90 printf(" %cHz%s", c, s);
93 void print_size(uint64_t size, const char *s)
95 unsigned long m = 0, n;
97 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
98 unsigned long d = 10 * ARRAY_SIZE(names);
102 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
110 printf("%llu Bytes%s", size, s);
115 f = size & ((1ULL << d) - 1);
117 /* If there's a remainder, deal with it */
119 m = (10ULL * f + (1ULL << (d - 1))) >> d;
131 printf (" %ciB%s", c, s);
134 #define MAX_LINE_LENGTH_BYTES (64)
135 #define DEFAULT_LINE_LENGTH_BYTES (16)
136 int print_buffer(ulong addr, const void *data, uint width, uint count,
139 /* linebuf as a union causes proper alignment */
141 #if MEM_SUPPORT_64BIT_DATA
142 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
144 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
145 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
146 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
149 #if MEM_SUPPORT_64BIT_DATA
150 uint64_t __maybe_unused x;
152 uint32_t __maybe_unused x;
155 if (linelen*width > MAX_LINE_LENGTH_BYTES)
156 linelen = MAX_LINE_LENGTH_BYTES / width;
158 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
161 uint thislinelen = linelen;
162 printf("%08lx:", addr);
164 /* check for overflow condition */
165 if (count < thislinelen)
168 /* Copy from memory into linebuf and print hex values */
169 for (i = 0; i < thislinelen; i++) {
171 x = lb.ui[i] = *(volatile uint32_t *)data;
172 #if MEM_SUPPORT_64BIT_DATA
174 x = lb.uq[i] = *(volatile uint64_t *)data;
177 x = lb.us[i] = *(volatile uint16_t *)data;
179 x = lb.uc[i] = *(volatile uint8_t *)data;
180 #if defined(CONFIG_SPL_BUILD)
181 printf(" %x", (uint)x);
182 #elif defined(MEM_SUPPORT_64BIT_DATA)
183 printf(" %0*llx", width * 2, (long long)x);
185 printf(" %0*x", width * 2, x);
190 while (thislinelen < linelen) {
191 /* fill line with whitespace for nice ASCII print */
192 for (i=0; i<width*2+1; i++)
197 /* Print data in ASCII characters */
198 for (i = 0; i < thislinelen * width; i++) {
199 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
203 printf(" %s\n", lb.uc);
205 /* update references */
206 addr += thislinelen * width;
207 count -= thislinelen;
209 #ifndef CONFIG_SPL_BUILD