1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
11 #include <version_string.h>
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) {
111 * SPL tiny-printf is not capable for printing uint64_t.
112 * We have just checked that the size is small enought to fit
113 * unsigned int safely.
115 printf("%u Bytes%s", (unsigned int)size, s);
120 f = size & ((1ULL << d) - 1);
122 /* If there's a remainder, deal with it */
124 m = (10ULL * f + (1ULL << (d - 1))) >> d;
136 printf (" %ciB%s", c, s);
139 #define MAX_LINE_LENGTH_BYTES 64
140 #define DEFAULT_LINE_LENGTH_BYTES 16
142 int hexdump_line(ulong addr, const void *data, uint width, uint count,
143 uint linelen, char *out, int size)
145 /* linebuf as a union causes proper alignment */
147 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
148 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
149 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
150 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
156 if (linelen * width > MAX_LINE_LENGTH_BYTES)
157 linelen = MAX_LINE_LENGTH_BYTES / width;
159 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
162 * Check the size here so that we don't need to use snprintf(). This
163 * helps to reduce code size
165 if (size < HEXDUMP_MAX_BUF_LENGTH(linelen * width))
168 thislinelen = linelen;
169 out += sprintf(out, "%08lx:", addr);
171 /* check for overflow condition */
172 if (count < thislinelen)
175 /* Copy from memory into linebuf and print hex values */
176 for (i = 0; i < thislinelen; i++) {
178 x = lb.ui[i] = *(volatile uint32_t *)data;
179 else if (MEM_SUPPORT_64BIT_DATA && width == 8)
180 x = lb.uq[i] = *(volatile ulong *)data;
182 x = lb.us[i] = *(volatile uint16_t *)data;
184 x = lb.uc[i] = *(volatile uint8_t *)data;
185 if (CONFIG_IS_ENABLED(USE_TINY_PRINTF))
186 out += sprintf(out, " %x", (uint)x);
188 out += sprintf(out, " %0*lx", width * 2, x);
192 /* fill line with whitespace for nice ASCII print */
193 for (i = 0; i < (linelen - thislinelen) * (width * 2 + 1); i++)
196 /* Print data in ASCII characters */
197 for (i = 0; i < thislinelen * width; i++) {
198 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
202 out += sprintf(out, " %s", lb.uc);
207 int print_buffer(ulong addr, const void *data, uint width, uint count,
210 if (linelen*width > MAX_LINE_LENGTH_BYTES)
211 linelen = MAX_LINE_LENGTH_BYTES / width;
213 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
217 char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
219 thislinelen = hexdump_line(addr, data, width, count, linelen,
221 assert(thislinelen >= 0);
225 /* update references */
226 data += thislinelen * width;
227 addr += thislinelen * width;
228 count -= thislinelen;
230 if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())