flash.c 18 KB

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