wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 25 | #include <asm/processor.h> |
| 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 28 | |
| 29 | /*----------------------------------------------------------------------- |
| 30 | * Functions |
| 31 | */ |
| 32 | static int write_word (flash_info_t *info, ulong dest, ulong data); |
| 33 | |
| 34 | /*----------------------------------------------------------------------- |
| 35 | */ |
| 36 | static void flash_get_offsets (ulong base, flash_info_t *info) |
| 37 | { |
| 38 | int i; |
| 39 | short n; |
| 40 | |
| 41 | /* set up sector start address table */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 42 | if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 43 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM640U)) { |
| 44 | for (i = 0; i < info->sector_count; i++) |
| 45 | info->start[i] = base + (i * 0x00010000); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 46 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322B) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 47 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323B) || |
| 48 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) || |
| 49 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324B)) { |
| 50 | /* set sector offsets for bottom boot block type */ |
| 51 | for (i=0; i<8; ++i) { /* 8 x 8k boot sectors */ |
| 52 | info->start[i] = base; |
| 53 | base += 8 << 10; |
| 54 | } |
| 55 | while (i < info->sector_count) { /* 64k regular sectors */ |
| 56 | info->start[i] = base; |
| 57 | base += 64 << 10; |
| 58 | ++i; |
| 59 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 60 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322T) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 61 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323T) || |
| 62 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) || |
| 63 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324T)) { |
| 64 | /* set sector offsets for top boot block type */ |
| 65 | base += info->size; |
| 66 | i = info->sector_count; |
| 67 | for (n=0; n<8; ++n) { /* 8 x 8k boot sectors */ |
| 68 | base -= 8 << 10; |
| 69 | --i; |
| 70 | info->start[i] = base; |
| 71 | } |
| 72 | while (i > 0) { /* 64k regular sectors */ |
| 73 | base -= 64 << 10; |
| 74 | --i; |
| 75 | info->start[i] = base; |
| 76 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 77 | } else { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 78 | if (info->flash_id & FLASH_BTYPE) { |
| 79 | /* set sector offsets for bottom boot block type */ |
| 80 | info->start[0] = base + 0x00000000; |
| 81 | info->start[1] = base + 0x00004000; |
| 82 | info->start[2] = base + 0x00006000; |
| 83 | info->start[3] = base + 0x00008000; |
| 84 | for (i = 4; i < info->sector_count; i++) { |
| 85 | info->start[i] = base + (i * 0x00010000) - 0x00030000; |
| 86 | } |
| 87 | } else { |
| 88 | /* set sector offsets for top boot block type */ |
| 89 | i = info->sector_count - 1; |
| 90 | info->start[i--] = base + info->size - 0x00004000; |
| 91 | info->start[i--] = base + info->size - 0x00006000; |
| 92 | info->start[i--] = base + info->size - 0x00008000; |
| 93 | for (; i >= 0; i--) { |
| 94 | info->start[i] = base + i * 0x00010000; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /*----------------------------------------------------------------------- |
| 101 | */ |
| 102 | void flash_print_info (flash_info_t *info) |
| 103 | { |
| 104 | int i; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 105 | int k; |
| 106 | int size; |
| 107 | int erased; |
| 108 | volatile unsigned long *flash; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 109 | |
| 110 | if (info->flash_id == FLASH_UNKNOWN) { |
| 111 | printf ("missing or unknown FLASH type\n"); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | switch (info->flash_id & FLASH_VENDMASK) { |
| 116 | case FLASH_MAN_AMD: printf ("AMD "); break; |
| 117 | case FLASH_MAN_FUJ: printf ("FUJITSU "); break; |
| 118 | case FLASH_MAN_SST: printf ("SST "); break; |
| 119 | case FLASH_MAN_STM: printf ("ST "); break; |
| 120 | default: printf ("Unknown Vendor "); break; |
| 121 | } |
| 122 | |
| 123 | switch (info->flash_id & FLASH_TYPEMASK) { |
| 124 | case FLASH_AM400B: printf ("AM29LV400B (4 Mbit, bottom boot sect)\n"); |
| 125 | break; |
| 126 | case FLASH_AM400T: printf ("AM29LV400T (4 Mbit, top boot sector)\n"); |
| 127 | break; |
| 128 | case FLASH_AM800B: printf ("AM29LV800B (8 Mbit, bottom boot sect)\n"); |
| 129 | break; |
| 130 | case FLASH_AM800T: printf ("AM29LV800T (8 Mbit, top boot sector)\n"); |
| 131 | break; |
| 132 | case FLASH_AM160B: printf ("AM29LV160B (16 Mbit, bottom boot sect)\n"); |
| 133 | break; |
| 134 | case FLASH_AM160T: printf ("AM29LV160T (16 Mbit, top boot sector)\n"); |
| 135 | break; |
| 136 | case FLASH_AM320T: printf ("AM29LV320T (32 M, top sector)\n"); |
| 137 | break; |
| 138 | case FLASH_AM320B: printf ("AM29LV320B (32 M, bottom sector)\n"); |
| 139 | break; |
| 140 | case FLASH_AMDL322T: printf ("AM29DL322T (32 M, top sector)\n"); |
| 141 | break; |
| 142 | case FLASH_AMDL322B: printf ("AM29DL322B (32 M, bottom sector)\n"); |
| 143 | break; |
| 144 | case FLASH_AMDL323T: printf ("AM29DL323T (32 M, top sector)\n"); |
| 145 | break; |
| 146 | case FLASH_AMDL323B: printf ("AM29DL323B (32 M, bottom sector)\n"); |
| 147 | break; |
| 148 | case FLASH_AM640U: printf ("AM29LV640D (64 M, uniform sector)\n"); |
| 149 | break; |
| 150 | case FLASH_SST800A: printf ("SST39LF/VF800 (8 Mbit, uniform sector size)\n"); |
| 151 | break; |
| 152 | case FLASH_SST160A: printf ("SST39LF/VF160 (16 Mbit, uniform sector size)\n"); |
| 153 | break; |
| 154 | case FLASH_STMW320DT: printf ("M29W320DT (32 M, top sector)\n"); |
| 155 | break; |
| 156 | default: printf ("Unknown Chip Type\n"); |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | printf (" Size: %ld MB in %d Sectors\n", |
| 161 | info->size >> 20, info->sector_count); |
| 162 | |
| 163 | printf (" Sector Start Addresses:"); |
| 164 | for (i=0; i<info->sector_count; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | #ifdef CONFIG_SYS_FLASH_EMPTY_INFO |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 166 | /* |
| 167 | * Check if whole sector is erased |
| 168 | */ |
| 169 | if (i != (info->sector_count-1)) |
| 170 | size = info->start[i+1] - info->start[i]; |
| 171 | else |
| 172 | size = info->start[0] + info->size - info->start[i]; |
| 173 | erased = 1; |
| 174 | flash = (volatile unsigned long *)info->start[i]; |
| 175 | size = size >> 2; /* divide by 4 for longword access */ |
| 176 | for (k=0; k<size; k++) |
| 177 | { |
| 178 | if (*flash++ != 0xffffffff) |
| 179 | { |
| 180 | erased = 0; |
| 181 | break; |
| 182 | } |
| 183 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 184 | |
| 185 | if ((i % 5) == 0) |
| 186 | printf ("\n "); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 187 | /* print empty and read-only info */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 188 | printf (" %08lX%s%s", |
| 189 | info->start[i], |
| 190 | erased ? " E" : " ", |
| 191 | info->protect[i] ? "RO " : " "); |
| 192 | #else |
| 193 | if ((i % 5) == 0) |
| 194 | printf ("\n "); |
| 195 | printf (" %08lX%s", |
| 196 | info->start[i], |
| 197 | info->protect[i] ? " (RO)" : " "); |
| 198 | #endif |
| 199 | |
| 200 | } |
| 201 | printf ("\n"); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | /*----------------------------------------------------------------------- |
| 206 | */ |
| 207 | |
| 208 | |
| 209 | /*----------------------------------------------------------------------- |
| 210 | */ |
| 211 | |
| 212 | /* |
| 213 | * The following code cannot be run from FLASH! |
| 214 | */ |
| 215 | static ulong flash_get_size (vu_long *addr, flash_info_t *info) |
| 216 | { |
| 217 | short i; |
| 218 | short n; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 219 | CONFIG_SYS_FLASH_WORD_SIZE value; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 220 | ulong base = (ulong)addr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 221 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)addr; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 222 | |
wdenk | e55ca7e | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 223 | debug("[%s, %d] Entering ...\n", __FUNCTION__, __LINE__); |
| 224 | |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 225 | /* Write auto select command: read Manufacturer ID */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 226 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 227 | addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 228 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00900090; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 229 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 230 | value = addr2[CONFIG_SYS_FLASH_READ0]; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 231 | |
| 232 | switch (value) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 233 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 234 | info->flash_id = FLASH_MAN_AMD; |
| 235 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | case (CONFIG_SYS_FLASH_WORD_SIZE)FUJ_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 237 | info->flash_id = FLASH_MAN_FUJ; |
| 238 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 239 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 240 | info->flash_id = FLASH_MAN_SST; |
| 241 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 242 | case (CONFIG_SYS_FLASH_WORD_SIZE)STM_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 243 | info->flash_id = FLASH_MAN_STM; |
| 244 | break; |
| 245 | default: |
| 246 | info->flash_id = FLASH_UNKNOWN; |
| 247 | info->sector_count = 0; |
| 248 | info->size = 0; |
| 249 | return (0); /* no or unknown flash */ |
| 250 | } |
| 251 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 252 | value = addr2[CONFIG_SYS_FLASH_READ1]; /* device ID */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 253 | |
| 254 | switch (value) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 255 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV400T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 256 | info->flash_id += FLASH_AM400T; |
| 257 | info->sector_count = 11; |
| 258 | info->size = 0x00080000; |
| 259 | break; /* => 0.5 MB */ |
| 260 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 261 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV400B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 262 | info->flash_id += FLASH_AM400B; |
| 263 | info->sector_count = 11; |
| 264 | info->size = 0x00080000; |
| 265 | break; /* => 0.5 MB */ |
| 266 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 267 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV800T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 268 | info->flash_id += FLASH_AM800T; |
| 269 | info->sector_count = 19; |
| 270 | info->size = 0x00100000; |
| 271 | break; /* => 1 MB */ |
| 272 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 273 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV800B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 274 | info->flash_id += FLASH_AM800B; |
| 275 | info->sector_count = 19; |
| 276 | info->size = 0x00100000; |
| 277 | break; /* => 1 MB */ |
| 278 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 279 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV160T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 280 | info->flash_id += FLASH_AM160T; |
| 281 | info->sector_count = 35; |
| 282 | info->size = 0x00200000; |
| 283 | break; /* => 2 MB */ |
| 284 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 285 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV160B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 286 | info->flash_id += FLASH_AM160B; |
| 287 | info->sector_count = 35; |
| 288 | info->size = 0x00200000; |
| 289 | break; /* => 2 MB */ |
| 290 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 291 | case (CONFIG_SYS_FLASH_WORD_SIZE)STM_ID_29W320DT: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 292 | info->flash_id += FLASH_STMW320DT; |
| 293 | info->sector_count = 67; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 294 | info->size = 0x00400000; break; /* => 4 MB */ |
| 295 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 296 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV320T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 297 | info->flash_id += FLASH_AM320T; |
| 298 | info->sector_count = 71; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 299 | info->size = 0x00400000; break; /* => 4 MB */ |
| 300 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 301 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV320B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 302 | info->flash_id += FLASH_AM320B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 303 | info->sector_count = 71; |
| 304 | info->size = 0x00400000; break; /* => 4 MB */ |
| 305 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 306 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL322T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 307 | info->flash_id += FLASH_AMDL322T; |
| 308 | info->sector_count = 71; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 309 | info->size = 0x00400000; break; /* => 4 MB */ |
| 310 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 311 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL322B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 312 | info->flash_id += FLASH_AMDL322B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 313 | info->sector_count = 71; |
| 314 | info->size = 0x00400000; break; /* => 4 MB */ |
| 315 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 316 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL323T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 317 | info->flash_id += FLASH_AMDL323T; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 318 | info->sector_count = 71; |
| 319 | info->size = 0x00400000; break; /* => 4 MB */ |
| 320 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL323B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 322 | info->flash_id += FLASH_AMDL323B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 323 | info->sector_count = 71; |
| 324 | info->size = 0x00400000; break; /* => 4 MB */ |
| 325 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 326 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV640U: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 327 | info->flash_id += FLASH_AM640U; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 328 | info->sector_count = 128; |
| 329 | info->size = 0x00800000; break; /* => 8 MB */ |
| 330 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 331 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_ID_xF800A: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 332 | info->flash_id += FLASH_SST800A; |
| 333 | info->sector_count = 16; |
| 334 | info->size = 0x00100000; |
| 335 | break; /* => 1 MB */ |
| 336 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 337 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_ID_xF160A: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 338 | info->flash_id += FLASH_SST160A; |
| 339 | info->sector_count = 32; |
| 340 | info->size = 0x00200000; |
| 341 | break; /* => 2 MB */ |
| 342 | |
| 343 | default: |
| 344 | info->flash_id = FLASH_UNKNOWN; |
| 345 | return (0); /* => no or unknown flash */ |
| 346 | |
| 347 | } |
| 348 | |
| 349 | /* set up sector start address table */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 350 | if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 351 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM640U)) { |
| 352 | for (i = 0; i < info->sector_count; i++) |
| 353 | info->start[i] = base + (i * 0x00010000); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 354 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322B) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 355 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323B) || |
| 356 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) || |
| 357 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324B)) { |
| 358 | /* set sector offsets for bottom boot block type */ |
| 359 | for (i=0; i<8; ++i) { /* 8 x 8k boot sectors */ |
| 360 | info->start[i] = base; |
| 361 | base += 8 << 10; |
| 362 | } |
| 363 | while (i < info->sector_count) { /* 64k regular sectors */ |
| 364 | info->start[i] = base; |
| 365 | base += 64 << 10; |
| 366 | ++i; |
| 367 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 368 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322T) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 369 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323T) || |
| 370 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) || |
| 371 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324T)) { |
| 372 | /* set sector offsets for top boot block type */ |
| 373 | base += info->size; |
| 374 | i = info->sector_count; |
| 375 | for (n=0; n<8; ++n) { /* 8 x 8k boot sectors */ |
| 376 | base -= 8 << 10; |
| 377 | --i; |
| 378 | info->start[i] = base; |
| 379 | } |
| 380 | while (i > 0) { /* 64k regular sectors */ |
| 381 | base -= 64 << 10; |
| 382 | --i; |
| 383 | info->start[i] = base; |
| 384 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 385 | } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 386 | /* set sector offsets for top boot block type */ |
| 387 | base += info->size; |
| 388 | i = info->sector_count; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 389 | /* 1 x 16k boot sector */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 390 | base -= 16 << 10; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 391 | --i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 392 | info->start[i] = base; |
| 393 | /* 2 x 8k boot sectors */ |
| 394 | for (n=0; n<2; ++n) { |
| 395 | base -= 8 << 10; |
| 396 | --i; |
| 397 | info->start[i] = base; |
| 398 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 399 | /* 1 x 32k boot sector */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 400 | base -= 32 << 10; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 401 | --i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 402 | info->start[i] = base; |
| 403 | |
| 404 | while (i > 0) { /* 64k regular sectors */ |
| 405 | base -= 64 << 10; |
| 406 | --i; |
| 407 | info->start[i] = base; |
| 408 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 409 | } else { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 410 | if (info->flash_id & FLASH_BTYPE) { |
| 411 | /* set sector offsets for bottom boot block type */ |
| 412 | info->start[0] = base + 0x00000000; |
| 413 | info->start[1] = base + 0x00004000; |
| 414 | info->start[2] = base + 0x00006000; |
| 415 | info->start[3] = base + 0x00008000; |
| 416 | for (i = 4; i < info->sector_count; i++) { |
| 417 | info->start[i] = base + (i * 0x00010000) - 0x00030000; |
| 418 | } |
| 419 | } else { |
| 420 | /* set sector offsets for top boot block type */ |
| 421 | i = info->sector_count - 1; |
| 422 | info->start[i--] = base + info->size - 0x00004000; |
| 423 | info->start[i--] = base + info->size - 0x00006000; |
| 424 | info->start[i--] = base + info->size - 0x00008000; |
| 425 | for (; i >= 0; i--) { |
| 426 | info->start[i] = base + i * 0x00010000; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /* check for protected sectors */ |
| 432 | for (i = 0; i < info->sector_count; i++) { |
| 433 | /* read sector protection at sector address, (A7 .. A0) = 0x02 */ |
| 434 | /* D0 = 1 if protected */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 435 | addr2 = (volatile CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[i]); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 436 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) |
| 437 | info->protect[i] = 0; |
| 438 | else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 439 | info->protect[i] = addr2[CONFIG_SYS_FLASH_READ2] & 1; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* |
| 443 | * Prevent writes to uninitialized FLASH. |
| 444 | */ |
| 445 | if (info->flash_id != FLASH_UNKNOWN) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 446 | addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)info->start[0]; |
| 447 | *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE)0x00F000F0; /* reset bank */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | return (info->size); |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /*----------------------------------------------------------------------- |
| 455 | */ |
| 456 | |
| 457 | int flash_erase (flash_info_t *info, int s_first, int s_last) |
| 458 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 459 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]); |
| 460 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 461 | int flag, prot, sect, l_sect; |
| 462 | ulong start, now, last; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 463 | int i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 464 | |
| 465 | if ((s_first < 0) || (s_first > s_last)) { |
| 466 | if (info->flash_id == FLASH_UNKNOWN) { |
| 467 | printf ("- missing\n"); |
| 468 | } else { |
| 469 | printf ("- no sectors to erase\n"); |
| 470 | } |
| 471 | return 1; |
| 472 | } |
| 473 | |
| 474 | if (info->flash_id == FLASH_UNKNOWN) { |
| 475 | printf ("Can't erase unknown flash type - aborted\n"); |
| 476 | return 1; |
| 477 | } |
| 478 | |
| 479 | prot = 0; |
| 480 | for (sect=s_first; sect<=s_last; ++sect) { |
| 481 | if (info->protect[sect]) { |
| 482 | prot++; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (prot) { |
| 487 | printf ("- Warning: %d protected sectors will not be erased!\n", |
| 488 | prot); |
| 489 | } else { |
| 490 | printf ("\n"); |
| 491 | } |
| 492 | |
| 493 | l_sect = -1; |
| 494 | |
| 495 | /* Disable interrupts which might cause a timeout here */ |
| 496 | flag = disable_interrupts(); |
| 497 | |
| 498 | /* Start erase on unprotected sectors */ |
| 499 | for (sect = s_first; sect<=s_last; sect++) { |
| 500 | if (info->protect[sect] == 0) { /* not protected */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 501 | addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[sect]); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 502 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 503 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 504 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 505 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080; |
| 506 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 507 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 508 | addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00500050; /* block erase */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 509 | for (i=0; i<50; i++) |
| 510 | udelay(1000); /* wait 1 ms */ |
| 511 | } else { |
| 512 | if (sect == s_first) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 513 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 514 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 515 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080; |
| 516 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 517 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 518 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 519 | addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00300030; /* sector erase */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 520 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 521 | l_sect = sect; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /* re-enable interrupts if necessary */ |
| 526 | if (flag) |
| 527 | enable_interrupts(); |
| 528 | |
| 529 | /* wait at least 80us - let's wait 1 ms */ |
| 530 | udelay (1000); |
| 531 | |
| 532 | /* |
| 533 | * We wait for the last triggered sector |
| 534 | */ |
| 535 | if (l_sect < 0) |
| 536 | goto DONE; |
| 537 | |
| 538 | start = get_timer (0); |
| 539 | last = start; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 540 | addr = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[l_sect]); |
| 541 | while ((addr[0] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) != (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) { |
| 542 | if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 543 | printf ("Timeout\n"); |
| 544 | return 1; |
| 545 | } |
| 546 | /* show that we're waiting */ |
| 547 | if ((now - last) > 1000) { /* every second */ |
| 548 | putc ('.'); |
| 549 | last = now; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | DONE: |
| 554 | /* reset to read mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 555 | addr = (CONFIG_SYS_FLASH_WORD_SIZE *)info->start[0]; |
| 556 | addr[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00F000F0; /* reset bank */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 557 | |
| 558 | printf (" done\n"); |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /*----------------------------------------------------------------------- |
| 563 | * Copy memory to flash, returns: |
| 564 | * 0 - OK |
| 565 | * 1 - write timeout |
| 566 | * 2 - Flash not erased |
| 567 | */ |
| 568 | |
| 569 | int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) |
| 570 | { |
| 571 | ulong cp, wp, data; |
| 572 | int i, l, rc; |
| 573 | |
| 574 | wp = (addr & ~3); /* get lower word aligned address */ |
| 575 | |
| 576 | /* |
| 577 | * handle unaligned start bytes |
| 578 | */ |
| 579 | if ((l = addr - wp) != 0) { |
| 580 | data = 0; |
| 581 | for (i=0, cp=wp; i<l; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 582 | #ifdef CONFIG_B2 |
| 583 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 584 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 585 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 586 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 587 | } |
| 588 | for (; i<4 && cnt>0; ++i) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 589 | #ifdef CONFIG_B2 |
| 590 | data = data | ((*src++)<<(8*i)); |
| 591 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 592 | data = (data << 8) | *src++; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 593 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 594 | --cnt; |
| 595 | ++cp; |
| 596 | } |
| 597 | for (; cnt==0 && i<4; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 598 | #ifdef CONFIG_B2 |
| 599 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 600 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 601 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 602 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | if ((rc = write_word(info, wp, data)) != 0) { |
| 606 | return (rc); |
| 607 | } |
| 608 | wp += 4; |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * handle word aligned part |
| 613 | */ |
| 614 | while (cnt >= 4) { |
| 615 | data = 0; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 616 | #ifdef CONFIG_B2 |
| 617 | data = (*(ulong*)src); |
| 618 | src += 4; |
| 619 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 620 | for (i=0; i<4; ++i) { |
| 621 | data = (data << 8) | *src++; |
| 622 | } |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 623 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 624 | if ((rc = write_word(info, wp, data)) != 0) { |
| 625 | return (rc); |
| 626 | } |
| 627 | wp += 4; |
| 628 | cnt -= 4; |
| 629 | } |
| 630 | |
| 631 | if (cnt == 0) { |
| 632 | return (0); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * handle unaligned tail bytes |
| 637 | */ |
| 638 | data = 0; |
| 639 | for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 640 | #ifdef CONFIG_B2 |
| 641 | data = data | ((*src++)<<(8*i)); |
| 642 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 643 | data = (data << 8) | *src++; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 644 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 645 | --cnt; |
| 646 | } |
| 647 | for (; i<4; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 648 | #ifdef CONFIG_B2 |
| 649 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 650 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 651 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 652 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | return (write_word(info, wp, data)); |
| 656 | } |
| 657 | |
| 658 | /*----------------------------------------------------------------------- |
| 659 | * Write a word to Flash, returns: |
| 660 | * 0 - OK |
| 661 | * 1 - write timeout |
| 662 | * 2 - Flash not erased |
| 663 | */ |
| 664 | static int write_word (flash_info_t *info, ulong dest, ulong data) |
| 665 | { |
Wolfgang Denk | 5168801 | 2009-09-11 11:28:21 +0200 | [diff] [blame^] | 666 | ulong *data_ptr = &data; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 667 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]); |
| 668 | volatile CONFIG_SYS_FLASH_WORD_SIZE *dest2 = (CONFIG_SYS_FLASH_WORD_SIZE *)dest; |
Wolfgang Denk | 5168801 | 2009-09-11 11:28:21 +0200 | [diff] [blame^] | 669 | volatile CONFIG_SYS_FLASH_WORD_SIZE *data2 = (CONFIG_SYS_FLASH_WORD_SIZE *)data_ptr; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 670 | ulong start; |
| 671 | int flag; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 672 | int i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 673 | |
| 674 | /* Check if Flash is (sufficiently) erased */ |
wdenk | 998eaae | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 675 | if ((*((volatile ulong *)dest) & data) != data) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 676 | return (2); |
| 677 | } |
| 678 | /* Disable interrupts which might cause a timeout here */ |
| 679 | flag = disable_interrupts(); |
| 680 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 681 | for (i=0; i<4/sizeof(CONFIG_SYS_FLASH_WORD_SIZE); i++) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 682 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 683 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 684 | addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 685 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00A000A0; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 686 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 687 | dest2[i] = data2[i]; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 688 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 689 | /* re-enable interrupts if necessary */ |
| 690 | if (flag) |
| 691 | enable_interrupts(); |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 692 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 693 | /* data polling for D7 */ |
| 694 | start = get_timer (0); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 695 | while ((dest2[i] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) != |
| 696 | (data2[i] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080)) { |
| 697 | if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 698 | return (1); |
| 699 | } |
| 700 | } |
| 701 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 702 | |
| 703 | return (0); |
| 704 | } |
| 705 | |
| 706 | /*----------------------------------------------------------------------- |
| 707 | */ |