2 * NXT bootstrap interface; NXT flash chip code.
4 * Copyright 2006 David Anderson <david.anderson@calixo.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include <sys/types.h>
34 enum nxt_flash_commands
37 FLASH_CMD_UNLOCK = 0x4,
41 nxt_flash_wait_ready(nxt_t *nxt)
43 nxt_word_t flash_status;
47 NXT_ERR(nxt_read_word(nxt, 0xFFFFFF68, &flash_status));
49 /* Bit 0 is the FRDY field. Set to 1 if the flash controller is
50 * ready to run a new command.
52 } while (!(flash_status & 0x1));
58 nxt_flash_alter_lock(nxt_t *nxt, int region_num,
59 enum nxt_flash_commands cmd)
61 nxt_word_t w = 0x5A000000 | ((64 * region_num) << 8);
64 NXT_ERR(nxt_flash_wait_ready(nxt));
66 /* Flash mode register: FCMN 0x5, FWS 0x1
67 * Flash command register: KEY 0x5A, FCMD = clear-lock-bit (0x4)
68 * Flash mode register: FCMN 0x34, FWS 0x1
70 NXT_ERR(nxt_write_word(nxt, 0xFFFFFF60, 0x00050100));
71 NXT_ERR(nxt_write_word(nxt, 0xFFFFFF64, w));
72 NXT_ERR(nxt_write_word(nxt, 0xFFFFFF60, 0x00340100));
79 nxt_flash_lock_region(nxt_t *nxt, int region_num)
81 return nxt_flash_alter_lock(nxt, region_num, FLASH_CMD_LOCK);
86 nxt_flash_unlock_region(nxt_t *nxt, int region_num)
88 return nxt_flash_alter_lock(nxt, region_num, FLASH_CMD_UNLOCK);
93 nxt_flash_lock_all_regions(nxt_t *nxt)
97 for (i = 0; i < 16; i++)
98 NXT_ERR(nxt_flash_lock_region(nxt, i));
105 nxt_flash_unlock_all_regions(nxt_t *nxt)
109 for (i = 0; i < 16; i++)
110 NXT_ERR(nxt_flash_unlock_region(nxt, i));