#include #include #include #include #include #include #include #include #include #include #include #include #include "cfi.h" static int Init_WinbondFlash(void); #define BL_PHY 0 #define BL_IC_PLUS 1 #define BL_MARVELL6052 2 tbl_info info; DECLARE_MUTEX(spare_lock); #define _DEBUG #undef _DEBUG #define MALLOC(x) kmalloc((x), GFP_KERNEL) #define FREE kfree #define MEMCPY memcpy //or use "copy_to_user" //yyang1 030605 ??? int __init Init_WinbondFlash(void) { if (cfiGetFlashInfo() == -1) { printk("No supported flash detected!\n"); return -EINVAL; } return 0; } asmlinkage int sys_ReadWinbondFlash(unsigned long pos, unsigned long length, char * buffer) { // if(!pCurFlash) // return -EINVAL; if(cfiGetFlashSize() <= 0) return(-EINVAL); #ifdef _DEBUG printk("\nWinbondFlash Read: pos = %x, length = %d, buffer = 0x%x.\n", pos, length, buffer); #endif if(length%2) length++; down(&spare_lock); if(copy_to_user(buffer, (void*)(FLASH_BASE | pos), length)) { up(&spare_lock); return -EFAULT; } up(&spare_lock); return length; } static int _FlashWrite(char *pcBuf, int iBufLen, int iOffset); asmlinkage int sys_WriteWinbondFlash(unsigned long pos, unsigned long length, char * buffer) { // if(!pCurFlash) // return -EINVAL;; if(cfiGetFlashSize() <= 0) return(-EINVAL); #ifdef _DEBUG printk("\nWinbondFlash Write: pos = %x, length = %d, buffer = 0x%x.\n", pos, length, buffer); #endif return _FlashWrite(buffer, length, pos); } asmlinkage int sys_WinbondFlashBlockSize(unsigned long pos) { if(cfiGetFlashSize() == 0) return -EINVAL;; #ifdef _DEBUG printk("\nWinbondFlash BlockSize: pos = %d.\n", pos); #endif pos |= FLASH_BASE; return cfiGetBlockSize(pos); } asmlinkage int sys_WinbondFlashTotalSize(void) { printk("sys_WinbondFlashTotalSize\n"); return cfiGetFlashSize(); } asmlinkage int sys_WinbondFlashBase(void) { return FLASH_BASE; } static int _FlashWrite(char *pcBuf, int iBufLen, int iOffset) { // unsigned long flags; UINT32 blockSize,src,dest; INT i; if (cfiGetFlashSize() == 0) return -EINVAL; #ifdef _DEBUG printk("\nWinbondFlash _FlashWrite: pos = %x, length = %d, buffer = 0x%x.\n", iOffset, iBufLen, pcBuf); #endif //i = iBufLen; i=(iBufLen%2)?(iBufLen+1):iBufLen; src = (UINT32)pcBuf; dest = (iOffset%2)?(iOffset+1):iOffset | FLASH_BASE; //CSR_WRITE(WTCR, (CSR_READ(WTCR)&0xF7)|0x01);//clyu reset watch dog while (i>0) { volatile UINT32 buf; volatile UINT32 addr; UINT32 count; int len; blockSize = cfiGetBlockSize(dest); if(blockSize<=0) return 0; #ifdef _DEBUG //#if 1 printk("\n_FlashWrite:dest:%x,cur blockSize:%x\n",dest,blockSize); #endif addr=dest&~(blockSize-1); for(len=0;len=i)||((len+dest-addr)>=cfiGetBlockSize(dest))) { if((dest&(blockSize-1))||(dest+i-addr)<=blockSize) { #ifdef _DEBUG printk("Write direct\n"); #endif if(i