1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
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
137 int hexdump_line(ulong addr, const void *data, uint width, uint count,
138 uint linelen, char *out, int size)
140 /* linebuf as a union causes proper alignment */
142 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];
151 if (linelen * width > MAX_LINE_LENGTH_BYTES)
152 linelen = MAX_LINE_LENGTH_BYTES / width;
154 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
157 * Check the size here so that we don't need to use snprintf(). This
158 * helps to reduce code size
160 if (size < HEXDUMP_MAX_BUF_LENGTH(linelen * width))
163 thislinelen = linelen;
164 out += sprintf(out, "%08lx:", addr);
166 /* check for overflow condition */
167 if (count < thislinelen)
170 /* Copy from memory into linebuf and print hex values */
171 for (i = 0; i < thislinelen; i++) {
173 x = lb.ui[i] = *(volatile uint32_t *)data;
174 else if (MEM_SUPPORT_64BIT_DATA && width == 8)
175 x = lb.uq[i] = *(volatile ulong *)data;
177 x = lb.us[i] = *(volatile uint16_t *)data;
179 x = lb.uc[i] = *(volatile uint8_t *)data;
180 if (CONFIG_IS_ENABLED(USE_TINY_PRINTF))
181 out += sprintf(out, " %x", (uint)x);
183 out += sprintf(out, " %0*lx", width * 2, x);
187 /* fill line with whitespace for nice ASCII print */
188 for (i = 0; i < (linelen - thislinelen) * (width * 2 + 1); i++)
191 /* Print data in ASCII characters */
192 for (i = 0; i < thislinelen * width; i++) {
193 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
197 out += sprintf(out, " %s", lb.uc);
202 int print_buffer(ulong addr, const void *data, uint width, uint count,
205 if (linelen*width > MAX_LINE_LENGTH_BYTES)
206 linelen = MAX_LINE_LENGTH_BYTES / width;
208 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
212 char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
214 thislinelen = hexdump_line(addr, data, width, count, linelen,
216 assert(thislinelen >= 0);
220 /* update references */
221 data += thislinelen * width;
222 addr += thislinelen * width;
223 count -= thislinelen;
225 if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())