From patchwork Thu Mar 7 14:25:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 225860 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 9D6782C03A3 for ; Fri, 8 Mar 2013 01:25:50 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D71484A2FE; Thu, 7 Mar 2013 15:25:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QiZq5vxVnAeY; Thu, 7 Mar 2013 15:25:46 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C33954A2F4; Thu, 7 Mar 2013 15:25:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E821B4A2F4 for ; Thu, 7 Mar 2013 15:25:40 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F0VPfW-ny0hN for ; Thu, 7 Mar 2013 15:25:40 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-gg0-f181.google.com (mail-gg0-f181.google.com [209.85.161.181]) by theia.denx.de (Postfix) with ESMTPS id D0AC34A2F3 for ; Thu, 7 Mar 2013 15:25:37 +0100 (CET) Received: by mail-gg0-f181.google.com with SMTP id e5so58312ggh.12 for ; Thu, 07 Mar 2013 06:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=7oOTbrjY43Uxx2lbqXphADzXROeIouhpvCReEfgjWJc=; b=JEaQ4em6vyOUugCRnp3VuDqZlhLEh6Xr/grxRYne9R06u4a2JprrPQJEl/PBfV7ktx yfR43CKVPQKsBqRcvwKxEARo++Qz/gu11izrc+LzgW+UR2q55V7+WlBxhqz3qEFLPVUy lLfztKN9yIrG3Fxz7n/U6EIbwSDNM2LW7jMP6SNuXu6UOsvwanunfnOf6umE2ioJ84pB Qm3ROj3z8JNSk07k0Uyu1Ivv9jw/wNDE0tggIk8V4CPlzT4uEdB/Tun/shiDcAhkcUP3 0LRKgTUL2ZIPwbTMkFNRuD4x3QA4FgZvpTcPjaFQSc31VGoXS1LLYiscJiphTszDLs53 0SKw== X-Received: by 10.236.194.231 with SMTP id m67mr9017909yhn.202.1362666335577; Thu, 07 Mar 2013 06:25:35 -0800 (PST) Received: from localhost.localdomain (cpe-065-184-250-089.ec.res.rr.com. [65.184.250.89]) by mx.google.com with ESMTPS id u3sm2114705yhd.14.2013.03.07.06.25.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Mar 2013 06:25:33 -0800 (PST) From: Tom Rini To: u-boot@lists.denx.de Date: Thu, 7 Mar 2013 09:25:44 -0500 Message-Id: <1362666344-21856-1-git-send-email-trini@ti.com> X-Mailer: git-send-email 1.7.9.5 Subject: [U-Boot] [PATCH] dfu:mmc: When doing block operations, operate on the given length X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Signed-off-by: Tom Rini Acked-by: Lukasz Majewski Tested-by: Lukasz Majewski --- 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);