1 // SPDX-License-Identifier: MIT
8 #define BOOTLDR_SIZE 0x1000
9 #define DIAG_TOTAL_SIZE 0x4000
11 char *rombuf, *zerobuf, *devicebuf;
13 int main(int argc, char *argv[]) {
14 FILE *rom = fopen("bootrom", "rb");
16 printf("Could not open file bootrom for reading.\n");
19 FILE *out = fopen("../piscsi.rom", "wb+");
21 printf("Could not open file piscsi.rom for writing.\n");
27 device = fopen(argv[1], "rb");
30 device = fopen("pi-scsi.device", "rb");
33 printf("Could not open device file for reading.\n");
39 fseek(device, 0, SEEK_END);
40 fseek(rom, 0, SEEK_END);
41 uint32_t rom_size = ftell(rom);
42 uint32_t device_size = ftell(device);
43 fseek(rom, 0, SEEK_SET);
44 fseek(device, 0, SEEK_SET);
46 uint32_t pad_size = BOOTLDR_SIZE - rom_size;
48 rombuf = malloc(rom_size);
49 devicebuf = malloc(device_size);
50 zerobuf = malloc(pad_size);
51 memset(zerobuf, 0x00, pad_size);
53 fread(rombuf, rom_size, 1, rom);
54 fread(devicebuf, device_size, 1, device);
56 fwrite(rombuf, rom_size, 1, out);
57 fwrite(zerobuf, pad_size, 1, out);
58 fwrite(devicebuf, device_size, 1, out);
61 zerobuf = malloc(DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size));
62 memset(zerobuf, 0x00, DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size));
63 fwrite(zerobuf, DIAG_TOTAL_SIZE - (rom_size + pad_size + device_size), 1, out);
65 printf("piscsi.rom successfully created.\n");