⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashpgm.c

📁 write flash through jtag for s3c4510
💻 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 <time.h>
#include "s3c4510.h"
#include "SST39VF160.h"#include "def.h"

extern int lpt_address;
unsigned char test_buf[256];
unsigned char test_buf2[4096];
int  lpt_addr;
int  bUsing28SF040;
unsigned long  nSize;
unsigned long  nBeginAddress;
int  bRead;
char pgmFileName[128];

void Usage(void)
{
	printf("Usage: jflashp w/r filename\n");
	printf("For example:\n");
	printf("  jflashp w bios.img  -->write bios.img to flash \n");
	printf("  jflashp r data.img  -->Read flash to data.bin  \n");
}


int  main(int argc, char **argv)
{
    FILE *pgmfile;
    unsigned  int  tdata = 0, taddr = 0, EndOfFile;
    if (argc < 3)
    {	printf("too few options!\n");
	Usage();
        return;	
    }
    bRead=-1;    if( strcmp(argv[1],"R") == 0 )
 	bRead = 1;    if( strcmp(argv[1],"r") == 0 )
 	bRead = 1;    if( strcmp(argv[1],"W") == 0 )
	bRead = 0;
    if( strcmp(argv[1],"w") == 0 )
	bRead = 0;    if( bRead == -1 )     {        printf("input error command follow jflashp.\n");        printf("first command must be r or w,try again.\n");	exit(0);    }    memset( pgmFileName,0x0,128 );
    if( argv[2] ) strcpy( pgmFileName,argv[2] );    else          strcpy( pgmFileName,"data.bin" );
    printf("Operation file: %s\n",pgmFileName);
    if( argv[3] ) nSize=atoi(argv[3]);    else          nSize=512;    //printf( "nSize:%d\n",nSize);    nBeginAddress=0;          
    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", lpt_addr);
	reset_jtag();
	test_logic_reset();
	id_command();
	extest();
	if (Check_SST_39VF160() ==  -1)
	{
   	    printf("SST39VF160 Chip Not Founded!!\n");
	    exit(0);
	}
	else
	    printf("SST39VF160 Chip Founded!!\n");
			
	EndOfFile = FALSE;
	while(1)
	{
	    memset(test_buf2, 0xff, 4096);
	    if (4096 > fread(test_buf2, sizeof(char), 4096, pgmfile))
		EndOfFile = TRUE;
				
	    if (Write_39VF160(test_buf2, taddr))
		printf("Write fail[%08x]\n", taddr);
	    else		printf("Write success[%08x]\n", taddr);
	    taddr = taddr + (SST39_ROW_SIZE/sizeof(WORD));
	    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("SST 39VF160 not found!!\n");
	    exit(0);
	}
	else
	    printf("SST 39VF160 found!!\n");
	    Read_39VF160( pgmfile,nBeginAddress,nSize );
    }

  printf("            ---The End----\n");    fclose(pgmfile);    io_access_on(lpt_address);    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -