flash.c 18 KB

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