1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <config.h>
25#include <common.h>
26#include <linux/ctype.h>
27#include <asm/io.h>
28
29int display_options (void)
30{
31 extern char version_string[];
32
33#if defined(BUILD_TAG)
34 printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
35#else
36 printf ("\n\n%s\n\n", version_string);
37#endif
38 return 0;
39}
40
41
42
43
44
45
46void print_size (phys_size_t size, const char *s)
47{
48 ulong m = 0, n;
49 phys_size_t d = 1 << 30;
50 char c = 'G';
51
52 if (size < d) {
53 c = 'M';
54 d = 1 << 20;
55 if (size < d) {
56 c = 'k';
57 d = 1 << 10;
58 }
59 }
60
61 n = size / d;
62
63
64 if(size % d) {
65 m = (10 * (size - (n * d)) + (d / 2) ) / d;
66
67 if (m >= 10) {
68 m -= 10;
69 n += 1;
70 }
71 }
72
73 printf ("%2ld", n);
74 if (m) {
75 printf (".%ld", m);
76 }
77 printf (" %cB%s", c, s);
78}
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93#define MAX_LINE_LENGTH_BYTES (64)
94#define DEFAULT_LINE_LENGTH_BYTES (16)
95int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen)
96{
97 uint8_t linebuf[MAX_LINE_LENGTH_BYTES];
98 uint32_t *uip = (void*)linebuf;
99 uint16_t *usp = (void*)linebuf;
100 uint8_t *ucp = (void*)linebuf;
101 int i;
102
103 if (linelen*width > MAX_LINE_LENGTH_BYTES)
104 linelen = MAX_LINE_LENGTH_BYTES / width;
105 if (linelen < 1)
106 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
107
108 while (count) {
109 printf("%08lx:", addr);
110
111
112 if (count < linelen)
113 linelen = count;
114
115
116 for (i = 0; i < linelen; i++) {
117 if (width == 4) {
118 uip[i] = *(volatile uint32_t *)data;
119 printf(" %08x", uip[i]);
120 } else if (width == 2) {
121 usp[i] = *(volatile uint16_t *)data;
122 printf(" %04x", usp[i]);
123 } else {
124 ucp[i] = *(volatile uint8_t *)data;
125 printf(" %02x", ucp[i]);
126 }
127 data += width;
128 }
129
130
131 puts(" ");
132 for (i = 0; i < linelen * width; i++)
133 putc(isprint(ucp[i]) && (ucp[i] < 0x80) ? ucp[i] : '.');
134 putc ('\n');
135
136
137 addr += linelen * width;
138 count -= linelen;
139
140 if (ctrlc())
141 return -1;
142 }
143
144 return 0;
145}
146