1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 #include <linux/ctype.h>
14 char *display_options_get_banner_priv(bool newlines
, const char *build_tag
,
19 len
= snprintf(buf
, size
, "%s%s", newlines
? "\n\n" : "",
21 if (build_tag
&& len
< size
)
22 len
+= snprintf(buf
+ len
, size
- len
, ", Build: %s",
26 strcpy(buf
+ len
, "\n\n");
32 #define BUILD_TAG NULL
35 char *display_options_get_banner(bool newlines
, char *buf
, int size
)
37 return display_options_get_banner_priv(newlines
, BUILD_TAG
, buf
, size
);
40 int display_options(void)
42 char buf
[DISPLAY_OPTIONS_BANNER_LENGTH
];
44 display_options_get_banner(true, buf
, sizeof(buf
));
50 void print_freq(uint64_t freq
, const char *s
)
54 static const char names
[] = {'G', 'M', 'K'};
55 unsigned long d
= 1e9
;
59 for (i
= 0; i
< ARRAY_SIZE(names
); i
++, d
/= 1000) {
67 printf("%llu Hz%s", freq
, s
);
73 /* If there's a remainder, show the first few digits */
78 while (m
&& !(m
% 10))
81 m
= (m
/ 10) + (m
% 100 >= 50);
84 printf("%lu", (unsigned long) freq
);
87 printf(" %cHz%s", c
, s
);
90 void print_size(uint64_t size
, const char *s
)
92 unsigned long m
= 0, n
;
94 static const char names
[] = {'E', 'P', 'T', 'G', 'M', 'K'};
95 unsigned long d
= 10 * ARRAY_SIZE(names
);
99 for (i
= 0; i
< ARRAY_SIZE(names
); i
++, d
-= 10) {
107 printf("%llu Bytes%s", size
, s
);
112 f
= size
& ((1ULL << d
) - 1);
114 /* If there's a remainder, deal with it */
116 m
= (10ULL * f
+ (1ULL << (d
- 1))) >> d
;
128 printf (" %ciB%s", c
, s
);
131 #define MAX_LINE_LENGTH_BYTES (64)
132 #define DEFAULT_LINE_LENGTH_BYTES (16)
133 int print_buffer(ulong addr
, const void *data
, uint width
, uint count
,
136 /* linebuf as a union causes proper alignment */
138 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
139 uint64_t uq
[MAX_LINE_LENGTH_BYTES
/sizeof(uint64_t) + 1];
141 uint32_t ui
[MAX_LINE_LENGTH_BYTES
/sizeof(uint32_t) + 1];
142 uint16_t us
[MAX_LINE_LENGTH_BYTES
/sizeof(uint16_t) + 1];
143 uint8_t uc
[MAX_LINE_LENGTH_BYTES
/sizeof(uint8_t) + 1];
146 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
147 uint64_t __maybe_unused x
;
149 uint32_t __maybe_unused x
;
152 if (linelen
*width
> MAX_LINE_LENGTH_BYTES
)
153 linelen
= MAX_LINE_LENGTH_BYTES
/ width
;
155 linelen
= DEFAULT_LINE_LENGTH_BYTES
/ width
;
158 uint thislinelen
= linelen
;
159 printf("%08lx:", addr
);
161 /* check for overflow condition */
162 if (count
< thislinelen
)
165 /* Copy from memory into linebuf and print hex values */
166 for (i
= 0; i
< thislinelen
; i
++) {
168 x
= lb
.ui
[i
] = *(volatile uint32_t *)data
;
169 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
171 x
= lb
.uq
[i
] = *(volatile uint64_t *)data
;
174 x
= lb
.us
[i
] = *(volatile uint16_t *)data
;
176 x
= lb
.uc
[i
] = *(volatile uint8_t *)data
;
177 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
178 printf(" %0*llx", width
* 2, (long long)x
);
180 printf(" %0*x", width
* 2, x
);
185 while (thislinelen
< linelen
) {
186 /* fill line with whitespace for nice ASCII print */
187 for (i
=0; i
<width
*2+1; i
++)
192 /* Print data in ASCII characters */
193 for (i
= 0; i
< thislinelen
* width
; i
++) {
194 if (!isprint(lb
.uc
[i
]) || lb
.uc
[i
] >= 0x80)
198 printf(" %s\n", lb
.uc
);
200 /* update references */
201 addr
+= thislinelen
* width
;
202 count
-= thislinelen
;