📄 romdrv.c
字号:
temp2 = (U32)FlashWriteByte;
FlashWriteByteP = tempP + temp2 - temp1;
temp2 = (U32)FlashWriteBlockWord;
FlashWriteBlockWordP = tempP + temp2 - temp1;
temp2 = (U32)FlashWriteBlock;
FlashWriteBlockP = tempP + temp2 - temp1;
}
unsigned long FlashReadBlock( U32 buffer, U32 Address, unsigned long len )
{
*(U32 *)Address = 0xff00ff; //gfd read status
memcpy( (void *)buffer, (void *)Address, len );
return 0;
}
#else
void FlashUnlockBlock(U32 Address)
{
U32 tempAddr = 0;
U32 counter = 0;
U32 temp = 0;
U16 j = 0;
tempAddr = Address - (Address & 0x1); // add 16bit age wuer
*(R_U16)tempAddr = 0x0060;
*(R_U16)tempAddr = 0x00d0;
*(R_U16)tempAddr = 0x0070;
for(j=0; j<0x100; j++);
temp = *(R_U16)tempAddr;
while( (temp & 0x0080) != 0x0080 )
{
if(counter++>0x1000)
{
break;
//return ~E_OK;
}
*(R_U16)tempAddr = 0x0070;
for(j=0; j<0x100; j++);
temp = *(R_U16)Address ;
}
}
void FlashLockBlock(U32 Address)
{
U32 tempAddr = 0;
U32 counter = 0;
U32 temp = 0;
U16 j = 0;
tempAddr = Address - (Address & 0x1); // add 16bit age wuer
*(R_U16)tempAddr = 0x0060;
*(R_U16)tempAddr = 0x0001;
*(R_U16)tempAddr = 0x0070;
for(j=0; j<0x100; j++);
temp = *(R_U16)tempAddr;
while( (temp & 0x0080) != 0x0080 )
{
if(counter++>0x1000)
{
break;
//return ~E_OK;
}
*(R_U16)tempAddr = 0x0070;
for(j=0; j<0x100; j++);
temp = *(R_U16)Address ;
}
*(R_U16)tempAddr = 0x00ff;
}
void FlashEraseBlock(U32 Address)
{
R_U16 tempAddr;
U32 temp = 0;
U32 IMRTemp =0 ;
U32 counter = 0;
U32 Sr = 0;
tempAddr = (R_U16)(Address - (Address & 0x1));
*tempAddr = 0x0020;
*tempAddr = 0x00d0;
for(Sr=0; Sr<80000; Sr++); // wait time for erase operation
*tempAddr = 0x0070;
temp = *tempAddr;
while( (temp & 0x0080) != 0x0080)
{
*tempAddr = 0x0070;
for(Sr=0; Sr<20000; Sr++);
(U16)temp = *tempAddr;
counter++;
if(counter > 10000)
break;
}
*tempAddr = 0x00ff;
}
U8 FlashWriteByte(U32 Address, U8 Data)
{
U32 IMRTemp,k;
U16 temp,mid;
R_U16 tempAddr;
U32 counter = 0;
U16 tempdata = Data;
U16 retrytimes = 0;
U16 datasave = 0;
RETRY_WRITE_BYTE:
datasave = *(R_U16)(Address - (Address & 0x01));
if( (Address & 0x01 ) == 0)
{
temp = tempdata | (datasave & 0xff00);
}
else if( (Address & 0x01 ) == 0x1)
{
temp = (tempdata << 8) | (datasave & 0xffff00ff);
}
tempAddr = (R_U16)( Address - (Address&0x01));
*tempAddr = 0x40;
*tempAddr = temp;
for(k=0; k<600; k++);
*tempAddr = 0x70;
mid = *tempAddr;
while( (mid & 0x80) != 0x80)
{
*tempAddr = 0x70;
mid = *tempAddr;
for(k=0; k<600; k++);
counter++;
if(counter > 1000)
break;
}
*tempAddr = 0x50;
*tempAddr = 0xff;
if(*tempAddr != temp) //judge
{
if(retrytimes++ <5)
goto RETRY_WRITE_BYTE; ////gfd
return(Address);
}
}
U32 FlashWriteBlockWord(U32 Address, U32 DataPoint, U32 len) //len--byte numbers; need modify deeplier
{
U32 i,mid,rawAddress,k;
S32 lenX;
U32 num, r;
R_U16 tempAddr;
U16 temp, temp16;
U32 counter;
U32 retrytimes=0;
rawAddress = Address;
if( (len==0) | (len < 0))
return(0);
if(len == 1)
{
for(i = 0; i < len; i++)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
return( 0);
}
if( (Address & 0x01) != 0x0) //byte opreation
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
len = len -1;
}
lenX = len;
num = lenX>>1;
r = lenX & 0x01;
for(i = 0; i < num; i++) // half word opreation
{
RETRY_WRITE:
tempAddr = (R_U16)(Address);
if(DataPoint & 0x01)
{
temp = *(P_U8)DataPoint;
DataPoint +=1;
temp16= *(P_U8)DataPoint;
temp |= (temp16 <<8);
DataPoint +=1;
}
else temp = *(R_U16)DataPoint;
*tempAddr = 0x40;
*tempAddr = temp;
for(k=0; k<600; k++);
counter = 0;
*tempAddr = 0x70;
mid = *tempAddr;
while( (mid & 0x80) != 0x80)
{
*tempAddr = 0x70;
mid = *tempAddr;
counter++;
if(counter > 10000000)
break;
}
*tempAddr = 0xff;
if(*tempAddr != temp) //judge
{
if(retrytimes++ <5)
goto RETRY_WRITE; ////gfd
return(Address);
}
Address += 2 ;
DataPoint += 2;
}
for(i = 0; i < r; i++) //fill left butes of lenX
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
*tempAddr = 0xff;
return(0);
}
U32 FlashWriteBlock(U32 Address, U32 DataPoint, U32 len)
{
U32 i;
S32 lenX;
U32 IMRTemp, rawAddress;
R_U16 tempAddr;
U16 x,y,temp;
U32 mid;
P_U8 addr8;
U8 temp8;
U32 counter = 0;
U32 BufferCount = 0;
U32 counter1 = 0;
rawAddress = Address;
lenX = len;
if( lenX==0 )
return(0);
if( (Address & 0x1) != 0x0) //judge adress end, and fill fore superabundance bytes.
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
lenX = lenX -1;
}
tempAddr = (R_U16)Address; // 需要仔细推敲下,wuer
while(counter < lenX)
{
if( ( (U32)tempAddr + 16) / 0x2000 == (U32)tempAddr / 0x2000)
if( (counter + 16) > lenX )
BufferCount = (lenX - counter) / 2;
else
BufferCount = 16;
else
BufferCount = ( ( ( (U32)tempAddr / 0x2000) + 1) * 0x2000 - (U32)tempAddr) / 2;
if(BufferCount < 16)
{
(*FlashWriteBlockWordP)( (U32)tempAddr, DataPoint, BufferCount * 2);
tempAddr += BufferCount;
DataPoint += BufferCount * 2;
counter += BufferCount * 2;
}
else
{
counter1 = 0x0;
*(U16 *)tempAddr = 0xe8;
while(( (*tempAddr) & 0x80) != 0x80)
{
counter1++;
if(counter1 > 10000000)
break;
}
*tempAddr = 16 - 1;
counter += BufferCount * 2;
for(i = 0; i < 16; i++)
{
temp = *(R_U16)DataPoint;
*tempAddr = temp;
DataPoint += 2;
tempAddr++;
}
*(tempAddr - 1) = 0xd0;
counter1 = 0x0;
mid = *(tempAddr - 1);
*(tempAddr - 1) = 0x70;
while( (mid & 0x80) != 0x80)
{
*(tempAddr - 1) = 0x70;
mid = *(tempAddr - 1);
counter1++;
if(counter1 > 10000000)
break;
}
*(tempAddr - 1) = 0x50;
*(tempAddr - 1) = 0xff;
}
}
Address = (P_U8)tempAddr;
if(lenX != len)
{
for(i = 0; i < (lenX -lenX); i++) //fill left butes of lenX
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
}
}
return(0);
}
void CopyFlashProgram()
{
P_U8 copyP,tempP;
U32 temp1,temp2,len;
len = (U32)CopyFlashProgram - (U32)FlashUnlockBlock;
tempP = (P_U8)SysLmalloc(len);
copyP = (P_U8)FlashUnlockBlock;
MoveBlock((R_U32)copyP, (R_U32)tempP, len);
FlashUnlockBlockP=tempP;
temp1 = (U32)FlashUnlockBlock;
temp2 = (U32)FlashLockBlock;
FlashLockBlockP = tempP + temp2 - temp1;
temp2 = (U32)FlashEraseBlock;
FlashEraseBlockP = tempP + temp2 - temp1;
temp2 = (U32)FlashWriteByte;
FlashWriteByteP = tempP + temp2 - temp1;
temp2 = (U32)FlashWriteBlockWord;
FlashWriteBlockWordP = tempP + temp2 - temp1;
temp2 = (U32)FlashWriteBlock;
FlashWriteBlockP = tempP + temp2 - temp1;
}
unsigned long FlashReadBlock( U32 buffer, U32 Address, unsigned long len )
{
*(U16 *)Address = 0x00ff; //gfd read status
memcpy( (void *)buffer, (void *)Address, len );
return 0;
}
#endif
void drv_flash_write ( unsigned char *data, unsigned int start, unsigned int size )
{
#ifdef NORFLASH
//// (*FlashUnlockBlockP)(start);
(*FlashEraseBlockP)(start);
(*FlashWriteBlockP)( start, data, size );
//// (*FlashLockBlockP)( start ); ////gfd 0813
#else //NAND FLASH
nand_write(start, size, data);
#endif
}
void drv_flash_read ( unsigned char *data, unsigned int start, unsigned int size )
{
#ifdef NORFLASH
FlashReadBlock( data, start, size );
#else //NAND FLASH
nand_read(start, size, data);
#endif
}
UINT8 *norflash_rd_alloc_page(VOID)
{
return((UINT8 *)0);
}
VOID norflash_rd_free_page(UINT8 *page)
{
}
INT norflash_rd_open(UINT16 driveno)
{
return(YES);
}
INT norflash_rd_close(UINT16 driveno)
{
return(YES);
}
extern INT norflash_rd_io(U16 driveno, U32 page, VOID *buffer, U16 count, INT do_read)
{
UINT8 *p;
UINT32 ltemp,tempblknum;
UINT32 page_number;
UINT32 byte_number;
UINT32 pageoffset = 0;
INT16 i;
UINT8 *pbuffer, *ptempbuffer;
INT flag;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
pbuffer = (UINT8 *)buffer;
flag = do_read;
flag &= 1;
while (count)
{
byte_number = 512*(page & 0x1ff);
tempblknum = (page >> 9);
/* Check. This shouldn't happen */
//if ( (page_number >= NUM_RAMDISK_PAGES) || !nor_rd_pages[page_number] )
// return(NO);
if(tempblknum != g_nor_blknum)
{
if (flag)
{
p = (UINT8 *)(OLD_START_ADDRESS + page * 512);
drv_flash_read(( unsigned char *)(pbuffer + (pageoffset++)*512), (unsigned int *)p, 512 );
}
else
{
drv_flash_write (( unsigned char *) g_nor_buf,( unsigned int *) (g_nor_blknum*512*512 + OLD_START_ADDRESS), FLASH_AREA_SIZE );
drv_flash_read(( unsigned char *)g_nor_buf, (unsigned int *)(tempblknum*512*512 + OLD_START_ADDRESS), FLASH_AREA_SIZE);
for (i = 0; i < 512; i++)
g_nor_buf[byte_number+i] = *pbuffer++;
g_nor_blknum = tempblknum;
}
}
else
{
if (flag)
{
for (i = 0; i < 512; i++)
*pbuffer++ = g_nor_buf[byte_number+i] ;
}
else
{
for (i = 0; i < 512; i++)
g_nor_buf[byte_number+i] = *pbuffer++;
}
}
count--;
page++;
}
if(do_read&FLUSH)
drv_flash_write (( unsigned char *) g_nor_buf,( unsigned int *) (g_nor_blknum*512*512 + OLD_START_ADDRESS), FLASH_AREA_SIZE );
return(YES);
}
INT norflash_rd_raw_open(UINT16 driveno)
{
}
INT norflash_rd_ioctl(UINT16 driveno, UINT16 command, VOID *buffer)
{
}
void norflash_flush(void)
{
drv_flash_write (( unsigned char *) g_nor_buf,( unsigned int *) (g_nor_blknum*512*512 + OLD_START_ADDRESS), FLASH_AREA_SIZE );
}
int norflash_write_page_format(U32 page, U32 *buffer, U32 do_read)
{
int i;
U8 *tmpbuffer;
U8 *tmpaddr;
tmpbuffer = (U8 *)buffer;
tmpaddr = (U8 *)(page<<9);
for(i = 0; i < 512; i++)
{
FlashWriteByte(tmpaddr,*tmpbuffer);
tmpbuffer ++;
tmpaddr ++;
}
return YES;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -