1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-12-29 19:32:25 +02: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,8 +170,12 @@ 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 ()
if all_ff && (buffer[t] & 0xff) != 0xff:
all_ff = false
if !all_ff || !parity_all_ff:
for unsigned t = 0; t < 9; ++t: for unsigned t = 0; t < 9; ++t:
((volatile char *)&EMC_NFPAR (0))[t] = error[t] ((volatile char *)&EMC_NFPAR (0))[t] = error[t]
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY
@ -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