print_size() -> size_human_readable()
return a pointer to a human readable string rather than printingit directly
This commit is contained in:
parent
5efc6836b7
commit
326e4bddc3
|
@ -754,11 +754,13 @@ print_image_hdr (image_header_t *hdr)
|
|||
printf (" Image Type: %s %s %s (%s)\n", image_arch(hdr), image_os(hdr),
|
||||
image_type(hdr), image_compression(hdr));
|
||||
#endif
|
||||
printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
|
||||
print_size (ntohl(hdr->ih_size), "\n");
|
||||
printf (" Load Address: %08x\n"
|
||||
printf (" Data Size: %d Bytes = %s\n"
|
||||
" Load Address: %08x\n"
|
||||
" Entry Point: %08x\n",
|
||||
ntohl(hdr->ih_load), ntohl(hdr->ih_ep));
|
||||
ntohl(hdr->ih_size),
|
||||
size_human_readable(ntohl(hdr->ih_size)),
|
||||
ntohl(hdr->ih_load),
|
||||
ntohl(hdr->ih_ep));
|
||||
|
||||
if (hdr->ih_type == IH_TYPE_MULTI) {
|
||||
int i;
|
||||
|
@ -767,8 +769,8 @@ print_image_hdr (image_header_t *hdr)
|
|||
|
||||
puts (" Contents:\n");
|
||||
for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
|
||||
printf (" Image %d: %8ld Bytes = ", i, len);
|
||||
print_size (len, "\n");
|
||||
printf (" Image %d: %8ld Bytes = %s", i, len,
|
||||
size_human_readable (len));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,8 +73,7 @@ void panic(const char *fmt, ...);
|
|||
|
||||
/* */
|
||||
long int initdram (int);
|
||||
int display_options (void);
|
||||
void print_size (ulong, const char *);
|
||||
char *size_human_readable(ulong size);
|
||||
|
||||
/* common/main.c */
|
||||
void main_loop (void);
|
||||
|
|
|
@ -24,14 +24,16 @@
|
|||
#include <common.h>
|
||||
|
||||
/*
|
||||
* print sizes as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
|
||||
* allow for optional trailing string (like "\n")
|
||||
* return a pointer to a string containing the size
|
||||
* as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
|
||||
*/
|
||||
void print_size (ulong size, const char *s)
|
||||
char *size_human_readable(ulong size)
|
||||
{
|
||||
static char buf[20];
|
||||
ulong m, n;
|
||||
ulong d = 1 << 20; /* 1 MB */
|
||||
char c = 'M';
|
||||
char *ptr = buf;
|
||||
|
||||
if (size < d) { /* print in kB */
|
||||
c = 'k';
|
||||
|
@ -47,9 +49,12 @@ void print_size (ulong size, const char *s)
|
|||
n += 1;
|
||||
}
|
||||
|
||||
printf ("%2ld", n);
|
||||
ptr += sprintf(buf, "%2ld", n);
|
||||
if (m) {
|
||||
printf (".%ld", m);
|
||||
ptr += sprintf (ptr,".%ld", m);
|
||||
}
|
||||
printf (" %cB%s", c, s);
|
||||
sprintf(ptr, " %cB", c);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -705,10 +705,11 @@ NfsStart (void)
|
|||
}
|
||||
printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
|
||||
|
||||
if (NetBootFileSize) {
|
||||
printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
|
||||
print_size (NetBootFileSize<<9, "");
|
||||
}
|
||||
if (NetBootFileSize)
|
||||
printf (" Size is 0x%x Bytes = %s",
|
||||
NetBootFileSize<<9);
|
||||
size_human_readable (NetBootFileSize<<9));
|
||||
|
||||
printf ("\nLoad address: 0x%lx\n"
|
||||
"Loading: *\b", load_addr);
|
||||
|
||||
|
|
12
net/tftp.c
12
net/tftp.c
|
@ -334,14 +334,12 @@ TftpStart (void)
|
|||
|
||||
printf ("Filename '%s'.", tftp_filename);
|
||||
|
||||
if (NetBootFileSize) {
|
||||
printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
|
||||
print_size (NetBootFileSize<<9, "");
|
||||
}
|
||||
if (NetBootFileSize)
|
||||
printf (" Size is 0x%x Bytes = %s",
|
||||
NetBootFileSize<<9,
|
||||
size_human_readable(NetBootFileSize<<9));
|
||||
|
||||
putchar('\n');
|
||||
|
||||
puts ("Loading: *\b");
|
||||
puts ("\nLoading: *\b");
|
||||
|
||||
NetSetTimeout (TIMEOUT * SECOND, TftpTimeout);
|
||||
NetSetHandler (TftpHandler);
|
||||
|
|
Loading…
Reference in New Issue