]>
Commit | Line | Data |
---|---|---|
20e0e233 WD |
1 | /* |
2 | * (C) Copyright 2000-2002 | |
3 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
20e0e233 WD |
6 | */ |
7 | ||
c95c4280 | 8 | #include <config.h> |
20e0e233 | 9 | #include <common.h> |
09c2e90c | 10 | #include <version.h> |
c95c4280 GL |
11 | #include <linux/ctype.h> |
12 | #include <asm/io.h> | |
20e0e233 WD |
13 | |
14 | int display_options (void) | |
15 | { | |
20e0e233 WD |
16 | #if defined(BUILD_TAG) |
17 | printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG); | |
18 | #else | |
19 | printf ("\n\n%s\n\n", version_string); | |
20 | #endif | |
21 | return 0; | |
22 | } | |
23 | ||
24 | /* | |
4b42c905 TT |
25 | * print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB", |
26 | * xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string | |
417faf28 | 27 | * (like "\n") |
20e0e233 | 28 | */ |
4b42c905 | 29 | void print_size(unsigned long long size, const char *s) |
20e0e233 | 30 | { |
52dbac69 | 31 | unsigned long m = 0, n; |
f2d76ae4 | 32 | unsigned long long f; |
4b42c905 | 33 | static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; |
f2d76ae4 | 34 | unsigned long d = 10 * ARRAY_SIZE(names); |
4b42c905 TT |
35 | char c = 0; |
36 | unsigned int i; | |
20e0e233 | 37 | |
f2d76ae4 NT |
38 | for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) { |
39 | if (size >> d) { | |
4b42c905 TT |
40 | c = names[i]; |
41 | break; | |
417faf28 | 42 | } |
20e0e233 WD |
43 | } |
44 | ||
4b42c905 TT |
45 | if (!c) { |
46 | printf("%llu Bytes%s", size, s); | |
47 | return; | |
48 | } | |
49 | ||
f2d76ae4 NT |
50 | n = size >> d; |
51 | f = size & ((1ULL << d) - 1); | |
20e0e233 | 52 | |
417faf28 | 53 | /* If there's a remainder, deal with it */ |
f2d76ae4 NT |
54 | if (f) { |
55 | m = (10ULL * f + (1ULL << (d - 1))) >> d; | |
20e0e233 | 56 | |
417faf28 BB |
57 | if (m >= 10) { |
58 | m -= 10; | |
59 | n += 1; | |
60 | } | |
0d498393 WD |
61 | } |
62 | ||
4b42c905 | 63 | printf ("%lu", n); |
20e0e233 WD |
64 | if (m) { |
65 | printf (".%ld", m); | |
66 | } | |
4b42c905 | 67 | printf (" %ciB%s", c, s); |
20e0e233 | 68 | } |
c95c4280 GL |
69 | |
70 | /* | |
71 | * Print data buffer in hex and ascii form to the terminal. | |
72 | * | |
73 | * data reads are buffered so that each memory address is only read once. | |
74 | * Useful when displaying the contents of volatile registers. | |
75 | * | |
76 | * parameters: | |
77 | * addr: Starting address to display at start of line | |
78 | * data: pointer to data buffer | |
79 | * width: data value width. May be 1, 2, or 4. | |
80 | * count: number of values to display | |
81 | * linelen: Number of values to print per line; specify 0 for default length | |
82 | */ | |
83 | #define MAX_LINE_LENGTH_BYTES (64) | |
84 | #define DEFAULT_LINE_LENGTH_BYTES (16) | |
bda32ffc SG |
85 | int print_buffer(ulong addr, const void *data, uint width, uint count, |
86 | uint linelen) | |
c95c4280 | 87 | { |
150f7236 RM |
88 | /* linebuf as a union causes proper alignment */ |
89 | union linebuf { | |
4d1fd7f1 YS |
90 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
91 | uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1]; | |
92 | #endif | |
150f7236 RM |
93 | uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1]; |
94 | uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1]; | |
95 | uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1]; | |
96 | } lb; | |
c95c4280 | 97 | int i; |
4d1fd7f1 YS |
98 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
99 | uint64_t x; | |
100 | #else | |
101 | uint32_t x; | |
102 | #endif | |
c95c4280 GL |
103 | |
104 | if (linelen*width > MAX_LINE_LENGTH_BYTES) | |
105 | linelen = MAX_LINE_LENGTH_BYTES / width; | |
106 | if (linelen < 1) | |
107 | linelen = DEFAULT_LINE_LENGTH_BYTES / width; | |
108 | ||
109 | while (count) { | |
efd7c114 | 110 | uint thislinelen = linelen; |
c95c4280 GL |
111 | printf("%08lx:", addr); |
112 | ||
113 | /* check for overflow condition */ | |
efd7c114 AB |
114 | if (count < thislinelen) |
115 | thislinelen = count; | |
c95c4280 GL |
116 | |
117 | /* Copy from memory into linebuf and print hex values */ | |
efd7c114 | 118 | for (i = 0; i < thislinelen; i++) { |
64419e47 | 119 | if (width == 4) |
150f7236 | 120 | x = lb.ui[i] = *(volatile uint32_t *)data; |
4d1fd7f1 YS |
121 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
122 | else if (width == 8) | |
123 | x = lb.uq[i] = *(volatile uint64_t *)data; | |
124 | #endif | |
64419e47 | 125 | else if (width == 2) |
150f7236 | 126 | x = lb.us[i] = *(volatile uint16_t *)data; |
64419e47 | 127 | else |
150f7236 | 128 | x = lb.uc[i] = *(volatile uint8_t *)data; |
4d1fd7f1 YS |
129 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
130 | printf(" %0*llx", width * 2, x); | |
131 | #else | |
64419e47 | 132 | printf(" %0*x", width * 2, x); |
4d1fd7f1 | 133 | #endif |
c95c4280 GL |
134 | data += width; |
135 | } | |
136 | ||
efd7c114 AB |
137 | while (thislinelen < linelen) { |
138 | /* fill line with whitespace for nice ASCII print */ | |
139 | for (i=0; i<width*2+1; i++) | |
140 | puts(" "); | |
141 | linelen--; | |
142 | } | |
143 | ||
c95c4280 | 144 | /* Print data in ASCII characters */ |
efd7c114 | 145 | for (i = 0; i < thislinelen * width; i++) { |
150f7236 RM |
146 | if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) |
147 | lb.uc[i] = '.'; | |
148 | } | |
149 | lb.uc[i] = '\0'; | |
150 | printf(" %s\n", lb.uc); | |
c95c4280 GL |
151 | |
152 | /* update references */ | |
efd7c114 AB |
153 | addr += thislinelen * width; |
154 | count -= thislinelen; | |
c95c4280 GL |
155 | |
156 | if (ctrlc()) | |
157 | return -1; | |
158 | } | |
159 | ||
160 | return 0; | |
161 | } |