From 8d5e29095ebc8d69554b7b6f4b9cef8a3d111053 Mon Sep 17 00:00:00 2001 From: Bas Wijnen Date: Tue, 12 Oct 2010 19:29:58 +0200 Subject: [PATCH] allow using 2GB nand and ignore 'valid'-bits --- mips/nand.hhp | 62 +++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/mips/nand.hhp b/mips/nand.hhp index dc05740..7d68f7b 100644 --- a/mips/nand.hhp +++ b/mips/nand.hhp @@ -134,7 +134,7 @@ static bool read (unsigned a, char *buffer): // 33: 9-byte ecc of 4th 512 bytes // 42: unused // 64: end of space - unsigned col = (1 << page_bits) + 2 + unsigned col = (1 << page_bits) + 6 + 9 * (column >> 9) cmd (CMD_READ0) addr (col) addr (col >> 8) @@ -142,21 +142,6 @@ static bool read (unsigned a, char *buffer): addr (row >> 8) addr (row >> 16) cmd (CMD_READSTART) - bool valid = false - for unsigned t = 0; t < 3; ++t: - if rdata () == 0: - valid = true - break - if !valid: - //debug ("invalid page for nand read: %x\n", a) - for unsigned i = 0; i < 1 << (9 - 2); ++i: - ((unsigned *)buffer)[i] = ~0 - return false - col = (1 << page_bits) + 6 + 9 * (column >> 9) - cmd (CMD_RNDOUT) - addr (col) - addr (col >> 8) - cmd (CMD_RNDOUTSTART) //debug ("parity data:") for unsigned t = 0; t < 9; ++t: error[t] = rdata () @@ -192,17 +177,18 @@ static bool read (unsigned a, char *buffer): data ^= mask << offset buffer[byte] = data buffer[byte + 1] = data >> 8 + #if 0 for unsigned i = 0; i < 0x10; ++i: if (buffer[i] & 0xff) < 0x10: - //debug (" 0") + debug (" 0") else: - //debug (" ") - //debug ("%x", buffer[i] & 0xff) - //debug ("\n") + debug (" ") + debug ("%x", buffer[i] & 0xff) + debug ("\n") + #endif return true static void write (unsigned a, char *buffer): - dbgl () unsigned row = a >> page_bits //debug ("writing: %x/%x\n", a, row) cmd (CMD_SEQIN) @@ -211,10 +197,8 @@ static void write (unsigned a, char *buffer): addr (row) addr (row >> 8) addr (row >> 16) - char ecc[4][12] - dbgl () - for unsigned i = 0; i < 0x4; ++i: - dbgl () + char ecc[8][12] + for unsigned i = 0; i < 1 << (page_bits - 9); ++i: bool all_ff = true EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_ENCODING | EMC_NFECR_ERST //debug ("writing data from %x\n", (unsigned)buffer + i * 0x200) @@ -225,19 +209,15 @@ static void write (unsigned a, char *buffer): if !all_ff: while !(EMC_NFINTS & EMC_NFINTS_ENCF): DELAY () - dbgl () for unsigned t = 0; t < 9; ++t: ecc[i][t] = ((volatile char *)&EMC_NFPAR (0))[t] - dbgl () //debug ("parity for %x:", i * 0x200 + a) //for unsigned t = 0; t < 9; ++t: //debug (" %x", ecc[i][t] & 0xff) //kdebug ("\n") else: - dbgl () for unsigned t = 0; t < 9; ++t: ecc[i][t] = 0xff - dbgl () // Spare space (starts at 1 << page_bits) // 0: unused // 2: detect valid data (at least 1 byte == 0 means valid) @@ -250,14 +230,12 @@ static void write (unsigned a, char *buffer): // 64: end of space for unsigned i = 0; i < 6; ++i: wdata (0) - for unsigned i = 0; i < 4; ++i: + for unsigned i = 0; i < 1 << (page_bits - 9); ++i: for unsigned j = 0; j < 9; ++j: wdata (ecc[i][j]) - dbgl () cmd (CMD_PAGEPROG) // Wait at least 100 ns. DELAY () - dbgl () cmd (CMD_READ0) addr (0) addr (0) @@ -265,9 +243,7 @@ static void write (unsigned a, char *buffer): addr (row >> 8) addr (row >> 16) cmd (CMD_READSTART) - dbgl () - for unsigned i = 0; i < 4; ++i: - dbgl () + for unsigned i = 0; i < 1 << (page_bits - 9); ++i: EMC_NFINTS = 0 EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST for unsigned t = 0; t < 0x200; ++t: @@ -292,26 +268,24 @@ static void write (unsigned a, char *buffer): unsigned offset= bit & 7 unsigned byte = bit / 8 debug ("error detected by parity: %x on %x+%d\n", mask, byte, offset) - dbgl () for unsigned i = 0; i < 6; ++i: if rdata () != 0: debug ("extra data not 0 at byte %d\n", i) - dbgl () - for unsigned i = 0; i < 4; ++i: + for unsigned i = 0; i < 1 << (page_bits - 9); ++i: for unsigned j = 0; j < 9; ++j: unsigned r = rdata () & 0xff if r != (ecc[i][j] & 0xff): debug ("ecc doesn't match: %x != %x\n", r, ecc[i][j] & 0xff) - dbgl () //debug ("nand program %x:", a) + #if 0 for unsigned i = 0; i < 0x10; ++i: if (buffer[i] & 0xff) < 0x10: - //debug (" 0") + debug (" 0") else: - //debug (" ") - //debug ("%x", buffer[i] & 0xff) - dbgl () - //debug ("\n") + debug (" ") + debug ("%x", buffer[i] & 0xff) + debug ("\n") + #endif static void erase (unsigned a): unsigned row = a >> page_bits