X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=board%2Ftrab%2Fflash.c;h=4e89c4102728fae360049346aac63acfa1c946ce;hb=530135dcacac278798346ad5825c03131ce51772;hp=a2a21c6d25e6bf5d40faa597c63ad93116d7470a;hpb=3b57fe0a70b903f4db66c558bb9828bc58acf06b;p=u-boot diff --git a/board/trab/flash.c b/board/trab/flash.c index a2a21c6d25..4e89c41027 100644 --- a/board/trab/flash.c +++ b/board/trab/flash.c @@ -1,6 +1,6 @@ /* * (C) Copyright 2002 - * Gary Jennejohn, DENX Software Engineering, + * Gary Jennejohn, DENX Software Engineering, * * See file CREDITS for list of people who contributed to this * project. @@ -28,7 +28,7 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info); -flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; +flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; #define CMD_READ_ARRAY 0x00F000F0 @@ -39,9 +39,12 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; #define CMD_PROGRAM 0x00A000A0 #define CMD_UNLOCK_BYPASS 0x00200020 #define CMD_READ_MANF_ID 0x00900090 +#define CMD_UNLOCK_BYPASS_RES1 0x00900090 +#define CMD_UNLOCK_BYPASS_RES2 0x00000000 -#define MEM_FLASH_ADDR1 (*(volatile u32 *)(CFG_FLASH_BASE + (0x00000555 << 2))) -#define MEM_FLASH_ADDR2 (*(volatile u32 *)(CFG_FLASH_BASE + (0x000002AA << 2))) +#define MEM_FLASH_ADDR (*(volatile u32 *)CONFIG_SYS_FLASH_BASE) +#define MEM_FLASH_ADDR1 (*(volatile u32 *)(CONFIG_SYS_FLASH_BASE + (0x00000555 << 2))) +#define MEM_FLASH_ADDR2 (*(volatile u32 *)(CONFIG_SYS_FLASH_BASE + (0x000002AA << 2))) #define BIT_ERASE_DONE 0x00800080 #define BIT_RDY_MASK 0x00800080 @@ -60,17 +63,17 @@ ulong flash_init (void) int i, j; ulong size = 0; - for (i=0; iflash_id = FLASH_UNKNOWN; - size += flash_get_size (CFG_FLASH_BASE, info); + size += flash_get_size (CONFIG_SYS_FLASH_BASE, info); if (i == 0) - flashbase = CFG_FLASH_BASE; + flashbase = CONFIG_SYS_FLASH_BASE; else panic ("configured too many flash banks!\n"); for (j = 0; j < info->sector_count; j++) { @@ -80,6 +83,7 @@ ulong flash_init (void) switch (info->flash_id & FLASH_TYPEMASK) { case (FLASH_AM320B & FLASH_TYPEMASK): + case (FLASH_MXLV320B & FLASH_TYPEMASK): /* Boot sector type: 8 x 8 + N x 128 kB */ flashbase += (j < 8) ? 0x4000 : 0x20000; break; @@ -98,18 +102,18 @@ ulong flash_init (void) * Protect monitor and environment sectors */ flash_protect ( FLAG_PROTECT_SET, - CFG_FLASH_BASE, - CFG_FLASH_BASE + monitor_flash_len - 1, + CONFIG_SYS_FLASH_BASE, + CONFIG_SYS_FLASH_BASE + monitor_flash_len - 1, &flash_info[0]); flash_protect ( FLAG_PROTECT_SET, - CFG_ENV_ADDR, - CFG_ENV_ADDR + CFG_ENV_SIZE - 1, &flash_info[0]); + CONFIG_ENV_ADDR, + CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, &flash_info[0]); -#ifdef CFG_ENV_ADDR_REDUND +#ifdef CONFIG_ENV_ADDR_REDUND flash_protect ( FLAG_PROTECT_SET, - CFG_ENV_ADDR_REDUND, - CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1, + CONFIG_ENV_ADDR_REDUND, + CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, &flash_info[0]); #endif @@ -127,6 +131,8 @@ void flash_print_info (flash_info_t * info) printf ("AMD "); break; case (FLASH_MAN_FUJ & FLASH_VENDMASK): printf ("FUJITSU "); break; + case (FLASH_MAN_MX & FLASH_VENDMASK): + printf ("MACRONIX "); break; default: printf ("Unknown Vendor "); break; } @@ -134,6 +140,9 @@ void flash_print_info (flash_info_t * info) case (FLASH_AM320B & FLASH_TYPEMASK): printf ("2x Am29LV320DB (32Mbit)\n"); break; + case (FLASH_MXLV320B & FLASH_TYPEMASK): + printf ("2x MX29LV320DB (32Mbit)\n"); + break; case (FLASH_AM640U & FLASH_TYPEMASK): printf ("2x Am29LV640D (64Mbit)\n"); break; @@ -157,7 +166,7 @@ void flash_print_info (flash_info_t * info) } printf ("\n"); - Done: +Done: ; } /*----------------------------------------------------------------------- @@ -188,6 +197,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) switch (info->flash_id & FLASH_VENDMASK) { case (FLASH_MAN_AMD & FLASH_VENDMASK): break; /* OK */ case (FLASH_MAN_FUJ & FLASH_VENDMASK): break; /* OK */ + case (FLASH_MAN_MX & FLASH_VENDMASK): break; /* OK */ default: debug ("## flash_erase: unknown manufacturer\n"); return (ERR_UNKNOWN_FLASH_VENDOR); @@ -247,7 +257,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) result = *addr; /* check timeout */ - if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) { + if (get_timer_masked () > CONFIG_SYS_FLASH_ERASE_TOUT) { MEM_FLASH_ADDR1 = CMD_READ_ARRAY; chip1 = TMO; break; @@ -271,10 +281,12 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) if (chip1 == ERR || chip2 == ERR) { rc = ERR_PROG_ERROR; + printf ("Flash erase error\n"); goto outahere; } if (chip1 == TMO) { rc = ERR_TIMOUT; + printf ("Flash erase timeout error\n"); goto outahere; } } @@ -298,8 +310,7 @@ outahere: * Copy memory to flash */ -volatile static int write_word (flash_info_t * info, ulong dest, - ulong data) +static int write_word (flash_info_t * info, ulong dest, ulong data) { vu_long *addr = (vu_long *) dest; ulong result; @@ -333,8 +344,7 @@ volatile static int write_word (flash_info_t * info, ulong dest, MEM_FLASH_ADDR1 = CMD_UNLOCK1; MEM_FLASH_ADDR2 = CMD_UNLOCK2; - MEM_FLASH_ADDR1 = CMD_UNLOCK_BYPASS; - *addr = CMD_PROGRAM; + MEM_FLASH_ADDR1 = CMD_PROGRAM; *addr = data; /* arm simple, non interrupt dependent timer */ @@ -346,7 +356,7 @@ volatile static int write_word (flash_info_t * info, ulong dest, result = *addr; /* check timeout */ - if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) { + if (get_timer_masked () > CONFIG_SYS_FLASH_WRITE_TOUT) { chip1 = ERR | TMO; break; } @@ -378,8 +388,13 @@ volatile static int write_word (flash_info_t * info, ulong dest, *addr = CMD_READ_ARRAY; - if (chip1 == ERR || chip2 == ERR || *addr != data) + if (chip1 == ERR || chip2 == ERR || *addr != data) { rc = ERR_PROG_ERROR; + printf ("Flash program error\n"); + debug ("chip1: %#x, chip2: %#x, addr: %#lx *addr: %#lx, " + "data: %#lx\n", + chip1, chip2, addr, *addr, data); + } if (iflag) enable_interrupts (); @@ -422,7 +437,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) } if ((rc = write_word (info, wp, data)) != 0) { - return (rc); + goto Done; } wp += 4; } @@ -439,9 +454,9 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) else { data = *((vu_long *) src); } - + if ((rc = write_word (info, wp, data)) != 0) { - return (rc); + goto Done; } src += 4; wp += 4; @@ -449,7 +464,8 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) } if (cnt == 0) { - return ERR_OK; + rc = ERR_OK; + goto Done; } /* @@ -464,7 +480,11 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) data = (data >> 8) | (*(uchar *) cp << 24); } - return write_word (info, wp, data); + rc = write_word (info, wp, data); + + Done: + + return (rc); } /*----------------------------------------------------------------------- @@ -490,11 +510,14 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info) case FUJ_MANUFACT: info->flash_id = FLASH_MAN_FUJ; break; + case MX_MANUFACT: + info->flash_id = FLASH_MAN_MX; + break; default: info->flash_id = FLASH_UNKNOWN; info->sector_count = 0; info->size = 0; - addr[0] = 0x00FF00FF; /* restore read mode */ + addr[0] = CMD_READ_ARRAY; /* restore read mode */ debug ("## flash_init: unknown manufacturer\n"); return (0); /* no or unknown flash */ } @@ -509,7 +532,7 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info) info->sector_count = 71; info->size = 0x00800000; - addr[0] = 0x00FF00FF; /* restore read mode */ + addr[0] = CMD_READ_ARRAY; /* restore read mode */ break; /* => 8 MB */ case AMD_ID_LV640U: @@ -517,21 +540,29 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info) info->sector_count = 128; info->size = 0x01000000; - addr[0] = 0x00F000F0; /* restore read mode */ + addr[0] = CMD_READ_ARRAY; /* restore read mode */ break; /* => 16 MB */ + case MX_ID_LV320B: + info->flash_id += FLASH_MXLV320B; + info->sector_count = 71; + info->size = 0x00800000; + + addr[0] = CMD_READ_ARRAY; /* restore read mode */ + break; /* => 8 MB */ + default: debug ("## flash_init: unknown flash chip\n"); info->flash_id = FLASH_UNKNOWN; - addr[0] = 0x00FF00FF; /* restore read mode */ + addr[0] = CMD_READ_ARRAY; /* restore read mode */ return (0); /* => no or unknown flash */ } - if (info->sector_count > CFG_MAX_FLASH_SECT) { + if (info->sector_count > CONFIG_SYS_MAX_FLASH_SECT) { printf ("** ERROR: sector count %d > max (%d) **\n", - info->sector_count, CFG_MAX_FLASH_SECT); - info->sector_count = CFG_MAX_FLASH_SECT; + info->sector_count, CONFIG_SYS_MAX_FLASH_SECT); + info->sector_count = CONFIG_SYS_MAX_FLASH_SECT; } return (info->size);