diff options
author | bencollins <tailor@grayson> | 2001-05-25 14:41:26 -0400 |
---|---|---|
committer | Ben Collins <bcollins@ubuntu.com> | 2006-06-01 13:17:37 -0400 |
commit | e06297f1496a279b30aef5eb30d0d5aaca9a41dc (patch) | |
tree | a8062ebc6c1580cd65c13efbfb92bebd0bc467c7 | |
parent | 877a3db9f8bd63bb288539632fa966a2f23b232d (diff) | |
download | silo-e06297f1496a279b30aef5eb30d0d5aaca9a41dc.tar.gz |
[silo @ 14]
* second/console.c: Move to common/
* second/udiv.S: Likewise.
* second/inflate.c: Likewise.
* second/jmp.S: Likewise.
* second/malloc.c: Likewise.
* second/printf.c: Likewise.
* second/prom.c: Likewise.
* second/stringops1.c: Likewise.
* second/stringops2.c: Likewise.
* second/tree.c: Likewise.
* second/urem.S: Likewise.
* second/bin2h.c: Likewise.
* second/stringops.h: Move to include/
* second/promlib.h: Likewise.
* second/silo.h: Likewise.
* common/Makefile: New file. Build common objects.
* docs/README.tilo: New file. README from original TILO.
* man/maketilo.1: New file. Maketilo manpage.
* man/tilo.1: New file. Tilo script man page.
* tilo/Makefile: New file. Welcome TILO
* tilo/crt0.S: Likewise.
* tilo/maketilo.c: Likewise.
* tilo/tilo.c: Likewise.
* tilo/tilo.sh: Likewise.
* second/setjmp.h: Removed.
* silo/util.c: Removed in favor of bin2h.
* common/bin2h.c: Modified so it takes a -l option which can be the
name of a define for the length of the file being converted.
* second/Makefile: Modify for new location of objects and the new
command line for bin2h.
* silo/Makefile: Likewise.
* Makefile: Add the common and tilo subdirectories.
* Rules.make: Add rules for ../common/% and move some common values
here (LD, CC, ELFTOAOUT, ...)
* first/Makefile: Modify for new header and object locations.
* second/9660.c: Likewise.
* second/cfg.c: Likewise.
* second/cmdline.c: Likewise.
* second/decomp.c: Likewise.
* second/disk.c: Likewise.
* second/file.c: Likewise.
* second/ls.c: Likewise.
* second/main.c: Likewise.
* second/memory.c: Likewise.
* second/misc.c: Likewise.
* second/ranges.c: Likewise.
* second/romfs.c: Likewise.
* second/timer.c: Likewise.
* second/ufs.c: Likewise.#
-rw-r--r-- | ChangeLog | 58 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | Rules.make | 9 | ||||
-rw-r--r-- | common/Makefile | 24 | ||||
-rw-r--r-- | common/bin2h.c | 75 | ||||
-rw-r--r-- | common/console.c (renamed from second/console.c) | 4 | ||||
-rw-r--r-- | common/inflate.c (renamed from second/inflate.c) | 2 | ||||
-rw-r--r-- | common/jmp.S (renamed from second/jmp.S) | 5 | ||||
-rw-r--r-- | common/malloc.c (renamed from second/malloc.c) | 7 | ||||
-rw-r--r-- | common/printf.c (renamed from second/printf.c) | 0 | ||||
-rw-r--r-- | common/prom.c (renamed from second/prom.c) | 4 | ||||
-rw-r--r-- | common/stringops1.c (renamed from second/stringops1.c) | 20 | ||||
-rw-r--r-- | common/stringops2.c (renamed from second/stringops2.c) | 8 | ||||
-rw-r--r-- | common/tree.c (renamed from second/tree.c) | 6 | ||||
-rw-r--r-- | common/udiv.S (renamed from second/udiv.S) | 2 | ||||
-rw-r--r-- | common/urem.S (renamed from second/urem.S) | 2 | ||||
-rw-r--r-- | docs/README.tilo | 40 | ||||
-rw-r--r-- | first/Makefile | 4 | ||||
-rw-r--r-- | include/promlib.h (renamed from second/promlib.h) | 0 | ||||
-rw-r--r-- | include/silo.h (renamed from second/silo.h) | 2 | ||||
-rw-r--r-- | include/stringops.h (renamed from second/stringops.h) | 2 | ||||
-rw-r--r-- | man/maketilo.1 | 3 | ||||
-rw-r--r-- | man/tilo.1 | 59 | ||||
-rw-r--r-- | second/9660.c | 4 | ||||
-rw-r--r-- | second/Makefile | 51 | ||||
-rw-r--r-- | second/cfg.c | 8 | ||||
-rw-r--r-- | second/cmdline.c | 2 | ||||
-rw-r--r-- | second/decomp.c | 6 | ||||
-rw-r--r-- | second/disk.c | 4 | ||||
-rw-r--r-- | second/file.c | 10 | ||||
-rw-r--r-- | second/ls.c | 4 | ||||
-rw-r--r-- | second/main.c | 4 | ||||
-rw-r--r-- | second/memory.c | 48 | ||||
-rw-r--r-- | second/misc.c | 4 | ||||
-rw-r--r-- | second/ranges.c | 2 | ||||
-rw-r--r-- | second/romfs.c | 4 | ||||
-rw-r--r-- | second/setjmp.h | 8 | ||||
-rw-r--r-- | second/timer.c | 2 | ||||
-rw-r--r-- | second/ufs.c | 4 | ||||
-rw-r--r-- | silo/Makefile | 10 | ||||
-rw-r--r-- | silo/util.c | 47 | ||||
-rw-r--r-- | tilo/Makefile | 63 | ||||
-rw-r--r-- | tilo/crt0.S | 143 | ||||
-rw-r--r-- | tilo/maketilo.c | 281 | ||||
-rw-r--r-- | tilo/tilo.c | 264 | ||||
-rwxr-xr-x | tilo/tilo.sh | 120 |
46 files changed, 1255 insertions, 180 deletions
@@ -1,3 +1,61 @@ +Fri May 25 10:16:39 EDT 2001 Ben Collins <bcollins@debian.org> + + * second/console.c: Move to common/ + * second/udiv.S: Likewise. + * second/inflate.c: Likewise. + * second/jmp.S: Likewise. + * second/malloc.c: Likewise. + * second/printf.c: Likewise. + * second/prom.c: Likewise. + * second/stringops1.c: Likewise. + * second/stringops2.c: Likewise. + * second/tree.c: Likewise. + * second/urem.S: Likewise. + * second/bin2h.c: Likewise. + + * second/stringops.h: Move to include/ + * second/promlib.h: Likewise. + * second/silo.h: Likewise. + + * common/Makefile: New file. Build common objects. + * docs/README.tilo: New file. README from original TILO. + * man/maketilo.1: New file. Maketilo manpage. + * man/tilo.1: New file. Tilo script man page. + + * tilo/Makefile: New file. Welcome TILO + * tilo/crt0.S: Likewise. + * tilo/maketilo.c: Likewise. + * tilo/tilo.c: Likewise. + * tilo/tilo.sh: Likewise. + + * second/setjmp.h: Removed. + * silo/util.c: Removed in favor of bin2h. + + * common/bin2h.c: Modified so it takes a -l option which can be the + name of a define for the length of the file being converted. + * second/Makefile: Modify for new location of objects and the new + command line for bin2h. + * silo/Makefile: Likewise. + * Makefile: Add the common and tilo subdirectories. + * Rules.make: Add rules for ../common/% and move some common values + here (LD, CC, ELFTOAOUT, ...) + + * first/Makefile: Modify for new header and object locations. + * second/9660.c: Likewise. + * second/cfg.c: Likewise. + * second/cmdline.c: Likewise. + * second/decomp.c: Likewise. + * second/disk.c: Likewise. + * second/file.c: Likewise. + * second/ls.c: Likewise. + * second/main.c: Likewise. + * second/memory.c: Likewise. + * second/misc.c: Likewise. + * second/ranges.c: Likewise. + * second/romfs.c: Likewise. + * second/timer.c: Likewise. + * second/ufs.c: Likewise. + Tue May 22 20:16:48 EDT 2001 Ben Collins <bcollins@debian.org> * silo/Makefile: Rewrite logic for checking arch/OS. Make it cleaner. @@ -1,4 +1,4 @@ -SUBDIRS=first second silo +SUBDIRS=common first second silo tilo all dep depend clean: @for I in $(SUBDIRS); do cd $$I; $(MAKE) $@ || exit 1; cd ..; done @@ -6,12 +6,14 @@ all dep depend clean: ifeq (Linux,$(shell uname)) install: install -d -m755 $(DESTDIR)/boot $(DESTDIR)/etc $(DESTDIR)/sbin \ - $(DESTDIR)/usr/sbin + $(DESTDIR)/usr/sbin $(DESTDIR)/usr/bin install -m644 first/*.b second/*.b $(DESTDIR)/boot/ install -m755 silo/silo $(DESTDIR)/sbin install -m755 silo/silocheck $(DESTDIR)/usr/sbin [ -f $(DESTDIR)/etc/silo.conf ] || \ install -m644 etc/silo.conf $(DESTDIR)/etc/ + install -m755 tilo/maketilo $(DESTDIR)/usr/bin + install -m755 tilo/tilo.sh $(DESTDIR)/usr/bin/tilo else ifeq (SunOS,$(shell uname -s)) ifeq (5.,$(findstring 5.,$(shell uname -r))) @@ -1,2 +1,9 @@ -VERSION=0.9.9.5 +VERSION=1.0 IMGVERSION=0.99 +RM=/bin/rm -f +CC=gcc +LD=ld +ELFTOAOUT=elftoaout + +../common/%: + $(MAKE) -C ../common $* diff --git a/common/Makefile b/common/Makefile new file mode 100644 index 0000000..df792b6 --- /dev/null +++ b/common/Makefile @@ -0,0 +1,24 @@ +## +## Common files between tilo and silo +## + +include ../Rules.make + +CFLAGS = -O2 -Wall -fomit-frame-pointer -I../include + +.c.o: + $(CC) $(CFLAGS) -c $*.c + +.S.o: + $(CC) $(CFLAGS) -c $*.S + +OBJS = udiv.o urem.o jmp.o printf.o console.o prom.o tree.o stringops2.o stringops1.o +PROGRAMS = bin2h + +all: $(OBJS) $(PROGRAMS) + +prom.o: prom.c + $(CC) $(CFLAGS) -c -Wa,-Av9 -o prom.o prom.c + +clean: + $(RM) $(OBJS) $(PROGRAMS) *.o diff --git a/common/bin2h.c b/common/bin2h.c new file mode 100644 index 0000000..87e5e8b --- /dev/null +++ b/common/bin2h.c @@ -0,0 +1,75 @@ +/* a simple utility to dump binary into a header file + + Copyright (C) 1996 Jakub Jelinek + + 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> + +int main (int argc, char **argv) +{ + FILE *f; + char buffer[512], *array_name, *file_name, *lendef_name = NULL; + int i, j, offset = 1; + + if (argc != 3 && !(argc == 5 && !strcmp(argv[1],"-l"))) { + fprintf(stderr, "Usage: %s [-l len_def] <array name> <file>\n", argv[0]); + exit (1); + } + + if (!strcmp(argv[1],"-l")) { + lendef_name = argv[offset + 1]; + offset += 2; + } + + array_name = argv[offset++]; + file_name = argv[offset]; + + if ((f = fopen(file_name, "r")) == NULL) { + perror("fopen"); + exit (1); + } + + if (lendef_name != NULL) { + int len; + if (fseek (f, 0, SEEK_END)) { + perror("fseek"); + exit (1); + } + + len = ftell (f); + + if (fseek (f, 0, SEEK_SET)) { + perror("fseek"); + exit (1); + } + + printf ("#define %s %d\n\n",lendef_name, len); + } + + printf ("char %s[] = {\n", array_name); + while ((offset = fread (buffer, 1, sizeof(buffer), f))) { + for (i = 0; i < 32 && offset; i++) { + for (j = 0; j < 16 && offset; j++) { + printf ("0x%02X, ", (unsigned char)buffer[16 * i + j]); + offset--; + } + printf ("\n"); + } + } + fclose(f); + printf ("};\n"); + exit (0); +} diff --git a/second/console.c b/common/console.c index 0235dba..44d7efb 100644 --- a/second/console.c +++ b/common/console.c @@ -1,4 +1,4 @@ -/* $Id: console.c,v 1.1 2001/04/27 21:55:24 bencollins Exp $ +/* $Id: console.c,v 1.1 2001/05/25 14:41:26 bencollins Exp $ * console.c: Routines that deal with sending and receiving IO * to/from the current console device using the PROM. * @@ -6,7 +6,7 @@ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ -#include "promlib.h" +#include <promlib.h> /* Non blocking get character from console input device, returns -1 * if no input was taken. This can be used for polling. diff --git a/second/inflate.c b/common/inflate.c index b44e382..6bd839b 100644 --- a/second/inflate.c +++ b/common/inflate.c @@ -95,7 +95,7 @@ the two sets of lengths. */ -#include "stringops.h" +#include <stringops.h> #define slide window diff --git a/second/jmp.S b/common/jmp.S index b4a16f7..0c33c8c 100644 --- a/second/jmp.S +++ b/common/jmp.S @@ -24,9 +24,10 @@ _RV; _RV; _RV; _RV; _RV; _RV; _RV; /* Save our return PC and SP. */ - .global __setjmp, setjmp + .global _setjmp, setjmp, __sigsetjmp setjmp: -__setjmp: +_setjmp: +__sigsetjmp: st %o7, [%o0] st %sp, [%o0 + 4] retl diff --git a/second/malloc.c b/common/malloc.c index 7d2f8b6..e055aef 100644 --- a/second/malloc.c +++ b/common/malloc.c @@ -17,10 +17,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define MALLOC_BASE 0x2B0000 - +#ifndef MALLOC_BASE extern unsigned long _start; static char *malloc_ptr = ((char *)&_start) + 0x30000; +#else +static char *malloc_ptr = (char *) MALLOC_BASE; +#endif + static char *last_alloc = 0; void *malloc (int size) diff --git a/second/printf.c b/common/printf.c index 584d609..584d609 100644 --- a/second/printf.c +++ b/common/printf.c diff --git a/second/prom.c b/common/prom.c index 53e318c..c2749d1 100644 --- a/second/prom.c +++ b/common/prom.c @@ -1,4 +1,4 @@ -/* $Id: prom.c,v 1.1 2001/04/27 21:55:44 bencollins Exp $ +/* $Id: prom.c,v 1.1 2001/05/25 14:41:26 bencollins Exp $ * init.c: Initialize internal variables used by the PROM * library functions. * @@ -6,7 +6,7 @@ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ -#include "promlib.h" +#include <promlib.h> struct linux_romvec *romvec; enum prom_major_version prom_vers; diff --git a/second/stringops1.c b/common/stringops1.c index 3588344..c74f9f0 100644 --- a/second/stringops1.c +++ b/common/stringops1.c @@ -5,7 +5,7 @@ Copyright (C) 1991, 1992 Linus Torvalds */ -#include "stringops.h" +#include <stringops.h> char *strcpy(char *dest, const char *src) { @@ -43,3 +43,21 @@ void *memcpy(void *dest,const void *src,size_t count) *tmp++ = *s++; return dest; } + +void *memmove(void *dest,const void *src,size_t count) +{ + char *d, *s; + + if (dest <= src) { + d = (char *) dest; + s = (char *) src; + while (count--) + *d++ = *s++; + } else { + d = (char *) dest + count; + s = (char *) src + count; + while (count--) + *--d = *--s; + } + return dest; +} diff --git a/second/stringops2.c b/common/stringops2.c index a003c95..d975b55 100644 --- a/second/stringops2.c +++ b/common/stringops2.c @@ -4,7 +4,7 @@ Copyright (C) 1991, 1992 Linus Torvalds */ -#include "stringops.h" +#include <stringops.h> char * strncpy(char *dest, const char *src, int count) { @@ -143,3 +143,9 @@ void *realloc(void *p, int size) { return 0; /* We do not support this */ } + +int sprintf (char *buf, char *fmt,...) +{ + strcpy (buf, fmt); + return 0; +} diff --git a/second/tree.c b/common/tree.c index 083cef4..6026fe9 100644 --- a/second/tree.c +++ b/common/tree.c @@ -1,4 +1,4 @@ -/* $Id: tree.c,v 1.2 2001/05/22 04:21:14 bencollins Exp $ +/* $Id: tree.c,v 1.1 2001/05/25 14:41:26 bencollins Exp $ * tree.c: Basic device tree traversal/scanning for the Linux * prom library. * @@ -6,8 +6,8 @@ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ -#include "silo.h" -#include "stringops.h" +#include <silo.h> +#include <stringops.h> static char promlib_buf[128]; diff --git a/second/udiv.S b/common/udiv.S index 393f674..d3b7b03 100644 --- a/second/udiv.S +++ b/common/udiv.S @@ -1,4 +1,4 @@ -/* $Id: udiv.S,v 1.1 2001/04/27 21:55:51 bencollins Exp $ +/* $Id: udiv.S,v 1.1 2001/05/25 14:41:26 bencollins Exp $ * udiv.S: This routine was taken from glibc-1.09 and is covered * by the GNU Library General Public License Version 2. */ diff --git a/second/urem.S b/common/urem.S index e44edb0..45e0200 100644 --- a/second/urem.S +++ b/common/urem.S @@ -1,4 +1,4 @@ -/* $Id: urem.S,v 1.1 2001/04/27 21:55:53 bencollins Exp $ +/* $Id: urem.S,v 1.1 2001/05/25 14:41:26 bencollins Exp $ * urem.S: This routine was taken from glibc-1.09 and is covered * by the GNU Library General Public License Version 2. */ diff --git a/docs/README.tilo b/docs/README.tilo new file mode 100644 index 0000000..4bd0966 --- /dev/null +++ b/docs/README.tilo @@ -0,0 +1,40 @@ + T I L O + (Trivial Image LOader) + ---------------------- + Jan Vondrak (C) 1998 + +This is a tool for building a simple TFTP boot loader +which embodies several kernel images for different Sun +architectures and a ramdisk root image. To minimize +memory usage, the images are gzipped. After starting +the boot loader, the architecture is detected, +the appropriate kernel is unpacked and then the +booting procedure is launched. + +How to build the boot image: + +1. Prepare a kernel image for each supported architecture + (in the ELF format). Currently, TILO expects two kernels + - for Sun4c/m/d and Sun4u. However, it will be possible + to add Sun4 support in the future as well. + +2. Prepare a root image for the initial ramdisk. + +3. Run the "tilo" script with the following parameters: + +tilo [ -o output ] <kernel images> <root image> + +A boot image will be created which contains everything +necessary to boot on each architecture. + +This code can be used and distributed freely +under the General Public Licence (see COPYING). + +Please address any comments or bug reports to: + + jvon4518@barbora.mff.cuni.cz + + + Enjoy ! + + Jan Vondrak diff --git a/first/Makefile b/first/Makefile index 0748414..9471dac 100644 --- a/first/Makefile +++ b/first/Makefile @@ -139,5 +139,5 @@ ieee32.b: ieee32.o clean: $(RM) *.o *~ first first.b first.map first.h ultra ultra.b ultra.s ultra.map ultra.h \ - ieee32.b ieee32.map \ - cd cd.b cd.s cd.map generic generic.b generic.s generic.map generic.h fd.h fd fd.b fd.s fd.map core + ieee32.b ieee32.map cd cd.b cd.s cd.map generic generic.b generic.s generic.map \ + generic.h fd.h fd fd.b fd.s fd.map core diff --git a/second/promlib.h b/include/promlib.h index 765bd93..765bd93 100644 --- a/second/promlib.h +++ b/include/promlib.h diff --git a/second/silo.h b/include/silo.h index e0d33e7..88c513c 100644 --- a/second/silo.h +++ b/include/silo.h @@ -1,7 +1,7 @@ #ifndef SILO_H #define SILO_H -#include "promlib.h" +#include <promlib.h> #define CMD_LENG 512 diff --git a/second/stringops.h b/include/stringops.h index a1a3c47..4e7dc5a 100644 --- a/second/stringops.h +++ b/include/stringops.h @@ -15,6 +15,7 @@ int strcmp(const char *, const char *); void *memset(void *, int, size_t); void __bzero(void *, size_t); void *memcpy(void *, const void *, size_t); +void *memmove(void *, const void *, size_t); /* stringops2.c */ char *strncpy(char *, const char *, int); @@ -31,5 +32,6 @@ char *strstr(const char *, const char *); unsigned long time(void); void *realloc(void *, int); int memcmp(const void *, const void *, size_t); +int sprintf (char *, char *, ...); #endif /* __STRINGOPS_H */ diff --git a/man/maketilo.1 b/man/maketilo.1 new file mode 100644 index 0000000..4840dcf --- /dev/null +++ b/man/maketilo.1 @@ -0,0 +1,3 @@ +.\" -*- nroff -*- +.\" +.so man1/tilo.1 diff --git a/man/tilo.1 b/man/tilo.1 new file mode 100644 index 0000000..cc1c925 --- /dev/null +++ b/man/tilo.1 @@ -0,0 +1,59 @@ +.\" -*- nroff -*- +.\" +.\" This file was written by Eric Delaunay <delaunay@debian.org>. +.\" It is just a transcript of the README file from tilo-0.2. +.\" +.TH TILO 1 "1998" "tilo" +.SH NAME +tilo \- Trivial Image LOader +.SH SYNOPSIS +.B tilo +.I <Sun4c/m/d kernel> +.I <Sun4u kernel> +.I <root image> +.I <TILO image> +.SH DESCRIPTION +.BI tilo +is a tool for building a simple TFTP boot loader +which embodies several kernel images for different Sun +architectures and a ramdisk root image. To minimize +memory usage, the images are gzipped. After starting +the boot loader, the architecture is detected, +the appropriate kernel is unpacked and then the +booting procedure is launched. +.PP +.SH OPTIONS +.TP +.I <Sun4c/m/d kernel> +the kernel for Sun4c/m/d architecture (in ELF format) +.TP +.I <Sun4u kernel> +the kernel for Sun4u (ultrasparc) architecture (in ELF format) +.TP +.I <root image> +the initial ramdisk image to append to the kernel image. It could be +compressed as well +.TP +.I <TILO image> +TFTP boot image name as result of +.B tilo +command. +.PP +A boot image will be created which contains everything +necessary to boot on each architecture. +.SH NOTE +.B maketilo +is an internal command used by the +.B tilo +script. There is no need to use it directly. +.SH AUTHOR +.B tilo +has been written by Jan Vondrak <jvon4518@barbora.mff.cuni.cz>. +.SH AVAILABILITY +.B tilo +is available for anonymous ftp from sunsite.mff.cuni.cz in +/OS/Linux/Non-x86/Sparc/local/ultrapenguin-1.1.9/sparc/misc/src/trees/tilo-0.2. +.SH SEE ALSO +.BR piggyback (1), +.BR piggyback64 (1), +.BR elftoaout (1) diff --git a/second/9660.c b/second/9660.c index 27794a6..09f2879 100644 --- a/second/9660.c +++ b/second/9660.c @@ -22,7 +22,7 @@ # include <ctype.h> # include <sys/types.h> # include <errno.h> -# include "silo.h" +# include <silo.h> typedef int FILE; # include <linux/ext2_fs.h> # include <linux/iso_fs.h> @@ -38,7 +38,7 @@ typedef int FILE; #endif -#include "stringops.h" +#include <stringops.h> #include "ext2fs/ext2fs.h" #include "9660.h" diff --git a/second/Makefile b/second/Makefile index 552a259..930767c 100644 --- a/second/Makefile +++ b/second/Makefile @@ -3,15 +3,11 @@ ## ## -CC=gcc -LD=ld AS=as -RM=/bin/rm -f NM=nm DD=dd AWK=awk LS=ls -ELFTOAOUT=elftoaout STRIP=strip GZIP=gzip GDB=gdb @@ -39,11 +35,11 @@ LDFLAGS2=-N -Ttext 0x380000 OBJS1 = crt0.o OBJS2 = decomp.o OBJS2N = decompnet.o -OBJS3 = console.o printf.o malloc.o jmp.o prom.o tree.o urem.o udiv.o stringops1.o +OBJS3 = ../common/console.o ../common/printf.o malloc.o ../common/jmp.o ../common/prom.o ../common/tree.o ../common/urem.o ../common/udiv.o ../common/stringops1.o OBJS4 = main.o OBJS4N = mainnet.o OBJS5 = cmdline.o disk.o file.o misc.o cfg.o strtol.o ranges.o timer.o memory.o ufs.o romfs.o 9660.o divdi3.o \ - mul.o rem.o sdiv.o umul.o stringops2.o ls.o muldi3.o + mul.o rem.o sdiv.o umul.o ../common/stringops2.o ls.o muldi3.o OBJS = $(OBJS1) $(OBJS2) $(OBJS3) bmark.o $(OBJS4) $(OBJS5) OBJSNET = $(OBJS1) $(OBJS2N) $(OBJS3) bmark.o $(OBJS4N) $(OBJS5) @@ -74,51 +70,26 @@ silotftp: $(OBJSNET) mark.o second.l: second ( $(ECHO) 'disassemble 0x280000 '`$(GREP) '_etext' second.map | $(SED) 's/ .*$$//' | $(SED) 's/^00/0x/'`; $(ECHO) quit ) | $(GDB) second | $(SED) '1,/^(gdb)/d;/^End /,$$d' > second.l -main.o: main.c silo.h -ls.o: ls.c silo.h -malloc.o: malloc.c silo.h -printf.o: printf.c silo.h -cmdline.o: cmdline.c silo.h -console.o: console.c silo.h -misc.o: misc.c silo.h -disk.o: disk.c silo.h -file.o: file.c silo.h ufs.h -cfg.o: cfg.c silo.h -ranges.o: ranges.c silo.h -tree.o: tree.c silo.h -timer.o: timer.c silo.h -decomp.o: decomp.c inflate.c silo.h -mark.o: mark.S -bmark.o: bmark.S -mul.o: mul.S -umul.o: umul.S -sdiv.o: sdiv.S -udiv.o: udiv.S -rem.o: rem.S -urem.o: urem.S -ufs.o: ufs.c silo.h ufs.h -romfs.o: romfs.c silo.h -memory.o: memory.c silo.h -jmp.o: jmp.S -divdi3.o: divdi3.S -prom.o: prom.c promlib.h -decompnet.o: decomp.c inflate.c silo.h +file.o: file.c ufs.h +ufs.o: ufs.c ufs.h + +decompnet.o: decomp.c $(CC) $(CFLAGS) -DTFTP -c -o decompnet.o decomp.c -mainnet.o: main.c silo.h +mainnet.o: main.c $(CC) $(CFLAGS) -DTFTP -c -o mainnet.o main.c +malloc.o: ../common/malloc.c + $(CC) $(CFLAGS) -c -o malloc.o ../common/malloc.c + util: util.c $(CC) -o util util.c clean: - $(RM) $(OBJS) *.o second second2 second.b silotftp silotftp2 silotftp.b second.l *.map core *~ util second.b second.image.tmp *.s + $(RM) *.o second second2 second.b silotftp silotftp2 silotftp.b second.l *.map core *~ util second.b second.image.tmp *.s crt0.o: crt0.S $(CC) $(CFLAGS) -c -Wa,-Av9 -DIMGVERSION='"SILO$(IMGVERSION)"' crt0.S -prom.o: prom.c - $(CC) $(CFLAGS) -c -Wa,-Av9 prom.c - memory.o: memory.c $(CC) $(CFLAGS) -c -Wa,-Av9 memory.c diff --git a/second/cfg.c b/second/cfg.c index 63dcc4b..31e9080 100644 --- a/second/cfg.c +++ b/second/cfg.c @@ -20,13 +20,13 @@ /* This file gets included by the confcheck (usespace), try to be nice */ #ifndef SILOCONFCHECK -#include "silo.h" -#include "stringops.h" -#include "setjmp.h" +#include <silo.h> +#include <stringops.h> +#include <setjmp.h> #ifndef NULL #define NULL (void *)0 #endif -#include "promlib.h" +#include <promlib.h> #endif /* !SILOCONFCHECK */ diff --git a/second/cmdline.c b/second/cmdline.c index 7bb1114..fdd9774 100644 --- a/second/cmdline.c +++ b/second/cmdline.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" +#include <silo.h> char cbuff[CMD_LENG]; char passwdbuff[CMD_LENG]; diff --git a/second/decomp.c b/second/decomp.c index 3c42830..3d77d66 100644 --- a/second/decomp.c +++ b/second/decomp.c @@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" -#include "setjmp.h" +#include <silo.h> +#include <setjmp.h> #ifndef NULL #define NULL (void *)0 #endif @@ -75,7 +75,7 @@ jmp_buf gunzip_env; #define get_byte() (*get_input_fun)() #define unget_byte() (*unget_input_fun)() -#include "inflate.c" +#include "../common/inflate.c" static void error (char *m) { diff --git a/second/disk.c b/second/disk.c index ec476f1..3fdee54 100644 --- a/second/disk.c +++ b/second/disk.c @@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" -#include "stringops.h" +#include <silo.h> +#include <stringops.h> static int net = 0; static int floppy = 0; diff --git a/second/file.c b/second/file.c index 2d71580..2b6b240 100644 --- a/second/file.c +++ b/second/file.c @@ -23,7 +23,7 @@ #include <sys/types.h> #include <sys/time.h> #include <errno.h> -#include "silo.h" +#include <silo.h> typedef int FILE; #include <linux/ext2_fs.h> #include <ext2fs/ext2fs.h> @@ -36,7 +36,7 @@ static struct { #include <ext2fs/ext2_err.et> } }; -#include "stringops.h" +#include <stringops.h> #include "ufs.h" #include "romfs.h" #include "9660.h" @@ -105,12 +105,6 @@ static int read_sun_partition (int partno) return 1; } -int sprintf (char *buf, char *fmt,...) -{ - strcpy (buf, fmt); - return 0; -} - void com_err (const char *a, long i, const char *fmt,...) { printf ((char *) fmt); diff --git a/second/ls.c b/second/ls.c index 8b0d444..e64f313 100644 --- a/second/ls.c +++ b/second/ls.c @@ -18,11 +18,11 @@ # include <ctype.h> # include <sys/types.h> -# include "silo.h" +# include <silo.h> typedef int FILE; # include <linux/ext2_fs.h> -#include "stringops.h" +#include <stringops.h> #include "ext2fs/ext2fs.h" int ls_opt = 0; diff --git a/second/main.c b/second/main.c index b30aae8..8e2156d 100644 --- a/second/main.c +++ b/second/main.c @@ -22,10 +22,10 @@ /* TODO: This file is a good candidate for rewrite from scratch */ -#include "silo.h" +#include <silo.h> #include <asm/page.h> #include <linux/elf.h> -#include "stringops.h" +#include <stringops.h> #ifndef NULL #define NULL (void *)0 diff --git a/second/memory.c b/second/memory.c index bc9ba94..c2a61ef 100644 --- a/second/memory.c +++ b/second/memory.c @@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" +#include <silo.h> struct linux_prom_registers prom_reg_memlist[64]; struct linux_mlist_v0 prom_phys_avail[64]; @@ -303,20 +303,20 @@ char *memory_find (int len) } sun4u_memory_base = base & ~0x3fffffULL; sun4u_initrd_pa = base - phys_base; - __asm __volatile(" - sethi %%hi(0xe0000000), %%g1 - ldx [%3], %%g2 - sllx %%g1, 32, %%g1 - or %%g2, 0x77, %%g2 - or %%g2, %%g1, %%g2 - rdpr %%pil, %%g1 - wrpr 15, %%pil - stxa %0, [%1] %2 - stxa %%g2, [%4] %5 - membar #Sync - flush %0 - membar #Sync - wrpr %%g1, %%pil + __asm __volatile("\n\ + sethi %%hi(0xe0000000), %%g1\n\ + ldx [%3], %%g2\n\ + sllx %%g1, 32, %%g1\n\ + or %%g2, 0x77, %%g2\n\ + or %%g2, %%g1, %%g2\n\ + rdpr %%pil, %%g1\n\ + wrpr 15, %%pil\n\ + stxa %0, [%1] %2\n\ + stxa %%g2, [%4] %5\n\ + membar #Sync\n\ + flush %0\n\ + membar #Sync\n\ + wrpr %%g1, %%pil\n\ " : : "r" (0x40000000), "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU), "r" (&sun4u_memory_base), "r" (63 << 3), "i" (ASI_DTLB_DATA_ACCESS) : "g1", "g2"); return (char *)0x40000000 + ((long)base & 0x3fffffUL); @@ -328,15 +328,15 @@ not_found: void memory_release(void) { if (sun4u_initrd_pa) { - __asm __volatile(" - rdpr %%pil, %%g1 - wrpr 16, %%pil - stxa %%g0, [%0] %1 - stxa %%g0, [%2] %3 - membar #Sync - flush %4 - membar #Sync - wrpr %%g1, %%pil + __asm __volatile("\n\ + rdpr %%pil, %%g1\n\ + wrpr 16, %%pil\n\ + stxa %%g0, [%0] %1\n\ + stxa %%g0, [%2] %3\n\ + membar #Sync\n\ + flush %4\n\ + membar #Sync\n\ + wrpr %%g1, %%pil\n\ " : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU), "r" (63 << 3), "i" (ASI_DTLB_DATA_ACCESS), "r" (memory_release) : "g1"); diff --git a/second/misc.c b/second/misc.c index 62e9ad2..300241a 100644 --- a/second/misc.c +++ b/second/misc.c @@ -18,10 +18,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" +#include <silo.h> #include <asm/idprom.h> #include <asm/machines.h> -#include "stringops.h" +#include <stringops.h> void fatal (const char *msg) { diff --git a/second/ranges.c b/second/ranges.c index 2d84fba..87708ff 100644 --- a/second/ranges.c +++ b/second/ranges.c @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" +#include <silo.h> struct linux_prom_ranges promlib_obio_ranges[PROMREG_MAX]; int num_obio_ranges; diff --git a/second/romfs.c b/second/romfs.c index 1d90e80..c9f039f 100644 --- a/second/romfs.c +++ b/second/romfs.c @@ -22,7 +22,7 @@ # include <ctype.h> # include <sys/types.h> # include <errno.h> -# include "silo.h" +# include <silo.h> typedef int FILE; # include <linux/ext2_fs.h> @@ -36,7 +36,7 @@ typedef int FILE; #endif -#include "stringops.h" +#include <stringops.h> #include "romfs.h" #define SUPROMFS (struct romfs_super_block *)(fs->io->private_data) diff --git a/second/setjmp.h b/second/setjmp.h deleted file mode 100644 index 604a772..0000000 --- a/second/setjmp.h +++ /dev/null @@ -1,8 +0,0 @@ -typedef struct { - char *__pc; - char *__fp; -} jmp_buf[1]; - -extern void longjmp (jmp_buf __env, int __val) __attribute__((noreturn)); -extern int setjmp (jmp_buf __env); -
\ No newline at end of file diff --git a/second/timer.c b/second/timer.c index f15582f..8114fdf 100644 --- a/second/timer.c +++ b/second/timer.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "silo.h" +#include <silo.h> #include <asm/mostek.h> struct sun4m_timer_regs { diff --git a/second/ufs.c b/second/ufs.c index 318bab4..527afca 100644 --- a/second/ufs.c +++ b/second/ufs.c @@ -23,7 +23,7 @@ # include <sys/types.h> # include <sys/time.h> # include <errno.h> -# include "silo.h" +# include <silo.h> typedef int FILE; # include <linux/ext2_fs.h> @@ -43,7 +43,7 @@ typedef int FILE; #include <sys/stat.h> #endif -#include "stringops.h" +#include <stringops.h> #define SUPUFS (struct ufs_superblock *)(fs->io->private_data) #define cgstart(cg) ((sb->fs_fpg * (cg)) + sb->fs_cgoffset * ((cg) & ~(sb->fs_cgmask))) diff --git a/silo/Makefile b/silo/Makefile index 5d9741f..bb6165a 100644 --- a/silo/Makefile +++ b/silo/Makefile @@ -24,7 +24,6 @@ all: $(PROGRAMS) CFLAGS=-Wall -g -O2 -I../include -I/usr/src/linux/include -Werror LDFLAGS= -CC=gcc HEADERS=../first/first.h ../first/ultra.h ../first/fd.h SILO_OBJS=confcheck.o prom.o silo.o SILOCHK_OBJS=silocheck.o @@ -35,15 +34,12 @@ silo: $(HEADERS) $(SILO_OBJS) silocheck: $(SILOCHK_OBJS) $(UFSDEPS) $(CC) $(LDFLAGS) -o $@ $(SILOCHK_OBJS) -floppy.h: floppy.label util - ./util floppy_label floppy.label > floppy.h +floppy.h: floppy.label ../common/bin2h + ../common/bin2h floppy_label floppy.label > floppy.h ufs.h: ../second/ufs.h ln -f ../second/ufs.h ufs.h -util: util.c - $(CC) $(CFLAGS) -o util util.c - $(HEADERS): $(MAKE) -C ../first first.h ultra.h fd.h @@ -51,4 +47,4 @@ silo.o: silo.c floppy.h $(UFSDEPS) $(CC) $(CFLAGS) -DVERSION='"$(VERSION)"' -DIMGVERSION='"$(IMGVERSION)"' -c silo.c clean: - rm -f *.o *~ silo floppy.h ufs.h util silocheck + $(RM) *.o *~ silo floppy.h ufs.h silocheck diff --git a/silo/util.c b/silo/util.c deleted file mode 100644 index 4240da2..0000000 --- a/silo/util.c +++ /dev/null @@ -1,47 +0,0 @@ -/* a simple utility to dump binary into a header file - - Copyright (C) 1996 Jakub Jelinek - - 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> - -int main (int argc, char **argv) -{ - FILE *f; - char buffer[512]; - int i, j; - - if (argc != 3) { - fprintf(stderr, "Usage: %s <array name> <file>\n", argv[0]); - exit (1); - } - - if ((f = fopen(argv[2], "r")) == NULL) { - perror("fopen"); - exit (1); - } - - fread (buffer, 1, sizeof(buffer), f); - fclose (f); - printf ("char %s[] = {\n", argv[1]); - for (i = 0; i < 32; i++) { - for (j = 0; j < 16; j++) - printf ("0x%02X, ", (unsigned char)buffer[16 * i + j]); - printf ("\n"); - } - printf ("};\n"); - exit (0); -} diff --git a/tilo/Makefile b/tilo/Makefile new file mode 100644 index 0000000..da92ad4 --- /dev/null +++ b/tilo/Makefile @@ -0,0 +1,63 @@ +## +## Trivial Linux Loader for SPARC +## +## + +include ../Rules.make + +CFLAGS = -O2 -Wall -fno-builtin -I../include #-DTILO_DEBUG + +# Relocate to 3.75MB +# Hopefully, 4MB are guaranteed to be mapped. +LDFLAGS_SMALL=-N -Ttext 0x3c0000 +# This is even more, but will be used only for extra large images. +LDFLAGS_LARGE=-N -Ttext 0x4c0000 + +PROGRAMS=maketilo + +all: $(PROGRAMS) + +.c.o: + $(CC) $(CFLAGS) -c $*.c + +.S.o: + $(CC) $(CFLAGS) -c $*.S + +OBJS = crt0.o tilo.o ../common/printf.o ../common/jmp.o ../common/prom.o ../common/console.o malloc.o ../common/stringops1.o ../common/urem.o ../common/stringops2.o ../common/tree.o ../common/udiv.o +OBJS2 = crt0l.o tilol.o ../common/printf.o ../common/jmp.o ../common/prom.o ../common/console.o mallocl.o ../common/stringops1.o ../common/urem.o ../common/stringops2.o ../common/tree.o ../common/udiv.o + +maketilo: maketilo.c b.h b2.h + $(CC) $(CFLAGS) maketilo.c -o maketilo + +b.h : b.out ../common/bin2h + ../common/bin2h -l BOOT_LEN boot_loader b.out > $@ || ($(RM) $@; exit 1) + +b2.h : b2.out ../common/bin2h + ../common/bin2h -l LARGE_BOOT_LEN large_boot_loader b2.out > $@ || ($(RM) $@; exit 1) + +b.out: $(OBJS) + $(LD) $(LDFLAGS_SMALL) -Bstatic -o boot $(OBJS) + $(ELFTOAOUT) boot -o b.out + +b2.out: $(OBJS2) + $(LD) $(LDFLAGS_LARGE) -Bstatic -o boot2 $(OBJS2) + $(ELFTOAOUT) boot2 -o b2.out + + +mallocl.o: ../common/malloc.c + $(CC) $(CFLAGS) -DMALLOC_BASE=0x4D0000 -c -o mallocl.o ../common/malloc.c + +malloc.o: ../common/malloc.c + $(CC) $(CFLAGS) -DMALLOC_BASE=0x3D0000 -c -o malloc.o ../common/malloc.c + +tilol.o: tilo.c + $(CC) $(CFLAGS) -DLARGETILO -c -o tilol.o tilo.c + +crt0.o: crt0.S + $(CC) $(CFLAGS) -c -Wa,-Av9 -o crt0.o crt0.S + +crt0l.o: crt0.S + $(CC) $(CFLAGS) -c -Wa,-Av9 -DLARGETILO -o crt0l.o crt0.S + +clean: + $(RM) *.o boot b.out boot2 b2.out b.h b2.h maketilo diff --git a/tilo/crt0.S b/tilo/crt0.S new file mode 100644 index 0000000..dcb31e9 --- /dev/null +++ b/tilo/crt0.S @@ -0,0 +1,143 @@ +/* Trivial lInux LOader bootstrap + + Copyright (C) 1996,1997 Jakub Jelinek + 1998 Jan Vondrak + + 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. */ + +#define COPY jmpl %o7 + (copy - _start), %l7 + +#ifndef LARGETILO +#define STACK_BASE 0x400000 +#else +#define STACK_BASE 0x500000 +#endif + + .text + .global _start, image_table + .align 16 +_start: + call 1f + mov %o7, %l0 + +image_table: + .skip 64 + + /* + struct { + int packed_start; + int packed_len; + int unpacked_len; + int root_start; + } + image_table[4]; + */ + +1: + /* Move ourselves up */ ! %l0 = original start + set __bss_start + 16, %i1 ! %i1 = original end + set _start, %l1 ! %i0 = %l1 = relocated start + mov %l1, %i0 ! %l2 = code length + COPY + sub %i1, %l1, %l2 + + /* Jump to relocated code */ + sethi %hi(_end), %l0 + jmpl %i0 + (jumphere - _start), %g0 + or %l0, %lo(_end), %l0 ! %l0 = _end +jumphere: + /* Clear BSS */ +5: andcc %i1, 4, %g0 + sub %l0, %i1, %i2 ! %i2 = BSS length + be 1f + mov %g0, %g1 + + st %g0, [%i1] + add %i1, 4, %i1 +1: + subcc %i2, 32, %i2 + std %g0, [%i1] + std %g0, [%i1 + 8] + std %g0, [%i1 + 16] + std %g0, [%i1 + 24] + bgu 1b + add %i1, 32, %i1 + + tst %o4 ! if not Ultra, + be 1f ! skip %pstate modification + nop + + rdpr %pstate, %l1 + or %l1, 8, %l1 + wrpr %l1, 0, %pstate +1: + + ! Set up a stack +setup_stack: + set STACK_BASE, %l1 + save %l1, -64, %sp + + ! Call tilo_main() to start the whole thingie up + + call flush_icache + mov %i6, %o2 ! Cif sp on sun4u + mov %i4, %o1 ! Cif handler on sun4u + call tilo_main + mov %i0, %o0 ! Prom vector or cifh on sun4m + call flush_icache + nop + jmpl %o0 + %g0, %g0 ! Jump to return address from tilo_main() + restore + +/* l0 from, l1 to, l2 len, l7 ret. Returns from + len in l0 */ +copy: + ld [%l0], %l3 + ld [%l0 + 4], %l4 + ld [%l0 + 8], %l5 + ld [%l0 + 12], %l6 + subcc %l2, 16, %l2 + add %l0, 16, %l0 + st %l3, [%l1] + st %l4, [%l1 + 4] + st %l5, [%l1 + 8] + st %l6, [%l1 + 12] + bgu copy + add %l1, 16, %l1 + + jmpl %l7 + 8, %g0 + nop + +flush_icache: + tst %i4 /* quit unless it's Sun4u */ + be 0f + nop + rdpr %ver, %l0 + sethi %hi(0x003e0014), %l1 + srlx %l0, 32, %l0 + or %l1, %lo(0x003e0014), %l1 + cmp %l0, %l1 + be 0f /* quit if it is Ultra-III */ + nop + clr %l0 + sethi %hi(16384), %l1 + stxa %g0, [%l0] 0x67 /* ASI_IC_TAG */ +1: + add %l0, 32, %l0 + cmp %l0, %l1 + blu,a,pt %xcc, 1b + stxa %g0, [%l0] 0x67 /* ASI_IC_TAG */ +0: + retl + nop diff --git a/tilo/maketilo.c b/tilo/maketilo.c new file mode 100644 index 0000000..8f4fbec --- /dev/null +++ b/tilo/maketilo.c @@ -0,0 +1,281 @@ + +/* + Jan Vondrak (C) 1998 + Jakub Jelinek (C) 1998 + + A simple program which appends the kernel and root images + to the boot loader and patches the addresses in its image_table[] + + Parameters: + kernel4=<filename> + kernel4c=<filename> + kernel4u=<filename> + ... compressed kernel images (in a.out format) + size4=<bytes> + size4c=<bytes> + size4u=<bytes> + ... original sizes of kernel images (uncompressed) + root4=<addr> + root4c=<addr> + root4u=<addr> + ... virtual address of root image for each kernel (in hex) + root=<filename> + ... compressed root image + out=<filename> + ... the output file +*/ + + +#include <stdio.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <string.h> +#include "b.h" +#include "b2.h" + +#define MAX_BOOT_LEN 0x400000 + +char output_buffer[MAX_BOOT_LEN]; + +struct ImageInfo { + unsigned packed_start; + unsigned packed_len; + unsigned unpacked_len; + unsigned root_start; +}; + +int root_tweak (char *s) +{ + unsigned p; + + p = strtoul (s, NULL, 16); /* read virtual address in hex */ + return p ? (p + 32 + 0x1fff) & ~0x1fff : 0; /* add 32 bytes and round to 8 KB */ +} + +int main (int argc, char **argv) +{ + int i,len,rootlen; + FILE *f, *g; + struct ImageInfo *ii; + + char *sun4_kernel_start; + char *sun4c_kernel_start; + char *sun4u_kernel_start; + char *root_image_start; + char *output_end; + + int sun4_size = 0, sun4_root = 0; + int sun4c_size = 0, sun4c_root = 0; + int sun4u_size = 0, sun4u_root = 0; + + char *sun4_kernel = 0; + char *sun4c_kernel = 0; + char *sun4u_kernel = 0; + char *root_image = 0; + char *output_file = 0; + + if (argc < 4) { + fprintf (stderr, "Usage: maketilo + sun4=<sun4 gzipped kernel> size4=<sun4 orig size> root4=<sun4 root address> + sun4c=<sun4c gzipped size> size4c=<sun4c orig size> root4c=<sun4c root address> + sun4u=<sun4u gzipped kernel> size4u=<sun4u orig size> root4u=<sun4u root address> + root=<root image> + out=<output file>\n"); + return -1; + } + + for (i=1;i<argc;i++) { + if (!strncmp (argv[i], "sun4=", 5)) + sun4_kernel = argv[i] + 5; + else if (!strncmp (argv[i], "sun4c=", 6)) + sun4c_kernel = argv[i] + 6; + else if (!strncmp (argv[i], "sun4u=", 6)) + sun4u_kernel = argv[i] + 6; + else if (!strncmp (argv[i], "size4=", 6)) + sun4_size = atoi (argv[i]+6); + else if (!strncmp (argv[i], "size4c=", 7)) + sun4c_size = atoi (argv[i]+7); + else if (!strncmp (argv[i], "size4u=", 7)) + sun4u_size = atoi (argv[i]+7); + else if (!strncmp (argv[i], "root4=", 6)) + sun4_root = root_tweak (argv[i]+6); + else if (!strncmp (argv[i], "root4c=", 7)) + sun4c_root = root_tweak (argv[i]+7); + else if (!strncmp (argv[i], "root4u=", 7)) + sun4u_root = root_tweak (argv[i]+7); + else if (!strncmp (argv[i], "root=", 5)) + root_image = argv[i] + 5; + else if (!strncmp (argv[i], "out=", 4)) + output_file = argv[i] + 4; + } + + if (!sun4_kernel) { + /*fprintf (stderr, "WARNING: Kernel for Sun4 not specified\n");*/ + } else if (!sun4_size || !sun4_root) { + fprintf (stderr, "WARNING: Original size and root address must be specified for Sun4\n"); + return -1; + } + + if (!sun4c_kernel) { + fprintf (stderr, "WARNING: Kernel for Sun4c/m/d not specified\n"); + } else if (!sun4c_size || !sun4c_root) { + fprintf (stderr, "ERROR: Original size and root address must be specified for Sun4c\n"); + return -1; + } + + if (!sun4u_kernel) { + fprintf (stderr, "WARNING: Kernel for Sun4u not specified\n"); + } else if (!sun4u_size || !sun4u_root) { + fprintf (stderr, "ERROR: Original size and root address must be specified for Sun4u\n"); + return -1; + } + + if (!root_image) { + fprintf (stderr, "ERROR: Root image not specified\n"); + return -1; + } + + if (!output_file) { + fprintf (stderr, "ERROR: Output file not specified\n"); + return -1; + } + + g = fopen (root_image, "rb"); + if (!g) { + fprintf (stderr, "Can't load %s\n", root_image); + return -1; + } + + fseek (g, 0, SEEK_END); + rootlen = ftell (g); + fseek (g, 0, SEEK_SET); + + if (rootlen + sun4_size + 0x4000 + 0x10000 >= 0x330000 || + rootlen + sun4c_size + 0x4000 + 0x10000 >= 0x330000 || + rootlen + sun4u_size + 0x4000 + 0x10000 >= 0x330000) { + printf("Images are large. Will load on machines with at least 5M mapped by PROM only\n"); + + for (i=0; i<LARGE_BOOT_LEN; i++) + output_buffer[i] = large_boot_loader[i]; + } else + for (i=0; i<BOOT_LEN; i++) + output_buffer[i] = boot_loader[i]; + + sun4_kernel_start = output_buffer + BOOT_LEN; + + if (sun4_kernel) { + f = fopen (sun4_kernel, "rb"); + if (!f) { + fprintf (stderr, "Can't load %s\n", sun4_kernel); + return -1; + } + + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + fread (sun4_kernel_start, 1, len, f); + fclose (f); + } else + len = 0; + + sun4c_kernel_start = sun4_kernel_start + len; + + if (sun4c_kernel) { + f = fopen (sun4c_kernel, "rb"); + if (!f) { + fprintf (stderr, "Can't load %s\n", sun4c_kernel); + return -1; + } + + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + fread (sun4c_kernel_start, 1, len, f); + fclose (f); + } else + len = 0; + + sun4u_kernel_start = sun4c_kernel_start + len; + + if (sun4u_kernel) { + f = fopen (sun4u_kernel, "rb"); + if (!f) { + fprintf (stderr, "Can't load %s\n", sun4u_kernel); + return -1; + } + + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + fread (sun4u_kernel_start, 1, len, f); + fclose (f); + } else + len = 0; + + root_image_start = sun4u_kernel_start + len; + + fread (root_image_start, 1, rootlen, g); + fclose (g); + + output_end = root_image_start + rootlen; + + /* patch code, data and BSS size in the .out header */ + *(unsigned*)(output_buffer+4) = output_end - output_buffer; + *(unsigned*)(output_buffer+8) = 0; + *(unsigned*)(output_buffer+12) = 0; + + /* fill image_table[] in the boot loader */ + ii = (struct ImageInfo*)(output_buffer + 40); + + if (sun4_kernel) { + ii[0].packed_start = sun4_kernel_start - output_buffer - 32; + ii[0].packed_len = sun4c_kernel_start - sun4_kernel_start; + ii[0].unpacked_len = sun4_size; + ii[0].root_start = sun4_root; + } else { + ii[0].packed_start = 0; + ii[0].packed_len = 0; + ii[0].unpacked_len = 0; + ii[0].root_start = 0; + } + + if (sun4c_kernel) { + ii[1].packed_start = sun4c_kernel_start - output_buffer - 32; + ii[1].packed_len = sun4u_kernel_start - sun4c_kernel_start; + ii[1].unpacked_len = sun4c_size; + ii[1].root_start = sun4c_root; + } else { + ii[1].packed_start = 0; + ii[1].packed_len = 0; + ii[1].unpacked_len = 0; + ii[1].root_start = 0; + } + + if (sun4u_kernel) { + ii[2].packed_start = sun4u_kernel_start - output_buffer - 32; + ii[2].packed_len = root_image_start - sun4u_kernel_start; + ii[2].unpacked_len = sun4u_size; + ii[2].root_start = sun4u_root; + } else { + ii[2].packed_start = 0; + ii[2].packed_len = 0; + ii[2].unpacked_len = 0; + ii[2].root_start = 0; + } + + ii[3].packed_start = root_image_start - output_buffer - 32; + ii[3].packed_len = output_end - root_image_start; + ii[3].unpacked_len = 0; + ii[3].root_start = 0; + + f = fopen (output_file, "wb"); + if (!f) { + fprintf (stderr, "Can't open %s for writing\n", output_file); + return -1; + } + + fwrite (output_buffer, 1, output_end - output_buffer, f); + fclose (f); + + return 0; +} diff --git a/tilo/tilo.c b/tilo/tilo.c new file mode 100644 index 0000000..fb03ecc --- /dev/null +++ b/tilo/tilo.c @@ -0,0 +1,264 @@ +/* TILO: The TFTP Image LOader + + Copyright (C) 1996 Jakub Jelinek + 1998 Jan Vondrak + + 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 <silo.h> +#include <setjmp.h> +#ifndef NULL +#define NULL (void *)0 +#endif + +#ifndef LARGETILO +#define MOVED_BASE 0x3c0000 +#else +#define MOVED_BASE 0x4c0000 +#endif + +/* + * gzip declarations + */ + +#define OF(args) args +#define STATIC static + +#define memzero(s, n) memset ((s), 0, (n)) + +typedef unsigned char uch; +typedef unsigned short ush; +typedef unsigned long ulg; + +#define WSIZE 0x8000 /* Window size must be at least 32k, */ + /* and a power of two */ +static uch window[WSIZE]; /* Sliding window buffer */ + +static unsigned outcnt = 0; /* bytes in output buffer */ + +/* gzip flag byte */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ +#define RESERVED 0xC0 /* bit 6,7: reserved */ + +#define Assert(cond,msg) +#define Trace(x) +#define Tracev(x) +#define Tracevv(x) +#define Tracec(c,x) +#define Tracecv(c,x) + +static void flush_window (void); +static void error (char *); +#define gzip_mark mark +inline void gzip_release (void **p) +{ + release (*p); +} + +static long bytes_out; +static uch *output_data, *output_limit; +static unsigned char (*get_input_fun) (void); +static void (*unget_input_fun) (void); + +jmp_buf gunzip_env; +#define get_byte() (*get_input_fun)() +#define unget_byte() (*unget_input_fun)() + +#include "../common/inflate.c" + +static void error (char *m) +{ + printf ("\nDecompression error: %s\n", m); + longjmp (gunzip_env, 1); +} + +static void flush_window () +{ + ulg c = crc; + unsigned n; + uch *in, ch; + in = window; + if (output_data + outcnt > output_limit) + error ("uncompressed image too long - wouldn't fit into destination"); + for (n = 0; n < outcnt; n++) { + ch = *output_data++ = *in++; + c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8); + } + crc = c; + bytes_out += (ulg) outcnt; + outcnt = 0; +} + +int decompress (char *outptr, char *outptrlim, unsigned char (*get_input) (void), void (*unget_input) (void)) +{ + void *save_ptr; + static int first = 1; + + gzip_mark (&save_ptr); + + if (setjmp (gunzip_env)) { + gzip_release (&save_ptr); + return -1; + } + output_data = outptr; + output_limit = outptrlim; + get_input_fun = get_input; + unget_input_fun = unget_input; + bytes_out = 0; + crc = 0xffffffffL; + if (first) { + makecrc (); + first = 0; + } + gunzip (); + gzip_release (&save_ptr); +#ifdef TILO_DEBUG + printf("Returning from decompress()\n"); +#endif + return bytes_out; +} + +static unsigned char *gzminp; +static unsigned char get_input(void) +{ + return *gzminp++; +} + +static void unget_input(void) +{ + gzminp--; +} + +extern char start, main_text_start, main_text_end, main_data_start, main_data_end, main_rodata_start, main_rodata_end, __bss_start; + +struct ImageInfo +{ +unsigned packed_start; +unsigned packed_len; +unsigned unpacked_len; /* this is meaningful for the kernel images only */ +unsigned root_start; /* this is meaningful for the kernel images only */ +}; + +extern struct ImageInfo image_table[4]; /* Sun4 kernel, Sun4c/d/m kernel, Sun4u kernel, root image */ + +#define SUN4_KERNEL 0 +#define SUN4C_KERNEL 1 +#define SUN4U_KERNEL 2 +#define ROOT_IMAGE 3 + +#define HDRS_TAG (('H'<<24) | ('d'<<16) | ('r'<<8) | 'S') + +char *tilo_main (struct linux_romvec *promvec, void *cifh, void *cifs) +{ +char *orig_code,*moved_code,*moved_ramdisk,*moved_kernel,*kernel_base; +unsigned *p,*q = NULL; +int kernel_number; + + prom_init(promvec, cifh, cifs); + + printf ("TILO\n"); + + if (cifh) + { + kernel_number = SUN4U_KERNEL; /* Sun4u */ + printf("Selecting sun4u kernel...\n"); + } + else if ((long)promvec == 0x4000) + { + kernel_number = SUN4_KERNEL; /* Sun4 */ + printf("Selecting sun4 kernel...\n"); + } + else + { + kernel_number = SUN4C_KERNEL; /* Sun4c/d/m */ + printf("Selecting sun4cdm kernel...\n"); + } + + if (image_table[kernel_number].packed_len == 0) + { + printf ("ERROR: No kernel for this architecture in this TILO image\n"); + prom_halt (); + } + + orig_code = (char*) 0x4000; + moved_code = (char*) MOVED_BASE; + moved_ramdisk = (char*)((long)(moved_code - image_table[ROOT_IMAGE].packed_len) & ~0xfff); + moved_kernel = (char*)((long)(moved_ramdisk - image_table[kernel_number].packed_len) & ~0xfff); +#ifdef TILO_DEBUG + printf("Locations: moved_code=%x moved_ramdisk=%x moved_kernel=%x\n", + moved_code, moved_ramdisk, moved_kernel); +#endif + memmove (moved_ramdisk, orig_code + image_table[ROOT_IMAGE].packed_start, image_table[ROOT_IMAGE].packed_len); + memmove (moved_kernel, orig_code + image_table[kernel_number].packed_start, image_table[kernel_number].packed_len); + + gzminp = (char*) moved_kernel; /* decompress kernel */ + kernel_base = (char*) 0x4000; + + if (decompress (kernel_base, kernel_base + ((image_table[kernel_number].unpacked_len + + 0xfff) & ~0xfff), get_input, unget_input) == -1) + { + printf ("\nKernel decompression error\n"); + prom_halt(); + } + + switch (kernel_number) + { + case SUN4U_KERNEL: + /* find HdrS in Sun4u kernel */ + q = (unsigned*)kernel_base + 2; + break; + + case SUN4C_KERNEL: + /* find HdrS in Sun4c/m/d kernel */ + p = (unsigned*)kernel_base; + p += *p & 0xffff; /* extract jump offset */ + q = p - 16; /* from the branch instruction */ + + while (q < p && *q != HDRS_TAG) + q++; + break; + + default: + /* find HdrS in Sun4 kernel */ + printf ("Sun4 kernel not supported yet\n"); + prom_halt (); + break; + + } + + if (*q != HDRS_TAG) + { + printf ("Can't find HdrS tag in kernel\n"); + prom_halt (); + } + + q[2] &= 0xffff0000; /* reset root flags */ + q[3] = 0x01000000; /* set root device and flags */ + q[4] = image_table[kernel_number].root_start; + q[5] = image_table[ROOT_IMAGE].packed_len; + + /* move root image */ + memmove ((void*)(image_table[kernel_number].root_start & 0x3fffff), + moved_ramdisk, image_table[ROOT_IMAGE].packed_len); +#ifdef TILO_DEBUG + printf("Returning from tilo_main() with address %x\n", kernel_base); +#endif + return kernel_base; /* return address to jump into kernel */ +} diff --git a/tilo/tilo.sh b/tilo/tilo.sh new file mode 100755 index 0000000..ff60063 --- /dev/null +++ b/tilo/tilo.sh @@ -0,0 +1,120 @@ +#!/bin/sh +# TILO - Trivial Image LOader +# +# by Jan Vondrak (C) 1998 +# +# This is just a simple wrapper for maketilo... + +usage () { + echo "Usage: tilo [ -o output ] <kernel images> <root image>" +} + +set -e + +sun4u= +sun4c= +rootimg= +tilo_args= +output= +to_remove= + +trap "rm -f $to_remove" 0 1 2 3 7 10 13 15 + +do_image () { + [ $# = 1 -a -n "$1" ] || exit + KERNEL=$1 + tag= + sun4u_init=`nm $KERNEL | awk '/t sun4u_init$/{print$1}'` + [ "$?" = 0 ] || exit 2 + if [ -n "$sun4u_init" ]; then + if [ -n "$sun4u" ]; then + echo "Multiple sun4u kernels" + exit 1 + fi + sun4u=$KERNEL + tag=sun4u + else + if [ -n "$sun4c" ]; then + echo "Multiple sun4cdm kernels" + exit 1 + fi + sun4c=$KERNEL + tag=sun4cdm + fi + echo "Converting $KERNEL ($tag) to a.out:" + elftoaout $KERNEL -o $KERNEL.out + tail --bytes +33 $KERNEL.out > $KERNEL.raw + rm $KERNEL.out + echo Compressing $KERNEL.raw: + gzip -c9v $KERNEL.raw > $KERNEL.gz + to_remove="$to_remove $KERNEL.gz" + PSIZE=`ls -l $KERNEL.gz | awk '{print$5}'` + SIZE=`ls -l $KERNEL.raw | awk '{print$5}'` + ROOTA=`nm $KERNEL | awk '/A _end$/{print$1}'` + rm $KERNEL.raw + echo "Sizes ($tag):" + echo " raw size = $SIZE" + echo " packed size = $PSIZE" + echo " root address = $ROOTA" + if [ -n "$sun4u" ]; then + tilo_args="$tilo_args sun4u=$KERNEL.gz size4u=$SIZE root4u=$ROOTA" + else + tilo_args="$tilo_args sun4c=$KERNEL.gz size4c=$SIZE root4c=$ROOTA" + fi +} + +do_root () { + [ $# = 1 -a -n "$1" ] || exit + if [ -n "$rootimg" ]; then + echo "Multiple root images?" + exit 1 + fi + rootimg=$1 + if file $rootimg | grep -q "gzip compressed data"; then + : # Nothing + else + echo Compressing $rootimg: + gzip -c9v $rootimg > $rootimg.gz + to_remove="$to_remove $rootimg.gz" + rootimg=$rootimg.gz + fi + ROOT_SIZE=`ls -l $rootimg | awk '{print$5}'` + echo Root image packed size = $ROOT_SIZE + tilo_args="$tilo_args root=$rootimg" +} + +while [ $# != 0 ]; do + case "$1" in + -h) usage; exit ;; + -o) shift; output="$1" ;; + -*) echo $"$0: Unrecognised option: $1" >&2 + usage >&2; exit 1 ;; + *) + if [ ! -f "$1" ]; then + echo "$1 does not exist" + exit 1 + fi + if file $1 | grep -q "MSB executable"; then + do_image $1 || exit 1 + else + # Suspect it is a root.bin + do_root $1 || exit 1 + fi + ;; + esac + shift +done + +test -z "$output" && output=tftpboot.img + +if [ -z "$sun4u" -a -z "$sun4c" ]; then + echo "No images provided" + exit 1 +fi + +`echo $0 | sed 's/tilo$/maketilo/'` $tilo_args out=$output + +rm -f $to_remove + +TILO_SIZE=`ls -l $output | awk '{print$5}'` +echo TILO size = $TILO_SIZE |