cmd_flash.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. * FLASH support
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #ifdef CONFIG_HAS_DATAFLASH
  29. #include <dataflash.h>
  30. #endif
  31. #if (CONFIG_COMMANDS & CFG_CMD_FLASH)
  32. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  33. #include <jffs2/jffs2.h>
  34. /* parition handling routines */
  35. int mtdparts_init(void);
  36. int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
  37. int find_dev_and_part(const char *id, struct mtd_device **dev,
  38. u8 *part_num, struct part_info **part);
  39. #endif
  40. extern flash_info_t flash_info[]; /* info for FLASH chips */
  41. /*
  42. * The user interface starts numbering for Flash banks with 1
  43. * for historical reasons.
  44. */
  45. /*
  46. * this routine looks for an abbreviated flash range specification.
  47. * the syntax is B:SF[-SL], where B is the bank number, SF is the first
  48. * sector to erase, and SL is the last sector to erase (defaults to SF).
  49. * bank numbers start at 1 to be consistent with other specs, sector numbers
  50. * start at zero.
  51. *
  52. * returns: 1 - correct spec; *pinfo, *psf and *psl are
  53. * set appropriately
  54. * 0 - doesn't look like an abbreviated spec
  55. * -1 - looks like an abbreviated spec, but got
  56. * a parsing error, a number out of range,
  57. * or an invalid flash bank.
  58. */
  59. static int
  60. abbrev_spec (char *str, flash_info_t ** pinfo, int *psf, int *psl)
  61. {
  62. flash_info_t *fp;
  63. int bank, first, last;
  64. char *p, *ep;
  65. if ((p = strchr (str, ':')) == NULL)
  66. return 0;
  67. *p++ = '\0';
  68. bank = simple_strtoul (str, &ep, 10);
  69. if (ep == str || *ep != '\0' ||
  70. bank < 1 || bank > CFG_MAX_FLASH_BANKS ||
  71. (fp = &flash_info[bank - 1])->flash_id == FLASH_UNKNOWN)
  72. return -1;
  73. str = p;
  74. if ((p = strchr (str, '-')) != NULL)
  75. *p++ = '\0';
  76. first = simple_strtoul (str, &ep, 10);
  77. if (ep == str || *ep != '\0' || first >= fp->sector_count)
  78. return -1;
  79. if (p != NULL) {
  80. last = simple_strtoul (p, &ep, 10);
  81. if (ep == p || *ep != '\0' ||
  82. last < first || last >= fp->sector_count)
  83. return -1;
  84. } else {
  85. last = first;
  86. }
  87. *pinfo = fp;
  88. *psf = first;
  89. *psl = last;
  90. return 1;
  91. }
  92. /*
  93. * This function computes the start and end addresses for both
  94. * erase and protect commands. The range of the addresses on which
  95. * either of the commands is to operate can be given in two forms:
  96. * 1. <cmd> start end - operate on <'start', 'end')
  97. * 2. <cmd> start +length - operate on <'start', start + length)
  98. * If the second form is used and the end address doesn't fall on the
  99. * sector boundary, than it will be adjusted to the next sector boundary.
  100. * If it isn't in the flash, the function will fail (return -1).
  101. * Input:
  102. * arg1, arg2: address specification (i.e. both command arguments)
  103. * Output:
  104. * addr_first, addr_last: computed address range
  105. * Return:
  106. * 1: success
  107. * -1: failure (bad format, bad address).
  108. */
  109. static int
  110. addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
  111. {
  112. char len_used = 0; /* indicates if the "start +length" form used */
  113. char *ep;
  114. *addr_first = simple_strtoul(arg1, &ep, 16);
  115. if (ep == arg1 || *ep != '\0')
  116. return -1;
  117. if (arg2 && *arg2 == '+'){
  118. len_used = 1;
  119. ++arg2;
  120. }
  121. *addr_last = simple_strtoul(arg2, &ep, 16);
  122. if (ep == arg2 || *ep != '\0')
  123. return -1;
  124. if (len_used){
  125. char found = 0;
  126. ulong bank;
  127. /*
  128. * *addr_last has the length, compute correct *addr_last
  129. * XXX watch out for the integer overflow! Right now it is
  130. * checked for in both the callers.
  131. */
  132. *addr_last = *addr_first + *addr_last - 1;
  133. /*
  134. * It may happen that *addr_last doesn't fall on the sector
  135. * boundary. We want to round such an address to the next
  136. * sector boundary, so that the commands don't fail later on.
  137. */
  138. /* find the end addr of the sector where the *addr_last is */
  139. for (bank = 0; bank < CFG_MAX_FLASH_BANKS && !found; ++bank){
  140. int i;
  141. flash_info_t *info = &flash_info[bank];
  142. for (i = 0; i < info->sector_count && !found; ++i){
  143. /* get the end address of the sector */
  144. ulong sector_end_addr;
  145. if (i == info->sector_count - 1){
  146. sector_end_addr =
  147. info->start[0] + info->size - 1;
  148. } else {
  149. sector_end_addr =
  150. info->start[i+1] - 1;
  151. }
  152. if (*addr_last <= sector_end_addr &&
  153. *addr_last >= info->start[i]){
  154. /* sector found */
  155. found = 1;
  156. /* adjust *addr_last if necessary */
  157. if (*addr_last < sector_end_addr){
  158. *addr_last = sector_end_addr;
  159. }
  160. }
  161. } /* sector */
  162. } /* bank */
  163. if (!found){
  164. /* error, addres not in flash */
  165. printf("Error: end address (0x%08lx) not in flash!\n",
  166. *addr_last);
  167. return -1;
  168. }
  169. } /* "start +length" from used */
  170. return 1;
  171. }
  172. static int
  173. flash_fill_sect_ranges (ulong addr_first, ulong addr_last,
  174. int *s_first, int *s_last,
  175. int *s_count )
  176. {
  177. flash_info_t *info;
  178. ulong bank;
  179. int rcode = 0;
  180. *s_count = 0;
  181. for (bank=0; bank < CFG_MAX_FLASH_BANKS; ++bank) {
  182. s_first[bank] = -1; /* first sector to erase */
  183. s_last [bank] = -1; /* last sector to erase */
  184. }
  185. for (bank=0,info=&flash_info[0];
  186. (bank < CFG_MAX_FLASH_BANKS) && (addr_first <= addr_last);
  187. ++bank, ++info) {
  188. ulong b_end;
  189. int sect;
  190. short s_end;
  191. if (info->flash_id == FLASH_UNKNOWN) {
  192. continue;
  193. }
  194. b_end = info->start[0] + info->size - 1; /* bank end addr */
  195. s_end = info->sector_count - 1; /* last sector */
  196. for (sect=0; sect < info->sector_count; ++sect) {
  197. ulong end; /* last address in current sect */
  198. end = (sect == s_end) ? b_end : info->start[sect + 1] - 1;
  199. if (addr_first > end)
  200. continue;
  201. if (addr_last < info->start[sect])
  202. continue;
  203. if (addr_first == info->start[sect]) {
  204. s_first[bank] = sect;
  205. }
  206. if (addr_last == end) {
  207. s_last[bank] = sect;
  208. }
  209. }
  210. if (s_first[bank] >= 0) {
  211. if (s_last[bank] < 0) {
  212. if (addr_last > b_end) {
  213. s_last[bank] = s_end;
  214. } else {
  215. puts ("Error: end address"
  216. " not on sector boundary\n");
  217. rcode = 1;
  218. break;
  219. }
  220. }
  221. if (s_last[bank] < s_first[bank]) {
  222. puts ("Error: end sector"
  223. " precedes start sector\n");
  224. rcode = 1;
  225. break;
  226. }
  227. sect = s_last[bank];
  228. addr_first = (sect == s_end) ? b_end + 1: info->start[sect + 1];
  229. (*s_count) += s_last[bank] - s_first[bank] + 1;
  230. } else if (addr_first >= info->start[0] && addr_first < b_end) {
  231. puts ("Error: start address not on sector boundary\n");
  232. rcode = 1;
  233. break;
  234. } else if (s_last[bank] >= 0) {
  235. puts ("Error: cannot span across banks when they are"
  236. " mapped in reverse order\n");
  237. rcode = 1;
  238. break;
  239. }
  240. }
  241. return rcode;
  242. }
  243. int do_flinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  244. {
  245. ulong bank;
  246. #ifdef CONFIG_HAS_DATAFLASH
  247. dataflash_print_info();
  248. #endif
  249. if (argc == 1) { /* print info for all FLASH banks */
  250. for (bank=0; bank <CFG_MAX_FLASH_BANKS; ++bank) {
  251. printf ("\nBank # %ld: ", bank+1);
  252. flash_print_info (&flash_info[bank]);
  253. }
  254. return 0;
  255. }
  256. bank = simple_strtoul(argv[1], NULL, 16);
  257. if ((bank < 1) || (bank > CFG_MAX_FLASH_BANKS)) {
  258. printf ("Only FLASH Banks # 1 ... # %d supported\n",
  259. CFG_MAX_FLASH_BANKS);
  260. return 1;
  261. }
  262. printf ("\nBank # %ld: ", bank);
  263. flash_print_info (&flash_info[bank-1]);
  264. return 0;
  265. }
  266. int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  267. {
  268. flash_info_t *info;
  269. ulong bank, addr_first, addr_last;
  270. int n, sect_first, sect_last;
  271. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  272. struct mtd_device *dev;
  273. struct part_info *part;
  274. u8 dev_type, dev_num, pnum;
  275. #endif
  276. int rcode = 0;
  277. if (argc < 2) {
  278. printf ("Usage:\n%s\n", cmdtp->usage);
  279. return 1;
  280. }
  281. if (strcmp(argv[1], "all") == 0) {
  282. for (bank=1; bank<=CFG_MAX_FLASH_BANKS; ++bank) {
  283. printf ("Erase Flash Bank # %ld ", bank);
  284. info = &flash_info[bank-1];
  285. rcode = flash_erase (info, 0, info->sector_count-1);
  286. }
  287. return rcode;
  288. }
  289. if ((n = abbrev_spec(argv[1], &info, &sect_first, &sect_last)) != 0) {
  290. if (n < 0) {
  291. puts ("Bad sector specification\n");
  292. return 1;
  293. }
  294. printf ("Erase Flash Sectors %d-%d in Bank # %d ",
  295. sect_first, sect_last, (info-flash_info)+1);
  296. rcode = flash_erase(info, sect_first, sect_last);
  297. return rcode;
  298. }
  299. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  300. /* erase <part-id> - erase partition */
  301. if ((argc == 2) && (id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) {
  302. mtdparts_init();
  303. if (find_dev_and_part(argv[1], &dev, &pnum, &part) == 0) {
  304. if (dev->id->type == MTD_DEV_TYPE_NOR) {
  305. bank = dev->id->num;
  306. info = &flash_info[bank];
  307. addr_first = part->offset + info->start[0];
  308. addr_last = addr_first + part->size - 1;
  309. printf ("Erase Flash Parition %s, "
  310. "bank %d, 0x%08lx - 0x%08lx ",
  311. argv[1], bank, addr_first,
  312. addr_last);
  313. rcode = flash_sect_erase(addr_first, addr_last);
  314. return rcode;
  315. }
  316. printf("cannot erase, not a NOR device\n");
  317. return 1;
  318. }
  319. }
  320. #endif
  321. if (argc != 3) {
  322. printf ("Usage:\n%s\n", cmdtp->usage);
  323. return 1;
  324. }
  325. if (strcmp(argv[1], "bank") == 0) {
  326. bank = simple_strtoul(argv[2], NULL, 16);
  327. if ((bank < 1) || (bank > CFG_MAX_FLASH_BANKS)) {
  328. printf ("Only FLASH Banks # 1 ... # %d supported\n",
  329. CFG_MAX_FLASH_BANKS);
  330. return 1;
  331. }
  332. printf ("Erase Flash Bank # %ld ", bank);
  333. info = &flash_info[bank-1];
  334. rcode = flash_erase (info, 0, info->sector_count-1);
  335. return rcode;
  336. }
  337. if (addr_spec(argv[1], argv[2], &addr_first, &addr_last) < 0){
  338. printf ("Bad address format\n");
  339. return 1;
  340. }
  341. if (addr_first >= addr_last) {
  342. printf ("Usage:\n%s\n", cmdtp->usage);
  343. return 1;
  344. }
  345. rcode = flash_sect_erase(addr_first, addr_last);
  346. return rcode;
  347. }
  348. int flash_sect_erase (ulong addr_first, ulong addr_last)
  349. {
  350. flash_info_t *info;
  351. ulong bank;
  352. int s_first[CFG_MAX_FLASH_BANKS], s_last[CFG_MAX_FLASH_BANKS];
  353. int erased = 0;
  354. int planned;
  355. int rcode = 0;
  356. rcode = flash_fill_sect_ranges (addr_first, addr_last,
  357. s_first, s_last, &planned );
  358. if (planned && (rcode == 0)) {
  359. for (bank=0,info=&flash_info[0];
  360. (bank < CFG_MAX_FLASH_BANKS) && (rcode == 0);
  361. ++bank, ++info) {
  362. if (s_first[bank]>=0) {
  363. erased += s_last[bank] - s_first[bank] + 1;
  364. debug ("Erase Flash from 0x%08lx to 0x%08lx "
  365. "in Bank # %ld ",
  366. info->start[s_first[bank]],
  367. (s_last[bank] == info->sector_count) ?
  368. info->start[0] + info->size - 1:
  369. info->start[s_last[bank]+1] - 1,
  370. bank+1);
  371. rcode = flash_erase (info, s_first[bank], s_last[bank]);
  372. }
  373. }
  374. printf ("Erased %d sectors\n", erased);
  375. } else if (rcode == 0) {
  376. puts ("Error: start and/or end address"
  377. " not on sector boundary\n");
  378. rcode = 1;
  379. }
  380. return rcode;
  381. }
  382. int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  383. {
  384. flash_info_t *info;
  385. ulong bank, addr_first, addr_last;
  386. int i, p, n, sect_first, sect_last;
  387. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  388. struct mtd_device *dev;
  389. struct part_info *part;
  390. u8 dev_type, dev_num, pnum;
  391. #endif
  392. int rcode = 0;
  393. #ifdef CONFIG_HAS_DATAFLASH
  394. int status;
  395. #endif
  396. if (argc < 3) {
  397. printf ("Usage:\n%s\n", cmdtp->usage);
  398. return 1;
  399. }
  400. if (strcmp(argv[1], "off") == 0) {
  401. p = 0;
  402. } else if (strcmp(argv[1], "on") == 0) {
  403. p = 1;
  404. } else {
  405. printf ("Usage:\n%s\n", cmdtp->usage);
  406. return 1;
  407. }
  408. #ifdef CONFIG_HAS_DATAFLASH
  409. if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) {
  410. addr_first = simple_strtoul(argv[2], NULL, 16);
  411. addr_last = simple_strtoul(argv[3], NULL, 16);
  412. if (addr_dataflash(addr_first) && addr_dataflash(addr_last)) {
  413. status = dataflash_real_protect(p,addr_first,addr_last);
  414. if (status < 0){
  415. puts ("Bad DataFlash sector specification\n");
  416. return 1;
  417. }
  418. printf("%sProtect %d DataFlash Sectors\n",
  419. p ? "" : "Un-", status);
  420. return 0;
  421. }
  422. }
  423. #endif
  424. if (strcmp(argv[2], "all") == 0) {
  425. for (bank=1; bank<=CFG_MAX_FLASH_BANKS; ++bank) {
  426. info = &flash_info[bank-1];
  427. if (info->flash_id == FLASH_UNKNOWN) {
  428. continue;
  429. }
  430. printf ("%sProtect Flash Bank # %ld\n",
  431. p ? "" : "Un-", bank);
  432. for (i=0; i<info->sector_count; ++i) {
  433. #if defined(CFG_FLASH_PROTECTION)
  434. if (flash_real_protect(info, i, p))
  435. rcode = 1;
  436. putc ('.');
  437. #else
  438. info->protect[i] = p;
  439. #endif /* CFG_FLASH_PROTECTION */
  440. }
  441. }
  442. #if defined(CFG_FLASH_PROTECTION)
  443. if (!rcode) puts (" done\n");
  444. #endif /* CFG_FLASH_PROTECTION */
  445. return rcode;
  446. }
  447. if ((n = abbrev_spec(argv[2], &info, &sect_first, &sect_last)) != 0) {
  448. if (n < 0) {
  449. puts ("Bad sector specification\n");
  450. return 1;
  451. }
  452. printf("%sProtect Flash Sectors %d-%d in Bank # %d\n",
  453. p ? "" : "Un-", sect_first, sect_last,
  454. (info-flash_info)+1);
  455. for (i = sect_first; i <= sect_last; i++) {
  456. #if defined(CFG_FLASH_PROTECTION)
  457. if (flash_real_protect(info, i, p))
  458. rcode = 1;
  459. putc ('.');
  460. #else
  461. info->protect[i] = p;
  462. #endif /* CFG_FLASH_PROTECTION */
  463. }
  464. #if defined(CFG_FLASH_PROTECTION)
  465. if (!rcode) puts (" done\n");
  466. #endif /* CFG_FLASH_PROTECTION */
  467. return rcode;
  468. }
  469. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  470. /* protect on/off <part-id> */
  471. if ((argc == 3) && (id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
  472. mtdparts_init();
  473. if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) {
  474. if (dev->id->type == MTD_DEV_TYPE_NOR) {
  475. bank = dev->id->num;
  476. info = &flash_info[bank];
  477. addr_first = part->offset + info->start[0];
  478. addr_last = addr_first + part->size - 1;
  479. printf ("%sProtect Flash Parition %s, "
  480. "bank %d, 0x%08lx - 0x%08lx\n",
  481. p ? "" : "Un", argv[1],
  482. bank, addr_first, addr_last);
  483. rcode = flash_sect_protect (p, addr_first, addr_last);
  484. return rcode;
  485. }
  486. printf("cannot %sprotect, not a NOR device\n",
  487. p ? "" : "un");
  488. return 1;
  489. }
  490. }
  491. #endif
  492. if (argc != 4) {
  493. printf ("Usage:\n%s\n", cmdtp->usage);
  494. return 1;
  495. }
  496. if (strcmp(argv[2], "bank") == 0) {
  497. bank = simple_strtoul(argv[3], NULL, 16);
  498. if ((bank < 1) || (bank > CFG_MAX_FLASH_BANKS)) {
  499. printf ("Only FLASH Banks # 1 ... # %d supported\n",
  500. CFG_MAX_FLASH_BANKS);
  501. return 1;
  502. }
  503. printf ("%sProtect Flash Bank # %ld\n",
  504. p ? "" : "Un-", bank);
  505. info = &flash_info[bank-1];
  506. if (info->flash_id == FLASH_UNKNOWN) {
  507. puts ("missing or unknown FLASH type\n");
  508. return 1;
  509. }
  510. for (i=0; i<info->sector_count; ++i) {
  511. #if defined(CFG_FLASH_PROTECTION)
  512. if (flash_real_protect(info, i, p))
  513. rcode = 1;
  514. putc ('.');
  515. #else
  516. info->protect[i] = p;
  517. #endif /* CFG_FLASH_PROTECTION */
  518. }
  519. #if defined(CFG_FLASH_PROTECTION)
  520. if (!rcode) puts (" done\n");
  521. #endif /* CFG_FLASH_PROTECTION */
  522. return rcode;
  523. }
  524. if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){
  525. printf("Bad address format\n");
  526. return 1;
  527. }
  528. if (addr_first >= addr_last) {
  529. printf ("Usage:\n%s\n", cmdtp->usage);
  530. return 1;
  531. }
  532. rcode = flash_sect_protect (p, addr_first, addr_last);
  533. return rcode;
  534. }
  535. int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
  536. {
  537. flash_info_t *info;
  538. ulong bank;
  539. int s_first[CFG_MAX_FLASH_BANKS], s_last[CFG_MAX_FLASH_BANKS];
  540. int protected, i;
  541. int planned;
  542. int rcode;
  543. rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned );
  544. protected = 0;
  545. if (planned && (rcode == 0)) {
  546. for (bank=0,info=&flash_info[0]; bank < CFG_MAX_FLASH_BANKS; ++bank, ++info) {
  547. if (info->flash_id == FLASH_UNKNOWN) {
  548. continue;
  549. }
  550. if (s_first[bank]>=0 && s_first[bank]<=s_last[bank]) {
  551. debug ("%sProtecting sectors %d..%d in bank %ld\n",
  552. p ? "" : "Un-",
  553. s_first[bank], s_last[bank], bank+1);
  554. protected += s_last[bank] - s_first[bank] + 1;
  555. for (i=s_first[bank]; i<=s_last[bank]; ++i) {
  556. #if defined(CFG_FLASH_PROTECTION)
  557. if (flash_real_protect(info, i, p))
  558. rcode = 1;
  559. putc ('.');
  560. #else
  561. info->protect[i] = p;
  562. #endif /* CFG_FLASH_PROTECTION */
  563. }
  564. }
  565. #if defined(CFG_FLASH_PROTECTION)
  566. if (!rcode) putc ('\n');
  567. #endif /* CFG_FLASH_PROTECTION */
  568. }
  569. printf ("%sProtected %d sectors\n",
  570. p ? "" : "Un-", protected);
  571. } else if (rcode == 0) {
  572. puts ("Error: start and/or end address"
  573. " not on sector boundary\n");
  574. rcode = 1;
  575. }
  576. return rcode;
  577. }
  578. /**************************************************/
  579. U_BOOT_CMD(
  580. flinfo, 2, 1, do_flinfo,
  581. "flinfo - print FLASH memory information\n",
  582. "\n - print information for all FLASH memory banks\n"
  583. "flinfo N\n - print information for FLASH memory bank # N\n"
  584. );
  585. U_BOOT_CMD(
  586. erase, 3, 1, do_flerase,
  587. "erase - erase FLASH memory\n",
  588. "start end\n"
  589. " - erase FLASH from addr 'start' to addr 'end'\n"
  590. "erase start +len\n"
  591. " - erase FLASH from addr 'start' to the end of sect "
  592. "w/addr 'start'+'len'-1\n"
  593. "erase N:SF[-SL]\n - erase sectors SF-SL in FLASH bank # N\n"
  594. "erase bank N\n - erase FLASH bank # N\n"
  595. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  596. "erase <part-id>\n - erase partition\n"
  597. #endif
  598. "erase all\n - erase all FLASH banks\n"
  599. );
  600. U_BOOT_CMD(
  601. protect, 4, 1, do_protect,
  602. "protect - enable or disable FLASH write protection\n",
  603. "on start end\n"
  604. " - protect FLASH from addr 'start' to addr 'end'\n"
  605. "protect on start +len\n"
  606. " - protect FLASH from addr 'start' to end of sect "
  607. "w/addr 'start'+'len'-1\n"
  608. "protect on N:SF[-SL]\n"
  609. " - protect sectors SF-SL in FLASH bank # N\n"
  610. "protect on bank N\n - protect FLASH bank # N\n"
  611. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  612. "protect on <part-id>\n - protect partition\n"
  613. #endif
  614. "protect on all\n - protect all FLASH banks\n"
  615. "protect off start end\n"
  616. " - make FLASH from addr 'start' to addr 'end' writable\n"
  617. "protect off start +len\n"
  618. " - make FLASH from addr 'start' to end of sect "
  619. "w/addr 'start'+'len'-1 wrtable\n"
  620. "protect off N:SF[-SL]\n"
  621. " - make sectors SF-SL writable in FLASH bank # N\n"
  622. "protect off bank N\n - make FLASH bank # N writable\n"
  623. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
  624. "protect off <part-id>\n - make partition writable\n"
  625. #endif
  626. "protect off all\n - make all FLASH banks writable\n"
  627. );
  628. #endif /* CFG_CMD_FLASH */