From: zippel@fh-brandenburg.de (Roman Zippel)
Subject: Re: L68K: ataboot-3.0 sources
To: rnhodek@faui22c.informatik.uni-erlangen.de (Roman Hodek)
Date: Mon, 10 Nov 1997 15:37:38 +0100 (MET)
In-Reply-To: <9711101418.AA06695@faui21.informatik.uni-erlangen.de> from "Roman Hodek" at Nov 10, 97 02:19:26 pm

Hi,

> I remember that I posted ataboot-3.0 as a tar.gz to this list (i.e.,
> no diff, complete arch/m68k/boot/atari). But it isn't in my patch
> archive or some other places where I keep stuff like that... It must
> have been around where 2.1.42 or 2.1.47 were current when I posted it.

Here it is. :)
BTW existiert bereits eine verdachtsweise stabile Version des m68k-boot-
loader. Ich hatte in letzter Zeit keine Zeit daran irgendetwas zu tun.

Roman

Message-Id: <9707070843.AA11381@faui21.informatik.uni-erlangen.de>
Date: Mon, 7 Jul 1997 10:43:12 +0200
From: Roman Hodek <rnhodek@faui22c.informatik.uni-erlangen.de>
Subject: L68K: Atari bootstrap 3.0


Jes asked us to hold back patches until he's back from his holiday, so
today his mailbox will be bombed... Ok, let's start :-)

This is version 3.0 of the Atari bootstrap. There aren't too many
user-visible changes, and those are rather minor. But internally
things have been totally rearranged...

The sources are meant for 2.1.42 and consist of two parts. First is a
little patch to arch/m68k/boot/Makefile and lib/inflate.c (I had to
make a little change there). It also adds a file
Documentation/m68k/ataboot.txt with a description of the bootstrap
options. Then follows a .tar.gz with a new version of the directory
arch/m68k/boot/atari. Please remove all old files from that directory
before unpacking. There would have been not much sense in building a
diff for the files in that dir, too much changed.

User-visible changes:

 - Dropped support for a.out kernels in the default configuration.
   a.out functionality is still present, but must be enabled with
   -DAOUT_KERNEL at compile time. Does anyone have an a.out kernel
   anymore??

 - Output made somewhat more systematic.

 - Option -b ("not prefer BOOTP") has been changed to -n ("no BOOTP"),
   which is more intuitive. Only available if compiled with
   USE_BOOTP=yes. Otherwise simply ignored (Formerly is was an error
   to use -b with a non-BOOTP bootstrap.)

 - New options -S and -T can be used to force sizes of ST-RAM or
   TT-RAM, resp. (Ok, -S isn't really new, the idea is by Juergen
   Orschiedt, but his patch has been lost somewhere...) The argument
   to each is a number, optionally with 'k' or 'm' for kByte or MByte
   appended. If one of these options is used, the autodetect size of
   the respective memory is ignored and overriden by the given value.
   Only useful application seems ignoring ST-RAM as far as possible if
   you have lots of TT-RAM, for speed reasons. But the mechanism is
   easy, so why not implement it? :-) Ok, can always be useful for
   debugging... :-)

 - A new option -m start:size can be used to tell Linux about some
   other alternate RAM that can't be autodetected (e.g. an unsupported
   memory board, or something like VME memory). Both numbers can be
   hex with 0x prefix, and size can be postfixed with 'k' or 'm' as
   above.

 - Ramdisk can now also be retrieved from a BOOTP server.

 - If compiled with BOOTP support, a prefix "local:" to a filename
   (kernel or ramdisk) forces disk access for this file (i.e., no
   BOOTP). Can be used to load kernel and ramdisk from different
   sources, whereas -n forces both files to be fetched from disk.

 - If there is enough space left on the kernel command line, bootstrap
   passes the string "BOOT_IMAGE=<kernelname>" to the kernel, just
   like PC LILO does. This argument ends up in init's environment, so
   rc scripts can use it.

 - Fixed a bug in TFTP code that rejected empty data packets. These
   aren't invalid, they signal EOF (if data amount is a multiple of
   512). [1]

Internal changes:

 - In the old bootstrap, the main function became bigger and bigger
   over the time... Finally bootstrap.c was one big chunk of main()
   being 90% of the file :-) So I've moved some functionality into
   subfunctions.

 - I've separated the parts that depend on being a TOS program from
   the actual code to boot Linux (like the Amiga bootstrap already
   does). The former are bootstrap.[ch], the latter the rest of files,
   but mainly linuxboot.[ch]. The intention is that all files except
   bootstrap.[ch] can be reused by the (to-be-written) Atari LILO.

 - The most dramatic change is how the kernel image and ramdisk image
   are read. In the far past, this was just reading a file. But later
   came other features: BOOTP/TFTP, and gunzipping the kernel. These
   extensions were attached by defining macros kopen, kread, ... that
   were defined according to the options present. This was ok with one
   such additional layer (BOOTP), but became rather clumsy with two of
   them. Another drawback of the old solution was extensive buffering:
   A lower layer first read all the data, buffered it, and then the
   read() function copied from that buffer into another buffer... In
   the most complex case (BOOTP+gunzip), all data were copied 4 times,
   not counting the many malloc() calls, which need time, too...

   To overcome all these problems and make room for future
   enhancements, I implemented a scheme I call "streams", conceptually
   similar to streams in SysV. You have a stack of modules that either
   produce data (file, BOOTP) or make modifications to data produced
   by lower modules (gunzip). A general stream code manages all the
   buffering and transforms higher level calls (read(), with arbitrary
   size) to a lower level fillbuf() (with fixed max. size of buffer).
   This makes implementation of the single modules easier and avoids
   writing the buffering code multiple times. Unnecessary buffering is
   avoided, too, by letting fillbuf() write to the user buffer if
   possible. If buffer sizes are not counter-productively choosen,
   this avoids memcpy()-ing data at all in the normal case.

   The module implementation of file_mod and bootp_mod is rather
   straightforward, but for gunzip_mod, kind of a hack was necessary.
   The template gunzip code in lib/inflate.c assumes that you call
   gunzip() and write away produced data in flush_window() until the
   end of data is reached. This doesn't fit the data-on-demand
   approach I needed for the streams. My solution for gunzip was to
   let it run on a separate stack, with flush_window() returning to
   the main stack if one output block is available. On the next
   request for data, the stack is changed back and from gunzip's view,
   flush_window() simply returns. Sounds like a co-routine, and really
   is very similar... Take a look at it :-) Another problem with
   gunzip was that the algorithm expects the window to be kind of a
   ring buffer, i.e. it also reads data that were already flushed, but
   not yet overwritten. This works fine with the old scheme (copy data
   out of window to some buffer), but not with the streams, where
   output data are written straight away into the user buffer. (I.e.,
   the window buffer is in a different location on every run.) But
   this was easily solvable by a little patch to inflate.c. If it
   wants to access data beyond the current window pointer, I redirect
   the access to use 'last_window' instead of 'window'. This assumes
   that read data aren't overwritten in the meantime, but this is
   currently given.

   To the extensibility of the streams model: It may seen too general,
   because currently we have only these three modules. But for Atari
   LILO, I can now easily write a (producing) module that reads the
   file from certain disk sectos, directed by a map file. With the old
   scheme, attaching such a 4th way to read a file would have become
   very complex...

Roman


Footnotes:

 [1] I've surely compiled more than 500 kernel since I use BOOTP/TFTP,
but never experienced this bug... but finally Geert's page-padded
ramdisk revealed it. That's probability :-)

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file /home/rnhodek/src/linux-2.1.42-orig/Documentation/m68k/00-INDEX linux-2.1.42/Documentation/m68k/00-INDEX
--- /home/rnhodek/src/linux-2.1.42-orig/Documentation/m68k/00-INDEX	Wed Jan 15 01:11:40 1997
+++ linux-2.1.42/Documentation/m68k/00-INDEX	Sun Jul  6 10:58:15 1997
@@ -2,6 +2,8 @@
 	- this file
 amiboot.txt
 	- info and options for the Linux/m68k Amiga bootstrap (Amiboot)
+ataboot.txt
+	- info and options for the Linux/m68k Atari bootstrap (ataboot)
 framebuffer.txt
 	- info about the Linux/m68k frame buffer device
 kernel-options.txt
diff -u --recursive --exclude-from=diff-excludes --new-file /home/rnhodek/src/linux-2.1.42-orig/Documentation/m68k/ataboot.txt linux-2.1.42/Documentation/m68k/ataboot.txt
--- /home/rnhodek/src/linux-2.1.42-orig/Documentation/m68k/ataboot.txt	Thu Jan  1 01:00:00 1970
+++ linux-2.1.42/Documentation/m68k/ataboot.txt	Sun Jul  6 20:03:34 1997
@@ -0,0 +1,221 @@
+
+				Linux/68k Atari Bootstrap version 3.0
+				-------------------------------------
+
+Date: Jul 6, 1997
+Linux/68k version: 2.1.42
+Author: Roman.Hodek@informatik.uni-erlangen.de (Roman Hodek)
+
+
+1) Introduction
+===============
+
+This document describes the options available for the Atari bootstrap
+(``ataboot''). This bootstrap program (program name BOOTSTRA.TTP or
+ATABOOT.TTP, depending on your taste :-) is used to boot the Linux/68k
+kernel from TOS. It can be started either from the desktop, by simply
+double-clicking on it, or from a shell. If you start it in the
+desktop, you'll be prompted for a command line. You can then either
+enter some options (unfortunately, the space is rather limited...), or
+rely on the default arguments feature described in section 3.
+
+ataboot in many versions is available on
+
+  ftp.uni-erlangen.de:/pub/Linux/680x0/vx.y/boot
+
+where vx.y is a kernel version (with the patchlevel omitted). There
+are usually two version, one with BOOTP and one without (see section 5
+on how to include BOOTP support if compiling yourself).
+
+FAQ 1: Where is the source for ataboot?
+A: You already have it if you have this document. The bootstrap
+sources are included in the kernel source tree, in directory
+arch/m68k/boot/atari.
+
+FAQ 2: How can I compile my own bootstrap?
+A: Unfortunately, that's not too easy :-( ataboot is a TOS program
+(obviously), so it must be compiled with a TOS compiler. On the other
+hand, it needs several files from include/{linux,asm}, so it needs the
+kernel source tree. And that isn't easy to unpack under TOS, because
+of its size and long file names. The best solution seems to be using a
+cross compiler, i.e. a compiler that runs under Linux but produces TOS
+programs. Such cross compilers (running under m68k-linux or
+i486-linux) are available at ftp.uni-erlangen.de, under
+/pub/Linux/680x0/tools.
+
+
+2) Options
+==========
+
+ataboot itself knows several options that modify its behaviour. These
+are:
+
+ -?
+   Display help information
+
+ -d
+   Enable debugging. This will print some additional data before
+   lauching the kernel, and will also wait for a key being pressed.
+
+ -k <kernel-name>
+   Sets the name of the kernel image to boot. Default is "vmlinux".
+   The name is first tried with ".gz" appended, to find a compressed
+   kernel. If such a file isn't found, the plain name is tried.
+
+   Specials if is supported: If the name is exactly "vmlinux", the
+   name sent to the BOOTP server is "" (empty string), which means use
+   the default kernel. A prefix "local:" before the name means to skip
+   BOOTP, and load a local disk file (name with prefix stripped).
+
+ -r <ramdisk-name>
+   Gives the name of a ramdisk image to pass to the kernel. Default is
+   not to use any ramdisk. You probably will also need the argument
+   "root=/dev/ram" to let the kernel recognize the ramdisk as its boot
+   device.
+
+   With BOOTP, a "local:" prefix is supported as above.
+
+ -s ("to ST-RAM")
+   Load kernel into ST-RAM, even if there is TT-RAM (which would be
+   preferred normally).
+
+   Note that -s is ignored on a Medusa, the kernel is always loaded to
+   ST-RAM there (it's the same kind of memory, no speed difference).
+
+ -t ("ignore TT-RAM")
+   Ignore any TT-RAM found, tell kernel only about ST-RAM. (Mainly for
+   testing purposes, or if you have problems under Linux with your
+   TT-RAM).
+
+ -S <size> ("force ST-RAM size")
+   Pretend that the ST-RAM has size <size>. <size> is a number in
+   decimal, a "0" prefix means octal, and "0x" hexadecimal. You can
+   append either "k" or "m" (case-insensitive) to denote kBytes or
+   MBytes, resp.
+
+   Making ST-RAM smaller than it really is can make sense if you have
+   lots of TT-RAM (min. 16 MB, better > 32 MB). Then using too much
+   ST-RAM would only slow down the machine. But remind that some
+   amount of ST-RAM is always needed for DMA buffer (video, floppy,
+   ...). ataboot knows this, and if <size> should be smaller than
+   256k, it announces 256k of ST-RAM nevertheless.
+
+   If <size> is bigger than the physical amount of ST-RAM you have,
+   the kernel will crash...
+
+ -T <size> ("force TT-RAM size")
+   Is the same as -S for TT-RAM, just no forcing of at least 256k is
+   done. As above, the kernel will probably crash is <size> is greater
+   than how much TT-RAM you really have.
+
+ -m <addr>:<size> ("memory block")
+   Tell the kernel about an additional memory block that isn't ST-RAM
+   or TT-RAM, or isn't autodetected (could happen for some Falcon
+   memory boards that aren't explictly supported. Magnum and BlowUp FX
+   are.) If the memory you announce isn't really present, a bad crash
+   will happen.
+
+   <addr> is the (physical) start address of the memory block, as
+   above "0" means octal notation, and "0x" hexadecimal. <size> can be
+   as above, i.e. with a "k" or "m" postfix.
+
+ -n ("no BOOTP")
+   If ataboot supports BOOTP, you can turn off its use with this
+   option. ataboot will search for local disk files for kernel and
+   ramdisk. (Usually a remote image has preference.)
+
+After these option understood by bootp, you can append further options
+that are passed to the kernel. See the file kernel-options.txt in this
+directory for a description of these. Just note: Kernel options *must
+follow* the bootstrap options, mixing both is not possible!
+
+
+3) Default Arguments (bootargs)
+===============================
+
+You'll see that most of the time, you'll be using ever the same
+arguments to bootstrap (kernel name, root device, maybe a video=
+option.) Since all these together can get quite long, there's an
+abbreviation to save typing. You can put a set of default options into
+a file "bootargs" in the same directory where the ataboot program is.
+
+In this file you can write down your default options just as you would
+have typed them on the command line. Just one exception: You can use
+newlines as separators, to make the file more readable (no over-long
+lines necessary). Newlines count simply as whitespace.
+
+The "bootargs" file is used whenever there are no options given to
+ataboot. (Really no options, not even a "-d" or the like...) E.g., if
+you just press RETURN in the desktop's dialog that lets you enter a
+command line.
+
+
+4) Bootinfo Version
+===================
+
+ataboot needs to pass some information to the kernel (machine type,
+memory configuration, command line, ...). These informations are
+stored in a structure called "boot info". Now different versions of
+kernels can need/use different infos from this bootinfo. In the past,
+we often had problems because ataboot's and the kernels view of the
+bootinfo strcuture were different. To fix this, a version number for
+the bootinfo has been introduced. The initial version used since
+around 1.2.13 was 1.0. (Seems we've added this versioning at a time
+where no more dramatic changes were needed... :-)
+
+Starting with 2.1 kernels, the bootinfo's internal structure has been
+changed totally, with the main advantage that no more incompabilities
+between the bootstrapper and the kernel are possible anymore. This
+format has been given version 2.0, and it probably is the highest
+version ever given to a bootinfo. (As stated, the new format should be
+general enough to avoid any mismatches.)
+
+Why I'm telling you all this? Well, 2.0 kernels still use bootinfo
+1.0, whereas 2.1 kernels use 2.0 bootinfo. So you basically can't boot
+a 2.0 kernel with a bootstrap from a 2.1 source, and vice versa. But
+all new bootstraps (in 2.1.x kernel sources) have a compability mode
+that allows to also boot a kernel with 1.0 bootinfo (i.e., 2.0.x, or
+even older). If you really want, you can omit that compat mode, by
+undefining BOOTINFO_COMPAT_1_0 (see next section).
+
+If there should be any unexpected problems with bootinfo versions,
+ataboot should tell you about it. The above should give you an idea
+what's going on. For the rest, ask an guru...
+
+
+5) Compile Time Options
+=======================
+
+ataboot has --in addition to the command line options described
+above-- also some compile time options. These are selected in
+arch/m68k/boot/Makefile (variable ATARI_BOOTOPTS), or on make's
+command line, e.g. like this:
+
+  make bootstrap ATARI_BOOTOPTS='-DBOOTINFO_COMPAT_1_0 -DAOUT_KERNEL'
+
+The options currently available are:
+
+ - BOOTINFO_COMPAT_1_0:
+   Support bootinfo version 1.0, in addition to current 2.0. This is
+   necessary to be able to boot 2.0.x kernels with a 3.0 ataboot.
+
+ - AOUT_KERNEL:
+   Support kernels in a.out executable format. By now, such kernels
+   should have become rather seldom, and can't even be built anymore
+   since 2.1.x. It's unprobable that you need it...
+
+ - USE_BOOTP:
+   Include support for the BOOTP and TFTP protocols, to read the
+   kernel (and ramdisk) image from a boot server (instead from disk).
+   This comes *very* handy if you use another machine to cross-compile
+   Linux/68k kernels :-) If USE_BOOTP is defined, also some Ethernet
+   low-level drivers should be selected by defining ETHLL_* macros.
+   The only such driver is current ETHLL_LANCE, for Lance-based boards
+   (RieblCard, PAM VME).
+
+The default configuration is -DBOOTINFO_COMPAT_1_0 only, others are
+off. Support for BOOTP/TFTP can be selected by adding "USE_BOOTP=yes"
+on the make command line:
+
+  make bootstrap USE_BOOTP=yes
+
diff -u --recursive --exclude-from=diff-excludes --new-file /home/rnhodek/src/linux-2.1.42-orig/arch/m68k/boot/Makefile linux-2.1.42/arch/m68k/boot/Makefile
--- /home/rnhodek/src/linux-2.1.42-orig/arch/m68k/boot/Makefile	Wed Feb 12 16:50:25 1997
+++ linux-2.1.42/arch/m68k/boot/Makefile	Fri Jul  4 00:17:09 1997
@@ -15,16 +15,27 @@
 
 ifdef CONFIG_ATARI
 ATARI_BOOTSTRAP = atari_bootstrap
-ATARI_BOOTOBJS := atari/bootstrap.o
+# possible options:
+#   AOUT_KERNEL:
+#     Include support for a.out kernels (may go away in future!)
+#   BOOTINFO_COMPAT_1_0:
+#     Include support for booting kernel with bootinfo version 1.0 (up
+#     to 2.0.x)
+#   USE_BOOTP:
+#     Include support for retrieving the kernel image via BOOTP/TFTP
+ATARI_BOOTOPTS  = -DBOOTINFO_COMPAT_1_0 # -DAOUT_KERNEL
+ATARI_BOOTOBJS := atari/bootstrap.o atari/linuxboot.o \
+                  atari/stream.o atari/file_mod.o atari/gunzip_mod.o 
 ATARI_HOSTCC = m68k-mint-gcc
 ATARI_HOSTINC = -I$(TOPDIR)/include
-ATARI_HOSTFLAGS = -m68030 -m68881 -Dlinux -O2 -Wall
+ATARI_HOSTFLAGS = -m68030 -m68881 -Dlinux -O2 -fomit-frame-pointer \
+                  -Wall $(ATARI_BOOTOPTS)
 
 # BOOTP/TFTP support in bootstrap?
 # USE_BOOTP = y
 
 ifdef USE_BOOTP
-ATARI_BOOTOBJS += atari/bootp.o
+ATARI_BOOTOBJS += atari/bootp_mod.o
 ATARI_HOSTFLAGS += -DUSE_BOOTP
 
 # low-level Ethernet drivers:
@@ -61,5 +72,15 @@
 clean:
 	rm -f *.o amiga/*.o atari/*.o amiga_bootstrap atari_bootstrap \
           ../../../bootstrap
+
+atari/bootstrap.o: atari/bootstrap.c atari/bootstrap.h atari/linuxboot.h
+atari/linuxboot.o: atari/linuxboot.c atari/bootstrap.h atari/linuxboot.h \
+                   atari/stream.h atari/inline-funcs.h
+atari/stream.o: atari/stream.c atari/stream.h
+atari/file_mod.o: atari/file_mod.c atari/stream.h
+atari/gunzip_mod.o: atari/gunzip_mod.c atari/bootp.h atari/stream.h \
+                    ../../../lib/inflate.c
+atari/bootp_mod.o: atari/bootp_mod.c atari/bootp.h atari/stream.h
+atari/ethlance.o: atari/ethlance.c atari/bootp.h atari/ethlance.h
 
 dep:
--- /home/rnhodek/src/linux-2.1.42-orig/lib/inflate.c	Sat Aug 24 14:50:25 1996
+++ linux-2.1.42/lib/inflate.c	Thu Jul  3 23:49:09 1997
@@ -582,7 +582,12 @@
 #if !defined(NOMEMCPY) && !defined(DEBUG)
         if (w - d >= e)         /* (this test assumes unsigned comparison) */
         {
+#ifdef CHANGING_WINDOW
+		  long adjust = (d > w) ? previous_window - slide : 0;
+          memcpy(slide + w, slide + d + adjust, e);
+#else
           memcpy(slide + w, slide + d, e);
+#endif
           w += e;
           d += e;
         }
------------------------------------------------------------------------------
[tar file here is in roman-ataboot-3.0.tar.gz]
