📄 allflash.c
字号:
if ((rows++ % 0x10) == 0) {
FULL_REP_MSG(("ROMTOOL: Verified upto 0x%x\r", rom_data.address));
fflush(stdout);
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Verified upto 0x%x\n", rom_data.address));
}
}
}
}
FULL_REP_MSG(("ROMTOOL: Operation complete\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Operation complete\n"));
if (rom_mode != PROGRAM) {
FULL_REP_MSG(("\nROMTOOL: ROM Fully verified.\n"));
FULL_LOG_MSG((rom_logfile_fp, "\nROMTOOL: ROM Fully verified.\n"));
}
printf("\nROMTOOL: Operation complete\n");
FULL_LOG_MSG((rom_logfile_fp, "\nROMTOOL: Operation complete\n"));
return;
}
/*******************************PROC::MAIN*****************************************
*
* Main procedure, this parses the command line and calls the function associated
* with the correct datafile format.
*
***********************************************************************************/
int main(int argc, char *argv[]){
char *s;
int BoxNumber, ManufacturerId;
/***********************************************************************************
*
* The command line of the IMS-B452 romtool is:
* flash [-e | -p | -v ] [-l] [-f | -r | -n ] filename Manufacterer Box
* Where:
* [-e | -p | -v] : erase, program, verify mode
* [-l] : create log file
* [-f | -r | -n] : full, reduced or no additional output
* filename : filename, without extension
*
* Filename extensions is assumed according to format, eg .hex,
* logfiles are always have a .log extension.
*
************************************************************************************/
result = TRUE;
printf("\n\n=============================\n");
printf( "\nSGS-ST20-TP2 ROMTOOL STARTUP.\n");
printf( "\n=============================\n\n");
while (--argc > 0 && (*++argv)[0] == '-')
for ( s = argv[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;
break;
case 'v': /* verify */
rom_mode = (rom_mode == NULL_MODE) ? VERIFY : ERROR_MODE;
break;
case 'l': /* logging */
rom_logging = TRUE;
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;
default:
fprintf(stderr, "ROMTOOL: illegal option %c\n", *s);
argc = 0;
break;
}
/*********************************************************************
* Check and set defaults if required
*/
if (rom_mode == NULL_MODE)
rom_mode = PROGRAM;
if (rom_report == NULL_REPORT)
rom_report = REDUCED;
/*********************************************************************
* There should be 1 parameter (filename) left and no conflicting options
*/
if (argc == 3) {
ManufacturerId = atoi(argv[1]);
BoxNumber = atoi(argv[2]);
argc = 1;
}
else {
/* eg for DSS */
ManufacturerId = 0;
fprintf(stderr, "Box number? : ");
scanf("%d", &BoxNumber);
argc = 1;
}
if ((argc != 1) || (rom_mode == ERROR_MODE) || (rom_report == ERROR_REPORT)) {
fprintf(stderr,
"Usage: ROMTOOL [-p | -v] [-l] [-f | -r | -n] filename\n");
rom_exit_terminate(EXIT_FAILURE);
}
strcpy(rom_datafile, *argv);
/*********************************************************************
* Sign on, unless -n option selected
*/
REDUCED_REP_MSG(("\nST20-TP2 Flash ROM Programmer v2.0 - 16 bits Flash version."));
REDUCED_REP_MSG(("\n(c) SGS-THOMSON Microelectronics Ltd 1995, 1996.\n"));
/*********************************************************************
* If logging selected (-l), try to open the logfile
*/
if (rom_logging) {
strcpy(rom_logfile, *argv);
strcat(rom_logfile, ".log");
if ((rom_logfile_fp = fopen(rom_logfile, "w")) == NULL) {
fprintf(stderr, "ROMTOOL: cannot open log file %s\n", rom_logfile);
FULL_REP_MSG(("ROMTOOL: could not open log file %s \n", rom_logfile));
rom_logging = FALSE;
}
else {
FULL_REP_MSG(("ROMTOOL: log file %s opened\n", rom_logfile));
REDUCED_REP_MSG(("\n\nSGS-ST20-TP1 Flash ROM Programmer v2.0."));
REDUCED_REP_MSG(("\n(c) SGS-Thomson Microelectronics Ltd 1995, 1996.\n\n"));
}
}
/*********************************************************************
* Give more details if requested (-f)
*/
FULL_REP_MSG(("ROMTOOL: Supported FlashROMs = AMD AM29F800B\n"));
FULL_REP_MSG(("ROMTOOL: Supported FlashROMs = ST M28F410\n"));
FULL_REP_MSG(("ROMTOOL: = ST M28F411\n"));
FULL_REP_MSG(("ROMTOOL: = ST M28F211\n"));
FULL_REP_MSG(("ROMTOOL: Supported FlashROMs = Intel 28F004BX-TL\n"));
FULL_REP_MSG(("ROMTOOL: = Intel 28F004BX-BL\n"));
FULL_REP_MSG(("ROMTOOL: = Intel 28F800-TL\n"));
FULL_REP_MSG(("ROMTOOL: Supported FlashROMs = SST 28sf040\n"));
FULL_REP_MSG(("ROMTOOL: mode = %s\n", modestr(rom_mode)));
FULL_REP_MSG(("ROMTOOL: logging = %s\n", boolstr(rom_logging)));
FULL_REP_MSG(("ROMTOOL: report = %s\n", reportstr(rom_report)));
FULL_REP_MSG(("ROMTOOL: file = %s\n", rom_datafile));
/* ???? */
/*
#ifndef ROM_BUS==8
*(volatile int *) PIO0_C0 = 0x0;
*(volatile int *) PIO0_C1 = 0x8;
*(volatile int *) PIO0_C2 = 0x0;
#endif
*/
if (rom_mode == ERASE) {
rom_erase();
FULL_REP_MSG(("ROMTOOL: ROM erased\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ROM erased\n"));
}
else {
if(mfr_id == INTEL_ID){
vpp_on(); /*for Intel_flash_rom write protect*/
ProcWait(CLOCKS_PER_SEC_LOW / 1000); /* 1ms settling time */
}
else if(mfr_id == SST_ID)
Disable_Chip_Data_Protection();
hex_format(); /* It all happens here */
if(mfr_id == SST_ID)
Enable_Chip_Data_Protection();
else if(mfr_id == INTEL_ID)
vpp_off(); /*for Intel_flash_rom write protect*/
}
/* If we have made it to here then things went well */
if (result)
rom_exit_terminate(EXIT_SUCCESS);
else
rom_exit_terminate(EXIT_FAILURE);
}
/******************************************************************************************************/
/*PROCEDURE: Check_Toggle_Ready */
/* */
/*During the internal write cycle, any consecutive read operation */
/*on DQ6 will produce alternating 0's and 1's i.e. toggling between */
/* 0 and 1. When the write cycle is completed, DQ6 of the data will */
/* stop toggling. After the DQ6 data bit stops toggling, the device is ready */
/* for next operation. */
/* */
/* Input: */
/* Dst must already set-up by the caller */
/* */
/* Output: */
/* None */
/*******************************************************************************************************/
void Check_Toggle_Ready (volatile USHORT *Dst)
{
BYTE Loop = TRUE;
volatile USHORT PreData;
volatile USHORT CurrData;
unsigned long TimeOut = 0;
PreData = *Dst;
PreData = PreData & 0x4040;
while ((TimeOut< 0x07FFFFFF) && (Loop)) {
CurrData = *Dst;
CurrData = CurrData & 0x4040;
if (PreData == CurrData)
Loop = FALSE; /* ready to exit the while loop */
PreData = CurrData;
TimeOut++;
}
}
/******************************************************************************************************/
/*PROCEDURE: Disable_Chip_Data_Protection */
/* */
/* This procedure DISABLES the data protection feature on the 28SF040 */
/* 4 Mbit SuperFlash EEPROM. After calling this routine, the chip can be written */
/* without any additional commands. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* None */
/*******************************************************************************************************/
void Disable_Chip_Data_Protection(void)
{
USHORT TempByte;
TempByte = *(volatile USHORT*)((0xE1823 << 1) | 0x40000000); /* set up address to be E000:1823h */
TempByte = *(volatile USHORT*)((0xE1820 << 1) | 0x40000000); /* set up address to be E000:1820h */
TempByte = *(volatile USHORT*)((0xE1822 << 1) | 0x40000000); /* set up address to be E000:1822h */
TempByte = *(volatile USHORT*)((0xE0418 << 1) | 0x40000000); /* set up address to be E000:0418h */
TempByte = *(volatile USHORT*)((0xE041b << 1) | 0x40000000); /* set up address to be E000:041bh */
TempByte = *(volatile USHORT*)((0xE0419 << 1) | 0x40000000); /* set up address to be E000:0419h */
TempByte = *(volatile USHORT*)((0xE041a << 1) | 0x40000000); /* set up address to be E000:041ah */
}
/******************************************************************************************************/
/*PROCEDURE: Enable_Chip_Data_Protection */
/* */
/* This procedure ENABLES the data protection feature on the 28SF040 */
/* 4 Mbit SuperFlash EEPROM. After calling this routine, the chip cannot be written */
/* without disabling SDP first. Disabling the SDP can be done by calling the */
/* "Disable_Chip_Data_Protection" routine. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* None */
/*******************************************************************************************************/
void Enable_Chip_Data_Protection(void)
{
USHORT TempByte;
TempByte = *(volatile USHORT*)((0xE1823 << 1) | 0x40000000); /* set up address to be E000:1823h */
TempByte = *(volatile USHORT*)((0xE1820 << 1) | 0x40000000); /* set up address to be E000:1820h */
TempByte = *(volatile USHORT*)((0xE1822 << 1) | 0x40000000); /* set up address to be E000:1822h */
TempByte = *(volatile USHORT*)((0xE0418 << 1) | 0x40000000); /* set up address to be E000:0418h */
TempByte = *(volatile USHORT*)((0xE041b << 1) | 0x40000000); /* set up address to be E000:041bh */
TempByte = *(volatile USHORT*)((0xE0419 << 1) | 0x40000000); /* set up address to be E000:0419h */
TempByte = *(volatile USHORT*)((0xE040a << 1) | 0x40000000); /* set up address to be E000:040ah */
}
/* vpp_on for Intel flash rom write protect*/
void vpp_on(void)
{
*((volatile BYTE*)ADT_CONTROL_PORTF0) = 0x00;
}
/* vpp_off for Intel flash rom write protect*/
void vpp_off(void)
{
*((volatile BYTE*)ADT_CONTROL_PORTF0) = 0xff;
}
USHORT flash_status(USHORT *fp){
BYTE data, togl_data;
USHORT retry = 1;
AGAIN:
data = *fp; /* read data */
togl_data = data ^ *fp; /* read it again and see what toggled */
if (togl_data == 0) { /* no toggles, nothing's happening */
return STATUS_READY;
}
else if (togl_data == 0x04) { /* erase-suspend */
if (retry--) goto AGAIN; /* may have been write completion */
return STATUS_ERSUSP;
}
else if (togl_data & 0x40){
if (data & 0x20){ /* timeout */
return STATUS_TIMEOUT;
}
else {
return STATUS_BUSY;
}
}
if (retry--) goto AGAIN; /* may have been write completion */
return STATUS_ERROR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -