6 #define BOOTLDR_SIZE 0x400
7 #define DIAG_TOTAL_SIZE 0x4000
9 char *rombuf, *zerobuf, *devicebuf;
11 int main(int argc, char *argv[]) {
12 FILE *rom = fopen("bootrom", "rb");
14 printf("Could not open file bootrom for reading.\n");
17 FILE *out = fopen("../piscsi.rom", "wb+");
19 printf("Could not open file piscsi.rom for writing.\n");
25 device = fopen(argv[1], "rb");
28 device = fopen("pi-scsi.device", "rb");
31 printf("Could not open device file for reading.\n");
37 fseek(device, 0, SEEK_END);
38 fseek(rom, 0, SEEK_END);
39 uint32_t rom_size = ftell(rom);
40 uint32_t device_size = ftell(device);
41 fseek(rom, 0, SEEK_SET);
42 fseek(device, 0, SEEK_SET);
44 uint32_t pad_size = BOOTLDR_SIZE - rom_size;
46 rombuf = malloc(rom_size);
47 devicebuf = malloc(device_size);
48 zerobuf = malloc(pad_size);
49 memset(zerobuf, 0x00, pad_size);
51 fread(rombuf, rom_size, 1, rom);
52 fread(devicebuf, device_size, 1, device);
54 fwrite(rombuf, rom_size, 1, out);
55 fwrite(zerobuf, pad_size, 1, out);
56 fwrite(devicebuf, device_size, 1, out);
59 zerobuf = malloc(DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size));
60 memset(zerobuf, 0x00, DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size));
61 fwrite(zerobuf, DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size), 1, out);
63 printf("piscsi.rom successfully created.\n");