flash.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Modified 4/5/2001
  25. * Wait for completion of each sector erase command issued
  26. * 4/5/2001
  27. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  28. */
  29. #include <common.h>
  30. #include <asm/ppc4xx.h>
  31. #include <asm/processor.h>
  32. flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  33. #undef DEBUG
  34. #ifdef DEBUG
  35. #define DEBUGF(x...) printf(x)
  36. #else
  37. #define DEBUGF(x...)
  38. #endif /* DEBUG */
  39. #define CONFIG_SYS_FLASH_CHAR_SIZE unsigned char
  40. #define CONFIG_SYS_FLASH_CHAR_ADDR0 (0x0aaa)
  41. #define CONFIG_SYS_FLASH_CHAR_ADDR1 (0x0555)
  42. /*-----------------------------------------------------------------------
  43. * Functions
  44. */
  45. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  46. static void flash_get_offsets(ulong base, flash_info_t * info);
  47. static int write_word(flash_info_t * info, ulong dest, ulong data);
  48. #ifdef FLASH_BASE1_PRELIM
  49. static int write_word_1(flash_info_t * info, ulong dest, ulong data);
  50. static int write_word_2(flash_info_t * info, ulong dest, ulong data);
  51. static int flash_erase_1(flash_info_t * info, int s_first, int s_last);
  52. static int flash_erase_2(flash_info_t * info, int s_first, int s_last);
  53. static ulong flash_get_size_1(vu_long * addr, flash_info_t * info);
  54. static ulong flash_get_size_2(vu_long * addr, flash_info_t * info);
  55. #endif
  56. unsigned long flash_init(void)
  57. {
  58. unsigned long size_b0, size_b1=0;
  59. int i;
  60. /* Init: no FLASHes known */
  61. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  62. flash_info[i].flash_id = FLASH_UNKNOWN;
  63. }
  64. /* Static FLASH Bank configuration here - FIXME XXX */
  65. size_b0 =
  66. flash_get_size((vu_long *) FLASH_BASE0_PRELIM, &flash_info[0]);
  67. if (flash_info[0].flash_id == FLASH_UNKNOWN) {
  68. printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
  69. size_b0, size_b0 << 20);
  70. }
  71. if (size_b0) {
  72. /* Setup offsets */
  73. flash_get_offsets(FLASH_BASE0_PRELIM, &flash_info[0]);
  74. /* Monitor protection ON by default */
  75. (void)flash_protect(FLAG_PROTECT_SET,
  76. CONFIG_SYS_MONITOR_BASE,
  77. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  78. &flash_info[0]);
  79. #ifdef CONFIG_ENV_IS_IN_FLASH
  80. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  81. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  82. &flash_info[0]);
  83. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  84. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  85. &flash_info[0]);
  86. #endif
  87. /* Also protect sector containing initial power-up instruction */
  88. /* (flash_protect() checks address range - other call ignored) */
  89. (void)flash_protect(FLAG_PROTECT_SET,
  90. 0xFFFFFFFC, 0xFFFFFFFF, &flash_info[0]);
  91. flash_info[0].size = size_b0;
  92. }
  93. #ifdef FLASH_BASE1_PRELIM
  94. size_b1 =
  95. flash_get_size((vu_long *) FLASH_BASE1_PRELIM, &flash_info[1])*2;
  96. if (flash_info[1].flash_id == FLASH_UNKNOWN) {
  97. printf("## Unknown FLASH on Bank 1 - Size = 0x%08lx = %ld MB\n",
  98. size_b1, size_b1 << 20);
  99. }
  100. if (size_b1) {
  101. /* Setup offsets */
  102. flash_get_offsets(FLASH_BASE1_PRELIM, &flash_info[1]);
  103. flash_info[1].size = size_b1;
  104. }
  105. #endif
  106. return (size_b0 + size_b1);
  107. }
  108. static void flash_get_offsets(ulong base, flash_info_t * info)
  109. {
  110. int i;
  111. /* set up sector start address table */
  112. if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
  113. (info->flash_id == FLASH_AM040)) {
  114. for (i = 0; i < info->sector_count; i++)
  115. info->start[i] = base + (i * 0x00010000);
  116. } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMLV128U) {
  117. for (i = 0; i < info->sector_count; i++) {
  118. info->start[i] = base + (i * 0x00010000*2);
  119. }
  120. } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_S29GL128N ) {
  121. for (i = 0; i < info->sector_count; i++) {
  122. info->start[i] = base + (i * 0x00020000*2);
  123. }
  124. } else {
  125. if (info->flash_id & FLASH_BTYPE) {
  126. /* set sector offsets for bottom boot block type */
  127. info->start[0] = base + 0x00000000;
  128. info->start[1] = base + 0x00004000;
  129. info->start[2] = base + 0x00006000;
  130. info->start[3] = base + 0x00008000;
  131. for (i = 4; i < info->sector_count; i++) {
  132. info->start[i] =
  133. base + (i * 0x00010000) - 0x00030000;
  134. }
  135. } else {
  136. /* set sector offsets for top boot block type */
  137. i = info->sector_count - 1;
  138. info->start[i--] = base + info->size - 0x00004000;
  139. info->start[i--] = base + info->size - 0x00006000;
  140. info->start[i--] = base + info->size - 0x00008000;
  141. for (; i >= 0; i--) {
  142. info->start[i] = base + i * 0x00010000;
  143. }
  144. }
  145. }
  146. }
  147. void flash_print_info(flash_info_t * info)
  148. {
  149. int i;
  150. int k;
  151. int size;
  152. int erased;
  153. volatile unsigned long *flash;
  154. if (info->flash_id == FLASH_UNKNOWN) {
  155. printf("missing or unknown FLASH type\n");
  156. return;
  157. }
  158. switch (info->flash_id & FLASH_VENDMASK) {
  159. case FLASH_MAN_AMD:
  160. printf("AMD ");
  161. break;
  162. case FLASH_MAN_STM:
  163. printf("STM ");
  164. break;
  165. case FLASH_MAN_FUJ:
  166. printf("FUJITSU ");
  167. break;
  168. case FLASH_MAN_SST:
  169. printf("SST ");
  170. break;
  171. default:
  172. printf("Unknown Vendor ");
  173. break;
  174. }
  175. switch (info->flash_id & FLASH_TYPEMASK) {
  176. case FLASH_AM040:
  177. printf("AM29F040 (512 Kbit, uniform sector size)\n");
  178. break;
  179. case FLASH_AM400B:
  180. printf("AM29LV400B (4 Mbit, bottom boot sect)\n");
  181. break;
  182. case FLASH_AM400T:
  183. printf("AM29LV400T (4 Mbit, top boot sector)\n");
  184. break;
  185. case FLASH_AM800B:
  186. printf("AM29LV800B (8 Mbit, bottom boot sect)\n");
  187. break;
  188. case FLASH_AM800T:
  189. printf("AM29LV800T (8 Mbit, top boot sector)\n");
  190. break;
  191. case FLASH_AMD016:
  192. printf("AM29F016D (16 Mbit, uniform sector size)\n");
  193. break;
  194. case FLASH_AM160B:
  195. printf("AM29LV160B (16 Mbit, bottom boot sect)\n");
  196. break;
  197. case FLASH_AM160T:
  198. printf("AM29LV160T (16 Mbit, top boot sector)\n");
  199. break;
  200. case FLASH_AM320B:
  201. printf("AM29LV320B (32 Mbit, bottom boot sect)\n");
  202. break;
  203. case FLASH_AM320T:
  204. printf("AM29LV320T (32 Mbit, top boot sector)\n");
  205. break;
  206. case FLASH_AM033C:
  207. printf("AM29LV033C (32 Mbit, top boot sector)\n");
  208. break;
  209. case FLASH_AMLV128U:
  210. printf("AM29LV128U (128 Mbit * 2, top boot sector)\n");
  211. break;
  212. case FLASH_SST800A:
  213. printf("SST39LF/VF800 (8 Mbit, uniform sector size)\n");
  214. break;
  215. case FLASH_SST160A:
  216. printf("SST39LF/VF160 (16 Mbit, uniform sector size)\n");
  217. break;
  218. case FLASH_STMW320DT:
  219. printf ("M29W320DT (32 M, top sector)\n");
  220. break;
  221. case FLASH_S29GL128N:
  222. printf ("S29GL128N (256 Mbit, uniform sector size)\n");
  223. break;
  224. default:
  225. printf("Unknown Chip Type\n");
  226. break;
  227. }
  228. printf(" Size: %ld KB in %d Sectors\n",
  229. info->size >> 10, info->sector_count);
  230. printf(" Sector Start Addresses:");
  231. for (i = 0; i < info->sector_count; ++i) {
  232. /*
  233. * Check if whole sector is erased
  234. */
  235. if (i != (info->sector_count - 1))
  236. size = info->start[i + 1] - info->start[i];
  237. else
  238. size = info->start[0] + info->size - info->start[i];
  239. erased = 1;
  240. flash = (volatile unsigned long *)info->start[i];
  241. size = size >> 2; /* divide by 4 for longword access */
  242. for (k = 0; k < size; k++) {
  243. if (*flash++ != 0xffffffff) {
  244. erased = 0;
  245. break;
  246. }
  247. }
  248. if ((i % 5) == 0)
  249. printf("\n ");
  250. printf(" %08lX%s%s",
  251. info->start[i],
  252. erased ? " E" : " ", info->protect[i] ? "RO " : " ");
  253. }
  254. printf("\n");
  255. return;
  256. }
  257. /*
  258. * The following code cannot be run from FLASH!
  259. */
  260. #ifdef FLASH_BASE1_PRELIM
  261. static ulong flash_get_size(vu_long * addr, flash_info_t * info)
  262. {
  263. if ((ulong)addr == FLASH_BASE1_PRELIM) {
  264. return flash_get_size_2(addr, info);
  265. } else {
  266. return flash_get_size_1(addr, info);
  267. }
  268. }
  269. static ulong flash_get_size_1(vu_long * addr, flash_info_t * info)
  270. #else
  271. static ulong flash_get_size(vu_long * addr, flash_info_t * info)
  272. #endif
  273. {
  274. short i;
  275. CONFIG_SYS_FLASH_WORD_SIZE value;
  276. ulong base = (ulong) addr;
  277. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *) addr;
  278. DEBUGF("FLASH ADDR: %08x\n", (unsigned)addr);
  279. /* Write auto select command: read Manufacturer ID */
  280. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  281. addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  282. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00900090;
  283. udelay(1000);
  284. value = addr2[0];
  285. DEBUGF("FLASH MANUFACT: %x\n", value);
  286. switch (value) {
  287. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_MANUFACT:
  288. info->flash_id = FLASH_MAN_AMD;
  289. break;
  290. case (CONFIG_SYS_FLASH_WORD_SIZE) FUJ_MANUFACT:
  291. info->flash_id = FLASH_MAN_FUJ;
  292. break;
  293. case (CONFIG_SYS_FLASH_WORD_SIZE) SST_MANUFACT:
  294. info->flash_id = FLASH_MAN_SST;
  295. break;
  296. case (CONFIG_SYS_FLASH_WORD_SIZE) STM_MANUFACT:
  297. info->flash_id = FLASH_MAN_STM;
  298. break;
  299. default:
  300. info->flash_id = FLASH_UNKNOWN;
  301. info->sector_count = 0;
  302. info->size = 0;
  303. return 0; /* no or unknown flash */
  304. }
  305. value = addr2[1]; /* device ID */
  306. DEBUGF("\nFLASH DEVICEID: %x\n", value);
  307. switch (value) {
  308. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV040B:
  309. info->flash_id += FLASH_AM040;
  310. info->sector_count = 8;
  311. info->size = 0x0080000; /* => 512 ko */
  312. break;
  313. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_F040B:
  314. info->flash_id += FLASH_AM040;
  315. info->sector_count = 8;
  316. info->size = 0x0080000; /* => 512 ko */
  317. break;
  318. case (CONFIG_SYS_FLASH_WORD_SIZE) STM_ID_M29W040B:
  319. info->flash_id += FLASH_AM040;
  320. info->sector_count = 8;
  321. info->size = 0x0080000; /* => 512 ko */
  322. break;
  323. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_F016D:
  324. info->flash_id += FLASH_AMD016;
  325. info->sector_count = 32;
  326. info->size = 0x00200000;
  327. break; /* => 2 MB */
  328. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV033C:
  329. info->flash_id += FLASH_AMDLV033C;
  330. info->sector_count = 64;
  331. info->size = 0x00400000;
  332. break; /* => 4 MB */
  333. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV400T:
  334. info->flash_id += FLASH_AM400T;
  335. info->sector_count = 11;
  336. info->size = 0x00080000;
  337. break; /* => 0.5 MB */
  338. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV400B:
  339. info->flash_id += FLASH_AM400B;
  340. info->sector_count = 11;
  341. info->size = 0x00080000;
  342. break; /* => 0.5 MB */
  343. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV800T:
  344. info->flash_id += FLASH_AM800T;
  345. info->sector_count = 19;
  346. info->size = 0x00100000;
  347. break; /* => 1 MB */
  348. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV800B:
  349. info->flash_id += FLASH_AM800B;
  350. info->sector_count = 19;
  351. info->size = 0x00100000;
  352. break; /* => 1 MB */
  353. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV160T:
  354. info->flash_id += FLASH_AM160T;
  355. info->sector_count = 35;
  356. info->size = 0x00200000;
  357. break; /* => 2 MB */
  358. case (CONFIG_SYS_FLASH_WORD_SIZE) AMD_ID_LV160B:
  359. info->flash_id += FLASH_AM160B;
  360. info->sector_count = 35;
  361. info->size = 0x00200000;
  362. break; /* => 2 MB */
  363. default:
  364. info->flash_id = FLASH_UNKNOWN;
  365. return 0; /* => no or unknown flash */
  366. }
  367. /* set up sector start address table */
  368. if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
  369. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM040) ||
  370. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMD016)) {
  371. for (i = 0; i < info->sector_count; i++)
  372. info->start[i] = base + (i * 0x00010000);
  373. }
  374. else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMLV128U) {
  375. for (i = 0; i < info->sector_count; i++)
  376. info->start[i] = base + (i * 0x00010000 * 2);
  377. } else {
  378. if (info->flash_id & FLASH_BTYPE) {
  379. /* set sector offsets for bottom boot block type */
  380. info->start[0] = base + 0x00000000;
  381. info->start[1] = base + 0x00004000;
  382. info->start[2] = base + 0x00006000;
  383. info->start[3] = base + 0x00008000;
  384. for (i = 4; i < info->sector_count; i++) {
  385. info->start[i] =
  386. base + (i * 0x00010000) - 0x00030000;
  387. }
  388. } else {
  389. /* set sector offsets for top boot block type */
  390. i = info->sector_count - 1;
  391. info->start[i--] = base + info->size - 0x00004000;
  392. info->start[i--] = base + info->size - 0x00006000;
  393. info->start[i--] = base + info->size - 0x00008000;
  394. for (; i >= 0; i--) {
  395. info->start[i] = base + i * 0x00010000;
  396. }
  397. }
  398. }
  399. /* check for protected sectors */
  400. for (i = 0; i < info->sector_count; i++) {
  401. /* read sector protection at sector address, (A7 .. A0) = 0x02 */
  402. /* D0 = 1 if protected */
  403. addr2 = (volatile CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[i]);
  404. /* For AMD29033C flash we need to resend the command of *
  405. * reading flash protection for upper 8 Mb of flash */
  406. if (i == 32) {
  407. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  408. addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  409. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x90909090;
  410. }
  411. if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST)
  412. info->protect[i] = 0;
  413. else
  414. info->protect[i] = addr2[2] & 1;
  415. }
  416. /* issue bank reset to return to read mode */
  417. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00F000F0;
  418. return info->size;
  419. }
  420. static int wait_for_DQ7_1(flash_info_t * info, int sect)
  421. {
  422. ulong start, now, last;
  423. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr =
  424. (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[sect]);
  425. start = get_timer(0);
  426. last = start;
  427. while ((addr[0] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080) !=
  428. (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080) {
  429. if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) {
  430. printf("Timeout\n");
  431. return -1;
  432. }
  433. /* show that we're waiting */
  434. if ((now - last) > 1000) { /* every second */
  435. putc('.');
  436. last = now;
  437. }
  438. }
  439. return 0;
  440. }
  441. #ifdef FLASH_BASE1_PRELIM
  442. int flash_erase(flash_info_t * info, int s_first, int s_last)
  443. {
  444. if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) ||
  445. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) ||
  446. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMLV128U) ||
  447. ((info->flash_id & FLASH_TYPEMASK) == FLASH_S29GL128N) ||
  448. ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT)) {
  449. return flash_erase_2(info, s_first, s_last);
  450. } else {
  451. return flash_erase_1(info, s_first, s_last);
  452. }
  453. }
  454. static int flash_erase_1(flash_info_t * info, int s_first, int s_last)
  455. #else
  456. int flash_erase(flash_info_t * info, int s_first, int s_last)
  457. #endif
  458. {
  459. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[0]);
  460. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2;
  461. int flag, prot, sect, l_sect;
  462. int i;
  463. if ((s_first < 0) || (s_first > s_last)) {
  464. if (info->flash_id == FLASH_UNKNOWN) {
  465. printf("- missing\n");
  466. } else {
  467. printf("- no sectors to erase\n");
  468. }
  469. return 1;
  470. }
  471. if (info->flash_id == FLASH_UNKNOWN) {
  472. printf("Can't erase unknown flash type - aborted\n");
  473. return 1;
  474. }
  475. prot = 0;
  476. for (sect = s_first; sect <= s_last; ++sect) {
  477. if (info->protect[sect]) {
  478. prot++;
  479. }
  480. }
  481. if (prot) {
  482. printf("- Warning: %d protected sectors will not be erased!\n",
  483. prot);
  484. } else {
  485. printf("\n");
  486. }
  487. l_sect = -1;
  488. /* Disable interrupts which might cause a timeout here */
  489. flag = disable_interrupts();
  490. /* Start erase on unprotected sectors */
  491. for (sect = s_first; sect <= s_last; sect++) {
  492. if (info->protect[sect] == 0) { /* not protected */
  493. addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[sect]);
  494. if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) {
  495. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  496. addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  497. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080;
  498. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  499. addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  500. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00500050; /* block erase */
  501. for (i = 0; i < 50; i++)
  502. udelay(1000); /* wait 1 ms */
  503. } else {
  504. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  505. addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  506. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080;
  507. addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  508. addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  509. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00300030; /* sector erase */
  510. }
  511. l_sect = sect;
  512. /*
  513. * Wait for each sector to complete, it's more
  514. * reliable. According to AMD Spec, you must
  515. * issue all erase commands within a specified
  516. * timeout. This has been seen to fail, especially
  517. * if printf()s are included (for debug)!!
  518. */
  519. wait_for_DQ7_1(info, sect);
  520. }
  521. }
  522. /* re-enable interrupts if necessary */
  523. if (flag)
  524. enable_interrupts();
  525. /* wait at least 80us - let's wait 1 ms */
  526. udelay(1000);
  527. /* reset to read mode */
  528. addr = (CONFIG_SYS_FLASH_WORD_SIZE *) info->start[0];
  529. addr[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00F000F0; /* reset bank */
  530. printf(" done\n");
  531. return 0;
  532. }
  533. /*-----------------------------------------------------------------------
  534. * Copy memory to flash, returns:
  535. * 0 - OK
  536. * 1 - write timeout
  537. * 2 - Flash not erased
  538. */
  539. int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
  540. {
  541. ulong cp, wp, data;
  542. int i, l, rc;
  543. wp = (addr & ~3); /* get lower word aligned address */
  544. /*
  545. * handle unaligned start bytes
  546. */
  547. if ((l = addr - wp) != 0) {
  548. data = 0;
  549. for (i = 0, cp = wp; i < l; ++i, ++cp) {
  550. data = (data << 8) | (*(uchar *) cp);
  551. }
  552. for (; i < 4 && cnt > 0; ++i) {
  553. data = (data << 8) | *src++;
  554. --cnt;
  555. ++cp;
  556. }
  557. for (; cnt == 0 && i < 4; ++i, ++cp) {
  558. data = (data << 8) | (*(uchar *) cp);
  559. }
  560. if ((rc = write_word(info, wp, data)) != 0) {
  561. return rc;
  562. }
  563. wp += 4;
  564. }
  565. /*
  566. * handle word aligned part
  567. */
  568. while (cnt >= 4) {
  569. data = 0;
  570. for (i = 0; i < 4; ++i) {
  571. data = (data << 8) | *src++;
  572. }
  573. if ((rc = write_word(info, wp, data)) != 0) {
  574. return rc;
  575. }
  576. wp += 4;
  577. cnt -= 4;
  578. }
  579. if (cnt == 0) {
  580. return 0;
  581. }
  582. /*
  583. * handle unaligned tail bytes
  584. */
  585. data = 0;
  586. for (i = 0, cp = wp; i < 4 && cnt > 0; ++i, ++cp) {
  587. data = (data << 8) | *src++;
  588. --cnt;
  589. }
  590. for (; i < 4; ++i, ++cp) {
  591. data = (data << 8) | (*(uchar *) cp);
  592. }
  593. return (write_word(info, wp, data));
  594. }
  595. /*-----------------------------------------------------------------------
  596. * Copy memory to flash, returns:
  597. * 0 - OK
  598. * 1 - write timeout
  599. * 2 - Flash not erased
  600. */
  601. #ifdef FLASH_BASE1_PRELIM
  602. static int write_word(flash_info_t * info, ulong dest, ulong data)
  603. {
  604. if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) ||
  605. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) ||
  606. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMLV128U) ||
  607. ((info->flash_id & FLASH_TYPEMASK) == FLASH_S29GL128N) ||
  608. ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT)) {
  609. return write_word_2(info, dest, data);
  610. } else {
  611. return write_word_1(info, dest, data);
  612. }
  613. }
  614. static int write_word_1(flash_info_t * info, ulong dest, ulong data)
  615. #else
  616. static int write_word(flash_info_t * info, ulong dest, ulong data)
  617. #endif
  618. {
  619. ulong *data_ptr = &data;
  620. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]);
  621. volatile CONFIG_SYS_FLASH_WORD_SIZE *dest2 = (CONFIG_SYS_FLASH_WORD_SIZE *)dest;
  622. volatile CONFIG_SYS_FLASH_WORD_SIZE *data2 = (CONFIG_SYS_FLASH_WORD_SIZE *)data_ptr;
  623. ulong start;
  624. int i;
  625. /* Check if Flash is (sufficiently) erased */
  626. if ((*((vu_long *)dest) & data) != data) {
  627. return 2;
  628. }
  629. for (i = 0; i < 4 / sizeof(CONFIG_SYS_FLASH_WORD_SIZE); i++) {
  630. int flag;
  631. /* Disable interrupts which might cause a timeout here */
  632. flag = disable_interrupts();
  633. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00AA00AA;
  634. addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00550055;
  635. addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x00A000A0;
  636. dest2[i] = data2[i];
  637. /* re-enable interrupts if necessary */
  638. if (flag)
  639. enable_interrupts();
  640. /* data polling for D7 */
  641. start = get_timer(0);
  642. while ((dest2[i] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080) !=
  643. (data2[i] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x00800080)) {
  644. if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
  645. return 1;
  646. }
  647. }
  648. }
  649. return 0;
  650. }
  651. #ifdef FLASH_BASE1_PRELIM
  652. /*
  653. * The following code cannot be run from FLASH!
  654. */
  655. static ulong flash_get_size_2(vu_long * addr, flash_info_t * info)
  656. {
  657. short i;
  658. CONFIG_SYS_FLASH_CHAR_SIZE value;
  659. ulong base = (ulong) addr;
  660. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *) addr;
  661. DEBUGF("FLASH ADDR: %08x\n", (unsigned)addr);
  662. /* Write auto select command: read Manufacturer ID */
  663. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  664. addr2[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  665. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x90909090;
  666. udelay(1000);
  667. value = (CONFIG_SYS_FLASH_CHAR_SIZE)addr2[0];
  668. DEBUGF("FLASH MANUFACT: %x\n", value);
  669. switch (value) {
  670. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_MANUFACT:
  671. info->flash_id = FLASH_MAN_AMD;
  672. break;
  673. case (CONFIG_SYS_FLASH_CHAR_SIZE) FUJ_MANUFACT:
  674. info->flash_id = FLASH_MAN_FUJ;
  675. break;
  676. case (CONFIG_SYS_FLASH_CHAR_SIZE) SST_MANUFACT:
  677. info->flash_id = FLASH_MAN_SST;
  678. break;
  679. case (CONFIG_SYS_FLASH_CHAR_SIZE) STM_MANUFACT:
  680. info->flash_id = FLASH_MAN_STM;
  681. break;
  682. default:
  683. info->flash_id = FLASH_UNKNOWN;
  684. info->sector_count = 0;
  685. info->size = 0;
  686. return 0; /* no or unknown flash */
  687. }
  688. value = (CONFIG_SYS_FLASH_CHAR_SIZE)addr2[2]; /* device ID */
  689. DEBUGF("\nFLASH DEVICEID: %x\n", value);
  690. switch (value) {
  691. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV040B:
  692. info->flash_id += FLASH_AM040;
  693. info->sector_count = 8;
  694. info->size = 0x0080000; /* => 512 ko */
  695. break;
  696. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_F040B:
  697. info->flash_id += FLASH_AM040;
  698. info->sector_count = 8;
  699. info->size = 0x0080000; /* => 512 ko */
  700. break;
  701. case (CONFIG_SYS_FLASH_CHAR_SIZE) STM_ID_M29W040B:
  702. info->flash_id += FLASH_AM040;
  703. info->sector_count = 8;
  704. info->size = 0x0080000; /* => 512 ko */
  705. break;
  706. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_F016D:
  707. info->flash_id += FLASH_AMD016;
  708. info->sector_count = 32;
  709. info->size = 0x00200000;
  710. break; /* => 2 MB */
  711. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV033C:
  712. info->flash_id += FLASH_AMDLV033C;
  713. info->sector_count = 64;
  714. info->size = 0x00400000;
  715. break; /* => 4 MB */
  716. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV400T:
  717. info->flash_id += FLASH_AM400T;
  718. info->sector_count = 11;
  719. info->size = 0x00080000;
  720. break; /* => 0.5 MB */
  721. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV400B:
  722. info->flash_id += FLASH_AM400B;
  723. info->sector_count = 11;
  724. info->size = 0x00080000;
  725. break; /* => 0.5 MB */
  726. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV800T:
  727. info->flash_id += FLASH_AM800T;
  728. info->sector_count = 19;
  729. info->size = 0x00100000;
  730. break; /* => 1 MB */
  731. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV800B:
  732. info->flash_id += FLASH_AM800B;
  733. info->sector_count = 19;
  734. info->size = 0x00100000;
  735. break; /* => 1 MB */
  736. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV160T:
  737. info->flash_id += FLASH_AM160T;
  738. info->sector_count = 35;
  739. info->size = 0x00200000;
  740. break; /* => 2 MB */
  741. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_LV160B:
  742. info->flash_id += FLASH_AM160B;
  743. info->sector_count = 35;
  744. info->size = 0x00200000;
  745. break; /* => 2 MB */
  746. case (CONFIG_SYS_FLASH_CHAR_SIZE) AMD_ID_MIRROR:
  747. if ((CONFIG_SYS_FLASH_CHAR_SIZE)addr2[0x1c] == (CONFIG_SYS_FLASH_CHAR_SIZE)AMD_ID_LV128U_2
  748. && (CONFIG_SYS_FLASH_CHAR_SIZE)addr2[0x1e] == (CONFIG_SYS_FLASH_CHAR_SIZE)AMD_ID_LV128U_3) {
  749. info->flash_id += FLASH_AMLV128U;
  750. info->sector_count = 256;
  751. info->size = 0x01000000;
  752. } else if ((CONFIG_SYS_FLASH_CHAR_SIZE)addr2[0x1c] == (CONFIG_SYS_FLASH_CHAR_SIZE)AMD_ID_GL128N_2
  753. && (CONFIG_SYS_FLASH_CHAR_SIZE)addr2[0x1e] == (CONFIG_SYS_FLASH_CHAR_SIZE)AMD_ID_GL128N_3 ) {
  754. info->flash_id += FLASH_S29GL128N;
  755. info->sector_count = 128;
  756. info->size = 0x01000000;
  757. }
  758. else
  759. info->flash_id = FLASH_UNKNOWN;
  760. break; /* => 2 MB */
  761. default:
  762. info->flash_id = FLASH_UNKNOWN;
  763. return 0; /* => no or unknown flash */
  764. }
  765. /* set up sector start address table */
  766. if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
  767. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM040) ||
  768. ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMD016)) {
  769. for (i = 0; i < info->sector_count; i++)
  770. info->start[i] = base + (i * 0x00010000);
  771. } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMLV128U) {
  772. for (i = 0; i < info->sector_count; i++)
  773. info->start[i] = base + (i * 0x00010000);
  774. } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_S29GL128N ) {
  775. for (i = 0; i < info->sector_count; i++)
  776. info->start[i] = base + (i * 0x00020000);
  777. } else {
  778. if (info->flash_id & FLASH_BTYPE) {
  779. /* set sector offsets for bottom boot block type */
  780. info->start[0] = base + 0x00000000;
  781. info->start[1] = base + 0x00004000;
  782. info->start[2] = base + 0x00006000;
  783. info->start[3] = base + 0x00008000;
  784. for (i = 4; i < info->sector_count; i++) {
  785. info->start[i] =
  786. base + (i * 0x00010000) - 0x00030000;
  787. }
  788. } else {
  789. /* set sector offsets for top boot block type */
  790. i = info->sector_count - 1;
  791. info->start[i--] = base + info->size - 0x00004000;
  792. info->start[i--] = base + info->size - 0x00006000;
  793. info->start[i--] = base + info->size - 0x00008000;
  794. for (; i >= 0; i--) {
  795. info->start[i] = base + i * 0x00010000;
  796. }
  797. }
  798. }
  799. /* check for protected sectors */
  800. for (i = 0; i < info->sector_count; i++) {
  801. /* read sector protection at sector address, (A7 .. A0) = 0x02 */
  802. /* D0 = 1 if protected */
  803. addr2 = (volatile CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[i]);
  804. /* For AMD29033C flash we need to resend the command of *
  805. * reading flash protection for upper 8 Mb of flash */
  806. if (i == 32) {
  807. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  808. addr2[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  809. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x90909090;
  810. }
  811. if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST)
  812. info->protect[i] = 0;
  813. else
  814. info->protect[i] = (CONFIG_SYS_FLASH_CHAR_SIZE)addr2[4] & 1;
  815. }
  816. /* issue bank reset to return to read mode */
  817. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xF0F0F0F0;
  818. return info->size;
  819. }
  820. static int wait_for_DQ7_2(flash_info_t * info, int sect)
  821. {
  822. ulong start, now, last;
  823. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr =
  824. (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[sect]);
  825. start = get_timer(0);
  826. last = start;
  827. while (((CONFIG_SYS_FLASH_WORD_SIZE)addr[0] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080) !=
  828. (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080) {
  829. if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) {
  830. printf("Timeout\n");
  831. return -1;
  832. }
  833. /* show that we're waiting */
  834. if ((now - last) > 1000) { /* every second */
  835. putc('.');
  836. last = now;
  837. }
  838. }
  839. return 0;
  840. }
  841. static int flash_erase_2(flash_info_t * info, int s_first, int s_last)
  842. {
  843. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[0]);
  844. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2;
  845. int flag, prot, sect, l_sect;
  846. int i;
  847. if ((s_first < 0) || (s_first > s_last)) {
  848. if (info->flash_id == FLASH_UNKNOWN) {
  849. printf("- missing\n");
  850. } else {
  851. printf("- no sectors to erase\n");
  852. }
  853. return 1;
  854. }
  855. if (info->flash_id == FLASH_UNKNOWN) {
  856. printf("Can't erase unknown flash type - aborted\n");
  857. return 1;
  858. }
  859. prot = 0;
  860. for (sect = s_first; sect <= s_last; ++sect) {
  861. if (info->protect[sect]) {
  862. prot++;
  863. }
  864. }
  865. if (prot) {
  866. printf("- Warning: %d protected sectors will not be erased!\n",
  867. prot);
  868. } else {
  869. printf("\n");
  870. }
  871. l_sect = -1;
  872. /* Disable interrupts which might cause a timeout here */
  873. flag = disable_interrupts();
  874. /* Start erase on unprotected sectors */
  875. for (sect = s_first; sect <= s_last; sect++) {
  876. if (info->protect[sect] == 0) { /* not protected */
  877. addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[sect]);
  878. if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) {
  879. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  880. addr[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  881. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080;
  882. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  883. addr[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  884. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x50505050; /* block erase */
  885. for (i = 0; i < 50; i++)
  886. udelay(1000); /* wait 1 ms */
  887. } else {
  888. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  889. addr[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  890. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080;
  891. addr[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  892. addr[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  893. addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x30303030; /* sector erase */
  894. }
  895. l_sect = sect;
  896. /*
  897. * Wait for each sector to complete, it's more
  898. * reliable. According to AMD Spec, you must
  899. * issue all erase commands within a specified
  900. * timeout. This has been seen to fail, especially
  901. * if printf()s are included (for debug)!!
  902. */
  903. wait_for_DQ7_2(info, sect);
  904. }
  905. }
  906. /* re-enable interrupts if necessary */
  907. if (flag)
  908. enable_interrupts();
  909. /* wait at least 80us - let's wait 1 ms */
  910. udelay(1000);
  911. /* reset to read mode */
  912. addr = (CONFIG_SYS_FLASH_WORD_SIZE *) info->start[0];
  913. addr[0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xF0F0F0F0; /* reset bank */
  914. printf(" done\n");
  915. return 0;
  916. }
  917. static int write_word_2(flash_info_t * info, ulong dest, ulong data)
  918. {
  919. ulong *data_ptr = &data;
  920. volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]);
  921. volatile CONFIG_SYS_FLASH_WORD_SIZE *dest2 = (CONFIG_SYS_FLASH_WORD_SIZE *)dest;
  922. volatile CONFIG_SYS_FLASH_WORD_SIZE *data2 = (CONFIG_SYS_FLASH_WORD_SIZE *)data_ptr;
  923. ulong start;
  924. int i;
  925. /* Check if Flash is (sufficiently) erased */
  926. if ((*((vu_long *)dest) & data) != data) {
  927. return 2;
  928. }
  929. for (i = 0; i < 4 / sizeof(CONFIG_SYS_FLASH_WORD_SIZE); i++) {
  930. int flag;
  931. /* Disable interrupts which might cause a timeout here */
  932. flag = disable_interrupts();
  933. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xAAAAAAAA;
  934. addr2[CONFIG_SYS_FLASH_CHAR_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE) 0x55555555;
  935. addr2[CONFIG_SYS_FLASH_CHAR_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE) 0xA0A0A0A0;
  936. dest2[i] = data2[i];
  937. /* re-enable interrupts if necessary */
  938. if (flag)
  939. enable_interrupts();
  940. /* data polling for D7 */
  941. start = get_timer(0);
  942. while ((dest2[i] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080) !=
  943. (data2[i] & (CONFIG_SYS_FLASH_WORD_SIZE) 0x80808080)) {
  944. if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
  945. return 1;
  946. }
  947. }
  948. }
  949. return 0;
  950. }
  951. #endif /* FLASH_BASE1_PRELIM */