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, 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",
61 (int)inbuf.st_size, size);
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 fprintf(stderr, "ERROR: payload (%d) + linuxbios (%d) - Size is %d bytes larger than ROM size (%d).\n",
69 payloadbuf.st_size, size,
70 payloadbuf.st_size+size-romsize,
75 printf("Payload: %d LinuxBIOS: %d ROM size: %d Left space: %d\n",
76 payloadbuf.st_size, size, romsize,
77 romsize-payloadbuf.st_size-size);
81 fatal("malloc buffer");
82 for (i = 0; i < romsize; i++) {
86 /* read the input file in at the END of the array */
87 readlen = read(infd, &cp[romsize - inbuf.st_size], inbuf.st_size);
88 if (readlen < inbuf.st_size) {
89 fprintf(stderr, "Wanted %d, got %d\n", (int)inbuf.st_size, readlen);
90 fatal("Read input file");
93 /* read the payload file in at the START of the array */
94 readlen = read(payloadfd, cp, payloadbuf.st_size);
95 if (readlen < payloadbuf.st_size) {
96 fprintf(stderr, "Wanted %d, got %d\n",
97 (int)payloadbuf.st_size, readlen);
98 fatal("Read payload file");
100 writelen = write(outfd, cp, romsize);
101 if (writelen < size) {
102 fprintf(stderr, "Wanted %d, got %d\n", size, writelen);
103 fatal("Write output file");