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