From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LB6qo-0000Gy-Aa for qemu-devel@nongnu.org; Fri, 12 Dec 2008 07:10:34 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LB6qm-0000G8-Hm for qemu-devel@nongnu.org; Fri, 12 Dec 2008 07:10:33 -0500 Received: from [199.232.76.173] (port=60220 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LB6qm-0000Fr-05 for qemu-devel@nongnu.org; Fri, 12 Dec 2008 07:10:32 -0500 Received: from bart.se.axis.com ([195.60.68.10]:35009) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LB6ql-0006QK-EZ for qemu-devel@nongnu.org; Fri, 12 Dec 2008 07:10:31 -0500 Received: from bart.se.axis.com (bart.se.axis.com [127.0.0.1]) by bart.se.axis.com (Postfix) with ESMTP id 862A1641D2 for ; Fri, 12 Dec 2008 13:10:30 +0100 (CET) Received: from axis.com (edgar.se.axis.com [10.93.151.1]) by bart.se.axis.com (Postfix) with ESMTP id 798096415C for ; Fri, 12 Dec 2008 13:10:30 +0100 (CET) Date: Fri, 12 Dec 2008 13:10:30 +0100 From: "Edgar E. Iglesias" Message-ID: <20081212121030.GC27147@edgar.se.axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] NAND: Correct random data reads. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org I'm having problems with machine that uses a NAND_MFR_STMICRO 0xf1, recent Linux versions cannot properly read from the flash. Turns out that Linux MTD recently learned howto do randomly accessed reads from NAND flashes. QEMU has problemns emulating these. This patch fixes the problem for me but I've only tested on one flash model and only with Linux. I'd appreciate help with testing more machines with NANDs and ofcourse any comments people may have on the patch. Thanks commit 68a19f4348b12f85bd5fbfd8cf7b19033e1fd784 Author: Edgar E. Iglesias Date: Fri Dec 12 12:48:58 2008 +0100 NAND: Correct random data reads. Random reading depends on having the last row/page latched and not beeing clobbered between read and any following random reads. Also, s->iolen must be updated when loading the io/data register with randomly accessed flash data. Signed-off-by: Edgar E. Iglesias diff --git a/hw/nand.c b/hw/nand.c index 7c9f0aa..a6f67c6 100644 --- a/hw/nand.c +++ b/hw/nand.c @@ -212,6 +212,7 @@ void nand_reset(struct nand_flash_s *s) static void nand_command(struct nand_flash_s *s) { + unsigned int offset; switch (s->cmd) { case NAND_CMD_READ0: s->iolen = 0; @@ -233,8 +234,12 @@ static void nand_command(struct nand_flash_s *s) case NAND_CMD_NOSERIALREAD2: if (!(nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP)) break; - - s->blk_load(s, s->addr, s->addr & ((1 << s->addr_shift) - 1)); + offset = s->addr & ((1 << s->addr_shift) - 1); + s->blk_load(s, s->addr, offset); + if (s->gnd) + s->iolen = (1 << s->page_shift) - offset; + else + s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset; break; case NAND_CMD_RESET: @@ -380,12 +385,15 @@ void nand_setio(struct nand_flash_s *s, uint8_t value) if (s->cmd != NAND_CMD_RANDOMREAD2) { s->addrlen = 0; - s->addr = 0; } } if (s->ale) { - s->addr |= value << (s->addrlen * 8); + unsigned int shift = s->addrlen * 8; + unsigned int mask = ~(0xff << shift); + unsigned int v = value << shift; + + s->addr = (s->addr & mask) | v; s->addrlen ++; if (s->addrlen == 1 && s->cmd == NAND_CMD_READID) @@ -680,9 +688,6 @@ static void glue(nand_blk_load_, PAGE_SIZE)(struct nand_flash_s *s, offset, PAGE_SIZE + OOB_SIZE - offset); s->ioaddr = s->io; } - - s->addr &= PAGE_SIZE - 1; - s->addr += PAGE_SIZE; } static void glue(nand_init_, PAGE_SIZE)(struct nand_flash_s *s)