diff mbox

[U-Boot,v2,04/14] sparse: Simplify multiple logic

Message ID 1444912462-3949-5-git-send-email-maxime.ripard@free-electrons.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Maxime Ripard Oct. 15, 2015, 12:34 p.m. UTC
To check the alignment of the image blocks to the storage blocks, the
current code uses a convoluted syntax, while a simple mod also does the
work.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 common/aboot.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Tom Rini Oct. 20, 2015, 7:39 p.m. UTC | #1
On Thu, Oct 15, 2015 at 02:34:12PM +0200, Maxime Ripard wrote:

> To check the alignment of the image blocks to the storage blocks, the
> current code uses a convoluted syntax, while a simple mod also does the
> work.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Tom Rini Nov. 13, 2015, 1:27 a.m. UTC | #2
On Thu, Oct 15, 2015 at 02:34:12PM +0200, Maxime Ripard wrote:

> To check the alignment of the image blocks to the storage blocks, the
> current code uses a convoluted syntax, while a simple mod also does the
> work.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/common/aboot.c b/common/aboot.c
index 243b330d9126..2775254c742e 100644
--- a/common/aboot.c
+++ b/common/aboot.c
@@ -37,11 +37,14 @@ 
 #include <config.h>
 #include <common.h>
 #include <aboot.h>
+#include <div64.h>
 #include <errno.h>
 #include <malloc.h>
 #include <part.h>
 #include <sparse_format.h>
 
+#include <linux/math64.h>
+
 typedef struct sparse_buffer {
 	void	*data;
 	u32	length;
@@ -260,7 +263,7 @@  void write_sparse_image(block_dev_desc_t *dev_desc,
 {
 	lbaint_t start;
 	lbaint_t blkcnt;
-	unsigned int chunk;
+	unsigned int chunk, offset;
 	sparse_header_t *sparse_header;
 	chunk_header_t *chunk_header;
 	sparse_buffer_t *buffer;
@@ -274,9 +277,12 @@  void write_sparse_image(block_dev_desc_t *dev_desc,
 		return;
 	}
 
-	/* verify sparse_header->blk_sz is an exact multiple of info->blksz */
-	if (sparse_header->blk_sz !=
-	    (sparse_header->blk_sz & ~(info->blksz - 1))) {
+	/*
+	 * Verify that the sparse block size is a multiple of our
+	 * storage backend block size
+	 */
+	div_u64_rem(sparse_header->blk_sz, info->blksz, &offset);
+	if (offset) {
 		printf("%s: Sparse image block size issue [%u]\n",
 		       __func__, sparse_header->blk_sz);
 		fastboot_fail("sparse image block size issue");