| init.config |
| 1 | 1 | # driver <name> = '<filename>' load a file into memory to be run priviledged. |
| 2 | 2 | # program <name> = '<filename>' load a file into memory to be run normally. |
| 3 | | #driver driver_lcd = "lcd.elf" |
| 4 | | #driver driver_buzzer = "buzzer.elf" |
| 3 | # receive <name> / <type> [, <index>] = <cap> prepare to accept a capability from a named program. |
| 4 | # sysreq <cap> use a capability as the system request keyboard. |
| 5 | # give <name> / <type> [, <index>] = <cap> give this capability to this program when it requests it. |
| 6 | # include <file> include a file as another config file. |
| 7 | # at end of file, the initial threads are killed and the drivers and programs are run as soon as all their dependencies are provided. |
| 8 | |
| 5 | 9 | driver driver_gpio = "gpio.elf" |
| 6 | | #program alarm = "alarm.elf" |
| 7 | | #program gui = "gui.elf" |
| 10 | receive driver_gpio / Keyboard , 0 = keyboard |
| 11 | receive driver_gpio / Keyboard , 1 = sysreq |
| 12 | receive driver_gpio / Event = sdmmc_gpio |
| 13 | sysreq sysreq |
| 14 | |
| 8 | 15 | driver nand = "nand.elf" |
| 9 | | #driver sdmmc = "sd+mmc.elf" |
| 10 | | #program partition = "partition.elf" |
| 11 | | #program fat = "fat.elf" |
| 12 | | #program test = "test.elf" |
| 13 | | #driver rtc = "rtc.elf" |
| 14 | 16 | |
| 15 | | # receive <name> / <type> [, <index>] = <cap> prepare to accept a capability from a named program. |
| 17 | #driver driver_lcd = "lcd.elf" |
| 16 | 18 | #receive driver_lcd / Display = display |
| 17 | 19 | #receive driver_lcd / Setting = display_bright |
| 20 | |
| 21 | #driver driver_buzzer = "buzzer.elf" |
| 18 | 22 | #receive driver_buzzer / Buzzer = buzzer |
| 19 | | receive driver_gpio / Keyboard , 0 = keyboard |
| 20 | | receive driver_gpio / Keyboard , 1 = sysreq |
| 21 | | receive driver_gpio / Event = sdmmc_gpio |
| 22 | | #receive alarm / UI = ui |
| 23 | | #receive sdmmc / WString = sdmmc |
| 24 | | #receive partition / WString, 0 = p0 |
| 25 | | #receive partition / WString, 1 = p1 |
| 26 | | #receive partition / WString, 2 = p2 |
| 27 | | #receive partition / WString, 3 = p3 |
| 28 | | #receive fat / Directory = root |
| 29 | 23 | |
| 30 | | # sysreq <cap> use a capability as the system request keyboard. |
| 31 | | sysreq sysreq |
| 24 | #program alarm = "alarm.elf" |
| 25 | #receive alarm / UI = ui |
| 32 | 26 | |
| 33 | | # give <name> / <type> [, <index>] = <cap> give this capability to this program when it requests it. |
| 27 | #program gui = "gui.elf" |
| 34 | 28 | #give gui / UI = ui |
| 35 | 29 | #give gui / Display = display |
| 36 | 30 | #give gui / Setting = display_bright |
| 37 | 31 | #give gui / Buzzer = buzzer |
| 38 | 32 | #give gui / Keyboard = keyboard |
| 33 | |
| 34 | #driver sdmmc = "sd+mmc.elf" |
| 35 | #receive sdmmc / WString = sdmmc |
| 39 | 36 | #give sdmmc / Event = sdmmc_gpio |
| 37 | |
| 38 | #program partition = "partition.elf" |
| 39 | #receive partition / WString, 0 = p0 |
| 40 | #receive partition / WString, 1 = p1 |
| 41 | #receive partition / WString, 2 = p2 |
| 42 | #receive partition / WString, 3 = p3 |
| 40 | 43 | #give partition / WString = sdmmc |
| 44 | |
| 45 | #program fat = "fat.elf" |
| 46 | #receive fat / Directory = root |
| 41 | 47 | #give fat / WString = p0 |
| 42 | | #give test / Directory = root |
| 43 | 48 | |
| 44 | | # include <file> include a file as another config file. |
| 49 | #program test = "test.elf" |
| 50 | #give test / Directory = root |
| 45 | 51 | |
| 46 | | # at end of file, the initial threads are killed and the drivers and programs are run as soon as all their dependencies are provided. |
| 52 | #driver rtc = "rtc.elf" |
| mips/nand.hhp |
| 1 | #pypp 0 |
| 2 | // Iris: micro-kernel for a capability-based operating system. |
| 3 | // mips/nand.hhp: NAND driver functions, split off to be used in two places. |
| 4 | // The functions are not inline, so this file must be included exactly once per executable that needs it. |
| 5 | // Copyright 2009 Bas Wijnen <wijnen@debian.org> |
| 6 | // |
| 7 | // This program is free software: you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation, either version 3 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // The following defines are taken from mtd/nand.h in the Linux source. |
| 21 | // Everything not in the nand datasheet is thrown out. |
| 22 | |
| 23 | // Standard NAND flash commands |
| 24 | #define CMD_READ0 0 |
| 25 | #define CMD_READSTART 0x30 |
| 26 | |
| 27 | #define CMD_READID 0x90 |
| 28 | |
| 29 | #define CMD_RESET 0xff |
| 30 | |
| 31 | #define CMD_SEQIN 0x80 |
| 32 | #define CMD_PAGEPROG 0x10 |
| 33 | |
| 34 | #define CMD_ERASE1 0x60 |
| 35 | #define CMD_ERASE2 0xd0 |
| 36 | |
| 37 | #define CMD_RNDIN 0x85 |
| 38 | |
| 39 | #define CMD_RNDOUT 5 |
| 40 | #define CMD_RNDOUTSTART 0xe0 |
| 41 | |
| 42 | #define CMD_STATUS 0x70 |
| 43 | |
| 44 | // Status bits |
| 45 | #define STATUS_FAIL 0x01 |
| 46 | #define STATUS_READY 0x40 |
| 47 | #define STATUS_WRITABLE 0x80 |
| 48 | |
| 49 | static volatile char *command |
| 50 | static volatile char *address |
| 51 | static volatile char *data |
| 52 | |
| 53 | static unsigned page_bits |
| 54 | static unsigned redundant_bits |
| 55 | static unsigned block_bits |
| 56 | static unsigned word_size |
| 57 | |
| 58 | static void unbusy (): |
| 59 | while !(gpio_get_port (2) & (1 << 30)): |
| 60 | DELAY () |
| 61 | |
| 62 | static void addr (unsigned d): |
| 63 | unbusy () |
| 64 | *address = d |
| 65 | |
| 66 | static void cmd (unsigned d): |
| 67 | unbusy () |
| 68 | *command = d |
| 69 | |
| 70 | static void wdata (unsigned d): |
| 71 | unbusy () |
| 72 | *data = d |
| 73 | |
| 74 | static unsigned rdata (): |
| 75 | unbusy () |
| 76 | unsigned ret = *data |
| 77 | return ret |
| 78 | |
| 79 | static void reset (): |
| 80 | // Set up. |
| 81 | gpio_as_nand () |
| 82 | EMC_NFCSR = EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1 |
| 83 | |
| 84 | // Reset nand. |
| 85 | cmd (CMD_RESET) |
| 86 | |
| 87 | cmd (CMD_READID) |
| 88 | addr (0) |
| 89 | unsigned d = rdata () |
| 90 | //unsigned maker = d |
| 91 | d = rdata () |
| 92 | //unsigned device = d |
| 93 | d = rdata () |
| 94 | //unsigned internal_chip_number = 1 << (d & 0x3) |
| 95 | //unsigned cell_type = 2 << ((d >> 2) & 0x3) |
| 96 | //unsigned simultaneously_programmed_pages = 1 << ((d >> 4) & 0x3) |
| 97 | //bool can_interleave_program_between_chips = d & 0x40 |
| 98 | //bool can_cache_program = d & 0x80 |
| 99 | d = rdata () |
| 100 | page_bits = 10 + (d & 3) |
| 101 | debug ("page bits: %d\n", page_bits) |
| 102 | redundant_bits = (d & 4 ? 4 : 3) |
| 103 | debug ("redundant bits: %d\n", redundant_bits) |
| 104 | block_bits = 16 + ((d >> 4) & 3) |
| 105 | debug ("block bits: %d\n", block_bits) |
| 106 | word_size = (d & 0x40 ? 16 : 8) |
| 107 | debug ("word size: %d\n", word_size) |
| 108 | //unsigned serial_access_minimum = (d & 0x80 ? 25 : 50) |
| 109 | d = rdata () |
| 110 | //unsigned num_planes = 1 << ((d >> 2) & 3) |
| 111 | //unsigned plane_bits = 26 + ((d >> 4) & 7) |
| 112 | |
| 113 | static bool read (unsigned a, char *buffer): |
| 114 | unsigned column = a & ((1 << page_bits) - 1) |
| 115 | unsigned row = a >> page_bits |
| 116 | debug ("reading %x:", a) |
| 117 | // Read oob information first. |
| 118 | char error[12] |
| 119 | // Spare space (starts at 1 << page_bits) |
| 120 | // 0: unused |
| 121 | // 2: detect valid data (at least 1 byte == 0 means valid) |
| 122 | // 5: unused |
| 123 | // 6: 9-byte ecc of 1st 512 bytes |
| 124 | // 15: 9-byte ecc of 2nd 512 bytes |
| 125 | // 24: 9-byte ecc of 3rd 512 bytes |
| 126 | // 33: 9-byte ecc of 4th 512 bytes |
| 127 | // 42: unused |
| 128 | // 64: end of space |
| 129 | unsigned col = (1 << page_bits) + 2 |
| 130 | cmd (CMD_READ0) |
| 131 | addr (col) |
| 132 | addr (col >> 8) |
| 133 | addr (row) |
| 134 | addr (row >> 8) |
| 135 | addr (row >> 16) |
| 136 | cmd (CMD_READSTART) |
| 137 | bool valid = false |
| 138 | for unsigned t = 0; t < 3; ++t: |
| 139 | if rdata () == 0: |
| 140 | valid = true |
| 141 | break |
| 142 | if !valid: |
| 143 | debug ("invalid page for nand read: %x\n", a) |
| 144 | return false |
| 145 | col = (1 << page_bits) + 6 + 9 * (column >> 9) |
| 146 | cmd (CMD_RNDOUT) |
| 147 | addr (col) |
| 148 | addr (col >> 8) |
| 149 | cmd (CMD_RNDOUTSTART) |
| 150 | //debug ("parity data:") |
| 151 | for unsigned t = 0; t < 9; ++t: |
| 152 | error[t] = rdata () |
| 153 | //debug (" %x", error[t] & 0xff) |
| 154 | //debug ("\n") |
| 155 | cmd (CMD_RNDOUT) |
| 156 | addr (column) |
| 157 | addr (column >> 8) |
| 158 | cmd (CMD_RNDOUTSTART) |
| 159 | EMC_NFINTS = 0 |
| 160 | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST |
| 161 | for unsigned t = 0; t < 0x200; ++t: |
| 162 | buffer[t] = rdata () |
| 163 | for unsigned t = 0; t < 9; ++t: |
| 164 | ((volatile char *)&EMC_NFPAR (0))[t] = error[t] |
| 165 | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY |
| 166 | while !(EMC_NFINTS & EMC_NFINTS_DECF): |
| 167 | DELAY () |
| 168 | unsigned ints = EMC_NFINTS |
| 169 | if ints & EMC_NFINTS_UNCOR: |
| 170 | debug ("uncorrectable error in nand at %x\n", a) |
| 171 | return false |
| 172 | unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT |
| 173 | for unsigned i = 0; i < errs; ++i: |
| 174 | unsigned err = EMC_NFERR (i) |
| 175 | unsigned index = (err >> 16) - 1 |
| 176 | unsigned mask = err & 0x1ff |
| 177 | unsigned bit = index * 9 |
| 178 | unsigned offset= bit & 7 |
| 179 | unsigned byte = bit / 8 |
| 180 | debug ("correcting %x on %x+%d\n", mask, byte, offset) |
| 181 | unsigned data = buffer[byte] | buffer[byte + 1] << 8 |
| 182 | data ^= mask << offset |
| 183 | buffer[byte] = data |
| 184 | buffer[byte + 1] = data >> 8 |
| 185 | for unsigned i = 0; i < 0x10; ++i: |
| 186 | if (buffer[i] & 0xff) < 0x10: |
| 187 | debug (" 0") |
| 188 | else: |
| 189 | debug (" ") |
| 190 | debug ("%x", buffer[i] & 0xff) |
| 191 | debug ("\n") |
| 192 | return true |
| 193 | |
| 194 | static void write (unsigned a, char *buffer): |
| 195 | unsigned row = a >> page_bits |
| 196 | //debug ("writing: %x/%x: ", a, row) |
| 197 | cmd (CMD_SEQIN) |
| 198 | addr (0) |
| 199 | addr (0) |
| 200 | addr (row) |
| 201 | addr (row >> 8) |
| 202 | addr (row >> 16) |
| 203 | char ecc[4][12] |
| 204 | for unsigned i = 0; i < 0x4; ++i: |
| 205 | bool all_ff = true |
| 206 | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_ENCODING | EMC_NFECR_ERST |
| 207 | //debug ("writing data from %x\n", (unsigned)buffer + i * 0x200) |
| 208 | for unsigned j = 0; j < 0x200; ++j: |
| 209 | wdata (buffer[i * 0x200 + j]) |
| 210 | if all_ff && (buffer[i * 0x200 + j] & 0xff) != 0xff: |
| 211 | all_ff = false |
| 212 | if !all_ff: |
| 213 | while !(EMC_NFINTS & EMC_NFINTS_ENCF): |
| 214 | DELAY () |
| 215 | for unsigned t = 0; t < 9; ++t: |
| 216 | ecc[i][t] = ((volatile char *)&EMC_NFPAR (0))[t] |
| 217 | //debug ("parity for %x:", i * 0x200 + a) |
| 218 | //for unsigned t = 0; t < 9; ++t: |
| 219 | //debug (" %x", ecc[i][t] & 0xff) |
| 220 | //kdebug ("\n") |
| 221 | else: |
| 222 | for unsigned t = 0; t < 9; ++t: |
| 223 | ecc[i][t] = 0xff |
| 224 | // Spare space (starts at 1 << page_bits) |
| 225 | // 0: unused |
| 226 | // 2: detect valid data (at least 1 byte == 0 means valid) |
| 227 | // 5: unused |
| 228 | // 6: 9-byte ecc of 1st 512 bytes |
| 229 | // 15: 9-byte ecc of 2nd 512 bytes |
| 230 | // 24: 9-byte ecc of 3rd 512 bytes |
| 231 | // 33: 9-byte ecc of 4th 512 bytes |
| 232 | // 42: unused |
| 233 | // 64: end of space |
| 234 | for unsigned i = 0; i < 6; ++i: |
| 235 | wdata (0) |
| 236 | for unsigned i = 0; i < 4; ++i: |
| 237 | for unsigned j = 0; j < 9; ++j: |
| 238 | wdata (ecc[i][j]) |
| 239 | cmd (CMD_PAGEPROG) |
| 240 | // Wait at least 100 ns. |
| 241 | DELAY () |
| 242 | cmd (CMD_READ0) |
| 243 | addr (0) |
| 244 | addr (0) |
| 245 | addr (row) |
| 246 | addr (row >> 8) |
| 247 | addr (row >> 16) |
| 248 | cmd (CMD_READSTART) |
| 249 | for unsigned i = 0; i < 4; ++i: |
| 250 | EMC_NFINTS = 0 |
| 251 | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST |
| 252 | for unsigned t = 0; t < 0x200; ++t: |
| 253 | unsigned r = rdata () & 0xff |
| 254 | if r != (buffer[i * 0x200 + t] & 0xff): |
| 255 | debug ("program error at %x: %x != %x\n", i * 0x200 + t, buffer[i * 0x200 + t] & 0xff, r) |
| 256 | for unsigned t = 0; t < 9; ++t: |
| 257 | ((volatile char *)&EMC_NFPAR (0))[t] = ecc[i][t] |
| 258 | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY |
| 259 | while !(EMC_NFINTS & EMC_NFINTS_DECF): |
| 260 | DELAY () |
| 261 | unsigned ints = EMC_NFINTS |
| 262 | if ints & EMC_NFINTS_UNCOR: |
| 263 | debug ("uncorrectable error during verify\n") |
| 264 | continue |
| 265 | unsigned errs = (ints & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT |
| 266 | for unsigned i = 0; i < errs; ++i: |
| 267 | unsigned err = EMC_NFERR (i) |
| 268 | unsigned index = (err >> 16) - 1 |
| 269 | unsigned mask = err & 0x1ff |
| 270 | unsigned bit = index * 9 |
| 271 | unsigned offset= bit & 7 |
| 272 | unsigned byte = bit / 8 |
| 273 | debug ("error detected by parity: %x on %x+%d\n", mask, byte, offset) |
| 274 | for unsigned i = 0; i < 6; ++i: |
| 275 | if rdata () != 0: |
| 276 | debug ("extra data not 0 at byte %d\n", i) |
| 277 | for unsigned i = 0; i < 4; ++i: |
| 278 | for unsigned j = 0; j < 9; ++j: |
| 279 | unsigned r = rdata () & 0xff |
| 280 | if r != (ecc[i][j] & 0xff): |
| 281 | debug ("ecc doesn't match: %x != %x\n", r, ecc[i][j] & 0xff) |
| 282 | debug ("nand program %x:", a) |
| 283 | for unsigned i = 0; i < 0x10; ++i: |
| 284 | if (buffer[i] & 0xff) < 0x10: |
| 285 | debug (" 0") |
| 286 | else: |
| 287 | debug (" ") |
| 288 | debug ("%x", buffer[i] & 0xff) |
| 289 | debug ("\n") |
| 290 | |
| 291 | static void erase (unsigned a): |
| 292 | unsigned row = a >> page_bits |
| 293 | cmd (CMD_ERASE1) |
| 294 | addr (row) |
| 295 | addr (row >> 8) |
| 296 | addr (row >> 16) |
| 297 | cmd (CMD_ERASE2) |
| 298 | debug ("nand erase %d done\n", a) |
| mips/nanonote/Makefile.arch |
| 15 | 15 | # You should have received a copy of the GNU General Public License |
| 16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | |
| 18 | | start_load = 0xa0600000 |
| 18 | start_load = 0x80600000 |
| 19 | 19 | load = 0x80000000 |
| 20 | | UDC_BOOT = comment this out for nand boot |
| 20 | UDC_BOOT = comment this out for sd boot |
| 21 | |
| 22 | arch_iris_sources = mips/interrupts.cc mips/arch.cc |
| 23 | boot_sources = mips/init.cc mips/nanonote/board.cc |
| 24 | arch_headers = mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh mips/nand.hh |
| 25 | udc_boot_programs = udc |
| 26 | sd_boot_programs = sd+mmc partition fat |
| 27 | standard_boot_programs = bootinit |
| 28 | |
| 29 | programs = init gpio lcd bsquare ball buzzer metronome elfrun alarm rtc gui nand test $(udc_boot_programs) $(sd_boot_programs) $(standard_boot_programs) |
| 30 | |
| 31 | ARCH_CPPFLAGS = -I. -Imips -Imips/nanonote -Wa,-mips32 -DNANONOTE -DUSE_SERIAL |
| 32 | CROSS = mipsel-linux-gnu- |
| 33 | OBJDUMP = $(CROSS)objdump |
| 34 | junk = mdebug.abi32 reginfo comment pdr |
| 35 | OBJCOPYFLAGS = $(addprefix --remove-section=.,$(junk)) |
| 21 | 36 | |
| 22 | 37 | ifdef UDC_BOOT |
| 23 | 38 | boot_threads = $(standard_boot_programs) $(udc_boot_programs) |
| 24 | 39 | threadlist = mips/nanonote/threadlist-udc |
| 25 | 40 | ARCH_CXXFLAGS = -DNUM_THREADS=2 |
| 26 | 41 | all: mips/nanonote/nand-boot.raw test |
| 42 | mips/start.o: TARGET = |
| 27 | 43 | else |
| 28 | 44 | boot_threads = $(standard_boot_programs) $(sd_boot_programs) |
| 29 | 45 | threadlist = mips/nanonote/threadlist-sd |
| 30 | 46 | ARCH_CXXFLAGS = -DNUM_THREADS=4 |
| 31 | 47 | all: mips/nanonote/nand-boot.raw iris-sd.tar |
| 48 | mips/start.o: TARGET = -DWRAPPED |
| 32 | 49 | iris-sd.tar: $(addprefix fs/,$(addsuffix .elf,$(programs))) mips/start.raw.gz fs/init.config |
| 33 | | mkimage -A mips -T kernel -a $(start_load) -e a$(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b2-8') -n Iris -d mips/start.raw.gz fs/uimage | sed -e 's/:/;/g' |
| 50 | mkimage -A mips -T kernel -a $(start_load) -e $(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') -n Iris -d mips/start.raw.gz fs/uimage | sed -e 's/:/;/g' |
| 34 | 51 | cd fs && tar cvf ../$@ uimage init.config $(addsuffix .elf,$(programs)) --dereference |
| 35 | 52 | endif |
| 36 | 53 | |
| 37 | | ARCH_CPPFLAGS = -I. -Imips -Imips/nanonote -Wa,-mips32 -DNANONOTE -DUSE_SERIAL |
| 38 | | CROSS = mipsel-linux-gnu- |
| 39 | | OBJDUMP = $(CROSS)objdump |
| 40 | | junk = mdebug.abi32 reginfo comment pdr |
| 41 | | OBJCOPYFLAGS = $(addprefix --remove-section=.,$(junk)) |
| 42 | 54 | iris.elf: LDFLAGS = --omagic -Ttext $(load) |
| 43 | 55 | mips/start.elf: LDFLAGS = --omagic -Ttext $(start_load) |
| 44 | 56 | mips/nanonote/nand-boot.elf: LDFLAGS = --omagic -Ttext 0x80000000 |
| 57 | mips/nanonote/nand-boot.o: mips/nand.hh |
| 45 | 58 | |
| 46 | | source/nand.o: mips/nanonote/nand-boot.raw |
| 47 | | |
| 48 | | arch_iris_sources = mips/interrupts.cc mips/arch.cc |
| 49 | | boot_sources = mips/init.cc mips/nanonote/board.cc |
| 50 | | arch_headers = mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh |
| 51 | | udc_boot_programs = udc |
| 52 | | sd_boot_programs = sd+mmc partition fat |
| 53 | | standard_boot_programs = bootinit |
| 54 | | |
| 55 | | programs = init gpio lcd bsquare ball buzzer metronome elfrun alarm rtc gui nand test $(udc_boot_programs) $(sd_boot_programs) $(standard_boot_programs) |
| 59 | source/nand.o: mips/nand.hh mips/nanonote/nand-boot.raw iris-sd.raw |
| 56 | 60 | |
| 57 | 61 | mips/start.o:mips/start.S Makefile Makefile.arch iris.raw |
| 58 | | $(CC) $(CPPFLAGS) -DSTART=0xa$(shell /bin/sh -c '$(OBJDUMP) -t iris.elf | grep __start$$ | cut -b2-8') -c $< -o $@ |
| 62 | $(CC) $(CPPFLAGS) $(TARGET) -DSTART=0x$(shell /bin/sh -c '$(OBJDUMP) -t iris.elf | grep __start$$ | cut -b1-8') -c $< -o $@ |
| 59 | 63 | |
| 60 | 64 | test: mips/start.raw mips/start.elf mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw $(addsuffix .elf,$(addprefix fs/,$(programs))) fs/init.config |
| 61 | | echo "reboot $(start_load) 0xa$(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b2-8') $<" | nc localhost 5050 |
| 65 | echo "reboot $(start_load) 0x$(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') $<" | nc localhost 5050 |
| 62 | 66 | |
| 63 | 67 | mips/nanonote/server/usb-server: mips/nanonote/server/usb-server.ccp mips/nanonote/server/Makefile.am mips/nanonote/server/configure.ac devices.hh |
| 64 | 68 | $(MAKE) -C mips/nanonote/server |
| mips/nanonote/nand-boot.ccp |
| 16 | 16 | // You should have received a copy of the GNU General Public License |
| 17 | 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | |
| 19 | | // The following defines are taken from mtd/nand.h in the Linux source. |
| 20 | | |
| 21 | 19 | asm volatile ("\t.set noreorder\n" |
| 22 | 20 | "\t.text\n" |
| 23 | 21 | "\t.globl __start\n" |
| ... | ... | |
| 28 | 26 | "\tnop\n" |
| 29 | 27 | "\t.word _gp\n" |
| 30 | 28 | "1:\n" |
| 29 | "\tori $t0, $zero, 0x0006\n" |
| 30 | "\tmtc0 $t0, $12\n" |
| 31 | 31 | "\tlw $gp, 0($ra)\n" |
| 32 | 32 | "\tla $sp, stack + 0x1000\n" |
| 33 | 33 | "\tla $t9, nandboot_start\n" |
| ... | ... | |
| 38 | 38 | #define __KERNEL__ |
| 39 | 39 | #include <jz4740.hh> |
| 40 | 40 | |
| 41 | | // Standard NAND flash commands |
| 42 | | #define CMD_READ0 0 |
| 43 | | #define CMD_READ1 1 |
| 44 | | #define CMD_RNDOUT 5 |
| 45 | | #define CMD_PAGEPROG 0x10 |
| 46 | | #define CMD_READOOB 0x50 |
| 47 | | #define CMD_ERASE1 0x60 |
| 48 | | #define CMD_STATUS 0x70 |
| 49 | | #define CMD_STATUS_MULTI 0x71 |
| 50 | | #define CMD_SEQIN 0x80 |
| 51 | | #define CMD_RNDIN 0x85 |
| 52 | | #define CMD_READID 0x90 |
| 53 | | #define CMD_ERASE2 0xd0 |
| 54 | | #define CMD_RESET 0xff |
| 55 | | |
| 56 | | // Extended commands for large page devices |
| 57 | | #define CMD_READSTART 0x30 |
| 58 | | #define CMD_RNDOUTSTART 0xE0 |
| 59 | | #define CMD_CACHEDPROG 0x15 |
| 60 | | |
| 61 | | // Status bits |
| 62 | | #define STATUS_FAIL 0x01 |
| 63 | | #define STATUS_FAIL_N1 0x02 |
| 64 | | #define STATUS_TRUE_READY 0x20 |
| 65 | | #define STATUS_READY 0x40 |
| 66 | | #define STATUS_WP 0x80 |
| 67 | | |
| 68 | | static volatile char *command |
| 69 | | static volatile char *address |
| 70 | | static volatile char *data |
| 71 | | |
| 72 | | static unsigned page_bits |
| 73 | | static unsigned redundant_bits |
| 74 | | static unsigned block_bits |
| 75 | | static unsigned word_size |
| 76 | | |
| 77 | | static void unbusy (): |
| 78 | | while !(gpio_get_port (2) & (1 << 30)): |
| 79 | | // Do nothing. |
| 80 | | // Delay. |
| 81 | | for unsigned i = 0; i < 1000; ++i: |
| 82 | | gpio_set (0, 0) |
| 83 | | |
| 84 | | static void addr (unsigned d): |
| 85 | | unbusy () |
| 86 | | *address = d |
| 87 | | unbusy () |
| 88 | | |
| 89 | | static void cmd (unsigned d): |
| 90 | | unbusy () |
| 91 | | *command = d |
| 92 | | unbusy () |
| 93 | | |
| 94 | | static void wdata (unsigned d): |
| 95 | | unbusy () |
| 96 | | *data = d |
| 97 | | unbusy () |
| 98 | | |
| 99 | | static unsigned rdata (): |
| 100 | | unbusy () |
| 101 | | unsigned ret = *data |
| 102 | | unbusy () |
| 103 | | return ret |
| 104 | | |
| 105 | | // Reset nand controller. |
| 106 | | static void reset (): |
| 107 | | unsigned base = 0xa0000000 + 0x18000000 |
| 108 | | data = (volatile char *)base |
| 109 | | command = (volatile char *)(base + 0x8000) |
| 110 | | address = (volatile char *)(base + 0x10000) |
| 111 | | |
| 112 | | // Set up. |
| 113 | | gpio_as_nand () |
| 114 | | EMC_NFCSR = EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1 |
| 115 | | |
| 116 | | // Reset nand. |
| 117 | | cmd (CMD_RESET) |
| 118 | | |
| 119 | | cmd (CMD_READID) |
| 120 | | addr (0) |
| 121 | | unsigned d = rdata () |
| 122 | | //unsigned maker = d |
| 123 | | d = rdata () |
| 124 | | //unsigned device = d |
| 125 | | d = rdata () |
| 126 | | //unsigned internal_chip_number = 1 << (d & 0x3) |
| 127 | | //unsigned cell_type = 2 << ((d >> 2) & 0x3) |
| 128 | | //unsigned simultaneously_programmed_pages = 1 << ((d >> 4) & 0x3) |
| 129 | | //bool can_interleave_program_between_chips = d & 0x40 |
| 130 | | //bool can_cache_program = d & 0x80 |
| 131 | | d = rdata () |
| 132 | | page_bits = 10 + (d & 3) |
| 133 | | redundant_bits = (d & 4 ? 4 : 3) |
| 134 | | block_bits = 16 + ((d >> 4) & 3) |
| 135 | | word_size = (d & 0x40 ? 16 : 8) |
| 136 | | //unsigned serial_access_minimum = (d & 0x80 ? 25 : 50) |
| 137 | | d = rdata () |
| 138 | | //unsigned num_planes = 1 << ((d >> 2) & 3) |
| 139 | | //unsigned plane_bits = 26 + ((d >> 4) & 7) |
| 140 | | |
| 141 | | // Read 512 bytes from nand and store them into buffer. a must be aligned. |
| 142 | | // Return value is true if the oob claims there is valid data. |
| 143 | | static bool read (unsigned a, char *buffer): |
| 144 | | unsigned column = a & ((1 << page_bits) - 1) |
| 145 | | unsigned row = a >> page_bits |
| 146 | | cmd (CMD_READ0) |
| 147 | | addr (column) |
| 148 | | addr (column >> 8) |
| 149 | | addr (row) |
| 150 | | addr (row >> 8) |
| 151 | | addr (row >> 16) |
| 152 | | cmd (CMD_READSTART) |
| 153 | | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST |
| 154 | | for unsigned t = 0; t < 0x200; ++t: |
| 155 | | buffer[t] = rdata () |
| 156 | | EMC_NFECR = EMC_NFECR_RS | EMC_NFECR_RS_DECODING |
| 157 | | char error[9] |
| 158 | | // Spare space (starts at 1 << page_bits) |
| 159 | | // 0: unused |
| 160 | | // 2: detect valid data (at least 1 byte == 0 means valid) |
| 161 | | // 5: unused |
| 162 | | // 6: 9-byte ecc of 1st 512 bytes |
| 163 | | // 15: 9-byte ecc of 2nd 512 bytes |
| 164 | | // 24: 9-byte ecc of 3rd 512 bytes |
| 165 | | // 33: 9-byte ecc of 4th 512 bytes |
| 166 | | // 42: unused |
| 167 | | // 64: end of space |
| 168 | | unsigned validcol = (1 << page_bits) + 2 |
| 169 | | bool valid = false |
| 170 | | cmd (CMD_RNDOUT) |
| 171 | | addr (validcol) |
| 172 | | addr (validcol >> 8) |
| 173 | | cmd (CMD_RNDOUTSTART) |
| 174 | | for unsigned t = 0; t < 3; ++t: |
| 175 | | valid = rdata () == 0 || valid |
| 176 | | unsigned errcol = (1 << page_bits) + (column >> 9) * 9 + 6 |
| 177 | | cmd (CMD_RNDOUT) |
| 178 | | addr (errcol) |
| 179 | | addr (errcol >> 8) |
| 180 | | cmd (CMD_RNDOUTSTART) |
| 181 | | for unsigned t = 0; t < 9; ++t: |
| 182 | | error[t] = rdata () |
| 183 | | EMC_NFPAR (0) = ((unsigned *)error)[0] |
| 184 | | EMC_NFPAR (1) = ((unsigned *)error)[1] |
| 185 | | EMC_NFPAR (2) = error[9] |
| 186 | | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY |
| 187 | | while !(EMC_NFINTS & EMC_NFINTS_DECF): |
| 188 | | // Do nothing. |
| 189 | | unsigned errs = (EMC_NFINTS & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT |
| 190 | | for unsigned i = 0; i < errs; ++i: |
| 191 | | buffer[EMC_NFERR (i) >> 16] ^= EMC_NFERR (i) & 0xff |
| 41 | #define DELAY() |
| 42 | |
| 43 | static void debug (unsigned ch): |
| 44 | while !(UART0_LSR & UARTLSR_TDRQ): |
| 45 | UART0_TDR = ch |
| 46 | |
| 47 | static void debug_num (unsigned num, unsigned base, unsigned min_digits = 1): |
| 48 | char const *encode = "0123456789abcdef" |
| 49 | unsigned digits = 1 |
| 50 | unsigned power = 1 |
| 51 | while power <= num / base || min_digits > digits: |
| 52 | power *= base |
| 53 | ++digits |
| 54 | for unsigned i = 0; i < digits; ++i: |
| 55 | unsigned d = num / power |
| 56 | debug (encode[d]) |
| 57 | num -= d * power |
| 58 | power /= base |
| 59 | |
| 60 | static void debug (char const *f, ...): |
| 61 | unsigned *last = (unsigned *)&f |
| 62 | while *f: |
| 63 | if *f == '%': |
| 64 | ++f |
| 65 | switch *f: |
| 66 | case '%': |
| 67 | debug ('%') |
| 68 | break |
| 69 | case 'd': |
| 70 | ++last |
| 71 | debug_num (*last, 10) |
| 72 | break |
| 73 | case 'x': |
| 74 | ++last |
| 75 | debug_num (*last, 0x10) |
| 76 | break |
| 77 | case 's': |
| 78 | ++last |
| 79 | char *str = (char*)*last |
| 80 | while *str: |
| 81 | debug (*str++) |
| 82 | break |
| 83 | default: |
| 84 | debug ("warning: invalid character in dbg format string\n") |
| 85 | break |
| 86 | else: |
| 87 | debug (*f) |
| 88 | ++f |
| 89 | |
| 90 | #define debug_line() debug ("nand-boot line %d\n", __LINE__) |
| 91 | |
| 92 | #include "nand.hh" |
| 93 | |
| 94 | static void setup_uart (): |
| 95 | cpm_start_uart0 () |
| 96 | gpio_as_uart0 () |
| 97 | UART0_IER = 0 |
| 98 | UART0_FCR = 0 |
| 99 | UART0_MCR = 0 |
| 100 | UART0_SIRCR = 0 |
| 101 | UART0_UACR = 0 |
| 102 | UART0_UMR = 16 |
| 103 | UART0_LCR = UARTLCR_WLEN_8 | UARTLCR_STOP1 | UARTLCR_DLAB |
| 104 | unsigned const baud = 57600 |
| 105 | unsigned uart_div = 12000000 / 16 / baud |
| 106 | UART0_DLHR = (uart_div >> 8) & 0xff |
| 107 | UART0_DLLR = uart_div & 0xff |
| 108 | UART0_LCR = UARTLCR_WLEN_8 | UARTLCR_STOP1 |
| 109 | UART0_FCR = UARTFCR_UUE | UARTFCR_FE | UARTFCR_RFLS | UARTFCR_TFLS |
| 110 | debug ("\n\nNand-boot: serial port initialized\n") |
| 192 | 111 | |
| 193 | 112 | extern "C": |
| 194 | 113 | void nandboot_start (): |
| 114 | unsigned base = 0x18000000 + 0xa0000000 |
| 115 | data = (volatile char *)base |
| 116 | command = (volatile char *)(base + 0x8000) |
| 117 | address = (volatile char *)(base + 0x10000) |
| 118 | pll_init () |
| 119 | cpm_start_all () |
| 120 | gpio_as_sdram_16bit () |
| 121 | gpio_as_nand () |
| 122 | setup_sdram () |
| 123 | setup_uart () |
| 195 | 124 | reset () |
| 196 | 125 | // Load contents of nand flash (from 0x4000) into 0xa0600000; |
| 197 | 126 | unsigned a = 0x4000 |
| ... | ... | |
| 199 | 128 | while read (a, (char *)target): |
| 200 | 129 | a += 0x200 |
| 201 | 130 | target += 0x200 |
| 131 | // Tell about what'll happen. |
| 132 | debug ("Jumping to a0600000:\n") |
| 133 | for unsigned d = 0; d < 0x40; ++d: |
| 134 | debug (" ") |
| 135 | debug_num (((char *)0xa0600000)[d] & 0xff, 16, 2) |
| 136 | debug ('\n') |
| 137 | // Wait for the serial port to finish. |
| 138 | while !(UART0_LSR & UARTLSR_TEMT): |
| 202 | 139 | // Then jump to 0xa0600000. |
| 203 | | return ((void (*)())0xa0600000) () |
| 140 | ((void (*)())0xa0600000) () |
| 204 | 141 | |
| 205 | 142 | unsigned char stack[0x1000] |
| 206 | 143 | |
| source/nand.ccp |
| 16 | 16 | // You should have received a copy of the GNU General Public License |
| 17 | 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | |
| 19 | #define DELAY Iris::schedule |
| 20 | |
| 19 | 21 | #include "devices.hh" |
| 20 | 22 | #define ARCH |
| 21 | 23 | #include "arch.hh" |
| 24 | #define debug Iris::debug |
| 25 | #include "nand.hh" |
| 22 | 26 | |
| 23 | | // The following defines are taken from mtd/nand.h in the Linux source. |
| 24 | | |
| 25 | | // Standard NAND flash commands |
| 26 | | #define CMD_READ0 0 |
| 27 | | #define CMD_READSTART 0x30 |
| 28 | | |
| 29 | | #define CMD_READID 0x90 |
| 30 | | |
| 31 | | #define CMD_RESET 0xff |
| 32 | | |
| 33 | | #define CMD_SEQIN 0x80 |
| 34 | | #define CMD_PAGEPROG 0x10 |
| 35 | | |
| 36 | | #define CMD_ERASE1 0x60 |
| 37 | | #define CMD_ERASE2 0xd0 |
| 38 | | |
| 39 | | #define CMD_RNDIN 0x85 |
| 40 | | |
| 41 | | #define CMD_RNDOUT 5 |
| 42 | | #define CMD_RNDOUTSTART 0xE0 |
| 43 | | |
| 44 | | #define CMD_STATUS 0x70 |
| 45 | | |
| 46 | | // Status bits |
| 47 | | #define STATUS_FAIL 0x01 |
| 48 | | #define STATUS_READY 0x40 |
| 49 | | #define STATUS_WRITABLE 0x80 |
| 50 | | |
| 51 | | static volatile char *command |
| 52 | | static volatile char *address |
| 53 | | static volatile char *data |
| 54 | | |
| 55 | | static unsigned page_bits |
| 56 | | static unsigned redundant_bits |
| 57 | | static unsigned block_bits |
| 58 | | static unsigned word_size |
| 59 | | |
| 60 | | static void unbusy (): |
| 61 | | while !(gpio_get_port (2) & (1 << 30)): |
| 62 | | Iris::schedule () |
| 63 | | Iris::schedule () |
| 64 | | |
| 65 | | static void addr (unsigned d): |
| 66 | | unbusy () |
| 67 | | *address = d |
| 68 | | unbusy () |
| 27 | extern "C": |
| 28 | extern char file_start, file_mid, file_end |
| 69 | 29 | |
| 70 | | static void cmd (unsigned d): |
| 71 | | unbusy () |
| 72 | | *command = d |
| 73 | | unbusy () |
| 30 | Iris::Num start (): |
| 31 | //kdebug ("starting nand operation in 10 seconds\n") |
| 32 | //Iris::sleep (10 * HZ) |
| 74 | 33 | |
| 75 | | static void wdata (unsigned d): |
| 76 | | unbusy () |
| 77 | | *data = d |
| 78 | | unbusy () |
| 34 | map_emc () |
| 35 | map_gpio () |
| 79 | 36 | |
| 80 | | static unsigned rdata (): |
| 81 | | unbusy () |
| 82 | | unsigned ret = *data |
| 83 | | unbusy () |
| 84 | | return ret |
| 37 | // Arbitrary addresses where the pages are mapped. |
| 38 | command = (volatile char *)0x15000 |
| 39 | address = (volatile char *)0x16000 |
| 40 | data = (volatile char *)0x17000 |
| 85 | 41 | |
| 86 | | static void reset (): |
| 87 | 42 | Iris::Page data_page = Iris::my_memory.create_page () |
| 88 | 43 | Iris::Page command_page = Iris::my_memory.create_page () |
| 89 | 44 | Iris::Page address_page = Iris::my_memory.create_page () |
| ... | ... | |
| 101 | 56 | Iris::free_cap (command_page) |
| 102 | 57 | Iris::free_cap (address_page) |
| 103 | 58 | |
| 104 | | // Set up. |
| 105 | | gpio_as_nand () |
| 106 | | EMC_NFCSR = EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1 |
| 107 | | |
| 108 | | // Reset nand. |
| 109 | | cmd (CMD_RESET) |
| 110 | | |
| 111 | | cmd (CMD_READID) |
| 112 | | addr (0) |
| 113 | | unsigned d = rdata () |
| 114 | | //unsigned maker = d |
| 115 | | d = rdata () |
| 116 | | //unsigned device = d |
| 117 | | d = rdata () |
| 118 | | //unsigned internal_chip_number = 1 << (d & 0x3) |
| 119 | | //unsigned cell_type = 2 << ((d >> 2) & 0x3) |
| 120 | | //unsigned simultaneously_programmed_pages = 1 << ((d >> 4) & 0x3) |
| 121 | | //bool can_interleave_program_between_chips = d & 0x40 |
| 122 | | //bool can_cache_program = d & 0x80 |
| 123 | | d = rdata () |
| 124 | | page_bits = 10 + (d & 3) |
| 125 | | Iris::debug ("page bits: %d\n", page_bits) |
| 126 | | redundant_bits = (d & 4 ? 4 : 3) |
| 127 | | Iris::debug ("redundant bits: %d\n", redundant_bits) |
| 128 | | block_bits = 16 + ((d >> 4) & 3) |
| 129 | | Iris::debug ("block bits: %d\n", block_bits) |
| 130 | | word_size = (d & 0x40 ? 16 : 8) |
| 131 | | Iris::debug ("word size: %d\n", word_size) |
| 132 | | //unsigned serial_access_minimum = (d & 0x80 ? 25 : 50) |
| 133 | | d = rdata () |
| 134 | | //unsigned num_planes = 1 << ((d >> 2) & 3) |
| 135 | | //unsigned plane_bits = 26 + ((d >> 4) & 7) |
| 136 | | |
| 137 | | static bool read (unsigned a, char *buffer): |
| 138 | | unsigned column = a & ((1 << page_bits) - 1) |
| 139 | | unsigned row = a >> page_bits |
| 140 | | //Iris::debug ("reading: %x/%x/%x: ", a, row, column) |
| 141 | | // Read oob information first. |
| 142 | | char error[12] |
| 143 | | // Spare space (starts at 1 << page_bits) |
| 144 | | // 0: unused |
| 145 | | // 2: detect valid data (at least 1 byte == 0 means valid) |
| 146 | | // 5: unused |
| 147 | | // 6: 9-byte ecc of 1st 512 bytes |
| 148 | | // 15: 9-byte ecc of 2nd 512 bytes |
| 149 | | // 24: 9-byte ecc of 3rd 512 bytes |
| 150 | | // 33: 9-byte ecc of 4th 512 bytes |
| 151 | | // 42: unused |
| 152 | | // 64: end of space |
| 153 | | unsigned col = (1 << page_bits) + 2 |
| 154 | | cmd (CMD_READ0) |
| 155 | | addr (col) |
| 156 | | addr (col >> 8) |
| 157 | | addr (row) |
| 158 | | addr (row >> 8) |
| 159 | | addr (row >> 16) |
| 160 | | cmd (CMD_READSTART) |
| 161 | | bool valid = false |
| 162 | | for unsigned t = 0; t < 3; ++t: |
| 163 | | if rdata () == 0: |
| 164 | | valid = true |
| 165 | | break |
| 166 | | if !valid: |
| 167 | | return false |
| 168 | | col = (1 << page_bits) + 6 + 9 * (column >> 9) |
| 169 | | cmd (CMD_RNDOUT) |
| 170 | | addr (col) |
| 171 | | addr (col >> 8) |
| 172 | | cmd (CMD_RNDOUTSTART) |
| 173 | | for unsigned t = 0; t < 9; ++t: |
| 174 | | error[t] = rdata () |
| 175 | | cmd (CMD_RNDOUT) |
| 176 | | addr (column) |
| 177 | | addr (column >> 8) |
| 178 | | cmd (CMD_RNDOUTSTART) |
| 179 | | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST |
| 180 | | for unsigned t = 0; t < 0x200; ++t: |
| 181 | | buffer[t] = rdata () |
| 182 | | EMC_NFPAR (0) = ((unsigned *)error)[0] |
| 183 | | EMC_NFPAR (1) = ((unsigned *)error)[1] |
| 184 | | EMC_NFPAR (2) = error[9] |
| 185 | | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY |
| 186 | | while !(EMC_NFINTS & EMC_NFINTS_DECF): |
| 187 | | Iris::schedule () |
| 188 | | unsigned errs = (EMC_NFINTS & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT |
| 189 | | for unsigned i = 0; i < errs; ++i: |
| 190 | | Iris::debug ("correcting %x on %x\n", EMC_NFERR (i) & 0xff, EMC_NFERR (i) >> 16) |
| 191 | | buffer[EMC_NFERR (i) >> 16] ^= EMC_NFERR (i) & 0xff |
| 192 | | |
| 193 | | static void write (unsigned a, char *buffer): |
| 194 | | kdebug_line () |
| 195 | | unsigned row = a >> page_bits |
| 196 | | kdebug_line () |
| 197 | | //Iris::debug ("writing: %x/%x: ", a, row) |
| 198 | | cmd (CMD_SEQIN) |
| 199 | | kdebug_line () |
| 200 | | addr (0) |
| 201 | | kdebug_line () |
| 202 | | addr (0) |
| 203 | | kdebug_line () |
| 204 | | addr (row) |
| 205 | | kdebug_line () |
| 206 | | addr (row >> 8) |
| 207 | | kdebug_line () |
| 208 | | addr (row >> 16) |
| 209 | | kdebug_line () |
| 210 | | char ecc[4][12] |
| 211 | | for unsigned i = 0; i < 0x4; ++i: |
| 212 | | kdebug_line () |
| 213 | | EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_ENCODING | EMC_NFECR_ERST |
| 214 | | Iris::debug ("writing data from %x\n", (unsigned)buffer + i * 0x200) |
| 215 | | for unsigned j = 0; j < 0x200; ++j: |
| 216 | | wdata (buffer[i * 0x200 + j]) |
| 217 | | kdebug_line () |
| 218 | | while !(EMC_NFINTS & EMC_NFINTS_ENCF): |
| 219 | | Iris::schedule () |
| 220 | | kdebug_line () |
| 221 | | ((unsigned *)ecc[i])[0] = EMC_NFPAR (0) |
| 222 | | kdebug_line () |
| 223 | | ((unsigned *)ecc[i])[1] = EMC_NFPAR (1) |
| 224 | | kdebug_line () |
| 225 | | ecc[i][9] = EMC_NFPAR (2) |
| 226 | | kdebug_line () |
| 227 | | // Spare space (starts at 1 << page_bits) |
| 228 | | // 0: unused |
| 229 | | // 2: detect valid data (at least 1 byte == 0 means valid) |
| 230 | | // 5: unused |
| 231 | | // 6: 9-byte ecc of 1st 512 bytes |
| 232 | | // 15: 9-byte ecc of 2nd 512 bytes |
| 233 | | // 24: 9-byte ecc of 3rd 512 bytes |
| 234 | | // 33: 9-byte ecc of 4th 512 bytes |
| 235 | | // 42: unused |
| 236 | | // 64: end of space |
| 237 | | for unsigned i = 0; i < 6; ++i: |
| 238 | | wdata (0) |
| 239 | | kdebug_line () |
| 240 | | for unsigned i = 0; i < 4; ++i: |
| 241 | | for unsigned j = 0; j < 9; ++j: |
| 242 | | wdata (ecc[i][j]) |
| 243 | | kdebug_line () |
| 244 | | cmd (CMD_PAGEPROG) |
| 245 | | kdebug_line () |
| 246 | | Iris::debug ("nand program %d done\n", a) |
| 247 | | |
| 248 | | static void erase (unsigned a): |
| 249 | | unsigned row = a >> page_bits |
| 250 | | cmd (CMD_ERASE1) |
| 251 | | addr (row) |
| 252 | | addr (row >> 8) |
| 253 | | addr (row >> 16) |
| 254 | | cmd (CMD_ERASE2) |
| 255 | | Iris::debug ("nand erase %d done\n", a) |
| 256 | | |
| 257 | | extern "C": |
| 258 | | extern char file_start, file_end |
| 259 | | |
| 260 | | Iris::Num start (): |
| 261 | | //kdebug ("starting nand operation in 10 seconds\n") |
| 262 | | //Iris::sleep (10 * HZ) |
| 263 | | map_emc () |
| 264 | | map_gpio () |
| 265 | | |
| 266 | | // Arbitrary addresses where the pages are mapped. |
| 267 | | command = (volatile char *)0x15000 |
| 268 | | address = (volatile char *)0x16000 |
| 269 | | data = (volatile char *)0x17000 |
| 270 | | |
| 271 | 59 | reset () |
| 272 | 60 | |
| 273 | | |
| 274 | | #if 0 |
| 61 | #if 1 |
| 275 | 62 | erase (0) |
| 276 | | kdebug_line () |
| 277 | 63 | char *source = &file_start |
| 278 | | kdebug_line () |
| 279 | | unsigned a = 0x0000 |
| 280 | | kdebug_line () |
| 64 | unsigned a = 0 |
| 65 | while source < &file_mid: |
| 66 | write (a, source) |
| 67 | a += 0x800 |
| 68 | source += 0x800 |
| 69 | source = &file_mid |
| 70 | a = 0x4000 |
| 281 | 71 | while source < &file_end: |
| 282 | | kdebug_line () |
| 283 | 72 | write (a, source) |
| 284 | 73 | a += 0x800 |
| 285 | 74 | source += 0x800 |
| 286 | | kdebug_line () |
| 287 | 75 | #endif |
| 288 | 76 | |
| 289 | | char buffer[0x800] |
| 290 | | |
| 291 | | kdebug_line () |
| 77 | char buffer[0x200] |
| 292 | 78 | // Send nand contents to serial port. |
| 293 | | for unsigned a = 0; a < 0x2000; a += 0x200: |
| 79 | for unsigned a = 0; a < 0x400; a += 0x200: |
| 294 | 80 | read (a, buffer) |
| 295 | 81 | for unsigned s = 0; s < 0x8; ++s: |
| 296 | 82 | for unsigned t = 0; t < 0x40; ++t: |
| ... | ... | |
| 303 | 89 | |
| 304 | 90 | asm volatile ("\t.set noreorder\n" |
| 305 | 91 | "\t.globl file_start\n" |
| 92 | "\t.globl file_mid\n" |
| 306 | 93 | "\t.globl file_end\n" |
| 307 | 94 | "\t.text\n" |
| 308 | 95 | "file_start:\n" |
| 309 | 96 | "\t.incbin \"mips/nanonote/nand-boot.raw\"\n" |
| 97 | "file_mid:\n" |
| 98 | "\t.incbin \"iris-sd.raw\"\n" |
| 310 | 99 | "file_end:\n" |
| 311 | 100 | ".set reorder") |