All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: "Dr. David Alan Gilbert" <david.gilbert@linaro.org>
Cc: qemu-devel@nongnu.org, patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH] Fix last sector write on sd card
Date: Fri, 29 Jul 2011 09:36:36 -0500	[thread overview]
Message-ID: <4E32C574.10802@codemonkey.ws> (raw)
In-Reply-To: <20110725122130.GA5297@davesworkthinkpad>

On 07/25/2011 07:21 AM, Dr. David Alan Gilbert wrote:
>      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<david.gilbert@linaro.org>

Applied.  Thanks.

Regards,

Anthony Liguori

>
> ---
> 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.  */
>
>

      reply	other threads:[~2011-07-29 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-25 12:21 [Qemu-devel] [PATCH] Fix last sector write on sd card Dr. David Alan Gilbert
2011-07-29 14:36 ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E32C574.10802@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=david.gilbert@linaro.org \
    --cc=patches@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.