Subject: Re: Boot sequence
To: Andy <andy@softbook.com>
From: Bill Studenmund <wrstuden@nas.nasa.gov>
List: port-macppc
Date: 10/29/1999 16:42:42
FAQ folks, this could be the start of an entry! :-)

On Fri, 29 Oct 1999, Andy wrote:

> Sorry for lame questions in advance..
> I'm trying to understand the boot process but am a bit lost in the maze of
> files in the sys directory. What is the exact sequence?

I'll answer both what happens now and what will happen in the future.

> Basically I'd like to know what  gets invoked , in what order and where the
> code is located in the source tree

The idea is to get ofwboot running. It in turn loads the kernel.

The way we've done this in the past, which works for OF 1.0.5 and for
2.0.X, is to have OF load the bootxx program, which loads ofwboot. For
OF 2.4 and 3.X, we need to just throw ofwboot on a filesystem somewhere.

> In particular:
> When you say in OF:  boot /blah/sd0:0 -what exactly happens?

OF looks on the disk. Since you didn't give a filename and since the disk
doesn't contain an FS it understands, it looks in the MacOS partition
table and finds a driver which contains bootxx, and loads that.

bootxx is REALLY simple. It has a table of block numbers, and a address to
which to load them. It allocates the memory for ofwboot, and has OF load
it. Note that bootxx loads filesystem block-sized blocks, not media block. 
Typically that's 8k, but it's 4k on install floppies. It can load 30 such
blocks, so it's file as long as ofwboot is less than 60k.

ofwboot now comes in two versions, ofwboot and ofwboot.elf. The former is
a memory image which gets loaded at a specific memory address and then
executed. ofwboot.elf is an elf file, the same format as all the other
executables in NetBSD/macppc. I'm working on adding a third, xcoff, which
is the format versions 1 & 2 of OF understand. At that point, we can just
throw ofwboot.xcf or ofwboot.elf on a filesystem and let OF load it
directly.

> Who looks at the NetBSD partition map and figures out where the boot code
> lives ? OF ?

Your question is poorly posed. Nothing looks at the NetBSD partition map
and figures out where the boot code lives. :-) OF will look in the MacOS
partition map either to find the partition with bootxx in it, or for a
partition with an hfs filesystem on it where it will find ofwboot.elf or
ofwboot.xcf.

Exactly what ofwboot does with partition info is unclear to me at the
moment. :-)

ofwboot will then mount the root filesystem (either cd9660 or ffs for
disks and nfs for netbooting) and load the netbsd file on there. You can
also have it load files with other names, so you can test new kernels.

> I understand that there's gotta be some booter program that gets invoked by OF
> How does exactly  it get invoked?

See bootxx above.

> What OF commands are sent?

Check the code. :-)

> Where is the code of the booter located in the src directory?

sys/arch/macppc/stand/
		      bootxx
		      installboot - configures and installs bootxx
		      ofwboot

> And as if this was not enough:
> What is the binary format of the NetBSD kernel?

elf

> Where can I find the description of it ? Structures?

Why? It's an elf file. All of the tool chain knows how to deal with it.
:-)

Take care,

Bill