/* DP83820 flash utility written by Dave Ashley for NXTV, Inc. Copyright (C) 2004 by NXTV, Inc. Written 20040219 by Dave Ashley. Currently only supports the AT29C512 This code is released under the terms of the GPL. No warranty. THEORY: This code uses the /proc/dp83820 file which is created by the dp83820flash.o module. That file allows single byte reads + writes to the bootrom. */ #include #include #include #include #include #include #include #include #include #include // SMC9462TX card has D5 + D6 on the bootrom socket reversed int fixb(int val) { return (val&~0x60) | ((val&0x20)<<1) | ((val&0x40)>>1); } int openit(void) { int fd; fd=open("/proc/dp83820",O_RDWR); if(fd<0) { printf("Failed to open the /proc/dp83820 file to access the flashrom.\n"); printf("Make sure you've done:\n"); printf(" modprobe dp83820flash\n"); exit(-1); } return fd; } void set(int addr, unsigned char val) { unsigned char msg[3]; int fd; fd=openit(); msg[0]=addr; msg[1]=addr>>8; msg[2]=val; write(fd,msg,3); close(fd); } int get(int addr) { unsigned char msg[2]; int fd; fd=openit(); msg[0]=addr; msg[1]=addr>>8; write(fd,msg,2); read(fd,msg,1); close(fd); return msg[0]; } int getromsize(unsigned char *id) { if(id[0]==0xbf && id[1]==0xb6) return 0x40000; if(id[0]==0xc2 && id[1]==0xb0) return 0x40000; if(id[0]==0x1f && id[1]==0x3d) return 0x10000; return -1; } #define MAXROMSIZE 0x200000 unsigned char *buffer; int loadfile(char *name) { int filefd; int filesize; filefd=open(name,O_RDONLY); if(filefd<0) { printf("Couldn't open file %s\n",name); return -1; } filesize=read(filefd,buffer,MAXROMSIZE); close(filefd); if(filesize<0) { printf("Error trying to read from file %s\n",name); } return filesize; } void readbios(char *name,int len) { int filefd; int filesize=0; unsigned char block[256]; int i,j; filefd=open(name,O_WRONLY|O_TRUNC|O_CREAT,0644); if(filefd<0) { printf("Couldn't create file %s for writing\n",name); return; } for(i=j=0;i\n",name); printf(" -v = verify bios rom contents with file\n"); printf(" -w = write to bios rom contents from file\n"); printf(" -r = read from bios rom contents to file\n"); printf(" -f = force erase/write even if contents already match\n"); exit(0); } int main(int argc,char **argv) { int i; int vals; unsigned char id[4]; char *filename=0; char action=0; int romsize; int force=0; int same; vals=0; if(argc<2) helptext(argv[0]); for(i=1;i