/* * Cut (appart the) Z(aurus) ROM (Image) * * cutzrom.c - Version 1.0 - March 16, 2002 * Mark T. Grennan - mark@grennan.com * * This file expects the input file ROMIMAGE */ /* * The SL-5000 can be updated either with a single "romimage" file * or with individual files for the kernel, root filesystem and bootflag * file (which specifies the initial filesystem). * * The romimage is exactly that - it is a 16M file which is loaded * more-or-less directly into the FLASH ROM. The layout is as follows * * offset length Name Contents * dec hex * 0 0 49688 BOOTSHP2.BIN Boot loader * 131072 020000 31740 CF.BIN Flash update utility? * 262144 040000 513960 COLLIE.BIN Hardware test utility? * 786432 0C0000 varies ZIMAGE kernel * 1835008 1C0000 varies ROMDISK.BIN Cramfs root filesystem image * 16695296 FEC000 4 BOOTFLAG.TXT Specifies the initial run level. * 16728064 FF4000 24 Text "SHARPSL-series" * 16744448 FF8000 224 Directory block * * The directory block seems to be structured as follows * * 8 bytes filename * 3 bytes extension * 1 byte ? always 00 * 2 byte ? varies * 2 bytes ? always 0xff * 8 bytes date in ASCII yyyymmdd * 4 bytes start offset in image * 4 bytes end offset in image + 1 * * The actual directory in the 1.02 ROM image is as follows * * 00ff8000: 424f 4f54 5348 5032 4249 4e00 a6d8 ffff BOOTSHP2BIN..... * 00ff8010: 3230 3031 3130 3133 0000 0000 0000 0200 20011013........ * 00ff8020: 4346 2020 2020 2020 4249 4e00 1ce4 ffff CF BIN..... * 00ff8030: 3230 3031 3130 3232 0000 0200 0000 0400 20011022........ * 00ff8040: 434f 4c4c 4945 2020 4249 4e00 ea6c ffff COLLIE BIN..l.. * 00ff8050: 3230 3031 3130 3133 0000 0400 0000 0c00 20011013........ * 00ff8060: 5a49 4d41 4745 2020 2020 2000 c45c ffff ZIMAGE ..\.. * 00ff8070: 3230 3031 3131 3038 0000 0c00 0000 1a00 20011108........ * 00ff8080: 524f 4d44 4953 4b20 4249 4e00 d66c ffff ROMDISK BIN..l.. * 00ff8090: 3230 3031 3131 3232 0000 1c00 0000 cc00 20011122........ * 00ff80a0: 454e 4420 2020 2020 2020 2000 0000 ffff END ..... * 00ff80b0: 3139 3830 3030 3030 0000 0000 0000 0000 19800000........ * 00ff80c0: 454c 4154 4520 2020 4249 4e00 0000 ffff ELATE BIN..... * 00ff80d0: 3139 3830 3033 3034 0000 0000 0100 0000 19800304........ * * There are two "files" in the directory block which don't appear * to be in the image which are "END" and "ELATE.BIN" and the bootflags.txt * file isn't in the directory, neither is there anything corresponding * to the text at offset 0xFF4000. * * If a given file is smaller than the space allocated for it then the * image is padded with 0xFF bytes. The two files that vary the most in * size are the kernel and the root filesystem image. * * One problem with this layout is that half a megabyte is "wasted" by * the "collie.bin" file. There is no documentation on this but looking * at the embedded strings suggests that it is some sort of hardware * diagnostics utility. Unfortunately although the directory contains * start/end offsets for the files I doubt that they are actually movable. * One boundary which is definately fixed is the start of the root * filesystem image at 0x1C0000 since the kernel device driver has this * address hard-wired in. * * Another thing which is apparent is that it should be much safer * to upgrade by copying zImage, initrd.bin and bootflag.txt as separate * files to the CF card. Assuming that the flash utility will overwrite * all of flash when upgrading from a single romimage file then it is * possible to corrupt the bootloader and/or the flash code (should, for * example, the power fail). Upgrading from separate files should not * involve overwriting any of the critical images so even if the Zarus * won't boot after an upgrade it should always be possible to try again. * */ #include int main() { FILE *fp1; FILE *fp2; long x; char d; /* Write BOOTSHP2.BIN - Boot loader */ printf("\nCreating BOOTSHP2.BIN\n"); fp1 = fopen("ROMIMAGE", "r"); fp2 = fopen("BOOTSHP2.BIN", "w"); for(x=0; x<49688; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write CF.BIN - Flash update utility */ printf("Creating CF.BIN\n"); fp2 = fopen("CF.BIN", "w"); fseek( fp1, 0x020000, SEEK_SET); for(x=0; x<31740; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write COLLIE.BIN - Hardware test utility */ printf("Creating COLLIE.BIN\n"); fp2 = fopen("COLLIE.BIN", "w"); fseek( fp1, 0x040000, SEEK_SET); for(x=0; x<513960; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write ZIMAGE - kernel */ printf("Creating zImage\n"); fp2 = fopen("zImage", "w"); fseek( fp1, 0x0c0000, SEEK_SET); for(x=0; x<=0x0100000; x++) /* lenth varies */ { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write ROMDISK.BIN Cramfs root filesystem image */ printf("Creating ROMDISK.BIN\n"); fp2 = fopen("ROMDISK.BIN", "w"); fseek( fp1, 0x01c0000, SEEK_SET); for(x=0; x<=0x0e2c000; x++) /* lenth varies */ { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write BOOTFLAG.TXT Specifies the initial run level */ printf("Creating BOOTFLAG.TXT\n"); fp2 = fopen("BOOTFLAG.TXT", "w"); fseek( fp1, 0x0fec000, SEEK_SET); for(x=0; x<=4; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write FILETYPE Specifies the initial run level */ printf("Creating FILETYPE\n"); fp2 = fopen("FILETYPE.TXT", "w"); fseek( fp1, 0x0ff4000, SEEK_SET); for(x=0; x<=24; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); /* Write DIRECTORY Specifies the initial run level */ printf("Creating DIRECTORY.BIN\n"); fp2 = fopen("DIRECTORY.BIN", "w"); fseek( fp1, 0x0ff8000, SEEK_SET); for(x=0; x<=244; x++) { fread(&d, 1, 1, fp1); fwrite(&d, 1,1, fp2); } fclose(fp2); fclose(fp1); exit(1); }