9 /* this is the beginning of a tool which will eventually
10 * be able to build rom images with both fallback and
11 * normal. For now it just builds a single image
14 /* one switch we already need: -zero allowing you to tell what
15 * to do with numbers that are "zero": make them 0xff or whatever
17 * For now we assume "zero" is 0xff
22 fprintf(stderr, "Usage: buildrom <input> <output> <payload> ");
23 fprintf(stderr, " <linuxbios-size> <total-size>\n");
33 int main(int argc, char *argv[])
35 int infd, payloadfd, outfd, size, insize, readlen, writelen, i;
38 struct stat inbuf, payloadbuf;
44 infd = open(argv[1], O_RDONLY);
47 outfd = open(argv[2], O_RDWR | O_CREAT, 0666);
50 payloadfd = open(argv[3], O_RDONLY);
54 size = strtol(argv[4], 0, 0);
55 romsize = strtol(argv[5], 0, 0);
57 if (fstat(infd, &inbuf) < 0)
58 fatal("stat of infile");
59 if (inbuf.st_size > size) {
60 fprintf(stderr, "linuxbios image is %d bytes; only %d allowed\n",
62 fatal("Linuxbios input file larger than allowed size!\n");
65 if (fstat(payloadfd, &payloadbuf) < 0)
66 fatal("stat of infile");
67 if (payloadbuf.st_size > (romsize - size))
68 fatal("payload + linuxbios size larger than ROM size!\n");
72 fatal("malloc buffer");
73 for (i = 0; i < romsize; i++) {
77 /* read the input file in at the END of the array */
78 readlen = read(infd, &cp[romsize - inbuf.st_size], inbuf.st_size);
79 if (readlen < inbuf.st_size) {
80 fprintf(stderr, "Wanted %d, got %d\n", inbuf.st_size, readlen);
81 fatal("Read input file");
84 /* read the payload file in at the START of the array */
85 readlen = read(payloadfd, cp, payloadbuf.st_size);
86 if (readlen < payloadbuf.st_size) {
87 fprintf(stderr, "Wanted %d, got %d\n",
88 payloadbuf.st_size, readlen);
89 fatal("Read payload file");
91 writelen = write(outfd, cp, romsize);
92 if (writelen < size) {
93 fprintf(stderr, "Wanted %d, got %d\n", size, writelen);
94 fatal("Write output file");