diff mbox

[v5,12/24] hw/nand.c: bug fix to erase operation

Message ID 1361949350-22241-13-git-send-email-dantesu@gmail.com
State New
Headers show

Commit Message

Kuo-Jung Su Feb. 27, 2013, 7:15 a.m. UTC
From: Kuo-Jung Su <dantesu@faraday-tech.com>

The s->addr should be reset along with the s->addrlen,
or it might have the previous address shifted to MSB
and then causes problem to nand erase operation.

Signed-off-by: Kuo-Jung Su <dantesu@faraday-tech.com>
---
 hw/nand.c |    1 +
 1 file changed, 1 insertion(+)

Comments

Peter Maydell Feb. 28, 2013, 5:04 p.m. UTC | #1
On 27 February 2013 07:15, Kuo-Jung Su <dantesu@gmail.com> wrote:
> From: Kuo-Jung Su <dantesu@faraday-tech.com>
>
> The s->addr should be reset along with the s->addrlen,
> or it might have the previous address shifted to MSB
> and then causes problem to nand erase operation.
>
> Signed-off-by: Kuo-Jung Su <dantesu@faraday-tech.com>
> ---
>  hw/nand.c |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/hw/nand.c b/hw/nand.c
> index 7f40ebf..3cf91c5 100644
> --- a/hw/nand.c
> +++ b/hw/nand.c
> @@ -511,6 +511,7 @@ void nand_setio(DeviceState *dev, uint32_t value)
>              nand_command(s);
>
>          if (s->cmd != NAND_CMD_RANDOMREAD2) {
> +            s->addr = 0;
>              s->addrlen = 0;
>          }
>      }

I think this patch is probably right, but the code in nand_setio()
is just awful. It's trying to implement the way some commands are
"do something now" and some are "expect an address and do
something when you have the full address" and some are "command
now; address follows; final command to say now do it". But it's a
pile of conditionals that I think are harder to understand than if
there were a table of commands which were flagged for whether they
wanted addresses or not.

-- PMM
diff mbox

Patch

diff --git a/hw/nand.c b/hw/nand.c
index 7f40ebf..3cf91c5 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -511,6 +511,7 @@  void nand_setio(DeviceState *dev, uint32_t value)
             nand_command(s);
 
         if (s->cmd != NAND_CMD_RANDOMREAD2) {
+            s->addr = 0;
             s->addrlen = 0;
         }
     }