diff mbox

[U-Boot] fastboot: mmc: Fix use of 64 bit division

Message ID 1447259769-26997-1-git-send-email-hdegoede@redhat.com
State Deferred
Delegated to: Tom Rini
Headers show

Commit Message

Hans de Goede Nov. 11, 2015, 4:36 p.m. UTC
Directly doing a 64 bit division (when CONFIG_SYS_64BIT_LBA is set)
causes linking to fail when building u-boot for ARMv7 with a hard-float
tool-chain.

This commit fixes this by properly using div_u64 for the division.

Note that an alternative fix would be to stop using lbaint_t for
blkcnt / blks, since the passed in "download_bytes" is only 32 bits
anyways. But we may want to support files / partitions larger then 4G
in the near future and using div_u64 is future proof for when
download_bytes' type gets changed to a lbaint_t itself.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 common/fb_mmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tom Rini Nov. 11, 2015, 5:09 p.m. UTC | #1
On Wed, Nov 11, 2015 at 05:36:09PM +0100, Hans de Goede wrote:

> Directly doing a 64 bit division (when CONFIG_SYS_64BIT_LBA is set)
> causes linking to fail when building u-boot for ARMv7 with a hard-float
> tool-chain.
> 
> This commit fixes this by properly using div_u64 for the division.
> 
> Note that an alternative fix would be to stop using lbaint_t for
> blkcnt / blks, since the passed in "download_bytes" is only 32 bits
> anyways. But we may want to support files / partitions larger then 4G
> in the near future and using div_u64 is future proof for when
> download_bytes' type gets changed to a lbaint_t itself.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Tom Rini Nov. 13, 2015, 1:26 a.m. UTC | #2
On Wed, Nov 11, 2015 at 12:09:32PM -0500, Tom Rini wrote:
> On Wed, Nov 11, 2015 at 05:36:09PM +0100, Hans de Goede wrote:
> 
> > Directly doing a 64 bit division (when CONFIG_SYS_64BIT_LBA is set)
> > causes linking to fail when building u-boot for ARMv7 with a hard-float
> > tool-chain.
> > 
> > This commit fixes this by properly using div_u64 for the division.
> > 
> > Note that an alternative fix would be to stop using lbaint_t for
> > blkcnt / blks, since the passed in "download_bytes" is only 32 bits
> > anyways. But we may want to support files / partitions larger then 4G
> > in the near future and using div_u64 is future proof for when
> > download_bytes' type gets changed to a lbaint_t itself.
> > 
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>

But a duplicate of https://patchwork.ozlabs.org/patch/537185/ sorry :(
diff mbox

Patch

diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 0c48cf9..83d66ed 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -11,6 +11,8 @@ 
 #include <aboot.h>
 #include <sparse_format.h>
 #include <mmc.h>
+#include <div64.h>
+#include <linux/math64.h>
 
 #ifndef CONFIG_FASTBOOT_GPT_NAME
 #define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME
@@ -64,7 +66,7 @@  static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
 
 	/* determine number of blocks to write */
 	blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
-	blkcnt = blkcnt / info->blksz;
+	blkcnt = div_u64(blkcnt, info->blksz);
 
 	if (blkcnt > info->size) {
 		error("too large for partition: '%s'\n", part_name);