summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/saturn-mkboot.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/saturn-mkboot.c b/src/saturn-mkboot.c
index 43e1a85..7551059 100644
--- a/src/saturn-mkboot.c
+++ b/src/saturn-mkboot.c
@@ -27,7 +27,7 @@ static struct systemid sysid = {
.load_size = 0,
};
-static char ipbuf[0x7200];
+static char ipbuf[0x7f00];
static char *ipfile, *outfile;
static void serialize_region_code(char *out, const struct symbolname *region)
@@ -45,9 +45,6 @@ static void serialize_region_code(char *out, const struct symbolname *region)
static int write_output(FILE *fp)
{
- extern const unsigned char securitycode[];
- extern const size_t securitycode_size;
-
/* system id - 0x100 bytes */
WRITE (fp, &sysid, offsetof(struct systemid, bootsize));
WRITE32(fp, sysid.bootsize);
@@ -59,11 +56,8 @@ static int write_output(FILE *fp)
WRITE32(fp, 0); /* reserved bytes */
WRITE32(fp, 0); /* reserved bytes */
- /* security code */
- WRITE(fp, securitycode, securitycode_size);
-
/* initial program */
- WRITE(fp, ipbuf, sysid.bootsize - 0xe00);
+ WRITE(fp, ipbuf, sysid.bootsize - 0x100);
return ferror(fp) ? -1 : 0;
}
@@ -84,34 +78,43 @@ static FILE *open_boot_file(const char *filename)
return NULL;
}
+static size_t readfile(FILE *fp, char *out, size_t maxsize, const char *errprefix)
+{
+ size_t size = fread(out, 1, maxsize, fp);
+ if (size == maxsize && fgetc(fp) != EOF) {
+ fprintf(stderr, "%s: exceeds maximum size\n", errprefix);
+ size = -1;
+ }
+ return size;
+}
+
+static size_t load_security_code(char *out)
+{
+ const char *errprefix = "Error loading security code";
+ FILE *fp;
+ if (!(fp = fopen(DATA_PATH "/securitycode.bin", "rb"))) {
+ perror(errprefix);
+ return -1;
+ }
+ size_t size = readfile(fp, out, 0xd00, errprefix);
+ if (size != -1 && size != 0xd00) fprintf(stderr, "%s: wrong size\n", errprefix);
+ fclose(fp);
+ return size;
+}
+
static size_t load_ip(char *out, size_t maxsize)
{
- size_t size;
FILE *fp = ipfile ? open_boot_file(ipfile) : open_installed_boot_file("simple");
const char *errprefix = "Error loading initial program";
- 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)) {
- goto fail_perror;
- }
- } else {
- /* successfully read the requested amount. verify we reached eof */
- if (fgetc(fp) != EOF) {
- fprintf(stderr, "%s: exceeds maximum size\n", errprefix);
- goto fail;
- }
+ if (!fp) {
+ perror(errprefix);
+ return -1;
}
+ size_t size = readfile(fp, out, maxsize, errprefix);
fclose(fp);
return size;
-
-fail_perror:
- perror(errprefix);
-fail:
- if (fp) fclose(fp);
- return -1;
}
static void print_symbols(int width, const struct symbolname *symbols)
@@ -248,6 +251,9 @@ int main(int argc, char **argv)
sysid.bootsize += 32;
}
+ ipsize = load_security_code(ipout);
+ if (ipsize == -1) goto fail;
+ ipout += ipsize;
ipsize = load_ip(ipout, sizeof ipbuf - (ipout - ipbuf));
if (ipsize == -1) goto fail;
sysid.bootsize += ipsize;