makerom.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/************************************************************************
Calculate ROM size for 3rd byte and ROM checksum for 6th byte in ROM image.
-3 option makes the last two bytes of an 8k ROM 0x80. The 3c503 ASIC will
report this value regardless of the ROM contents, so we need to make
the checksum work properly. A 3Com EtherStart ROM I have handy sets
these to 0x80, so we'll use that for now. 0x04 has also been reported.
Any more offers?
Added capability to handle PCI and PnP headers. Detection is automatic.
************************************************************************/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#endif
#if defined(__TURBOC__) || defined(__BORLANDC__)
typedef long off_t;
#endif
/* should be powers of 2 and MAX a multiple of MIN */
#define MINROMSIZE 8192L
#define MAXROMSIZE 262144L
#define MAGIC_3C503 0x80
#define PCI_HDR_SIZE 0x18
#define PNP_HDR_SIZE 0x20
#define UNDI_HDR_SIZE 0x16
unsigned char *rom;
long romsize = 0L; /* for autosizing */
char *identstring = 0;
int verbose = 0;
int pci_vendor_id = 0, pci_device_id = 0;
int ispxe = 0;
/* read the first three bytes to get the ROM size */
{
unsigned char buffer[3];
long size, i;
exit(1);
}
/* reset pointer to beginning of file */
perror("fseek");
exit(1);
}
/* warn if preamble is not 0x55 0xAA */
/* sizes are usually powers of two, warn if not */
;
size);
return (size);
}
static unsigned int addident(void)
{
/* include the terminating NUL byte too */
/* Put the identifier in only if the space is blank */
}
return (0); /* otherwise return 0 */
}
/* Accepts a spec of the form vendorid,deviceid where the ids are
numeric strings accepted by strtoul */
{
unsigned long value;
char *endptr;
if (device != 0)
*device++ = '\0';
if (device == 0)
return;
}
static void pcipnpheaders(unsigned int identoffset)
{
int pnp_hdr_offset, pci_hdr_offset;
int i;
unsigned int sum;
/* sanity checks */
pci_hdr_offset = pnp_hdr_offset = 0;
pci_hdr_offset = pnp_hdr_offset = 0;
else
printf("PCI header at 0x%x and PnP header at 0x%x\n",
if (pci_hdr_offset)
{
/* we only fill in the low byte, this limits us to ROMs of
255 * 512 bytes = 127.5kB or so */
if (pci_vendor_id != 0)
{
}
if (pci_device_id != 0)
{
}
}
if (pnp_hdr_offset)
{
/* Point to device id string at end of ROM image */
}
}
static void undiheaders(void)
{
int undi_hdr_offset;
int i;
unsigned int sum;
/* sanity checks */
undi_hdr_offset = 0;
else
if (undi_hdr_offset) {
}
}
static void checksum(void)
{
int i;
unsigned int sum;
/* double check */
if (sum & 0xFF)
printf("Checksum fails.\n");
else if (verbose)
printf("Checksum ok\n");
}
{
int i;
long fs;
unsigned int identoffset;
char *progname;
int is3c503;
extern int optind;
extern char *optarg;
is3c503 = 0;
switch (i) {
case '3':
is3c503 = 1;
break;
case 'x':
ispxe = 1;
break;
case 'i':
break;
case 'p':
break;
case 's':
if (romsize <= 0)
romsize = 32768L;
break;
case 'v':
++verbose;
break;
}
}
if (argc < 1) {
#if defined(__TURBOC__) || defined(__BORLANDC__)
fprintf(stderr, "Usage: %s [/s romsize] [/i ident] [/p vendorid,deviceid] [/3] rom-file\n", progname);
#else
fprintf(stderr, "Usage: %s [-s romsize] [-i ident] [-p vendorid,deviceid] [-3] rom-file\n", progname);
#endif
exit(1);
}
exit(1);
}
/* If size not specified, infer it from 3rd byte */
/* If that is 0, choose the right size */
if (romsize == 0)
exit(1);
}
/* fill with FFs, slightly less work for PROM burner
and allows limited patching */
perror("fread");
exit(1);
}
if (verbose)
if (ispxe) {
goto writerom ;
}
exit(1);
}
/* shrink it down to the smallest size that will do */
romsize /= 2L;
rom[5] = 0;
if (verbose)
if (identstring != 0)
identoffset = addident();
else
identoffset = 0;
undiheaders();
/* 3c503 requires last two bytes to be MAGIC_3C503 */
}
checksum();
perror("fseek");
exit(1);
}
exit(1);
}
exit(0);
}
/*
* Local variables:
* c-basic-offset: 8
* End:
*/