]>
Commit | Line | Data |
---|---|---|
20e0e233 WD |
1 | /* |
2 | * (C) Copyright 2000-2002 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
20e0e233 WD |
6 | */ |
7 | ||
c95c4280 | 8 | #include <config.h> |
20e0e233 | 9 | #include <common.h> |
33eac2dc | 10 | #include <div64.h> |
c6da9ae8 | 11 | #include <inttypes.h> |
09c2e90c | 12 | #include <version.h> |
c95c4280 GL |
13 | #include <linux/ctype.h> |
14 | #include <asm/io.h> | |
20e0e233 WD |
15 | |
16 | int display_options (void) | |
17 | { | |
20e0e233 WD |
18 | #if defined(BUILD_TAG) |
19 | printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG); | |
20 | #else | |
21 | printf ("\n\n%s\n\n", version_string); | |
22 | #endif | |
23 | return 0; | |
24 | } | |
25 | ||
33eac2dc SG |
26 | void print_freq(uint64_t freq, const char *s) |
27 | { | |
80402f34 HS |
28 | unsigned long m = 0; |
29 | #if defined(CONFIG_SPL_SERIAL_SUPPORT) | |
30 | unsigned long n; | |
31 | #endif | |
33eac2dc SG |
32 | uint32_t f; |
33 | static const char names[] = {'G', 'M', 'K'}; | |
34 | unsigned long d = 1e9; | |
35 | char c = 0; | |
36 | unsigned int i; | |
37 | ||
38 | for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) { | |
39 | if (freq >= d) { | |
40 | c = names[i]; | |
41 | break; | |
42 | } | |
43 | } | |
44 | ||
45 | if (!c) { | |
46 | printf("%" PRIu64 " Hz%s", freq, s); | |
47 | return; | |
48 | } | |
49 | ||
50 | f = do_div(freq, d); | |
80402f34 | 51 | #if defined(CONFIG_SPL_SERIAL_SUPPORT) |
33eac2dc | 52 | n = freq; |
80402f34 | 53 | #endif |
33eac2dc SG |
54 | |
55 | /* If there's a remainder, show the first few digits */ | |
56 | if (f) { | |
57 | m = f; | |
58 | while (m > 1000) | |
59 | m /= 10; | |
60 | while (m && !(m % 10)) | |
61 | m /= 10; | |
62 | if (m >= 100) | |
63 | m = (m / 10) + (m % 100 >= 50); | |
64 | } | |
65 | ||
80402f34 | 66 | #if defined(CONFIG_SPL_SERIAL_SUPPORT) |
33eac2dc | 67 | printf("%lu", n); |
80402f34 | 68 | #endif |
33eac2dc SG |
69 | if (m) |
70 | printf(".%ld", m); | |
71 | printf(" %cHz%s", c, s); | |
72 | } | |
73 | ||
c6da9ae8 | 74 | void print_size(uint64_t size, const char *s) |
20e0e233 | 75 | { |
52dbac69 | 76 | unsigned long m = 0, n; |
c6da9ae8 | 77 | uint64_t f; |
4b42c905 | 78 | static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; |
f2d76ae4 | 79 | unsigned long d = 10 * ARRAY_SIZE(names); |
4b42c905 TT |
80 | char c = 0; |
81 | unsigned int i; | |
20e0e233 | 82 | |
f2d76ae4 NT |
83 | for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) { |
84 | if (size >> d) { | |
4b42c905 TT |
85 | c = names[i]; |
86 | break; | |
417faf28 | 87 | } |
20e0e233 WD |
88 | } |
89 | ||
4b42c905 | 90 | if (!c) { |
c6da9ae8 | 91 | printf("%" PRIu64 " Bytes%s", size, s); |
4b42c905 TT |
92 | return; |
93 | } | |
94 | ||
f2d76ae4 NT |
95 | n = size >> d; |
96 | f = size & ((1ULL << d) - 1); | |
20e0e233 | 97 | |
417faf28 | 98 | /* If there's a remainder, deal with it */ |
f2d76ae4 NT |
99 | if (f) { |
100 | m = (10ULL * f + (1ULL << (d - 1))) >> d; | |
20e0e233 | 101 | |
417faf28 BB |
102 | if (m >= 10) { |
103 | m -= 10; | |
104 | n += 1; | |
105 | } | |
0d498393 WD |
106 | } |
107 | ||
4b42c905 | 108 | printf ("%lu", n); |
20e0e233 WD |
109 | if (m) { |
110 | printf (".%ld", m); | |
111 | } | |
4b42c905 | 112 | printf (" %ciB%s", c, s); |
20e0e233 | 113 | } |
c95c4280 | 114 | |
c95c4280 GL |
115 | #define MAX_LINE_LENGTH_BYTES (64) |
116 | #define DEFAULT_LINE_LENGTH_BYTES (16) | |
bda32ffc SG |
117 | int print_buffer(ulong addr, const void *data, uint width, uint count, |
118 | uint linelen) | |
c95c4280 | 119 | { |
150f7236 RM |
120 | /* linebuf as a union causes proper alignment */ |
121 | union linebuf { | |
4d1fd7f1 YS |
122 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
123 | uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1]; | |
124 | #endif | |
150f7236 RM |
125 | uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1]; |
126 | uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1]; | |
127 | uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1]; | |
128 | } lb; | |
c95c4280 | 129 | int i; |
4d1fd7f1 | 130 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
80402f34 | 131 | uint64_t __maybe_unused x; |
4d1fd7f1 | 132 | #else |
80402f34 | 133 | uint32_t __maybe_unused x; |
4d1fd7f1 | 134 | #endif |
c95c4280 GL |
135 | |
136 | if (linelen*width > MAX_LINE_LENGTH_BYTES) | |
137 | linelen = MAX_LINE_LENGTH_BYTES / width; | |
138 | if (linelen < 1) | |
139 | linelen = DEFAULT_LINE_LENGTH_BYTES / width; | |
140 | ||
141 | while (count) { | |
efd7c114 | 142 | uint thislinelen = linelen; |
c95c4280 GL |
143 | printf("%08lx:", addr); |
144 | ||
145 | /* check for overflow condition */ | |
efd7c114 AB |
146 | if (count < thislinelen) |
147 | thislinelen = count; | |
c95c4280 GL |
148 | |
149 | /* Copy from memory into linebuf and print hex values */ | |
efd7c114 | 150 | for (i = 0; i < thislinelen; i++) { |
64419e47 | 151 | if (width == 4) |
150f7236 | 152 | x = lb.ui[i] = *(volatile uint32_t *)data; |
4d1fd7f1 YS |
153 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
154 | else if (width == 8) | |
155 | x = lb.uq[i] = *(volatile uint64_t *)data; | |
156 | #endif | |
64419e47 | 157 | else if (width == 2) |
150f7236 | 158 | x = lb.us[i] = *(volatile uint16_t *)data; |
64419e47 | 159 | else |
150f7236 | 160 | x = lb.uc[i] = *(volatile uint8_t *)data; |
4d1fd7f1 | 161 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
66da9beb | 162 | printf(" %0*llx", width * 2, (long long)x); |
4d1fd7f1 | 163 | #else |
64419e47 | 164 | printf(" %0*x", width * 2, x); |
4d1fd7f1 | 165 | #endif |
c95c4280 GL |
166 | data += width; |
167 | } | |
168 | ||
efd7c114 AB |
169 | while (thislinelen < linelen) { |
170 | /* fill line with whitespace for nice ASCII print */ | |
171 | for (i=0; i<width*2+1; i++) | |
172 | puts(" "); | |
173 | linelen--; | |
174 | } | |
175 | ||
c95c4280 | 176 | /* Print data in ASCII characters */ |
efd7c114 | 177 | for (i = 0; i < thislinelen * width; i++) { |
150f7236 RM |
178 | if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) |
179 | lb.uc[i] = '.'; | |
180 | } | |
181 | lb.uc[i] = '\0'; | |
182 | printf(" %s\n", lb.uc); | |
c95c4280 GL |
183 | |
184 | /* update references */ | |
efd7c114 AB |
185 | addr += thislinelen * width; |
186 | count -= thislinelen; | |
c95c4280 GL |
187 | |
188 | if (ctrlc()) | |
189 | return -1; | |
190 | } | |
191 | ||
192 | return 0; | |
193 | } |