<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reading the firmware ROM from a Renesas uPD720202 USB 3.0 Host Controller using Linux</title>
	<atom:link href="http://billauer.se/blog/2015/11/renesas-rom-setpci/feed/" rel="self" type="application/rss+xml" />
	<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/</link>
	<description>Anything I found worthy to write down.</description>
	<lastBuildDate>Thu, 26 Mar 2026 13:15:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: gdes</title>
		<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/comment-page-1/#comment-1520</link>
		<dc:creator>gdes</dc:creator>
		<pubDate>Thu, 03 Sep 2020 10:13:48 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=4832#comment-1520</guid>
		<description>Hi,

I have the following;
03:00.0 USB controller: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller (rev 03)

When I run setpci -s 03:00.0 fw.6, I get 8000 as expected. However, when I run setpci -s 03:00.0 ec.1 I get the following error message.

setpci: Invalid width &quot;1&quot;.

My knowledge about eeprom etc is zilch so would appreciate if you can shed some light on what is going on with my card.

Many thanks</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have the following;<br />
03:00.0 USB controller: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller (rev 03)</p>
<p>When I run setpci -s 03:00.0 fw.6, I get 8000 as expected. However, when I run setpci -s 03:00.0 ec.1 I get the following error message.</p>
<p>setpci: Invalid width &#8220;1&#8243;.</p>
<p>My knowledge about eeprom etc is zilch so would appreciate if you can shed some light on what is going on with my card.</p>
<p>Many thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AreYouLoco?</title>
		<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/comment-page-1/#comment-1471</link>
		<dc:creator>AreYouLoco?</dc:creator>
		<pubDate>Tue, 14 Jan 2020 22:23:46 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=4832#comment-1471</guid>
		<description>https://raw.githubusercontent.com/markusj/upd72020x-load/master/upd72020x-load.c</description>
		<content:encoded><![CDATA[<p><a href="https://raw.githubusercontent.com/markusj/upd72020x-load/master/upd72020x-load.c" rel="nofollow">https://raw.githubusercontent.com/markusj/upd72020x-load/master/upd72020x-load.c</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bushytails</title>
		<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/comment-page-1/#comment-1225</link>
		<dc:creator>Bushytails</dc:creator>
		<pubDate>Fri, 27 Jan 2017 22:23:49 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=4832#comment-1225</guid>
		<description>Unfortunately, more than just the indentation was lost.  Have a .c file?</description>
		<content:encoded><![CDATA[<p>Unfortunately, more than just the indentation was lost.  Have a .c file?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eli</title>
		<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/comment-page-1/#comment-1137</link>
		<dc:creator>eli</dc:creator>
		<pubDate>Thu, 05 Nov 2015 17:12:09 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=4832#comment-1137</guid>
		<description>Thanks for that input. Too bad the indentation was lost (hope only that).</description>
		<content:encoded><![CDATA[<p>Thanks for that input. Too bad the indentation was lost (hope only that).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jf simon</title>
		<link>https://billauer.se/blog/2015/11/renesas-rom-setpci/comment-page-1/#comment-1136</link>
		<dc:creator>jf simon</dc:creator>
		<pubDate>Thu, 05 Nov 2015 16:12:05 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=4832#comment-1136</guid>
		<description>i hated that chip. I got this work though. for what it is worth.
-jfs

usage: upd72020 -r -b  -d  -f    -s  -o outfile :  read eeprom to file (size default is 0x10000 or 64KB)
usage: upd72020 -w -b  -d  -f    -i iinfile :  write file to eeprom



upd720202.c:
 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define FAILED  &quot;                                ======&gt;  FAILED&quot;
#define PASSED  &quot;                                ======&gt;  PASSED&quot;


#define	ROM_INFORMATION_NUMONYX_M25P40 0x00202013   //ROM information for our eeprom device. See table 6.1 in doc
#define	ROM_PARAMETER_NUMONYX_M25P40   0x00000760   //ROM information for our eeprom device. See table 6.1 in doc

#define	EXT_ROM_INFO_REG	0xEC
#define	EXT_ROM_CONFIG_REG	0xF0
#define	EXT_ROM_FW_DLOAD_CTRL_STATUS	0xF4
#define	EXT_ROM_CTRL_STATUS		0xF6
#define	EXT_ROM_DATA0			0xF8
#define	EXT_ROM_DATA1			0xFC

#define GET_DATA0	0	
#define GET_DATA1	1	
#define GET_DATA0_OFF	10	
#define GET_DATA1_OFF   11	
#define SET_DATA0	0	
#define SET_DATA1	1	
#define SET_DATA0_OFF	8	
#define SET_DATA1_OFF	9	
#define GET	0	
#define SET	1	
#define DISABLE	0	
#define ENABLE	1	
#define LOOPNB	100000	

int pci_cfg_read32( int fd, u_int off){
        u_int val32;
        lseek(fd, off, SEEK_SET);
        read(fd, &amp;val32, 4);
        return val32;
}
int pci_cfg_write32( int fd, u_int off, u_int val32){
        lseek(fd, off, SEEK_SET);
        return write(fd, &amp;val32, 4);
}

int pci_cfg_read16( int fd, u_int off){
	u_int val16;
	lseek(fd, off, SEEK_SET);
	read(fd, &amp;val16, 2);
	return val16;
}
int pci_cfg_write16( int fd, u_int off, u_int val16){
	lseek(fd, off, SEEK_SET);
	return write(fd, &amp;val16, 2);
}

int set_data0_1( u_int fd,  u_int datareg, u_int action){

	u_int reg;
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
	if (datareg == SET_DATA0){
        	if (action == SET){
                	reg = reg &#124; (0x1 &lt;&lt; SET_DATA0_OFF);
                	return pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );
		}else{
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );
			reg &amp;= (0x1 &lt;&lt; SET_DATA0_OFF);
			return reg ;
		}
	}else{
        	if (action == SET){
                	reg = reg &#124; (0x1 &lt;&lt; SET_DATA1_OFF);
                	return pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );
		}else{
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );
			reg &amp;=(0x1 &lt;&lt; SET_DATA1_OFF);
			return reg ;
		}
	}
}
int get_data0_1( u_int fd,  u_int datareg, u_int action){

	u_int reg=0;
	if (datareg == GET_DATA0){
        	if (action == SET){
        		reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
                	reg = reg &#124; (0x1 &lt;&lt; GET_DATA0_OFF);
                	pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );
			return 0;
		}else{
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );
			reg &amp;= (0x1 &lt;&lt; GET_DATA0_OFF);
			return reg ;
		}
	}else{
        	if (action == SET){
        		reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
                	reg = reg &#124; (0x1 &lt;&lt; GET_DATA1_OFF);
                	pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );
			return 0;
		}else{
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );
			reg &amp;=(0x1 &lt;&lt; GET_DATA1_OFF);
			return reg ;
		}
	}
}

int external_rom_access( int fd, int enable){
	u_int reg, ix;

        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
        if (enable){
                reg = reg &#124; 0x1;
                pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );

		for (ix&lt;0;ix&lt;LOOPNB;ix++){
			reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS);
			//printf (&quot;reg %x\n&quot;, reg);
			if ( (reg &amp;0x70) ==0 )
				return 0;
		}
		printf(&quot;cant enable ext rom access\n&quot;);
		return -1;
        }else{
                //disable it
                reg = reg &amp; ~0x1;
                pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );
		return 0;
	}
}


int external_rom_erase( int fd){
        u_int reg, ix;

        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
        reg = reg &#124; 0x2;
        pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );

        for (ix&lt;0;ix&lt;LOOPNB;ix++){
			sleep(1);
                        reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS);
                        if ( (reg &amp;0x02) ==0 )
                                return 0;
                }
        printf(&quot;ERROR: cant erase ext rom \n&quot;);
	return -1;
}



int read_eeprom(int fd, unsigned char *filename, unsigned int len){

	int ofile;
	u_int reg, ix, jx, val32;

	ofile = open(filename, O_CREAT &#124; O_RDWR &#124; O_TRUNC);
	if (ofile &lt;0){
		printf(&quot;ERROR: cant open file %s\n&quot;, filename);
		return 1;
	}

	//--is ROM present?
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
	if (reg &lt; 0){
		printf(&quot;ERROR: PCI CFG read of EXT_ROM_CTRL_STATUS register failed\n&quot;);
		return 1;
    }

	if (!(reg &amp; 0x8000)){
		printf(&quot;ERROR: ROM doesnt exist\n&quot;);
		return 1;
	}

	//--write pattern
	if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x53524F4D) &lt;0){
		printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);
		return 1;
    }

	//--enable access
	if (external_rom_access(fd, ENABLE) &lt; 0){
		printf(&quot;ERROR: cant enable access to ROM \n&quot;);
		return 1;
    }
	sleep(2);

	if (get_data0_1(fd, GET_DATA0, SET) &lt;0){
		printf(&quot;ERROR: cant set GET_DATA0\n&quot;);
		return 1;	
	}
	if (get_data0_1(fd, GET_DATA1, SET) &lt;0){
		printf(&quot;ERROR: cant set GET_DATA1\n&quot;);
		return 1;	
	}
	sleep(2);
	//printf(&quot;before reg %x\n&quot;, pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS ));

	for (ix=0;ix&lt;len/8;ix++){

		for (jx=0;jx&lt;LOOPNB;jx++){
			if (get_data0_1(fd, GET_DATA0, GET) == 0)
				break;
		}
		if (jx == LOOPNB){
			printf(&quot;ERROR: GET_DATA0 never go to zero\n&quot;);
			return 1;	
		}
		usleep(8000);
		//printf(&quot;after reg %x\n&quot;, pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS ));
		
		//read eeprom
		val32 = pci_cfg_read32(fd, EXT_ROM_DATA0);
		//printf (&quot;val32=%x\n&quot;, val32);
		if (val32 &lt;0){
		    printf(&quot;ERROR: PCI CFG read of EXT_ROM_DATA0 register failed\n&quot;);
			return 1;
        }
		usleep(4000);
		if (get_data0_1(fd, GET_DATA0, SET) &lt;0){
		    printf(&quot;ERROR: cant set GET_DATA0\n&quot;);
			return 1;	
        }
		write(ofile, &amp;val32, 4);

		usleep(8000);

		for (jx&lt;0;jx&lt;LOOPNB;jx++){
			usleep(1000);
			if (get_data0_1(fd, GET_DATA1, GET) == 0)
				break;
		}
		if (jx == LOOPNB){
			printf(&quot;ERROR: GET_DATA1 not zero\n&quot;);
			return 1;	
		}
		usleep(4000);


		//read eeprom
		val32 = pci_cfg_read32(fd, EXT_ROM_DATA1);
		//printf (&quot;val32=%x\n&quot;, val32);
		if (val32 &lt;0){
		    printf(&quot;ERROR: PCI CFG read of EXT_ROM_DATA0 register failed\n&quot;);
			return 1;
        }

		if (get_data0_1(fd, GET_DATA1, SET) &lt;0){
		    printf(&quot;ERROR: cant set GET_DATA1\n&quot;);
			return 1;	
        }
		write(ofile, &amp;val32, 4);

	} 
	if (external_rom_access(fd, DISABLE) &lt; 0){
		printf(&quot;ERROR: cant DISABLE access to ROM\n&quot;);
		return 1;
    }


    return 0;  //Success!

}


int write_eeprom(int fd, unsigned char *filename, unsigned int len){

	int ifile;
	u_int reg, ix, jx, val32, rc;

	ifile = open(filename, O_RDWR );
	if (ifile &lt;0){
		printf(&quot;ERROR: cant open file image %s\n&quot;, filename);
		return 1;
	}


	//--is ROM present?
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );
	if (reg &lt; 0){
        	printf(&quot;ERROR: PCI CFG read of EXT_ROM_CTRL_STATUS register failed\n&quot;); 
		return 1;
    }

	if (!(reg &amp; 0x8000)){
		printf(&quot;ERROR: ROM doesnt exist\n&quot;);
		return 1;
	}


        //--Doing the EEPROM erase: write pattern
	printf(&quot;Erasing eeprom\n&quot;);
        if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x5A65726F) &lt;0){
        	printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);
                return 1;
    	}
	if (external_rom_erase(fd)&lt;0)
		return 1;

	printf(&quot;.....erase done\n&quot;);

	//--step2: write pattern
	if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x53524F4D) &lt;0){
        printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);
		return 1;
    }

	//--enable access
	if (external_rom_access(fd, ENABLE) &lt; 0){
        printf(&quot;ERROR: cant enable access to ROM \n&quot;);
		return 1;
    }
    sleep(1);
    //-- step5: Read “Set DATA0” and confirm it is ‘0b’.
    
	for (jx=0;jx&lt;LOOPNB;jx++){
		if (set_data0_1(fd, SET_DATA0, GET) == 0)
			break;
	}
	if (jx == LOOPNB){
		printf(&quot;ERROR: SET_DATA0 not zero\n&quot;);
		return 1;	
	}

    //-- step6: Write FW data to”DATA0”
    rc = read(ifile, &amp;val32, 4);
    if ( rc &lt;0){
        printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);
        return 1;
    }
    if ( rc != 4){
        printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);
        return 1;
    }
    //printf(&quot;fw val = %x\n&quot;, val32);
    if (pci_cfg_write32(fd, EXT_ROM_DATA0, val32) &lt;0){
        printf(&quot;ERROR: Cant write eeprom at step6\n&quot;);
        return 1;
    }


    //-- step7: Read “Set DATA1” and confirm it is ‘0b’.
    
	for (jx=0;jx&lt;LOOPNB;jx++){
		if (set_data0_1(fd, SET_DATA1, GET) == 0)
			break;
	}
	if (jx == LOOPNB){
		printf(&quot;ERROR: SET_DATA1 not zero\n&quot;);
		return 1;	
	}

    //-- step8: Write FW data to”DATA1”
    rc = read(ifile, &amp;val32, 4);
    if ( rc &lt;0){
        printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);
        return 1;
    }
    if ( rc != 4){
        printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);
        return 1;
    }

    //printf(&quot;fw val = %x\n&quot;, val32);
    if (pci_cfg_write32(fd, EXT_ROM_DATA1, val32) &lt;0){
        printf(&quot;ERROR: Cant write eeprom at step8\n&quot;);
        return 1;
    }


    //-- step9: Set “Set DATA0” and “Set DATA1” to ‘1b’.
	if (set_data0_1(fd, SET_DATA0, SET) &lt;0){
		printf(&quot;ERROR: cant set SET_DATA0\n&quot;);
		return 1;	
	}
	if (set_data0_1(fd, SET_DATA1, SET) &lt;0){
		printf(&quot;ERROR: cant set SET_DATA1\n&quot;);
		return 1;	
	}


	//printf(&quot;write01\n&quot;);


	//for (ix=0;ix&lt;len/8;ix++){
    while(1){                //do it til end of file image
	//printf(&quot;writeloop\n&quot;);

        //-- step10: Read “Set DATA0” and confirm it is ‘0b’.
        
		for (jx=0;jx&lt;LOOPNB;jx++){
			if (set_data0_1(fd, SET_DATA0, GET) == 0)
				break;
		}
		if (jx == LOOPNB){
			printf(&quot;ERROR: SET_DATA0 not zero\n&quot;);
			return 1;	
		}

	//usleep(8000);
        //-- step11: Write FW data to”DATA0”
    	rc = read(ifile, &amp;val32, 4);
    	if ( rc &lt;0){
        	printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);
        	return 1;
    	}
    	if ( rc != 4){
        	printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);
        	return 1;
    	}
    	//printf(&quot;fw val = %x\n&quot;, val32);

        if (pci_cfg_write32(fd, EXT_ROM_DATA0, val32) &lt;0){
            printf(&quot;ERROR: Cant write eeprom at step11\n&quot;);
            return 1;
        }
	usleep(8000);

        //-- step12: Set “Set DATA0” to ‘1b’.
	    if (set_data0_1(fd, SET_DATA0, SET) &lt;0){
		    printf(&quot;ERROR: cant set SET_DATA0\n&quot;);
		    return 1;	
	    }

	usleep(8000);
        //-- step13: Read “Set DATA1” and confirm it is ‘0b’.
		for (jx=0;jx&lt;LOOPNB;jx++){
			if (set_data0_1(fd, SET_DATA1, GET) == 0)
				break;
		}
		if (jx == LOOPNB){
			printf(&quot;ERROR: SET_DATA1 not zero\n&quot;);
			return 1;	
		}
   
	usleep(8000);
        //-- step14: Write FW data to”DATA1”
    	rc = read(ifile, &amp;val32, 4);
    	if ( rc &lt;0){
        	printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);
        	return 1;
    	}
    	if ( rc != 4){
        	printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);
        	return 1;
    	}
    	//printf(&quot;fw val = %x\n&quot;, val32);
        if (pci_cfg_write32(fd, EXT_ROM_DATA1, val32) &lt;0){
            printf(&quot;ERROR: Cant write eeprom at step14\n&quot;);
            return 1;
        }

	usleep(8000);

        //-- step15: Set “Set DATA1” to ‘1b’.
	    if (set_data0_1(fd, SET_DATA1, SET) &lt;0){
		    printf(&quot;ERROR: cant set SET_DATA1\n&quot;);
		    return 1;	
	    }
	usleep(8000);
    }
	if (external_rom_access(fd, DISABLE) &lt; 0){
        printf(&quot;ERROR: cant DISABLE access to ROM\n&quot;);
		return 1;
    }

    return 0; //Success!
}



void usage(){

        printf(&quot;upd72020: version 1.0\n&quot;);
        printf(&quot;usage: upd72020 -r -b  -d  -f    -s  -o outfile :  read eeprom to file (size default is 0x10000 or 64KB)\n&quot;);
        //printf(&quot;usage: upd7202 -c -b  -d  -f    -s  -i outfile :  check eeprom against file\n&quot;);
        printf(&quot;usage: upd72020 -w -b  -d  -f    -i iinfile :  write file to eeprom\n&quot;);

}

int
main (int argc, char **argv)
{
        //const uint32_t BAR_LENGTH = 0x2000;
        //const uint32_t CTRL_REGS  =  0x80000;
        //const uint32_t CTRL_LEN   =     0x30;

	unsigned char pcidevid[] = {0x12, 0x19, 0x15, 0x00};   //vendor id = 1912  devid = 0015
	unsigned char val;
        unsigned char buf[100];
        unsigned int len;

        int i, fd;
        uint32_t *ptr;

        uint32_t bus, dev, fct, size;
	uint32_t rflag=0;
	uint32_t wflag=0;
	uint32_t cflag, bflag, dflag, fflag, sflag, fileflag = 0;
        char *filename = NULL;
        char pcicfgfile[100];
	int c;
	opterr = 0;

	//printf (&quot;argc %d\n&quot;, argc);

        if (argc &lt; 10){
                usage();
                exit(1);
        }

// -b bus -d dev -f fct -f file -l len 

	while ((c = getopt (argc, argv, &quot;rwb:d:f:o:i:l:s:&quot;)) != -1){
		switch (c) {
		case &#039;r&#039;:
			printf(&quot;Doing the reading\n&quot;);
			rflag =1;
			break;
		case &#039;c&#039;:
			cflag =1;
			break;
		case &#039;w&#039;:
			printf(&quot;Doing the writing\n&quot;);
			wflag =1;
			break;
		case &#039;b&#039;:
			bflag = 1;
			printf(&quot;bus is %s\n&quot;, optarg);
                        bus = strtoul(optarg, NULL, 16);        //hex numbers for size!!!
			break;	
		case &#039;d&#039;:
			dflag = 1;
                        dev = strtol(optarg, NULL, 16);        //hex numbers for size!!!
			break;	
		case &#039;f&#039;:
			fflag = 1;
                        fct = strtol(optarg, NULL, 16);        //hex numbers for size!!!
			break;	
		case &#039;s&#039;:
			sflag = 1;
                        size = strtol(optarg, NULL, 16);        //hex numbers for size!!!
			break;	
		case &#039;o&#039;:
			fileflag = 1;
                        filename = optarg;        //hex numbers for size!!!
			break;	
		case &#039;i&#039;:
			fileflag = 1;
                        filename = optarg;        //hex numbers for size!!!
			break;	

		default:
		break;
		}


 	}
	printf (&quot;bus = %x \n&quot;, bus);
	printf (&quot;dev = %x \n&quot;, dev);
	printf (&quot;fct = %x \n&quot;, fct);
	printf (&quot;fname = %s \n&quot;, filename);

	sprintf(pcicfgfile,&quot;/sys/bus/pci/devices/0000:%02x:%02x.%01x/config&quot;, bus, dev, fct);
	//printf(&quot;%s&quot;, pcicfgfile);

        fd = open(pcicfgfile, O_RDWR);
	if (fd &lt;0){
		printf(&quot;ERROR: cant open PCI CONFIGURATION file %s&quot;, pcicfgfile);
		printf(&quot;FAILED&quot;);
		exit(1);
	}

	//--make sure the device is the right one.
        len =4;
        read (fd, buf, len);

	for (i=0;i&lt;4;i++){
		if (pcidevid[i] != buf[i]){
			printf(&quot;ERROR: wrong vendorid/devid. We expect a UPD720202 chip and this is not one!&quot;);
			printf(FAILED);
			exit(1);
		}
	}

#if 0
#define ROM_INFORMATION_NUMONYX_M25P40 0x00202013   //ROM information for our eeprom device. See table 6.1 in doc
#define ROM_PARAMETER_NUMONYX_M25P40   0x00000760   //ROM information for our eeprom device. See table 6.1 in doc

#define EXT_ROM_INFO_REG        0xEC
#define EXT_ROM_CONFIG_REG      0xF0
#endif

	pci_cfg_write32( fd,  EXT_ROM_INFO_REG , ROM_INFORMATION_NUMONYX_M25P40);
	pci_cfg_write32( fd,  EXT_ROM_CONFIG_REG , ROM_PARAMETER_NUMONYX_M25P40);

	//printf (&quot;%x\n&quot;, pci_cfg_read16(fd, 0));
	//printf (&quot;%x\n&quot;, pci_cfg_read16(fd, 2));
	//printf (&quot;%x\n&quot;, pci_cfg_read32(fd, 0xec));
	//pci_cfg_write32(fd, 0xf0, 0xdeadbeef);
	//printf (&quot;%x\n&quot;, pci_cfg_read32(fd, 0xf0));


	if (rflag==1){
		if (read_eeprom(fd, filename, size)){
			printf(FAILED);
            		exit(1);
        	}else{
			printf(PASSED);
            		exit(0);
        	}

	}
	if (wflag==1){
		if (write_eeprom(fd, filename, size)){
			printf(FAILED);
            		exit(1);
        	}else{
			printf(PASSED);
            		exit(0);
        	}

	}

    printf(&quot;ERROR: Please specify an action. See help\n&quot;);


}</description>
		<content:encoded><![CDATA[<p>i hated that chip. I got this work though. for what it is worth.<br />
-jfs</p>
<p>usage: upd72020 -r -b  -d  -f    -s  -o outfile :  read eeprom to file (size default is 0x10000 or 64KB)<br />
usage: upd72020 -w -b  -d  -f    -i iinfile :  write file to eeprom</p>
<p>upd720202.c:</p>
<p>#include<br />
#include<br />
#include<br />
#include<br />
#include<br />
#include<br />
#include<br />
#include </p>
<p>#define FAILED  &#8221;                                ======&gt;  FAILED&#8221;<br />
#define PASSED  &#8221;                                ======&gt;  PASSED&#8221;</p>
<p>#define	ROM_INFORMATION_NUMONYX_M25P40 0x00202013   //ROM information for our eeprom device. See table 6.1 in doc<br />
#define	ROM_PARAMETER_NUMONYX_M25P40   0x00000760   //ROM information for our eeprom device. See table 6.1 in doc</p>
<p>#define	EXT_ROM_INFO_REG	0xEC<br />
#define	EXT_ROM_CONFIG_REG	0xF0<br />
#define	EXT_ROM_FW_DLOAD_CTRL_STATUS	0xF4<br />
#define	EXT_ROM_CTRL_STATUS		0xF6<br />
#define	EXT_ROM_DATA0			0xF8<br />
#define	EXT_ROM_DATA1			0xFC</p>
<p>#define GET_DATA0	0<br />
#define GET_DATA1	1<br />
#define GET_DATA0_OFF	10<br />
#define GET_DATA1_OFF   11<br />
#define SET_DATA0	0<br />
#define SET_DATA1	1<br />
#define SET_DATA0_OFF	8<br />
#define SET_DATA1_OFF	9<br />
#define GET	0<br />
#define SET	1<br />
#define DISABLE	0<br />
#define ENABLE	1<br />
#define LOOPNB	100000	</p>
<p>int pci_cfg_read32( int fd, u_int off){<br />
        u_int val32;<br />
        lseek(fd, off, SEEK_SET);<br />
        read(fd, &amp;val32, 4);<br />
        return val32;<br />
}<br />
int pci_cfg_write32( int fd, u_int off, u_int val32){<br />
        lseek(fd, off, SEEK_SET);<br />
        return write(fd, &amp;val32, 4);<br />
}</p>
<p>int pci_cfg_read16( int fd, u_int off){<br />
	u_int val16;<br />
	lseek(fd, off, SEEK_SET);<br />
	read(fd, &amp;val16, 2);<br />
	return val16;<br />
}<br />
int pci_cfg_write16( int fd, u_int off, u_int val16){<br />
	lseek(fd, off, SEEK_SET);<br />
	return write(fd, &amp;val16, 2);<br />
}</p>
<p>int set_data0_1( u_int fd,  u_int datareg, u_int action){</p>
<p>	u_int reg;<br />
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
	if (datareg == SET_DATA0){<br />
        	if (action == SET){<br />
                	reg = reg | (0x1 &lt;&lt; SET_DATA0_OFF);<br />
                	return pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );<br />
		}else{<br />
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );<br />
			reg &amp;= (0x1 &lt;&lt; SET_DATA0_OFF);<br />
			return reg ;<br />
		}<br />
	}else{<br />
        	if (action == SET){<br />
                	reg = reg | (0x1 &lt;&lt; SET_DATA1_OFF);<br />
                	return pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );<br />
		}else{<br />
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );<br />
			reg &amp;=(0x1 &lt;&lt; SET_DATA1_OFF);<br />
			return reg ;<br />
		}<br />
	}<br />
}<br />
int get_data0_1( u_int fd,  u_int datareg, u_int action){</p>
<p>	u_int reg=0;<br />
	if (datareg == GET_DATA0){<br />
        	if (action == SET){<br />
        		reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
                	reg = reg | (0x1 &lt;&lt; GET_DATA0_OFF);<br />
                	pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );<br />
			return 0;<br />
		}else{<br />
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );<br />
			reg &amp;= (0x1 &lt;&lt; GET_DATA0_OFF);<br />
			return reg ;<br />
		}<br />
	}else{<br />
        	if (action == SET){<br />
        		reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
                	reg = reg | (0x1 &lt;&lt; GET_DATA1_OFF);<br />
                	pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );<br />
			return 0;<br />
		}else{<br />
                	reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS );<br />
			reg &amp;=(0x1 &lt;&lt; GET_DATA1_OFF);<br />
			return reg ;<br />
		}<br />
	}<br />
}</p>
<p>int external_rom_access( int fd, int enable){<br />
	u_int reg, ix;</p>
<p>        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
        if (enable){<br />
                reg = reg | 0x1;<br />
                pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );</p>
<p>		for (ix&lt;0;ix&lt;LOOPNB;ix++){<br />
			reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS);<br />
			//printf (&quot;reg %x\n&quot;, reg);<br />
			if ( (reg &amp;0x70) ==0 )<br />
				return 0;<br />
		}<br />
		printf(&quot;cant enable ext rom access\n&quot;);<br />
		return -1;<br />
        }else{<br />
                //disable it<br />
                reg = reg &amp; ~0x1;<br />
                pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );<br />
		return 0;<br />
	}<br />
}</p>
<p>int external_rom_erase( int fd){<br />
        u_int reg, ix;</p>
<p>        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
        reg = reg | 0x2;<br />
        pci_cfg_write16(fd, EXT_ROM_CTRL_STATUS, reg );</p>
<p>        for (ix&lt;0;ix&lt;LOOPNB;ix++){<br />
			sleep(1);<br />
                        reg = pci_cfg_read16(fd, EXT_ROM_CTRL_STATUS);<br />
                        if ( (reg &amp;0x02) ==0 )<br />
                                return 0;<br />
                }<br />
        printf(&quot;ERROR: cant erase ext rom \n&quot;);<br />
	return -1;<br />
}</p>
<p>int read_eeprom(int fd, unsigned char *filename, unsigned int len){</p>
<p>	int ofile;<br />
	u_int reg, ix, jx, val32;</p>
<p>	ofile = open(filename, O_CREAT | O_RDWR | O_TRUNC);<br />
	if (ofile &lt;0){<br />
		printf(&quot;ERROR: cant open file %s\n&quot;, filename);<br />
		return 1;<br />
	}</p>
<p>	//&#8211;is ROM present?<br />
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
	if (reg &lt; 0){<br />
		printf(&quot;ERROR: PCI CFG read of EXT_ROM_CTRL_STATUS register failed\n&quot;);<br />
		return 1;<br />
    }</p>
<p>	if (!(reg &amp; 0x8000)){<br />
		printf(&quot;ERROR: ROM doesnt exist\n&quot;);<br />
		return 1;<br />
	}</p>
<p>	//&#8211;write pattern<br />
	if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x53524F4D) &lt;0){<br />
		printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);<br />
		return 1;<br />
    }</p>
<p>	//&#8211;enable access<br />
	if (external_rom_access(fd, ENABLE) &lt; 0){<br />
		printf(&quot;ERROR: cant enable access to ROM \n&quot;);<br />
		return 1;<br />
    }<br />
	sleep(2);</p>
<p>	if (get_data0_1(fd, GET_DATA0, SET) &lt;0){<br />
		printf(&quot;ERROR: cant set GET_DATA0\n&quot;);<br />
		return 1;<br />
	}<br />
	if (get_data0_1(fd, GET_DATA1, SET) &lt;0){<br />
		printf(&quot;ERROR: cant set GET_DATA1\n&quot;);<br />
		return 1;<br />
	}<br />
	sleep(2);<br />
	//printf(&quot;before reg %x\n&quot;, pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS ));</p>
<p>	for (ix=0;ix&lt;len/8;ix++){</p>
<p>		for (jx=0;jx&lt;LOOPNB;jx++){<br />
			if (get_data0_1(fd, GET_DATA0, GET) == 0)<br />
				break;<br />
		}<br />
		if (jx == LOOPNB){<br />
			printf(&quot;ERROR: GET_DATA0 never go to zero\n&quot;);<br />
			return 1;<br />
		}<br />
		usleep(8000);<br />
		//printf(&quot;after reg %x\n&quot;, pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS ));</p>
<p>		//read eeprom<br />
		val32 = pci_cfg_read32(fd, EXT_ROM_DATA0);<br />
		//printf (&quot;val32=%x\n&quot;, val32);<br />
		if (val32 &lt;0){<br />
		    printf(&quot;ERROR: PCI CFG read of EXT_ROM_DATA0 register failed\n&quot;);<br />
			return 1;<br />
        }<br />
		usleep(4000);<br />
		if (get_data0_1(fd, GET_DATA0, SET) &lt;0){<br />
		    printf(&quot;ERROR: cant set GET_DATA0\n&quot;);<br />
			return 1;<br />
        }<br />
		write(ofile, &amp;val32, 4);</p>
<p>		usleep(8000);</p>
<p>		for (jx&lt;0;jx&lt;LOOPNB;jx++){<br />
			usleep(1000);<br />
			if (get_data0_1(fd, GET_DATA1, GET) == 0)<br />
				break;<br />
		}<br />
		if (jx == LOOPNB){<br />
			printf(&quot;ERROR: GET_DATA1 not zero\n&quot;);<br />
			return 1;<br />
		}<br />
		usleep(4000);</p>
<p>		//read eeprom<br />
		val32 = pci_cfg_read32(fd, EXT_ROM_DATA1);<br />
		//printf (&quot;val32=%x\n&quot;, val32);<br />
		if (val32 &lt;0){<br />
		    printf(&quot;ERROR: PCI CFG read of EXT_ROM_DATA0 register failed\n&quot;);<br />
			return 1;<br />
        }</p>
<p>		if (get_data0_1(fd, GET_DATA1, SET) &lt;0){<br />
		    printf(&quot;ERROR: cant set GET_DATA1\n&quot;);<br />
			return 1;<br />
        }<br />
		write(ofile, &amp;val32, 4);</p>
<p>	}<br />
	if (external_rom_access(fd, DISABLE) &lt; 0){<br />
		printf(&quot;ERROR: cant DISABLE access to ROM\n&quot;);<br />
		return 1;<br />
    }</p>
<p>    return 0;  //Success!</p>
<p>}</p>
<p>int write_eeprom(int fd, unsigned char *filename, unsigned int len){</p>
<p>	int ifile;<br />
	u_int reg, ix, jx, val32, rc;</p>
<p>	ifile = open(filename, O_RDWR );<br />
	if (ifile &lt;0){<br />
		printf(&quot;ERROR: cant open file image %s\n&quot;, filename);<br />
		return 1;<br />
	}</p>
<p>	//&#8211;is ROM present?<br />
        reg = pci_cfg_read16 (fd, EXT_ROM_CTRL_STATUS );<br />
	if (reg &lt; 0){<br />
        	printf(&quot;ERROR: PCI CFG read of EXT_ROM_CTRL_STATUS register failed\n&quot;);<br />
		return 1;<br />
    }</p>
<p>	if (!(reg &amp; 0x8000)){<br />
		printf(&quot;ERROR: ROM doesnt exist\n&quot;);<br />
		return 1;<br />
	}</p>
<p>        //&#8211;Doing the EEPROM erase: write pattern<br />
	printf(&quot;Erasing eeprom\n&quot;);<br />
        if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x5A65726F) &lt;0){<br />
        	printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);<br />
                return 1;<br />
    	}<br />
	if (external_rom_erase(fd)&lt;0)<br />
		return 1;</p>
<p>	printf(&quot;&#8230;..erase done\n&quot;);</p>
<p>	//&#8211;step2: write pattern<br />
	if (pci_cfg_write32(fd, EXT_ROM_DATA0, 0x53524F4D) &lt;0){<br />
        printf(&quot;ERROR: PCI CFG write of EXT_ROM_DATA0 register failed\n&quot;);<br />
		return 1;<br />
    }</p>
<p>	//&#8211;enable access<br />
	if (external_rom_access(fd, ENABLE) &lt; 0){<br />
        printf(&quot;ERROR: cant enable access to ROM \n&quot;);<br />
		return 1;<br />
    }<br />
    sleep(1);<br />
    //&#8211; step5: Read “Set DATA0” and confirm it is ‘0b’.</p>
<p>	for (jx=0;jx&lt;LOOPNB;jx++){<br />
		if (set_data0_1(fd, SET_DATA0, GET) == 0)<br />
			break;<br />
	}<br />
	if (jx == LOOPNB){<br />
		printf(&quot;ERROR: SET_DATA0 not zero\n&quot;);<br />
		return 1;<br />
	}</p>
<p>    //&#8211; step6: Write FW data to”DATA0”<br />
    rc = read(ifile, &amp;val32, 4);<br />
    if ( rc &lt;0){<br />
        printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);<br />
        return 1;<br />
    }<br />
    if ( rc != 4){<br />
        printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);<br />
        return 1;<br />
    }<br />
    //printf(&quot;fw val = %x\n&quot;, val32);<br />
    if (pci_cfg_write32(fd, EXT_ROM_DATA0, val32) &lt;0){<br />
        printf(&quot;ERROR: Cant write eeprom at step6\n&quot;);<br />
        return 1;<br />
    }</p>
<p>    //&#8211; step7: Read “Set DATA1” and confirm it is ‘0b’.</p>
<p>	for (jx=0;jx&lt;LOOPNB;jx++){<br />
		if (set_data0_1(fd, SET_DATA1, GET) == 0)<br />
			break;<br />
	}<br />
	if (jx == LOOPNB){<br />
		printf(&quot;ERROR: SET_DATA1 not zero\n&quot;);<br />
		return 1;<br />
	}</p>
<p>    //&#8211; step8: Write FW data to”DATA1”<br />
    rc = read(ifile, &amp;val32, 4);<br />
    if ( rc &lt;0){<br />
        printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);<br />
        return 1;<br />
    }<br />
    if ( rc != 4){<br />
        printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);<br />
        return 1;<br />
    }</p>
<p>    //printf(&quot;fw val = %x\n&quot;, val32);<br />
    if (pci_cfg_write32(fd, EXT_ROM_DATA1, val32) &lt;0){<br />
        printf(&quot;ERROR: Cant write eeprom at step8\n&quot;);<br />
        return 1;<br />
    }</p>
<p>    //&#8211; step9: Set “Set DATA0” and “Set DATA1” to ‘1b’.<br />
	if (set_data0_1(fd, SET_DATA0, SET) &lt;0){<br />
		printf(&quot;ERROR: cant set SET_DATA0\n&quot;);<br />
		return 1;<br />
	}<br />
	if (set_data0_1(fd, SET_DATA1, SET) &lt;0){<br />
		printf(&quot;ERROR: cant set SET_DATA1\n&quot;);<br />
		return 1;<br />
	}</p>
<p>	//printf(&quot;write01\n&quot;);</p>
<p>	//for (ix=0;ix&lt;len/8;ix++){<br />
    while(1){                //do it til end of file image<br />
	//printf(&quot;writeloop\n&quot;);</p>
<p>        //&#8211; step10: Read “Set DATA0” and confirm it is ‘0b’.</p>
<p>		for (jx=0;jx&lt;LOOPNB;jx++){<br />
			if (set_data0_1(fd, SET_DATA0, GET) == 0)<br />
				break;<br />
		}<br />
		if (jx == LOOPNB){<br />
			printf(&quot;ERROR: SET_DATA0 not zero\n&quot;);<br />
			return 1;<br />
		}</p>
<p>	//usleep(8000);<br />
        //&#8211; step11: Write FW data to”DATA0”<br />
    	rc = read(ifile, &amp;val32, 4);<br />
    	if ( rc &lt;0){<br />
        	printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);<br />
        	return 1;<br />
    	}<br />
    	if ( rc != 4){<br />
        	printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);<br />
        	return 1;<br />
    	}<br />
    	//printf(&quot;fw val = %x\n&quot;, val32);</p>
<p>        if (pci_cfg_write32(fd, EXT_ROM_DATA0, val32) &lt;0){<br />
            printf(&quot;ERROR: Cant write eeprom at step11\n&quot;);<br />
            return 1;<br />
        }<br />
	usleep(8000);</p>
<p>        //&#8211; step12: Set “Set DATA0” to ‘1b’.<br />
	    if (set_data0_1(fd, SET_DATA0, SET) &lt;0){<br />
		    printf(&quot;ERROR: cant set SET_DATA0\n&quot;);<br />
		    return 1;<br />
	    }</p>
<p>	usleep(8000);<br />
        //&#8211; step13: Read “Set DATA1” and confirm it is ‘0b’.<br />
		for (jx=0;jx&lt;LOOPNB;jx++){<br />
			if (set_data0_1(fd, SET_DATA1, GET) == 0)<br />
				break;<br />
		}<br />
		if (jx == LOOPNB){<br />
			printf(&quot;ERROR: SET_DATA1 not zero\n&quot;);<br />
			return 1;<br />
		}</p>
<p>	usleep(8000);<br />
        //&#8211; step14: Write FW data to”DATA1”<br />
    	rc = read(ifile, &amp;val32, 4);<br />
    	if ( rc &lt;0){<br />
        	printf(&quot;ERROR: Cant read image file %s \n&quot;, filename);<br />
        	return 1;<br />
    	}<br />
    	if ( rc != 4){<br />
        	printf(&quot;ERROR: Could not get 4 bytes. Only got %x\n&quot;, rc);<br />
        	return 1;<br />
    	}<br />
    	//printf(&quot;fw val = %x\n&quot;, val32);<br />
        if (pci_cfg_write32(fd, EXT_ROM_DATA1, val32) &lt;0){<br />
            printf(&quot;ERROR: Cant write eeprom at step14\n&quot;);<br />
            return 1;<br />
        }</p>
<p>	usleep(8000);</p>
<p>        //&#8211; step15: Set “Set DATA1” to ‘1b’.<br />
	    if (set_data0_1(fd, SET_DATA1, SET) &lt;0){<br />
		    printf(&quot;ERROR: cant set SET_DATA1\n&quot;);<br />
		    return 1;<br />
	    }<br />
	usleep(8000);<br />
    }<br />
	if (external_rom_access(fd, DISABLE) &lt; 0){<br />
        printf(&quot;ERROR: cant DISABLE access to ROM\n&quot;);<br />
		return 1;<br />
    }</p>
<p>    return 0; //Success!<br />
}</p>
<p>void usage(){</p>
<p>        printf(&quot;upd72020: version 1.0\n&quot;);<br />
        printf(&quot;usage: upd72020 -r -b  -d  -f    -s  -o outfile :  read eeprom to file (size default is 0x10000 or 64KB)\n&#8221;);<br />
        //printf(&#8220;usage: upd7202 -c -b  -d  -f    -s  -i outfile :  check eeprom against file\n&#8221;);<br />
        printf(&#8220;usage: upd72020 -w -b  -d  -f    -i iinfile :  write file to eeprom\n&#8221;);</p>
<p>}</p>
<p>int<br />
main (int argc, char **argv)<br />
{<br />
        //const uint32_t BAR_LENGTH = 0x2000;<br />
        //const uint32_t CTRL_REGS  =  0x80000;<br />
        //const uint32_t CTRL_LEN   =     0x30;</p>
<p>	unsigned char pcidevid[] = {0x12, 0x19, 0x15, 0x00};   //vendor id = 1912  devid = 0015<br />
	unsigned char val;<br />
        unsigned char buf[100];<br />
        unsigned int len;</p>
<p>        int i, fd;<br />
        uint32_t *ptr;</p>
<p>        uint32_t bus, dev, fct, size;<br />
	uint32_t rflag=0;<br />
	uint32_t wflag=0;<br />
	uint32_t cflag, bflag, dflag, fflag, sflag, fileflag = 0;<br />
        char *filename = NULL;<br />
        char pcicfgfile[100];<br />
	int c;<br />
	opterr = 0;</p>
<p>	//printf (&#8220;argc %d\n&#8221;, argc);</p>
<p>        if (argc &lt; 10){<br />
                usage();<br />
                exit(1);<br />
        }</p>
<p>// -b bus -d dev -f fct -f file -l len </p>
<p>	while ((c = getopt (argc, argv, &quot;rwb:d:f:o:i:l:s:&quot;)) != -1){<br />
		switch (c) {<br />
		case &#039;r&#039;:<br />
			printf(&quot;Doing the reading\n&quot;);<br />
			rflag =1;<br />
			break;<br />
		case &#039;c&#039;:<br />
			cflag =1;<br />
			break;<br />
		case &#039;w&#039;:<br />
			printf(&quot;Doing the writing\n&quot;);<br />
			wflag =1;<br />
			break;<br />
		case &#039;b&#039;:<br />
			bflag = 1;<br />
			printf(&quot;bus is %s\n&quot;, optarg);<br />
                        bus = strtoul(optarg, NULL, 16);        //hex numbers for size!!!<br />
			break;<br />
		case &#039;d&#039;:<br />
			dflag = 1;<br />
                        dev = strtol(optarg, NULL, 16);        //hex numbers for size!!!<br />
			break;<br />
		case &#039;f&#039;:<br />
			fflag = 1;<br />
                        fct = strtol(optarg, NULL, 16);        //hex numbers for size!!!<br />
			break;<br />
		case &#039;s&#039;:<br />
			sflag = 1;<br />
                        size = strtol(optarg, NULL, 16);        //hex numbers for size!!!<br />
			break;<br />
		case &#039;o&#039;:<br />
			fileflag = 1;<br />
                        filename = optarg;        //hex numbers for size!!!<br />
			break;<br />
		case &#039;i&#039;:<br />
			fileflag = 1;<br />
                        filename = optarg;        //hex numbers for size!!!<br />
			break;	</p>
<p>		default:<br />
		break;<br />
		}</p>
<p> 	}<br />
	printf (&quot;bus = %x \n&quot;, bus);<br />
	printf (&quot;dev = %x \n&quot;, dev);<br />
	printf (&quot;fct = %x \n&quot;, fct);<br />
	printf (&quot;fname = %s \n&quot;, filename);</p>
<p>	sprintf(pcicfgfile,&quot;/sys/bus/pci/devices/0000:%02x:%02x.%01x/config&quot;, bus, dev, fct);<br />
	//printf(&quot;%s&quot;, pcicfgfile);</p>
<p>        fd = open(pcicfgfile, O_RDWR);<br />
	if (fd &lt;0){<br />
		printf(&quot;ERROR: cant open PCI CONFIGURATION file %s&quot;, pcicfgfile);<br />
		printf(&quot;FAILED&quot;);<br />
		exit(1);<br />
	}</p>
<p>	//&#8211;make sure the device is the right one.<br />
        len =4;<br />
        read (fd, buf, len);</p>
<p>	for (i=0;i&lt;4;i++){<br />
		if (pcidevid[i] != buf[i]){<br />
			printf(&quot;ERROR: wrong vendorid/devid. We expect a UPD720202 chip and this is not one!&quot;);<br />
			printf(FAILED);<br />
			exit(1);<br />
		}<br />
	}</p>
<p>#if 0<br />
#define ROM_INFORMATION_NUMONYX_M25P40 0x00202013   //ROM information for our eeprom device. See table 6.1 in doc<br />
#define ROM_PARAMETER_NUMONYX_M25P40   0x00000760   //ROM information for our eeprom device. See table 6.1 in doc</p>
<p>#define EXT_ROM_INFO_REG        0xEC<br />
#define EXT_ROM_CONFIG_REG      0xF0<br />
#endif</p>
<p>	pci_cfg_write32( fd,  EXT_ROM_INFO_REG , ROM_INFORMATION_NUMONYX_M25P40);<br />
	pci_cfg_write32( fd,  EXT_ROM_CONFIG_REG , ROM_PARAMETER_NUMONYX_M25P40);</p>
<p>	//printf (&quot;%x\n&quot;, pci_cfg_read16(fd, 0));<br />
	//printf (&quot;%x\n&quot;, pci_cfg_read16(fd, 2));<br />
	//printf (&quot;%x\n&quot;, pci_cfg_read32(fd, 0xec));<br />
	//pci_cfg_write32(fd, 0xf0, 0xdeadbeef);<br />
	//printf (&quot;%x\n&quot;, pci_cfg_read32(fd, 0xf0));</p>
<p>	if (rflag==1){<br />
		if (read_eeprom(fd, filename, size)){<br />
			printf(FAILED);<br />
            		exit(1);<br />
        	}else{<br />
			printf(PASSED);<br />
            		exit(0);<br />
        	}</p>
<p>	}<br />
	if (wflag==1){<br />
		if (write_eeprom(fd, filename, size)){<br />
			printf(FAILED);<br />
            		exit(1);<br />
        	}else{<br />
			printf(PASSED);<br />
            		exit(0);<br />
        	}</p>
<p>	}</p>
<p>    printf(&quot;ERROR: Please specify an action. See help\n&quot;);</p>
<p>}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
