wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
| 10 | * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de> |
| 11 | * |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 12 | * (C) Copyright 2002 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 13 | * Auerswald GmbH & Co KG, Germany |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 14 | * Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de> |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 15 | * |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 16 | * See file CREDITS for list of people who contributed to this |
| 17 | * project. |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU General Public License as |
| 21 | * published by the Free Software Foundation; either version 2 of |
| 22 | * the License, or (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 32 | * MA 02111-1307 USA |
| 33 | */ |
| 34 | |
| 35 | #include <common.h> |
| 36 | #include <asm/arch/pxa-regs.h> |
| 37 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 38 | #if defined CFG_JFFS_CUSTOM_PART |
| 39 | #include <jffs2/jffs2.h> |
| 40 | #endif |
| 41 | |
| 42 | /* Debugging macros ------------------------------------------------------ */ |
| 43 | |
| 44 | #undef FLASH_DEBUG |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 45 | |
| 46 | /* Some debug macros */ |
| 47 | #if (FLASH_DEBUG > 2 ) |
| 48 | #define PRINTK3(args...) printf(args) |
| 49 | #else |
| 50 | #define PRINTK3(args...) |
| 51 | #endif |
| 52 | |
| 53 | #if FLASH_DEBUG > 1 |
| 54 | #define PRINTK2(args...) printf(args) |
| 55 | #else |
| 56 | #define PRINTK2(args...) |
| 57 | #endif |
| 58 | |
| 59 | #ifdef FLASH_DEBUG |
| 60 | #define PRINTK(args...) printf(args) |
| 61 | #else |
| 62 | #define PRINTK(args...) |
| 63 | #endif |
| 64 | |
| 65 | /* ------------------------------------------------------------------------ */ |
| 66 | |
| 67 | /* Development system: we have only 16 MB Flash */ |
| 68 | #ifdef CONFIG_MTD_INNOKOM_16MB |
| 69 | #define FLASH_BANK_SIZE 0x01000000 /* 16 MB (during development) */ |
| 70 | #define MAIN_SECT_SIZE 0x00020000 /* 128k per sector */ |
| 71 | #endif |
| 72 | |
| 73 | /* Production system: we have 64 MB Flash */ |
| 74 | #ifdef CONFIG_MTD_INNOKOM_64MB |
| 75 | #define FLASH_BANK_SIZE 0x04000000 /* 64 MB */ |
| 76 | #define MAIN_SECT_SIZE 0x00020000 /* 128k per sector */ |
| 77 | #endif |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 78 | |
| 79 | flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; |
| 80 | |
| 81 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 82 | #if defined CFG_JFFS_CUSTOM_PART |
| 83 | |
| 84 | /** |
| 85 | * jffs2_part_info - get information about a JFFS2 partition |
| 86 | * |
| 87 | * @part_num: number of the partition you want to get info about |
| 88 | * @return: struct part_info* in case of success, 0 if failure |
| 89 | */ |
| 90 | |
| 91 | static struct part_info part; |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 92 | static int current_part = -1; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 93 | |
| 94 | #ifdef CONFIG_MTD_INNOKOM_16MB |
| 95 | #ifdef CONFIG_MTD_INNOKOM_64MB |
| 96 | #error Please define only one CONFIG_MTD_INNOKOM_XXMB option. |
| 97 | #endif |
| 98 | struct part_info* jffs2_part_info(int part_num) { |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 99 | void *jffs2_priv_saved = part.jffs2_priv; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 100 | |
| 101 | PRINTK2("jffs2_part_info: part_num=%i\n",part_num); |
| 102 | |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 103 | if (current_part == part_num) |
| 104 | return ∂ |
| 105 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 106 | /* u-boot partition */ |
| 107 | if(part_num==0){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 108 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 109 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 110 | part.offset=(char*)0x00000000; |
| 111 | part.size=256*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 112 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 113 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 114 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 115 | |
| 116 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 117 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* primary OS+firmware partition */ |
| 121 | if(part_num==1){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 122 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 123 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 124 | part.offset=(char*)0x00040000; |
| 125 | part.size=768*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 126 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 127 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 128 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 129 | |
| 130 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 131 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 132 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 133 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 134 | /* secondary OS+firmware partition */ |
| 135 | if(part_num==2){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 136 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 137 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 138 | part.offset=(char*)0x00100000; |
| 139 | part.size=8*1024*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 140 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 141 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 142 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 143 | |
| 144 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 145 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* data partition */ |
| 149 | if(part_num==3){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 150 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 151 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 152 | part.offset=(char*)0x00900000; |
| 153 | part.size=7*1024*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 154 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 155 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 156 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 157 | |
| 158 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 159 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 160 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 161 | |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 162 | if (current_part == part_num) { |
| 163 | part.usr_priv = ¤t_part; |
| 164 | part.jffs2_priv = jffs2_priv_saved; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 165 | return ∂ |
| 166 | } |
| 167 | |
| 168 | PRINTK("jffs2_part_info: end of partition table\n"); |
| 169 | return 0; |
| 170 | } |
| 171 | #endif /* CONFIG_MTD_INNOKOM_16MB */ |
| 172 | |
| 173 | #ifdef CONFIG_MTD_INNOKOM_64MB |
| 174 | #ifdef CONFIG_MTD_INNOKOM_16MB |
| 175 | #error Please define only one CONFIG_MTD_INNOKOM_XXMB option. |
| 176 | #endif |
| 177 | struct part_info* jffs2_part_info(int part_num) { |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 178 | void *jffs2_priv_saved = part.jffs2_priv; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 179 | |
| 180 | PRINTK2("jffs2_part_info: part_num=%i\n",part_num); |
| 181 | |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 182 | if (current_part == part_num) |
| 183 | return ∂ |
| 184 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 185 | /* u-boot partition */ |
| 186 | if(part_num==0){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 187 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 188 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 189 | part.offset=(char*)0x00000000; |
| 190 | part.size=256*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 191 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 192 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 193 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 194 | |
| 195 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 196 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* primary OS+firmware partition */ |
| 200 | if(part_num==1){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 201 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 202 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 203 | part.offset=(char*)0x00040000; |
| 204 | part.size=16*1024*1024-128*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 205 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 206 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 207 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 208 | |
| 209 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 210 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 211 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 212 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 213 | /* secondary OS+firmware partition */ |
| 214 | if(part_num==2){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 215 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 216 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 217 | part.offset=(char*)0x01020000; |
| 218 | part.size=16*1024*1024-128*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 219 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 220 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 221 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 222 | |
| 223 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 224 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* data partition */ |
| 228 | if(part_num==3){ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 229 | memset(&part, 0, sizeof(part)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 230 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 231 | part.offset=(char*)0x02000000; |
| 232 | part.size=32*1024*1024; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 233 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 234 | /* Mark the struct as ready */ |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 235 | current_part = part_num; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 236 | |
| 237 | PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset); |
| 238 | PRINTK("part.size = 0x%08x\n",(unsigned int)part.size); |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 239 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 240 | |
wdenk | ef5fe75 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 241 | if (current_part == part_num) { |
| 242 | part.usr_priv = ¤t_part; |
| 243 | part.jffs2_priv = jffs2_priv_saved; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 244 | return ∂ |
| 245 | } |
| 246 | |
| 247 | PRINTK("jffs2_part_info: end of partition table\n"); |
| 248 | return 0; |
| 249 | } |
| 250 | #endif /* CONFIG_MTD_INNOKOM_64MB */ |
| 251 | #endif /* defined CFG_JFFS_CUSTOM_PART */ |
| 252 | |
| 253 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 254 | /** |
| 255 | * flash_init: - initialize data structures for flash chips |
| 256 | * |
| 257 | * @return: size of the flash |
| 258 | */ |
| 259 | |
| 260 | ulong flash_init(void) |
| 261 | { |
| 262 | int i, j; |
| 263 | ulong size = 0; |
| 264 | |
| 265 | for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) { |
| 266 | ulong flashbase = 0; |
| 267 | flash_info[i].flash_id = |
| 268 | (INTEL_MANUFACT & FLASH_VENDMASK) | |
| 269 | (INTEL_ID_28F128J3 & FLASH_TYPEMASK); |
| 270 | flash_info[i].size = FLASH_BANK_SIZE; |
| 271 | flash_info[i].sector_count = CFG_MAX_FLASH_SECT; |
| 272 | memset(flash_info[i].protect, 0, CFG_MAX_FLASH_SECT); |
| 273 | |
| 274 | switch (i) { |
| 275 | case 0: |
| 276 | flashbase = PHYS_FLASH_1; |
| 277 | break; |
| 278 | default: |
| 279 | panic("configured to many flash banks!\n"); |
| 280 | break; |
| 281 | } |
| 282 | for (j = 0; j < flash_info[i].sector_count; j++) { |
| 283 | flash_info[i].start[j] = flashbase + j*MAIN_SECT_SIZE; |
| 284 | } |
| 285 | size += flash_info[i].size; |
| 286 | } |
| 287 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 288 | /* Protect u-boot sectors */ |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 289 | flash_protect(FLAG_PROTECT_SET, |
| 290 | CFG_FLASH_BASE, |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 291 | CFG_FLASH_BASE + (256*1024) - 1, |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 292 | &flash_info[0]); |
| 293 | |
| 294 | #ifdef CFG_ENV_IS_IN_FLASH |
| 295 | flash_protect(FLAG_PROTECT_SET, |
| 296 | CFG_ENV_ADDR, |
| 297 | CFG_ENV_ADDR + CFG_ENV_SIZE - 1, |
| 298 | &flash_info[0]); |
| 299 | #endif |
| 300 | |
| 301 | return size; |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * flash_print_info: - print information about the flash situation |
| 307 | * |
| 308 | * @param info: |
| 309 | */ |
| 310 | |
| 311 | void flash_print_info (flash_info_t *info) |
| 312 | { |
| 313 | int i, j; |
| 314 | |
| 315 | for (j=0; j<CFG_MAX_FLASH_BANKS; j++) { |
| 316 | |
| 317 | switch (info->flash_id & FLASH_VENDMASK) { |
| 318 | |
| 319 | case (INTEL_MANUFACT & FLASH_VENDMASK): |
| 320 | printf("Intel: "); |
| 321 | break; |
| 322 | default: |
| 323 | printf("Unknown Vendor "); |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | switch (info->flash_id & FLASH_TYPEMASK) { |
| 328 | |
| 329 | case (INTEL_ID_28F128J3 & FLASH_TYPEMASK): |
| 330 | printf("28F128J3 (128Mbit)\n"); |
| 331 | break; |
| 332 | default: |
| 333 | printf("Unknown Chip Type\n"); |
| 334 | return; |
| 335 | } |
| 336 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 337 | printf(" Size: %ld MB in %d Sectors\n", |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 338 | info->size >> 20, info->sector_count); |
| 339 | |
| 340 | printf(" Sector Start Addresses:"); |
| 341 | for (i = 0; i < info->sector_count; i++) { |
| 342 | if ((i % 5) == 0) printf ("\n "); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 343 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 344 | printf (" %08lX%s", info->start[i], |
| 345 | info->protect[i] ? " (RO)" : " "); |
| 346 | } |
| 347 | printf ("\n"); |
| 348 | info++; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /** |
| 354 | * flash_erase: - erase flash sectors |
| 355 | * |
| 356 | */ |
| 357 | |
| 358 | int flash_erase(flash_info_t *info, int s_first, int s_last) |
| 359 | { |
| 360 | int flag, prot, sect; |
| 361 | int rc = ERR_OK; |
| 362 | |
| 363 | if (info->flash_id == FLASH_UNKNOWN) |
| 364 | return ERR_UNKNOWN_FLASH_TYPE; |
| 365 | |
| 366 | if ((s_first < 0) || (s_first > s_last)) { |
| 367 | return ERR_INVAL; |
| 368 | } |
| 369 | |
| 370 | if ((info->flash_id & FLASH_VENDMASK) != (INTEL_MANUFACT & FLASH_VENDMASK)) |
| 371 | return ERR_UNKNOWN_FLASH_VENDOR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 372 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 373 | prot = 0; |
| 374 | for (sect=s_first; sect<=s_last; ++sect) { |
| 375 | if (info->protect[sect]) prot++; |
| 376 | } |
| 377 | |
| 378 | if (prot) return ERR_PROTECTED; |
| 379 | |
| 380 | /* |
| 381 | * Disable interrupts which might cause a timeout |
| 382 | * here. Remember that our exception vectors are |
| 383 | * at address 0 in the flash, and we don't want a |
| 384 | * (ticker) exception to happen while the flash |
| 385 | * chip is in programming mode. |
| 386 | */ |
| 387 | |
| 388 | flag = disable_interrupts(); |
| 389 | |
| 390 | /* Start erase on unprotected sectors */ |
| 391 | for (sect = s_first; sect<=s_last && !ctrlc(); sect++) { |
| 392 | |
| 393 | printf("Erasing sector %2d ... ", sect); |
| 394 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 395 | PRINTK("\n"); |
| 396 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 397 | /* arm simple, non interrupt dependent timer */ |
| 398 | reset_timer_masked(); |
| 399 | |
| 400 | if (info->protect[sect] == 0) { /* not protected */ |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 401 | u16 * volatile addr = (u16 * volatile)(info->start[sect]); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 402 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 403 | PRINTK("unlocking sector\n"); |
| 404 | *addr = 0x0060; |
| 405 | *addr = 0x00d0; |
| 406 | *addr = 0x00ff; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 407 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 408 | PRINTK("erasing sector\n"); |
| 409 | *addr = 0x0020; |
| 410 | PRINTK("confirming erase\n"); |
| 411 | *addr = 0x00D0; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 412 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 413 | while ((*addr & 0x0080) != 0x0080) { |
| 414 | PRINTK("."); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 415 | if (get_timer_masked() > CFG_FLASH_ERASE_TOUT) { |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 416 | *addr = 0x00B0; /* suspend erase*/ |
| 417 | *addr = 0x00FF; /* read mode */ |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 418 | rc = ERR_TIMOUT; |
| 419 | goto outahere; |
| 420 | } |
| 421 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 422 | |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 423 | PRINTK("clearing status register\n"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 424 | *addr = 0x0050; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 425 | PRINTK("resetting to read mode"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 426 | *addr = 0x00FF; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 427 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame^] | 428 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 429 | printf("ok.\n"); |
| 430 | } |
| 431 | |
| 432 | if (ctrlc()) printf("User Interrupt!\n"); |
| 433 | |
| 434 | outahere: |
| 435 | |
| 436 | /* allow flash to settle - wait 10 ms */ |
| 437 | udelay_masked(10000); |
| 438 | |
| 439 | if (flag) enable_interrupts(); |
| 440 | |
| 441 | return rc; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /** |
| 446 | * write_word: - copy memory to flash |
| 447 | * |
| 448 | * @param info: |
| 449 | * @param dest: |
| 450 | * @param data: |
| 451 | * @return: |
| 452 | */ |
| 453 | |
| 454 | static int write_word (flash_info_t *info, ulong dest, ushort data) |
| 455 | { |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 456 | volatile u16 *addr = (u16 *)dest, val; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 457 | int rc = ERR_OK; |
| 458 | int flag; |
| 459 | |
| 460 | /* Check if Flash is (sufficiently) erased */ |
| 461 | if ((*addr & data) != data) return ERR_NOT_ERASED; |
| 462 | |
| 463 | /* |
| 464 | * Disable interrupts which might cause a timeout |
| 465 | * here. Remember that our exception vectors are |
| 466 | * at address 0 in the flash, and we don't want a |
| 467 | * (ticker) exception to happen while the flash |
| 468 | * chip is in programming mode. |
| 469 | */ |
| 470 | flag = disable_interrupts(); |
| 471 | |
| 472 | /* clear status register command */ |
| 473 | *addr = 0x50; |
| 474 | |
| 475 | /* program set-up command */ |
| 476 | *addr = 0x40; |
| 477 | |
| 478 | /* latch address/data */ |
| 479 | *addr = data; |
| 480 | |
| 481 | /* arm simple, non interrupt dependent timer */ |
| 482 | reset_timer_masked(); |
| 483 | |
| 484 | /* wait while polling the status register */ |
| 485 | while(((val = *addr) & 0x80) != 0x80) { |
| 486 | if (get_timer_masked() > CFG_FLASH_WRITE_TOUT) { |
| 487 | rc = ERR_TIMOUT; |
| 488 | *addr = 0xB0; /* suspend program command */ |
| 489 | goto outahere; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | if(val & 0x1A) { /* check for error */ |
| 494 | printf("\nFlash write error %02x at address %08lx\n", |
| 495 | (int)val, (unsigned long)dest); |
| 496 | if(val & (1<<3)) { |
| 497 | printf("Voltage range error.\n"); |
| 498 | rc = ERR_PROG_ERROR; |
| 499 | goto outahere; |
| 500 | } |
| 501 | if(val & (1<<1)) { |
| 502 | printf("Device protect error.\n"); |
| 503 | rc = ERR_PROTECTED; |
| 504 | goto outahere; |
| 505 | } |
| 506 | if(val & (1<<4)) { |
| 507 | printf("Programming error.\n"); |
| 508 | rc = ERR_PROG_ERROR; |
| 509 | goto outahere; |
| 510 | } |
| 511 | rc = ERR_PROG_ERROR; |
| 512 | goto outahere; |
| 513 | } |
| 514 | |
| 515 | outahere: |
| 516 | |
| 517 | *addr = 0xFF; /* read array command */ |
| 518 | if (flag) enable_interrupts(); |
| 519 | |
| 520 | return rc; |
| 521 | } |
| 522 | |
| 523 | |
| 524 | /** |
| 525 | * write_buf: - Copy memory to flash. |
| 526 | * |
| 527 | * @param info: |
| 528 | * @param src: source of copy transaction |
| 529 | * @param addr: where to copy to |
| 530 | * @param cnt: number of bytes to copy |
| 531 | * |
| 532 | * @return error code |
| 533 | */ |
| 534 | |
| 535 | int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) |
| 536 | { |
| 537 | ulong cp, wp; |
| 538 | ushort data; |
| 539 | int l; |
| 540 | int i, rc; |
| 541 | |
| 542 | wp = (addr & ~1); /* get lower word aligned address */ |
| 543 | |
| 544 | /* |
| 545 | * handle unaligned start bytes |
| 546 | */ |
| 547 | if ((l = addr - wp) != 0) { |
| 548 | data = 0; |
| 549 | for (i=0, cp=wp; i<l; ++i, ++cp) { |
| 550 | data = (data >> 8) | (*(uchar *)cp << 8); |
| 551 | } |
| 552 | for (; i<2 && cnt>0; ++i) { |
| 553 | data = (data >> 8) | (*src++ << 8); |
| 554 | --cnt; |
| 555 | ++cp; |
| 556 | } |
| 557 | for (; cnt==0 && i<2; ++i, ++cp) { |
| 558 | data = (data >> 8) | (*(uchar *)cp << 8); |
| 559 | } |
| 560 | |
| 561 | if ((rc = write_word(info, wp, data)) != 0) { |
| 562 | return (rc); |
| 563 | } |
| 564 | wp += 2; |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * handle word aligned part |
| 569 | */ |
| 570 | while (cnt >= 2) { |
| 571 | /* data = *((vushort*)src); */ |
| 572 | data = *((ushort*)src); |
| 573 | if ((rc = write_word(info, wp, data)) != 0) { |
| 574 | return (rc); |
| 575 | } |
| 576 | src += 2; |
| 577 | wp += 2; |
| 578 | cnt -= 2; |
| 579 | } |
| 580 | |
| 581 | if (cnt == 0) return ERR_OK; |
| 582 | |
| 583 | /* |
| 584 | * handle unaligned tail bytes |
| 585 | */ |
| 586 | data = 0; |
| 587 | for (i=0, cp=wp; i<2 && cnt>0; ++i, ++cp) { |
| 588 | data = (data >> 8) | (*src++ << 8); |
| 589 | --cnt; |
| 590 | } |
| 591 | for (; i<2; ++i, ++cp) { |
| 592 | data = (data >> 8) | (*(uchar *)cp << 8); |
| 593 | } |
| 594 | |
| 595 | return write_word(info, wp, data); |
| 596 | } |