Blame view
lib/display_options.c
4.27 KB
20e0e2331 Initial revision |
1 2 3 4 |
/* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
20e0e2331 Initial revision |
6 7 8 |
*/ #include <common.h> |
24b852a7a Move console defi... |
9 |
#include <console.h> |
33eac2dc2 Add print_freq() ... |
10 |
#include <div64.h> |
c6da9ae8a Tidy up data size... |
11 |
#include <inttypes.h> |
09c2e90c1 unify version_string |
12 |
#include <version.h> |
c95c4280d [PATCH 3_9] Move ... |
13 14 |
#include <linux/ctype.h> #include <asm/io.h> |
20e0e2331 Initial revision |
15 |
|
6c519f2dc display_options: ... |
16 17 |
char *display_options_get_banner_priv(bool newlines, const char *build_tag, char *buf, int size) |
20e0e2331 Initial revision |
18 |
{ |
6c519f2dc display_options: ... |
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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; strcpy(buf + len, " "); return buf; } #ifndef BUILD_TAG #define BUILD_TAG NULL |
20e0e2331 Initial revision |
39 |
#endif |
6c519f2dc display_options: ... |
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 Initial revision |
52 53 |
return 0; } |
33eac2dc2 Add print_freq() ... |
54 55 |
void print_freq(uint64_t freq, const char *s) { |
80402f34f spl, common, seri... |
56 |
unsigned long m = 0; |
33eac2dc2 Add print_freq() ... |
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
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) { printf("%" PRIu64 " Hz%s", freq, s); return; } f = do_div(freq, d); |
33eac2dc2 Add print_freq() ... |
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 lib/display_optio... |
87 |
printf("%lu", (unsigned long) freq); |
33eac2dc2 Add print_freq() ... |
88 89 90 91 |
if (m) printf(".%ld", m); printf(" %cHz%s", c, s); } |
c6da9ae8a Tidy up data size... |
92 |
void print_size(uint64_t size, const char *s) |
20e0e2331 Initial revision |
93 |
{ |
52dbac69c fix print_size pr... |
94 |
unsigned long m = 0, n; |
c6da9ae8a Tidy up data size... |
95 |
uint64_t f; |
4b42c9059 allow print_size ... |
96 |
static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; |
f2d76ae4f Avoid use of divi... |
97 |
unsigned long d = 10 * ARRAY_SIZE(names); |
4b42c9059 allow print_size ... |
98 99 |
char c = 0; unsigned int i; |
20e0e2331 Initial revision |
100 |
|
f2d76ae4f Avoid use of divi... |
101 102 |
for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) { if (size >> d) { |
4b42c9059 allow print_size ... |
103 104 |
c = names[i]; break; |
417faf285 Allow print_size ... |
105 |
} |
20e0e2331 Initial revision |
106 |
} |
4b42c9059 allow print_size ... |
107 |
if (!c) { |
c6da9ae8a Tidy up data size... |
108 |
printf("%" PRIu64 " Bytes%s", size, s); |
4b42c9059 allow print_size ... |
109 110 |
return; } |
f2d76ae4f Avoid use of divi... |
111 112 |
n = size >> d; f = size & ((1ULL << d) - 1); |
20e0e2331 Initial revision |
113 |
|
417faf285 Allow print_size ... |
114 |
/* If there's a remainder, deal with it */ |
f2d76ae4f Avoid use of divi... |
115 116 |
if (f) { m = (10ULL * f + (1ULL << (d - 1))) >> d; |
20e0e2331 Initial revision |
117 |
|
417faf285 Allow print_size ... |
118 119 120 121 |
if (m >= 10) { m -= 10; n += 1; } |
0d4983930 Patch by Kenneth ... |
122 |
} |
4b42c9059 allow print_size ... |
123 |
printf ("%lu", n); |
20e0e2331 Initial revision |
124 125 126 |
if (m) { printf (".%ld", m); } |
4b42c9059 allow print_size ... |
127 |
printf (" %ciB%s", c, s); |
20e0e2331 Initial revision |
128 |
} |
c95c4280d [PATCH 3_9] Move ... |
129 |
|
c95c4280d [PATCH 3_9] Move ... |
130 131 |
#define MAX_LINE_LENGTH_BYTES (64) #define DEFAULT_LINE_LENGTH_BYTES (16) |
bda32ffcf Update print_buff... |
132 133 |
int print_buffer(ulong addr, const void *data, uint width, uint count, uint linelen) |
c95c4280d [PATCH 3_9] Move ... |
134 |
{ |
150f72366 display_buffer: f... |
135 136 |
/* linebuf as a union causes proper alignment */ union linebuf { |
4d1fd7f1a Add 64-bit data s... |
137 138 139 |
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1]; #endif |
150f72366 display_buffer: f... |
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 [PATCH 3_9] Move ... |
144 |
int i; |
4d1fd7f1a Add 64-bit data s... |
145 |
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
80402f34f spl, common, seri... |
146 |
uint64_t __maybe_unused x; |
4d1fd7f1a Add 64-bit data s... |
147 |
#else |
80402f34f spl, common, seri... |
148 |
uint32_t __maybe_unused x; |
4d1fd7f1a Add 64-bit data s... |
149 |
#endif |
c95c4280d [PATCH 3_9] Move ... |
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 display_options:p... |
157 |
uint thislinelen = linelen; |
c95c4280d [PATCH 3_9] Move ... |
158 159 160 |
printf("%08lx:", addr); /* check for overflow condition */ |
efd7c1140 display_options:p... |
161 162 |
if (count < thislinelen) thislinelen = count; |
c95c4280d [PATCH 3_9] Move ... |
163 164 |
/* Copy from memory into linebuf and print hex values */ |
efd7c1140 display_options:p... |
165 |
for (i = 0; i < thislinelen; i++) { |
64419e475 print_buffer: opt... |
166 |
if (width == 4) |
150f72366 display_buffer: f... |
167 |
x = lb.ui[i] = *(volatile uint32_t *)data; |
4d1fd7f1a Add 64-bit data s... |
168 169 170 171 |
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (width == 8) x = lb.uq[i] = *(volatile uint64_t *)data; #endif |
64419e475 print_buffer: opt... |
172 |
else if (width == 2) |
150f72366 display_buffer: f... |
173 |
x = lb.us[i] = *(volatile uint16_t *)data; |
64419e475 print_buffer: opt... |
174 |
else |
150f72366 display_buffer: f... |
175 |
x = lb.uc[i] = *(volatile uint8_t *)data; |
4d1fd7f1a Add 64-bit data s... |
176 |
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
66da9beb6 sandbox: Fix warn... |
177 |
printf(" %0*llx", width * 2, (long long)x); |
4d1fd7f1a Add 64-bit data s... |
178 |
#else |
64419e475 print_buffer: opt... |
179 |
printf(" %0*x", width * 2, x); |
4d1fd7f1a Add 64-bit data s... |
180 |
#endif |
c95c4280d [PATCH 3_9] Move ... |
181 182 |
data += width; } |
efd7c1140 display_options:p... |
183 184 185 186 187 188 |
while (thislinelen < linelen) { /* fill line with whitespace for nice ASCII print */ for (i=0; i<width*2+1; i++) puts(" "); linelen--; } |
c95c4280d [PATCH 3_9] Move ... |
189 |
/* Print data in ASCII characters */ |
efd7c1140 display_options:p... |
190 |
for (i = 0; i < thislinelen * width; i++) { |
150f72366 display_buffer: f... |
191 192 193 194 195 196 |
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) lb.uc[i] = '.'; } lb.uc[i] = '\0'; printf(" %s ", lb.uc); |
c95c4280d [PATCH 3_9] Move ... |
197 198 |
/* update references */ |
efd7c1140 display_options:p... |
199 200 |
addr += thislinelen * width; count -= thislinelen; |
c95c4280d [PATCH 3_9] Move ... |
201 202 203 204 205 206 207 |
if (ctrlc()) return -1; } return 0; } |