2003-03-12 10:41:04 +00:00
|
|
|
/*
|
|
|
|
**=====================================================================
|
|
|
|
**
|
|
|
|
** Copyright (C) 2000, 2001, 2002, 2003
|
|
|
|
** The LEOX team <team@leox.org>, http://www.leox.org
|
|
|
|
**
|
|
|
|
** LEOX.org is about the development of free hardware and software resources
|
|
|
|
** for system on chip.
|
|
|
|
**
|
|
|
|
** Description: U-Boot port on the LEOX's ELPT860 CPU board
|
|
|
|
** ~~~~~~~~~~~
|
|
|
|
**
|
|
|
|
**=====================================================================
|
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU General Public License as
|
|
|
|
** published by the Free Software Foundation; either version 2 of
|
|
|
|
** the License, or (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software
|
|
|
|
** Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
** MA 02111-1307 USA
|
|
|
|
**
|
|
|
|
**=====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Note 1: In this file, you have to provide the following variable:
|
|
|
|
** ------
|
|
|
|
** flash_info_t flash_info[CFG_MAX_FLASH_BANKS]
|
|
|
|
** 'flash_info_t' structure is defined into 'include/flash.h'
|
|
|
|
** and defined as extern into 'common/cmd_flash.c'
|
|
|
|
**
|
|
|
|
** Note 2: In this file, you have to provide the following functions:
|
|
|
|
** ------
|
|
|
|
** unsigned long flash_init(void)
|
|
|
|
** called from 'board_init_r()' into 'common/board.c'
|
|
|
|
**
|
|
|
|
** void flash_print_info(flash_info_t *info)
|
|
|
|
** called from 'do_flinfo()' into 'common/cmd_flash.c'
|
|
|
|
**
|
|
|
|
** int flash_erase(flash_info_t *info,
|
|
|
|
** int s_first,
|
|
|
|
** int s_last)
|
|
|
|
** called from 'do_flerase()' & 'flash_sect_erase()' into 'common/cmd_flash.c'
|
|
|
|
**
|
|
|
|
** int write_buff (flash_info_t *info,
|
|
|
|
** uchar *src,
|
|
|
|
** ulong addr,
|
|
|
|
** ulong cnt)
|
|
|
|
** called from 'flash_write()' into 'common/cmd_flash.c'
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <mpc8xx.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CFG_ENV_ADDR
|
|
|
|
# define CFG_ENV_ADDR (CFG_FLASH_BASE + CFG_ENV_OFFSET)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* Internal Functions
|
|
|
|
*/
|
|
|
|
static void flash_get_offsets (ulong base, flash_info_t *info);
|
|
|
|
static ulong flash_get_size (volatile unsigned char *addr, flash_info_t *info);
|
|
|
|
|
|
|
|
static int write_word (flash_info_t *info, ulong dest, ulong data);
|
|
|
|
static int write_byte (flash_info_t *info, ulong dest, uchar data);
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
unsigned long
|
2003-03-12 10:41:04 +00:00
|
|
|
flash_init (void)
|
|
|
|
{
|
|
|
|
volatile immap_t *immap = (immap_t *)CFG_IMMR;
|
|
|
|
volatile memctl8xx_t *memctl = &immap->im_memctl;
|
|
|
|
unsigned long size_b0;
|
|
|
|
int i;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Init: no FLASHes known */
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i=0; i<CFG_MAX_FLASH_BANKS; ++i)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
flash_info[i].flash_id = FLASH_UNKNOWN;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Static FLASH Bank configuration here - FIXME XXX */
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
size_b0 = flash_get_size ((volatile unsigned char *)FLASH_BASE0_PRELIM,
|
2003-03-12 10:41:04 +00:00
|
|
|
&flash_info[0]);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( flash_info[0].flash_id == FLASH_UNKNOWN )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
|
|
|
|
size_b0, size_b0<<20);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Remap FLASH according to real size */
|
|
|
|
memctl->memc_or0 = CFG_OR_TIMING_FLASH | (-size_b0 & OR_AM_MSK);
|
|
|
|
memctl->memc_br0 = (CFG_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_PS_8 | BR_V;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Re-do sizing to get full correct info */
|
2003-06-27 21:31:46 +00:00
|
|
|
size_b0 = flash_get_size ((volatile unsigned char *)CFG_FLASH_BASE,
|
2003-03-12 10:41:04 +00:00
|
|
|
&flash_info[0]);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
flash_get_offsets (CFG_FLASH_BASE, &flash_info[0]);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
#if CFG_MONITOR_BASE >= CFG_FLASH_BASE
|
|
|
|
/* monitor protection ON by default */
|
|
|
|
flash_protect (FLAG_PROTECT_SET,
|
|
|
|
CFG_MONITOR_BASE,
|
2003-05-30 12:48:29 +00:00
|
|
|
CFG_MONITOR_BASE + monitor_flash_len-1,
|
2003-03-12 10:41:04 +00:00
|
|
|
&flash_info[0]);
|
|
|
|
#endif
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
#ifdef CFG_ENV_IS_IN_FLASH
|
|
|
|
/* ENV protection ON by default */
|
|
|
|
flash_protect(FLAG_PROTECT_SET,
|
|
|
|
CFG_ENV_ADDR,
|
|
|
|
CFG_ENV_ADDR + CFG_ENV_SIZE-1,
|
|
|
|
&flash_info[0]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
flash_info[0].size = size_b0;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
return (size_b0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
static void
|
|
|
|
flash_get_offsets (ulong base,
|
2003-03-12 10:41:04 +00:00
|
|
|
flash_info_t *info)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define SECTOR_64KB 0x00010000
|
|
|
|
|
|
|
|
/* set up sector start adress table */
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i = 0; i < info->sector_count; i++)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
info->start[i] = base + (i * SECTOR_64KB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
void
|
2003-03-12 10:41:04 +00:00
|
|
|
flash_print_info (flash_info_t *info)
|
|
|
|
{
|
|
|
|
int i;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( info->flash_id == FLASH_UNKNOWN )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("missing or unknown FLASH type\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
switch ( info->flash_id & FLASH_VENDMASK )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
case FLASH_MAN_AMD: printf ("AMD "); break;
|
|
|
|
case FLASH_MAN_FUJ: printf ("FUJITSU "); break;
|
|
|
|
case FLASH_MAN_STM: printf ("STM (Thomson) "); break;
|
|
|
|
default: printf ("Unknown Vendor "); break;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
switch ( info->flash_id & FLASH_TYPEMASK )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
case FLASH_AM040: printf ("AM29F040 (4 Mbits)\n");
|
|
|
|
break;
|
|
|
|
default: printf ("Unknown Chip Type\n");
|
|
|
|
break;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
printf (" Size: %ld KB in %d Sectors\n",
|
2003-03-12 10:41:04 +00:00
|
|
|
info->size >> 10, info->sector_count);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
printf (" Sector Start Addresses:");
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i=0; i<info->sector_count; ++i)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
if ((i % 5) == 0)
|
|
|
|
printf ("\n ");
|
|
|
|
printf (" %08lX%s",
|
|
|
|
info->start[i],
|
|
|
|
info->protect[i] ? " (RO)" : " "
|
|
|
|
);
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following code cannot be run from FLASH!
|
|
|
|
*/
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
static ulong
|
|
|
|
flash_get_size (volatile unsigned char *addr,
|
|
|
|
flash_info_t *info)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
short i;
|
|
|
|
uchar value;
|
|
|
|
ulong base = (ulong)addr;
|
|
|
|
|
|
|
|
/* Write auto select command: read Manufacturer ID */
|
|
|
|
addr[0x0555] = 0xAA;
|
|
|
|
addr[0x02AA] = 0x55;
|
|
|
|
addr[0x0555] = 0x90;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
value = addr[0];
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
switch ( value )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
/* case AMD_MANUFACT: */
|
|
|
|
case 0x01:
|
|
|
|
info->flash_id = FLASH_MAN_AMD;
|
|
|
|
break;
|
|
|
|
/* case FUJ_MANUFACT: */
|
|
|
|
case 0x04:
|
|
|
|
info->flash_id = FLASH_MAN_FUJ;
|
|
|
|
break;
|
|
|
|
/* case STM_MANUFACT: */
|
|
|
|
case 0x20:
|
|
|
|
info->flash_id = FLASH_MAN_STM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
info->flash_id = FLASH_UNKNOWN;
|
|
|
|
info->sector_count = 0;
|
|
|
|
info->size = 0;
|
|
|
|
return (0); /* no or unknown flash */
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
value = addr[1]; /* device ID */
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
switch ( value )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
case STM_ID_F040B:
|
|
|
|
case AMD_ID_F040B:
|
|
|
|
info->flash_id += FLASH_AM040; /* 4 Mbits = 512k * 8 */
|
|
|
|
info->sector_count = 8;
|
|
|
|
info->size = 0x00080000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
info->flash_id = FLASH_UNKNOWN;
|
|
|
|
return (0); /* => no or unknown flash */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up sector start adress table */
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i = 0; i < info->sector_count; i++)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
info->start[i] = base + (i * 0x00010000);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* check for protected sectors */
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i = 0; i < info->sector_count; i++)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
/* read sector protection at sector address, (A7 .. A0) = 0x02 */
|
|
|
|
/* D0 = 1 if protected */
|
|
|
|
addr = (volatile unsigned char *)(info->start[i]);
|
|
|
|
info->protect[i] = addr[2] & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent writes to uninitialized FLASH.
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( info->flash_id != FLASH_UNKNOWN )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
addr = (volatile unsigned char *)info->start[0];
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
*addr = 0xF0; /* reset bank */
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
return (info->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2003-06-27 21:31:46 +00:00
|
|
|
flash_erase (flash_info_t *info,
|
|
|
|
int s_first,
|
2003-03-12 10:41:04 +00:00
|
|
|
int s_last)
|
|
|
|
{
|
|
|
|
volatile unsigned char *addr = (volatile unsigned char *)(info->start[0]);
|
|
|
|
int flag, prot, sect, l_sect;
|
|
|
|
ulong start, now, last;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( (s_first < 0) || (s_first > s_last) )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( info->flash_id == FLASH_UNKNOWN )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("- missing\n");
|
2003-06-27 21:31:46 +00:00
|
|
|
}
|
|
|
|
else
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("- no sectors to erase\n");
|
|
|
|
}
|
|
|
|
return ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (info->flash_id == FLASH_UNKNOWN) ||
|
2003-06-27 21:31:46 +00:00
|
|
|
(info->flash_id > FLASH_AMD_COMP) )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("Can't erase unknown flash type %08lx - aborted\n",
|
|
|
|
info->flash_id);
|
|
|
|
return ( 1 );
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
prot = 0;
|
2003-06-27 21:31:46 +00:00
|
|
|
for (sect=s_first; sect<=s_last; ++sect)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( info->protect[sect] )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
prot++;
|
|
|
|
}
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( prot )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("- Warning: %d protected sectors will not be erased!\n", prot);
|
2003-06-27 21:31:46 +00:00
|
|
|
}
|
|
|
|
else
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
l_sect = -1;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Disable interrupts which might cause a timeout here */
|
|
|
|
flag = disable_interrupts();
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
addr[0x0555] = 0xAA;
|
|
|
|
addr[0x02AA] = 0x55;
|
|
|
|
addr[0x0555] = 0x80;
|
|
|
|
addr[0x0555] = 0xAA;
|
|
|
|
addr[0x02AA] = 0x55;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Start erase on unprotected sectors */
|
2003-06-27 21:31:46 +00:00
|
|
|
for (sect = s_first; sect<=s_last; sect++)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
if (info->protect[sect] == 0) /* not protected */
|
|
|
|
{
|
|
|
|
addr = (volatile unsigned char *)(info->start[sect]);
|
|
|
|
addr[0] = 0x30;
|
|
|
|
l_sect = sect;
|
|
|
|
}
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* re-enable interrupts if necessary */
|
|
|
|
if ( flag )
|
|
|
|
enable_interrupts();
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* wait at least 80us - let's wait 1 ms */
|
|
|
|
udelay (1000);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/*
|
|
|
|
* We wait for the last triggered sector
|
|
|
|
*/
|
|
|
|
if ( l_sect < 0 )
|
|
|
|
goto DONE;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
start = get_timer (0);
|
|
|
|
last = start;
|
|
|
|
addr = (volatile unsigned char *)(info->start[l_sect]);
|
2003-06-27 21:31:46 +00:00
|
|
|
while ( (addr[0] & 0x80) != 0x80 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( (now = get_timer(start)) > CFG_FLASH_ERASE_TOUT )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
printf ("Timeout\n");
|
|
|
|
return ( 1 );
|
|
|
|
}
|
|
|
|
/* show that we're waiting */
|
|
|
|
if ( (now - last) > 1000 ) /* every second */
|
|
|
|
{
|
|
|
|
putc ('.');
|
|
|
|
last = now;
|
|
|
|
}
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
DONE:
|
|
|
|
/* reset to read mode */
|
|
|
|
addr = (volatile unsigned char *)info->start[0];
|
|
|
|
addr[0] = 0xF0; /* reset bank */
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
printf (" done\n");
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* Copy memory to flash, returns:
|
|
|
|
* 0 - OK
|
|
|
|
* 1 - write timeout
|
|
|
|
* 2 - Flash not erased
|
|
|
|
*/
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
int
|
|
|
|
write_buff (flash_info_t *info,
|
|
|
|
uchar *src,
|
|
|
|
ulong addr,
|
2003-03-12 10:41:04 +00:00
|
|
|
ulong cnt)
|
|
|
|
{
|
|
|
|
ulong cp, wp, data;
|
|
|
|
uchar bdata;
|
|
|
|
int i, l, rc;
|
|
|
|
|
|
|
|
if ( (info->flash_id & FLASH_TYPEMASK) == FLASH_AM040 )
|
|
|
|
{
|
|
|
|
/* Width of the data bus: 8 bits */
|
|
|
|
|
|
|
|
wp = addr;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
while ( cnt )
|
|
|
|
{
|
|
|
|
bdata = *src++;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
if ( (rc = write_byte(info, wp, bdata)) != 0 )
|
|
|
|
{
|
|
|
|
return (rc);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
++wp;
|
|
|
|
--cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Width of the data bus: 32 bits */
|
|
|
|
|
|
|
|
wp = (addr & ~3); /* get lower word aligned address */
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/*
|
|
|
|
* handle unaligned start bytes
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( (l = addr - wp) != 0 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = 0;
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i=0, cp=wp; i<l; ++i, ++cp)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | (*(uchar *)cp);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
for (; i<4 && cnt>0; ++i)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | *src++;
|
|
|
|
--cnt;
|
|
|
|
++cp;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
for (; cnt==0 && i<4; ++i, ++cp)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | (*(uchar *)cp);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( (rc = write_word(info, wp, data)) != 0 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
wp += 4;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/*
|
|
|
|
* handle word aligned part
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
while ( cnt >= 4 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = 0;
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i=0; i<4; ++i)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | *src++;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( (rc = write_word(info, wp, data)) != 0 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
wp += 4;
|
|
|
|
cnt -= 4;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
if ( cnt == 0 )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/*
|
|
|
|
* handle unaligned tail bytes
|
|
|
|
*/
|
|
|
|
data = 0;
|
2003-06-27 21:31:46 +00:00
|
|
|
for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | *src++;
|
|
|
|
--cnt;
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
for (; i<4; ++i, ++cp)
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
data = (data << 8) | (*(uchar *)cp);
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
return (write_word(info, wp, data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* Write a word to Flash, returns:
|
|
|
|
* 0 - OK
|
|
|
|
* 1 - write timeout
|
|
|
|
* 2 - Flash not erased
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
static int
|
|
|
|
write_word (flash_info_t *info,
|
|
|
|
ulong dest,
|
2003-03-12 10:41:04 +00:00
|
|
|
ulong data)
|
|
|
|
{
|
|
|
|
vu_long *addr = (vu_long*)(info->start[0]);
|
|
|
|
ulong start;
|
|
|
|
int flag;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Check if Flash is (sufficiently) erased */
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( (*((vu_long *)dest) & data) != data )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
/* Disable interrupts which might cause a timeout here */
|
|
|
|
flag = disable_interrupts();
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
addr[0x0555] = 0x00AA00AA;
|
|
|
|
addr[0x02AA] = 0x00550055;
|
|
|
|
addr[0x0555] = 0x00A000A0;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
*((vu_long *)dest) = data;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* re-enable interrupts if necessary */
|
|
|
|
if ( flag )
|
|
|
|
enable_interrupts();
|
|
|
|
|
|
|
|
/* data polling for D7 */
|
|
|
|
start = get_timer (0);
|
2003-06-27 21:31:46 +00:00
|
|
|
while ( (*((vu_long *)dest) & 0x00800080) != (data & 0x00800080) )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( get_timer(start) > CFG_FLASH_WRITE_TOUT )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* Write a byte to Flash, returns:
|
|
|
|
* 0 - OK
|
|
|
|
* 1 - write timeout
|
|
|
|
* 2 - Flash not erased
|
|
|
|
*/
|
2003-06-27 21:31:46 +00:00
|
|
|
static int
|
|
|
|
write_byte (flash_info_t *info,
|
|
|
|
ulong dest,
|
2003-03-12 10:41:04 +00:00
|
|
|
uchar data)
|
|
|
|
{
|
|
|
|
volatile unsigned char *addr = (volatile unsigned char *)(info->start[0]);
|
|
|
|
ulong start;
|
|
|
|
int flag;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* Check if Flash is (sufficiently) erased */
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( (*((volatile unsigned char *)dest) & data) != data )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
/* Disable interrupts which might cause a timeout here */
|
|
|
|
flag = disable_interrupts();
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
addr[0x0555] = 0xAA;
|
|
|
|
addr[0x02AA] = 0x55;
|
|
|
|
addr[0x0555] = 0xA0;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
*((volatile unsigned char *)dest) = data;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2003-03-12 10:41:04 +00:00
|
|
|
/* re-enable interrupts if necessary */
|
|
|
|
if ( flag )
|
|
|
|
enable_interrupts();
|
|
|
|
|
|
|
|
/* data polling for D7 */
|
|
|
|
start = get_timer (0);
|
2003-06-27 21:31:46 +00:00
|
|
|
while ( (*((volatile unsigned char *)dest) & 0x80) != (data & 0x80) )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
2003-06-27 21:31:46 +00:00
|
|
|
if ( get_timer(start) > CFG_FLASH_WRITE_TOUT )
|
2003-03-12 10:41:04 +00:00
|
|
|
{
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|