/* * readutil.c - perform various control ops on the 3c509b bios rom * */ #ifndef __i386__ # error "This program can't compile or run on non-intel computers" #else #include #include #include #include #ifdef __FreeBSD__ #include #include #define OUTB(data, port) outb(port, data) #define OUTW(data, port) outw(port, data) #define OUTL(data, port) outl(port, data) #else #include #define OUTB(data, port) outb(data, port) #define OUTW(data, port) outw(data, port) #define OUTL(data, port) outl(data, port) #endif /* * write_eeprom() and enum definitions are copied from vortex-diag.c, * Copyright 1997-2004 by Donald Becker. * This software may be used and distributed according to the terms of * the GNU General Public License (GPL), incorporated herein by reference. * Contact the author for use under other terms. */ enum vortex_cmd { TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11, RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, UpStall = 6<<11, UpUnstall = (6<<11)+1, DownStall = (6<<11)+2, DownUnstall = (6<<11)+3, RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11, FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11, SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11, SetTxThreshold = 18<<11, SetTxStart = 19<<11, StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11, StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11, }; enum Window0 { Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */ Wn0EepromData = 12, /* Window 0: EEPROM results register. */ IntrStatus=0x0E, /* Valid in all windows. */ }; enum Win0_EEPROM_cmds { EEPROM_Read = 2, EEPROM_WRITE = 1, EEPROM_ERASE = 3, EEPROM_EWENB = 0xC, /* Enable erasing/writing for 10 msec. */ EEPROM_EWDIS = 0x0, /* Disable EWENB before 10 msec timeout. */ }; #define debug 1 static void write_eeprom(long ioaddr, int addrlen, int index, int value) { int timer; /* Verify that the EEPROM is idle. */ for (timer = 1620; inw(ioaddr + Wn0EepromCmd) & 0x8000;) if (--timer < 0) goto error_return; /* Enable writing: EEPROM_EWENB | 110000.... */ OUTW(3 << (addrlen-2), ioaddr + Wn0EepromCmd); for (timer = 400; inw(ioaddr + Wn0EepromCmd) & 0x8000;) { if (--timer < 0) goto error_return; } if (debug) fprintf(stderr, "EEPROM write enable took %d ticks!\n", 400 - timer); OUTW((EEPROM_ERASE << addrlen) + index, ioaddr + Wn0EepromCmd); for (timer = 16000; inw(ioaddr + Wn0EepromCmd) & 0x8000;) if (--timer < 0) { fprintf(stderr, "EEPROM failed to erase index %d!\n", index); return; } if (debug) fprintf(stderr, "EEPROM erased index %d after %d ticks!\n", index, 16000-timer); OUTW(3 << (addrlen-2), ioaddr + Wn0EepromCmd); for (timer = 400; inw(ioaddr + Wn0EepromCmd) & 0x8000;) { if (--timer < 0) goto error_return; } if (debug) fprintf(stderr, "EEPROM write enable took %d ticks!\n", 400-timer); OUTW(value, ioaddr + Wn0EepromData); OUTW((EEPROM_WRITE << addrlen) + index, ioaddr + Wn0EepromCmd); for (timer = 16000; inw(ioaddr + Wn0EepromCmd) & 0x8000;) if (--timer < 0) goto error_return; if (debug) fprintf(stderr, "EEPROM wrote index %d with 0x%4.4x after %d ticks!\n", index, value, 16000-timer); return; error_return: fprintf(stderr, "Failed to write EEPROM location %d with 0x%4.4x!\n", index, value); } int main(int argc, char **argv) { unsigned int i, j, n; unsigned int ioaddr; unsigned long recvrstat; unsigned char buf[128]; unsigned char b; if (argc != 3) { printf ("Usage: romid ioaddr [erase|protect|unprotect|id|bootrom|read >file|prog