flash.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * (C) Copyright 2000-2002
  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. /* #define DEBUG */
  24. #include <common.h>
  25. #include <mpc8xx.h>
  26. #include <environment.h>
  27. #ifndef CFG_ENV_ADDR
  28. #define CFG_ENV_ADDR (CFG_FLASH_BASE + CFG_ENV_OFFSET)
  29. #endif
  30. flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  31. /*-----------------------------------------------------------------------
  32. * Functions
  33. */
  34. static ulong flash_get_size (vu_long *addr, flash_info_t *info);
  35. static int write_word (flash_info_t *info, ulong dest, ulong data);
  36. /*-----------------------------------------------------------------------
  37. */
  38. unsigned long flash_init (void)
  39. {
  40. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  41. volatile memctl8xx_t *memctl = &immap->im_memctl;
  42. unsigned long size_b0, size_b1;
  43. int i;
  44. /* Init: no FLASHes known */
  45. for (i=0; i<CFG_MAX_FLASH_BANKS; ++i) {
  46. flash_info[i].flash_id = FLASH_UNKNOWN;
  47. }
  48. /* Static FLASH Bank configuration here - FIXME XXX */
  49. debug ("\n## Get flash bank 1 size @ 0x%08x\n",FLASH_BASE0_PRELIM);
  50. size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
  51. debug ("## Get flash bank 2 size @ 0x%08x\n",FLASH_BASE1_PRELIM);
  52. if (flash_info[0].flash_id == FLASH_UNKNOWN) {
  53. printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
  54. size_b0, size_b0<<20);
  55. }
  56. size_b1 = flash_get_size((vu_long *)FLASH_BASE1_PRELIM, &flash_info[1]);
  57. debug ("## Prelim. Flash bank sizes: %08lx + 0x%08lx\n",size_b0,size_b1);
  58. if (size_b1 > size_b0) {
  59. printf ("## ERROR: "
  60. "Bank 1 (0x%08lx = %ld MB) > Bank 0 (0x%08lx = %ld MB)\n",
  61. size_b1, size_b1<<20,
  62. size_b0, size_b0<<20
  63. );
  64. flash_info[0].flash_id = FLASH_UNKNOWN;
  65. flash_info[1].flash_id = FLASH_UNKNOWN;
  66. flash_info[0].sector_count = -1;
  67. flash_info[1].sector_count = -1;
  68. flash_info[0].size = 0;
  69. flash_info[1].size = 0;
  70. return (0);
  71. }
  72. debug ("## Before remap: "
  73. "BR0: 0x%08x OR0: 0x%08x "
  74. "BR1: 0x%08x OR1: 0x%08x\n",
  75. memctl->memc_br0, memctl->memc_or0,
  76. memctl->memc_br1, memctl->memc_or1);
  77. /* Remap FLASH according to real size */
  78. memctl->memc_or0 = CFG_OR_TIMING_FLASH | (-size_b0 & OR_AM_MSK);
  79. memctl->memc_br0 = (CFG_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
  80. debug ("## BR0: 0x%08x OR0: 0x%08x\n",
  81. memctl->memc_br0, memctl->memc_or0);
  82. /* Re-do sizing to get full correct info */
  83. size_b0 = flash_get_size((vu_long *)CFG_FLASH_BASE, &flash_info[0]);
  84. #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
  85. /* monitor protection ON by default */
  86. debug ("Protect monitor: %08lx ... %08lx\n",
  87. (ulong)CFG_MONITOR_BASE,
  88. (ulong)CFG_MONITOR_BASE + monitor_flash_len - 1);
  89. flash_protect(FLAG_PROTECT_SET,
  90. CFG_MONITOR_BASE,
  91. CFG_MONITOR_BASE + monitor_flash_len - 1,
  92. &flash_info[0]);
  93. #endif
  94. #ifdef CFG_ENV_IS_IN_FLASH
  95. /* ENV protection ON by default */
  96. debug ("Protect %senvironment: %08lx ... %08lx\n",
  97. # ifdef CFG_ENV_ADDR_REDUND
  98. "primary ",
  99. # else
  100. "",
  101. # endif
  102. (ulong)CFG_ENV_ADDR,
  103. (ulong)CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1);
  104. flash_protect(FLAG_PROTECT_SET,
  105. CFG_ENV_ADDR,
  106. CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
  107. &flash_info[0]);
  108. #endif
  109. #ifdef CFG_ENV_ADDR_REDUND
  110. debug ("Protect redundand environment: %08lx ... %08lx\n",
  111. (ulong)CFG_ENV_ADDR_REDUND,
  112. (ulong)CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1);
  113. flash_protect(FLAG_PROTECT_SET,
  114. CFG_ENV_ADDR_REDUND,
  115. CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1,
  116. &flash_info[0]);
  117. #endif
  118. if (size_b1) {
  119. memctl->memc_or1 = CFG_OR_TIMING_FLASH | (-size_b1 & 0xFFFF8000);
  120. memctl->memc_br1 = ((CFG_FLASH_BASE + size_b0) & BR_BA_MSK) |
  121. BR_MS_GPCM | BR_V;
  122. debug ("## BR1: 0x%08x OR1: 0x%08x\n",
  123. memctl->memc_br1, memctl->memc_or1);
  124. /* Re-do sizing to get full correct info */
  125. size_b1 = flash_get_size((vu_long *)(CFG_FLASH_BASE + size_b0),
  126. &flash_info[1]);
  127. #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
  128. /* monitor protection ON by default */
  129. flash_protect(FLAG_PROTECT_SET,
  130. CFG_MONITOR_BASE,
  131. CFG_MONITOR_BASE+monitor_flash_len-1,
  132. &flash_info[1]);
  133. #endif
  134. #ifdef CFG_ENV_IS_IN_FLASH
  135. /* ENV protection ON by default */
  136. flash_protect(FLAG_PROTECT_SET,
  137. CFG_ENV_ADDR,
  138. CFG_ENV_ADDR+CFG_ENV_SIZE-1,
  139. &flash_info[1]);
  140. #endif
  141. } else {
  142. memctl->memc_br1 = 0; /* invalidate bank */
  143. flash_info[1].flash_id = FLASH_UNKNOWN;
  144. flash_info[1].sector_count = -1;
  145. flash_info[1].size = 0;
  146. debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n",
  147. memctl->memc_br1, memctl->memc_or1);
  148. }
  149. debug ("## Final Flash bank sizes: %08lx + 0x%08lx\n",size_b0,size_b1);
  150. flash_info[0].size = size_b0;
  151. flash_info[1].size = size_b1;
  152. return (size_b0 + size_b1);
  153. }
  154. /*-----------------------------------------------------------------------
  155. */
  156. void flash_print_info (flash_info_t *info)
  157. {
  158. int i;
  159. if (info->flash_id == FLASH_UNKNOWN) {
  160. printf ("missing or unknown FLASH type\n");
  161. return;
  162. }
  163. switch (info->flash_id & FLASH_VENDMASK) {
  164. case FLASH_MAN_AMD: printf ("AMD "); break;
  165. case FLASH_MAN_FUJ: printf ("FUJITSU "); break;
  166. default: printf ("Unknown Vendor "); break;
  167. }
  168. switch (info->flash_id & FLASH_TYPEMASK) {
  169. #ifdef CONFIG_TQM8xxM /* mirror bit flash */
  170. case FLASH_AMLV128U: printf ("AM29LV128ML (128Mbit, uniform sector size)\n");
  171. break;
  172. # else /* ! TQM8xxM */
  173. case FLASH_AM400B: printf ("AM29LV400B (4 Mbit, bottom boot sect)\n");
  174. break;
  175. case FLASH_AM400T: printf ("AM29LV400T (4 Mbit, top boot sector)\n");
  176. break;
  177. case FLASH_AM800B: printf ("AM29LV800B (8 Mbit, bottom boot sect)\n");
  178. break;
  179. case FLASH_AM800T: printf ("AM29LV800T (8 Mbit, top boot sector)\n");
  180. break;
  181. case FLASH_AM160B: printf ("AM29LV160B (16 Mbit, bottom boot sect)\n");
  182. break;
  183. case FLASH_AM160T: printf ("AM29LV160T (16 Mbit, top boot sector)\n");
  184. break;
  185. case FLASH_AM320B: printf ("AM29LV320B (32 Mbit, bottom boot sect)\n");
  186. break;
  187. case FLASH_AM320T: printf ("AM29LV320T (32 Mbit, top boot sector)\n");
  188. break;
  189. #endif /* TQM8xxM */
  190. default: printf ("Unknown Chip Type\n");
  191. break;
  192. }
  193. printf (" Size: %ld MB in %d Sectors\n",
  194. info->size >> 20, info->sector_count);
  195. printf (" Sector Start Addresses:");
  196. for (i=0; i<info->sector_count; ++i) {
  197. if ((i % 5) == 0)
  198. printf ("\n ");
  199. printf (" %08lX%s",
  200. info->start[i],
  201. info->protect[i] ? " (RO)" : " "
  202. );
  203. }
  204. printf ("\n");
  205. return;
  206. }
  207. /*-----------------------------------------------------------------------
  208. */
  209. /*-----------------------------------------------------------------------
  210. */
  211. /*
  212. * The following code cannot be run from FLASH!
  213. */
  214. static ulong flash_get_size (vu_long *addr, flash_info_t *info)
  215. {
  216. short i;
  217. ulong value;
  218. ulong base = (ulong)addr;
  219. /* Write auto select command: read Manufacturer ID */
  220. addr[0x0555] = 0x00AA00AA;
  221. addr[0x02AA] = 0x00550055;
  222. addr[0x0555] = 0x00900090;
  223. value = addr[0];
  224. debug ("Manuf. ID @ 0x%08lx: 0x%08lx\n", (ulong)addr, value);
  225. switch (value) {
  226. case AMD_MANUFACT:
  227. info->flash_id = FLASH_MAN_AMD;
  228. break;
  229. case FUJ_MANUFACT:
  230. info->flash_id = FLASH_MAN_FUJ;
  231. break;
  232. default:
  233. info->flash_id = FLASH_UNKNOWN;
  234. info->sector_count = 0;
  235. info->size = 0;
  236. return (0); /* no or unknown flash */
  237. }
  238. value = addr[1]; /* device ID */
  239. debug ("Device ID @ 0x%08lx: 0x%08lx\n", (ulong)(&addr[1]), value);
  240. switch (value) {
  241. #ifdef CONFIG_TQM8xxM /* mirror bit flash */
  242. case AMD_ID_MIRROR:
  243. switch(addr[14]) {
  244. case AMD_ID_LV128U_2:
  245. if (addr[15] != AMD_ID_LV128U_3) {
  246. info->flash_id = FLASH_UNKNOWN;
  247. }
  248. else {
  249. info->flash_id += FLASH_AMLV128U;
  250. info->sector_count = 256;
  251. info->size = 0x02000000;
  252. }
  253. break; /* => 32 MB */
  254. default:
  255. info->flash_id = FLASH_UNKNOWN;
  256. break;
  257. }
  258. break;
  259. # else /* ! TQM8xxM */
  260. case AMD_ID_LV400T:
  261. info->flash_id += FLASH_AM400T;
  262. info->sector_count = 11;
  263. info->size = 0x00100000;
  264. break; /* => 1 MB */
  265. case AMD_ID_LV400B:
  266. info->flash_id += FLASH_AM400B;
  267. info->sector_count = 11;
  268. info->size = 0x00100000;
  269. break; /* => 1 MB */
  270. case AMD_ID_LV800T:
  271. info->flash_id += FLASH_AM800T;
  272. info->sector_count = 19;
  273. info->size = 0x00200000;
  274. break; /* => 2 MB */
  275. case AMD_ID_LV800B:
  276. info->flash_id += FLASH_AM800B;
  277. info->sector_count = 19;
  278. info->size = 0x00200000;
  279. break; /* => 2 MB */
  280. case AMD_ID_LV160T:
  281. info->flash_id += FLASH_AM160T;
  282. info->sector_count = 35;
  283. info->size = 0x00400000;
  284. break; /* => 4 MB */
  285. case AMD_ID_LV160B:
  286. info->flash_id += FLASH_AM160B;
  287. info->sector_count = 35;
  288. info->size = 0x00400000;
  289. break; /* => 4 MB */
  290. case AMD_ID_LV320T:
  291. info->flash_id += FLASH_AM320T;
  292. info->sector_count = 71;
  293. info->size = 0x00800000;
  294. break; /* => 8 MB */
  295. case AMD_ID_LV320B:
  296. info->flash_id += FLASH_AM320B;
  297. info->sector_count = 71;
  298. info->size = 0x00800000;
  299. break; /* => 8 MB */
  300. #endif /* TQM8xxM */
  301. default:
  302. info->flash_id = FLASH_UNKNOWN;
  303. return (0); /* => no or unknown flash */
  304. }
  305. /* set up sector start address table */
  306. switch (value) {
  307. #ifdef CONFIG_TQM8xxM /* mirror bit flash */
  308. case AMD_ID_MIRROR:
  309. switch (info->flash_id & FLASH_TYPEMASK) {
  310. /* only known types here - no default */
  311. case FLASH_AMLV128U:
  312. for (i = 0; i < info->sector_count; i++) {
  313. info->start[i] = base;
  314. base += 0x20000;
  315. }
  316. break;
  317. }
  318. break;
  319. # else /* ! TQM8xxM */
  320. case AMD_ID_LV400B:
  321. case AMD_ID_LV800B:
  322. case AMD_ID_LV160B:
  323. /* set sector offsets for bottom boot block type */
  324. info->start[0] = base + 0x00000000;
  325. info->start[1] = base + 0x00008000;
  326. info->start[2] = base + 0x0000C000;
  327. info->start[3] = base + 0x00010000;
  328. for (i = 4; i < info->sector_count; i++) {
  329. info->start[i] = base + (i * 0x00020000) - 0x00060000;
  330. }
  331. break;
  332. case AMD_ID_LV400T:
  333. case AMD_ID_LV800T:
  334. case AMD_ID_LV160T:
  335. /* set sector offsets for top boot block type */
  336. i = info->sector_count - 1;
  337. info->start[i--] = base + info->size - 0x00008000;
  338. info->start[i--] = base + info->size - 0x0000C000;
  339. info->start[i--] = base + info->size - 0x00010000;
  340. for (; i >= 0; i--) {
  341. info->start[i] = base + i * 0x00020000;
  342. }
  343. break;
  344. case AMD_ID_LV320B:
  345. for (i = 0; i < info->sector_count; i++) {
  346. info->start[i] = base;
  347. /*
  348. * The first 8 sectors are 8 kB,
  349. * all the other ones are 64 kB
  350. */
  351. base += (i < 8)
  352. ? 2 * ( 8 << 10)
  353. : 2 * (64 << 10);
  354. }
  355. break;
  356. case AMD_ID_LV320T:
  357. for (i = 0; i < info->sector_count; i++) {
  358. info->start[i] = base;
  359. /*
  360. * The last 8 sectors are 8 kB,
  361. * all the other ones are 64 kB
  362. */
  363. base += (i < (info->sector_count - 8))
  364. ? 2 * (64 << 10)
  365. : 2 * ( 8 << 10);
  366. }
  367. break;
  368. #endif /* TQM8xxM */
  369. default:
  370. return (0);
  371. break;
  372. }
  373. /* check for protected sectors */
  374. for (i = 0; i < info->sector_count; i++) {
  375. /* read sector protection at sector address, (A7 .. A0) = 0x02 */
  376. /* D0 = 1 if protected */
  377. addr = (volatile unsigned long *)(info->start[i]);
  378. info->protect[i] = addr[2] & 1;
  379. }
  380. /*
  381. * Prevent writes to uninitialized FLASH.
  382. */
  383. if (info->flash_id != FLASH_UNKNOWN) {
  384. addr = (volatile unsigned long *)info->start[0];
  385. *addr = 0x00F000F0; /* reset bank */
  386. }
  387. return (info->size);
  388. }
  389. /*-----------------------------------------------------------------------
  390. */
  391. int flash_erase (flash_info_t *info, int s_first, int s_last)
  392. {
  393. vu_long *addr = (vu_long*)(info->start[0]);
  394. int flag, prot, sect, l_sect;
  395. ulong start, now, last;
  396. debug ("flash_erase: first: %d last: %d\n", s_first, s_last);
  397. if ((s_first < 0) || (s_first > s_last)) {
  398. if (info->flash_id == FLASH_UNKNOWN) {
  399. printf ("- missing\n");
  400. } else {
  401. printf ("- no sectors to erase\n");
  402. }
  403. return 1;
  404. }
  405. if ((info->flash_id == FLASH_UNKNOWN) ||
  406. (info->flash_id > FLASH_AMD_COMP)) {
  407. printf ("Can't erase unknown flash type %08lx - aborted\n",
  408. info->flash_id);
  409. return 1;
  410. }
  411. prot = 0;
  412. for (sect=s_first; sect<=s_last; ++sect) {
  413. if (info->protect[sect]) {
  414. prot++;
  415. }
  416. }
  417. if (prot) {
  418. printf ("- Warning: %d protected sectors will not be erased!\n",
  419. prot);
  420. } else {
  421. printf ("\n");
  422. }
  423. l_sect = -1;
  424. /* Disable interrupts which might cause a timeout here */
  425. flag = disable_interrupts();
  426. addr[0x0555] = 0x00AA00AA;
  427. addr[0x02AA] = 0x00550055;
  428. addr[0x0555] = 0x00800080;
  429. addr[0x0555] = 0x00AA00AA;
  430. addr[0x02AA] = 0x00550055;
  431. /* Start erase on unprotected sectors */
  432. for (sect = s_first; sect<=s_last; sect++) {
  433. if (info->protect[sect] == 0) { /* not protected */
  434. addr = (vu_long*)(info->start[sect]);
  435. addr[0] = 0x00300030;
  436. l_sect = sect;
  437. }
  438. }
  439. /* re-enable interrupts if necessary */
  440. if (flag)
  441. enable_interrupts();
  442. /* wait at least 80us - let's wait 1 ms */
  443. udelay (1000);
  444. /*
  445. * We wait for the last triggered sector
  446. */
  447. if (l_sect < 0)
  448. goto DONE;
  449. start = get_timer (0);
  450. last = start;
  451. addr = (vu_long*)(info->start[l_sect]);
  452. while ((addr[0] & 0x00800080) != 0x00800080) {
  453. if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
  454. printf ("Timeout\n");
  455. return 1;
  456. }
  457. /* show that we're waiting */
  458. if ((now - last) > 1000) { /* every second */
  459. putc ('.');
  460. last = now;
  461. }
  462. }
  463. DONE:
  464. /* reset to read mode */
  465. addr = (volatile unsigned long *)info->start[0];
  466. addr[0] = 0x00F000F0; /* reset bank */
  467. printf (" done\n");
  468. return 0;
  469. }
  470. /*-----------------------------------------------------------------------
  471. * Copy memory to flash, returns:
  472. * 0 - OK
  473. * 1 - write timeout
  474. * 2 - Flash not erased
  475. */
  476. int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
  477. {
  478. ulong cp, wp, data;
  479. int i, l, rc;
  480. wp = (addr & ~3); /* get lower word aligned address */
  481. /*
  482. * handle unaligned start bytes
  483. */
  484. if ((l = addr - wp) != 0) {
  485. data = 0;
  486. for (i=0, cp=wp; i<l; ++i, ++cp) {
  487. data = (data << 8) | (*(uchar *)cp);
  488. }
  489. for (; i<4 && cnt>0; ++i) {
  490. data = (data << 8) | *src++;
  491. --cnt;
  492. ++cp;
  493. }
  494. for (; cnt==0 && i<4; ++i, ++cp) {
  495. data = (data << 8) | (*(uchar *)cp);
  496. }
  497. if ((rc = write_word(info, wp, data)) != 0) {
  498. return (rc);
  499. }
  500. wp += 4;
  501. }
  502. /*
  503. * handle word aligned part
  504. */
  505. while (cnt >= 4) {
  506. data = 0;
  507. for (i=0; i<4; ++i) {
  508. data = (data << 8) | *src++;
  509. }
  510. if ((rc = write_word(info, wp, data)) != 0) {
  511. return (rc);
  512. }
  513. wp += 4;
  514. cnt -= 4;
  515. }
  516. if (cnt == 0) {
  517. return (0);
  518. }
  519. /*
  520. * handle unaligned tail bytes
  521. */
  522. data = 0;
  523. for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) {
  524. data = (data << 8) | *src++;
  525. --cnt;
  526. }
  527. for (; i<4; ++i, ++cp) {
  528. data = (data << 8) | (*(uchar *)cp);
  529. }
  530. return (write_word(info, wp, data));
  531. }
  532. /*-----------------------------------------------------------------------
  533. * Write a word to Flash, returns:
  534. * 0 - OK
  535. * 1 - write timeout
  536. * 2 - Flash not erased
  537. */
  538. static int write_word (flash_info_t *info, ulong dest, ulong data)
  539. {
  540. vu_long *addr = (vu_long*)(info->start[0]);
  541. ulong start;
  542. int flag;
  543. /* Check if Flash is (sufficiently) erased */
  544. if ((*((vu_long *)dest) & data) != data) {
  545. return (2);
  546. }
  547. /* Disable interrupts which might cause a timeout here */
  548. flag = disable_interrupts();
  549. addr[0x0555] = 0x00AA00AA;
  550. addr[0x02AA] = 0x00550055;
  551. addr[0x0555] = 0x00A000A0;
  552. *((vu_long *)dest) = data;
  553. /* re-enable interrupts if necessary */
  554. if (flag)
  555. enable_interrupts();
  556. /* data polling for D7 */
  557. start = get_timer (0);
  558. while ((*((vu_long *)dest) & 0x00800080) != (data & 0x00800080)) {
  559. if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
  560. return (1);
  561. }
  562. }
  563. return (0);
  564. }
  565. /*-----------------------------------------------------------------------
  566. */