wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 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 | /* |
| 25 | * FLASH support |
| 26 | */ |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_HAS_DATAFLASH |
| 31 | #include <dataflash.h> |
| 32 | #endif |
| 33 | |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 34 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 35 | #include <jffs2/jffs2.h> |
| 36 | |
Wolfgang Denk | 161bfc5 | 2009-11-17 21:27:39 +0100 | [diff] [blame] | 37 | /* partition handling routines */ |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 38 | int mtdparts_init(void); |
Stefan Roese | b1423dd | 2009-03-19 13:30:36 +0100 | [diff] [blame] | 39 | int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num); |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 40 | int find_dev_and_part(const char *id, struct mtd_device **dev, |
| 41 | u8 *part_num, struct part_info **part); |
| 42 | #endif |
| 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | #ifndef CONFIG_SYS_NO_FLASH |
Stefan Roese | 64b96a3 | 2010-08-31 10:04:11 +0200 | [diff] [blame] | 45 | #include <flash.h> |
| 46 | #include <mtd/cfi_flash.h> |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 47 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 48 | |
| 49 | /* |
| 50 | * The user interface starts numbering for Flash banks with 1 |
| 51 | * for historical reasons. |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | * this routine looks for an abbreviated flash range specification. |
| 56 | * the syntax is B:SF[-SL], where B is the bank number, SF is the first |
| 57 | * sector to erase, and SL is the last sector to erase (defaults to SF). |
| 58 | * bank numbers start at 1 to be consistent with other specs, sector numbers |
| 59 | * start at zero. |
| 60 | * |
| 61 | * returns: 1 - correct spec; *pinfo, *psf and *psl are |
| 62 | * set appropriately |
| 63 | * 0 - doesn't look like an abbreviated spec |
| 64 | * -1 - looks like an abbreviated spec, but got |
| 65 | * a parsing error, a number out of range, |
| 66 | * or an invalid flash bank. |
| 67 | */ |
| 68 | static int |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 69 | abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 70 | { |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 71 | flash_info_t *fp; |
| 72 | int bank, first, last; |
| 73 | char *p, *ep; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 74 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 75 | if ((p = strchr (str, ':')) == NULL) |
| 76 | return 0; |
| 77 | *p++ = '\0'; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 78 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 79 | bank = simple_strtoul (str, &ep, 10); |
| 80 | if (ep == str || *ep != '\0' || |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS || |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 82 | (fp = &flash_info[bank - 1])->flash_id == FLASH_UNKNOWN) |
| 83 | return -1; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 84 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 85 | str = p; |
| 86 | if ((p = strchr (str, '-')) != NULL) |
| 87 | *p++ = '\0'; |
| 88 | |
| 89 | first = simple_strtoul (str, &ep, 10); |
| 90 | if (ep == str || *ep != '\0' || first >= fp->sector_count) |
| 91 | return -1; |
| 92 | |
| 93 | if (p != NULL) { |
| 94 | last = simple_strtoul (p, &ep, 10); |
| 95 | if (ep == p || *ep != '\0' || |
| 96 | last < first || last >= fp->sector_count) |
| 97 | return -1; |
| 98 | } else { |
| 99 | last = first; |
| 100 | } |
| 101 | |
| 102 | *pinfo = fp; |
| 103 | *psf = first; |
| 104 | *psl = last; |
| 105 | |
| 106 | return 1; |
| 107 | } |
| 108 | |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 109 | /* |
Bartlomiej Sieka | 6c24d31 | 2008-10-01 15:26:27 +0200 | [diff] [blame] | 110 | * Take *addr in Flash and adjust it to fall on the end of its sector |
| 111 | */ |
| 112 | int flash_sect_roundb (ulong *addr) |
| 113 | { |
| 114 | flash_info_t *info; |
| 115 | ulong bank, sector_end_addr; |
| 116 | char found; |
| 117 | int i; |
| 118 | |
| 119 | /* find the end addr of the sector where the *addr is */ |
| 120 | found = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 121 | for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS && !found; ++bank) { |
Bartlomiej Sieka | 6c24d31 | 2008-10-01 15:26:27 +0200 | [diff] [blame] | 122 | info = &flash_info[bank]; |
| 123 | for (i = 0; i < info->sector_count && !found; ++i) { |
| 124 | /* get the end address of the sector */ |
| 125 | if (i == info->sector_count - 1) { |
| 126 | sector_end_addr = info->start[0] + |
| 127 | info->size - 1; |
| 128 | } else { |
| 129 | sector_end_addr = info->start[i+1] - 1; |
| 130 | } |
| 131 | |
| 132 | if (*addr <= sector_end_addr && |
| 133 | *addr >= info->start[i]) { |
| 134 | found = 1; |
| 135 | /* adjust *addr if necessary */ |
| 136 | if (*addr < sector_end_addr) |
| 137 | *addr = sector_end_addr; |
| 138 | } /* sector */ |
| 139 | } /* bank */ |
| 140 | } |
| 141 | if (!found) { |
| 142 | /* error, addres not in flash */ |
| 143 | printf("Error: end address (0x%08lx) not in flash!\n", *addr); |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 151 | * This function computes the start and end addresses for both |
| 152 | * erase and protect commands. The range of the addresses on which |
| 153 | * either of the commands is to operate can be given in two forms: |
| 154 | * 1. <cmd> start end - operate on <'start', 'end') |
Wolfgang Denk | d06ce5d | 2005-08-02 17:06:17 +0200 | [diff] [blame] | 155 | * 2. <cmd> start +length - operate on <'start', start + length) |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 156 | * If the second form is used and the end address doesn't fall on the |
| 157 | * sector boundary, than it will be adjusted to the next sector boundary. |
| 158 | * If it isn't in the flash, the function will fail (return -1). |
| 159 | * Input: |
| 160 | * arg1, arg2: address specification (i.e. both command arguments) |
| 161 | * Output: |
| 162 | * addr_first, addr_last: computed address range |
| 163 | * Return: |
| 164 | * 1: success |
| 165 | * -1: failure (bad format, bad address). |
| 166 | */ |
| 167 | static int |
| 168 | addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last) |
| 169 | { |
| 170 | char *ep; |
Heiko Schocher | fd9e97c | 2006-04-11 14:39:21 +0200 | [diff] [blame] | 171 | char len_used; /* indicates if the "start +length" form used */ |
Wolfgang Denk | bb5c404 | 2005-08-05 11:10:31 +0200 | [diff] [blame] | 172 | |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 173 | *addr_first = simple_strtoul(arg1, &ep, 16); |
| 174 | if (ep == arg1 || *ep != '\0') |
| 175 | return -1; |
| 176 | |
Heiko Schocher | fd9e97c | 2006-04-11 14:39:21 +0200 | [diff] [blame] | 177 | len_used = 0; |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 178 | if (arg2 && *arg2 == '+'){ |
| 179 | len_used = 1; |
| 180 | ++arg2; |
| 181 | } |
| 182 | |
| 183 | *addr_last = simple_strtoul(arg2, &ep, 16); |
| 184 | if (ep == arg2 || *ep != '\0') |
| 185 | return -1; |
| 186 | |
| 187 | if (len_used){ |
| 188 | /* |
| 189 | * *addr_last has the length, compute correct *addr_last |
| 190 | * XXX watch out for the integer overflow! Right now it is |
| 191 | * checked for in both the callers. |
| 192 | */ |
| 193 | *addr_last = *addr_first + *addr_last - 1; |
| 194 | |
| 195 | /* |
| 196 | * It may happen that *addr_last doesn't fall on the sector |
| 197 | * boundary. We want to round such an address to the next |
| 198 | * sector boundary, so that the commands don't fail later on. |
| 199 | */ |
| 200 | |
Bartlomiej Sieka | 6c24d31 | 2008-10-01 15:26:27 +0200 | [diff] [blame] | 201 | if (flash_sect_roundb(addr_last) > 0) |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 202 | return -1; |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 203 | } /* "start +length" from used */ |
| 204 | |
| 205 | return 1; |
| 206 | } |
| 207 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 208 | static int |
| 209 | flash_fill_sect_ranges (ulong addr_first, ulong addr_last, |
| 210 | int *s_first, int *s_last, |
| 211 | int *s_count ) |
| 212 | { |
| 213 | flash_info_t *info; |
| 214 | ulong bank; |
| 215 | int rcode = 0; |
| 216 | |
| 217 | *s_count = 0; |
| 218 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 219 | for (bank=0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 220 | s_first[bank] = -1; /* first sector to erase */ |
| 221 | s_last [bank] = -1; /* last sector to erase */ |
| 222 | } |
| 223 | |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 224 | for (bank=0,info = &flash_info[0]; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (addr_first <= addr_last); |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 226 | ++bank, ++info) { |
| 227 | ulong b_end; |
| 228 | int sect; |
| 229 | short s_end; |
| 230 | |
| 231 | if (info->flash_id == FLASH_UNKNOWN) { |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | b_end = info->start[0] + info->size - 1; /* bank end addr */ |
| 236 | s_end = info->sector_count - 1; /* last sector */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 237 | |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 238 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 239 | for (sect=0; sect < info->sector_count; ++sect) { |
| 240 | ulong end; /* last address in current sect */ |
| 241 | |
| 242 | end = (sect == s_end) ? b_end : info->start[sect + 1] - 1; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 243 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 244 | if (addr_first > end) |
| 245 | continue; |
| 246 | if (addr_last < info->start[sect]) |
| 247 | continue; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 248 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 249 | if (addr_first == info->start[sect]) { |
| 250 | s_first[bank] = sect; |
| 251 | } |
| 252 | if (addr_last == end) { |
| 253 | s_last[bank] = sect; |
| 254 | } |
| 255 | } |
| 256 | if (s_first[bank] >= 0) { |
| 257 | if (s_last[bank] < 0) { |
| 258 | if (addr_last > b_end) { |
| 259 | s_last[bank] = s_end; |
| 260 | } else { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 261 | puts ("Error: end address" |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 262 | " not on sector boundary\n"); |
| 263 | rcode = 1; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | if (s_last[bank] < s_first[bank]) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 268 | puts ("Error: end sector" |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 269 | " precedes start sector\n"); |
| 270 | rcode = 1; |
| 271 | break; |
| 272 | } |
| 273 | sect = s_last[bank]; |
| 274 | addr_first = (sect == s_end) ? b_end + 1: info->start[sect + 1]; |
| 275 | (*s_count) += s_last[bank] - s_first[bank] + 1; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 276 | } else if (addr_first >= info->start[0] && addr_first < b_end) { |
| 277 | puts ("Error: start address not on sector boundary\n"); |
| 278 | rcode = 1; |
| 279 | break; |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 280 | } else if (s_last[bank] >= 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 281 | puts ("Error: cannot span across banks when they are" |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 282 | " mapped in reverse order\n"); |
| 283 | rcode = 1; |
| 284 | break; |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | return rcode; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 289 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 290 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 291 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 292 | int do_flinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 293 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 294 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 295 | ulong bank; |
Stelian Pop | a63d2eb | 2008-03-26 22:52:35 +0100 | [diff] [blame] | 296 | #endif |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 297 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 298 | #ifdef CONFIG_HAS_DATAFLASH |
| 299 | dataflash_print_info(); |
| 300 | #endif |
| 301 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 302 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 303 | if (argc == 1) { /* print info for all FLASH banks */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 304 | for (bank=0; bank <CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 305 | printf ("\nBank # %ld: ", bank+1); |
| 306 | |
| 307 | flash_print_info (&flash_info[bank]); |
| 308 | } |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | bank = simple_strtoul(argv[1], NULL, 16); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 313 | if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 314 | printf ("Only FLASH Banks # 1 ... # %d supported\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 315 | CONFIG_SYS_MAX_FLASH_BANKS); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 316 | return 1; |
| 317 | } |
| 318 | printf ("\nBank # %ld: ", bank); |
| 319 | flash_print_info (&flash_info[bank-1]); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 320 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 321 | return 0; |
| 322 | } |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 323 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 324 | int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 325 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 326 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 327 | flash_info_t *info; |
| 328 | ulong bank, addr_first, addr_last; |
| 329 | int n, sect_first, sect_last; |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 330 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 331 | struct mtd_device *dev; |
| 332 | struct part_info *part; |
| 333 | u8 dev_type, dev_num, pnum; |
| 334 | #endif |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 335 | int rcode = 0; |
| 336 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 337 | if (argc < 2) |
| 338 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 339 | |
| 340 | if (strcmp(argv[1], "all") == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 341 | for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 342 | printf ("Erase Flash Bank # %ld ", bank); |
| 343 | info = &flash_info[bank-1]; |
| 344 | rcode = flash_erase (info, 0, info->sector_count-1); |
| 345 | } |
| 346 | return rcode; |
| 347 | } |
| 348 | |
| 349 | if ((n = abbrev_spec(argv[1], &info, §_first, §_last)) != 0) { |
| 350 | if (n < 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 351 | puts ("Bad sector specification\n"); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 352 | return 1; |
| 353 | } |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 354 | printf ("Erase Flash Sectors %d-%d in Bank # %zu ", |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 355 | sect_first, sect_last, (info-flash_info)+1); |
| 356 | rcode = flash_erase(info, sect_first, sect_last); |
| 357 | return rcode; |
| 358 | } |
| 359 | |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 360 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 361 | /* erase <part-id> - erase partition */ |
Stefan Roese | b1423dd | 2009-03-19 13:30:36 +0100 | [diff] [blame] | 362 | if ((argc == 2) && (mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) { |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 363 | mtdparts_init(); |
| 364 | if (find_dev_and_part(argv[1], &dev, &pnum, &part) == 0) { |
| 365 | if (dev->id->type == MTD_DEV_TYPE_NOR) { |
| 366 | bank = dev->id->num; |
| 367 | info = &flash_info[bank]; |
| 368 | addr_first = part->offset + info->start[0]; |
| 369 | addr_last = addr_first + part->size - 1; |
| 370 | |
Wolfgang Denk | 161bfc5 | 2009-11-17 21:27:39 +0100 | [diff] [blame] | 371 | printf ("Erase Flash Partition %s, " |
Kim Phillips | f91aa8d | 2008-07-10 14:00:15 -0500 | [diff] [blame] | 372 | "bank %ld, 0x%08lx - 0x%08lx ", |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 373 | argv[1], bank, addr_first, |
| 374 | addr_last); |
| 375 | |
| 376 | rcode = flash_sect_erase(addr_first, addr_last); |
| 377 | return rcode; |
| 378 | } |
| 379 | |
| 380 | printf("cannot erase, not a NOR device\n"); |
| 381 | return 1; |
| 382 | } |
| 383 | } |
| 384 | #endif |
| 385 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 386 | if (argc != 3) |
| 387 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 388 | |
| 389 | if (strcmp(argv[1], "bank") == 0) { |
| 390 | bank = simple_strtoul(argv[2], NULL, 16); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 391 | if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 392 | printf ("Only FLASH Banks # 1 ... # %d supported\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 393 | CONFIG_SYS_MAX_FLASH_BANKS); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 394 | return 1; |
| 395 | } |
| 396 | printf ("Erase Flash Bank # %ld ", bank); |
| 397 | info = &flash_info[bank-1]; |
| 398 | rcode = flash_erase (info, 0, info->sector_count-1); |
| 399 | return rcode; |
| 400 | } |
| 401 | |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 402 | if (addr_spec(argv[1], argv[2], &addr_first, &addr_last) < 0){ |
| 403 | printf ("Bad address format\n"); |
| 404 | return 1; |
| 405 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 406 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 407 | if (addr_first >= addr_last) |
| 408 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 409 | |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 410 | rcode = flash_sect_erase(addr_first, addr_last); |
| 411 | return rcode; |
Stelian Pop | a63d2eb | 2008-03-26 22:52:35 +0100 | [diff] [blame] | 412 | #else |
| 413 | return 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 414 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 417 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 418 | int flash_sect_erase (ulong addr_first, ulong addr_last) |
| 419 | { |
| 420 | flash_info_t *info; |
| 421 | ulong bank; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 422 | int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS]; |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 423 | int erased = 0; |
| 424 | int planned; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 425 | int rcode = 0; |
| 426 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 427 | rcode = flash_fill_sect_ranges (addr_first, addr_last, |
| 428 | s_first, s_last, &planned ); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 429 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 430 | if (planned && (rcode == 0)) { |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 431 | for (bank=0,info = &flash_info[0]; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 432 | (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (rcode == 0); |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 433 | ++bank, ++info) { |
| 434 | if (s_first[bank]>=0) { |
| 435 | erased += s_last[bank] - s_first[bank] + 1; |
wdenk | 3f08e20 | 2003-08-07 14:52:18 +0000 | [diff] [blame] | 436 | debug ("Erase Flash from 0x%08lx to 0x%08lx " |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 437 | "in Bank # %ld ", |
| 438 | info->start[s_first[bank]], |
| 439 | (s_last[bank] == info->sector_count) ? |
| 440 | info->start[0] + info->size - 1: |
| 441 | info->start[s_last[bank]+1] - 1, |
| 442 | bank+1); |
| 443 | rcode = flash_erase (info, s_first[bank], s_last[bank]); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 444 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 445 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 446 | printf ("Erased %d sectors\n", erased); |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 447 | } else if (rcode == 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 448 | puts ("Error: start and/or end address" |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 449 | " not on sector boundary\n"); |
| 450 | rcode = 1; |
| 451 | } |
| 452 | return rcode; |
| 453 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 454 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 455 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 456 | int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 457 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 458 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 459 | flash_info_t *info; |
Stelian Pop | a63d2eb | 2008-03-26 22:52:35 +0100 | [diff] [blame] | 460 | ulong bank; |
| 461 | int i, n, sect_first, sect_last; |
Wolfgang Denk | a2f3082 | 2009-07-18 23:18:14 +0200 | [diff] [blame] | 462 | #endif /* CONFIG_SYS_NO_FLASH */ |
Wolfgang Denk | fd53c5e | 2009-07-19 19:32:37 +0200 | [diff] [blame] | 463 | #if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH) |
| 464 | ulong addr_first, addr_last; |
| 465 | #endif |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 466 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 467 | struct mtd_device *dev; |
| 468 | struct part_info *part; |
| 469 | u8 dev_type, dev_num, pnum; |
| 470 | #endif |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 471 | #ifdef CONFIG_HAS_DATAFLASH |
| 472 | int status; |
| 473 | #endif |
Wolfgang Denk | a2f3082 | 2009-07-18 23:18:14 +0200 | [diff] [blame] | 474 | int p; |
| 475 | int rcode = 0; |
Stefan Roese | efef95b | 2006-04-01 13:41:03 +0200 | [diff] [blame] | 476 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 477 | if (argc < 3) |
| 478 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 479 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 480 | if (strcmp(argv[1], "off") == 0) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 481 | p = 0; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 482 | else if (strcmp(argv[1], "on") == 0) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 483 | p = 1; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 484 | else |
| 485 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 486 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 487 | #ifdef CONFIG_HAS_DATAFLASH |
| 488 | if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) { |
| 489 | addr_first = simple_strtoul(argv[2], NULL, 16); |
| 490 | addr_last = simple_strtoul(argv[3], NULL, 16); |
| 491 | |
| 492 | if (addr_dataflash(addr_first) && addr_dataflash(addr_last)) { |
| 493 | status = dataflash_real_protect(p,addr_first,addr_last); |
| 494 | if (status < 0){ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 495 | puts ("Bad DataFlash sector specification\n"); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 496 | return 1; |
| 497 | } |
| 498 | printf("%sProtect %d DataFlash Sectors\n", |
| 499 | p ? "" : "Un-", status); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | } |
| 503 | #endif |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 504 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 505 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 506 | if (strcmp(argv[2], "all") == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 507 | for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 508 | info = &flash_info[bank-1]; |
| 509 | if (info->flash_id == FLASH_UNKNOWN) { |
| 510 | continue; |
| 511 | } |
| 512 | printf ("%sProtect Flash Bank # %ld\n", |
| 513 | p ? "" : "Un-", bank); |
| 514 | |
| 515 | for (i=0; i<info->sector_count; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 516 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 517 | if (flash_real_protect(info, i, p)) |
| 518 | rcode = 1; |
| 519 | putc ('.'); |
| 520 | #else |
| 521 | info->protect[i] = p; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 522 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 523 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 524 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
Heiko Schocher | fd9e97c | 2006-04-11 14:39:21 +0200 | [diff] [blame] | 525 | if (!rcode) puts (" done\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 526 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
Heiko Schocher | fd9e97c | 2006-04-11 14:39:21 +0200 | [diff] [blame] | 527 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 528 | return rcode; |
| 529 | } |
| 530 | |
| 531 | if ((n = abbrev_spec(argv[2], &info, §_first, §_last)) != 0) { |
| 532 | if (n < 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 533 | puts ("Bad sector specification\n"); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 534 | return 1; |
| 535 | } |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 536 | printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n", |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 537 | p ? "" : "Un-", sect_first, sect_last, |
| 538 | (info-flash_info)+1); |
| 539 | for (i = sect_first; i <= sect_last; i++) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 540 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 541 | if (flash_real_protect(info, i, p)) |
| 542 | rcode = 1; |
| 543 | putc ('.'); |
| 544 | #else |
| 545 | info->protect[i] = p; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 546 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 549 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 550 | if (!rcode) puts (" done\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 551 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 552 | |
| 553 | return rcode; |
| 554 | } |
Wolfgang Denk | eb95c85 | 2005-08-10 15:14:32 +0200 | [diff] [blame] | 555 | |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 556 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 557 | /* protect on/off <part-id> */ |
Stefan Roese | b1423dd | 2009-03-19 13:30:36 +0100 | [diff] [blame] | 558 | if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) { |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 559 | mtdparts_init(); |
| 560 | if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) { |
| 561 | if (dev->id->type == MTD_DEV_TYPE_NOR) { |
| 562 | bank = dev->id->num; |
| 563 | info = &flash_info[bank]; |
| 564 | addr_first = part->offset + info->start[0]; |
| 565 | addr_last = addr_first + part->size - 1; |
| 566 | |
Wolfgang Denk | 161bfc5 | 2009-11-17 21:27:39 +0100 | [diff] [blame] | 567 | printf ("%sProtect Flash Partition %s, " |
Kim Phillips | f91aa8d | 2008-07-10 14:00:15 -0500 | [diff] [blame] | 568 | "bank %ld, 0x%08lx - 0x%08lx\n", |
Wolfgang Denk | 47f5779 | 2005-08-08 01:03:24 +0200 | [diff] [blame] | 569 | p ? "" : "Un", argv[1], |
| 570 | bank, addr_first, addr_last); |
| 571 | |
| 572 | rcode = flash_sect_protect (p, addr_first, addr_last); |
| 573 | return rcode; |
| 574 | } |
| 575 | |
| 576 | printf("cannot %sprotect, not a NOR device\n", |
| 577 | p ? "" : "un"); |
| 578 | return 1; |
| 579 | } |
| 580 | } |
| 581 | #endif |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 582 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 583 | if (argc != 4) |
| 584 | return cmd_usage(cmdtp); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 585 | |
| 586 | if (strcmp(argv[2], "bank") == 0) { |
| 587 | bank = simple_strtoul(argv[3], NULL, 16); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 588 | if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 589 | printf ("Only FLASH Banks # 1 ... # %d supported\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 590 | CONFIG_SYS_MAX_FLASH_BANKS); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 591 | return 1; |
| 592 | } |
| 593 | printf ("%sProtect Flash Bank # %ld\n", |
| 594 | p ? "" : "Un-", bank); |
| 595 | info = &flash_info[bank-1]; |
| 596 | |
| 597 | if (info->flash_id == FLASH_UNKNOWN) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 598 | puts ("missing or unknown FLASH type\n"); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 599 | return 1; |
| 600 | } |
| 601 | for (i=0; i<info->sector_count; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 602 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 603 | if (flash_real_protect(info, i, p)) |
| 604 | rcode = 1; |
| 605 | putc ('.'); |
| 606 | #else |
| 607 | info->protect[i] = p; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 608 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 611 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 612 | if (!rcode) puts (" done\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 613 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 614 | |
| 615 | return rcode; |
| 616 | } |
| 617 | |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 618 | if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){ |
| 619 | printf("Bad address format\n"); |
| 620 | return 1; |
| 621 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 622 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 623 | if (addr_first >= addr_last) |
| 624 | return cmd_usage(cmdtp); |
| 625 | |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 626 | rcode = flash_sect_protect (p, addr_first, addr_last); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 627 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 628 | return rcode; |
| 629 | } |
| 630 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 631 | #ifndef CONFIG_SYS_NO_FLASH |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 632 | int flash_sect_protect (int p, ulong addr_first, ulong addr_last) |
| 633 | { |
| 634 | flash_info_t *info; |
| 635 | ulong bank; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 636 | int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS]; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 637 | int protected, i; |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 638 | int planned; |
| 639 | int rcode; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 640 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 641 | rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned ); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 642 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 643 | protected = 0; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 644 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 645 | if (planned && (rcode == 0)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 646 | for (bank=0,info = &flash_info[0]; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) { |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 647 | if (info->flash_id == FLASH_UNKNOWN) { |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 648 | continue; |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 649 | } |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 650 | |
| 651 | if (s_first[bank]>=0 && s_first[bank]<=s_last[bank]) { |
stroese | eb4a439 | 2003-12-09 14:58:22 +0000 | [diff] [blame] | 652 | debug ("%sProtecting sectors %d..%d in bank %ld\n", |
| 653 | p ? "" : "Un-", |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 654 | s_first[bank], s_last[bank], bank+1); |
| 655 | protected += s_last[bank] - s_first[bank] + 1; |
| 656 | for (i=s_first[bank]; i<=s_last[bank]; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 657 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 658 | if (flash_real_protect(info, i, p)) |
| 659 | rcode = 1; |
| 660 | putc ('.'); |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 661 | #else |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 662 | info->protect[i] = p; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 663 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 664 | } |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 665 | } |
Stefan Roese | efef95b | 2006-04-01 13:41:03 +0200 | [diff] [blame] | 666 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 667 | #if defined(CONFIG_SYS_FLASH_PROTECTION) |
Stefan Roese | efef95b | 2006-04-01 13:41:03 +0200 | [diff] [blame] | 668 | puts (" done\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 669 | #endif /* CONFIG_SYS_FLASH_PROTECTION */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 670 | |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 671 | printf ("%sProtected %d sectors\n", |
| 672 | p ? "" : "Un-", protected); |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 673 | } else if (rcode == 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 674 | puts ("Error: start and/or end address" |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 675 | " not on sector boundary\n"); |
| 676 | rcode = 1; |
| 677 | } |
| 678 | return rcode; |
| 679 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 680 | #endif /* CONFIG_SYS_NO_FLASH */ |
wdenk | 38a24a6 | 2002-09-18 12:49:44 +0000 | [diff] [blame] | 681 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 682 | |
| 683 | /**************************************************/ |
Alexander Stein | 8967edf | 2010-08-11 16:48:04 +0200 | [diff] [blame] | 684 | #if defined(CONFIG_CMD_MTDPARTS) |
Wolfgang Denk | 16439ee | 2005-08-09 17:25:22 +0200 | [diff] [blame] | 685 | # define TMP_ERASE "erase <part-id>\n - erase partition\n" |
| 686 | # define TMP_PROT_ON "protect on <part-id>\n - protect partition\n" |
| 687 | # define TMP_PROT_OFF "protect off <part-id>\n - make partition writable\n" |
| 688 | #else |
| 689 | # define TMP_ERASE /* empty */ |
| 690 | # define TMP_PROT_ON /* empty */ |
| 691 | # define TMP_PROT_OFF /* empty */ |
| 692 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 693 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 694 | U_BOOT_CMD( |
| 695 | flinfo, 2, 1, do_flinfo, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 696 | "print FLASH memory information", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 697 | "\n - print information for all FLASH memory banks\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 698 | "flinfo N\n - print information for FLASH memory bank # N" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 699 | ); |
| 700 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 701 | U_BOOT_CMD( |
Detlev Zundel | 409a285 | 2007-05-23 19:02:41 +0200 | [diff] [blame] | 702 | erase, 3, 0, do_flerase, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 703 | "erase FLASH memory", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 704 | "start end\n" |
| 705 | " - erase FLASH from addr 'start' to addr 'end'\n" |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 706 | "erase start +len\n" |
| 707 | " - erase FLASH from addr 'start' to the end of sect " |
| 708 | "w/addr 'start'+'len'-1\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 709 | "erase N:SF[-SL]\n - erase sectors SF-SL in FLASH bank # N\n" |
| 710 | "erase bank N\n - erase FLASH bank # N\n" |
Wolfgang Denk | 16439ee | 2005-08-09 17:25:22 +0200 | [diff] [blame] | 711 | TMP_ERASE |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 712 | "erase all\n - erase all FLASH banks" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 713 | ); |
| 714 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 715 | U_BOOT_CMD( |
Detlev Zundel | 409a285 | 2007-05-23 19:02:41 +0200 | [diff] [blame] | 716 | protect, 4, 0, do_protect, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 717 | "enable or disable FLASH write protection", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 718 | "on start end\n" |
| 719 | " - protect FLASH from addr 'start' to addr 'end'\n" |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 720 | "protect on start +len\n" |
| 721 | " - protect FLASH from addr 'start' to end of sect " |
| 722 | "w/addr 'start'+'len'-1\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 723 | "protect on N:SF[-SL]\n" |
| 724 | " - protect sectors SF-SL in FLASH bank # N\n" |
| 725 | "protect on bank N\n - protect FLASH bank # N\n" |
Wolfgang Denk | 16439ee | 2005-08-09 17:25:22 +0200 | [diff] [blame] | 726 | TMP_PROT_ON |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 727 | "protect on all\n - protect all FLASH banks\n" |
| 728 | "protect off start end\n" |
| 729 | " - make FLASH from addr 'start' to addr 'end' writable\n" |
Wolfgang Denk | 104866b | 2005-07-21 11:45:50 +0200 | [diff] [blame] | 730 | "protect off start +len\n" |
| 731 | " - make FLASH from addr 'start' to end of sect " |
| 732 | "w/addr 'start'+'len'-1 wrtable\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 733 | "protect off N:SF[-SL]\n" |
| 734 | " - make sectors SF-SL writable in FLASH bank # N\n" |
| 735 | "protect off bank N\n - make FLASH bank # N writable\n" |
Wolfgang Denk | 16439ee | 2005-08-09 17:25:22 +0200 | [diff] [blame] | 736 | TMP_PROT_OFF |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 737 | "protect off all\n - make all FLASH banks writable" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 738 | ); |
| 739 | |
Wolfgang Denk | 16439ee | 2005-08-09 17:25:22 +0200 | [diff] [blame] | 740 | #undef TMP_ERASE |
| 741 | #undef TMP_PROT_ON |
| 742 | #undef TMP_PROT_OFF |