📄 nordriver.c
字号:
wurj modify*/ unsigned int tempaddress = 0; tempaddress = (pVol->socket->window.baseAddress << 12) + address; #ifdef AT91_NOR_FLASH_16M_TO_32M if ((tempaddress > 0x10ffffff) && (tempaddress < 0x12000000)) { TFFS_NOR_DEBUG_PRINT(DEBUG_MAP, ("\namd29lvMap() tempaddress :0x%x\n",tempaddress)); tempaddress += 0x1000000; } #endif return ((void FAR0*)tempaddress); }/******************************************************************************** flashProgram16Bits - Program 16 bits at 2 byte aligned address.** RETURNS: OK or ERROR**/LOCAL STATUS flashProgram16Bits ( FLFlash* pVol, volatile UINT16* pData, UINT16 data, BOOL upper ) { BOOL programmed = FALSE; int timeout; flashUnlock(pVol, upper); flashRegWrite16Bits(pVol, 0x555, 0x00a000a0, upper); TFFS_NOR_DEBUG_PRINT(DEBUG_PROG32, ("Programming 0x%08x to %p, upper = %d\n", data, pData, upper)); *pData = data; CACHE_PIPE_FLUSH(); for (timeout = flMsecCounter + 3000; flMsecCounter < timeout;) { if (*pData == data) { programmed = TRUE; break; } taskDelay(0); } if (!programmed) { TFFS_NOR_DEBUG_PRINT(DEBUG_ALWAYS, ("Timeout\n")); return(ERROR); } return(OK); }#if 0/******************************************************************************** flashHalfSectorErase - Erase lower or upper half of sector.** RETURNS: OK or ERROR**/LOCAL STATUS flashHalfSectorErase ( FLFlash* pVol, int sectorNum, BOOL upper ){ BOOL erased = FALSE; int timeout = sysClkRateGet() * 5; UINT32 offset; UINT32 size; volatile UINT32* pFlash; UINT32 sectorAddr; if (pVol->type == 0x017e) /* amd29LV160BT */ { offset = sectorNum * S29GL_N_256_MTD_SECTOR_SIZE; size = S29GL_N_256_MTD_SECTOR_SIZE; sectorAddr = (sectorNum << 15); } else if (pVol->type == 0x1C4) /* amd29LV160BT */ { /* Sectors 31 - 34 are funky sizes */ switch (sectorNum) { case 31: offset = 0x7c0000; size = 0x20000; sectorAddr = 0xf8000; break; case 32: offset = 0x7e0000; size = 0x8000; sectorAddr = 0xfc000; break; case 33: offset = 0x7e8000; size = 0x8000; sectorAddr = 0xfd000; break; case 34: offset = 0x7f0000; size = 0x10000; sectorAddr = 0xfe000; break; default: offset = sectorNum * AMD29LV_MTD_SECTOR_SIZE; size = AMD29LV_MTD_SECTOR_SIZE; sectorAddr = (sectorNum << 15); } } else if (pVol->type == 0x149) /* amd29LV160d */ { /* Sectors 31 - 34 are funky sizes */ switch (sectorNum) { case 0: case 1: case 2: case 3: default: offset = sectorNum * AMD29LV_160_D_MTD_SECTOR_SIZE; size = AMD29LV_160_D_CHIP_SIZE; sectorAddr = (sectorNum << 15); } } else /* amd29LV323CT */ { /* Sectors 63 - 70 are 1/8th size of other sectors */ if (sectorNum < AMD29LV_323_LAST_SECTOR_NUM) { offset = sectorNum * AMD29LV_MTD_SECTOR_SIZE; size = AMD29LV_MTD_SECTOR_SIZE; sectorAddr = (sectorNum << 15); } else { offset = AMD29LV_323_LAST_SECTOR_NUM * AMD29LV_MTD_SECTOR_SIZE; offset += (sectorNum - AMD29LV_323_LAST_SECTOR_NUM) * AMD29LV_323_LAST_SECTOR_SIZE; size = AMD29LV_323_LAST_SECTOR_SIZE; sectorAddr = (AMD29LV_323_LAST_SECTOR_NUM << 15); sectorAddr += ((sectorNum - AMD29LV_323_LAST_SECTOR_NUM) << 12); } } TFFS_NOR_DEBUG_PRINT(DEBUG_ERASE, ("Erasing sector %d, 0x%02x, upper = %d\n", sectorNum, sectorAddr, upper)); /* Erase the sector half */ flashUnlock(pVol, upper); flashRegWrite16Bits(pVol, 0x555, 0x00800080, upper); flashUnlock(&vol, upper); flashRegWrite16Bits(pVol, sectorAddr, 0x00300030, upper); pFlash = (volatile UINT32*) pVol->map(pVol, offset, size); if (upper) pFlash++; /* Sector's upper/lower half erased? If not, return ERROR */ for (timeout = flMsecCounter + 5000; flMsecCounter < timeout;) { if (*pFlash == 0xffffffff) { erased = TRUE; break; } } if (!erased) { TFFS_NOR_DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase timeout, %p\n", pFlash)); return(ERROR); } return(OK); }#endif/******************************************************************************** flashSectorErase - Erase sector.** RETURNS: OK or ERROR**/LOCAL STATUS flashSectorErase ( FLFlash* pVol, int sectorNum, BOOL upper ){ BOOL erased = FALSE; int timeout = sysClkRateGet() * 5; volatile UINT16* pFlash = NULL; UINT32 sectorAddr = 0; UINT32 tempaddr = 0;/*add wurj*/ switch(pVol->type) { case 0x017e: sectorAddr = sectorNum * S29GL_N_256_MTD_SECTOR_SIZE; break; default: printf("Unknown medium type.\r\n"); return ERROR; } /*TFFS_NOR_DEBUG_PRINT(DEBUG_ERASE, ("Erasing sector %d, 0x%02x, upper = %d\n", sectorNum, sectorAddr, upper)); printf("\nErasing sector %d, 0x%02x, upper = %d",sectorNum, sectorAddr, upper) delete by wurj*/; printf("........ "); /* Erase the sector half */ flashUnlock(pVol, upper); flashRegWrite16Bits(pVol, 0x555, 0x00800080, upper); flashUnlock(&vol, upper); #if 0 flashRegWrite16Bits(pVol, sectorAddr, 0x00300030, upper);#else #if 0 *((volatile UINT16*) ((pVol->socket->window.baseAddress << 12) + sectorAddr)) = (UINT16)0x0030; #else tempaddr = ((pVol->socket->window.baseAddress << 12) + sectorAddr); #ifdef AT91_NOR_FLASH_16M_TO_32M if((tempaddr >= 0x11000000) && (tempaddr < 0x12000000)) { TFFS_NOR_DEBUG_PRINT(DEBUG_ERASE, ("\n\tflashSectorErase() tempaddr:0x%x > 0x11000000\n\t",tempaddr)); tempaddr += 0x1000000; } #endif *((volatile UINT16*)tempaddr) = (UINT16)0x0030; /*add by wurj*/ #endif#endif pFlash = (volatile UINT16*) pVol->map(pVol, sectorAddr, S29GL_N_256_MTD_SECTOR_SIZE); if (upper) pFlash++; /* Sector's upper/lower half erased? If not, return ERROR */ for (timeout = flMsecCounter + 5000; flMsecCounter < timeout;) { if (*pFlash == (UINT16)0xffff) { erased = TRUE; break; } } if (!erased) { TFFS_NOR_DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase timeout, %p\n", pFlash)); return(ERROR); } return(OK); }/******************************************************************************** flashRegWrite16Bits - Write 16 bits to 2 byte aligned address.** RETURNS: N/A**/LOCAL void flashRegWrite16Bits ( FLFlash* pVol, UINT32 addr, UINT32 data, BOOL upper ){#if 1 *((volatile UINT16*) (pVol->socket->window.baseAddress << 12) + addr) = (UINT16)data; /*TFFS_NOR_DEBUG_PRINT(DEBUG_WRITE, ("Writing 0x%08x to 0x%08x\n", data, addr));delete by wurj*/ CACHE_PIPE_FLUSH();#else/*MODIFY by wurj */ UINT32 tempaddr = 0; tempaddr = ((pVol->socket->window.baseAddress << 12) + addr*2); #ifdef AT91_NOR_FLASH_16M_TO_32M if((tempaddr >= 0x11000000) && (tempaddr < 0x12000000)) { printf("\n\tflashRegWrite16Bits() tempaddr:0x%x > 0x11000000\n\t",tempaddr); tempaddr += 0x1000000; }#endif *((volatile UINT16*) tempaddr) = (UINT16)data; /*TFFS_NOR_DEBUG_PRINT(DEBUG_WRITE, ("Writing 0x%08x to 0x%08x\n", data, addr));wurj*/ CACHE_PIPE_FLUSH();#endif}/******************************************************************************** flashRegRead16Bits - Read 16 bits from 2 byte aligned address.** RETURNS: data at specified address**/LOCAL UINT16 flashRegRead16Bits ( FLFlash* pVol, UINT32 addr, BOOL upper ) { UINT16 data; #if 0 UINT32 flashBaseAddr = (pVol->socket->window.baseAddress << 12); addr = flashBaseAddr + 8 * addr; if (upper) addr += 4; data = *((volatile UINT16*) addr); #else #if 1 data = *((volatile UINT16*)(pVol->socket->window.baseAddress << 12) + addr); #else/*wurj*/ unsigned int tempaddress = 0; tempaddress = (pVol->socket->window.baseAddress << 12) + addr*2; #ifdef AT91_NOR_FLASH_16M_TO_32M if((tempaddress >= 0x11000000)&&( tempaddress < 0x12000000)) { tempaddress += 0x1000000; TFFS_NOR_DEBUG_PRINT(DEBUG_READ, ("\nflashRegRead16Bitsn() tempaddr:0x%x\n", (UINT32)tempaddr)); } #endif /* AT91_NOR_FLASH_16M_TO_32M */ data = *((volatile UINT16*)tempaddress); #endif#endif TFFS_NOR_DEBUG_PRINT(DEBUG_READ, ("Read 0x%08x from 0x%08x\n", data, addr)); CACHE_PIPE_FLUSH(); return(data); }/******************************************************************************** flashIdGet - Get flash man. and device codes.** RETURNS: N/A**/LOCAL void flashIdGet ( FLFlash* pVol, UINT16* manCode, UINT16* devCode ) { flashUnlock(pVol, FALSE); flashRegWrite16Bits(pVol, 0x555, 0x00900090, FALSE); *manCode = flashRegRead16Bits(pVol, 0x00, FALSE); *devCode = flashRegRead16Bits(pVol, 0x01, FALSE); flashReset(pVol, FALSE); }/******************************************************************************** flashUnlock - Write unlock sequence to upper or lower flash section.** RETURNS: N/A**/LOCAL void flashUnlock ( FLFlash* pVol, BOOL upper ) { flashRegWrite16Bits(pVol, 0x555, 0x00aa00aa, upper); flashRegWrite16Bits(pVol, 0x2aa, 0x00550055, upper); }/******************************************************************************** flashReset - Write reset sequence to upper or lower flash section.** RETURNS: N/A**/LOCAL void flashReset ( FLFlash* pVol, BOOL upper ) { flashRegWrite16Bits(pVol, 0, 0x00f000f0, upper); }#endif /* INCLUDE_TFFS */#ifdef INCLUDE_NOR_FLASH/*-----------------------------------------------------------------------------Function: amd_flash_cmd_erase_chipOverview: Input: NoneOutput: NoneReturn: None-----------------------------------------------------------------------------*/STATUS amd_flash_cmd_erase_chip(){ UINT32 i = 0; *((volatile UINT16 *)ROM_BASE_ADRS+0x555) = 0xAA; *((volatile UINT16 *)ROM_BASE_ADRS+0x2AA) = 0x55; *((volatile UINT16 *)ROM_BASE_ADRS+0x555) = 0x80; *((volatile UINT16 *)ROM_BASE_ADRS+0x555) = 0xAA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -