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",
27 strcpy(buf + len, "\n\n");
33 #define BUILD_TAG NULL
36 char *display_options_get_banner(bool newlines, char *buf, int size)
38 return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size);
41 int display_options(void)
43 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
45 display_options_get_banner(true, buf, sizeof(buf));
51 void print_freq(uint64_t freq, const char *s)
55 static const char names[] = {'G', 'M', 'K'};
56 unsigned long d = 1e9;
60 for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) {
68 printf("%" PRIu64 " Hz%s", freq, s);
74 /* If there's a remainder, show the first few digits */
79 while (m && !(m % 10))
82 m = (m / 10) + (m % 100 >= 50);
85 printf("%lu", (unsigned long) freq);
88 printf(" %cHz%s", c, s);
91 void print_size(uint64_t size, const char *s)
93 unsigned long m = 0, n;
95 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
96 unsigned long d = 10 * ARRAY_SIZE(names);
100 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
108 printf("%" PRIu64 " Bytes%s", size, s);
113 f = size & ((1ULL << d) - 1);
115 /* If there's a remainder, deal with it */
117 m = (10ULL * f + (1ULL << (d - 1))) >> d;
129 printf (" %ciB%s", c, s);
132 #define MAX_LINE_LENGTH_BYTES (64)
133 #define DEFAULT_LINE_LENGTH_BYTES (16)
134 int print_buffer(ulong addr, const void *data, uint width, uint count,
137 /* linebuf as a union causes proper alignment */
139 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
140 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
142 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
143 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
144 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
147 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
148 uint64_t __maybe_unused x;
150 uint32_t __maybe_unused x;
153 if (linelen*width > MAX_LINE_LENGTH_BYTES)
154 linelen = MAX_LINE_LENGTH_BYTES / width;
156 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
159 uint thislinelen = linelen;
160 printf("%08lx:", addr);
162 /* check for overflow condition */
163 if (count < thislinelen)
166 /* Copy from memory into linebuf and print hex values */
167 for (i = 0; i < thislinelen; i++) {
169 x = lb.ui[i] = *(volatile uint32_t *)data;
170 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
172 x = lb.uq[i] = *(volatile uint64_t *)data;
175 x = lb.us[i] = *(volatile uint16_t *)data;
177 x = lb.uc[i] = *(volatile uint8_t *)data;
178 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
179 printf(" %0*llx", width * 2, (long long)x);
181 printf(" %0*x", width * 2, x);
186 while (thislinelen < linelen) {
187 /* fill line with whitespace for nice ASCII print */
188 for (i=0; i<width*2+1; i++)
193 /* Print data in ASCII characters */
194 for (i = 0; i < thislinelen * width; i++) {
195 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
199 printf(" %s\n", lb.uc);
201 /* update references */
202 addr += thislinelen * width;
203 count -= thislinelen;