summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2010-08-12 23:08:05 +0200
committerWolfgang Denk <wd@denx.de>2010-08-12 23:08:05 +0200
commitae37a0704a8a27e47471f541a68b88370cd14aa8 (patch)
treee591e61ff80c3ea1961b37c96e3ad161c8a1f0af /disk
parent18a056a18f6294a88c34105efcabf4c0638a946b (diff)
parentdc41b8bf3df2b2c3bd833f871d88ff5ef40a19f3 (diff)
downloadu-boot-imx-ae37a0704a8a27e47471f541a68b88370cd14aa8.zip
u-boot-imx-ae37a0704a8a27e47471f541a68b88370cd14aa8.tar.gz
u-boot-imx-ae37a0704a8a27e47471f541a68b88370cd14aa8.tar.bz2
Merge branch 'master' of git://git.denx.de/u-boot-ti
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/disk/part.c b/disk/part.c
index b6bae17..3ba88c7 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -109,14 +109,31 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
/*
* reports device info to the user
*/
-void dev_print (block_dev_desc_t *dev_desc)
-{
+
#ifdef CONFIG_LBA48
- uint64_t lba512; /* number of blocks if 512bytes block size */
+typedef uint64_t lba512_t;
#else
- lbaint_t lba512;
+typedef lbaint_t lba512_t;
#endif
+/*
+ * Overflowless variant of (block_count * mul_by / div_by)
+ * when div_by > mul_by
+ */
+static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
+{
+ lba512_t bc_quot, bc_rem;
+
+ /* x * m / d == x / d * m + (x % d) * m / d */
+ bc_quot = block_count / div_by;
+ bc_rem = block_count - div_by * bc_quot;
+ return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
+}
+
+void dev_print (block_dev_desc_t *dev_desc)
+{
+ lba512_t lba512; /* number of blocks if 512bytes block size */
+
if (dev_desc->type == DEV_TYPE_UNKNOWN) {
puts ("not available\n");
return;
@@ -184,8 +201,9 @@ void dev_print (block_dev_desc_t *dev_desc)
lba = dev_desc->lba;
lba512 = (lba * (dev_desc->blksz/512));
- mb = (10 * lba512) / 2048; /* 2048 = (1024 * 1024) / 512 MB */
/* round to 1 digit */
+ mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */
+
mb_quot = mb / 10;
mb_rem = mb - (10 * mb_quot);