2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 #define SECTSZ (64 * 1024)
13 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
15 /*----------------------------------------------------------------------*/
16 unsigned long flash_init (void)
20 flash_info_t *fli = &flash_info[0];
22 fli->size = CONFIG_SYS_FLASH_SIZE;
23 fli->sector_count = CONFIG_SYS_MAX_FLASH_SECT;
24 fli->flash_id = FLASH_MAN_AMD + FLASH_AMDLV065D;
26 addr = CONFIG_SYS_FLASH_BASE;
27 for (i = 0; i < fli->sector_count; ++i) {
33 return (CONFIG_SYS_FLASH_SIZE);
35 /*--------------------------------------------------------------------*/
36 void flash_print_info (flash_info_t * info)
42 printf (" Size: %ld KB in %d Sectors\n",
43 info->size >> 10, info->sector_count);
44 printf (" Sector Start Addresses:");
45 for (i = 0; i < info->sector_count; ++i) {
47 /* Check if whole sector is erased */
49 addr = (unsigned long *) info->start[i];
50 for (k = 0; k < SECTSZ/sizeof(unsigned long); k++) {
51 if ( readl(addr++) != (unsigned long)-1) {
63 info->protect[i] ? "RO " : " ");
68 /*-------------------------------------------------------------------*/
71 int flash_erase (flash_info_t * info, int s_first, int s_last)
73 unsigned char *addr = (unsigned char *) info->start[0];
78 /* Some sanity checking */
79 if ((s_first < 0) || (s_first > s_last)) {
80 printf ("- no sectors to erase\n");
85 for (sect = s_first; sect <= s_last; ++sect) {
86 if (info->protect[sect]) {
91 printf ("- Warning: %d protected sectors will not be erased!\n",
97 /* It's ok to erase multiple sectors provided we don't delay more
98 * than 50 usec between cmds ... at which point the erase time-out
99 * occurs. So don't go and put printf() calls in the loop ... it
100 * won't be very helpful ;-)
102 for (sect = s_first; sect <= s_last; sect++) {
103 if (info->protect[sect] == 0) { /* not protected */
104 addr2 = (unsigned char *) info->start[sect];
110 writeb (0x30, addr2);
111 /* Now just wait for 0xff & provide some user
112 * feedback while we wait.
114 start = get_timer (0);
115 while ( readb (addr2) != 0xff) {
116 udelay (1000 * 1000);
118 if (get_timer (start) > CONFIG_SYS_FLASH_ERASE_TOUT) {
119 printf ("timeout\n");
129 /*-----------------------------------------------------------------------
130 * Copy memory to flash, returns:
133 * 2 - Flash not erased
136 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
139 vu_char *cmd = (vu_char *) info->start[0];
140 vu_char *dst = (vu_char *) addr;
145 /* Check for sufficient erase */
147 if ((readb (dst) & b) != b) {
148 printf ("%02x : %02x\n", readb (dst), b);
158 start = get_timer (0);
159 while (readb (dst) != b) {
160 if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {