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;
77 /* Some sanity checking */
78 if ((s_first < 0) || (s_first > s_last)) {
79 printf ("- no sectors to erase\n");
84 for (sect = s_first; sect <= s_last; ++sect) {
85 if (info->protect[sect]) {
90 printf ("- Warning: %d protected sectors will not be erased!\n",
97 for (sect = s_first; sect <= s_last; sect++) {
98 printf("- Erase: Sect: %i @ 0x%08x\n", sect, info->start[sect]);
102 /* NOTE: disabling interrupts on Nios can be very bad since it
103 * also disables the LO_LIMIT exception. It's better here to
104 * set the interrupt priority to 3 & restore it when we're done.
108 /* It's ok to erase multiple sectors provided we don't delay more
109 * than 50 usec between cmds ... at which point the erase time-out
110 * occurs. So don't go and put printf() calls in the loop ... it
111 * won't be very helpful ;-)
113 for (sect = s_first; sect <= s_last; sect++) {
114 if (info->protect[sect] == 0) { /* not protected */
115 addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
122 /* Now just wait for 0xff & provide some user
123 * feedback while we wait. Here we have to grant
124 * timer interrupts. Otherwise get_timer() can't
127 start = get_timer (0);
128 while (*addr2 != 0xff) {
129 udelay (1000 * 1000);
131 if (get_timer (start) > CFG_FLASH_ERASE_TOUT) {
132 printf ("timeout\n");
136 oldpri = ipri (3); /* disallow non important irqs again */
142 /* Restore interrupt priority */
148 /*-----------------------------------------------------------------------
149 * Copy memory to flash, returns:
152 * 2 - Flash not erased
155 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
158 vu_char *cmd = (vu_char *) info->start[0];
159 vu_char *dst = (vu_char *) addr;
165 /* Check for sufficient erase */
167 if ((*dst & b) != b) {
168 printf ("%02x : %02x\n", *dst, b);
172 /* Disable interrupts other than window underflow
173 * (interrupt priority 2)
182 start = get_timer (0);
184 if (get_timer (start) > CFG_FLASH_WRITE_TOUT) {