Blame view
lib/display_options.c
4.33 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
20e0e2331 Initial revision |
2 3 4 |
/* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
20e0e2331 Initial revision |
5 6 7 |
*/ #include <common.h> |
24b852a7a Move console defi... |
8 |
#include <console.h> |
33eac2dc2 Add print_freq() ... |
9 |
#include <div64.h> |
09c2e90c1 unify version_string |
10 |
#include <version.h> |
c95c4280d [PATCH 3_9] Move ... |
11 12 |
#include <linux/ctype.h> #include <asm/io.h> |
20e0e2331 Initial revision |
13 |
|
6c519f2dc display_options: ... |
14 15 |
char *display_options_get_banner_priv(bool newlines, const char *build_tag, char *buf, int size) |
20e0e2331 Initial revision |
16 |
{ |
6c519f2dc display_options: ... |
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 lib/display_optio... |
28 29 30 31 32 |
if (len < 0) len = 0; snprintf(buf + len, size - len, " "); |
6c519f2dc display_options: ... |
33 34 35 36 37 38 |
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 |
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 Remove <inttypes.... |
71 |
printf("%llu Hz%s", freq, s); |
33eac2dc2 Add print_freq() ... |
72 73 74 75 |
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) { |
dee37fc99 Remove <inttypes.... |
108 |
printf("%llu 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 { |
4d979bfdb common: Move and ... |
137 |
#ifdef MEM_SUPPORT_64BIT_DATA |
4d1fd7f1a Add 64-bit data s... |
138 139 |
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; |
4d979bfdb common: Move and ... |
145 |
#ifdef MEM_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; |
4d979bfdb common: Move and ... |
168 |
#ifdef MEM_SUPPORT_64BIT_DATA |
4d1fd7f1a Add 64-bit data s... |
169 170 171 |
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; |
f60662de7 lib: Allow using ... |
176 177 |
#if defined(CONFIG_SPL_BUILD) printf(" %x", (uint)x); |
4d979bfdb common: Move and ... |
178 |
#elif defined(MEM_SUPPORT_64BIT_DATA) |
66da9beb6 sandbox: Fix warn... |
179 |
printf(" %0*llx", width * 2, (long long)x); |
4d1fd7f1a Add 64-bit data s... |
180 |
#else |
64419e475 print_buffer: opt... |
181 |
printf(" %0*x", width * 2, x); |
4d1fd7f1a Add 64-bit data s... |
182 |
#endif |
c95c4280d [PATCH 3_9] Move ... |
183 184 |
data += width; } |
efd7c1140 display_options:p... |
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 [PATCH 3_9] Move ... |
191 |
/* Print data in ASCII characters */ |
efd7c1140 display_options:p... |
192 |
for (i = 0; i < thislinelen * width; i++) { |
150f72366 display_buffer: f... |
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 [PATCH 3_9] Move ... |
199 200 |
/* update references */ |
efd7c1140 display_options:p... |
201 202 |
addr += thislinelen * width; count -= thislinelen; |
c95c4280d [PATCH 3_9] Move ... |
203 |
|
9bb746d81 spl: Avoid checki... |
204 |
#ifndef CONFIG_SPL_BUILD |
c95c4280d [PATCH 3_9] Move ... |
205 206 |
if (ctrlc()) return -1; |
9bb746d81 spl: Avoid checki... |
207 |
#endif |
c95c4280d [PATCH 3_9] Move ... |
208 209 210 211 |
} return 0; } |