summaryrefslogtreecommitdiffstats
path: root/arch/sparc/boot
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc/boot
downloadop-kernel-dev-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.zip
op-kernel-dev-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.gz
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sparc/boot')
-rw-r--r--arch/sparc/boot/Makefile58
-rw-r--r--arch/sparc/boot/btfixupprep.c386
-rw-r--r--arch/sparc/boot/piggyback.c137
3 files changed, 581 insertions, 0 deletions
diff --git a/arch/sparc/boot/Makefile b/arch/sparc/boot/Makefile
new file mode 100644
index 0000000..b365084
--- /dev/null
+++ b/arch/sparc/boot/Makefile
@@ -0,0 +1,58 @@
+# $Id: Makefile,v 1.10 2000/02/23 08:17:46 jj Exp $
+# Makefile for the Sparc boot stuff.
+#
+# Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+# Copyright (C) 1997,1998 Jakub Jelinek (jj@ultra.linux.cz)
+
+ROOT_IMG := /usr/src/root.img
+ELFTOAOUT := elftoaout
+
+hostprogs-y := piggyback btfixupprep
+targets := tftpboot.img btfix.o btfix.S image
+
+quiet_cmd_elftoaout = ELFTOAOUT $@
+ cmd_elftoaout = $(ELFTOAOUT) $(obj)/image -o $@
+quiet_cmd_piggy = PIGGY $@
+ cmd_piggy = $(obj)/piggyback $@ $(obj)/System.map $(ROOT_IMG)
+quiet_cmd_btfix = BTFIX $@
+ cmd_btfix = $(OBJDUMP) -x vmlinux | $(obj)/btfixupprep > $@
+quiet_cmd_sysmap = SYSMAP $(obj)/System.map
+ cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
+quiet_cmd_image = LD $@
+ cmd_image = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) -o $@
+
+define rule_image
+ $(if $($(quiet)cmd_image), \
+ echo ' $($(quiet)cmd_image)' &&) \
+ $(cmd_image); \
+ $(if $($(quiet)cmd_sysmap), \
+ echo ' $($(quiet)cmd_sysmap)' &&) \
+ $(cmd_sysmap) $@ $(obj)/System.map; \
+ if [ $$? -ne 0 ]; then \
+ rm -f $@; \
+ /bin/false; \
+ fi; \
+ echo 'cmd_$@ := $(cmd_image)' > $(@D)/.$(@F).cmd
+endef
+
+BTOBJS := $(HEAD_Y) $(INIT_Y)
+BTLIBS := $(CORE_Y) $(LIBS_Y) $(DRIVERS_Y) $(NET_Y)
+LDFLAGS_image := -T arch/sparc/kernel/vmlinux.lds $(BTOBJS) \
+ --start-group $(BTLIBS) --end-group \
+ $(kallsyms.o) $(obj)/btfix.o
+
+# Link the final image including btfixup'ed symbols.
+# This is a replacement for the link done in the top-level Makefile.
+# Note: No dependency on the prerequisite files since that would require
+# make to try check if they are updated - and due to changes
+# in gcc options (path for example) this would result in
+# these files being recompiled for each build.
+$(obj)/image: $(obj)/btfix.o FORCE
+ $(call if_changed_rule,image)
+
+$(obj)/tftpboot.img: $(obj)/piggyback $(obj)/System.map $(obj)/image FORCE
+ $(call if_changed,elftoaout)
+ $(call if_changed,piggy)
+
+$(obj)/btfix.S: $(obj)/btfixupprep vmlinux FORCE
+ $(call if_changed,btfix)
diff --git a/arch/sparc/boot/btfixupprep.c b/arch/sparc/boot/btfixupprep.c
new file mode 100644
index 0000000..dc7b054
--- /dev/null
+++ b/arch/sparc/boot/btfixupprep.c
@@ -0,0 +1,386 @@
+/* $Id: btfixupprep.c,v 1.6 2001/08/22 15:27:47 davem Exp $
+ Simple utility to prepare vmlinux image for sparc.
+ Resolves all BTFIXUP uses and settings and creates
+ a special .s object to link to the image.
+
+ Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+#define MAXSYMS 1024
+
+static char *symtab = "SYMBOL TABLE:";
+static char *relrec = "RELOCATION RECORDS FOR [";
+static int rellen;
+static int symlen;
+int mode;
+
+struct _btfixup;
+
+typedef struct _btfixuprel {
+ char *sect;
+ unsigned long offset;
+ struct _btfixup *f;
+ int frel;
+ struct _btfixuprel *next;
+} btfixuprel;
+
+typedef struct _btfixup {
+ int type;
+ int setinitval;
+ unsigned int initval;
+ char *initvalstr;
+ char *name;
+ btfixuprel *rel;
+} btfixup;
+
+btfixup array[MAXSYMS];
+int last = 0;
+char buffer[1024];
+unsigned long lastfoffset = -1;
+unsigned long lastfrelno;
+btfixup *lastf;
+
+void fatal(void) __attribute__((noreturn));
+void fatal(void)
+{
+ fprintf(stderr, "Malformed output from objdump\n%s\n", buffer);
+ exit(1);
+}
+
+btfixup *find(int type, char *name)
+{
+ int i;
+ for (i = 0; i < last; i++) {
+ if (array[i].type == type && !strcmp(array[i].name, name))
+ return array + i;
+ }
+ array[last].type = type;
+ array[last].name = strdup(name);
+ array[last].setinitval = 0;
+ if (!array[last].name) fatal();
+ array[last].rel = NULL;
+ last++;
+ if (last >= MAXSYMS) {
+ fprintf(stderr, "Ugh. Something strange. More than %d different BTFIXUP symbols\n", MAXSYMS);
+ exit(1);
+ }
+ return array + last - 1;
+}
+
+void set_mode (char *buffer)
+{
+ for (mode = 0;; mode++)
+ if (buffer[mode] < '0' || buffer[mode] > '9')
+ break;
+ if (mode != 8 && mode != 16)
+ fatal();
+}
+
+
+int main(int argc,char **argv)
+{
+ char *p, *q;
+ char *sect;
+ int i, j, k;
+ unsigned int initval;
+ int shift;
+ btfixup *f;
+ btfixuprel *r, **rr;
+ unsigned long offset;
+ char *initvalstr;
+
+ symlen = strlen(symtab);
+ while (fgets (buffer, 1024, stdin) != NULL)
+ if (!strncmp (buffer, symtab, symlen))
+ goto main0;
+ fatal();
+main0:
+ rellen = strlen(relrec);
+ while (fgets (buffer, 1024, stdin) != NULL)
+ if (!strncmp (buffer, relrec, rellen))
+ goto main1;
+ fatal();
+main1:
+ sect = malloc(strlen (buffer + rellen) + 1);
+ if (!sect) fatal();
+ strcpy (sect, buffer + rellen);
+ p = strchr (sect, ']');
+ if (!p) fatal();
+ *p = 0;
+ if (fgets (buffer, 1024, stdin) == NULL)
+ fatal();
+ while (fgets (buffer, 1024, stdin) != NULL) {
+ int nbase;
+ if (!strncmp (buffer, relrec, rellen))
+ goto main1;
+ if (mode == 0)
+ set_mode (buffer);
+ p = strchr (buffer, '\n');
+ if (p) *p = 0;
+ if (strlen (buffer) < 22+mode)
+ continue;
+ if (strncmp (buffer + mode, " R_SPARC_", 9))
+ continue;
+ nbase = 27 - 8 + mode;
+ if (buffer[nbase] != '_' || buffer[nbase+1] != '_' || buffer[nbase+2] != '_')
+ continue;
+ switch (buffer[nbase+3]) {
+ case 'f': /* CALL */
+ case 'b': /* BLACKBOX */
+ case 's': /* SIMM13 */
+ case 'a': /* HALF */
+ case 'h': /* SETHI */
+ case 'i': /* INT */
+ break;
+ default:
+ continue;
+ }
+ p = strchr (buffer + nbase+5, '+');
+ if (p) *p = 0;
+ shift = nbase + 5;
+ if (buffer[nbase+4] == 's' && buffer[nbase+5] == '_') {
+ shift = nbase + 6;
+ if (strcmp (sect, ".init.text")) {
+ fprintf(stderr,
+ "Wrong use of '%s' BTFIXUPSET in '%s' section.\n"
+ "BTFIXUPSET_CALL can be used only in"
+ " __init sections\n",
+ buffer + shift, sect);
+ exit(1);
+ }
+ } else if (buffer[nbase+4] != '_')
+ continue;
+ if (!strcmp (sect, ".text.exit"))
+ continue;
+ if (strcmp (sect, ".text") &&
+ strcmp (sect, ".init.text") &&
+ strcmp (sect, ".fixup") &&
+ (strcmp (sect, "__ksymtab") || buffer[nbase+3] != 'f')) {
+ if (buffer[nbase+3] == 'f')
+ fprintf(stderr,
+ "Wrong use of '%s' in '%s' section.\n"
+ " It can be used only in .text, .init.text,"
+ " .fixup and __ksymtab\n",
+ buffer + shift, sect);
+ else
+ fprintf(stderr,
+ "Wrong use of '%s' in '%s' section.\n"
+ " It can be only used in .text, .init.text,"
+ " and .fixup\n", buffer + shift, sect);
+ exit(1);
+ }
+ p = strstr (buffer + shift, "__btset_");
+ if (p && buffer[nbase+4] == 's') {
+ fprintf(stderr, "__btset_ in BTFIXUP name can only be used when defining the variable, not for setting\n%s\n", buffer);
+ exit(1);
+ }
+ initval = 0;
+ initvalstr = NULL;
+ if (p) {
+ if (p[8] != '0' || p[9] != 'x') {
+ fprintf(stderr, "Pre-initialized values can be only initialized with hexadecimal constants starting 0x\n%s\n", buffer);
+ exit(1);
+ }
+ initval = strtoul(p + 10, &q, 16);
+ if (*q || !initval) {
+ fprintf(stderr, "Pre-initialized values can be only in the form name__btset_0xXXXXXXXX where X are hex digits.\nThey cannot be name__btset_0x00000000 though. Use BTFIXUPDEF_XX instead of BTFIXUPDEF_XX_INIT then.\n%s\n", buffer);
+ exit(1);
+ }
+ initvalstr = p + 10;
+ *p = 0;
+ }
+ f = find(buffer[nbase+3], buffer + shift);
+ if (buffer[nbase+4] == 's')
+ continue;
+ switch (buffer[nbase+3]) {
+ case 'f':
+ if (initval) {
+ fprintf(stderr, "Cannot use pre-initalized fixups for calls\n%s\n", buffer);
+ exit(1);
+ }
+ if (!strcmp (sect, "__ksymtab")) {
+ if (strncmp (buffer + mode+9, "32 ", 10)) {
+ fprintf(stderr, "BTFIXUP_CALL in EXPORT_SYMBOL results in relocation other than R_SPARC_32\n\%s\n", buffer);
+ exit(1);
+ }
+ } else if (strncmp (buffer + mode+9, "WDISP30 ", 10) &&
+ strncmp (buffer + mode+9, "HI22 ", 10) &&
+ strncmp (buffer + mode+9, "LO10 ", 10)) {
+ fprintf(stderr, "BTFIXUP_CALL results in relocation other than R_SPARC_WDISP30, R_SPARC_HI22 or R_SPARC_LO10\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ case 'b':
+ if (initval) {
+ fprintf(stderr, "Cannot use pre-initialized fixups for blackboxes\n%s\n", buffer);
+ exit(1);
+ }
+ if (strncmp (buffer + mode+9, "HI22 ", 10)) {
+ fprintf(stderr, "BTFIXUP_BLACKBOX results in relocation other than R_SPARC_HI22\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ case 's':
+ if (initval + 0x1000 >= 0x2000) {
+ fprintf(stderr, "Wrong initializer for SIMM13. Has to be from $fffff000 to $00000fff\n%s\n", buffer);
+ exit(1);
+ }
+ if (strncmp (buffer + mode+9, "13 ", 10)) {
+ fprintf(stderr, "BTFIXUP_SIMM13 results in relocation other than R_SPARC_13\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ case 'a':
+ if (initval + 0x1000 >= 0x2000 && (initval & 0x3ff)) {
+ fprintf(stderr, "Wrong initializer for HALF.\n%s\n", buffer);
+ exit(1);
+ }
+ if (strncmp (buffer + mode+9, "13 ", 10)) {
+ fprintf(stderr, "BTFIXUP_HALF results in relocation other than R_SPARC_13\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ case 'h':
+ if (initval & 0x3ff) {
+ fprintf(stderr, "Wrong initializer for SETHI. Cannot have set low 10 bits\n%s\n", buffer);
+ exit(1);
+ }
+ if (strncmp (buffer + mode+9, "HI22 ", 10)) {
+ fprintf(stderr, "BTFIXUP_SETHI results in relocation other than R_SPARC_HI22\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ case 'i':
+ if (initval) {
+ fprintf(stderr, "Cannot use pre-initalized fixups for INT\n%s\n", buffer);
+ exit(1);
+ }
+ if (strncmp (buffer + mode+9, "HI22 ", 10) && strncmp (buffer + mode+9, "LO10 ", 10)) {
+ fprintf(stderr, "BTFIXUP_INT results in relocation other than R_SPARC_HI22 and R_SPARC_LO10\n%s\n", buffer);
+ exit(1);
+ }
+ break;
+ }
+ if (!f->setinitval) {
+ f->initval = initval;
+ if (initvalstr) {
+ f->initvalstr = strdup(initvalstr);
+ if (!f->initvalstr) fatal();
+ }
+ f->setinitval = 1;
+ } else if (f->initval != initval) {
+ fprintf(stderr, "Btfixup %s previously used with initializer %s which doesn't match with current initializer\n%s\n",
+ f->name, f->initvalstr ? : "0x00000000", buffer);
+ exit(1);
+ } else if (initval && strcmp(f->initvalstr, initvalstr)) {
+ fprintf(stderr, "Btfixup %s previously used with initializer %s which doesn't match with current initializer.\n"
+ "Initializers have to match literally as well.\n%s\n",
+ f->name, f->initvalstr, buffer);
+ exit(1);
+ }
+ offset = strtoul(buffer, &q, 16);
+ if (q != buffer + mode || (!offset && (mode == 8 ? strncmp (buffer, "00000000 ", 9) : strncmp (buffer, "0000000000000000 ", 17)))) {
+ fprintf(stderr, "Malformed relocation address in\n%s\n", buffer);
+ exit(1);
+ }
+ for (k = 0, r = f->rel, rr = &f->rel; r; rr = &r->next, r = r->next, k++)
+ if (r->offset == offset && !strcmp(r->sect, sect)) {
+ fprintf(stderr, "Ugh. One address has two relocation records\n");
+ exit(1);
+ }
+ *rr = malloc(sizeof(btfixuprel));
+ if (!*rr) fatal();
+ (*rr)->offset = offset;
+ (*rr)->f = NULL;
+ if (buffer[nbase+3] == 'f') {
+ lastf = f;
+ lastfoffset = offset;
+ lastfrelno = k;
+ } else if (lastfoffset + 4 == offset) {
+ (*rr)->f = lastf;
+ (*rr)->frel = lastfrelno;
+ }
+ (*rr)->sect = sect;
+ (*rr)->next = NULL;
+ }
+ printf("! Generated by btfixupprep. Do not edit.\n\n");
+ printf("\t.section\t\".data.init\",#alloc,#write\n\t.align\t4\n\n");
+ printf("\t.global\t___btfixup_start\n___btfixup_start:\n\n");
+ for (i = 0; i < last; i++) {
+ f = array + i;
+ printf("\t.global\t___%cs_%s\n", f->type, f->name);
+ if (f->type == 'f')
+ printf("___%cs_%s:\n\t.word 0x%08x,0,0,", f->type, f->name, f->type << 24);
+ else
+ printf("___%cs_%s:\n\t.word 0x%08x,0,", f->type, f->name, f->type << 24);
+ for (j = 0, r = f->rel; r != NULL; j++, r = r->next);
+ if (j)
+ printf("%d\n\t.word\t", j * 2);
+ else
+ printf("0\n");
+ for (r = f->rel, j--; r != NULL; j--, r = r->next) {
+ if (!strcmp (r->sect, ".text"))
+ printf ("_stext+0x%08lx", r->offset);
+ else if (!strcmp (r->sect, ".init.text"))
+ printf ("__init_begin+0x%08lx", r->offset);
+ else if (!strcmp (r->sect, "__ksymtab"))
+ printf ("__start___ksymtab+0x%08lx", r->offset);
+ else if (!strcmp (r->sect, ".fixup"))
+ printf ("__start___fixup+0x%08lx", r->offset);
+ else
+ fatal();
+ if (f->type == 'f' || !r->f)
+ printf (",0");
+ else
+ printf (",___fs_%s+0x%08x", r->f->name, (4 + r->frel*2)*4 + 4);
+ if (j) printf (",");
+ else printf ("\n");
+ }
+ printf("\n");
+ }
+ printf("\n\t.global\t___btfixup_end\n___btfixup_end:\n");
+ printf("\n\n! Define undefined references\n\n");
+ for (i = 0; i < last; i++) {
+ f = array + i;
+ if (f->type == 'f') {
+ printf("\t.global\t___f_%s\n", f->name);
+ printf("___f_%s:\n", f->name);
+ }
+ }
+ printf("\tretl\n\t nop\n\n");
+ for (i = 0; i < last; i++) {
+ f = array + i;
+ if (f->type != 'f') {
+ if (!f->initval) {
+ printf("\t.global\t___%c_%s\n", f->type, f->name);
+ printf("___%c_%s = 0\n", f->type, f->name);
+ } else {
+ printf("\t.global\t___%c_%s__btset_0x%s\n", f->type, f->name, f->initvalstr);
+ printf("___%c_%s__btset_0x%s = 0x%08x\n", f->type, f->name, f->initvalstr, f->initval);
+ }
+ }
+ }
+ printf("\n\n");
+ exit(0);
+}
diff --git a/arch/sparc/boot/piggyback.c b/arch/sparc/boot/piggyback.c
new file mode 100644
index 0000000..6962cc6
--- /dev/null
+++ b/arch/sparc/boot/piggyback.c
@@ -0,0 +1,137 @@
+/* $Id: piggyback.c,v 1.4 2000/12/05 00:48:57 anton Exp $
+ Simple utility to make a single-image install kernel with initial ramdisk
+ for Sparc tftpbooting without need to set up nfs.
+
+ Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ Pete Zaitcev <zaitcev@yahoo.com> endian fixes for cross-compiles, 2000.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*
+ * Note: run this on an a.out kernel (use elftoaout for it),
+ * as PROM looks for a.out image only.
+ */
+
+unsigned short ld2(char *p)
+{
+ return (p[0] << 8) | p[1];
+}
+
+unsigned int ld4(char *p)
+{
+ return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+}
+
+void st4(char *p, unsigned int x)
+{
+ p[0] = x >> 24;
+ p[1] = x >> 16;
+ p[2] = x >> 8;
+ p[3] = x;
+}
+
+void usage(void)
+{
+ /* fs_img.gz is an image of initial ramdisk. */
+ fprintf(stderr, "Usage: piggyback vmlinux.aout System.map fs_img.gz\n");
+ fprintf(stderr, "\tKernel image will be modified in place.\n");
+ exit(1);
+}
+
+void die(char *str)
+{
+ perror (str);
+ exit(1);
+}
+
+int main(int argc,char **argv)
+{
+ static char aout_magic[] = { 0x01, 0x03, 0x01, 0x07 };
+ unsigned char buffer[1024], *q, *r;
+ unsigned int i, j, k, start, end, offset;
+ FILE *map;
+ struct stat s;
+ int image, tail;
+
+ if (argc != 4) usage();
+ start = end = 0;
+ if (stat (argv[3], &s) < 0) die (argv[3]);
+ map = fopen (argv[2], "r");
+ if (!map) die(argv[2]);
+ while (fgets (buffer, 1024, map)) {
+ if (!strcmp (buffer + 8, " T start\n") || !strcmp (buffer + 16, " T start\n"))
+ start = strtoul (buffer, NULL, 16);
+ else if (!strcmp (buffer + 8, " A end\n") || !strcmp (buffer + 16, " A end\n"))
+ end = strtoul (buffer, NULL, 16);
+ }
+ fclose (map);
+ if (!start || !end) {
+ fprintf (stderr, "Could not determine start and end from System.map\n");
+ exit(1);
+ }
+ if ((image = open(argv[1],O_RDWR)) < 0) die(argv[1]);
+ if (read(image,buffer,512) != 512) die(argv[1]);
+ if (memcmp (buffer, "\177ELF", 4) == 0) {
+ q = buffer + ld4(buffer + 28);
+ i = ld4(q + 4) + ld4(buffer + 24) - ld4(q + 8);
+ if (lseek(image,i,0) < 0) die("lseek");
+ if (read(image,buffer,512) != 512) die(argv[1]);
+ j = 0;
+ } else if (memcmp(buffer, aout_magic, 4) == 0) {
+ i = j = 32;
+ } else {
+ fprintf (stderr, "Not ELF nor a.out. Don't blame me.\n");
+ exit(1);
+ }
+ k = i;
+ i += (ld2(buffer + j + 2)<<2) - 512;
+ if (lseek(image,i,0) < 0) die("lseek");
+ if (read(image,buffer,1024) != 1024) die(argv[1]);
+ for (q = buffer, r = q + 512; q < r; q += 4) {
+ if (*q == 'H' && q[1] == 'd' && q[2] == 'r' && q[3] == 'S')
+ break;
+ }
+ if (q == r) {
+ fprintf (stderr, "Couldn't find headers signature in the kernel.\n");
+ exit(1);
+ }
+ offset = i + (q - buffer) + 10;
+ if (lseek(image, offset, 0) < 0) die ("lseek");
+
+ st4(buffer, 0);
+ st4(buffer + 4, 0x01000000);
+ st4(buffer + 8, (end + 32 + 4095) & ~4095);
+ st4(buffer + 12, s.st_size);
+
+ if (write(image,buffer+2,14) != 14) die (argv[1]);
+ if (lseek(image, k - start + ((end + 32 + 4095) & ~4095), 0) < 0) die ("lseek");
+ if ((tail = open(argv[3],O_RDONLY)) < 0) die(argv[3]);
+ while ((i = read (tail,buffer,1024)) > 0)
+ if (write(image,buffer,i) != i) die (argv[1]);
+ if (close(image) < 0) die("close");
+ if (close(tail) < 0) die("close");
+ return 0;
+}
OpenPOWER on IntegriCloud