mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
mass storage sort of working, but not nice
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
// The following defines are taken from mtd/nand.h in the Linux source.
|
||||
// Everything not in the nand datasheet is thrown out.
|
||||
|
||||
//#define dbgl() debug ("%s:%d\n", __PRETTY_FUNCTION__, __LINE__)
|
||||
#define dbgl()
|
||||
|
||||
// Standard NAND flash commands
|
||||
#define CMD_READ0 0
|
||||
#define CMD_READSTART 0x30
|
||||
@@ -118,7 +121,7 @@ static void reset ():
|
||||
static bool read (unsigned a, char *buffer):
|
||||
unsigned column = a & ((1 << page_bits) - 1)
|
||||
unsigned row = a >> page_bits
|
||||
debug ("reading %x:", a)
|
||||
//debug ("reading %x:", a)
|
||||
// Read oob information first.
|
||||
char error[12]
|
||||
// Spare space (starts at 1 << page_bits)
|
||||
@@ -145,18 +148,20 @@ static bool read (unsigned a, char *buffer):
|
||||
valid = true
|
||||
break
|
||||
if !valid:
|
||||
debug ("invalid page for nand read: %x\n", a)
|
||||
//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:")
|
||||
//debug ("parity data:")
|
||||
for unsigned t = 0; t < 9; ++t:
|
||||
error[t] = rdata ()
|
||||
debug (" %x", error[t] & 0xff)
|
||||
debug ("\n")
|
||||
//debug (" %x", error[t] & 0xff)
|
||||
//debug ("\n")
|
||||
cmd (CMD_RNDOUT)
|
||||
addr (column)
|
||||
addr (column >> 8)
|
||||
@@ -168,10 +173,8 @@ static bool read (unsigned a, char *buffer):
|
||||
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
|
||||
debug ("before\n")
|
||||
while !(EMC_NFINTS & EMC_NFINTS_DECF):
|
||||
DELAY ()
|
||||
debug ("after\n")
|
||||
unsigned ints = EMC_NFINTS
|
||||
if ints & EMC_NFINTS_UNCOR:
|
||||
debug ("uncorrectable error in nand at %x\n", a)
|
||||
@@ -191,16 +194,17 @@ static bool read (unsigned a, char *buffer):
|
||||
buffer[byte + 1] = data >> 8
|
||||
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")
|
||||
return true
|
||||
|
||||
static void write (unsigned a, char *buffer):
|
||||
dbgl ()
|
||||
unsigned row = a >> page_bits
|
||||
//debug ("writing: %x/%x: ", a, row)
|
||||
//debug ("writing: %x/%x\n", a, row)
|
||||
cmd (CMD_SEQIN)
|
||||
addr (0)
|
||||
addr (0)
|
||||
@@ -208,7 +212,9 @@ static void write (unsigned a, char *buffer):
|
||||
addr (row >> 8)
|
||||
addr (row >> 16)
|
||||
char ecc[4][12]
|
||||
dbgl ()
|
||||
for unsigned i = 0; i < 0x4; ++i:
|
||||
dbgl ()
|
||||
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)
|
||||
@@ -219,15 +225,19 @@ 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)
|
||||
@@ -243,9 +253,11 @@ static void write (unsigned a, char *buffer):
|
||||
for unsigned i = 0; i < 4; ++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)
|
||||
@@ -253,7 +265,9 @@ 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 ()
|
||||
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:
|
||||
@@ -278,22 +292,26 @@ 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 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)
|
||||
debug ("nand program %x:", a)
|
||||
dbgl ()
|
||||
//debug ("nand program %x:", a)
|
||||
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)
|
||||
dbgl ()
|
||||
//debug ("\n")
|
||||
|
||||
static void erase (unsigned a):
|
||||
unsigned row = a >> page_bits
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
asm volatile ("\t.set noreorder\n"
|
||||
"\t.text\n"
|
||||
"\t.globl __start\n"
|
||||
"\t.globl addr_0\n"
|
||||
"addr_0:\n"
|
||||
"\t.word ~0\n"
|
||||
"__start:\n"
|
||||
"\tbal 1f\n"
|
||||
@@ -33,6 +35,40 @@ asm volatile ("\t.set noreorder\n"
|
||||
"\tla $t9, nandboot_start\n"
|
||||
"\tjr $t9\n"
|
||||
"\tnop\n"
|
||||
"\t.fill 0x1b8 - (. - addr_0)\n"
|
||||
"\t.word 0xd2b9e1a8\n" // Disk signature.
|
||||
"\t.short 0x0000\n"
|
||||
|
||||
"\t.byte 0x00\n" // bootable: no.
|
||||
"\t.byte 0x00, 0x02, 0x00\n" // first sector chs.
|
||||
"\t.byte 0x83\n" // type.
|
||||
"\t.byte 0x08, 0x18, 0x00\n" // last sector chs.
|
||||
"\t.byte 0x01, 0x00, 0x00, 0x00\n" // first sector, lba.
|
||||
"\t.byte 0xff, 0x01, 0x00, 0x00\n" // size, lba.
|
||||
|
||||
"\t.byte 0x00\n" // bootable: no.
|
||||
"\t.byte 0x08, 0x19, 0x00\n" // first sector chs.
|
||||
"\t.byte 0x83\n" // type.
|
||||
"\t.byte 0x05, 0xe1, 0xf3\n" // last sector chs.
|
||||
"\t.byte 0x00, 0x02, 0x00, 0x00\n" // first sector, lba: 256 kB.
|
||||
"\t.byte 0x00, 0xfe, 0x1f, 0x00\n" // size, lba: 1 GB - first.
|
||||
|
||||
"\t.byte 0\n" // bootable: no.
|
||||
"\t.byte 0, 0, 0\n" // first sector chs.
|
||||
"\t.byte 0\n" // type.
|
||||
"\t.byte 0, 0, 0\n" // last sector chs.
|
||||
"\t.byte 0, 0, 0, 0\n" // first sector, lba.
|
||||
"\t.byte 0, 0, 0, 0\n" // size, lba.
|
||||
|
||||
"\t.byte 0\n" // bootable: no.
|
||||
"\t.byte 0, 0, 0\n" // first sector chs.
|
||||
"\t.byte 0\n" // type.
|
||||
"\t.byte 0, 0, 0\n" // last sector chs.
|
||||
"\t.byte 0, 0, 0, 0\n" // first sector, lba.
|
||||
"\t.byte 0, 0, 0, 0\n" // size, lba.
|
||||
|
||||
"\t.byte 0x55, 0xaa\n" // mbr signature.
|
||||
|
||||
"\t.set reorder")
|
||||
|
||||
#define __KERNEL__
|
||||
|
||||
Reference in New Issue
Block a user