]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/impa7/flash.c
7db0b3289dc6c260a7f2495030218474a618f842
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #define FLASH_BANK_SIZE 0x800000
28 #define MAIN_SECT_SIZE 0x20000
29 #define PARAM_SECT_SIZE 0x4000
31 flash_info_t flash_info
[CFG_MAX_FLASH_BANKS
];
34 /*-----------------------------------------------------------------------
37 ulong
flash_init(void)
42 for (i
= 0; i
< CFG_MAX_FLASH_BANKS
; i
++)
45 flash_info
[i
].flash_id
=
46 (INTEL_MANUFACT
& FLASH_VENDMASK
) |
47 (INTEL_ID_28F320B3T
& FLASH_TYPEMASK
);
48 flash_info
[i
].size
= FLASH_BANK_SIZE
;
49 flash_info
[i
].sector_count
= CFG_MAX_FLASH_SECT
;
50 memset(flash_info
[i
].protect
, 0, CFG_MAX_FLASH_SECT
);
52 flashbase
= PHYS_FLASH_1
;
54 flashbase
= PHYS_FLASH_2
;
56 panic("configured to many flash banks!\n");
57 for (j
= 0; j
< flash_info
[i
].sector_count
; j
++)
61 flash_info
[i
].start
[j
] = flashbase
+ j
* PARAM_SECT_SIZE
;
65 flash_info
[i
].start
[j
] = flashbase
+ (j
- 7)*MAIN_SECT_SIZE
;
68 size
+= flash_info
[i
].size
;
71 /* Protect monitor and environment sectors
73 flash_protect(FLAG_PROTECT_SET
,
75 CFG_FLASH_BASE
+ monitor_flash_len
- 1,
78 flash_protect(FLAG_PROTECT_SET
,
80 CFG_ENV_ADDR
+ CFG_ENV_SIZE
- 1,
86 /*-----------------------------------------------------------------------
88 void flash_print_info (flash_info_t
*info
)
92 switch (info
->flash_id
& FLASH_VENDMASK
)
94 case (INTEL_MANUFACT
& FLASH_VENDMASK
):
98 printf("Unknown Vendor ");
102 switch (info
->flash_id
& FLASH_TYPEMASK
)
104 case (INTEL_ID_28F320B3T
& FLASH_TYPEMASK
):
105 printf("28F320F3B (16Mbit)\n");
108 printf("Unknown Chip Type\n");
113 printf(" Size: %ld MB in %d Sectors\n",
114 info
->size
>> 20, info
->sector_count
);
116 printf(" Sector Start Addresses:");
117 for (i
= 0; i
< info
->sector_count
; i
++)
123 printf (" %08lX%s", info
->start
[i
],
124 info
->protect
[i
] ? " (RO)" : " ");
131 /*-----------------------------------------------------------------------
134 int flash_erase (flash_info_t
*info
, int s_first
, int s_last
)
136 int flag
, prot
, sect
;
139 if (info
->flash_id
== FLASH_UNKNOWN
)
140 return ERR_UNKNOWN_FLASH_TYPE
;
142 if ((s_first
< 0) || (s_first
> s_last
)) {
146 if ((info
->flash_id
& FLASH_VENDMASK
) !=
147 (INTEL_MANUFACT
& FLASH_VENDMASK
)) {
148 return ERR_UNKNOWN_FLASH_VENDOR
;
152 for (sect
=s_first
; sect
<=s_last
; ++sect
) {
153 if (info
->protect
[sect
]) {
158 return ERR_PROTECTED
;
161 * Disable interrupts which might cause a timeout
162 * here. Remember that our exception vectors are
163 * at address 0 in the flash, and we don't want a
164 * (ticker) exception to happen while the flash
165 * chip is in programming mode.
167 flag
= disable_interrupts();
169 /* Start erase on unprotected sectors */
170 for (sect
= s_first
; sect
<=s_last
&& !ctrlc(); sect
++) {
172 printf("Erasing sector %2d ... ", sect
);
174 /* arm simple, non interrupt dependent timer */
175 reset_timer_masked();
177 if (info
->protect
[sect
] == 0) { /* not protected */
178 vu_long
*addr
= (vu_long
*)(info
->start
[sect
]);
180 *addr
= 0x00200020; /* erase setup */
181 *addr
= 0x00D000D0; /* erase confirm */
183 while ((*addr
& 0x00800080) != 0x00800080) {
184 if (get_timer_masked() > CFG_FLASH_ERASE_TOUT
) {
185 *addr
= 0x00B000B0; /* suspend erase */
186 *addr
= 0x00FF00FF; /* reset to read mode */
192 *addr
= 0x00FF00FF; /* reset to read mode */
197 printf("User Interrupt!\n");
201 /* allow flash to settle - wait 10 ms */
202 udelay_masked(10000);
210 /*-----------------------------------------------------------------------
211 * Copy memory to flash
214 static int write_word (flash_info_t
*info
, ulong dest
, ulong data
)
216 vu_long
*addr
= (vu_long
*)dest
;
221 /* Check if Flash is (sufficiently) erased
223 if ((*addr
& data
) != data
)
224 return ERR_NOT_ERASED
;
227 * Disable interrupts which might cause a timeout
228 * here. Remember that our exception vectors are
229 * at address 0 in the flash, and we don't want a
230 * (ticker) exception to happen while the flash
231 * chip is in programming mode.
233 flag
= disable_interrupts();
235 /* clear status register command */
238 /* program set-up command */
241 /* latch address/data */
244 /* arm simple, non interrupt dependent timer */
245 reset_timer_masked();
247 /* read status register command */
250 /* wait while polling the status register */
251 while((*addr
& 0x00800080) != 0x00800080)
253 if (get_timer_masked() > CFG_FLASH_WRITE_TOUT
) {
255 /* suspend program command */
260 if( *addr
& 0x003A003A) { /* check for error */
262 if( barf
& 0x003A0000) {
267 printf("\nFlash write error %02lx at address %08lx\n",
268 barf
, (unsigned long)dest
);
270 printf("Block locked, not erased.\n");
275 printf("Programming error.\n");
280 printf("Vpp Low error.\n");
291 /* read array command */
300 /*-----------------------------------------------------------------------
301 * Copy memory to flash.
304 int write_buff (flash_info_t
*info
, uchar
*src
, ulong addr
, ulong cnt
)
310 wp
= (addr
& ~3); /* get lower word aligned address */
313 * handle unaligned start bytes
315 if ((l
= addr
- wp
) != 0) {
317 for (i
=0, cp
=wp
; i
<l
; ++i
, ++cp
) {
318 data
= (data
>> 8) | (*(uchar
*)cp
<< 24);
320 for (; i
<4 && cnt
>0; ++i
) {
321 data
= (data
>> 8) | (*src
++ << 24);
325 for (; cnt
==0 && i
<4; ++i
, ++cp
) {
326 data
= (data
>> 8) | (*(uchar
*)cp
<< 24);
329 if ((rc
= write_word(info
, wp
, data
)) != 0) {
336 * handle word aligned part
339 data
= *((vu_long
*)src
);
340 if ((rc
= write_word(info
, wp
, data
)) != 0) {
353 * handle unaligned tail bytes
356 for (i
=0, cp
=wp
; i
<4 && cnt
>0; ++i
, ++cp
) {
357 data
= (data
>> 8) | (*src
++ << 24);
360 for (; i
<4; ++i
, ++cp
) {
361 data
= (data
>> 8) | (*(uchar
*)cp
<< 24);
364 return write_word(info
, wp
, data
);