📄 flashprg.c
字号:
FULL_REP_MSG((printBuf,
"Read hex line of %ld bytes from %s file. Writing to 0x%x\n",
numBytes, rom_datafile, addr ));
#endif
FULL_REP_MSG((printBuf,
"ROMTOOL> Writing (hex) to 0x%lx (%d bytes) -> Total= %d bytes \r",
addr, numBytes, TotalNumBytes));
status = ProgramFlash((addr, hexFileBuffer, numBytes));
}
else
{
FULL_REP_MSG((printBuf,
"Read hex line of %d bytes from %s file. Checking 0x%lx\n",
numBytes, rom_datafile, addr));
status = VerifyFlash ((addr, hexFileBuffer, numBytes));
}
if (!status)
{
break ;
}
}
} /* of while */
FULL_REP_MSG((printBuf, "\n Duration = %d ms",
time_minus(time_now(), StartDate)/1000));
if (!status)
return FALSE ;
if (program)
{
FULL_REP_MSG((printBuf, "\nProgram operation complete \n"));
}
else
{
FULL_REP_MSG((printBuf, "\nVerify operation complete \n"));
}
return TRUE ;
}
/*
* The command line of the romtool is:
* flash [-e | -p filename | -v filename ] [-l] [-f | -r | -n | -a address] [ -b 5500 | -b stb3 ]
* Where:
* [-e | -p | -v] : erase, program, verify mode
* [-f | -r | -n] : full, reduced or no additional output
* [-b type] : board type
* filename : filename, with extension .bin or .hex
*
*/
int main(int argc, char* argv[])
{
#define BUF_LEN 512
int status = FALSE;
BOOL help = FALSE ;
char buf[BUF_LEN];
BOOL rom_mode = FALSE;
#ifndef ARGS
#define BUF_LEN 512
// char buf[BUF_LEN];
int valid ;
/* Initialise the OS20 kernel */
if (kernel_start() != 0)
{
ESSENTIAL_REP_MSG("OS20 Kernel start failed\n");
RomClearup();
exit(1);
}
debugmessage(Version);
valid = FALSE ;
#if 0
while (!valid)
{
debugmessage("ROMTOOL>Operation: \n");
debugmessage(" 1) Erase \n");
debugmessage(" 2) Program \n");
debugmessage(" 3) Verify \n");
debugmessage(" 4) Exit \n");
debugmessage(" Enter a number : ");
debuggets( buf, BUF_LEN ) ;
switch (buf[0]) {
case '1':
rom_mode = ERASE ;
valid = TRUE ;
break ;
case '2':
rom_mode = PROGRAM ;
valid = TRUE ;
break ;
case '3':
rom_mode = VERIFY ;
valid = TRUE ;
break ;
case '4':
exit(0) ;
default:
debugmessage("\nInvalid selection, try again : ");
break ;
}
}
if (rom_mode==PROGRAM || rom_mode==VERIFY)
{
debugmessage( "\nROMTOOL> Enter filename to Flash : " );
debuggets(buf, BUF_LEN);
strcpy(rom_datafile, buf);
}
valid = FALSE ;
while (!valid) {
debugmessage("\nROMTOOL> Evaluation Board type: \n");
debugmessage(" 1) EVAL-5500 \n");
debugmessage(" 2) EVALSTB3 \n");
debugmessage(" Enter a number : ");
debuggets( buf, BUF_LEN ) ;
switch (buf[0]) {
case '1':
rom_board = EVAL5500 ;
valid = TRUE ;
break ;
case '2':
rom_board = STB3 ;
valid = TRUE ;
break ;
default:
debugmessage("\nInvalid selection, try again : ");
break ;
}
}
rom_report = FULL ;
status = TRUE ;
#else
rom_mode = PROGRAM ;
valid = TRUE ;
strcpy(rom_datafile, "main.bin");
rom_board = EVAL5500 ;
rom_report = FULL ;
status = TRUE ;
#endif
#else
char *s;
printf ("argc = %d argv[0]=%s temp=%d \n", argc, argv[0], temp);
while (argc-- > 0 && (*(argv++))[0] == '-')
{
status = TRUE ;
for ( s = (argv-1)[0] + 1; *s != '\0'; s++) {
switch(*s) {
case 'e': /* erase only */
rom_mode = (rom_mode == NULL_MODE) ? ERASE : ERROR_MODE;
break;
case 'p': /* program */
rom_mode = (rom_mode == NULL_MODE) ? PROGRAM : ERROR_MODE;
memcpy( rom_datafile, *argv, strlen(*argv) ) ;
argv++ ;
argc-- ;
break;
case 'v': /* verify */
rom_mode = (rom_mode == NULL_MODE) ? VERIFY : ERROR_MODE;
memcpy( rom_datafile, *argv, strlen(*argv) ) ;
argv++ ;
argc-- ;
break;
case 'f': /* full */
rom_report = (rom_report == NULL_REPORT) ? FULL : ERROR_REPORT;
break;
case 'r': /* reduced */
rom_report = (rom_report == NULL_REPORT) ? REDUCED : ERROR_REPORT;
break;
case 'n': /* none */
rom_report = (rom_report == NULL_REPORT) ? NONE : ERROR_REPORT;
break;
case 'a': /* address */
address_override = TRUE ;
address_load = hatoi( *argv ) ;
argv++ ;
argc-- ;
break;
case 'b': /* board */
rom_board = ((*argv)[0]=='d')?EVAL5500:STB3 ;
argv++ ;
argc-- ;
break;
case 'h': /* help */
help = TRUE ;
break;
default:
REDUCED_REP_MSG( "illegal option\n" ) ;
FULL_REP_MSG((printBuf, "Illegal option %c\n", *s));
argc = 0;
break;
}
}
}
#endif
#if 0
debugmessage("ROMTOOL>Operation: \n");
debugmessage(" 1) program \n");
debugmessage(" 2) read \n");
debugmessage(" 3) exit \n");
debugmessage(" Enter a number : ");
debuggets( buf, BUF_LEN ) ;
switch (buf[0]) {
case '1':
rom_mode = FALSE ;
break ;
case '2':
rom_mode = TRUE ;
break ;
case '3':
exit(0) ;
default:
debugmessage("\nInvalid selection, try again : ");
break ;
}
if (rom_mode)
{
FILE *fp;
unsigned char *buf;
int i;
int all=2048*1024;/*2M*/
int address_load = 0x7fe00000;
volatile unsigned int* fpl=(unsigned int*)address_load;
volatile unsigned char* pRead=(unsigned char*)address_load;
buf=malloc(all);
if (buf==NULL){
debugmessage("\nCan malloc buffer,exit...\n");
exit(0);
}
fp=fopen("Read.bin","wb");
if (fp==NULL){
debugmessage("\nCan open Read.bin file,exit...\n");
free(buf);
exit(0);
}
debugmessage("\nreading... please wait\n");
*fpl =0xf0f0;
for (i=0;i<all;i++){
*(buf+i)=*(pRead+i);
}
if (fwrite(buf,1,all,fp)==all)
printf("\nRead Ok! save in Read.bin lenth=%dK,exit...\n",all/1024);
else
debugmessage("\nCan put code to Read.bin ,exit...\n");
free(buf);
exit(0);
}
#endif
if (rom_report == NULL_REPORT)
rom_report = REDUCED;
REDUCED_REP_MSG("\nFlash Programmer v1.0 - EVAL-STB3 and ST5500.");
REDUCED_REP_MSG("\n(c) SGS-THOMSON Microelectronics Ltd 1998.\n\n");
if (help || !status) {
ESSENTIAL_REP_MSG("Supported Flash devices:-\n" );
ESSENTIAL_REP_MSG(" Intel 28F004-TL (MB159, 5500)\n");
ESSENTIAL_REP_MSG(" Intel 28F800-TL \n");
ESSENTIAL_REP_MSG(" SGS-Thomson 28F411-TL (MB193, STB3)\n");
ESSENTIAL_REP_MSG("\nOptions:-\n");
ESSENTIAL_REP_MSG(" -e erase entire FLASH memory\n");
ESSENTIAL_REP_MSG(" -p f.hex prog hex file\n");
ESSENTIAL_REP_MSG(" -p f.bin prog binary file\n");
ESSENTIAL_REP_MSG(" -v f.hex verify hex file\n");
ESSENTIAL_REP_MSG(" -v f.bin verify binary file\n");
ESSENTIAL_REP_MSG(" -a addr start address (in hex) for binary file\n");
ESSENTIAL_REP_MSG(" -b 5500 5500 eval board\n");
ESSENTIAL_REP_MSG(" -b stb3 STB3 EVAL board\n");
ESSENTIAL_REP_MSG(" -f verbose output\n");
ESSENTIAL_REP_MSG(" -r reduced output\n");
ESSENTIAL_REP_MSG(" -n limited output\n\n");
}
FULL_REP_MSG((printBuf, "board = %s\n", (rom_board==STB3)?"STB3":"5500"));
FULL_REP_MSG((printBuf, "mode = %s\n", modestr(rom_mode)));
FULL_REP_MSG((printBuf, "report = %s\n", reportstr(rom_report)));
vpp_on();
if(FlashCheck()){
#ifdef YUYIWEI_SKYWORTH
printf("\n Unknown flash memory");
exit(1);
#else
printf("\n Unknown flash memory");
printf("\n but go on");
#endif
};
if (rom_datafile[0]!='\0')
FULL_REP_MSG((printBuf, "file = %s\n", rom_datafile));
if (address_override)
FULL_REP_MSG((printBuf, "address = 0x%x\n", address_load));
if (rom_mode==ERASE || rom_mode==PROGRAM ) {
status = EraseFlash() ;
if (!status) {
ESSENTIAL_REP_MSG("Erase failed\n") ;
RomClearup() ;
exit(1) ;
}
}
if (rom_mode==PROGRAM || rom_mode==VERIFY) {
ESSENTIAL_REP_MSG("Programming\n") ;
status = ProgramOrVerify(rom_mode==PROGRAM);
if (!status) {
ESSENTIAL_REP_MSG("Program/verify failed\n") ;
RomClearup() ;
exit(1) ;
}
ESSENTIAL_REP_MSG("Operation completed successfully\n") ;
}
RomClearup() ;
exit(0) ;
}
/* vpp_on for Intel flash rom write protect*/
#define PGM_POWER_BIT 0x80 | 0x10
#define PIO0_base ((volatile unsigned char *)0x2000C000)
#define PIO0_CONFIG_OUTPUT_BYTE PGM_POWER_BIT
#define PIO_SET_OFFSET 0x04
#define PIO_CLR_OFFSET 0x08
#define PIO_C0_SET_OFFSET 0x24
#define PIO_C0_CLR_OFFSET 0x28
#define PIO_C1_SET_OFFSET 0x34
#define PIO_C1_CLR_OFFSET 0x38
#define PIO_C2_SET_OFFSET 0x44
#define PIO_C2_CLR_OFFSET 0x48
/* for CI_MODEL */
#define PORT_6027 0x60270000
#define PGM_POWER_BIT_CI 0x08
static unsigned char port6027_value = 0x5a;
void vpp_on(void)
{
*(PIO0_base + PIO_C0_CLR_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_C1_SET_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_C2_CLR_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_CLR_OFFSET) = PGM_POWER_BIT;
/* for CI_MODEL */
port6027_value &= ~PGM_POWER_BIT_CI;
*((volatile BYTE*)PORT_6027) = port6027_value;
}
void vpp_off(void)
{
*(PIO0_base + PIO_C0_CLR_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_C1_SET_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_C2_CLR_OFFSET) = PGM_POWER_BIT;
*(PIO0_base + PIO_SET_OFFSET) = PGM_POWER_BIT;
/* for CI_MODEL */
port6027_value |= PGM_POWER_BIT_CI;
*((volatile BYTE*)PORT_6027) = port6027_value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -