aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/boot
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc64/boot
Linux-2.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/sparc64/boot')
-rw-r--r--arch/sparc64/boot/Makefile34
-rw-r--r--arch/sparc64/boot/piggyback.c109
2 files changed, 143 insertions, 0 deletions
diff --git a/arch/sparc64/boot/Makefile b/arch/sparc64/boot/Makefile
new file mode 100644
index 00000000000..6968a6da57d
--- /dev/null
+++ b/arch/sparc64/boot/Makefile
@@ -0,0 +1,34 @@
1# $Id: Makefile,v 1.4 1997/12/15 20:08:56 ecd Exp $
2# Makefile for the Sparc64 boot stuff.
3#
4# Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5# Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6
7ROOT_IMG := /usr/src/root.img
8ELFTOAOUT := elftoaout
9
10hostprogs-y := piggyback
11targets := image tftpboot.img vmlinux.aout
12
13quiet_cmd_elftoaout = ELF2AOUT $@
14 cmd_elftoaout = $(ELFTOAOUT) vmlinux -o $@
15quiet_cmd_piggy = PIGGY $@
16 cmd_piggy = $(obj)/piggyback $@ System.map $(ROOT_IMG)
17quiet_cmd_strip = STRIP $@
18 cmd_strip = $(STRIP) -R .comment -R .note -K sun4u_init -K _end -K _start vmlinux -o $@
19
20
21# Actual linking
22$(obj)/image: vmlinux FORCE
23 $(call if_changed,strip)
24 @echo ' kernel: $@ is ready'
25
26$(obj)/tftpboot.img: vmlinux $(obj)/piggyback System.map $(ROOT_IMG) FORCE
27 $(call if_changed,elftoaout)
28 $(call if_changed,piggy)
29 @echo ' kernel: $@ is ready'
30
31$(obj)/vmlinux.aout: vmlinux FORCE
32 $(call if_changed,elftoaout)
33 @echo ' kernel: $@ is ready'
34
diff --git a/arch/sparc64/boot/piggyback.c b/arch/sparc64/boot/piggyback.c
new file mode 100644
index 00000000000..36f907408c6
--- /dev/null
+++ b/arch/sparc64/boot/piggyback.c
@@ -0,0 +1,109 @@
1/* $Id: piggyback.c,v 1.2 2000/09/19 14:34:39 anton Exp $
2 Simple utility to make a single-image install kernel with initial ramdisk
3 for Sparc64 tftpbooting without need to set up nfs.
4
5 Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include <stdio.h>
22#include <string.h>
23#include <ctype.h>
24#include <errno.h>
25#include <fcntl.h>
26#include <dirent.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31
32/* Note: run this on an a.out kernel (use elftoaout for it), as PROM looks for a.out image onlly
33 usage: piggyback vmlinux System.map tail, where tail is gzipped fs of the initial ramdisk */
34
35void die(char *str)
36{
37 perror (str);
38 exit(1);
39}
40
41int main(int argc,char **argv)
42{
43 char buffer [1024], *q, *r;
44 unsigned int i, j, k, start, end, offset;
45 FILE *map;
46 struct stat s;
47 int image, tail;
48
49 if (stat (argv[3], &s) < 0) die (argv[3]);
50 map = fopen (argv[2], "r");
51 if (!map) die(argv[2]);
52 while (fgets (buffer, 1024, map)) {
53 if (!strcmp (buffer + 19, "_start\n"))
54 start = strtoul (buffer + 8, NULL, 16);
55 else if (!strcmp (buffer + 19, "_end\n"))
56 end = strtoul (buffer + 8, NULL, 16);
57 }
58 fclose (map);
59 if ((image = open(argv[1],O_RDWR)) < 0) die(argv[1]);
60 if (read(image,buffer,512) != 512) die(argv[1]);
61 if (!memcmp (buffer, "\177ELF", 4)) {
62 unsigned int *p = (unsigned int *)(buffer + *(unsigned int *)(buffer + 28));
63
64 i = p[1] + *(unsigned int *)(buffer + 24) - p[2];
65 if (lseek(image,i,0) < 0) die("lseek");
66 if (read(image,buffer,512) != 512) die(argv[1]);
67 j = 0;
68 } else if (*(unsigned int *)buffer == 0x01030107) {
69 i = j = 32;
70 } else {
71 fprintf (stderr, "Not ELF nor a.out. Don't blame me.\n");
72 exit(1);
73 }
74 k = i;
75 if (j == 32 && buffer[40] == 'H' && buffer[41] == 'd' && buffer[42] == 'r' && buffer[43] == 'S') {
76 offset = 40 + 10;
77 } else {
78 i += ((*(unsigned short *)(buffer + j + 2))<<2) - 512;
79 if (lseek(image,i,0) < 0) die("lseek");
80 if (read(image,buffer,1024) != 1024) die(argv[1]);
81 for (q = buffer, r = q + 512; q < r; q += 4) {
82 if (*q == 'H' && q[1] == 'd' && q[2] == 'r' && q[3] == 'S')
83 break;
84 }
85 if (q == r) {
86 fprintf (stderr, "Couldn't find headers signature in the kernel.\n");
87 exit(1);
88 }
89 offset = i + (q - buffer) + 10;
90 }
91 if (lseek(image, offset, 0) < 0) die ("lseek");
92 *(unsigned *)buffer = 0;
93 *(unsigned *)(buffer + 4) = 0x01000000;
94 *(unsigned *)(buffer + 8) = ((end + 32 + 8191) & ~8191);
95 *(unsigned *)(buffer + 12) = s.st_size;
96 if (write(image,buffer+2,14) != 14) die (argv[1]);
97 if (lseek(image, 4, 0) < 0) die ("lseek");
98 *(unsigned *)buffer = ((end + 32 + 8191) & ~8191) - (start & ~0x3fffffUL) + s.st_size;
99 *(unsigned *)(buffer + 4) = 0;
100 *(unsigned *)(buffer + 8) = 0;
101 if (write(image,buffer,12) != 12) die (argv[1]);
102 if (lseek(image, k - start + ((end + 32 + 8191) & ~8191), 0) < 0) die ("lseek");
103 if ((tail = open(argv[3],O_RDONLY)) < 0) die(argv[3]);
104 while ((i = read (tail,buffer,1024)) > 0)
105 if (write(image,buffer,i) != i) die (argv[1]);
106 if (close(image) < 0) die("close");
107 if (close(tail) < 0) die("close");
108 return 0;
109}