From 326e4bddc3d36a2afc2781e3018e2649d2be0680 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 26 Sep 2007 15:23:46 +0200 Subject: [PATCH] print_size() -> size_human_readable() return a pointer to a human readable string rather than printingit directly --- commands/bootm.c | 14 ++++++++------ include/common.h | 3 +-- lib/display_options.c | 17 +++++++++++------ net/nfs.c | 9 +++++---- net/tftp.c | 12 +++++------- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/commands/bootm.c b/commands/bootm.c index 5f2bec938..8f45d4c34 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -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)); } } } diff --git a/include/common.h b/include/common.h index f786fe9b8..de6d47334 100644 --- a/include/common.h +++ b/include/common.h @@ -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); diff --git a/lib/display_options.c b/lib/display_options.c index 6b8414573..5d9240327 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -24,14 +24,16 @@ #include /* - * 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; } + diff --git a/net/nfs.c b/net/nfs.c index d0d11ccec..3770fe8f2 100644 --- a/net/nfs.c +++ b/net/nfs.c @@ -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); diff --git a/net/tftp.c b/net/tftp.c index e690c3934..c0b29df3b 100644 --- a/net/tftp.c +++ b/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);