flash.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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], s_last[bank]);
  362. }
  363. }
  364. if (rcode == 0)
  365. printf("Erased %d sectors\n", erased);
  366. } else if (rcode == 0) {
  367. puts ("Error: start and/or end address"
  368. " not on sector boundary\n");
  369. rcode = 1;
  370. }
  371. return rcode;
  372. }
  373. #endif /* CONFIG_MTD_NOR_FLASH */
  374. static int do_protect(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  375. {
  376. int rcode = 0;
  377. #ifdef CONFIG_MTD_NOR_FLASH
  378. flash_info_t *info = NULL;
  379. ulong bank;
  380. int i, n, sect_first = 0, sect_last = 0;
  381. #if defined(CONFIG_CMD_MTDPARTS)
  382. struct mtd_device *dev;
  383. struct part_info *part;
  384. u8 dev_type, dev_num, pnum;
  385. #endif
  386. #endif /* CONFIG_MTD_NOR_FLASH */
  387. #if defined(CONFIG_MTD_NOR_FLASH)
  388. int p;
  389. ulong addr_first, addr_last;
  390. #endif
  391. if (argc < 3)
  392. return CMD_RET_USAGE;
  393. #if defined(CONFIG_MTD_NOR_FLASH)
  394. if (strcmp(argv[1], "off") == 0)
  395. p = 0;
  396. else if (strcmp(argv[1], "on") == 0)
  397. p = 1;
  398. else
  399. return CMD_RET_USAGE;
  400. #endif
  401. #ifdef CONFIG_MTD_NOR_FLASH
  402. if (strcmp(argv[2], "all") == 0) {
  403. for (bank=1; bank<=CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
  404. info = &flash_info[bank-1];
  405. if (info->flash_id == FLASH_UNKNOWN) {
  406. continue;
  407. }
  408. printf ("%sProtect Flash Bank # %ld\n",
  409. p ? "" : "Un-", bank);
  410. for (i=0; i<info->sector_count; ++i) {
  411. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  412. if (flash_real_protect(info, i, p))
  413. rcode = 1;
  414. putc ('.');
  415. #else
  416. info->protect[i] = p;
  417. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  418. }
  419. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  420. if (!rcode) puts (" done\n");
  421. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  422. }
  423. return rcode;
  424. }
  425. if ((n = abbrev_spec(argv[2], &info, &sect_first, &sect_last)) != 0) {
  426. if (n < 0) {
  427. puts ("Bad sector specification\n");
  428. return 1;
  429. }
  430. printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n",
  431. p ? "" : "Un-", sect_first, sect_last,
  432. (info-flash_info)+1);
  433. for (i = sect_first; i <= sect_last; i++) {
  434. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  435. if (flash_real_protect(info, i, p))
  436. rcode = 1;
  437. putc ('.');
  438. #else
  439. info->protect[i] = p;
  440. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  441. }
  442. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  443. if (!rcode) puts (" done\n");
  444. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  445. return rcode;
  446. }
  447. #if defined(CONFIG_CMD_MTDPARTS)
  448. /* protect on/off <part-id> */
  449. if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
  450. mtdparts_init();
  451. if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) {
  452. if (dev->id->type == MTD_DEV_TYPE_NOR) {
  453. bank = dev->id->num;
  454. info = &flash_info[bank];
  455. addr_first = part->offset + info->start[0];
  456. addr_last = addr_first + part->size - 1;
  457. printf ("%sProtect Flash Partition %s, "
  458. "bank %ld, 0x%08lx - 0x%08lx\n",
  459. p ? "" : "Un", argv[1],
  460. bank, addr_first, addr_last);
  461. rcode = flash_sect_protect (p, addr_first, addr_last);
  462. return rcode;
  463. }
  464. printf("cannot %sprotect, not a NOR device\n",
  465. p ? "" : "un");
  466. return 1;
  467. }
  468. }
  469. #endif
  470. if (argc != 4)
  471. return CMD_RET_USAGE;
  472. if (strcmp(argv[2], "bank") == 0) {
  473. bank = simple_strtoul(argv[3], NULL, 16);
  474. if ((bank < 1) || (bank > CONFIG_SYS_MAX_FLASH_BANKS)) {
  475. printf ("Only FLASH Banks # 1 ... # %d supported\n",
  476. CONFIG_SYS_MAX_FLASH_BANKS);
  477. return 1;
  478. }
  479. printf ("%sProtect Flash Bank # %ld\n",
  480. p ? "" : "Un-", bank);
  481. info = &flash_info[bank-1];
  482. if (info->flash_id == FLASH_UNKNOWN) {
  483. puts ("missing or unknown FLASH type\n");
  484. return 1;
  485. }
  486. for (i=0; i<info->sector_count; ++i) {
  487. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  488. if (flash_real_protect(info, i, p))
  489. rcode = 1;
  490. putc ('.');
  491. #else
  492. info->protect[i] = p;
  493. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  494. }
  495. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  496. if (!rcode) puts (" done\n");
  497. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  498. return rcode;
  499. }
  500. if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){
  501. printf("Bad address format\n");
  502. return 1;
  503. }
  504. if (addr_first >= addr_last)
  505. return CMD_RET_USAGE;
  506. rcode = flash_sect_protect (p, addr_first, addr_last);
  507. #endif /* CONFIG_MTD_NOR_FLASH */
  508. return rcode;
  509. }
  510. #ifdef CONFIG_MTD_NOR_FLASH
  511. int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
  512. {
  513. flash_info_t *info;
  514. ulong bank;
  515. int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS];
  516. int protected, i;
  517. int planned;
  518. int rcode;
  519. rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned );
  520. protected = 0;
  521. if (planned && (rcode == 0)) {
  522. for (bank=0,info = &flash_info[0]; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) {
  523. if (info->flash_id == FLASH_UNKNOWN) {
  524. continue;
  525. }
  526. if (s_first[bank]>=0 && s_first[bank]<=s_last[bank]) {
  527. debug ("%sProtecting sectors %d..%d in bank %ld\n",
  528. p ? "" : "Un-",
  529. s_first[bank], s_last[bank], bank+1);
  530. protected += s_last[bank] - s_first[bank] + 1;
  531. for (i=s_first[bank]; i<=s_last[bank]; ++i) {
  532. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  533. if (flash_real_protect(info, i, p))
  534. rcode = 1;
  535. putc ('.');
  536. #else
  537. info->protect[i] = p;
  538. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  539. }
  540. }
  541. }
  542. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  543. puts (" done\n");
  544. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  545. printf ("%sProtected %d sectors\n",
  546. p ? "" : "Un-", protected);
  547. } else if (rcode == 0) {
  548. puts ("Error: start and/or end address"
  549. " not on sector boundary\n");
  550. rcode = 1;
  551. }
  552. return rcode;
  553. }
  554. #endif /* CONFIG_MTD_NOR_FLASH */
  555. /**************************************************/
  556. #if defined(CONFIG_CMD_MTDPARTS)
  557. # define TMP_ERASE "erase <part-id>\n - erase partition\n"
  558. # define TMP_PROT_ON "protect on <part-id>\n - protect partition\n"
  559. # define TMP_PROT_OFF "protect off <part-id>\n - make partition writable\n"
  560. #else
  561. # define TMP_ERASE /* empty */
  562. # define TMP_PROT_ON /* empty */
  563. # define TMP_PROT_OFF /* empty */
  564. #endif
  565. U_BOOT_CMD(
  566. flinfo, 2, 1, do_flinfo,
  567. "print FLASH memory information",
  568. "\n - print information for all FLASH memory banks\n"
  569. "flinfo N\n - print information for FLASH memory bank # N"
  570. );
  571. U_BOOT_CMD(
  572. erase, 3, 0, do_flerase,
  573. "erase FLASH memory",
  574. "start end\n"
  575. " - erase FLASH from addr 'start' to addr 'end'\n"
  576. "erase start +len\n"
  577. " - erase FLASH from addr 'start' to the end of sect "
  578. "w/addr 'start'+'len'-1\n"
  579. "erase N:SF[-SL]\n - erase sectors SF-SL in FLASH bank # N\n"
  580. "erase bank N\n - erase FLASH bank # N\n"
  581. TMP_ERASE
  582. "erase all\n - erase all FLASH banks"
  583. );
  584. U_BOOT_CMD(
  585. protect, 4, 0, do_protect,
  586. "enable or disable FLASH write protection",
  587. "on start end\n"
  588. " - protect FLASH from addr 'start' to addr 'end'\n"
  589. "protect on start +len\n"
  590. " - protect FLASH from addr 'start' to end of sect "
  591. "w/addr 'start'+'len'-1\n"
  592. "protect on N:SF[-SL]\n"
  593. " - protect sectors SF-SL in FLASH bank # N\n"
  594. "protect on bank N\n - protect FLASH bank # N\n"
  595. TMP_PROT_ON
  596. "protect on all\n - protect all FLASH banks\n"
  597. "protect off start end\n"
  598. " - make FLASH from addr 'start' to addr 'end' writable\n"
  599. "protect off start +len\n"
  600. " - make FLASH from addr 'start' to end of sect "
  601. "w/addr 'start'+'len'-1 wrtable\n"
  602. "protect off N:SF[-SL]\n"
  603. " - make sectors SF-SL writable in FLASH bank # N\n"
  604. "protect off bank N\n - make FLASH bank # N writable\n"
  605. TMP_PROT_OFF
  606. "protect off all\n - make all FLASH banks writable"
  607. );
  608. #undef TMP_ERASE
  609. #undef TMP_PROT_ON
  610. #undef TMP_PROT_OFF