summaryrefslogtreecommitdiff
path: root/lib_generic
diff options
context:
space:
mode:
authorBecky Bruce <becky.bruce@freescale.com>2008-07-09 11:09:41 -0500
committerWolfgang Denk <wd@denx.de>2008-07-09 22:50:20 +0200
commit417faf285b2527acb2de24c5cd3e2621d385408c (patch)
tree1e7370d9458cf2f99d81fe05347e90dd60c50ccd /lib_generic
parentc956717ab25c962ef49d49064dfc73f4edcba1fb (diff)
downloadu-boot-imx-417faf285b2527acb2de24c5cd3e2621d385408c.zip
u-boot-imx-417faf285b2527acb2de24c5cd3e2621d385408c.tar.gz
u-boot-imx-417faf285b2527acb2de24c5cd3e2621d385408c.tar.bz2
Allow print_size to print in GB
Signed-off-by: Becky Bruce <becky.bruce@freescale.com>
Diffstat (limited to 'lib_generic')
-rw-r--r--lib_generic/display_options.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib_generic/display_options.c b/lib_generic/display_options.c
index a52fa04..2dc2567 100644
--- a/lib_generic/display_options.c
+++ b/lib_generic/display_options.c
@@ -39,27 +39,35 @@ int display_options (void)
}
/*
- * print sizes as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
- * allow for optional trailing string (like "\n")
+ * print sizes as "xxx kB", "xxx.y kB", "xxx MB", "xxx.y MB",
+ * xxx GB, or xxx.y GB as needed; allow for optional trailing string
+ * (like "\n")
*/
void print_size (phys_size_t size, const char *s)
{
- ulong m, n;
- ulong d = 1 << 20; /* 1 MB */
- char c = 'M';
-
- if (size < d) { /* print in kB */
- c = 'k';
- d = 1 << 10;
+ ulong m = 0, n;
+ phys_size_t d = 1 << 30; /* 1 GB */
+ char c = 'G';
+
+ if (size < d) { /* try MB */
+ c = 'M';
+ d = 1 << 20;
+ if (size < d) { /* print in kB */
+ c = 'k';
+ d = 1 << 10;
+ }
}
n = size / d;
- m = (10 * (size - (n * d)) + (d / 2) ) / d;
+ /* If there's a remainder, deal with it */
+ if(size % d) {
+ m = (10 * (size - (n * d)) + (d / 2) ) / d;
- if (m >= 10) {
- m -= 10;
- n += 1;
+ if (m >= 10) {
+ m -= 10;
+ n += 1;
+ }
}
printf ("%2ld", n);