?? flashloader_intel.c
字號:
#include <stdio.h>
#include <pc.h>
#include <time.h>
#define lpt_base1 0x3bc
#define lpt_base2 0x378
#define lpt_base3 0x278
//last up date
int data_y = 2001;//Year
int data_m = 1;//Month
int data_d = 12;//day
int ver_no = 11;//soft version
int lpt_base;
int tsu_delay = 1;
int cmd_delay = 10;
int up_delay = 1;
int comp = 16;
unsigned long flash_byte_number = 4194303;
/****Get pararell port data(ack)***************************************/
unsigned int input_value(void)
{ static unsigned char last_value = 0xFF;
unsigned char new1, new2;
new1 = inportb(lpt_base + 1) & 0xF8;
if (new1 != last_value)
{ while (1)
{ new2 = inportb(lpt_base + 1) & 0xF8;
if (new2 == new1) /* Wait for stable value */
break;
new1 = new2; //compare to see if a change in logic level has occured
}
last_value = new1;
}
return (last_value ^ 0x80) >> 3;
}
/* Delay function*************************************************************/
void delay(int N)
{
int i;
for (i=0;i<N;i++)
{}
}
/*****Transmit an 8-bit byte value********************************************/
/* Function that is used to transmit the the LSB to the MSB of the 8 bit data
that was parsed from the ttf file */
/*****************************************************************************/
void transmit_byte(unsigned int val,unsigned int mode)
{ int i,a, out_data,w_cnt;
unsigned int tx_data;
unsigned int tx_data_shift;
unsigned int tx_stb;
tx_stb =0x00;
val &= 0xFF;
w_cnt = 0;
for (i=0;i<=7;i++) /*Sends LSB to MSB of the data*/
{ tx_data = (val & 0x01);
tx_data_shift = (tx_data<<1); /*Need to shift tx_data to the right by 1*/
tx_data_shift = (tx_data_shift & 0x02); /*Need to mask only the second bit others=0*/
outportb(lpt_base, tx_data_shift|tx_stb); /*Shift out to the required position*/
delay(tsu_delay); /*Delay the data to meet reg Tsu*/
out_data=(i & 0x01);
if (out_data==0)
{
tx_stb = 0x40;
outportb(lpt_base, tx_data_shift| tx_stb); /* Set nibble flag */
/************************* wait for flash-rom erase is end. *************************/
if (mode == 0) { /* mode is cnt_int in flash_memory_configuration */
//printf("Wait for flash-rom erase is end.\n");
while ((input_value() & 0x10) == 0); /* Await returned flag high */
}
else {
a = 0;
while ((input_value() & 0x10) == 0){
if( a > 20000){
printf("ACK signal is not changing. Abnormal Exit\n");
exit(1);
}
else {
delay(1);
a = a + 1;
}
}
}
}
if (out_data==1)
{
tx_stb=0x00;
outportb(lpt_base, tx_data_shift| tx_stb); /* Clear nibble flag */
if (mode == 0) {
while ((input_value() & 0x10) != 0){ /* Await returned flag low */
//Used to inform user that the Flashrom controller is currently erasing the Flashrom
w_cnt = w_cnt + 1;
if (w_cnt == 1500000) {
printf("#");
w_cnt = 0;
}}
}
else {
a = 0;
while ((input_value() & 0x10) != 0){
if( a > 20000){
printf("ACK signal is not changing. Abnormal Exit\n");
exit(1);
}
else {
delay(1);
a = a + 1;
}
}
}
}
val=(val>>1);
}
return;
}
/****************************************************************************/
/*Functions to set the hardware on the MAX device to a specifed mode. */
/****************************************************************************/
/*****Sends the APEX configuration CMD***************************************/
void APEX_configuration()
{ outportb(lpt_base, 0x03); //03 cmd_mode=1 and stb=0 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x43); //cmd_mode=1 and stb=1 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x41); //cmd_mode=1 and stb=1 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x01); //cmd_mode=1 and stb=0 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x00); //signals are set to low
}
/*****Sends the Verify configuration CMD*************************************/
void verify_configuration()
{ outportb(lpt_base, 0x03); //cmd_mode=1 and stb=0 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x43); //cmd_mode=1 and stb=1 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x43); //cmd_mode=1 and stb=1 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x03); //cmd_mode=1 and stb=0 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x00); //signals are set to low
}
/*****Sends the Idle configuration CMD***************************************/
void idle_state_configuration()
{ outportb(lpt_base, 0x01); //cmd_mode=1 and stb=0 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x41); //cmd_mode=1 and stb=1 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x41); //cmd_mode=1 and stb=1 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x01); //cmd_mode=1 and stb=0 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x00); //signals are set to low
}
/*****Sends the FLASH configuration CMD***************************************/
void flash_configuration()
{
delay(cmd_delay); // ADD MISAWA 2000.11.08
outportb(lpt_base, 0x00); // ADD MISAWA 2000.11.08
delay(cmd_delay); // ADD MISAWA 2000.11.08
//DATA IS 01(FLASH WRITE)
outportb(lpt_base, 0x01); //02 cmd_mode=1
delay(cmd_delay);
//printf("Setting back to 1\n");
outportb(lpt_base, 0x41); //42cmd_mode=1 and stb=1 and data=0
delay(cmd_delay);
outportb(lpt_base, 0x43); //cmd_mode=1 and stb=1 and data=1
delay(cmd_delay);
outportb(lpt_base, 0x03); //cmd_mode=1 and stb=0 and data=1
//printf("Setting back to 0\n");
delay(cmd_delay);
outportb(lpt_base, 0x00); //signals are set to low
}
/*****Function to configure the FLASH MEM************************************/
void flash_memory_configuration(int argc, char *argv[])
{
FILE *f;
char one_byte[3];
int cnt_int, i, char_cnt, byte_val,d_cnt;
char c;
printf("Start FLASH-ROM Erasing...\n");
flash_configuration(); // FLASH ERASE COMMAND TO MAX3000
cnt_int = 0;
//initialize the char buffer
for (i=0; i<3; i++)
one_byte[i]=' ';
char_cnt = 0;
d_cnt = 0;
f=fopen(argv[1],"r");
while (( c =(char) fgetc(f)) != EOF)//For processing .ttf files
{
if (c != ',')
{
if (char_cnt == 0)
{
one_byte[2] = c;
char_cnt++;
}
else if (char_cnt == 1)
{
one_byte[1] = one_byte[2];
one_byte[2] = c;
char_cnt++;
}
else
{
one_byte[0] = one_byte[1];
one_byte[1] = one_byte[2];
one_byte[2] = c;
}
}
else
{
sscanf(one_byte, "%d", &byte_val);
transmit_byte(byte_val, cnt_int);//sending a byte to Max3000 after it erased of Flashrom
//used to inform user that the PC is sending data to the Max3000 device
d_cnt = d_cnt + 1;
if ( d_cnt == 40000) {
printf("*");
d_cnt = 0;
}
//-----------------------------------------
if (cnt_int == 0 )
{
printf("\nStart Programming Flash ROM...\n");
cnt_int = 1;
}
//initialize the char buffer
for (i=0; i<3; i++)
one_byte[i]=' ';
char_cnt = 0;
}
}
fclose(f);
}
/****** Get pararell port data(conf_status)***********************************/
unsigned int input_value2(void)
{ static unsigned char last_value = 0xFF;
unsigned char new1, new2;
new1 = inportb(lpt_base + 1) & 0xF8;
if (new1 != last_value)
{ while (1)
{ new2 = inportb(lpt_base + 1) & 0xF8;
if (new2 == new1) /* Wait for stable value */
break;
new1 = new2; //Look for a change in logic state
}
last_value = new1;
}
// printf("last_value : %x \n",last_value);
return (last_value & 0x10) ;
}
/*****Function to FLASH MEM偐傜偺data偺庢摼************************************/
void verify_getdata()
//void verify_getdata(int argc, char *argv[])
{
FILE *f;
char one_byte[8],port_data;
int a,flg,total_byte,data_cnt,i;
int port_datab,u_cnt;
char byte_datac;
char byte_data[8];
//initialization
flg = 0;
total_byte = 0;
data_cnt = 0;
u_cnt = 0;
for (i=0; i<8; i++){//initialization
one_byte[i]=' ';
}
port_data = ' ';
//TMP-file open
f=fopen("tmpdata.txt","w");
//STB偐傜Low傪弌椡
outportb(lpt_base, 0x00); //signals are set to low
delay(cmd_delay);
a = 0;
while ((input_value() & 0x10) != 16) {
if( a > 20000){
printf("Verify:ACK signal is not changing. Abnormal Exit\n");
exit(1);
}
else {
delay(1);
a = a + 1;
}
}
delay(cmd_delay);
printf("Start uploading from Flashrom
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -