📄 flashpgm.c
字号:
// The ARM ANYWHERE II JTAG based flash programer
// any problem,contact me:surper_bat@citiz.net
#define VERSION "1.0"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
#include "s3c4510.h"
#include "sst28sf040.h"
#include "sst39vf160.h"
//unsigned char test_buf[256];
unsigned char test_buf2[4096*2];
int lpt_addr;
int bUsing28SF040;
unsigned long nSize;
unsigned long nBeginAddress;
int bRead;
char pgmFileName[MAX_PATH];
void Usage(void)
{
printf("Welcome to using S3C44B0x ARM Develop Board \n");
printf("This program use JTAG cable from www.clfy.com \n");
printf("Made by zhaoqian \n");
printf("Usage: <this> command [options]\n");
printf("command: (case insensitive)\n");
printf(" R Read from Flash\n");
printf(" W Write to Flash\n");
// printf(" -T type Flash type [28|39],28 is the default\n");
printf(" -F filename Read or write file name\n");
printf(" -B address Begin from address\n");
printf(" -S size size of the operation\n");
printf("For example:\n");
printf(" flash R -B 0x00001234 -S 512 -F data.bin \n");//
printf(" Reading 29lv160 to data.bin begin from address 0x1234 the size is 512 bytes\n");
printf(" flash W -F data.bin \n");
printf(" write data.bin to 29lv160 begin from address 0\n");
}
int ParseCmd(int argc, char* argv[])
{
// default value
int i;
char *stopchar = "\0";
memset( pgmFileName,0x0,MAX_PATH );
strcpy( pgmFileName,"data.bin" );
nSize = 512;
nBeginAddress = 0;
bUsing28SF040 = 0;
bRead = 1;
if(argc < 2)
{
printf("Too few parameters !\n\n");
return 1;
}
for(i=1; i< argc; i++ )
{
if( strcmpi(argv[i],"R") == 0 )
{
bRead = 1;
}
else if( strcmpi(argv[i],"W") == 0 )
{
bRead = 0;
}
/* else if( strcmpi(argv[i],"-T") == 0)
{
if( strcmp(argv[++i],"28") == 0 )
bUsing28SF040 = 1;
else
bUsing28SF040 = 0;
}*/
else if( strcmpi(argv[i],"-F") == 0)
{
strcpy(pgmFileName, argv[++i]);
}
else if( strcmpi(argv[i],"-B") == 0)
{
nBeginAddress = strtol(argv[++i],&stopchar,16);
}
else if( strcmpi(argv[i],"-S") == 0)
{
nSize = atoi(argv[++i]);
}
else
{
printf("Unknown option !\n\n");
return 1;
}
}
return 0;
}
void main(int argc, char **argv)
{
FILE *pgmfile;
unsigned int tdata = 0, taddr = 0, EndOfFile;
if (argc < 2)
{
Usage();
return;
}
if( ParseCmd( argc,argv ) )
return;
printf("Operation file: %s\n",pgmFileName);
if( bRead )
pgmfile = fopen(pgmFileName, "wb");
else
pgmfile = fopen(pgmFileName, "rb");
if (pgmfile == NULL)
{
printf("File %s not found\n", pgmFileName);
return;
}
if( !bRead )
{
taddr = nBeginAddress;
lpt_addr = test_port(); // find a valid parallel port address
printf("LPT is at %04x\n\n", lpt_addr);
reset_jtag();
test_logic_reset();
id_command();
extest();
if (Check_SST_39VF160() == -1)
{
printf("HY 29LV160 not found!!\n");
exit(0);
}
else
printf("HY 29LV160 found!!\n");
EndOfFile = FALSE;
while(1) //以4k word为单位进行编程
{
memset(test_buf2, 0xff, 4096*2); // 填充指定长度的字节
if (4096*2 > fread(test_buf2, sizeof(char), 4096*2, pgmfile))
EndOfFile = TRUE;
if (Write_39VF160(test_buf2, taddr))
printf("Write fail[%08x]\n", taddr);
else
printf("Write success from [0x%08x] to [0x%08x]\n", taddr,taddr+0x2000-1);
taddr = taddr + 0x2000;
if (EndOfFile == TRUE)
break;
}
}
else
{
lpt_addr = test_port(); // find a valid parallel port address
printf("LPT is at %04x\n\n", lpt_addr);
reset_jtag();
test_logic_reset();
id_command();
extest();
if (Check_SST_39VF160() == -1)
{
printf("HY 29LV160 not found!!\n");
exit(0);
}
else
printf("HY 29LV160 found!!\n");
Read_39VF160( pgmfile,nBeginAddress,nSize );
}
fclose(pgmfile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -