*/
void flash_reset(void)
{
- if( flash_info[0].flash_id != FLASH_UNKNOWN )
- {
+ if( flash_info[0].flash_id != FLASH_UNKNOWN ) {
V_ULONG( flash_info[0].start[0] ) = 0x00F000F0;
V_ULONG( flash_info[0].start[0] + 4 ) = 0x00F000F0;
}
flashtest_h = V_ULONG( baseaddr ); /* manufacturer ID */
flashtest_l = V_ULONG( baseaddr + 4 );
- if (flashtest_h != AMD_MANUFACT)
- {
- info->flash_id = FLASH_UNKNOWN;
- info->sector_count = 0;
- info->size = 0;
- return( 0 ); /* no or unknown flash */
- }
- info->flash_id = AMD_MANUFACT << 16; /* set manufacturer offset */
+ switch ((int)flashtest_h) {
+ case AMD_MANUFACT:
+ info->flash_id = FLASH_MAN_AMD;
+ break;
+ case FUJ_MANUFACT:
+ info->flash_id = FLASH_MAN_FUJ;
+ break;
+ default:
+ info->flash_id = FLASH_UNKNOWN;
+ info->sector_count = 0;
+ info->size = 0;
+ return (0); /* no or unknown flash */
+ }
flashtest_h = V_ULONG( baseaddr + 8 ); /* device ID */
flashtest_l = V_ULONG( baseaddr + 12 );
- if( flashtest_h != flashtest_l )
+ if( flashtest_h != flashtest_l ) {
info->flash_id = FLASH_UNKNOWN;
- else
- switch( flashtest_h )
- {
+ } else {
+ switch( flashtest_h ) {
case AMD_ID_LV800T:
info->flash_id += FLASH_AM800T;
info->sector_count = 19;
info->flash_id = FLASH_UNKNOWN;
return( 0 ); /* no or unknown flash */
}
+ }
+
+ if (flashtest_h == AMD_ID_LV640U) {
- if (flashtest_h == AMD_ID_LV640U)
- {
/* set up sector start adress table (uniform sector type) */
for( i = 0; i < info->sector_count; i++ )
info->start[i] = baseaddr + (i * 0x00040000);
- }
- else if (info->flash_id & FLASH_BTYPE)
- {
+
+ } else if (info->flash_id & FLASH_BTYPE) {
+
/* set up sector start adress table (bottom sector type) */
info->start[0] = baseaddr + 0x00000000;
info->start[1] = baseaddr + 0x00010000;
info->start[2] = baseaddr + 0x00018000;
info->start[3] = baseaddr + 0x00020000;
- for( i = 4; i < info->sector_count; i++ )
+ for( i = 4; i < info->sector_count; i++ ) {
info->start[i] = baseaddr + (i * 0x00040000) - 0x000C0000;
- }
- else
- {
+ }
+
+ } else {
+
/* set up sector start adress table (top sector type) */
i = info->sector_count - 1;
info->start[i--] = baseaddr + info->size - 0x00010000;
info->start[i--] = baseaddr + info->size - 0x00018000;
info->start[i--] = baseaddr + info->size - 0x00020000;
- for( ; i >= 0; i-- )
+ for( ; i >= 0; i-- ) {
info->start[i] = baseaddr + i * 0x00040000;
+ }
}
/* check for protected sectors */
- for( i = 0; i < info->sector_count; i++ )
- {
+ for( i = 0; i < info->sector_count; i++ ) {
/* read sector protection at sector address, (A7 .. A0) = 0x02 */
if( (V_ULONG( info->start[i] + 16 ) & 0x00010001) ||
- (V_ULONG( info->start[i] + 20 ) & 0x00010001) )
- info->protect[i] = 1; /* D0 = 1 if protected */
- else info->protect[i] = 0;
+ (V_ULONG( info->start[i] + 20 ) & 0x00010001) ) {
+ info->protect[i] = 1; /* D0 = 1 if protected */
+ } else {
+ info->protect[i] = 0;
+ }
}
flash_reset();
int i;
/* Init: no FLASHes known */
- for (i=0; i<CFG_MAX_FLASH_BANKS; ++i)
- {
+ for (i=0; i<CFG_MAX_FLASH_BANKS; ++i) {
flash_info[i].flash_id = FLASH_UNKNOWN;
}
/* Static FLASH Bank configuration here (only one bank) */
size_b0 = flash_get_size(CFG_FLASH0_BASE, &flash_info[0]);
- if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b0 == 0)
- {
+ if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b0 == 0) {
printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
size_b0, size_b0>>20);
}
{
int i;
- if (info->flash_id == FLASH_UNKNOWN)
- {
+ if (info->flash_id == FLASH_UNKNOWN) {
printf ("missing or unknown FLASH type\n");
return;
}
- switch ((info->flash_id >> 16) & 0xff)
- {
- case 0x1:
- printf ("AMD ");
- break;
- default:
- printf ("Unknown Vendor ");
- break;
+ switch ((info->flash_id >> 16) & 0xff) {
+ case FLASH_MAN_AMD: printf ("AMD "); break;
+ case FLASH_MAN_FUJ: printf ("FUJITSU "); break;
+ default: printf ("Unknown Vendor "); break;
}
- switch (info->flash_id & FLASH_TYPEMASK)
- {
- case FLASH_AM800T:
- printf ("29LV800T (8 M, top sector)\n");
- break;
- case FLASH_AM800B:
- printf ("29LV800T (8 M, bottom sector)\n");
- break;
- case FLASH_AM160T:
- printf ("29LV160T (16 M, top sector)\n");
- break;
- case FLASH_AM160B:
- printf ("29LV160B (16 M, bottom sector)\n");
- break;
- case FLASH_AMDL322T:
- printf ("29DL322T (32 M, top sector)\n");
- break;
- case FLASH_AMDL322B:
- printf ("29DL322B (32 M, bottom sector)\n");
- break;
- case FLASH_AMDL323T:
- printf ("29DL323T (32 M, top sector)\n");
- break;
- case FLASH_AMDL323B:
- printf ("29DL323B (32 M, bottom sector)\n");
- break;
- case FLASH_AM640U:
- printf ("29LV640D (64 M, uniform sector)\n");
- break;
- default:
- printf ("Unknown Chip Type\n");
- break;
+ switch (info->flash_id & FLASH_TYPEMASK) {
+ case FLASH_AM800T: printf ("29LV800T (8 M, top sector)\n");
+ break;
+ case FLASH_AM800B: printf ("29LV800T (8 M, bottom sector)\n");
+ break;
+ case FLASH_AM160T: printf ("29LV160T (16 M, top sector)\n");
+ break;
+ case FLASH_AM160B: printf ("29LV160B (16 M, bottom sector)\n");
+ break;
+ case FLASH_AMDL322T: printf ("29DL322T (32 M, top sector)\n");
+ break;
+ case FLASH_AMDL322B: printf ("29DL322B (32 M, bottom sector)\n");
+ break;
+ case FLASH_AMDL323T: printf ("29DL323T (32 M, top sector)\n");
+ break;
+ case FLASH_AMDL323B: printf ("29DL323B (32 M, bottom sector)\n");
+ break;
+ case FLASH_AM640U: printf ("29LV640D (64 M, uniform sector)\n");
+ break;
+ default: printf ("Unknown Chip Type\n");
+ break;
}
printf (" Size: %ld MB in %d Sectors\n",
info->size >> 20, info->sector_count);
printf (" Sector Start Addresses:");
- for (i=0; i<info->sector_count; ++i)
- {
+ for (i=0; i<info->sector_count; ++i) {
if ((i % 5) == 0)
printf ("\n ");
printf (" %08lX%s",
int flag, prot, sect, l_sect;
ulong start, now, last;
- if ((s_first < 0) || (s_first > s_last))
- {
- if (info->flash_id == FLASH_UNKNOWN)
- {
+ if ((s_first < 0) || (s_first > s_last)) {
+ if (info->flash_id == FLASH_UNKNOWN) {
printf ("- missing\n");
} else {
printf ("- no sectors to erase\n");
}
prot = 0;
- for (sect = s_first; sect <= s_last; sect++)
- {
+ for (sect = s_first; sect <= s_last; sect++) {
if (info->protect[sect])
prot++;
}
- if (prot)
- {
+ if (prot) {
printf ("- Warning: %d protected sectors will not be erased!\n",
prot);
- } else
- {
+ } else {
printf ("\n");
}
udelay (1000);
/* Start erase on unprotected sectors */
- for (sect = s_first; sect<=s_last; sect++)
- {
- if (info->protect[sect] == 0)
- { /* not protected */
+ for (sect = s_first; sect<=s_last; sect++) {
+ if (info->protect[sect] == 0) { /* not protected */
V_ULONG( info->start[sect] ) = 0x00300030;
V_ULONG( info->start[sect] + 4 ) = 0x00300030;
l_sect = sect;
while ((V_ULONG( info->start[l_sect] ) & 0x00800080) != 0x00800080 ||
(V_ULONG( info->start[l_sect] + 4 ) & 0x00800080) != 0x00800080)
{
- if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT)
- {
+ if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
printf ("Timeout\n");
return 1;
}
/* show that we're waiting */
- if ((now - last) > 1000)
- { /* every second */
+ if ((now - last) > 1000) { /* every second */
serial_putc ('.');
last = now;
}
/*
* handle unaligned start bytes
*/
- if ((l = addr - dp) != 0)
- {
+ if ((l = addr - dp) != 0) {
for (i = 0; i < 8; i++)
bb[i] = (i < l || (i-l) >= cc) ? V_BYTE(dp+i) : *src++;
if ((rc = write_dword(info, dp, bb)) != 0)
/*
* handle word aligned part
*/
- while (cc >= 8)
- {
- if ((rc = write_dword(info, dp, src)) != 0)
- {
+ while (cc >= 8) {
+ if ((rc = write_dword(info, dp, src)) != 0) {
return (rc);
}
dp += 8;
cc -= 8;
}
- if (cc <= 0)
- {
+ if (cc <= 0) {
return (0);
}
/*
* handle unaligned tail bytes
*/
- for (i = 0; i < 8; i++)
- {
+ for (i = 0; i < 8; i++) {
bb[i] = (i < cc) ? *src++ : V_BYTE(dp+i);
}
return (write_dword(info, dp, bb));
while( ((V_ULONG( dest ) & 0x00800080) != (ch & 0x00800080)) ||
((V_ULONG( dest + 4 ) & 0x00800080) != (cl & 0x00800080)) )
{
- if (get_timer(start) > CFG_FLASH_WRITE_TOUT)
- {
+ if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
return (1);
}
}
return (0);
}
-