📄 flash.c
字号:
//====================================================================
// File Name : flash.c
// Function : S3C2460 Flash Program
// Program : Kong, In Wook (KIW)
// Date : May 30, 2002
// Version : 0.0
// History
// 0.0 : Programming start (May 30,2002) -> KIW
// Arrangement source code(8/01/2002)-> SOP
// Edited for SMDK2460(07/07/2003) -> Junon
//====================================================================
#include <string.h>
#include "def.h"
#include "option.h"
#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"
#include "mmu.h"
#include "am29f800.h"
#include "strata16.h"
unsigned int downloadAddress;
unsigned int downloadProgramSize;
//==========================================================================================
void *flashType[][2]=
{
(void *)ProgramAM29F800, "AM29LV800BB x1 ",
(void *)Program28F256K3_16Bit, "28F256K3(16MB) ",
// (void *)Erase28F256K3_16Bit, "Erase 28F256K3 ",
0,0
};
//==========================================================================================
void ProgramFlash(void)
{
int i=0,whichFlash;
char key;
printf("\n[ NOR Flash Memory Writer Ver 0.1 ]\n\n");
#if (WHICH_PORT==2)
printf("The program buffer : 0x21000000 ~ 0x21ff0000\n");
#else
printf("The program buffer : 0x11000000 ~ 0x11ff0000\n");
#endif
//org
//downloadAddress=0x11000000;
//khs(050909)
downloadAddress=_NONCACHE_STARTADDRESS;
downloadProgramSize=0x0;
//MMU_Init();
ChangeRomCacheStatus(RW_NCNB);
while(1)
{ //display menu
printf("%2d:%s",i,flashType[i][1]);
i++;
if((int)(flashType[i][0])==0)
{
printf("\n");
break;
}
if((i%4)==0)
printf("\n");
}
printf(" (NOTE!! Before selection, adjust the switches[S1,S2,S38] for NOR Boot Condition)\n");
printf("Select the type of a flash memory (D=0)? ");
whichFlash = GetIntNum();
if (whichFlash == (-1)) whichFlash = 0;
if(whichFlash==0)
{
printf("\n[Check AM29LVxxx]\n");
switch(AM29F800_CheckId()) //04.01.12 junon
{
case 1 :
printf("This device is AM29LV200B!\n");
break;
case 2 :
printf("This device is AM29LV400B!\n");
break;
case 3 :
printf("This device is AM29LV800B!\n");
break;
case 4 :
printf("This device is AM29LV160B!\n");
break;
default:
printf("ID Check Error!!!\n");
return;
}
}
if( i<0 || (i>=(sizeof(flashType)/8)) )
return;
printf("\nDo you want to download through UART0 from 0x%x? [y/N/c] : ",downloadAddress);
key=getchar();
if(key=='y')
{
if(!DownloadData())
return;
}
else if(key=='c')
return;
( (void (*)(void))(flashType[whichFlash][0]) )();
}
//==========================================================================================
int DownloadData(void)
{
int i,tmp;
unsigned short checkSum=0,dnCS;
unsigned int fileSize=10;
unsigned char *downPt;
downPt=(unsigned char *)downloadAddress;
printf("\ndownloadAddress = %x\n",downloadAddress);
ChangeRomCacheStatus(RW_NCNB);
printf("Download the plain binary file(.BHC) to be written\n");
printf("The file format : <n+6>(4)+(n)+CS(2)\n");
printf("To transmit .BIN file : wkocm2 xxx.BIN /1 /d:1\n");
printf("Download methods : COM:8Bit,NP,1STOP\n");
printf("\nSTATUS : ");
rINTMSK=BIT_ALLMSK;
tmp=RdURXH0(); //To remove overrun error state.
i=0;
while(i<fileSize)
{
while(!(rUTRSTAT0&0x1));
*(downPt+i)=RdURXH0();
if(i==3)
{
fileSize=*((unsigned char *)(downloadAddress+0))+
(*((unsigned char *)(downloadAddress+1))<<8)+
(*((unsigned char *)(downloadAddress+2))<<16)+
(*((unsigned char *)(downloadAddress+3))<<24);
}
if((i%1000)==0)
WrUTXH0('#');
i++;
}
downloadProgramSize=fileSize-6;
for(i=4;i<(fileSize-2);i++)
{
checkSum+=*((unsigned char *)(i+downloadAddress));
}
dnCS=*((unsigned char *)(downloadAddress+fileSize-2))+
(*( (unsigned char *)(downloadAddress+fileSize-1) )<<8);
if(checkSum!=dnCS)
{
printf("Checksum Error!!! MEM : %x DN : %x\n",checkSum,dnCS);
return 0;
}
printf("\nDownload O.K.\n");
return 1;
}
static int DownloadImage(void)
{
int i,j,tmp;
unsigned short checkSum=0,dnCS;
unsigned int fileSize=10;
unsigned char *downPt;
downPt=(unsigned char *)downloadAddress;
printf("\ndownloadAddress = %x\n",downloadAddress);
ChangeRomCacheStatus(RW_NCNB);
printf("Download the plain binary file(.BHC) to be written\n");
printf("The file format : <n+6>(4)+(n)+CS(2)\n");
printf("To transmit .BIN file : wkocm2 xxx.BIN /1 /d:1\n");
printf("Download methods : COM:8Bit,NP,1STOP\n");
printf("\nSTATUS : ");
rINTMSK=BIT_ALLMSK;
tmp=RdURXH0(); //To remove overrun error state.
i=0;
j=0;
while(i<fileSize)
{
while(!(rUTRSTAT0&0x1));
*(downPt+j)=RdURXH0();
j++;
if(i==3)
{
fileSize=*((unsigned char *)(downloadAddress+0))+
(*((unsigned char *)(downloadAddress+1))<<8)+
(*((unsigned char *)(downloadAddress+2))<<16)+
(*((unsigned char *)(downloadAddress+3))<<24);
j = 0;
}
if((i%1000)==0)
WrUTXH0('#');
i++;
}
downloadProgramSize=fileSize-6;
for(i=0;i<(fileSize-2-4);i++)
{
checkSum+=*((unsigned char *)(i+downloadAddress));
}
dnCS=*((unsigned char *)(downloadAddress+fileSize-2-4))+
(*( (unsigned char *)(downloadAddress+fileSize-1-4) )<<8);
if(checkSum!=dnCS)
{
printf("Checksum Error!!! MEM : %x DN : %x\n",checkSum,dnCS);
return 0;
}
printf("\nDownload O.K.\n");
return 1;
}
void DownloadBinary(void)
{
int i=0, tmp;
char key;
unsigned short checkSum=0,dnCS;
unsigned int fileSize=10;
unsigned char *downPt;
printf("\n[ Writing Binary Data to Memory]\n\n");
#if (WHICH_PORT==2)
printf("Set Download Address[D=0x21000000] : ");
#else
printf("Set Download Address[D=0x11000000] : ");
#endif
i = GetIntNum();
//org
//if (i== (-1)) i = 0x11000000;
//khs(050909)
if (i== (-1)) i = _NONCACHE_STARTADDRESS;
printf("\n");
downloadAddress=i;
downloadProgramSize=0x0;
//MMU_Init();
ChangeRomCacheStatus(RW_NCNB);
printf("Do you want to download through UART0 from 0x%x? [Y/n] : ",downloadAddress);
key=getchar();
printf("%c\n",key);
if(key=='n') return;
DownloadImage();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -