Blame view
lib/display_options.c
4.33 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0+ |
20e0e2331
|
2 3 4 |
/* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
20e0e2331
|
5 6 7 |
*/ #include <common.h> |
24b852a7a
|
8 |
#include <console.h> |
33eac2dc2
|
9 |
#include <div64.h> |
09c2e90c1
|
10 |
#include <version.h> |
c95c4280d
|
11 12 |
#include <linux/ctype.h> #include <asm/io.h> |
20e0e2331
|
13 |
|
6c519f2dc
|
14 15 |
char *display_options_get_banner_priv(bool newlines, const char *build_tag, char *buf, int size) |
20e0e2331
|
16 |
{ |
6c519f2dc
|
17 18 19 20 21 22 23 24 25 26 27 |
int len; len = snprintf(buf, size, "%s%s", newlines ? " " : "", version_string); if (build_tag && len < size) len += snprintf(buf + len, size - len, ", Build: %s", build_tag); if (len > size - 3) len = size - 3; |
6c74e94a6
|
28 29 30 31 32 |
if (len < 0) len = 0; snprintf(buf + len, size - len, " "); |
6c519f2dc
|
33 34 35 36 37 38 |
return buf; } #ifndef BUILD_TAG #define BUILD_TAG NULL |
20e0e2331
|
39 |
#endif |
6c519f2dc
|
40 41 42 43 44 45 46 47 48 49 50 51 |
char *display_options_get_banner(bool newlines, char *buf, int size) { return display_options_get_banner_priv(newlines, BUILD_TAG, buf, size); } int display_options(void) { char buf[DISPLAY_OPTIONS_BANNER_LENGTH]; display_options_get_banner(true, buf, sizeof(buf)); printf("%s", buf); |
20e0e2331
|
52 53 |
return 0; } |
33eac2dc2
|
54 55 |
void print_freq(uint64_t freq, const char *s) { |
80402f34f
|
56 |
unsigned long m = 0; |
33eac2dc2
|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
uint32_t f; static const char names[] = {'G', 'M', 'K'}; unsigned long d = 1e9; char c = 0; unsigned int i; for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) { if (freq >= d) { c = names[i]; break; } } if (!c) { |
dee37fc99
|
71 |
printf("%llu Hz%s", freq, s); |
33eac2dc2
|
72 73 74 75 |
return; } f = do_div(freq, d); |
33eac2dc2
|
76 77 78 79 80 81 82 83 84 85 86 |
/* If there's a remainder, show the first few digits */ if (f) { m = f; while (m > 1000) m /= 10; while (m && !(m % 10)) m /= 10; if (m >= 100) m = (m / 10) + (m % 100 >= 50); } |
e9015b304
|
87 |
printf("%lu", (unsigned long) freq); |
33eac2dc2
|
88 89 90 91 |
if (m) printf(".%ld", m); printf(" %cHz%s", c, s); } |
c6da9ae8a
|
92 |
void print_size(uint64_t size, const char *s) |
20e0e2331
|
93 |
{ |
52dbac69c
|
94 |
unsigned long m = 0, n; |
c6da9ae8a
|
95 |
uint64_t f; |
4b42c9059
|
96 |
static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; |
f2d76ae4f
|
97 |
unsigned long d = 10 * ARRAY_SIZE(names); |
4b42c9059
|
98 99 |
char c = 0; unsigned int i; |
20e0e2331
|
100 |
|
f2d76ae4f
|
101 102 |
for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) { if (size >> d) { |
4b42c9059
|
103 104 |
c = names[i]; break; |
417faf285
|
105 |
} |
20e0e2331
|
106 |
} |
4b42c9059
|
107 |
if (!c) { |
dee37fc99
|
108 |
printf("%llu Bytes%s", size, s); |
4b42c9059
|
109 110 |
return; } |
f2d76ae4f
|
111 112 |
n = size >> d; f = size & ((1ULL << d) - 1); |
20e0e2331
|
113 |
|
417faf285
|
114 |
/* If there's a remainder, deal with it */ |
f2d76ae4f
|
115 116 |
if (f) { m = (10ULL * f + (1ULL << (d - 1))) >> d; |
20e0e2331
|
117 |
|
417faf285
|
118 119 120 121 |
if (m >= 10) { m -= 10; n += 1; } |
0d4983930
|
122 |
} |
4b42c9059
|
123 |
printf ("%lu", n); |
20e0e2331
|
124 125 126 |
if (m) { printf (".%ld", m); } |
4b42c9059
|
127 |
printf (" %ciB%s", c, s); |
20e0e2331
|
128 |
} |
c95c4280d
|
129 |
|
c95c4280d
|
130 131 |
#define MAX_LINE_LENGTH_BYTES (64) #define DEFAULT_LINE_LENGTH_BYTES (16) |
bda32ffcf
|
132 133 |
int print_buffer(ulong addr, const void *data, uint width, uint count, uint linelen) |
c95c4280d
|
134 |
{ |
150f72366
|
135 136 |
/* linebuf as a union causes proper alignment */ union linebuf { |
4d979bfdb
|
137 |
#ifdef MEM_SUPPORT_64BIT_DATA |
4d1fd7f1a
|
138 139 |
uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1]; #endif |
150f72366
|
140 141 142 143 |
uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1]; uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1]; uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1]; } lb; |
c95c4280d
|
144 |
int i; |
4d979bfdb
|
145 |
#ifdef MEM_SUPPORT_64BIT_DATA |
80402f34f
|
146 |
uint64_t __maybe_unused x; |
4d1fd7f1a
|
147 |
#else |
80402f34f
|
148 |
uint32_t __maybe_unused x; |
4d1fd7f1a
|
149 |
#endif |
c95c4280d
|
150 151 152 153 154 155 156 |
if (linelen*width > MAX_LINE_LENGTH_BYTES) linelen = MAX_LINE_LENGTH_BYTES / width; if (linelen < 1) linelen = DEFAULT_LINE_LENGTH_BYTES / width; while (count) { |
efd7c1140
|
157 |
uint thislinelen = linelen; |
c95c4280d
|
158 159 160 |
printf("%08lx:", addr); /* check for overflow condition */ |
efd7c1140
|
161 162 |
if (count < thislinelen) thislinelen = count; |
c95c4280d
|
163 164 |
/* Copy from memory into linebuf and print hex values */ |
efd7c1140
|
165 |
for (i = 0; i < thislinelen; i++) { |
64419e475
|
166 |
if (width == 4) |
150f72366
|
167 |
x = lb.ui[i] = *(volatile uint32_t *)data; |
4d979bfdb
|
168 |
#ifdef MEM_SUPPORT_64BIT_DATA |
4d1fd7f1a
|
169 170 171 |
else if (width == 8) x = lb.uq[i] = *(volatile uint64_t *)data; #endif |
64419e475
|
172 |
else if (width == 2) |
150f72366
|
173 |
x = lb.us[i] = *(volatile uint16_t *)data; |
64419e475
|
174 |
else |
150f72366
|
175 |
x = lb.uc[i] = *(volatile uint8_t *)data; |
f60662de7
|
176 177 |
#if defined(CONFIG_SPL_BUILD) printf(" %x", (uint)x); |
4d979bfdb
|
178 |
#elif defined(MEM_SUPPORT_64BIT_DATA) |
66da9beb6
|
179 |
printf(" %0*llx", width * 2, (long long)x); |
4d1fd7f1a
|
180 |
#else |
64419e475
|
181 |
printf(" %0*x", width * 2, x); |
4d1fd7f1a
|
182 |
#endif |
c95c4280d
|
183 184 |
data += width; } |
efd7c1140
|
185 186 187 188 189 190 |
while (thislinelen < linelen) { /* fill line with whitespace for nice ASCII print */ for (i=0; i<width*2+1; i++) puts(" "); linelen--; } |
c95c4280d
|
191 |
/* Print data in ASCII characters */ |
efd7c1140
|
192 |
for (i = 0; i < thislinelen * width; i++) { |
150f72366
|
193 194 195 196 197 198 |
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) lb.uc[i] = '.'; } lb.uc[i] = '\0'; printf(" %s ", lb.uc); |
c95c4280d
|
199 200 |
/* update references */ |
efd7c1140
|
201 202 |
addr += thislinelen * width; count -= thislinelen; |
c95c4280d
|
203 |
|
9bb746d81
|
204 |
#ifndef CONFIG_SPL_BUILD |
c95c4280d
|
205 206 |
if (ctrlc()) return -1; |
9bb746d81
|
207 |
#endif |
c95c4280d
|
208 209 210 211 |
} return 0; } |