All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] dfu:mmc: When doing block operations, operate on the given length
@ 2013-03-07 14:25 Tom Rini
  2013-03-07 23:19 ` Michael Cashwell
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tom Rini @ 2013-03-07 14:25 UTC (permalink / raw)
  To: u-boot

When working on RAW partitions, it's possible that the whole area
is larger than DDR.  So what we need to do is make sure that the length
we are given is aligned with the LBA block size, then pass that length
in as our count of LBA blocks to operate on.  In doing this, we no
longer need to modify *len on read operations.

Cc: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
---
 drivers/dfu/dfu_mmc.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 083d745..0bed405 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -34,14 +34,21 @@ static int mmc_block_op(enum dfu_mmc_op op, struct dfu_entity *dfu,
 {
 	char cmd_buf[DFU_CMD_BUF_SIZE];
 
-	sprintf(cmd_buf, "mmc %s 0x%x %x %x",
-		op == DFU_OP_READ ? "read" : "write",
-		(unsigned int) buf,
-		dfu->data.mmc.lba_start,
-		dfu->data.mmc.lba_size);
+	/*
+	 * We must ensure that we read in lba_blk_size chunks, so ALIGN
+	 * this value.
+	 */
+	*len = ALIGN(*len, dfu->data.mmc.lba_blk_size);
+
+	if (*len > (dfu->data.mmc.lba_size * dfu->data.mmc.lba_blk_size)) {
+		puts("Request would exceed designated area!\n");
+		return -EINVAL;
+	}
 
-	if (op == DFU_OP_READ)
-		*len = dfu->data.mmc.lba_blk_size * dfu->data.mmc.lba_size;
+	sprintf(cmd_buf, "mmc %s 0x%x %x %lx",
+		op == DFU_OP_READ ? "read" : "write",
+		(unsigned int) buf, dfu->data.mmc.lba_start,
+		*len / dfu->data.mmc.lba_blk_size);
 
 	debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf);
 	return run_command(cmd_buf, 0);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-08 15:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-07 14:25 [U-Boot] [PATCH] dfu:mmc: When doing block operations, operate on the given length Tom Rini
2013-03-07 23:19 ` Michael Cashwell
2013-03-07 23:33   ` Tom Rini
2013-03-08  0:14     ` Michael Cashwell
2013-03-08 15:06 ` Tom Rini
2013-03-08 15:41 ` Lukasz Majewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.