flash.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. p = strchr(str, ':');
  50. if (!p)
  51. return 0;
  52. *p++ = '\0';
  53. bank = dectoul(str, &ep);
  54. if (ep == str || *ep != '\0' ||
  55. bank < 1 || bank > CFI_FLASH_BANKS)
  56. return -1;
  57. fp = &flash_info[bank - 1];
  58. if (fp->flash_id == FLASH_UNKNOWN)
  59. return -1;
  60. str = p;
  61. p = strchr(str, '-');
  62. if (p)
  63. *p++ = '\0';
  64. first = dectoul(str, &ep);
  65. if (ep == str || *ep != '\0' || first >= fp->sector_count)
  66. return -1;
  67. if (p) {
  68. last = dectoul(p, &ep);
  69. if (ep == p || *ep != '\0' ||
  70. last < first || last >= fp->sector_count)
  71. return -1;
  72. } else {
  73. last = first;
  74. }
  75. *pinfo = fp;
  76. *psf = first;
  77. *psl = last;
  78. return 1;
  79. }
  80. /*
  81. * Take *addr in Flash and adjust it to fall on the end of its sector
  82. */
  83. int flash_sect_roundb(ulong *addr)
  84. {
  85. flash_info_t *info;
  86. ulong bank, sector_end_addr;
  87. char found;
  88. int i;
  89. /* find the end addr of the sector where the *addr is */
  90. found = 0;
  91. for (bank = 0; bank < CFI_FLASH_BANKS && !found; ++bank) {
  92. info = &flash_info[bank];
  93. for (i = 0; i < info->sector_count && !found; ++i) {
  94. /* get the end address of the sector */
  95. if (i == info->sector_count - 1) {
  96. sector_end_addr = info->start[0] +
  97. info->size - 1;
  98. } else {
  99. sector_end_addr = info->start[i + 1] - 1;
  100. }
  101. if (*addr <= sector_end_addr && *addr >= info->start[i]) {
  102. found = 1;
  103. /* adjust *addr if necessary */
  104. if (*addr < sector_end_addr)
  105. *addr = sector_end_addr;
  106. } /* sector */
  107. } /* bank */
  108. }
  109. if (!found) {
  110. /* error, address not in flash */
  111. printf("Error: end address (0x%08lx) not in flash!\n", *addr);
  112. return 1;
  113. }
  114. return 0;
  115. }
  116. /*
  117. * This function computes the start and end addresses for both
  118. * erase and protect commands. The range of the addresses on which
  119. * either of the commands is to operate can be given in two forms:
  120. * 1. <cmd> start end - operate on <'start', 'end')
  121. * 2. <cmd> start +length - operate on <'start', start + length)
  122. * If the second form is used and the end address doesn't fall on the
  123. * sector boundary, than it will be adjusted to the next sector boundary.
  124. * If it isn't in the flash, the function will fail (return -1).
  125. * Input:
  126. * arg1, arg2: address specification (i.e. both command arguments)
  127. * Output:
  128. * addr_first, addr_last: computed address range
  129. * Return:
  130. * 1: success
  131. * -1: failure (bad format, bad address).
  132. */
  133. static int
  134. addr_spec(char *arg1, char *arg2, ulong *addr_first, ulong *addr_last)
  135. {
  136. char *ep;
  137. char len_used; /* indicates if the "start +length" form used */
  138. *addr_first = hextoul(arg1, &ep);
  139. if (ep == arg1 || *ep != '\0')
  140. return -1;
  141. len_used = 0;
  142. if (arg2 && *arg2 == '+') {
  143. len_used = 1;
  144. ++arg2;
  145. }
  146. *addr_last = hextoul(arg2, &ep);
  147. if (ep == arg2 || *ep != '\0')
  148. return -1;
  149. if (len_used) {
  150. /*
  151. * *addr_last has the length, compute correct *addr_last
  152. * XXX watch out for the integer overflow! Right now it is
  153. * checked for in both the callers.
  154. */
  155. *addr_last = *addr_first + *addr_last - 1;
  156. /*
  157. * It may happen that *addr_last doesn't fall on the sector
  158. * boundary. We want to round such an address to the next
  159. * sector boundary, so that the commands don't fail later on.
  160. */
  161. if (flash_sect_roundb(addr_last) > 0)
  162. return -1;
  163. } /* "start +length" from used */
  164. return 1;
  165. }
  166. static int
  167. flash_fill_sect_ranges(ulong addr_first, ulong addr_last,
  168. int *s_first, int *s_last,
  169. int *s_count)
  170. {
  171. flash_info_t *info;
  172. ulong bank;
  173. int rcode = 0;
  174. *s_count = 0;
  175. for (bank = 0; bank < CFI_FLASH_BANKS; ++bank) {
  176. s_first[bank] = -1; /* first sector to erase */
  177. s_last[bank] = -1; /* last sector to erase */
  178. }
  179. for (bank = 0, info = &flash_info[0];
  180. (bank < CFI_FLASH_BANKS) && (addr_first <= addr_last);
  181. ++bank, ++info) {
  182. ulong b_end;
  183. int sect;
  184. short s_end;
  185. if (info->flash_id == FLASH_UNKNOWN)
  186. continue;
  187. b_end = info->start[0] + info->size - 1; /* bank end addr */
  188. s_end = info->sector_count - 1; /* last sector */
  189. for (sect = 0; sect < info->sector_count; ++sect) {
  190. ulong end; /* last address in current sect */
  191. end = (sect == s_end) ? b_end : info->start[sect + 1] - 1;
  192. if (addr_first > end)
  193. continue;
  194. if (addr_last < info->start[sect])
  195. continue;
  196. if (addr_first == info->start[sect])
  197. s_first[bank] = sect;
  198. if (addr_last == end)
  199. s_last[bank] = sect;
  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 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 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(struct cmd_tbl *cmdtp, int flag, int argc,
  234. 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 < CFI_FLASH_BANKS; ++bank) {
  242. printf("\nBank # %ld: ", bank + 1);
  243. flash_print_info(&flash_info[bank]);
  244. }
  245. return 0;
  246. }
  247. bank = hextoul(argv[1], NULL);
  248. if (bank < 1 || bank > CFI_FLASH_BANKS) {
  249. printf("Only FLASH Banks # 1 ... # %d supported\n",
  250. CFI_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(struct cmd_tbl *cmdtp, int flag, int argc,
  259. char *const argv[])
  260. {
  261. #ifdef CONFIG_MTD_NOR_FLASH
  262. flash_info_t *info = NULL;
  263. ulong bank, addr_first, addr_last;
  264. int n, sect_first = 0, sect_last = 0;
  265. #if defined(CONFIG_CMD_MTDPARTS)
  266. struct mtd_device *dev;
  267. struct part_info *part;
  268. u8 dev_type, dev_num, pnum;
  269. #endif
  270. int rcode = 0;
  271. if (argc < 2)
  272. return CMD_RET_USAGE;
  273. if (strcmp(argv[1], "all") == 0) {
  274. for (bank = 1; bank <= CFI_FLASH_BANKS; ++bank) {
  275. printf("Erase Flash Bank # %ld ", bank);
  276. info = &flash_info[bank - 1];
  277. rcode = flash_erase(info, 0, info->sector_count - 1);
  278. }
  279. return rcode;
  280. }
  281. n = abbrev_spec(argv[1], &info, &sect_first, &sect_last);
  282. if (n) {
  283. if (n < 0) {
  284. puts("Bad sector specification\n");
  285. return 1;
  286. }
  287. printf("Erase Flash Sectors %d-%d in Bank # %zu ",
  288. sect_first, sect_last, (info - flash_info) + 1);
  289. rcode = flash_erase(info, sect_first, sect_last);
  290. return rcode;
  291. }
  292. #if defined(CONFIG_CMD_MTDPARTS)
  293. /* erase <part-id> - erase partition */
  294. if (argc == 2 && mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0) {
  295. mtdparts_init();
  296. if (find_dev_and_part(argv[1], &dev, &pnum, &part) == 0) {
  297. if (dev->id->type == MTD_DEV_TYPE_NOR) {
  298. bank = dev->id->num;
  299. info = &flash_info[bank];
  300. addr_first = part->offset + info->start[0];
  301. addr_last = addr_first + part->size - 1;
  302. printf("Erase Flash Partition %s, bank %ld, 0x%08lx - 0x%08lx ",
  303. argv[1], bank, addr_first,
  304. addr_last);
  305. rcode = flash_sect_erase(addr_first, addr_last);
  306. return rcode;
  307. }
  308. printf("cannot erase, not a NOR device\n");
  309. return 1;
  310. }
  311. }
  312. #endif
  313. if (argc != 3)
  314. return CMD_RET_USAGE;
  315. if (strcmp(argv[1], "bank") == 0) {
  316. bank = hextoul(argv[2], NULL);
  317. if (bank < 1 || bank > CFI_FLASH_BANKS) {
  318. printf("Only FLASH Banks # 1 ... # %d supported\n",
  319. CFI_FLASH_BANKS);
  320. return 1;
  321. }
  322. printf("Erase Flash Bank # %ld ", bank);
  323. info = &flash_info[bank - 1];
  324. rcode = flash_erase(info, 0, info->sector_count - 1);
  325. return rcode;
  326. }
  327. if (addr_spec(argv[1], argv[2], &addr_first, &addr_last) < 0) {
  328. printf("Bad address format\n");
  329. return 1;
  330. }
  331. if (addr_first >= addr_last)
  332. return CMD_RET_USAGE;
  333. rcode = flash_sect_erase(addr_first, addr_last);
  334. return rcode;
  335. #else
  336. return 0;
  337. #endif /* CONFIG_MTD_NOR_FLASH */
  338. }
  339. #ifdef CONFIG_MTD_NOR_FLASH
  340. int flash_sect_erase(ulong addr_first, ulong addr_last)
  341. {
  342. flash_info_t *info;
  343. ulong bank;
  344. int s_first[CFI_FLASH_BANKS], s_last[CFI_FLASH_BANKS];
  345. int erased = 0;
  346. int planned;
  347. int rcode = 0;
  348. rcode = flash_fill_sect_ranges(addr_first, addr_last, s_first, s_last, &planned);
  349. if (planned && rcode == 0) {
  350. for (bank = 0, info = &flash_info[0];
  351. bank < CFI_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 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 not on sector boundary\n");
  369. rcode = 1;
  370. }
  371. return rcode;
  372. }
  373. #endif /* CONFIG_MTD_NOR_FLASH */
  374. static int do_protect(struct cmd_tbl *cmdtp, int flag, int argc,
  375. 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 <= CFI_FLASH_BANKS; ++bank) {
  405. info = &flash_info[bank - 1];
  406. if (info->flash_id == FLASH_UNKNOWN)
  407. continue;
  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)
  421. puts(" done\n");
  422. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  423. }
  424. return rcode;
  425. }
  426. n = abbrev_spec(argv[2], &info, &sect_first, &sect_last);
  427. if (n) {
  428. if (n < 0) {
  429. puts("Bad sector specification\n");
  430. return 1;
  431. }
  432. printf("%sProtect Flash Sectors %d-%d in Bank # %zu\n",
  433. p ? "" : "Un-", sect_first, sect_last,
  434. (info - flash_info) + 1);
  435. for (i = sect_first; i <= sect_last; i++) {
  436. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  437. if (flash_real_protect(info, i, p))
  438. rcode = 1;
  439. putc('.');
  440. #else
  441. info->protect[i] = p;
  442. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  443. }
  444. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  445. if (!rcode)
  446. puts(" done\n");
  447. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  448. return rcode;
  449. }
  450. #if defined(CONFIG_CMD_MTDPARTS)
  451. /* protect on/off <part-id> */
  452. if (argc == 3 && mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0) {
  453. mtdparts_init();
  454. if (find_dev_and_part(argv[2], &dev, &pnum, &part) == 0) {
  455. if (dev->id->type == MTD_DEV_TYPE_NOR) {
  456. bank = dev->id->num;
  457. info = &flash_info[bank];
  458. addr_first = part->offset + info->start[0];
  459. addr_last = addr_first + part->size - 1;
  460. printf("%sProtect Flash Partition %s, "
  461. "bank %ld, 0x%08lx - 0x%08lx\n",
  462. p ? "" : "Un", argv[1],
  463. bank, addr_first, addr_last);
  464. rcode = flash_sect_protect(p, addr_first,
  465. addr_last);
  466. return rcode;
  467. }
  468. printf("cannot %sprotect, not a NOR device\n",
  469. p ? "" : "un");
  470. return 1;
  471. }
  472. }
  473. #endif
  474. if (argc != 4)
  475. return CMD_RET_USAGE;
  476. if (strcmp(argv[2], "bank") == 0) {
  477. bank = hextoul(argv[3], NULL);
  478. if (bank < 1 || bank > CFI_FLASH_BANKS) {
  479. printf("Only FLASH Banks # 1 ... # %d supported\n",
  480. CFI_FLASH_BANKS);
  481. return 1;
  482. }
  483. printf("%sProtect Flash Bank # %ld\n",
  484. p ? "" : "Un-", bank);
  485. info = &flash_info[bank - 1];
  486. if (info->flash_id == FLASH_UNKNOWN) {
  487. puts("missing or unknown FLASH type\n");
  488. return 1;
  489. }
  490. for (i = 0; i < info->sector_count; ++i) {
  491. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  492. if (flash_real_protect(info, i, p))
  493. rcode = 1;
  494. putc('.');
  495. #else
  496. info->protect[i] = p;
  497. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  498. }
  499. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  500. if (!rcode)
  501. puts(" done\n");
  502. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  503. return rcode;
  504. }
  505. if (addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0) {
  506. printf("Bad address format\n");
  507. return 1;
  508. }
  509. if (addr_first >= addr_last)
  510. return CMD_RET_USAGE;
  511. rcode = flash_sect_protect(p, addr_first, addr_last);
  512. #endif /* CONFIG_MTD_NOR_FLASH */
  513. return rcode;
  514. }
  515. #ifdef CONFIG_MTD_NOR_FLASH
  516. int flash_sect_protect(int p, ulong addr_first, ulong addr_last)
  517. {
  518. flash_info_t *info;
  519. ulong bank;
  520. int s_first[CFI_FLASH_BANKS], s_last[CFI_FLASH_BANKS];
  521. int protected, i;
  522. int planned;
  523. int rcode;
  524. rcode = flash_fill_sect_ranges(addr_first, addr_last, s_first, s_last, &planned);
  525. protected = 0;
  526. if (planned && rcode == 0) {
  527. for (bank = 0, info = &flash_info[0];
  528. bank < CFI_FLASH_BANKS; ++bank, ++info) {
  529. if (info->flash_id == FLASH_UNKNOWN)
  530. continue;
  531. if (s_first[bank] >= 0 && s_first[bank] <= s_last[bank]) {
  532. debug("%sProtecting sectors %d..%d in bank %ld\n",
  533. p ? "" : "Un-", s_first[bank],
  534. s_last[bank], bank + 1);
  535. protected += s_last[bank] - s_first[bank] + 1;
  536. for (i = s_first[bank]; i <= s_last[bank]; ++i) {
  537. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  538. if (flash_real_protect(info, i, p))
  539. rcode = 1;
  540. putc('.');
  541. #else
  542. info->protect[i] = p;
  543. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  544. }
  545. }
  546. }
  547. #if defined(CONFIG_SYS_FLASH_PROTECTION)
  548. puts(" done\n");
  549. #endif /* CONFIG_SYS_FLASH_PROTECTION */
  550. printf("%sProtected %d sectors\n",
  551. p ? "" : "Un-", protected);
  552. } else if (rcode == 0) {
  553. puts("Error: start and/or end address not on sector boundary\n");
  554. rcode = 1;
  555. }
  556. return rcode;
  557. }
  558. #endif /* CONFIG_MTD_NOR_FLASH */
  559. /**************************************************/
  560. #if defined(CONFIG_CMD_MTDPARTS)
  561. # define TMP_ERASE "erase <part-id>\n - erase partition\n"
  562. # define TMP_PROT_ON "protect on <part-id>\n - protect partition\n"
  563. # define TMP_PROT_OFF "protect off <part-id>\n - make partition writable\n"
  564. #else
  565. # define TMP_ERASE /* empty */
  566. # define TMP_PROT_ON /* empty */
  567. # define TMP_PROT_OFF /* empty */
  568. #endif
  569. U_BOOT_CMD(
  570. flinfo, 2, 1, do_flinfo,
  571. "print FLASH memory information",
  572. "\n - print information for all FLASH memory banks\n"
  573. "flinfo N\n - print information for FLASH memory bank # N"
  574. );
  575. U_BOOT_CMD(
  576. erase, 3, 0, do_flerase,
  577. "erase FLASH memory",
  578. "start end\n"
  579. " - erase FLASH from addr 'start' to addr 'end'\n"
  580. "erase start +len\n"
  581. " - erase FLASH from addr 'start' to the end of sect w/addr 'start'+'len'-1\n"
  582. "erase N:SF[-SL]\n - erase sectors SF-SL in FLASH bank # N\n"
  583. "erase bank N\n - erase FLASH bank # N\n"
  584. TMP_ERASE
  585. "erase all\n - erase all FLASH banks"
  586. );
  587. U_BOOT_CMD(
  588. protect, 4, 0, do_protect,
  589. "enable or disable FLASH write protection",
  590. "on start end\n"
  591. " - protect FLASH from addr 'start' to addr 'end'\n"
  592. "protect on start +len\n"
  593. " - protect FLASH from addr 'start' to end of sect 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 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