From: Maxime Ripard Date: Thu, 15 Oct 2015 12:34:12 +0000 (+0200) Subject: sparse: Simplify multiple logic X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=40aeeda396024913835dc67fa17041693af97bd1;p=u-boot.git sparse: Simplify multiple logic 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 Reviewed-by: Tom Rini --- diff --git a/common/aboot.c b/common/aboot.c index 243b330d91..2775254c74 100644 --- a/common/aboot.c +++ b/common/aboot.c @@ -37,11 +37,14 @@ #include #include #include +#include #include #include #include #include +#include + 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");