X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=board%2Feric%2Fflash.c;h=fded41271f176146cc96bfb73c6c34ab93ae9f57;hb=86caca1cd97ba71b7a7c82f2b0163682df35ce5d;hp=c3f6e15bc54019c815d39f23e316702cc280590c;hpb=fe8c2806cdba70479e351299881a395dc2be7785;p=u-boot diff --git a/board/eric/flash.c b/board/eric/flash.c index c3f6e15bc5..fded41271f 100644 --- a/board/eric/flash.c +++ b/board/eric/flash.c @@ -25,10 +25,10 @@ #include #include -flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */ +flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ -#ifdef CFG_FLASH_16BIT +#ifdef CONFIG_SYS_FLASH_16BIT #define FLASH_WORD_SIZE unsigned short #define FLASH_ID_MASK 0xFFFF #else @@ -42,7 +42,7 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */ /* stolen from esteem192e/flash.c */ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info); -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT static int write_word (flash_info_t *info, ulong dest, ulong data); #else static int write_short (flash_info_t *info, ulong dest, ushort data); @@ -57,11 +57,11 @@ unsigned long flash_init (void) { unsigned long size_b0, size_b1; int i; - uint pbcr; - unsigned long base_b0, base_b1; + uint pbcr; + unsigned long base_b0, base_b1; /* Init: no FLASHes known */ - for (i=0; istart[i] = base + (i * info->size/info->sector_count); } } else if (info->flash_id & FLASH_BTYPE) { - if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { + if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT /* set sector offsets for bottom boot block type */ info->start[0] = base + 0x00000000; info->start[1] = base + 0x00004000; @@ -200,9 +199,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info) info->start[7] = base + 0x0001C000; for (i = 8; i < info->sector_count; i++) { info->start[i] = base + (i * 0x00020000) - 0x000E0000; - } - } - else { + } + } + else { /* set sector offsets for bottom boot block type */ info->start[0] = base + 0x00000000; info->start[1] = base + 0x00008000; @@ -224,9 +223,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info) info->start[7] = base + 0x0000E000; for (i = 8; i < info->sector_count; i++) { info->start[i] = base + (i * 0x00010000) - 0x00070000; - } + } } - else { + else { /* set sector offsets for bottom boot block type */ info->start[0] = base + 0x00000000; info->start[1] = base + 0x00004000; @@ -240,9 +239,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info) } else { /* set sector offsets for top boot block type */ i = info->sector_count - 1; - if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { + if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) { -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT info->start[i--] = base + info->size - 0x00004000; info->start[i--] = base + info->size - 0x00008000; info->start[i--] = base + info->size - 0x0000C000; @@ -254,7 +253,7 @@ static void flash_get_offsets (ulong base, flash_info_t *info) info->start[i] = base + i * 0x00020000; } - } else { + } else { info->start[i--] = base + info->size - 0x00008000; info->start[i--] = base + info->size - 0x0000C000; @@ -275,7 +274,7 @@ static void flash_get_offsets (ulong base, flash_info_t *info) info->start[i] = base + i * 0x00010000; } - } else { + } else { info->start[i--] = base + info->size - 0x00004000; info->start[i--] = base + info->size - 0x00006000; @@ -404,12 +403,12 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info) /* Write auto select command: read Manufacturer ID */ -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT /* * Note: if it is an AMD flash and the word at addr[0000] - * is 0x00890089 this routine will think it is an Intel - * flash device and may(most likely) cause trouble. + * is 0x00890089 this routine will think it is an Intel + * flash device and may(most likely) cause trouble. */ addr[0x0000] = 0x00900090; @@ -421,8 +420,8 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info) /* * Note: if it is an AMD flash and the word at addr[0000] - * is 0x0089 this routine will think it is an Intel - * flash device and may(most likely) cause trouble. + * is 0x0089 this routine will think it is an Intel + * flash device and may(most likely) cause trouble. */ addr[0x0000] = 0x0090; @@ -565,17 +564,17 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info) info->flash_id += FLASH_28F320J3A; info->sector_count = 32; info->size = 0x00400000; - break; /* => 32 MBit */ + break; /* => 32 MBit */ case (INTEL_ID_28F640J3A & FLASH_ID_MASK): info->flash_id += FLASH_28F640J3A; info->sector_count = 64; info->size = 0x00800000; - break; /* => 64 MBit */ + break; /* => 64 MBit */ case (INTEL_ID_28F128J3A & FLASH_ID_MASK): info->flash_id += FLASH_28F128J3A; info->sector_count = 128; info->size = 0x01000000; - break; /* => 128 MBit */ + break; /* => 128 MBit */ default: /* FIXME*/ @@ -631,7 +630,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) if ((info->flash_id == FLASH_UNKNOWN) || ((info->flash_id > FLASH_AMD_COMP) && - ( (info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL ) ) ){ + ( (info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL ) ) ){ printf ("Can't erase unknown flash type - aborted\n"); return 1; } @@ -655,7 +654,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) /* Disable interrupts which might cause a timeout here */ flag = disable_interrupts(); if(info->flash_id < FLASH_AMD_COMP) { -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT addr[0x0555] = 0x00AA00AA; addr[0x02AA] = 0x00550055; addr[0x0555] = 0x00800080; @@ -696,7 +695,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) while ((addr[0] & (0x00800080&FLASH_ID_MASK)) != (0x00800080&FLASH_ID_MASK) ) { - if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) { + if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) { printf ("Timeout\n"); return 1; } @@ -717,7 +716,7 @@ DONE: for (sect = s_first; sect<=s_last; sect++) { if (info->protect[sect] == 0) { /* not protected */ barf = 0; -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT addr = (vu_long*)(info->start[sect]); addr[0] = 0x00200020; addr[0] = 0x00D000D0; @@ -768,7 +767,7 @@ DONE: flash_info_t *info; int i; - for (i=0, info=&flash_info[0]; i= info->start[0]) && (addr < (info->start[0] + info->size)) ) { return (info); @@ -845,7 +844,7 @@ DONE: int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) { -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT ulong cp, wp, data; int l; #else @@ -854,7 +853,7 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) #endif int i, rc; -#ifndef CFG_FLASH_16BIT +#ifndef CONFIG_SYS_FLASH_16BIT wp = (addr & ~3); /* get lower word aligned address */ @@ -981,150 +980,152 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) * 1 - write timeout * 2 - Flash not erased */ -#ifndef CFG_FLASH_16BIT -static int write_word (flash_info_t *info, ulong dest, ulong data) +#ifndef CONFIG_SYS_FLASH_16BIT +static int write_word (flash_info_t * info, ulong dest, ulong data) { - vu_long *addr = (vu_long*)(info->start[0]); - ulong start,barf; + vu_long *addr = (vu_long *) (info->start[0]); + ulong start, barf; int flag; /* Check if Flash is (sufficiently) erased */ - if ((*((vu_long *)dest) & data) != data) { + if ((*((vu_long *) dest) & data) != data) { return (2); } /* Disable interrupts which might cause a timeout here */ - flag = disable_interrupts(); + flag = disable_interrupts (); - if(info->flash_id > FLASH_AMD_COMP) { - /* AMD stuff */ - addr[0x0555] = 0x00AA00AA; - addr[0x02AA] = 0x00550055; - addr[0x0555] = 0x00A000A0; - } else { - /* intel stuff */ - *addr = 0x00400040; - } - *((vu_long *)dest) = data; + if (info->flash_id > FLASH_AMD_COMP) { + /* AMD stuff */ + addr[0x0555] = 0x00AA00AA; + addr[0x02AA] = 0x00550055; + addr[0x0555] = 0x00A000A0; + } else { + /* intel stuff */ + *addr = 0x00400040; + } + *((vu_long *) dest) = data; /* re-enable interrupts if necessary */ if (flag) - enable_interrupts(); + enable_interrupts (); /* data polling for D7 */ start = get_timer (0); - if(info->flash_id > FLASH_AMD_COMP) { + if (info->flash_id > FLASH_AMD_COMP) { - while ((*((vu_long *)dest) & 0x00800080) != (data & 0x00800080)) { - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) { - return (1); + while ((*((vu_long *) dest) & 0x00800080) != + (data & 0x00800080)) { + if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { + return (1); + } } - } - } else { + } else { - while(!(addr[0] & 0x00800080)){ /* wait for error or finish */ - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) { - return (1); - } + while (!(addr[0] & 0x00800080)) { /* wait for error or finish */ + if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { + return (1); + } - if( addr[0] & 0x003A003A) { /* check for error */ - barf = addr[0] & 0x003A0000; - if( barf ) { - barf >>=16; - } else { - barf = addr[0] & 0x0000003A; - } - printf("\nFlash write error at address %lx\n",(unsigned long)dest); - if(barf & 0x0002) printf("Block locked, not erased.\n"); - if(barf & 0x0010) printf("Programming error.\n"); - if(barf & 0x0008) printf("Vpp Low error.\n"); - return(2); - } + if (addr[0] & 0x003A003A) { /* check for error */ + barf = addr[0] & 0x003A0000; + if (barf) { + barf >>= 16; + } else { + barf = addr[0] & 0x0000003A; + } + printf ("\nFlash write error at address %lx\n", + (unsigned long) dest); + if (barf & 0x0002) + printf ("Block locked, not erased.\n"); + if (barf & 0x0010) + printf ("Programming error.\n"); + if (barf & 0x0008) + printf ("Vpp Low error.\n"); + return (2); + } - } + } - return (0); + return (0); -} + } #else -static int write_short (flash_info_t *info, ulong dest, ushort data) +static int write_short (flash_info_t * info, ulong dest, ushort data) { - vu_short *addr = (vu_short*)(info->start[0]); - ulong start,barf; + vu_short *addr = (vu_short *) (info->start[0]); + ulong start, barf; int flag; /* Check if Flash is (sufficiently) erased */ - if ((*((vu_short *)dest) & data) != data) { + if ((*((vu_short *) dest) & data) != data) { return (2); } /* Disable interrupts which might cause a timeout here */ - flag = disable_interrupts(); + flag = disable_interrupts (); - if(info->flash_id < FLASH_AMD_COMP) { - /* AMD stuff */ - addr[0x0555] = 0x00AA; - addr[0x02AA] = 0x0055; - addr[0x0555] = 0x00A0; - } else { - /* intel stuff */ - *addr = 0x00D0; - *addr = 0x0040; - } - *((vu_short *)dest) = data; + if (info->flash_id < FLASH_AMD_COMP) { + /* AMD stuff */ + addr[0x0555] = 0x00AA; + addr[0x02AA] = 0x0055; + addr[0x0555] = 0x00A0; + } else { + /* intel stuff */ + *addr = 0x00D0; + *addr = 0x0040; + } + *((vu_short *) dest) = data; /* re-enable interrupts if necessary */ if (flag) - enable_interrupts(); + enable_interrupts (); /* data polling for D7 */ start = get_timer (0); - if(info->flash_id < FLASH_AMD_COMP) { - /* AMD stuff */ - while ((*((vu_short *)dest) & 0x0080) != (data & 0x0080)) { - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) { - return (1); + if (info->flash_id < FLASH_AMD_COMP) { + /* AMD stuff */ + while ((*((vu_short *) dest) & 0x0080) != (data & 0x0080)) { + if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) { + return (1); + } } - } - } else { - /* intel stuff */ - while(!(addr[0] & 0x0080)){ /* wait for error or finish */ - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) return (1); - } + } else { + /* intel stuff */ + while (!(addr[0] & 0x0080)) { /* wait for error or finish */ + if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) + return (1); + } - if( addr[0] & 0x003A) { /* check for error */ - barf = addr[0] & 0x003A; - printf("\nFlash write error at address %lx\n",(unsigned long)dest); - if(barf & 0x0002) printf("Block locked, not erased.\n"); - if(barf & 0x0010) printf("Programming error.\n"); - if(barf & 0x0008) printf("Vpp Low error.\n"); - return(2); - } - *addr = 0x00B0; - *addr = 0x0070; - while(!(addr[0] & 0x0080)){ /* wait for error or finish */ - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) return (1); + if (addr[0] & 0x003A) { /* check for error */ + barf = addr[0] & 0x003A; + printf ("\nFlash write error at address %lx\n", + (unsigned long) dest); + if (barf & 0x0002) + printf ("Block locked, not erased.\n"); + if (barf & 0x0010) + printf ("Programming error.\n"); + if (barf & 0x0008) + printf ("Vpp Low error.\n"); + return (2); + } + *addr = 0x00B0; + *addr = 0x0070; + while (!(addr[0] & 0x0080)) { /* wait for error or finish */ + if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) + return (1); + } + *addr = 0x00FF; } - - *addr = 0x00FF; - - } - return (0); - } - - #endif - -/*----------------------------------------------------------------------- - */ - +/*-----------------------------------------------------------------------*/