wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mpc8xx.h> |
| 10 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 11 | flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 12 | |
| 13 | #ifdef CONFIG_FLASH_16BIT |
| 14 | #define FLASH_WORD_SIZE unsigned short |
| 15 | #define FLASH_ID_MASK 0xFFFF |
| 16 | #else |
| 17 | #define FLASH_WORD_SIZE unsigned long |
| 18 | #define FLASH_ID_MASK 0xFFFFFFFF |
| 19 | #endif |
| 20 | |
| 21 | /*----------------------------------------------------------------------- |
| 22 | * Functions |
| 23 | */ |
| 24 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 25 | ulong flash_get_size (volatile FLASH_WORD_SIZE * addr, flash_info_t * info); |
| 26 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 27 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 28 | static int write_word (flash_info_t * info, ulong dest, ulong data); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 29 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 30 | static int write_short (flash_info_t * info, ulong dest, ushort data); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 31 | #endif |
| 32 | /*int flash_write (uchar *, ulong, ulong); */ |
| 33 | /*flash_info_t *addr2info (ulong); */ |
| 34 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 35 | static void flash_get_offsets (ulong base, flash_info_t * info); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 36 | |
| 37 | /*----------------------------------------------------------------------- |
| 38 | */ |
| 39 | unsigned long flash_init (void) |
| 40 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 42 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 43 | unsigned long size_b0, size_b1; |
| 44 | int i; |
| 45 | |
| 46 | /* Init: no FLASHes known */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 48 | flash_info[i].flash_id = FLASH_UNKNOWN; |
| 49 | } |
| 50 | |
| 51 | /* Static FLASH Bank configuration here - FIXME XXX */ |
| 52 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 53 | size_b0 = |
| 54 | flash_get_size ((volatile FLASH_WORD_SIZE *) |
| 55 | FLASH_BASE0_PRELIM, &flash_info[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 56 | if (flash_info[0].flash_id == FLASH_UNKNOWN) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 57 | printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n", size_b0, size_b0 << 20); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 60 | size_b1 = |
| 61 | flash_get_size ((volatile FLASH_WORD_SIZE *) |
| 62 | FLASH_BASE1_PRELIM, &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 63 | |
| 64 | if (size_b1 > size_b0) { |
| 65 | printf ("## ERROR: " |
| 66 | "Bank 1 (0x%08lx = %ld MB) > Bank 0 (0x%08lx = %ld MB)\n", |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 67 | size_b1, size_b1 << 20, size_b0, size_b0 << 20); |
| 68 | flash_info[0].flash_id = FLASH_UNKNOWN; |
| 69 | flash_info[1].flash_id = FLASH_UNKNOWN; |
| 70 | flash_info[0].sector_count = -1; |
| 71 | flash_info[1].sector_count = -1; |
| 72 | flash_info[0].size = 0; |
| 73 | flash_info[1].size = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 74 | return (0); |
| 75 | } |
| 76 | |
| 77 | /* Remap FLASH according to real size */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | memctl->memc_or0 = CONFIG_SYS_OR_TIMING_FLASH | (-size_b0 & 0xFFFF8000); |
| 79 | memctl->memc_br0 = CONFIG_SYS_FLASH_BASE | 0x00000801; /* (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V; */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 80 | |
| 81 | /* Re-do sizing to get full correct info */ |
| 82 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | size_b0 = flash_get_size ((volatile FLASH_WORD_SIZE *) CONFIG_SYS_FLASH_BASE, |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 84 | &flash_info[0]); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | flash_get_offsets (CONFIG_SYS_FLASH_BASE, &flash_info[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 86 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 87 | #if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 88 | /* monitor protection ON by default */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 89 | (void) flash_protect (FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | CONFIG_SYS_MONITOR_BASE, |
| 91 | CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 92 | &flash_info[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
| 95 | if (size_b1) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 96 | memctl->memc_or1 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | CONFIG_SYS_OR_TIMING_FLASH | (-size_b1 & 0xFFFF8000); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 98 | memctl->memc_br1 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | (CONFIG_SYS_FLASH_BASE | 0x00000801) + (size_b0 & BR_BA_MSK); |
| 100 | /*((CONFIG_SYS_FLASH_BASE + size_b0) & BR_BA_MSK) | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 101 | BR_MS_GPCM | BR_V; */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 102 | |
| 103 | /* Re-do sizing to get full correct info */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 104 | size_b1 = |
| 105 | flash_get_size ((volatile FLASH_WORD_SIZE |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | *) (CONFIG_SYS_FLASH_BASE + size_b0), |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 107 | &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 108 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | flash_get_offsets (CONFIG_SYS_FLASH_BASE + size_b0, &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 110 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | #if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 112 | /* monitor protection ON by default */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 113 | (void) flash_protect (FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | CONFIG_SYS_MONITOR_BASE, |
| 115 | CONFIG_SYS_MONITOR_BASE + monitor_flash_len - |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 116 | 1, &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 117 | #endif |
| 118 | } else { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 119 | memctl->memc_br1 = 0; /* invalidate bank */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 120 | |
| 121 | flash_info[1].flash_id = FLASH_UNKNOWN; |
| 122 | flash_info[1].sector_count = -1; |
| 123 | } |
| 124 | |
| 125 | flash_info[0].size = size_b0; |
| 126 | flash_info[1].size = size_b1; |
| 127 | |
| 128 | return (size_b0 + size_b1); |
| 129 | } |
| 130 | |
| 131 | /*----------------------------------------------------------------------- |
| 132 | */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 133 | static void flash_get_offsets (ulong base, flash_info_t * info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 134 | { |
| 135 | int i; |
| 136 | |
| 137 | /* set up sector start adress table */ |
| 138 | if (info->flash_id & FLASH_BTYPE) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 139 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 140 | |
| 141 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 142 | /* set sector offsets for bottom boot block type */ |
| 143 | info->start[0] = base + 0x00000000; |
| 144 | info->start[1] = base + 0x00004000; |
| 145 | info->start[2] = base + 0x00008000; |
| 146 | info->start[3] = base + 0x0000C000; |
| 147 | info->start[4] = base + 0x00010000; |
| 148 | info->start[5] = base + 0x00014000; |
| 149 | info->start[6] = base + 0x00018000; |
| 150 | info->start[7] = base + 0x0001C000; |
| 151 | for (i = 8; i < info->sector_count; i++) { |
| 152 | info->start[i] = |
| 153 | base + (i * 0x00020000) - 0x000E0000; |
| 154 | } |
| 155 | } else { |
| 156 | /* set sector offsets for bottom boot block type */ |
| 157 | info->start[0] = base + 0x00000000; |
| 158 | info->start[1] = base + 0x00008000; |
| 159 | info->start[2] = base + 0x0000C000; |
| 160 | info->start[3] = base + 0x00010000; |
| 161 | for (i = 4; i < info->sector_count; i++) { |
| 162 | info->start[i] = |
| 163 | base + (i * 0x00020000) - 0x00060000; |
| 164 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 165 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 166 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 167 | /* set sector offsets for bottom boot block type */ |
| 168 | info->start[0] = base + 0x00000000; |
| 169 | info->start[1] = base + 0x00002000; |
| 170 | info->start[2] = base + 0x00004000; |
| 171 | info->start[3] = base + 0x00006000; |
| 172 | info->start[4] = base + 0x00008000; |
| 173 | info->start[5] = base + 0x0000A000; |
| 174 | info->start[6] = base + 0x0000C000; |
| 175 | info->start[7] = base + 0x0000E000; |
| 176 | for (i = 8; i < info->sector_count; i++) { |
| 177 | info->start[i] = |
| 178 | base + (i * 0x00010000) - 0x00070000; |
| 179 | } |
| 180 | } else { |
| 181 | /* set sector offsets for bottom boot block type */ |
| 182 | info->start[0] = base + 0x00000000; |
| 183 | info->start[1] = base + 0x00004000; |
| 184 | info->start[2] = base + 0x00006000; |
| 185 | info->start[3] = base + 0x00008000; |
| 186 | for (i = 4; i < info->sector_count; i++) { |
| 187 | info->start[i] = |
| 188 | base + (i * 0x00010000) - 0x00030000; |
| 189 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 190 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 191 | #endif |
| 192 | } else { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 193 | /* set sector offsets for top boot block type */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 194 | i = info->sector_count - 1; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 195 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 196 | |
| 197 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 198 | info->start[i--] = base + info->size - 0x00004000; |
| 199 | info->start[i--] = base + info->size - 0x00008000; |
| 200 | info->start[i--] = base + info->size - 0x0000C000; |
| 201 | info->start[i--] = base + info->size - 0x00010000; |
| 202 | info->start[i--] = base + info->size - 0x00014000; |
| 203 | info->start[i--] = base + info->size - 0x00018000; |
| 204 | info->start[i--] = base + info->size - 0x0001C000; |
| 205 | for (; i >= 0; i--) { |
| 206 | info->start[i] = base + i * 0x00020000; |
| 207 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 208 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 209 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 210 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 211 | info->start[i--] = base + info->size - 0x00008000; |
| 212 | info->start[i--] = base + info->size - 0x0000C000; |
| 213 | info->start[i--] = base + info->size - 0x00010000; |
| 214 | for (; i >= 0; i--) { |
| 215 | info->start[i] = base + i * 0x00020000; |
| 216 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 217 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 218 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 219 | info->start[i--] = base + info->size - 0x00002000; |
| 220 | info->start[i--] = base + info->size - 0x00004000; |
| 221 | info->start[i--] = base + info->size - 0x00006000; |
| 222 | info->start[i--] = base + info->size - 0x00008000; |
| 223 | info->start[i--] = base + info->size - 0x0000A000; |
| 224 | info->start[i--] = base + info->size - 0x0000C000; |
| 225 | info->start[i--] = base + info->size - 0x0000E000; |
| 226 | for (; i >= 0; i--) { |
| 227 | info->start[i] = base + i * 0x00010000; |
| 228 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 229 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 230 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 231 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 232 | info->start[i--] = base + info->size - 0x00004000; |
| 233 | info->start[i--] = base + info->size - 0x00006000; |
| 234 | info->start[i--] = base + info->size - 0x00008000; |
| 235 | for (; i >= 0; i--) { |
| 236 | info->start[i] = base + i * 0x00010000; |
| 237 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 238 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 239 | #endif |
| 240 | } |
| 241 | |
| 242 | |
| 243 | } |
| 244 | |
| 245 | /*----------------------------------------------------------------------- |
| 246 | */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 247 | void flash_print_info (flash_info_t * info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 248 | { |
| 249 | int i; |
| 250 | uchar *boottype; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 251 | uchar botboot[] = ", bottom boot sect)\n"; |
| 252 | uchar topboot[] = ", top boot sector)\n"; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 253 | |
| 254 | if (info->flash_id == FLASH_UNKNOWN) { |
| 255 | printf ("missing or unknown FLASH type\n"); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | switch (info->flash_id & FLASH_VENDMASK) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 260 | case FLASH_MAN_AMD: |
| 261 | printf ("AMD "); |
| 262 | break; |
| 263 | case FLASH_MAN_FUJ: |
| 264 | printf ("FUJITSU "); |
| 265 | break; |
| 266 | case FLASH_MAN_SST: |
| 267 | printf ("SST "); |
| 268 | break; |
| 269 | case FLASH_MAN_STM: |
| 270 | printf ("STM "); |
| 271 | break; |
| 272 | case FLASH_MAN_INTEL: |
| 273 | printf ("INTEL "); |
| 274 | break; |
| 275 | default: |
| 276 | printf ("Unknown Vendor "); |
| 277 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 280 | if (info->flash_id & 0x0001) { |
| 281 | boottype = botboot; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 282 | } else { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 283 | boottype = topboot; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | switch (info->flash_id & FLASH_TYPEMASK) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 287 | case FLASH_AM400B: |
| 288 | printf ("AM29LV400B (4 Mbit%s", boottype); |
| 289 | break; |
| 290 | case FLASH_AM400T: |
| 291 | printf ("AM29LV400T (4 Mbit%s", boottype); |
| 292 | break; |
| 293 | case FLASH_AM800B: |
| 294 | printf ("AM29LV800B (8 Mbit%s", boottype); |
| 295 | break; |
| 296 | case FLASH_AM800T: |
| 297 | printf ("AM29LV800T (8 Mbit%s", boottype); |
| 298 | break; |
| 299 | case FLASH_AM160B: |
| 300 | printf ("AM29LV160B (16 Mbit%s", boottype); |
| 301 | break; |
| 302 | case FLASH_AM160T: |
| 303 | printf ("AM29LV160T (16 Mbit%s", boottype); |
| 304 | break; |
| 305 | case FLASH_AM320B: |
| 306 | printf ("AM29LV320B (32 Mbit%s", boottype); |
| 307 | break; |
| 308 | case FLASH_AM320T: |
| 309 | printf ("AM29LV320T (32 Mbit%s", boottype); |
| 310 | break; |
| 311 | case FLASH_INTEL800B: |
| 312 | printf ("INTEL28F800B (8 Mbit%s", boottype); |
| 313 | break; |
| 314 | case FLASH_INTEL800T: |
| 315 | printf ("INTEL28F800T (8 Mbit%s", boottype); |
| 316 | break; |
| 317 | case FLASH_INTEL160B: |
| 318 | printf ("INTEL28F160B (16 Mbit%s", boottype); |
| 319 | break; |
| 320 | case FLASH_INTEL160T: |
| 321 | printf ("INTEL28F160T (16 Mbit%s", boottype); |
| 322 | break; |
| 323 | case FLASH_INTEL320B: |
| 324 | printf ("INTEL28F320B (32 Mbit%s", boottype); |
| 325 | break; |
| 326 | case FLASH_INTEL320T: |
| 327 | printf ("INTEL28F320T (32 Mbit%s", boottype); |
| 328 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 329 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 330 | #if 0 /* enable when devices are available */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 331 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 332 | case FLASH_INTEL640B: |
| 333 | printf ("INTEL28F640B (64 Mbit%s", boottype); |
| 334 | break; |
| 335 | case FLASH_INTEL640T: |
| 336 | printf ("INTEL28F640T (64 Mbit%s", boottype); |
| 337 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 338 | #endif |
| 339 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 340 | default: |
| 341 | printf ("Unknown Chip Type\n"); |
| 342 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | printf (" Size: %ld MB in %d Sectors\n", |
| 346 | info->size >> 20, info->sector_count); |
| 347 | |
| 348 | printf (" Sector Start Addresses:"); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 349 | for (i = 0; i < info->sector_count; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 350 | if ((i % 5) == 0) |
| 351 | printf ("\n "); |
| 352 | printf (" %08lX%s", |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 353 | info->start[i], info->protect[i] ? " (RO)" : " "); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 354 | } |
| 355 | printf ("\n"); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | /*----------------------------------------------------------------------- |
| 360 | */ |
| 361 | |
| 362 | |
| 363 | /*----------------------------------------------------------------------- |
| 364 | */ |
| 365 | |
| 366 | /* |
| 367 | * The following code cannot be run from FLASH! |
| 368 | */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 369 | ulong flash_get_size (volatile FLASH_WORD_SIZE * addr, flash_info_t * info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 370 | { |
| 371 | short i; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 372 | ulong base = (ulong) addr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 373 | FLASH_WORD_SIZE value; |
| 374 | |
| 375 | /* Write auto select command: read Manufacturer ID */ |
| 376 | |
| 377 | |
| 378 | #ifndef CONFIG_FLASH_16BIT |
| 379 | |
| 380 | /* |
| 381 | * Note: if it is an AMD flash and the word at addr[0000] |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 382 | * is 0x00890089 this routine will think it is an Intel |
| 383 | * flash device and may(most likely) cause trouble. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 384 | */ |
| 385 | |
| 386 | addr[0x0000] = 0x00900090; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 387 | if (addr[0x0000] != 0x00890089) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 388 | addr[0x0555] = 0x00AA00AA; |
| 389 | addr[0x02AA] = 0x00550055; |
| 390 | addr[0x0555] = 0x00900090; |
| 391 | #else |
| 392 | |
| 393 | /* |
| 394 | * Note: if it is an AMD flash and the word at addr[0000] |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 395 | * is 0x0089 this routine will think it is an Intel |
| 396 | * flash device and may(most likely) cause trouble. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 397 | */ |
| 398 | |
| 399 | addr[0x0000] = 0x0090; |
| 400 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 401 | if (addr[0x0000] != 0x0089) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 402 | addr[0x0555] = 0x00AA; |
| 403 | addr[0x02AA] = 0x0055; |
| 404 | addr[0x0555] = 0x0090; |
| 405 | #endif |
| 406 | } |
| 407 | value = addr[0]; |
| 408 | |
| 409 | switch (value) { |
| 410 | case (AMD_MANUFACT & FLASH_ID_MASK): |
| 411 | info->flash_id = FLASH_MAN_AMD; |
| 412 | break; |
| 413 | case (FUJ_MANUFACT & FLASH_ID_MASK): |
| 414 | info->flash_id = FLASH_MAN_FUJ; |
| 415 | break; |
| 416 | case (STM_MANUFACT & FLASH_ID_MASK): |
| 417 | info->flash_id = FLASH_MAN_STM; |
| 418 | break; |
| 419 | case (SST_MANUFACT & FLASH_ID_MASK): |
| 420 | info->flash_id = FLASH_MAN_SST; |
| 421 | break; |
| 422 | case (INTEL_MANUFACT & FLASH_ID_MASK): |
| 423 | info->flash_id = FLASH_MAN_INTEL; |
| 424 | break; |
| 425 | default: |
| 426 | info->flash_id = FLASH_UNKNOWN; |
| 427 | info->sector_count = 0; |
| 428 | info->size = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 429 | return (0); /* no or unknown flash */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 430 | |
| 431 | } |
| 432 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 433 | value = addr[1]; /* device ID */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 434 | |
| 435 | switch (value) { |
| 436 | |
| 437 | case (AMD_ID_LV400T & FLASH_ID_MASK): |
| 438 | info->flash_id += FLASH_AM400T; |
| 439 | info->sector_count = 11; |
| 440 | info->size = 0x00100000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 441 | break; /* => 1 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 442 | |
| 443 | case (AMD_ID_LV400B & FLASH_ID_MASK): |
| 444 | info->flash_id += FLASH_AM400B; |
| 445 | info->sector_count = 11; |
| 446 | info->size = 0x00100000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 447 | break; /* => 1 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 448 | |
| 449 | case (AMD_ID_LV800T & FLASH_ID_MASK): |
| 450 | info->flash_id += FLASH_AM800T; |
| 451 | info->sector_count = 19; |
| 452 | info->size = 0x00200000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 453 | break; /* => 2 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 454 | |
| 455 | case (AMD_ID_LV800B & FLASH_ID_MASK): |
| 456 | info->flash_id += FLASH_AM800B; |
| 457 | info->sector_count = 19; |
| 458 | info->size = 0x00200000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 459 | break; /* => 2 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 460 | |
| 461 | case (AMD_ID_LV160T & FLASH_ID_MASK): |
| 462 | info->flash_id += FLASH_AM160T; |
| 463 | info->sector_count = 35; |
| 464 | info->size = 0x00400000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 465 | break; /* => 4 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 466 | |
| 467 | case (AMD_ID_LV160B & FLASH_ID_MASK): |
| 468 | info->flash_id += FLASH_AM160B; |
| 469 | info->sector_count = 35; |
| 470 | info->size = 0x00400000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 471 | break; /* => 4 MB */ |
| 472 | #if 0 /* enable when device IDs are available */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 473 | case (AMD_ID_LV320T & FLASH_ID_MASK): |
| 474 | info->flash_id += FLASH_AM320T; |
| 475 | info->sector_count = 67; |
| 476 | info->size = 0x00800000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 477 | break; /* => 8 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 478 | |
| 479 | case (AMD_ID_LV320B & FLASH_ID_MASK): |
| 480 | info->flash_id += FLASH_AM320B; |
| 481 | info->sector_count = 67; |
| 482 | info->size = 0x00800000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 483 | break; /* => 8 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 484 | #endif |
| 485 | |
| 486 | case (INTEL_ID_28F800B3T & FLASH_ID_MASK): |
| 487 | info->flash_id += FLASH_INTEL800T; |
| 488 | info->sector_count = 23; |
| 489 | info->size = 0x00200000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 490 | break; /* => 2 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 491 | |
| 492 | case (INTEL_ID_28F800B3B & FLASH_ID_MASK): |
| 493 | info->flash_id += FLASH_INTEL800B; |
| 494 | info->sector_count = 23; |
| 495 | info->size = 0x00200000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 496 | break; /* => 2 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 497 | |
| 498 | case (INTEL_ID_28F160B3T & FLASH_ID_MASK): |
| 499 | info->flash_id += FLASH_INTEL160T; |
| 500 | info->sector_count = 39; |
| 501 | info->size = 0x00400000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 502 | break; /* => 4 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 503 | |
| 504 | case (INTEL_ID_28F160B3B & FLASH_ID_MASK): |
| 505 | info->flash_id += FLASH_INTEL160B; |
| 506 | info->sector_count = 39; |
| 507 | info->size = 0x00400000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 508 | break; /* => 4 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 509 | |
| 510 | case (INTEL_ID_28F320B3T & FLASH_ID_MASK): |
| 511 | info->flash_id += FLASH_INTEL320T; |
| 512 | info->sector_count = 71; |
| 513 | info->size = 0x00800000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 514 | break; /* => 8 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 515 | |
| 516 | case (INTEL_ID_28F320B3B & FLASH_ID_MASK): |
| 517 | info->flash_id += FLASH_AM320B; |
| 518 | info->sector_count = 71; |
| 519 | info->size = 0x00800000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 520 | break; /* => 8 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 521 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 522 | #if 0 /* enable when devices are available */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 523 | case (INTEL_ID_28F320B3T & FLASH_ID_MASK): |
| 524 | info->flash_id += FLASH_INTEL320T; |
| 525 | info->sector_count = 135; |
| 526 | info->size = 0x01000000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 527 | break; /* => 16 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 528 | |
| 529 | case (INTEL_ID_28F320B3B & FLASH_ID_MASK): |
| 530 | info->flash_id += FLASH_AM320B; |
| 531 | info->sector_count = 135; |
| 532 | info->size = 0x01000000; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 533 | break; /* => 16 MB */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 534 | #endif |
| 535 | default: |
| 536 | info->flash_id = FLASH_UNKNOWN; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 537 | return (0); /* => no or unknown flash */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 538 | |
| 539 | } |
| 540 | |
| 541 | /* set up sector start adress table */ |
| 542 | if (info->flash_id & FLASH_BTYPE) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 543 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 544 | |
| 545 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 546 | /* set sector offsets for bottom boot block type */ |
| 547 | info->start[0] = base + 0x00000000; |
| 548 | info->start[1] = base + 0x00004000; |
| 549 | info->start[2] = base + 0x00008000; |
| 550 | info->start[3] = base + 0x0000C000; |
| 551 | info->start[4] = base + 0x00010000; |
| 552 | info->start[5] = base + 0x00014000; |
| 553 | info->start[6] = base + 0x00018000; |
| 554 | info->start[7] = base + 0x0001C000; |
| 555 | for (i = 8; i < info->sector_count; i++) { |
| 556 | info->start[i] = |
| 557 | base + (i * 0x00020000) - 0x000E0000; |
| 558 | } |
| 559 | } else { |
| 560 | /* set sector offsets for bottom boot block type */ |
| 561 | info->start[0] = base + 0x00000000; |
| 562 | info->start[1] = base + 0x00008000; |
| 563 | info->start[2] = base + 0x0000C000; |
| 564 | info->start[3] = base + 0x00010000; |
| 565 | for (i = 4; i < info->sector_count; i++) { |
| 566 | info->start[i] = |
| 567 | base + (i * 0x00020000) - 0x00060000; |
| 568 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 569 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 570 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 571 | /* set sector offsets for bottom boot block type */ |
| 572 | info->start[0] = base + 0x00000000; |
| 573 | info->start[1] = base + 0x00002000; |
| 574 | info->start[2] = base + 0x00004000; |
| 575 | info->start[3] = base + 0x00006000; |
| 576 | info->start[4] = base + 0x00008000; |
| 577 | info->start[5] = base + 0x0000A000; |
| 578 | info->start[6] = base + 0x0000C000; |
| 579 | info->start[7] = base + 0x0000E000; |
| 580 | for (i = 8; i < info->sector_count; i++) { |
| 581 | info->start[i] = |
| 582 | base + (i * 0x00010000) - 0x00070000; |
| 583 | } |
| 584 | } else { |
| 585 | /* set sector offsets for bottom boot block type */ |
| 586 | info->start[0] = base + 0x00000000; |
| 587 | info->start[1] = base + 0x00004000; |
| 588 | info->start[2] = base + 0x00006000; |
| 589 | info->start[3] = base + 0x00008000; |
| 590 | for (i = 4; i < info->sector_count; i++) { |
| 591 | info->start[i] = |
| 592 | base + (i * 0x00010000) - 0x00030000; |
| 593 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 594 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 595 | #endif |
| 596 | } else { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 597 | /* set sector offsets for top boot block type */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 598 | i = info->sector_count - 1; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 599 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 600 | |
| 601 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 602 | info->start[i--] = base + info->size - 0x00004000; |
| 603 | info->start[i--] = base + info->size - 0x00008000; |
| 604 | info->start[i--] = base + info->size - 0x0000C000; |
| 605 | info->start[i--] = base + info->size - 0x00010000; |
| 606 | info->start[i--] = base + info->size - 0x00014000; |
| 607 | info->start[i--] = base + info->size - 0x00018000; |
| 608 | info->start[i--] = base + info->size - 0x0001C000; |
| 609 | for (; i >= 0; i--) { |
| 610 | info->start[i] = base + i * 0x00020000; |
| 611 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 612 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 613 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 614 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 615 | info->start[i--] = base + info->size - 0x00008000; |
| 616 | info->start[i--] = base + info->size - 0x0000C000; |
| 617 | info->start[i--] = base + info->size - 0x00010000; |
| 618 | for (; i >= 0; i--) { |
| 619 | info->start[i] = base + i * 0x00020000; |
| 620 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 621 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 622 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 623 | info->start[i--] = base + info->size - 0x00002000; |
| 624 | info->start[i--] = base + info->size - 0x00004000; |
| 625 | info->start[i--] = base + info->size - 0x00006000; |
| 626 | info->start[i--] = base + info->size - 0x00008000; |
| 627 | info->start[i--] = base + info->size - 0x0000A000; |
| 628 | info->start[i--] = base + info->size - 0x0000C000; |
| 629 | info->start[i--] = base + info->size - 0x0000E000; |
| 630 | for (; i >= 0; i--) { |
| 631 | info->start[i] = base + i * 0x00010000; |
| 632 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 633 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 634 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 635 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 636 | info->start[i--] = base + info->size - 0x00004000; |
| 637 | info->start[i--] = base + info->size - 0x00006000; |
| 638 | info->start[i--] = base + info->size - 0x00008000; |
| 639 | for (; i >= 0; i--) { |
| 640 | info->start[i] = base + i * 0x00010000; |
| 641 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 642 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 643 | #endif |
| 644 | } |
| 645 | |
| 646 | /* check for protected sectors */ |
| 647 | for (i = 0; i < info->sector_count; i++) { |
| 648 | /* read sector protection at sector address, (A7 .. A0) = 0x02 */ |
| 649 | /* D0 = 1 if protected */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 650 | addr = (volatile FLASH_WORD_SIZE *) (info->start[i]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 651 | info->protect[i] = addr[2] & 1; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Prevent writes to uninitialized FLASH. |
| 656 | */ |
| 657 | if (info->flash_id != FLASH_UNKNOWN) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 658 | addr = (volatile FLASH_WORD_SIZE *) info->start[0]; |
| 659 | if ((info->flash_id & 0xFF00) == FLASH_MAN_INTEL) { |
| 660 | *addr = (0x00F000F0 & FLASH_ID_MASK); /* reset bank */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 661 | } else { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 662 | *addr = (0x00FF00FF & FLASH_ID_MASK); /* reset bank */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | return (info->size); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | /*----------------------------------------------------------------------- |
| 671 | */ |
| 672 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 673 | int flash_erase (flash_info_t * info, int s_first, int s_last) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 674 | { |
| 675 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 676 | volatile FLASH_WORD_SIZE *addr = |
| 677 | (volatile FLASH_WORD_SIZE *) (info->start[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 678 | int flag, prot, sect, l_sect, barf; |
| 679 | ulong start, now, last; |
| 680 | int rcode = 0; |
| 681 | |
| 682 | if ((s_first < 0) || (s_first > s_last)) { |
| 683 | if (info->flash_id == FLASH_UNKNOWN) { |
| 684 | printf ("- missing\n"); |
| 685 | } else { |
| 686 | printf ("- no sectors to erase\n"); |
| 687 | } |
| 688 | return 1; |
| 689 | } |
| 690 | |
| 691 | if ((info->flash_id == FLASH_UNKNOWN) || |
| 692 | ((info->flash_id > FLASH_AMD_COMP) && |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 693 | ((info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL))) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 694 | printf ("Can't erase unknown flash type - aborted\n"); |
| 695 | return 1; |
| 696 | } |
| 697 | |
| 698 | prot = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 699 | for (sect = s_first; sect <= s_last; ++sect) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 700 | if (info->protect[sect]) { |
| 701 | prot++; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | if (prot) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 706 | printf ("- Warning: %d protected sectors will not be erased!\n", prot); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 707 | } else { |
| 708 | printf ("\n"); |
| 709 | } |
| 710 | |
| 711 | l_sect = -1; |
| 712 | |
| 713 | /* Disable interrupts which might cause a timeout here */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 714 | flag = disable_interrupts (); |
| 715 | if (info->flash_id < FLASH_AMD_COMP) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 716 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 717 | addr[0x0555] = 0x00AA00AA; |
| 718 | addr[0x02AA] = 0x00550055; |
| 719 | addr[0x0555] = 0x00800080; |
| 720 | addr[0x0555] = 0x00AA00AA; |
| 721 | addr[0x02AA] = 0x00550055; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 722 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 723 | addr[0x0555] = 0x00AA; |
| 724 | addr[0x02AA] = 0x0055; |
| 725 | addr[0x0555] = 0x0080; |
| 726 | addr[0x0555] = 0x00AA; |
| 727 | addr[0x02AA] = 0x0055; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 728 | #endif |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 729 | /* Start erase on unprotected sectors */ |
| 730 | for (sect = s_first; sect <= s_last; sect++) { |
| 731 | if (info->protect[sect] == 0) { /* not protected */ |
| 732 | addr = (volatile FLASH_WORD_SIZE *) (info->start[sect]); |
| 733 | addr[0] = (0x00300030 & FLASH_ID_MASK); |
| 734 | l_sect = sect; |
| 735 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 736 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 737 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 738 | /* re-enable interrupts if necessary */ |
| 739 | if (flag) |
| 740 | enable_interrupts (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 741 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 742 | /* wait at least 80us - let's wait 1 ms */ |
| 743 | udelay (1000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 744 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 745 | /* |
| 746 | * We wait for the last triggered sector |
| 747 | */ |
| 748 | if (l_sect < 0) |
| 749 | goto DONE; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 750 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 751 | start = get_timer (0); |
| 752 | last = start; |
| 753 | addr = (volatile FLASH_WORD_SIZE *) (info->start[l_sect]); |
| 754 | while ((addr[0] & (0x00800080 & FLASH_ID_MASK)) != |
| 755 | (0x00800080 & FLASH_ID_MASK)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 756 | if ((now = get_timer (start)) > CONFIG_SYS_FLASH_ERASE_TOUT) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 757 | printf ("Timeout\n"); |
| 758 | return 1; |
| 759 | } |
| 760 | /* show that we're waiting */ |
| 761 | if ((now - last) > 1000) { /* every second */ |
| 762 | serial_putc ('.'); |
| 763 | last = now; |
| 764 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 765 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 766 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 767 | DONE: |
| 768 | /* reset to read mode */ |
| 769 | addr = (volatile FLASH_WORD_SIZE *) info->start[0]; |
| 770 | addr[0] = (0x00F000F0 & FLASH_ID_MASK); /* reset bank */ |
| 771 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 772 | |
| 773 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 774 | for (sect = s_first; sect <= s_last; sect++) { |
| 775 | if (info->protect[sect] == 0) { /* not protected */ |
| 776 | barf = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 777 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 778 | addr = (vu_long *) (info->start[sect]); |
| 779 | addr[0] = 0x00200020; |
| 780 | addr[0] = 0x00D000D0; |
| 781 | while (!(addr[0] & 0x00800080)); /* wait for error or finish */ |
| 782 | if (addr[0] & 0x003A003A) { /* check for error */ |
| 783 | barf = addr[0] & 0x003A0000; |
| 784 | if (barf) { |
| 785 | barf >>= 16; |
| 786 | } else { |
| 787 | barf = addr[0] & 0x0000003A; |
| 788 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 789 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 790 | #else |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 791 | addr = (vu_short *) (info->start[sect]); |
| 792 | addr[0] = 0x0020; |
| 793 | addr[0] = 0x00D0; |
| 794 | while (!(addr[0] & 0x0080)); /* wait for error or finish */ |
| 795 | if (addr[0] & 0x003A) /* check for error */ |
| 796 | barf = addr[0] & 0x003A; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 797 | #endif |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 798 | if (barf) { |
| 799 | printf ("\nFlash error in sector at %lx\n", (unsigned long) addr); |
| 800 | if (barf & 0x0002) |
| 801 | printf ("Block locked, not erased.\n"); |
| 802 | if ((barf & 0x0030) == 0x0030) |
| 803 | printf ("Command Sequence error.\n"); |
| 804 | if ((barf & 0x0030) == 0x0020) |
| 805 | printf ("Block Erase error.\n"); |
| 806 | if (barf & 0x0008) |
| 807 | printf ("Vpp Low error.\n"); |
| 808 | rcode = 1; |
| 809 | } else |
| 810 | printf ("."); |
| 811 | l_sect = sect; |
| 812 | } |
| 813 | addr = (volatile FLASH_WORD_SIZE *) info->start[0]; |
| 814 | addr[0] = (0x00FF00FF & FLASH_ID_MASK); /* reset bank */ |
| 815 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 816 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 817 | |
| 818 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 819 | printf (" done\n"); |
| 820 | return rcode; |
| 821 | } |
| 822 | |
| 823 | /*----------------------------------------------------------------------- |
| 824 | */ |
| 825 | |
| 826 | /*----------------------------------------------------------------------- |
| 827 | * Copy memory to flash, returns: |
| 828 | * 0 - OK |
| 829 | * 1 - write timeout |
| 830 | * 2 - Flash not erased |
| 831 | */ |
| 832 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 833 | int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 834 | { |
| 835 | #ifndef CONFIG_FLASH_16BIT |
| 836 | ulong cp, wp, data; |
| 837 | int l; |
| 838 | #else |
| 839 | ulong cp, wp; |
| 840 | ushort data; |
| 841 | #endif |
| 842 | int i, rc; |
| 843 | |
| 844 | #ifndef CONFIG_FLASH_16BIT |
| 845 | |
| 846 | |
| 847 | wp = (addr & ~3); /* get lower word aligned address */ |
| 848 | |
| 849 | /* |
| 850 | * handle unaligned start bytes |
| 851 | */ |
| 852 | if ((l = addr - wp) != 0) { |
| 853 | data = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 854 | for (i = 0, cp = wp; i < l; ++i, ++cp) { |
| 855 | data = (data << 8) | (*(uchar *) cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 856 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 857 | for (; i < 4 && cnt > 0; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 858 | data = (data << 8) | *src++; |
| 859 | --cnt; |
| 860 | ++cp; |
| 861 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 862 | for (; cnt == 0 && i < 4; ++i, ++cp) { |
| 863 | data = (data << 8) | (*(uchar *) cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 866 | if ((rc = write_word (info, wp, data)) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 867 | return (rc); |
| 868 | } |
| 869 | wp += 4; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * handle word aligned part |
| 874 | */ |
| 875 | while (cnt >= 4) { |
| 876 | data = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 877 | for (i = 0; i < 4; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 878 | data = (data << 8) | *src++; |
| 879 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 880 | if ((rc = write_word (info, wp, data)) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 881 | return (rc); |
| 882 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 883 | wp += 4; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 884 | cnt -= 4; |
| 885 | } |
| 886 | |
| 887 | if (cnt == 0) { |
| 888 | return (0); |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * handle unaligned tail bytes |
| 893 | */ |
| 894 | data = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 895 | for (i = 0, cp = wp; i < 4 && cnt > 0; ++i, ++cp) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 896 | data = (data << 8) | *src++; |
| 897 | --cnt; |
| 898 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 899 | for (; i < 4; ++i, ++cp) { |
| 900 | data = (data << 8) | (*(uchar *) cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 903 | return (write_word (info, wp, data)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 904 | |
| 905 | #else |
| 906 | wp = (addr & ~1); /* get lower word aligned address */ |
| 907 | |
| 908 | /* |
| 909 | * handle unaligned start byte |
| 910 | */ |
| 911 | if (addr - wp) { |
| 912 | data = 0; |
| 913 | data = (data << 8) | *src++; |
| 914 | --cnt; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 915 | if ((rc = write_short (info, wp, data)) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 916 | return (rc); |
| 917 | } |
| 918 | wp += 2; |
| 919 | } |
| 920 | |
| 921 | /* |
| 922 | * handle word aligned part |
| 923 | */ |
| 924 | /* l = 0; used for debuging */ |
| 925 | while (cnt >= 2) { |
| 926 | data = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 927 | for (i = 0; i < 2; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 928 | data = (data << 8) | *src++; |
| 929 | } |
| 930 | |
| 931 | /* if(!l){ |
| 932 | printf("%x",data); |
| 933 | l = 1; |
| 934 | } used for debuging */ |
| 935 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 936 | if ((rc = write_short (info, wp, data)) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 937 | return (rc); |
| 938 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 939 | wp += 2; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 940 | cnt -= 2; |
| 941 | } |
| 942 | |
| 943 | if (cnt == 0) { |
| 944 | return (0); |
| 945 | } |
| 946 | |
| 947 | /* |
| 948 | * handle unaligned tail bytes |
| 949 | */ |
| 950 | data = 0; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 951 | for (i = 0, cp = wp; i < 2 && cnt > 0; ++i, ++cp) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 952 | data = (data << 8) | *src++; |
| 953 | --cnt; |
| 954 | } |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 955 | for (; i < 2; ++i, ++cp) { |
| 956 | data = (data << 8) | (*(uchar *) cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 959 | return (write_short (info, wp, data)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 960 | |
| 961 | |
| 962 | #endif |
| 963 | } |
| 964 | |
| 965 | /*----------------------------------------------------------------------- |
| 966 | * Write a word to Flash, returns: |
| 967 | * 0 - OK |
| 968 | * 1 - write timeout |
| 969 | * 2 - Flash not erased |
| 970 | */ |
| 971 | #ifndef CONFIG_FLASH_16BIT |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 972 | static int write_word (flash_info_t * info, ulong dest, ulong data) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 973 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 974 | vu_long *addr = (vu_long *) (info->start[0]); |
| 975 | ulong start, barf; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 976 | int flag; |
| 977 | |
| 978 | |
| 979 | /* Check if Flash is (sufficiently) erased */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 980 | if ((*((vu_long *) dest) & data) != data) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 981 | return (2); |
| 982 | } |
| 983 | |
| 984 | /* Disable interrupts which might cause a timeout here */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 985 | flag = disable_interrupts (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 986 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 987 | if (info->flash_id > FLASH_AMD_COMP) { |
| 988 | /* AMD stuff */ |
| 989 | addr[0x0555] = 0x00AA00AA; |
| 990 | addr[0x02AA] = 0x00550055; |
| 991 | addr[0x0555] = 0x00A000A0; |
| 992 | } else { |
| 993 | /* intel stuff */ |
| 994 | *addr = 0x00400040; |
| 995 | } |
| 996 | *((vu_long *) dest) = data; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 997 | |
| 998 | /* re-enable interrupts if necessary */ |
| 999 | if (flag) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1000 | enable_interrupts (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* data polling for D7 */ |
| 1003 | start = get_timer (0); |
| 1004 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1005 | if (info->flash_id > FLASH_AMD_COMP) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1006 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1007 | while ((*((vu_long *) dest) & 0x00800080) != |
| 1008 | (data & 0x00800080)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1009 | if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1010 | return (1); |
| 1011 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1012 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1013 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1014 | } else { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1015 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1016 | while (!(addr[0] & 0x00800080)) { /* wait for error or finish */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1017 | if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1018 | return (1); |
| 1019 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1020 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1021 | if (addr[0] & 0x003A003A) { /* check for error */ |
| 1022 | barf = addr[0] & 0x003A0000; |
| 1023 | if (barf) { |
| 1024 | barf >>= 16; |
| 1025 | } else { |
| 1026 | barf = addr[0] & 0x0000003A; |
| 1027 | } |
| 1028 | printf ("\nFlash write error at address %lx\n", (unsigned long) dest); |
| 1029 | if (barf & 0x0002) |
| 1030 | printf ("Block locked, not erased.\n"); |
| 1031 | if (barf & 0x0010) |
| 1032 | printf ("Programming error.\n"); |
| 1033 | if (barf & 0x0008) |
| 1034 | printf ("Vpp Low error.\n"); |
| 1035 | return (2); |
| 1036 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1037 | |
| 1038 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1039 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1040 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1041 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1042 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1043 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1044 | |
| 1045 | #else |
| 1046 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1047 | static int write_short (flash_info_t * info, ulong dest, ushort data) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1048 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1049 | vu_short *addr = (vu_short *) (info->start[0]); |
| 1050 | ulong start, barf; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1051 | int flag; |
| 1052 | |
| 1053 | /* Check if Flash is (sufficiently) erased */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1054 | if ((*((vu_short *) dest) & data) != data) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1055 | return (2); |
| 1056 | } |
| 1057 | |
| 1058 | /* Disable interrupts which might cause a timeout here */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1059 | flag = disable_interrupts (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1060 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1061 | if (info->flash_id < FLASH_AMD_COMP) { |
| 1062 | /* AMD stuff */ |
| 1063 | addr[0x0555] = 0x00AA; |
| 1064 | addr[0x02AA] = 0x0055; |
| 1065 | addr[0x0555] = 0x00A0; |
| 1066 | } else { |
| 1067 | /* intel stuff */ |
| 1068 | *addr = 0x00D0; |
| 1069 | *addr = 0x0040; |
| 1070 | } |
| 1071 | *((vu_short *) dest) = data; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1072 | |
| 1073 | /* re-enable interrupts if necessary */ |
| 1074 | if (flag) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1075 | enable_interrupts (); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1076 | |
| 1077 | /* data polling for D7 */ |
| 1078 | start = get_timer (0); |
| 1079 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1080 | if (info->flash_id < FLASH_AMD_COMP) { |
| 1081 | /* AMD stuff */ |
| 1082 | while ((*((vu_short *) dest) & 0x0080) != (data & 0x0080)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1083 | if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1084 | return (1); |
| 1085 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1086 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1087 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1088 | } else { |
| 1089 | /* intel stuff */ |
| 1090 | while (!(addr[0] & 0x0080)) { /* wait for error or finish */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1091 | if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1092 | return (1); |
| 1093 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1094 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1095 | if (addr[0] & 0x003A) { /* check for error */ |
| 1096 | barf = addr[0] & 0x003A; |
| 1097 | printf ("\nFlash write error at address %lx\n", |
| 1098 | (unsigned long) dest); |
| 1099 | if (barf & 0x0002) |
| 1100 | printf ("Block locked, not erased.\n"); |
| 1101 | if (barf & 0x0010) |
| 1102 | printf ("Programming error.\n"); |
| 1103 | if (barf & 0x0008) |
| 1104 | printf ("Vpp Low error.\n"); |
| 1105 | return (2); |
| 1106 | } |
| 1107 | *addr = 0x00B0; |
| 1108 | *addr = 0x0070; |
| 1109 | while (!(addr[0] & 0x0080)) { /* wait for error or finish */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1110 | if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1111 | return (1); |
| 1112 | } |
| 1113 | *addr = 0x00FF; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1114 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1115 | return (0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1118 | #endif |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1119 | /*-----------------------------------------------------------------------*/ |