2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
30 /*--------------------------------------------------------------------*/
31 void flash_print_info (flash_info_t * info)
36 volatile unsigned char *flash;
38 printf (" Size: %ld KB in %d Sectors\n",
39 info->size >> 10, info->sector_count);
40 printf (" Sector Start Addresses:");
41 for (i = 0; i < info->sector_count; ++i) {
43 /* Check if whole sector is erased */
44 if (i != (info->sector_count - 1))
45 size = info->start[i + 1] - info->start[i];
47 size = info->start[0] + info->size - info->start[i];
49 flash = (volatile unsigned char *) info->start[i];
50 for (k = 0; k < size; k++) {
51 if (*flash++ != 0xff) {
60 printf (" %08lX%s%s", info->start[i], erased ? " E" : " ",
61 info->protect[i] ? "RO " : " ");
66 /*-------------------------------------------------------------------*/
69 int flash_erase (flash_info_t * info, int s_first, int s_last)
71 volatile CFG_FLASH_WORD_SIZE *addr = (CFG_FLASH_WORD_SIZE *) (info->start[0]);
72 volatile CFG_FLASH_WORD_SIZE *addr2;
78 /* Some sanity checking */
79 if ((s_first < 0) || (s_first > s_last)) {
80 printf ("- no sectors to erase\n");
85 for (sect = s_first; sect <= s_last; ++sect) {
86 if (info->protect[sect]) {
91 printf ("- Warning: %d protected sectors will not be erased!\n",
97 /* NOTE: disabling interrupts on Nios can be very bad since it
98 * also disables the LO_LIMIT exception. It's better here to
99 * set the interrupt priority to 3 & restore it when we're done.
103 /* It's ok to erase multiple sectors provided we don't delay more
104 * than 50 usec between cmds ... at which point the erase time-out
105 * occurs. So don't go and put printf() calls in the loop ... it
106 * won't be very helpful ;-)
108 for (sect = s_first; sect <= s_last; sect++) {
109 if (info->protect[sect] == 0) { /* not protected */
110 addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
121 /* Now just wait for 0xff & provide some user feedback while
125 addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
126 start = get_timer (0);
127 while (*addr2 != 0xff) {
128 udelay (1000 * 1000);
130 if (get_timer (start) > CFG_FLASH_ERASE_TOUT) {
131 printf ("timeout\n");
138 /* Restore interrupt priority */
144 /*-----------------------------------------------------------------------
145 * Copy memory to flash, returns:
148 * 2 - Flash not erased
151 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
154 vu_char *cmd = (vu_char *) info->start[0];
155 vu_char *dst = (vu_char *) addr;
161 /* Check for sufficient erase */
163 if ((*dst & b) != b) {
164 printf ("%02x : %02x\n", *dst, b);
168 /* Disable interrupts other than window underflow
169 * (interrupt priority 2)
178 start = get_timer (0);
180 if (get_timer (start) > CFG_FLASH_WRITE_TOUT) {