1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00

start nand-boot; wrap startup

This commit is contained in:
Bas Wijnen
2010-08-10 10:09:50 +02:00
parent 7659673f33
commit e4151e737b
11 changed files with 437 additions and 105 deletions

View File

@@ -472,8 +472,8 @@ Iris::Num start ():
if Iris::recv.protected_data.l == SYSREQ:
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
continue
kdebug ("sysreq event: rebooting device\n")
Iris::reboot ()
kdebug ("sysreq event: powering device off\n")
Iris::poweroff ()
continue
Program *caller = (Program *)Iris::recv.protected_data.l
switch Iris::recv.data[0].l:

View File

@@ -24,49 +24,29 @@
// Standard NAND flash commands
#define CMD_READ0 0
#define CMD_READ1 1
#define CMD_RNDOUT 5
#define CMD_PAGEPROG 0x10
#define CMD_READOOB 0x50
#define CMD_ERASE1 0x60
#define CMD_STATUS 0x70
#define CMD_STATUS_MULTI 0x71
#define CMD_SEQIN 0x80
#define CMD_RNDIN 0x85
#define CMD_READSTART 0x30
#define CMD_READID 0x90
#define CMD_ERASE2 0xd0
#define CMD_RESET 0xff
// Extended commands for large page devices
#define CMD_READSTART 0x30
#define CMD_SEQIN 0x80
#define CMD_PAGEPROG 0x10
#define CMD_ERASE1 0x60
#define CMD_ERASE2 0xd0
#define CMD_RNDIN 0x85
#define CMD_RNDOUT 5
#define CMD_RNDOUTSTART 0xE0
#define CMD_CACHEDPROG 0x15
// Extended commands for AG-AND device
// Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but
// there is no way to distinguish that from NAND_CMD_READ0
// until the remaining sequence of commands has been completed
// so add a high order bit and mask it off in the command.
#define CMD_DEPLETE1 0x100
#define CMD_DEPLETE2 0x38
#define CMD_STATUS_MULTI 0x71
#define CMD_STATUS_ERROR 0x72
// multi-bank error status (banks 0-3)
#define CMD_STATUS_ERROR0 0x73
#define CMD_STATUS_ERROR1 0x74
#define CMD_STATUS_ERROR2 0x75
#define CMD_STATUS_ERROR3 0x76
#define CMD_STATUS_RESET 0x7f
#define CMD_STATUS_CLEAR 0xff
#define CMD_NONE -1
#define CMD_STATUS 0x70
// Status bits
#define STATUS_FAIL 0x01
#define STATUS_FAIL_N1 0x02
#define STATUS_TRUE_READY 0x20
#define STATUS_READY 0x40
#define STATUS_WP 0x80
#define STATUS_WRITABLE 0x80
static volatile char *command
static volatile char *address
@@ -154,21 +134,12 @@ static void reset ():
//unsigned num_planes = 1 << ((d >> 2) & 3)
//unsigned plane_bits = 26 + ((d >> 4) & 7)
static void read (unsigned a, char *buffer):
static bool read (unsigned a, char *buffer):
unsigned column = a & ((1 << page_bits) - 1)
unsigned row = a >> page_bits
//Iris::debug ("reading: %x/%x/%x: ", a, row, column)
cmd (CMD_READ0)
addr (column)
addr (column >> 8)
addr (row)
addr (row >> 8)
addr (row >> 16)
cmd (CMD_READSTART)
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST
for unsigned t = 0; t < 0x200; ++t:
buffer[t] = rdata ()
char error[9]
// Read oob information first.
char error[12]
// Spare space (starts at 1 << page_bits)
// 0: unused
// 2: detect valid data (at least 1 byte == 0 means valid)
@@ -179,13 +150,35 @@ static void read (unsigned a, char *buffer):
// 33: 9-byte ecc of 4th 512 bytes
// 42: unused
// 64: end of space
unsigned errcol = (1 << page_bits) + (column >> 9) * 9 + 6
unsigned col = (1 << page_bits) + 2
cmd (CMD_READ0)
addr (col)
addr (col >> 8)
addr (row)
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:
return false
col = (1 << page_bits) + 6 + 9 * (column >> 9)
cmd (CMD_RNDOUT)
addr (errcol)
addr (errcol >> 8)
addr (col)
addr (col >> 8)
cmd (CMD_RNDOUTSTART)
for unsigned t = 0; t < 9; ++t:
error[t] = rdata ()
cmd (CMD_RNDOUT)
addr (column)
addr (column >> 8)
cmd (CMD_RNDOUTSTART)
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST
for unsigned t = 0; t < 0x200; ++t:
buffer[t] = rdata ()
EMC_NFPAR (0) = ((unsigned *)error)[0]
EMC_NFPAR (1) = ((unsigned *)error)[1]
EMC_NFPAR (2) = error[9]
@@ -198,24 +191,39 @@ static void read (unsigned a, char *buffer):
buffer[EMC_NFERR (i) >> 16] ^= EMC_NFERR (i) & 0xff
static void write (unsigned a, char *buffer):
kdebug_line ()
unsigned row = a >> page_bits
kdebug_line ()
//Iris::debug ("writing: %x/%x: ", a, row)
cmd (CMD_SEQIN)
kdebug_line ()
addr (0)
kdebug_line ()
addr (0)
kdebug_line ()
addr (row)
kdebug_line ()
addr (row >> 8)
kdebug_line ()
addr (row >> 16)
char ecc[4][9]
kdebug_line ()
char ecc[4][12]
for unsigned i = 0; i < 0x4; ++i:
kdebug_line ()
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_ENCODING | EMC_NFECR_ERST
Iris::debug ("writing data from %x\n", (unsigned)buffer + i * 0x200)
for unsigned j = 0; j < 0x200; ++j:
wdata (buffer[i * 0x200 + j])
kdebug_line ()
while !(EMC_NFINTS & EMC_NFINTS_ENCF):
Iris::schedule ()
kdebug_line ()
((unsigned *)ecc[i])[0] = EMC_NFPAR (0)
kdebug_line ()
((unsigned *)ecc[i])[1] = EMC_NFPAR (1)
kdebug_line ()
ecc[i][9] = EMC_NFPAR (2)
kdebug_line ()
// Spare space (starts at 1 << page_bits)
// 0: unused
// 2: detect valid data (at least 1 byte == 0 means valid)
@@ -228,10 +236,13 @@ static void write (unsigned a, char *buffer):
// 64: end of space
for unsigned i = 0; i < 6; ++i:
wdata (0)
kdebug_line ()
for unsigned i = 0; i < 4; ++i:
for unsigned j = 0; j < 9; ++j:
wdata (ecc[i][j])
kdebug_line ()
cmd (CMD_PAGEPROG)
kdebug_line ()
Iris::debug ("nand program %d done\n", a)
static void erase (unsigned a):
@@ -243,9 +254,12 @@ static void erase (unsigned a):
cmd (CMD_ERASE2)
Iris::debug ("nand erase %d done\n", a)
extern "C":
extern char file_start, file_end
Iris::Num start ():
kdebug ("starting nand operation in 10 seconds\n")
Iris::sleep (10 * HZ)
//kdebug ("starting nand operation in 10 seconds\n")
//Iris::sleep (10 * HZ)
map_emc ()
map_gpio ()
@@ -256,18 +270,42 @@ Iris::Num start ():
reset ()
#if 0
erase (0)
kdebug_line ()
char *source = &file_start
kdebug_line ()
unsigned a = 0x0000
kdebug_line ()
while source < &file_end:
kdebug_line ()
write (a, source)
a += 0x800
source += 0x800
kdebug_line ()
#endif
char buffer[0x800]
//erase (0)
kdebug_line ()
// Send nand contents to serial port.
for unsigned a = 0; a < 0x4000; a += 0x200:
for unsigned a = 0; a < 0x2000; a += 0x200:
read (a, buffer)
for unsigned s = 0; s < 0x10; ++s:
for unsigned t = 0; t < 0x20; ++t:
for unsigned s = 0; s < 0x8; ++s:
for unsigned t = 0; t < 0x40; ++t:
kdebug (" ")
kdebug_num (buffer[s * 0x20 + t], 2)
kdebug_num (buffer[s * 0x40 + t], 2)
kdebug ("\n")
kdebug ("\n")
// Exit.
return 0
asm volatile ("\t.set noreorder\n"
"\t.globl file_start\n"
"\t.globl file_end\n"
"\t.text\n"
"file_start:\n"
"\t.incbin \"mips/nanonote/nand-boot.raw\"\n"
"file_end:\n"
".set reorder")

58
source/rtc.ccp Normal file
View File

@@ -0,0 +1,58 @@
#pypp 0
// Iris: micro-kernel for a capability-based operating system.
// source/rtc.ccp: real-time clock driver.
// Copyright 2010 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "devices.hh"
#define ARCH
#include "arch.hh"
static void ready ():
while !rtc_write_ready ():
Iris::schedule ()
static unsigned get_second ():
ready ()
unsigned ret = rtc_get_second ()
unsigned r2
while true:
ready ()
r2 = rtc_get_second ()
if ret == r2:
return ret
kdebug ("ret != r2\n")
ret = r2
Iris::Num start ():
map_cpm ()
map_rtc ()
cpm_start_rtc ()
ready ()
rtc_enabled ()
ready ()
rtc_set_nc1Hz_val (RTC_CLOCK)
ready ()
rtc_enable_1Hz_irq ()
rtc_clear_alarm_flag ()
rtc_set_hwfcr_val (0)
while true:
ready ()
rtc_clear_1Hz_flag ()
ready ()
Iris::register_interrupt (IRQ_RTC)
Iris::wait ()
kdebug ("tick\n")
return 0