mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-12-28 12:20:49 +02:00
use proper place for 2 GB ecc
This commit is contained in:
parent
8d5e29095e
commit
7e8cc1d25e
@ -58,6 +58,7 @@ static unsigned redundant_bits
|
||||
static unsigned block_bits
|
||||
static unsigned size_bits
|
||||
static unsigned word_size
|
||||
static unsigned ecc_start
|
||||
|
||||
static void unbusy ():
|
||||
while !(gpio_get_port (2) & (1 << 30)):
|
||||
@ -117,6 +118,13 @@ static void reset ():
|
||||
unsigned num_planes_bits = d >> 2 & 3
|
||||
unsigned plane_bits = 26 + (d >> 4 & 7)
|
||||
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):
|
||||
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
|
||||
// 42: unused
|
||||
// 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)
|
||||
addr (col)
|
||||
addr (col >> 8)
|
||||
@ -143,8 +157,11 @@ static bool read (unsigned a, char *buffer):
|
||||
addr (row >> 16)
|
||||
cmd (CMD_READSTART)
|
||||
//debug ("parity data:")
|
||||
bool parity_all_ff = true
|
||||
for unsigned t = 0; t < 9; ++t:
|
||||
error[t] = rdata ()
|
||||
if parity_all_ff && (error[t] & 0xff) != 0xff:
|
||||
parity_all_ff = false
|
||||
//debug (" %x", error[t] & 0xff)
|
||||
//debug ("\n")
|
||||
cmd (CMD_RNDOUT)
|
||||
@ -153,30 +170,34 @@ static bool read (unsigned a, char *buffer):
|
||||
cmd (CMD_RNDOUTSTART)
|
||||
EMC_NFINTS = 0
|
||||
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:
|
||||
buffer[t] = rdata ()
|
||||
for unsigned t = 0; t < 9; ++t:
|
||||
((volatile char *)&EMC_NFPAR (0))[t] = error[t]
|
||||
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY
|
||||
while !(EMC_NFINTS & EMC_NFINTS_DECF):
|
||||
DELAY ()
|
||||
unsigned ints = EMC_NFINTS
|
||||
if ints & EMC_NFINTS_UNCOR:
|
||||
debug ("uncorrectable error in nand at %x\n", a)
|
||||
return false
|
||||
unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT
|
||||
for unsigned i = 0; i < errs; ++i:
|
||||
unsigned err = EMC_NFERR (i)
|
||||
unsigned index = (err >> 16) - 1
|
||||
unsigned mask = err & 0x1ff
|
||||
unsigned bit = index * 9
|
||||
unsigned offset= bit & 7
|
||||
unsigned byte = bit / 8
|
||||
debug ("correcting %x on %x+%d\n", mask, byte, offset)
|
||||
unsigned data = buffer[byte] | buffer[byte + 1] << 8
|
||||
data ^= mask << offset
|
||||
buffer[byte] = data
|
||||
buffer[byte + 1] = data >> 8
|
||||
if all_ff && (buffer[t] & 0xff) != 0xff:
|
||||
all_ff = false
|
||||
if !all_ff || !parity_all_ff:
|
||||
for unsigned t = 0; t < 9; ++t:
|
||||
((volatile char *)&EMC_NFPAR (0))[t] = error[t]
|
||||
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY
|
||||
while !(EMC_NFINTS & EMC_NFINTS_DECF):
|
||||
DELAY ()
|
||||
unsigned ints = EMC_NFINTS
|
||||
if ints & EMC_NFINTS_UNCOR:
|
||||
debug ("uncorrectable error in nand at %x\n", a)
|
||||
return false
|
||||
unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT
|
||||
for unsigned i = 0; i < errs; ++i:
|
||||
unsigned err = EMC_NFERR (i)
|
||||
unsigned index = (err >> 16) - 1
|
||||
unsigned mask = err & 0x1ff
|
||||
unsigned bit = index * 9
|
||||
unsigned offset= bit & 7
|
||||
unsigned byte = bit / 8
|
||||
debug ("correcting %x on %x+%d\n", mask, byte, offset)
|
||||
unsigned data = buffer[byte] | buffer[byte + 1] << 8
|
||||
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:
|
||||
@ -228,8 +249,14 @@ static void write (unsigned a, char *buffer):
|
||||
// 33: 9-byte ecc of 4th 512 bytes
|
||||
// 42: unused
|
||||
// 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 j = 0; j < 9; ++j:
|
||||
wdata (ecc[i][j])
|
||||
@ -268,9 +295,9 @@ 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)
|
||||
for unsigned i = 0; i < 6; ++i:
|
||||
if rdata () != 0:
|
||||
debug ("extra data not 0 at byte %d\n", i)
|
||||
for unsigned i = 0; i < ecc_start; ++i:
|
||||
if rdata () != (i == 4 ? 0 : 0xff):
|
||||
debug ("incorrect extra data at byte %d\n", i)
|
||||
for unsigned i = 0; i < 1 << (page_bits - 9); ++i:
|
||||
for unsigned j = 0; j < 9; ++j:
|
||||
unsigned r = rdata () & 0xff
|
||||
|
Loading…
Reference in New Issue
Block a user