diff options
-rw-r--r-- | src/satmkboot.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/satmkboot.c b/src/satmkboot.c index 71232dc..6abae51 100644 --- a/src/satmkboot.c +++ b/src/satmkboot.c @@ -76,6 +76,26 @@ static int write_output(FILE *fp) return ferror(fp) ? -1 : 0; } +static size_t default_ip(char *out) +{ + size_t size = 0; + + out[size++] = 0xd0; /* mov.l addr, r0 */ + out[size++] = 0x01; + out[size++] = 0x40; /* jmp @r0 */ + out[size++] = 0x2b; + out[size++] = 0x00; /* nop */ + out[size++] = 0x09; + out[size++] = 0x00; /* nop */ + out[size++] = 0x09; + out[size++] = sysid.load_addr >> 24 & 0xff; /* addr: .long <sysid.load_addr> */ + out[size++] = sysid.load_addr >> 16 & 0xff; + out[size++] = sysid.load_addr >> 8 & 0xff; + out[size++] = sysid.load_addr >> 0 & 0xff; + + return size; +} + static size_t load_ip(char *filename, char *out, size_t maxsize) { FILE *fp; @@ -131,10 +151,10 @@ static void usage(const char *progname) const int width = 20; fprintf(stderr, "usage: %s -h\n", progname); - fprintf(stderr, " %s -io[prms]\n\n", progname); + fprintf(stderr, " %s -o[iprms]\n\n", progname); fprintf(stderr, "\t%-*s%s\n", width, "-h", "Show this help text"); - fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file"); fprintf(stderr, "\t%-*s%s\n", width, "-o output", "Output file"); + fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file"); fprintf(stderr, "\t%-*s%s\n", width, "-p peripherals", "Supported peripherals (default: control pad):"); print_symbols(stderr, width, peripheraldefs); fprintf(stderr, "\t%-*s%s\n", width, "-r regions", "Geographical regions (default: all):"); @@ -260,7 +280,7 @@ static int process_args(int argc, char **argv) } else if (!fail) { if (argv[optind]) errors = show_arg_error(argv[0], errors, ERR_UNKNOWN_OPTION); - if (!ipfile || !outfile) + if (!outfile) errors = show_arg_error(argv[0], errors, ERR_MISSING_OPTION); fail = errors; } @@ -290,9 +310,10 @@ int main(int argc, char **argv) if (region) ipout = serialize_region_code(ipout, region); } - if ((ipsize = load_ip(ipfile, ipout, sizeof ipbuf - (ipout - ipbuf))) == -1) { - goto fail; - } + ipsize = ipfile + ? load_ip(ipfile, ipout, sizeof ipbuf - (ipout - ipbuf)) + : default_ip(ipout); + if (ipsize == -1) goto fail; sysid.bootsize += ipsize; if (!(outfp = fopen(outfile, "wb"))) { |