📄 allflash.c
字号:
/***************************************************************************************************/
if (!(((mfr_id == AMD_ID) && (dev_id == AMD_AM29F800)) ||
((mfr_id == INTEL_ID) && (dev_id == INTEL_28F800TL)) ||
((mfr_id == INTEL_ID) && (dev_id == INTEL_28F004BX_TL)) ||
((mfr_id == INTEL_ID) && (dev_id == INTEL_28F004BX_BL)) ||
((mfr_id == ST_ID) && (dev_id == ST_M28F410)) ||
((mfr_id == ST_ID) && (dev_id == ST_M28F411)) ||
((mfr_id == SST_ID) && (dev_id == SST_28SF040)))){
FULL_REP_MSG(("ROMTOOL: Error detected in FlashROM Identifiers..\n"));
FULL_REP_MSG((" ID not recognized\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Error detected in FlashROM Identifiers..\n"));
FULL_LOG_MSG((rom_logfile_fp, " ID not recognized\n"));
sprintf(s_mfri, "%08x", mfr_id); /* mfr_id to 12chr hex_string */
sprintf(s_devi, "%08x\n", dev_id); /* dev_id to 12chr hex_string */
strcpy( s_msg, "Manufacturer_ID = Unknown"); /* initialize message string */
strcat (s_msg, s_mfri); /* add string of mfr_id value */
strcat (s_msg, " :: Device_ID = Unknown");
strcat (s_msg, s_devi);
FULL_REP_MSG(("ROMTOOL: %s\n", s_msg));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: %s\n", s_msg));
error = TRUE; /* set error flag for return */
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
/* OK - flash_id's are those expected */
FULL_REP_MSG(("===================================================================\n"));
FULL_REP_MSG(("ROMTOOL: FlashROM Identifiers are recognised, OK.\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: FlashROM Identifiers are recognised, OK.\n"));
FULL_REP_MSG(("===================================================================\n"));
if(dev_id == AMD_AM29F800)
meminfo = &used_flash[0];
else if (dev_id == INTEL_28F800TL)
meminfo = &used_flash[1];
else if (dev_id == INTEL_28F004BX_TL)
meminfo = &used_flash[2];
else if (dev_id == SST_28SF040)
meminfo = &used_flash[3];
else if(dev_id == ST_M28F410)
meminfo = &used_flash[4];
sprintf(s_mfri, "%08x", mfr_id); /* mfr_id to 12chr hex_string */
sprintf(s_devi, "%08x\n", dev_id); /* dev_id to 12chr hex_string */
strcpy( s_msg, "Manufacturer_ID = "); /* initialize message string */
strcat (s_msg, s_mfri); /* add string of mfr_id value */
strcat (s_msg, " :: Device_ID = ");
strcat (s_msg, s_devi);
FULL_REP_MSG(("ROMTOOL: %s\n", s_msg));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: %s\n", s_msg));
if (mfr_id == ST_ID) {
FULL_REP_MSG(("ROMTOOL: Manufacturer ID recognized: SGS-THOMSON\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Manufacturer ID recognized: SGS-THOMSON\n"));
if (dev_id == ST_M28F411) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: M28F411\n\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: M28F411\n\n"));
type_bl = FALSE; /* TL type */
}
else if (dev_id == ST_M28F410) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: M28F410\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: M28F410\n"));
type_bl = TRUE; /* BL type */
}
}
if (mfr_id == INTEL_ID) {
FULL_REP_MSG(("ROMTOOL: Manufacturer ID recognized: Intel\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Manufacturer ID recognized: Intel\n"));
if (dev_id == INTEL_28F004BX_TL) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: 28F004BX-TL\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: 28F004BX-TL\n"));
type_bl = FALSE; /* TL type */
}
else if (dev_id == INTEL_28F004BX_BL) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: 28F004BX-BL\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: 28F004BX-BL\n"));
type_bl = TRUE; /* BL type */
}
else if (dev_id == INTEL_28F800TL) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: 28F800-TL\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: 28F800-TL\n"));
type_bl = TRUE; /* TL type */
}
}
if (mfr_id == SST_ID) {
FULL_REP_MSG(("ROMTOOL: Manufacturer ID recognized: SST\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Manufacturer ID recognized: SST\n"));
if (dev_id == SST_28SF040) {
FULL_REP_MSG(("ROMTOOL: Device ID recognized: 28SF040\n\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Device ID recognized: 28SF040\n\n"));
}
}
return(error);
}
int cursor (int csr_num){
csr_num++; /* increment cursor value */
return(csr_num); /* return with cursor new_value */
}
/*******************************PROC::ERASE_BLOCK***************************************************
*
* erase flashrom block
*
***************************************************************************************************/
int erase_block (int block){
volatile USHORT *ptr_to_b; /* block_pointer def'n */
int csr_num; /* cursor counter */
error = FALSE; /* reset error value for return */
csr_num = 0;
ptr_to_b = (USHORT *)block; /* point to block_start_add for erase */
*ptr_to_b = CLEAR_SREG; /* clear status_register command */
*ptr_to_b = ERASE_SETUP; /* write erase_setup command for block */
*ptr_to_b = ERASE_CONFIRM; /* write erase_confm command for block */
*ptr_to_b = READ_SREG; /* read status_register setup command */
while (~(*ptr_to_b) & BIT7_STATUS){ /* wait for bit7 of sreg = 1 (=finish) */
csr_num = cursor(csr_num);
}
if (*ptr_to_b & BIT3_STATUS) { /* test s_reg vpp_error_flag */
error = TRUE; /* inc(=1) temp return value on error */
FULL_REP_MSG(("ROMTOOL: VPP_Error in FlashROM erase\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: VPP_Error in FlashROM erase\n"));
}
if (*ptr_to_b & BIT4_STATUS) { /* test s_reg comseq_error_flag */
error = TRUE; /* inc(=1) temp return value on error */
FULL_REP_MSG(("ROMTOOL: Command_Error in FlashROM erase\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Command_Error in FlashROM erase\n"));
}
if (*ptr_to_b & BIT5_STATUS) { /* test s_reg erase_error_flag */
/*error = TRUE;*/ /* inc(=1) temp return value on error */
FULL_REP_MSG(("ROMTOOL: Block_Erase_Error in FlashROM erase\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Block_Erase_Error in FlashROM erase\n"));
}
if (*ptr_to_b & BIT6_STATUS) { /* test s_reg ers_suspend_flag */
error = TRUE; /* inc(=1) temp return value on error */
FULL_REP_MSG(("ROMTOOL: Erase_Suspend in FlashROM erase\n"));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Erase_Suspend in FlashROM erase\n"));
}
return(error);
}
/*******************************PROC::*MODESTRing***************************************************
*
* Return textual representation of the ROMTOOL_MODE enumeration
*
***************************************************************************************************/
char *modestr(ROMTOOL_MODE m)
{
static char *modes[] = {
"NULL_MODE",
"ERROR_MODE",
"PROGRAM",
"VERIFY",
"DUMP"
};
return(modes[m]);
}
/*******************************PROC::*BOOLSTRing***************************************************
*
* Return textual representation of the BOOL enumeration
*
***************************************************************************************************/
char *boolstr(BOOL b){
static char *bools[] = {
"FALSE",
"TRUE"
};
return(bools[b]);
}
/*******************************PROC::*REPORTSTRing**************************************************
*
* Return textual representation of the ROMTOOL_REPORT enumeration
*
***************************************************************************************************/
char *reportstr(ROMTOOL_REPORT r){
static char *reports[] = {
"NULL_REPORT",
"ERROR_REPORT",
"FULL",
"REDUCED",
"NONE"
};
return(reports[r]);
}
/****************************************************************************************************
*
* Program the specified address with the supplied word value.
* If unsuccessful report an error and exit.
*
* The following programming algorithm uses the 28F400 CUI programming and
* status_read operations, which removes the necessity to perform a verify.
* The algorithm allows for just 1 programming operations per word.
*
****************************************************************************************************/
void program_word ( volatile USHORT *addr, USHORT flashdata ){
BOOL error;
USHORT *flashptr, status;
result = TRUE;
error = FALSE;
if(mfr_id == SST_ID) {
if(flashdata != 0xFFFF) {
*addr = 0x1010; /* clear status_register command */
*addr = flashdata; /* write word to addressed location */
Check_Toggle_Ready(addr); /* wait for Toggle bit ready */
if (*addr != flashdata) { /* test s_reg vpp_error_flag */
error = TRUE; /* error detected, set flag and report */
FULL_REP_MSG(("ROMTOOL: Read_Error detected, when programming 0x%x\n",(unsigned int)addr));
printf ("Data was 0x%x \n", flashdata);
/* Here we verify that the word in flash is what we wanted to put there. */
printf ("Read value is 0x%x \n", *addr);
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Read_Error detected, when programming 0x%x\n",
(unsigned int)addr));
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
}
else if(mfr_id == AMD_ID){
flashptr = (USHORT *)MFGID_ADDR;
*flashptr = 0xF0;
while ((status = flash_status(flashptr)) == STATUS_BUSY) {
};
if (status == STATUS_ERROR){ /* on errors.. */
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
flashptr[0x555] = 0xAA; /* unlock 1 */
flashptr[0x2AA] = 0x55; /* unlock 2 */
flashptr[0x555] = 0xA0;
*addr = flashdata;
while ((status = flash_status(flashptr)) == STATUS_BUSY){
};
if (status == STATUS_ERROR){ /* on errors.. */
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
else{
*addr = CLEAR_SREG; /* clear status_register command */
*addr = READ_SREG; /* read status_register setup command */
*addr = PROGRAM_SETUP; /* setup write word */
*addr = flashdata; /* write word to addressed location */
*addr = READ_SREG; /* read status_register setup command */
while (~(*addr) & BIT7_STATUS); /* wait for bit7 of sreg = 1 (=finish) */
if (*addr & BIT3_STATUS){ /* test s_reg vpp_error_flag */
error = TRUE; /* error detected, set flag */
printf("addr value: %x\n", *addr);
FULL_REP_MSG(("ROMTOOL: VPP_Error detected, when programming 0x%x\n",
(unsigned int)addr));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: VPP_Error detected, when programming 0x%x\n",
(unsigned int)addr));
}
if (*addr & BIT4_STATUS){ /* test s_reg prog_error_flag */
/* error = TRUE; */ /* error detected, set flag */
FULL_REP_MSG(("ROMTOOL: Program_Error detected, when programming 0x%x\n",
(unsigned int)addr));
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Program_Error detected, when programming 0x%x\n",
(unsigned int)addr));
}
/* Here we verify that the word in flash is what we wanted to put there. */
*addr = 0xFF; /*READ_ARRAY*/
if (*addr != flashdata) { /* test s_reg vpp_error_flag */
/* error = TRUE; */ /* error detected, set flag and report */
FULL_REP_MSG(("ROMTOOL: Read_Error detected, when programming 0x%x\n",
(unsigned int)addr));
printf ("Data was 0x%x \n", flashdata);
/* Here we verify that the word in flash is what we wanted to put there. */
/* *addr = READ_ARRAY; */
printf ("Read value is 0x%x \n", *addr);
FULL_LOG_MSG((rom_logfile_fp, "ROMTOOL: Read_Error detected, when programming 0x%x\n",
(unsigned int)addr));
}
}
if (error == TRUE){ /* on errors.. */
rom_exit_terminate(EXIT_FAILURE); /* jump to end of process */
}
}
/*******************************PROC::VERIFY_HALFWORD***********************************************
*
* Verify that the contents of the specified address match the supplied data
* value, if not report to stderr and if logging is enabled the logfile.
*
***************************************************************************************************/
void verify_word ( volatile USHORT *addr, USHORT word){
BOOL error;
error = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -