📄 jflash.cpp
字号:
mem_output_enable(DISABLE);
mem_data_driver(DRIVE);
set_data(data);
}
//----------------------------------------------
else if(rw == RS) // setup prior to RD_nWR_OUT
{
if(Debug_Mode)
printf("RS Mode\n");
mem_output_enable(DISABLE);
}
else if(rw == K3)
clear_chip_selects();
// Common finish
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,1,IP); //select DR scan
putp(1,0,IP); //capture DR
putp(1,0,IP); //shift IR ---> (Rami: should be DR?)
int out_dat[MAX_CHAIN_LENGTH];
for(device = DEVICES_IN_CHAIN -1 ; device >= 0; device--)
{
if(device == DEVICE_CONTROLLER)
{
for(i = 1; i < ChainLength; i++) // shift write data in to JTAG port and read data out
out_dat[i] = putp(pin[i-1],0,rp);
// for(i = 0; i < ChainLength; i++) // shift write data in to JTAG port and read data out
// out_dat[i] = putp(pin[i],0,rp);
}
else
{
putp(0,0,IP); // extra clicks for devices in the chain
}
}
#ifdef serious_error
if(Debug_Mode)
{
for(i = 1; i < ChainLength; i++)
{
if(rw == READ)
{
if(i%30 == 0) printf("\n");
printf(" %d", out_dat[i]);
}
}
printf("\n");
}
#endif
putp(0,1,IP); //Exit1-DR
putp(1,1,IP); //Update-DR
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
DWORD busdat = 0;
for(i = 0; i < 32; i++) // convert serial data to single DWORD
busdat = busdat | ((DWORD)(out_dat[input_dat_order[i]] << i));
//extest();
IR_Command(IR_Extest);
if(Debug_Mode)
{
printf("just before return\n");
dump_chain();
}
return(busdat);
}
/*
*******************************************************************************
*
* FUNCTION: test_port
*
* DESCRIPTION: Searches for a valid parallel port
*
* INPUT PARAMETERS: void
*
* RETURNS: int - Address of the port or zero if none available
*
*******************************************************************************
*/
int test_port(void)
{
// search for valid parallel port
_outp(LPT1, 0x55);
if((int)_inp(LPT1) == 0x55)
{
if(Debug_Mode)
printf("Parallel Com port found at I/O address: %X\n", LPT1);
return LPT1;
}
_outp(LPT2, 0x55);
if((int)_inp(LPT2) == 0x55)
{
if(Debug_Mode)
printf("Parallel Com port found at I/O address: %X\n", LPT2);
return LPT2;
}
_outp(LPT3, 0x55);
if((int)_inp(LPT3) == 0x55)
{
if(Debug_Mode)
printf("Parallel Com port found at I/O address: %X\n", LPT3);
return LPT3;
}
return(0); // return zero if none found
}
/*
*******************************************************************************
*
* FUNCTION: check_id
*
* DESCRIPTION: Compare an ID string returned from the device with the expected string.
*
* INPUT PARAMETERS: char * device_id - a pointer to the string returned from the device
*
* RETURNS: int - 0 if ID matches expected, -1 if a match fails
*
*******************************************************************************
*/
int check_id(char *device_id)
{
// compare passed device ID to the one returned from the ID command
char in_id[40];
BOOL error_flag = FALSE;
if(DEVICES_IN_CHAIN > 1)
putp(1,0,IGNORE_PORT); // this is a bug fudge factor - look into this
for(int i = 34; i >= 0; i--)
{
// skip over the spaces in the ID string
if(i == 4 || i == 21 || i == 33)
{
in_id[i] = ' ';
i--;
}
if(putp(1,0,READ_PORT) == 0)
in_id[i] = '0';
else
in_id[i] = '1';
if((in_id[i] != *(device_id + i)) && (*(device_id + i) != '*'))
{
error_flag = TRUE;
}
}
in_id[35] = 0;
if(error_flag)
{
printf("error, failed to read device ID\n");
printf("check cables and power\n");
printf("ACT: %s\n",in_id);
printf("EXP: %s\n\n",device_id);
return -1;
}
int revision = (int)(in_id[0] - '0') * 8 +
(int)(in_id[1] - '0') * 4 +
(int)(in_id[2] - '0') * 2 +
(int)(in_id[3] - '0');
switch(revision)
{
case 0:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID0][0]);
break;
case 1:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID1][0]);
break;
case 2:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID2][0]);
break;
case 3:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID3][0]);
break;
case 4:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID4][0]);
break;
case 5:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID5][0]);
break;
case 6:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID6][0]);
break;
case 7:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID7][0]);
break;
case 8:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID8][0]);
break;
case 9:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID9][0]);
break;
case 10:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID10][0]);
break;
case 11:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID11][0]);
break;
case 12:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID12][0]);
break;
case 13:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID13][0]);
break;
case 14:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID14][0]);
break;
case 15:
printf("%s revision %s\n", &WORDARRAY[p_processor][0], &WORDARRAY[p_CID15][0]);
break;
default: printf("Unknown revision number. Out of range!"); // should never get here
}
return 0;
}
/*
*******************************************************************************
*
* FUNCTION: error_out
*
* DESCRIPTION: generic error printout and program exit.
*
* INPUT PARAMETERS: char * error_string to print before exit
*
* RETURNS: void
*
* GLOBAL EFFECTS: Exits the program
*******************************************************************************
*/
void error_out(char *error_string)
{
printf("%s\n",error_string);
if(Debug_Mode)
{
// analyze failure
printf("\n\nF A I L U R E A N A L Y S I S\n\n");
printf("Processor ID: %s\n", (DebugProgress & foundProcID) ? "Found" : "Not Found");
printf("Flash ID: %s\n", (DebugProgress & foundFlashID) ? "Found" : "Not Found");
printf("Flash Lock Status: %s\n", (DebugProgress & unlockedFlash) ? "Unlocked" : "Not Unlocked");
printf("Verification: %s\n", (DebugProgress & firstWordVerified) ? "Some Data Verified" : "No Data Verified");
printf("Flash Erase Status: %s\n\n", (DebugProgress & eraseSuccess) ? "Erased" : "Not Erased");
if(foundProcID & ~DebugProgress)
{
printf("You have a serious failure.\n");
printf("The ID of the processor was not detected.\n");
printf("Check all cable attachments.\n");
printf("Check for power on Pin 1 of your JTAG connector.\n");
printf("Check seating of processor and cards in sockets or connectors\n");
printf("If the bits for the ID string appear to be shifted left or right,\n");
printf(" then you probably have a JTAG routing switch set in the wrong state.\n");
printf("If the ACTual bits are all 0s or 1s, you may have a\n");
printf( "cable or a power problem on this board.\n");
}
else if(foundFlashID & ~DebugProgress)
{
printf("You cannot read the flash ID.\n");
printf("You can read the Processor ID.\n");
printf("This means that you have some power and cabling looks OK.\n");
printf("Check all voltages on the flash and processor devices.\n");
printf("You have power on the processor chip and at least a few other connections.\n");
printf("You may have a bad memory bus connection.\n");
printf("You may be missing a flash data file for this memory type.\n");
printf("You may have a badly connected flash memory device.\n");
printf("You may have a bad flash memory.\n");
}
else if(unlockedFlash & ~DebugProgress)
{
printf("You cannot unlock the flash.\n");
printf("You can read the Processor ID.\n");
printf("You can read the Flash ID.\n");
printf("This means that you have some power and cabling looks OK.\n");
printf("You most likely have a functional memory bus.\n");
printf("The debug log will show the last Status word from the flash \n");
printf(" just before this message. Check this value in the Flash Datasheet\n");
printf(" for clues about the state of the flash.\n");
printf("Check all voltages on the flash and processor devices.\n");
printf("You may have a badly connected flash memory device.\n");
printf("You may have a bad flash memory.\n");
}
else if(eraseSuccess & ~DebugProgress)
{
printf("You are unable to erase the flash.\n");
printf("You can read the Processor ID.\n");
printf("You can read the Flash ID.\n");
printf("You can unlock the flash.\n");
printf("This means that you have some power and cabling looks OK.\n");
printf("You most likely have a functional memory bus.\n");
printf("The debug log will show the last Status word from the flash \n");
printf(" just before this message. Check this value in the Flash Datasheet\n");
printf(" for clues about the state of the flash.\n");
printf("Check all voltages on the flash and processor devices.\n");
printf("You may have a badly connected flash memory device.\n");
printf("You may have a bad flash memory.\n");
}
else if(firstWordVerified & ~DebugProgress)
{
printf("You have at least one data word verified.\n");
printf("You can read the Processor ID.\n");
printf("You can read the Flash ID.\n");
printf("You can unlock the flash.\n");
printf("You can erase the flash.\n");
printf("This means that you have some power and cabling looks OK.\n");
printf("You most likely have a functional memory bus.\n");
printf("You probably got some other verify error.\n");
printf("Check the actual and expected data values for clues \n");
printf(" indicating open or shorted data lines.\n");
printf("Check all voltages on the flash and processor devices.\n");
printf("You may have a badly connected flash memory device.\n");
printf("You may have a bad flash memory.\n");
}
else
{
printf("No data was verified to be programmed.\n");
printf("You can read the Processor ID.\n");
printf("You can read the Flash ID.\n");
printf("You can unlock the flash.\n");
printf("You can erase the flash.\n");
printf("This means that you have some power and cabling looks OK.\n");
printf("You most likely have a functional memory bus.\n");
printf("You probably did not actually program anything into flash memory.\n");
printf("Check the actual and expected data values for clues \n");
printf(" indicating open or shorted data lines.\n");
printf("Check all voltages on the flash and processor devices.\n");
printf("You may have a badly connected flash memory device.\n");
printf("You may have a bad flash memory.\n");
}
}
exit(1);
}
/*
*******************************************************************************
*
* FUNCTION: program_flash
*
* DESCRIPTION: program the flash using buffered writes
*
* INPUT PARAMETERS: DWORD max_write_buffer derived from the flash query
* DWORD base_address
* DWORD fsize (flash size)
*
* RETURNS: void
*
*******************************************************************************
*/
void program_flash(DWORD max_write_buffer, DWORD base_address, DWORD fsize)
{
time_t start = 0;
time_t now = 0;
WORD li_WORD;
DWORD li_DWORD;
DWORD write_word_count;
DWORD lj;
// int bus_width;
// DWORD Status;
printf("Starting programming\n");
if(!strcmp("WORD", &WORDARRAY[P_progmode][0] ))
{
printf("Using WORD programming mode...\n");
for(lj = base_address; lj < fsize + base_address; lj = lj +1)
{
time(&now);
if(difftime(now,start) > STATUS_UPDATE) // Update status every 2 seconds
{
printf("Writing flash at hex address %8lx, %5.2f%% done \r"
,lj * ADDR_MULT ,(float)(lj - base_address)/(float)fsize*100.0);
time(&start);
}
if(!PlatformIs16bit)
{
fread((DWORD *)&li_DWORD, sizeof(DWORD) , 1, in_file);
access_rom(WRITE, lj, F_WORDBYTE_PROG, IGNORE_PORT);
access_rom(HOLD, lj, F_WORDBYTE_PROG, IGNORE_PORT);
access_rom(WRITE, lj, li_DWORD, IGNORE_PORT);
access_rom(HOLD, lj, li_DWORD, IGNORE_PORT);
}
else
{
fread((WORD *)&li_WORD, sizeof(WORD) , 1, in_file);
access_rom(WRITE, lj, F_WORDBYTE_PROG, IGNORE_PORT);
access_rom(HOLD, lj, F_WORDBYTE_PROG, IGNORE_PORT);
access_rom(WRITE, lj, li_WORD, IGNORE_PORT);
access_rom(HOLD, lj, li_WORD, IGNORE_PORT);
}
}
Write_Rom(lj, F_READ_ARRAY);
}
else if(!strcmp("BUFFER", &WORDARRAY[P_progmode][0] ))
{
printf("Using BUFFER programming mode...\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -