flash.c 18 KB

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