1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-08 14:37:28 +03:00

use proper place for 2 GB ecc

This commit is contained in:
Bas Wijnen 2010-10-14 16:11:47 +02:00
parent 8d5e29095e
commit 7e8cc1d25e

View File

@ -58,6 +58,7 @@ static unsigned redundant_bits
static unsigned block_bits static unsigned block_bits
static unsigned size_bits static unsigned size_bits
static unsigned word_size static unsigned word_size
static unsigned ecc_start
static void unbusy (): static void unbusy ():
while !(gpio_get_port (2) & (1 << 30)): while !(gpio_get_port (2) & (1 << 30)):
@ -117,6 +118,13 @@ static void reset ():
unsigned num_planes_bits = d >> 2 & 3 unsigned num_planes_bits = d >> 2 & 3
unsigned plane_bits = 26 + (d >> 4 & 7) unsigned plane_bits = 26 + (d >> 4 & 7)
size_bits = plane_bits + num_planes_bits - 3 size_bits = plane_bits + num_planes_bits - 3
if page_bits == 11:
ecc_start = 6
else if page_bits == 12:
ecc_start = 12
else:
debug ("unknown nand type; assuming ecc offset to be 6. This is probably wrong!\n")
ecc_start = 6
static bool read (unsigned a, char *buffer): static bool read (unsigned a, char *buffer):
unsigned column = a & ((1 << page_bits) - 1) unsigned column = a & ((1 << page_bits) - 1)
@ -134,7 +142,13 @@ static bool read (unsigned a, char *buffer):
// 33: 9-byte ecc of 4th 512 bytes // 33: 9-byte ecc of 4th 512 bytes
// 42: unused // 42: unused
// 64: end of space // 64: end of space
unsigned col = (1 << page_bits) + 6 + 9 * (column >> 9)
// For 2 GB nand:
// 0-11: unused/bad block markers
// 12-89: 8 times 9-byte ecc
// 90-127: unused
// 128: end of space
unsigned col = (1 << page_bits) + ecc_start + 9 * (column >> 9)
cmd (CMD_READ0) cmd (CMD_READ0)
addr (col) addr (col)
addr (col >> 8) addr (col >> 8)
@ -143,8 +157,11 @@ static bool read (unsigned a, char *buffer):
addr (row >> 16) addr (row >> 16)
cmd (CMD_READSTART) cmd (CMD_READSTART)
//debug ("parity data:") //debug ("parity data:")
bool parity_all_ff = true
for unsigned t = 0; t < 9; ++t: for unsigned t = 0; t < 9; ++t:
error[t] = rdata () error[t] = rdata ()
if parity_all_ff && (error[t] & 0xff) != 0xff:
parity_all_ff = false
//debug (" %x", error[t] & 0xff) //debug (" %x", error[t] & 0xff)
//debug ("\n") //debug ("\n")
cmd (CMD_RNDOUT) cmd (CMD_RNDOUT)
@ -153,30 +170,34 @@ static bool read (unsigned a, char *buffer):
cmd (CMD_RNDOUTSTART) cmd (CMD_RNDOUTSTART)
EMC_NFINTS = 0 EMC_NFINTS = 0
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST
bool all_ff = true
for unsigned t = 0; t < 0x200; ++t: for unsigned t = 0; t < 0x200; ++t:
buffer[t] = rdata () buffer[t] = rdata ()
for unsigned t = 0; t < 9; ++t: if all_ff && (buffer[t] & 0xff) != 0xff:
((volatile char *)&EMC_NFPAR (0))[t] = error[t] all_ff = false
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY if !all_ff || !parity_all_ff:
while !(EMC_NFINTS & EMC_NFINTS_DECF): for unsigned t = 0; t < 9; ++t:
DELAY () ((volatile char *)&EMC_NFPAR (0))[t] = error[t]
unsigned ints = EMC_NFINTS EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY
if ints & EMC_NFINTS_UNCOR: while !(EMC_NFINTS & EMC_NFINTS_DECF):
debug ("uncorrectable error in nand at %x\n", a) DELAY ()
return false unsigned ints = EMC_NFINTS
unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT if ints & EMC_NFINTS_UNCOR:
for unsigned i = 0; i < errs; ++i: debug ("uncorrectable error in nand at %x\n", a)
unsigned err = EMC_NFERR (i) return false
unsigned index = (err >> 16) - 1 unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT
unsigned mask = err & 0x1ff for unsigned i = 0; i < errs; ++i:
unsigned bit = index * 9 unsigned err = EMC_NFERR (i)
unsigned offset= bit & 7 unsigned index = (err >> 16) - 1
unsigned byte = bit / 8 unsigned mask = err & 0x1ff
debug ("correcting %x on %x+%d\n", mask, byte, offset) unsigned bit = index * 9
unsigned data = buffer[byte] | buffer[byte + 1] << 8 unsigned offset= bit & 7
data ^= mask << offset unsigned byte = bit / 8
buffer[byte] = data debug ("correcting %x on %x+%d\n", mask, byte, offset)
buffer[byte + 1] = data >> 8 unsigned data = buffer[byte] | buffer[byte + 1] << 8
data ^= mask << offset
buffer[byte] = data
buffer[byte + 1] = data >> 8
#if 0 #if 0
for unsigned i = 0; i < 0x10; ++i: for unsigned i = 0; i < 0x10; ++i:
if (buffer[i] & 0xff) < 0x10: if (buffer[i] & 0xff) < 0x10:
@ -228,8 +249,14 @@ static void write (unsigned a, char *buffer):
// 33: 9-byte ecc of 4th 512 bytes // 33: 9-byte ecc of 4th 512 bytes
// 42: unused // 42: unused
// 64: end of space // 64: end of space
for unsigned i = 0; i < 6; ++i:
wdata (0) // For 2 GB nand:
// 0-11: unused/bad block markers
// 12-89: 8 times 9-byte ecc
// 90-127: unused
// 128: end of space
for unsigned i = 0; i < ecc_start; ++i:
wdata (i == 4 ? 0 : 0xff)
for unsigned i = 0; i < 1 << (page_bits - 9); ++i: for unsigned i = 0; i < 1 << (page_bits - 9); ++i:
for unsigned j = 0; j < 9; ++j: for unsigned j = 0; j < 9; ++j:
wdata (ecc[i][j]) wdata (ecc[i][j])
@ -268,9 +295,9 @@ static void write (unsigned a, char *buffer):
unsigned offset= bit & 7 unsigned offset= bit & 7
unsigned byte = bit / 8 unsigned byte = bit / 8
debug ("error detected by parity: %x on %x+%d\n", mask, byte, offset) debug ("error detected by parity: %x on %x+%d\n", mask, byte, offset)
for unsigned i = 0; i < 6; ++i: for unsigned i = 0; i < ecc_start; ++i:
if rdata () != 0: if rdata () != (i == 4 ? 0 : 0xff):
debug ("extra data not 0 at byte %d\n", i) debug ("incorrect extra data at byte %d\n", i)
for unsigned i = 0; i < 1 << (page_bits - 9); ++i: for unsigned i = 0; i < 1 << (page_bits - 9); ++i:
for unsigned j = 0; j < 9; ++j: for unsigned j = 0; j < 9; ++j:
unsigned r = rdata () & 0xff unsigned r = rdata () & 0xff