2 * readutil.c - perform various control ops on the 3c509b bios rom
7 # error "This program can't compile or run on non-intel computers"
17 #include <machine/cpufunc.h>
19 #define OUTB(data, port) outb(port, data)
20 #define OUTW(data, port) outw(port, data)
21 #define OUTL(data, port) outl(port, data)
27 #define OUTB(data, port) outb(data, port)
28 #define OUTW(data, port) outw(data, port)
29 #define OUTL(data, port) outl(data, port)
33 int main(int argc
, char **argv
)
37 unsigned long recvrstat
;
38 unsigned char buf
[128];
42 printf("Usage: romid ioaddr [erase|protect|unprotect|id|read >file|prog <file]\n");
47 /* get permissions for in/out{blw} */
48 open("/dev/io",O_RDONLY
,0);
50 setuid(0); /* if we're setuid, do it really */
57 sscanf(argv
[1],"%x",&ioaddr
);
58 /* Set the register window to 3 for the 3c905b */
59 OUTW(0x803, ioaddr
+0xe);
60 recvrstat
= inl(ioaddr
); /* save the receiver status */
61 /* set the receiver type to MII so the full bios rom address space
63 OUTL((recvrstat
& 0xf00fffff)|0x00600000, ioaddr
);
65 /* Set the register window to 0 for the 3c905b */
66 OUTW(0x800, ioaddr
+0xe);
68 if (strcmp(argv
[2], "erase") == 0) {
69 /* do the funky chicken to erase the rom contents */
70 OUTL(0x5555, ioaddr
+0x4);
71 OUTB(0xaa, ioaddr
+0x8);
72 OUTL(0x2aaa, ioaddr
+0x4);
73 OUTB(0x55, ioaddr
+0x8);
74 OUTL(0x5555, ioaddr
+0x4);
75 OUTB(0x80, ioaddr
+0x8);
76 OUTL(0x5555, ioaddr
+0x4);
77 OUTB(0xaa, ioaddr
+0x8);
78 OUTL(0x2aaa, ioaddr
+0x4);
79 OUTB(0x55, ioaddr
+0x8);
80 OUTL(0x5555, ioaddr
+0x4);
81 OUTB(0x10, ioaddr
+0x8);
82 printf("Bios ROM at %04x has been erased\n", ioaddr
);
83 } else if (strcmp(argv
[2], "protect") == 0) {
84 OUTL(0x5555, ioaddr
+0x4);
85 OUTB(0xaa, ioaddr
+0x8);
86 OUTL(0x2aaa, ioaddr
+0x4);
87 OUTB(0x55, ioaddr
+0x8);
88 OUTL(0x5555, ioaddr
+0x4);
89 OUTB(0xa0, ioaddr
+0x8);
90 printf("Software Data Protection for Bios ROM at %04x has been enabled\n",
92 } else if (strcmp(argv
[2], "unprotect") == 0) {
93 OUTL(0x5555, ioaddr
+0x4);
94 OUTB(0xaa, ioaddr
+0x8);
95 OUTL(0x2aaa, ioaddr
+0x4);
96 OUTB(0x55, ioaddr
+0x8);
97 OUTL(0x5555, ioaddr
+0x4);
98 OUTB(0x80, ioaddr
+0x8);
99 OUTL(0x5555, ioaddr
+0x4);
100 OUTB(0xaa, ioaddr
+0x8);
101 OUTL(0x2aaa, ioaddr
+0x4);
102 OUTB(0x55, ioaddr
+0x8);
103 OUTL(0x5555, ioaddr
+0x4);
104 OUTB(0x20, ioaddr
+0x8);
105 printf("Software Data Protection for Bios ROM at %04x has been disabled\n",
107 } else if (strcmp(argv
[2], "id") == 0) {
108 OUTL(0x5555, ioaddr
+0x4);
109 OUTB(0xaa, ioaddr
+0x8);
110 OUTL(0x2aaa, ioaddr
+0x4);
111 OUTB(0x55, ioaddr
+0x8);
112 OUTL(0x5555, ioaddr
+0x4);
113 OUTB(0x90, ioaddr
+0x8);
114 /* 10ms delay needed */
115 printf("Manufacturer ID - ");
117 OUTL(0x0000, ioaddr
+0x4);
118 printf("%02x\n", inb(ioaddr
+0x8));
120 OUTL(0x0001, ioaddr
+0x4);
121 printf("Device ID - %02x\n", inb(ioaddr
+0x8));
122 /* undo the funky chicken */
123 OUTL(0x5555, ioaddr
+0x4);
124 OUTB(0xaa, ioaddr
+0x8);
125 OUTL(0x2aaa, ioaddr
+0x4);
126 OUTB(0x55, ioaddr
+0x8);
127 OUTL(0x5555, ioaddr
+0x4);
128 OUTB(0xf0, ioaddr
+0x8);
129 } else if (strcmp(argv
[2], "read") == 0) {
130 for (i
= 0; i
< 65536; i
++) {
135 } else if (strcmp(argv
[2], "prog") == 0) {
136 /* program the rom in 128 bute chunks */
137 for (i
= 0, n
= 0; i
< 65536; i
+= n
) {
138 n
= read(0, buf
, 128);
142 perror("File Error");
145 /* disable SDP temporarily for programming a sector */
146 OUTL(0x5555, ioaddr
+0x4);
147 OUTB(0xaa, ioaddr
+0x8);
148 OUTL(0x2aaa, ioaddr
+0x4);
149 OUTB(0x55, ioaddr
+0x8);
150 OUTL(0x5555, ioaddr
+0x4);
151 OUTB(0xa0, ioaddr
+0x8);
152 for (j
= 0; j
< n
; j
++) {
153 OUTL(i
+j
, ioaddr
+0x4);
154 OUTB(buf
[j
], ioaddr
+0x8);
156 /* wait for the programming of this sector to coomplete */
157 while (inb(ioaddr
+0x8) != buf
[j
-1])
162 /* Set the register window to 3 for the 3c905b */
163 OUTW(0x803, ioaddr
+0xe);
164 /* restore the receiver status */
165 OUTL(recvrstat
, ioaddr
);
169 #endif /* __i386__ */