?? jflash.cpp
字號:
exit(0); // by ldh...
flash_reset();
test_logic_reset();
}
int putp(int tdi, int tms, int rp)
{
// Output pins (LPT driving)
// LPT D3 Pin 5 and TDI (bit 3 lptaddress )
// LPT D2 Pin 4 and TCK (bit 2 lptaddress )
// LPT D1 Pin 3 and TMS (bit 1 lptaddress )
// LPT D0 Pin 2 and TRST (bit 0 lptaddress )
//
// Input pin (S3C4510 board drives)
// LPT BUSY Pin 11 and TDO (bit 7 lptaddress + 2)
int tdo = -1;
int t1;//,t2;
t1 = tdi*8+tms*2;
_outp(lpt_address, t1+0x01); //TCK low
t1= tdi*8+tms*2+4;
_outp(lpt_address, t1+0x01); // TCK high
/*
if(rp == RP)
{
_outp(lpt_address, tdi*8+tms*2+0x01); // TCK low
t1 = INB(lpt_address + 1);
t2 = t1>>7;
tdo = !t2; // get TDO data
}
*/
if(rp == RP)
{
tdo = !((int)_inp(lpt_address + 1) >> 7);
}
return tdo;
}
void id_command(void)
{
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);
putp(1,1,IP); //select IR scan
putp(1,0,IP); //capture IR
putp(1,0,IP); //shift IR
putp(0,0,IP); //S3C4510 IDCODE, LSB first
putp(1,0,IP); //
putp(1,0,IP); //
putp(1,1,IP); //Exit1-IR
putp(1,1,IP); //Update-IR
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,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
if(check_id(S44B0ID))
error_out("failed to read device ID for the SA-1110");
putp(1,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
}
void bypass_all(void)
{
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);
putp(1,1,IP); //select IR scan
putp(1,0,IP); //capture IR
putp(1,0,IP); //shift IR
putp(1,0,IP); //S3C4510 BYPASS
putp(1,0,IP); //
putp(1,0,IP); //
putp(1,1,IP); //Exit1-IR
putp(1,1,IP); //Update-IR
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
}
void extest(void)
{
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);
putp(1,1,IP); //select IR scan
putp(1,0,IP); //capture IR
putp(1,0,IP); //shift IR
putp(0,0,IP); //S3C4510 extest
putp(0,0,IP); //
putp(0,0,IP); //
putp(0,1,IP); //Exit1-IR
putp(1,1,IP); //Update-IR
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
putp(1,0,IP); //Run-Test/Idle
}
WORD access_rom(int rw, DWORD address, WORD data, int rp)
{
return(access_bus(rw, address, data, rp));
}
WORD access_bus(int rw, DWORD address, WORD data, int rp)
{
// Preset SA-1110 pins to default values (all others set in sa1110jtag.h)
pin[NBE0_1_EN] = 0; // enable pin for nCS0, nOE, nWE.
pin[nCS0_OUT] = 1;
pin[nOE_OUT] = 0;
pin[nWE_OUT] = 1;
pin[A15_EN] = 0;
pin[A16_EN] = 0;
pin[A17_EN] = 0;
pin[A18_EN] = 0;
pin[A19_EN] = 0;
pin[A20_EN] = 0;
pin[D7_EN] = 0;
pin[D15_EN] = 0;
// set the address 1 thru 20
for(int i = 0; i < 20; i++)
pin[add_order[i+1]] = (int)((address >> i) & 1L);
if(rw == READ)
{
pin[D7_EN] = 1;
pin[D15_EN] = 1;
pin[nOE_OUT] = 0;
pin[nWE_OUT] = 1;
pin[nCS0_OUT] = 0;
}
if(rw == WRITE)
{
pin[nWE_OUT] = 0;
pin[nOE_OUT] = 1;
pin[nCS0_OUT] = 0;
pin[D7_EN] = 0; // switch data pins to drive
pin[D15_EN] = 0;
// set the data
for(WORD li = 0; li < 16; li++)
pin[dat_order[li]] = (int)((data >> li) & 1L); // set data pins
}
if(rw == SETUP || rw == HOLD) // just like a write except WE, WE needs setup time
{
pin[nCS0_OUT] = 1;
pin[nOE_OUT] = 1;
pin[nWE_OUT] = 1;
pin[D7_EN] = 0;
pin[D15_EN] = 0;
for(WORD li = 0L; li < 16; li++)
pin[dat_order[li]] = (int)((data >> li) & 1L); // serialize data pins
}
if(rw == RS) // setup prior to RD_nWR_OUT
{
pin[nOE_OUT] = 1;
}
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
int out_dat[300];
for(i = 0; i < 256; i++) // shift write data in to JTAG port and read data out
out_dat[i] = putp(pin[i],0,rp);
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
WORD busdat = 0;
for(i = 0; i < 16; i++) // convert serial data to single DWORD
{
busdat = busdat | (WORD)(out_dat[dat_inorder[i]] << i);
}
extest();
return(busdat);
}
int test_port(void)
{
// search for valid parallel port
_outp(LPT1, 0x55);
if((int)_inp(LPT1) == 0x55)return LPT1;
_outp(LPT2, 0x55);
if((int)_inp(LPT2) == 0x55)return LPT2;
_outp(LPT1, 0x55);
if((int)_inp(LPT3) == 0x55)return LPT3;
return(0); // return zero if none found
}
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;
putp(1,0,IP);
for(int i = 34; i >= 0; i--)
{
if(i == 4 || i == 21 || i == 33)
{
in_id[i] = ' ';
i--;
}
if(putp(1,0,RP) == 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;
// printf("ACT IDCODE: %s\n",in_id);
// return -1;
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;
}
if(0)//!strcmp(device_id,S44B0ID)) // print SA-1110 device revision
{
int sa_rev =
(int)(in_id[0] - '0') * 8 +
(int)(in_id[1] - '0') * 4 +
(int)(in_id[2] - '0') * 2 +
(int)(in_id[3] - '0');
switch(sa_rev)
{
case 0: printf("SA-1110 revision A0\n"); break;
case 4: printf("SA-1110 revision B0\n"); break;
case 5: printf("SA-1110 revision B1\n"); break;
case 6: printf("SA-1110 revision B2\n"); break;
case 8: printf("SA-1110 revision B4\n"); break;
default: printf("SA-1110 revision B4 + %d\n",sa_rev - 8);
}
}
return 0;
}
void error_out(char *error_string)
{
printf("%s\n",error_string);
exit(0);
}
void write_flash()
{
int addr = 0x70000;
WORD data;
for(;;)
{
fread((WORD *)&data, sizeof(WORD) , 1, in_file);
write_command(0,0xa0);
write_command(addr,data);
addr++;
// printf(" %x\n", data);
if(feof(in_file))
break;
}
fclose(in_file);
return;
}
void verify_flash(DWORD base_address, DWORD fsize)
{
time_t start, now;
DWORD li, li1;
time(&start);
for(DWORD lj = base_address + 1; lj <= fsize + base_address; lj++)
{
fread((DWORD *)&li, sizeof(DWORD) , 1, in_file);
li1 = access_rom(READ, lj, 0x0L, RP);
time(&now);
if(difftime(now,start) > STATUS_UPDATE) // Update status every 2 seconds
{
printf("Verifying flash at hex address %8lx, %5.2f%% done \r"
,lj,(float)(lj - base_address)/(float)fsize*100.0);
time(&start);
}
if(li != li1)
{
printf("verify error at address = %lx exp_dat = %lx act_dat = %lx\n",lj - 1,li,li1);
exit(1);
}
}
printf("Verification successful! \n");
}
void test_logic_reset(void)
{
putp(1,1,IP); // keep TMS set to 1 force a test logic reset
putp(1,1,IP); // no matter where you are in the TAP controller
putp(1,1,IP);
putp(1,1,IP);
putp(1,1,IP);
putp(1,1,IP);
}
void test_lock_flash(DWORD base_address, DWORD fsize, DWORD block_size, DWORD max_erase_time, int block_number)
{
time_t start, now;
for(DWORD lj = base_address; lj < fsize + base_address; lj = lj + block_size) // Test only blocks to be programmed
{
access_rom(SETUP, 0, 0x90, IP); // Read Identifier Codes
access_rom(WRITE, 0, 0x90, IP);
access_rom(HOLD, 0, 0x90, IP);
access_rom(READ, lj + 2, 0, IP); // read lock configuration (extra read to get JTAG pipeline going)
if(access_rom(READ, lj + 2, 0, RP) == 0x10001)
{
printf("Block of Flash Memory is Write Locked, would you like to unlock it? [y/n]: ");
if(toupper(_getche()) == 'Y')
{
printf("\nblock is locked\n");
access_rom(SETUP, 0, 0x60, IP); // Clear block lock bit command
access_rom(WRITE, 0, 0x60, IP);
access_rom(HOLD, 0, 0x60, IP);
access_rom(SETUP, lj, 0xd0, IP); // Confirm
access_rom(WRITE, lj, 0xd0, IP);
access_rom(HOLD, lj, 0xd0, IP);
time(&start);
printf("Unlocking block %3d \r",block_number++);
while(access_rom(RS, 0, 0, RP) != 0x800080L) // Loop until successful status return
{
access_rom(READ, 0, 0, RP);
time(&now);
if(difftime(now,start) > max_erase_time + 1) // Check for status timeout
error_out("\nError, Clear lock timed out");
}
}
else
error_out("\nUnable to program Write Locked Flash Memory Block");
}
}
}
void set_lock_flash(DWORD base_address, DWORD fsize, DWORD block_size, DWORD max_erase_time, int block_number)
{
time_t start, now;
printf("Starting set block lock bit\n");
for(DWORD lj = base_address; lj < fsize + base_address; lj = lj + block_size) // Erase only blocks to be programmed
{
access_rom(SETUP, 0, 0x60, IP); // block lock bit command
access_rom(WRITE, 0, 0x60, IP);
access_rom(HOLD, 0, 0x60, IP);
access_rom(SETUP, lj, 0x10, IP); // Confirm
access_rom(WRITE, lj, 0x10, IP);
access_rom(HOLD, lj, 0x10, IP);
time(&start);
printf("Erasing block %3d \r",block_number++);
while(access_rom(RS, 0, 0, RP) != 0x800080L) // Loop until successful status return
{
access_rom(READ, 0, 0, RP);
time(&now);
if(difftime(now,start) > max_erase_time + 1) // Check for status timeout
error_out("Error, Clear lock timed out");
}
}
printf("Set lock bit done \n");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -