1 /* This little program is my try to provide information about the
2 EtherBoot rom via environment variables to a batch file. This
3 could be done better, I think, but it works...
4 The program compiles with Borland C 3.1; other versions not tested.
5 The C code for setting the environment variables I got from an
6 archive, it was written by Richard Marks <rmarks@KSP.unisys.COM>.
7 ROMID is written by Guenter Knauf <eflash@gmx.net>
10 #define VDATE "2003-08-24"
17 #define ROMSTART 0xC8000
18 #define ROMEND 0xE8000
19 #define ROMINCREMENT 0x00800
20 #define ROMMASK 0x03FFF
24 int settheenv(char *symbol
, char *val
);
26 static int rom_scan(const unsigned char huge
*rom
,long offset
,long len
) {
33 if (rom
[offset
] != 0x55 || rom
[offset
+1] != 0xAA)
36 size
= (long)rom
[offset
+2]*512L;
38 printf("Found ROM header at %04lX:0000; announces %ldk image\n", offset
/16,(size
+512)/1024);
40 printf(" This is a unusual position; not all BIOSs might find it.\n"
41 " Try to move to a 16kB boundary.\n");
43 printf(" This image extends beyond %04X:0000. It clashes with the system BIOS\n", ROMEND
/16);
48 for (i
=0; i
<64; i
++) {
49 if (rom
[offset
+size
-3-i
] == 0xff)
55 val
[j
] = rom
[offset
+size
-3-i
+j
];
60 if (strstr(val
, "therboot") == NULL
)
64 printf("ROM Signature '%s'\n", val
);
65 if ((rptr
= strstr(val
, "rom")) != NULL
) {
72 while (!(rptr
[0] == 0x20 || rptr
< val
)) {
78 strncpy(romid
, rptr
, i
);
81 printf("ROM Driver ID '%s'\n", romid
);
82 strcpy(symbol
, "ROMID");
83 if (settheenv(symbol
, romid
))
84 printf("Error setting evironment var %s with value %s\n", symbol
, romid
);
87 printf("Couldnt find driver name!\n");
90 if (rom
[offset
+0x1C] == 'P' && rom
[offset
+0x1D] == 'C' && rom
[offset
+0x1E] == 'I') {
91 sprintf(val
, "%02X%02X:%02X%02X", rom
[offset
+0x21], rom
[offset
+0x20],
92 rom
[offset
+0x23], rom
[offset
+0x22]);
94 printf("ROM Vendor ID '%s'\n", val
);
95 strcpy(symbol
, "PCIID");
96 if (settheenv(symbol
, val
))
97 printf("Error setting evironment var %s with value %s\n", symbol
, val
);
102 /* **************** main stuff **************** */
103 int main (int argc
, char *argv
[]) {
106 printf("\nROM-ID for Etherboot v%s (c) G. Knauf %s\n", VERSION
, VDATE
);
108 /* parse input parameters */
109 for (argc
--, argv
++; *argv
; argc
--, argv
++) {
110 if ((strnicmp (*argv
, "-", 1) == 0) || (strnicmp (*argv
, "/", 1) == 0)) {
111 if ((strnicmp (*argv
, "-V", 2) == 0) || (strnicmp (*argv
, "/V", 2) == 0)) {
114 printf("Usage: %s [-v]\n");
119 for (i
= ROMEND
; (i
-= ROMINCREMENT
) >= ROMSTART
;)
120 if (rom_scan(0,i
,ROMEND
-i
))