1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <common.h>
24#include <asm/arch/hardware.h>
25
26#define SST_BASEADDR 0x80000000
27#define SST_ADDR1 ((volatile ushort*)(SST_BASEADDR + (0x5555 << 1)))
28#define SST_ADDR2 ((volatile ushort*)(SST_BASEADDR + (0x2AAA << 1)))
29
30
31flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
32
33extern int lpc2292_copy_buffer_to_flash(flash_info_t *, ulong);
34extern int lpc2292_flash_erase(flash_info_t *, int, int);
35extern int lpc2292_write_buff (flash_info_t *, uchar *, ulong, ulong);
36
37
38
39
40void write_word_sst(ulong addr, ushort data)
41{
42 ushort tmp;
43
44 *SST_ADDR1 = 0x00AA;
45 *SST_ADDR2 = 0x0055;
46 *SST_ADDR1 = 0x00A0;
47 *((volatile ushort*)addr) = data;
48
49 do {
50 tmp = *((volatile ushort*)addr);
51 } while (tmp != data);
52}
53
54
55
56
57ulong flash_init (void)
58{
59 int j, k;
60 ulong size = 0;
61 ulong flashbase = 0;
62
63 flash_info[0].flash_id = (PHILIPS_LPC2292 & FLASH_VENDMASK);
64 flash_info[0].size = 0x003E000;
65 flash_info[0].sector_count = 17;
66 memset (flash_info[0].protect, 0, 17);
67 flashbase = 0x00000000;
68 for (j = 0, k = 0; j < 8; j++, k++) {
69 flash_info[0].start[k] = flashbase;
70 flashbase += 0x00002000;
71 }
72 for (j = 0; j < 2; j++, k++) {
73 flash_info[0].start[k] = flashbase;
74 flashbase += 0x00010000;
75 }
76 for (j = 0; j < 7; j++, k++) {
77 flash_info[0].start[k] = flashbase;
78 flashbase += 0x00002000;
79 }
80 size += flash_info[0].size;
81
82 flash_info[1].flash_id = (SST_MANUFACT & FLASH_VENDMASK);
83 flash_info[1].size = 0x00200000;
84 flash_info[1].sector_count = 512;
85 memset (flash_info[1].protect, 0, 512);
86 flashbase = SST_BASEADDR;
87 for (j=0; j<512; j++) {
88 flash_info[1].start[j] = flashbase;
89 flashbase += 0x1000;
90 }
91 size += flash_info[1].size;
92
93
94 flash_protect (FLAG_PROTECT_SET,
95 0x0,
96 0x0 + monitor_flash_len - 1,
97 &flash_info[0]);
98
99 flash_protect (FLAG_PROTECT_SET,
100 CONFIG_ENV_ADDR,
101 CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1,
102 &flash_info[0]);
103
104 return size;
105}
106
107
108
109void flash_print_info (flash_info_t * info)
110{
111 int i;
112 int erased = 0;
113 unsigned long j;
114 unsigned long count;
115 unsigned char *p;
116
117 switch (info->flash_id & FLASH_VENDMASK) {
118 case (SST_MANUFACT & FLASH_VENDMASK):
119 printf("SST: ");
120 break;
121 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
122 printf("Philips: ");
123 break;
124 default:
125 printf ("Unknown Vendor ");
126 break;
127 }
128
129 printf (" Size: %ld KB in %d Sectors\n",
130 info->size >> 10, info->sector_count);
131
132 printf (" Sector Start Addresses:");
133 for (i = 0; i < info->sector_count; i++) {
134 if ((i % 5) == 0) {
135 printf ("\n ");
136 }
137 if (i < (info->sector_count - 1)) {
138 count = info->start[i+1] - info->start[i];
139 }
140 else {
141 count = info->start[0] + info->size - info->start[i];
142 }
143 p = (unsigned char*)(info->start[i]);
144 erased = 1;
145 for (j = 0; j < count; j++) {
146 if (*p != 0xFF) {
147 erased = 0;
148 break;
149 }
150 p++;
151 }
152 printf (" %08lX%s%s", info->start[i], info->protect[i] ? " RO" : " ",
153 erased ? " E" : " ");
154 }
155 printf ("\n");
156}
157
158int flash_erase_sst (flash_info_t * info, int s_first, int s_last)
159{
160 int i;
161
162 for (i = s_first; i <= s_last; i++) {
163 *SST_ADDR1 = 0x00AA;
164 *SST_ADDR2 = 0x0055;
165 *SST_ADDR1 = 0x0080;
166 *SST_ADDR1 = 0x00AA;
167 *SST_ADDR2 = 0x0055;
168 *((volatile ushort*)(info->start[i])) = 0x0030;
169
170 udelay(25000);
171 }
172
173 return ERR_OK;
174}
175
176int flash_erase (flash_info_t * info, int s_first, int s_last)
177{
178 switch (info->flash_id & FLASH_VENDMASK) {
179 case (SST_MANUFACT & FLASH_VENDMASK):
180 return flash_erase_sst(info, s_first, s_last);
181 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
182 return lpc2292_flash_erase(info, s_first, s_last);
183 default:
184 return ERR_PROTECTED;
185 }
186 return ERR_PROTECTED;
187}
188
189
190
191
192
193
194
195int write_buff_sst (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
196{
197 ushort tmp;
198 ulong i;
199 uchar* src_org;
200 uchar* dst_org;
201 ulong cnt_org = cnt;
202 int ret = ERR_OK;
203
204 src_org = src;
205 dst_org = (uchar*)addr;
206
207 if (addr & 1) {
208 tmp = *((uchar*)(addr - 1));
209 tmp |= (*src << 8);
210 write_word_sst(addr - 1, tmp);
211 addr += 1;
212 cnt -= 1;
213 src++;
214 }
215 while (cnt > 1) {
216 tmp = ((*(src+1)) << 8) + (*src);
217 write_word_sst(addr, tmp);
218 addr += 2;
219 src += 2;
220 cnt -= 2;
221 }
222 if (cnt > 0) {
223 tmp = (*((uchar*)(addr + 1))) << 8;
224 tmp |= *src;
225 write_word_sst(addr, tmp);
226 }
227
228 for (i = 0; i < cnt_org; i++) {
229 if (*dst_org != *src_org) {
230 printf("Write failed. Byte %lX differs\n", i);
231 ret = ERR_PROG_ERROR;
232 break;
233 }
234 dst_org++;
235 src_org++;
236 }
237
238 return ret;
239}
240
241int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
242{
243 switch (info->flash_id & FLASH_VENDMASK) {
244 case (SST_MANUFACT & FLASH_VENDMASK):
245 return write_buff_sst(info, src, addr, cnt);
246 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
247 return lpc2292_write_buff(info, src, addr, cnt);
248 default:
249 return ERR_PROG_ERROR;
250 }
251 return ERR_PROG_ERROR;
252}
253