diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2015-09-14 21:05:25 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2015-09-15 22:43:33 -0500 |
commit | ba2468c582934a97445f78bbbbb652386c642439 (patch) | |
tree | bec8f7e9d2b582d6905be840efc00d2ddf68ec38 | |
parent | d30a6525d237105ff77e0728fd7378cc674701a3 (diff) |
search for bootloader inputs in installed share dir
We remove the hard-coded default bootloader as part of this, and instead
hard-code the name of an installed default bootloader input.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/saturn-mkboot.c | 42 |
2 files changed, 23 insertions, 24 deletions
@@ -50,6 +50,11 @@ share/boot/%: boot/%.elf %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ +src/saturn-mkboot.o: src/paths.h + +src/paths.h: config.mak + echo "#define DATA_PATH \"$(sharedir)\"" > $@ + $(DESTDIR)$(bindir)/%: bin/% $(INSTALL) -D $< $@ diff --git a/src/saturn-mkboot.c b/src/saturn-mkboot.c index 63e7bb6..43e1a85 100644 --- a/src/saturn-mkboot.c +++ b/src/saturn-mkboot.c @@ -6,6 +6,7 @@ #include <string.h> #include "bootinfo.h" +#include "paths.h" #include "symbols.h" static struct systemid sysid = { @@ -66,35 +67,30 @@ static int write_output(FILE *fp) return ferror(fp) ? -1 : 0; } -static size_t default_ip(char *out) +static FILE *open_installed_boot_file(const char *filename) { - 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; + static const char *bootpath = DATA_PATH "/boot"; + char *path = malloc(strlen(bootpath) + strlen(filename) + 2); + if (!path) return NULL; + sprintf(path, "%s/%s", bootpath, filename); + return fopen(path, "rb"); +} - return size; +static FILE *open_boot_file(const char *filename) +{ + FILE *fp = fopen(filename, "rb"); + if (fp) return fp; + if (!strchr(filename, '/')) return open_installed_boot_file(filename); + return NULL; } -static size_t load_ip(char *filename, char *out, size_t maxsize) +static size_t load_ip(char *out, size_t maxsize) { - FILE *fp; size_t size; + FILE *fp = ipfile ? open_boot_file(ipfile) : open_installed_boot_file("simple"); const char *errprefix = "Error loading initial program"; - if (!(fp = fopen(filename, "rb"))) { - goto fail_perror; - } + if (!fp) goto fail_perror; if ((size = fread(out, 1, maxsize, fp)) < maxsize) { /* read fewer than requested amount. determine if we hit error or eof */ if (ferror(fp)) { @@ -252,9 +248,7 @@ int main(int argc, char **argv) sysid.bootsize += 32; } - ipsize = ipfile - ? load_ip(ipfile, ipout, sizeof ipbuf - (ipout - ipbuf)) - : default_ip(ipout); + ipsize = load_ip(ipout, sizeof ipbuf - (ipout - ipbuf)); if (ipsize == -1) goto fail; sysid.bootsize += ipsize; |