📄 allflash.c
字号:
if(mfr_id==AMD_ID){
}
else{
*addr = 0xFF; /* array_read setup command */
if (*addr != word){ /* test the contents of the address */
error = TRUE; /* error detected, set flag and report */
FULL_REP_MSG(("ROMTOOL: verify failed for address 0x%x: 0x%x # 0x%x\n",
(unsigned int)addr, *addr, word));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: verify failed for address 0x%x: 0x%x # 0x%x\n",
(unsigned int)addr, *addr, word));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
}
/*******************************PROC::ROM_ERASE***********************************
*
* Erase the entire ROM contents. If the erase fails, an error is reported
* and the program exits. Erasure of the 28F400BX-TL/BL FlashROM is achieved
* by using the automated erase routine, which erases entire blocks in one
* instruction, and (using the status register) flags any errors.
*
*
* Erase verification (data = FFh) begins at rom_address 0 and continues
* through the array to the last address, or until data other than FFh is
* encountered.
*
***********************************************************************************/
BOOL rom_erase()
{
volatile USHORT *ptr_to_m;
int temp;
BOOL error;
USHORT *flashptr;
int Count;
int csr_num;
int i;
volatile USHORT SourceWord;
BOOL Continue;
error = FALSE;
FULL_REP_MSG(("ROMTOOL: Starting FlashROM erase\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Starting FlashROM erase\n"));
check_idents(); /* check the FlashROMs are recognised */
if(mfr_id == AMD_ID){
ptr_to_m = (USHORT *)MEMBLOCK(BOOTBLK) /*BTBLK_TL*/; /* point to -TL flash base address */
temp = 0; /* clear temp error variable */
FULL_REP_MSG(("ROMTOOL: Erasing ALL\n"));
ptr_to_m[0x555] = 0xAA;
ptr_to_m[0x2AA] = 0x55;
ptr_to_m[0x555] = 0x80;
ptr_to_m[0x555] = 0xAA;
ptr_to_m[0x2AA] = 0x55;
ptr_to_m[0x555] = 0x10;
while (flash_status(flashptr) == STATUS_BUSY) {
};
}
else if(mfr_id == SST_ID) {
FULL_REP_MSG(("ROMTOOL: Erasing Blocks ...\n"));
csr_num = 0;
ptr_to_m = (USHORT *)0x7ff00000;
Continue = TRUE;
for (i = 0; i < 2048; i++) { /* 2048 * 256 = 1M */
*ptr_to_m = 0x2020; /* clear status_register command */
*ptr_to_m = 0xD0D0; /* read status_register setup command */
Check_Toggle_Ready(ptr_to_m); /* wait for Toggle bit ready */
Count = 0;
while ((Count < ROW_SIZE) && (Continue)) {
SourceWord = *ptr_to_m;
if (SourceWord == 0xFFFF)
Count++;
else{
printf("-=-=-09---==");
Continue = FALSE;
}
ptr_to_m ++;
}
if(!Continue) break;
}
if (!Continue) {
FULL_REP_MSG(("ROMTOOL: ERRORS in FlashROM ERASE.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ERRORS in FlashROM ERASE.\n"));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
FULL_REP_MSG(("ROMTOOL: ROM erased with no errors..\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ROM erased with no errors..\n"));
/* =====================check array is erased================== */
FULL_REP_MSG(("ROMTOOL: Checking array is fully erased..\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Checking array is fully erased..\n"));
ptr_to_m = (USHORT *)FROM_BOT; /* point to lowest _add in FlashROM */
for (ptr_to_m = (USHORT *)FROM_BOT; /* point to flash_start and change type */
ptr_to_m < (USHORT *)FROM_TOP; /* point to flash_end and change type */
ptr_to_m++){ /* inc pointer */
if (*ptr_to_m != ALLBITS1) { /* check all bits are set to 1 */
FULL_REP_MSG(("ROMTOOL: ERRORS in FlashROM ERASE.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ERRORS in FlashROM ERASE.\n"));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
}
else { /* not SST && AMD */
ptr_to_m = (USHORT *)MEMBLOCK(MAINBLK1);
*ptr_to_m = CLEAR_SREG; /* clear status_register command */
*ptr_to_m = READ_SREG; /* read status_register setup command */
temp = 0; /* clear temp error variable */
*ptr_to_m = CLEAR_SREG; /* clear status_register command */
*ptr_to_m = READ_SREG; /* read status_register setup command */
FULL_REP_MSG(("ROMTOOL: Erasing Block 1\n"));
temp = temp + erase_block(MEMBLOCK(MAINBLK1)); /* erase main_block1 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 2\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK2)); /* erase main_block2 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 3\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK3)); /* erase main_block3 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 4\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK4)); /* erase main_block4 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 5\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK5)); /* erase main_block5 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 6\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK6)); /* erase main_block6 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 7\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK7)); /* erase main_block7 */
FULL_REP_MSG(("ROMTOOL: Erasing Block 8\n"));
temp = temp + erase_block (MEMBLOCK(MAINBLK8)); /* erase main_block8 */
FULL_REP_MSG(("ROMTOOL: Erasing Parameter Block 1 \n"));
temp = temp + erase_block (MEMBLOCK(PARAMBLK1)); /* erase para_block1 */
FULL_REP_MSG(("ROMTOOL: Erasing Parameter Block 2\n"));
temp = temp + erase_block (MEMBLOCK(PARAMBLK2)); /* erase para_block2 */
FULL_REP_MSG(("ROMTOOL: Erasing Boot Block \n"));
temp = temp + erase_block (MEMBLOCK(BOOTBLK)); /* erase boot_block */
if (temp != 0) { /* on errors.. */
FULL_REP_MSG(("ROMTOOL: ERRORS in FlashROM ERASE.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ERRORS in FlashROM ERASE.\n"));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
FULL_REP_MSG(("ROMTOOL: ROM erased with no errors..\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ROM erased with no errors..\n"));
/* =====================check array is erased================== */
FULL_REP_MSG(("ROMTOOL: Checking array is fully erased..\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Checking array is fully erased..\n"));
ptr_to_m = (USHORT *)FROM_BOT; /* point to lowest _add in FlashROM */
*ptr_to_m = READ_ARRAY; /* read_array command */
for (ptr_to_m = (USHORT *)FROM_BOT; /* point to flash_start and change type */
ptr_to_m < (USHORT *)FROM_TOP; /* point to flash_end and change type */
ptr_to_m++){ /* inc pointer */
if (*ptr_to_m != ALLBITS1) { /* check all bits are set to 1 */
FULL_REP_MSG(("ROMTOOL: ERRORS in FlashROM ERASE.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ERRORS in FlashROM ERASE.\n"));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
}
FULL_REP_MSG(("ROMTOOL: Array is fully erased.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Array is fully erased.\n"));
return(error);
}
/*******************************PROC::PROGRAM_ROW***********************************
*
* The new version of the program_row() splits and formats the row entries into
* the form suitable for word programming, calling the program_word() for each
* formatted word of the programming data.
*
* Note that the new version of program_word() also performs the write verify
* during that routine, and exits on failure - there is no need to perform any
* further write verify.
*
***********************************************************************************/
void program_row(HEX_ROM_STRUCT row)
{
int i;
USHORT *w_addr; /* word_address pointer */
USHORT progword;
result = TRUE;
w_addr = (USHORT *)(row.address & 0x7fffffff); /* initialise word address pointer */
for (i = 0; i < row.entries/2; i++){
progword = (row.row[i*2+1] * 0x100) + row.row[i*2];
/* make 16 bit word from 2 hexfile chars */
program_word(w_addr, progword);
w_addr++;
}
return;
}
/*******************************PROC::VERIFY_ROW************************************
* The new version of the verify_row() splits and formats the row entries into
* the form suitable for word verification, calling the verify_word() for each
* formatted word of the programmed data.
*
* Note that the new version of program_word() also performs the write verify
* during that routine, and exits on failure - there is no need to perform any
* further write verify.
***********************************************************************************/
void verify_row(HEX_ROM_STRUCT row)
{
int i;
USHORT *w_addr; /* word_address pointer */
USHORT dataword;
result = TRUE;
w_addr = (USHORT *)(row.address & 0x7fffffff);
for (i = 0; i < row.entries; i += 2){
dataword = (row.row[i+1] * 0x100) + row.row[i];
/* make 16 bit word from 2 hexfile chars */
verify_word(w_addr+i, dataword); /* verify the assembled word */
}
return;
}
/*******************************PROC::HEX_FORMAT************************************
*
* Hexadecimal format file processing
*
***********************************************************************************/
void hex_format()
{
HEX_ROM_STRUCT rom_data;
STRING raw_data;
int rows;
/************************************************************************
* Create filename and attempt to open it
*/
strcat(rom_datafile, ".hex");
rom_datafile_fp = fopen(rom_datafile, "r");
if (rom_datafile_fp == NULL) {
fprintf(stderr, "ROMTOOL: cannot open data file %s\n", rom_datafile);
rom_exit_terminate(EXIT_FAILURE);
}
FULL_REP_MSG(("ROMTOOL: data file %s opened\n", rom_datafile));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: data file %s opened\n", rom_datafile));
/************************************************************************
* If programming ROM, erase it first.
*/
if (rom_mode == PROGRAM) {
rom_erase();
FULL_REP_MSG(("ROMTOOL: ROM erased\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: ROM erased\n"));
}
/************************************************************************
* read lines from the hex datafile, this has the following syntax:
*
* address 1{byte}16
*
* where n{...}m means at least n terms and no more than m
*/
FULL_REP_MSG(("ROMTOOL: Programming.....................\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Programming.....................\n"));
rows = 0;
while (1) {
if (fgets(raw_data, MAX_STRING_LENGTH, rom_datafile_fp) == NULL)
break;
rom_data.entries = sscanf(raw_data, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
&rom_data.address,
&rom_data.row[0], &rom_data.row[1], &rom_data.row[2], &rom_data.row[3],
&rom_data.row[4], &rom_data.row[5], &rom_data.row[6], &rom_data.row[7],
&rom_data.row[8], &rom_data.row[9], &rom_data.row[10], &rom_data.row[11],
&rom_data.row[12], &rom_data.row[13], &rom_data.row[14], &rom_data.row[15])
- 1; /* don't count address, 0 <= rom_data.entries <= 16 */
/**********************************************************************
* If we read some data, either program or verify it
*/
if (rom_data.entries > 0) {
if (rom_mode == PROGRAM) {
program_row(rom_data);
if ((rows++ % 0x100) == 0) {
FULL_REP_MSG(("ROMTOOL: Programmed upto 0x%x\r", rom_data.address));
fflush(stdout);
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Programmed upto 0x%x\n", rom_data.address));
}
}
else {
verify_row(rom_data);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -