1
2
3
4
5
6
7
8
9#include <common.h>
10#include <asm/io.h>
11
12#define SECTSZ (64 * 1024)
13flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
14
15
16unsigned long flash_init (void)
17{
18 int i;
19 unsigned long addr;
20 flash_info_t *fli = &flash_info[0];
21
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;
25
26 addr = CONFIG_SYS_FLASH_BASE;
27 for (i = 0; i < fli->sector_count; ++i) {
28 fli->start[i] = addr;
29 addr += SECTSZ;
30 fli->protect[i] = 1;
31 }
32
33 return (CONFIG_SYS_FLASH_SIZE);
34}
35
36void flash_print_info (flash_info_t * info)
37{
38 int i, k;
39 int erased;
40 unsigned long *addr;
41
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) {
46
47
48 erased = 1;
49 addr = (unsigned long *) info->start[i];
50 for (k = 0; k < SECTSZ/sizeof(unsigned long); k++) {
51 if ( readl(addr++) != (unsigned long)-1) {
52 erased = 0;
53 break;
54 }
55 }
56
57
58 if ((i % 5) == 0)
59 printf ("\n ");
60 printf (" %08lX%s%s",
61 info->start[i],
62 erased ? " E" : " ",
63 info->protect[i] ? "RO " : " ");
64 }
65 printf ("\n");
66}
67
68
69
70
71int flash_erase (flash_info_t * info, int s_first, int s_last)
72{
73 unsigned char *addr = (unsigned char *) info->start[0];
74 unsigned char *addr2;
75 int prot, sect;
76 ulong start;
77
78
79 if ((s_first < 0) || (s_first > s_last)) {
80 printf ("- no sectors to erase\n");
81 return 1;
82 }
83
84 prot = 0;
85 for (sect = s_first; sect <= s_last; ++sect) {
86 if (info->protect[sect]) {
87 prot++;
88 }
89 }
90 if (prot) {
91 printf ("- Warning: %d protected sectors will not be erased!\n",
92 prot);
93 } else {
94 printf ("\n");
95 }
96
97
98
99
100
101
102 for (sect = s_first; sect <= s_last; sect++) {
103 if (info->protect[sect] == 0) {
104 addr2 = (unsigned char *) info->start[sect];
105 writeb (0xaa, addr);
106 writeb (0x55, addr);
107 writeb (0x80, addr);
108 writeb (0xaa, addr);
109 writeb (0x55, addr);
110 writeb (0x30, addr2);
111
112
113
114 start = get_timer (0);
115 while ( readb (addr2) != 0xff) {
116 udelay (1000 * 1000);
117 putc ('.');
118 if (get_timer (start) > CONFIG_SYS_FLASH_ERASE_TOUT) {
119 printf ("timeout\n");
120 return 1;
121 }
122 }
123 }
124 }
125 printf ("\n");
126 return 0;
127}
128
129
130
131
132
133
134
135
136int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
137{
138
139 vu_char *cmd = (vu_char *) info->start[0];
140 vu_char *dst = (vu_char *) addr;
141 unsigned char b;
142 ulong start;
143
144 while (cnt) {
145
146 b = *src;
147 if ((readb (dst) & b) != b) {
148 printf ("%02x : %02x\n", readb (dst), b);
149 return (2);
150 }
151
152 writeb (0xaa, cmd);
153 writeb (0x55, cmd);
154 writeb (0xa0, cmd);
155 writeb (dst, b);
156
157
158 start = get_timer (0);
159 while (readb (dst) != b) {
160 if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
161 return 1;
162 }
163 }
164 dst++;
165 src++;
166 cnt--;
167 }
168
169 return (0);
170}
171