From patchwork Mon Jul 25 12:21:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 3074 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id BB7A723E54 for ; Mon, 25 Jul 2011 12:21:36 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id 7EE0CA18314 for ; Mon, 25 Jul 2011 12:21:36 +0000 (UTC) Received: by qyk10 with SMTP id 10so996242qyk.11 for ; Mon, 25 Jul 2011 05:21:35 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr3379507qcc.148.1311596495730; Mon, 25 Jul 2011 05:21:35 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs75449qcb; Mon, 25 Jul 2011 05:21:35 -0700 (PDT) Received: by 10.227.176.65 with SMTP id bd1mr3723992wbb.78.1311596494343; Mon, 25 Jul 2011 05:21:34 -0700 (PDT) Received: from mtagate3.uk.ibm.com (mtagate3.uk.ibm.com [194.196.100.163]) by mx.google.com with ESMTPS id fd19si9336271wbb.146.2011.07.25.05.21.33 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 05:21:34 -0700 (PDT) Received-SPF: neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of david.gilbert@linaro.org) client-ip=194.196.100.163; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of david.gilbert@linaro.org) smtp.mail=david.gilbert@linaro.org Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p6PCLXTo019162 for ; Mon, 25 Jul 2011 12:21:33 GMT Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6PCLXiD2597040 for ; Mon, 25 Jul 2011 13:21:33 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6PCLWeu000987 for ; Mon, 25 Jul 2011 06:21:33 -0600 Received: from davesworkthinkpad (dyn-9-174-219-90.manchester-maybrook.uk.ibm.com [9.174.219.90]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p6PCLV1A000921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 25 Jul 2011 06:21:32 -0600 Date: Mon, 25 Jul 2011 13:21:30 +0100 From: "Dr. David Alan Gilbert" To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH] Fix last sector write on sd card Message-ID: <20110725122130.GA5297@davesworkthinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) When writing the last sector of an SD card using WRITE_MULTIPLE_BLOCK QEmu throws an error saying that we've run off the end, and leaves itself in the wrong state. Tested on ARM Vexpress model. Signed-off-by: Dr. David Alan Gilbert --- Don't throw address error on last block, and leave in correct state. diff --git a/hw/sd.c b/hw/sd.c index cedfb20..219a0dd 100644 --- a/hw/sd.c +++ b/hw/sd.c @@ -1450,14 +1450,8 @@ void sd_write_data(SDState *sd, uint8_t value) break; case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { - /* TODO: Check CRC before committing */ - sd->state = sd_programming_state; - BLK_WRITE_BLOCK(sd->data_start, sd->data_offset); - sd->blk_written ++; - sd->data_start += sd->blk_len; - sd->data_offset = 0; + if (sd->data_offset == 0) { + /* Start of the block - lets check the address is valid */ if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; break; @@ -1466,6 +1460,15 @@ void sd_write_data(SDState *sd, uint8_t value) sd->card_status |= WP_VIOLATION; break; } + } + sd->data[sd->data_offset++] = value; + if (sd->data_offset >= sd->blk_len) { + /* TODO: Check CRC before committing */ + sd->state = sd_programming_state; + BLK_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd->blk_written++; + sd->data_start += sd->blk_len; + sd->data_offset = 0; sd->csd[14] |= 0x40; /* Bzzzzzzztt .... Operation complete. */