Monday, November 28, 2005

Understanding the yaboot bootstrap process

Again, if you're researching and you don't have access to a debian box, here's some juicy bits, this time from the bootstrap man page that comes with yaboot. I'm including this because it gives a good explanation of OpenFirmware paths, boot partitions, and the bootstrap process in general. It assumes that you are working off of an internal IDE drive like a normal person.


NEWWORLD
The process of booting so called NewWorld PowerMacs from
disk starts with OpenFirmware first attempting to execute
the file specified in the boot-device variable. Unlike
older versions of OpenFirmware the NewWorld version will
not attempt to read a boot sector. By default Open­
Firmware attempts to load a file with HFS file type "tbxi"
in the "blessed" directory from each partition of each
disk OpenFirmware is aware of, the first partition/disk
that is found to be bootable is booted immediately.

Ybin(8) configures a bootstrap partition to pass all of
OpenFirmware's tests to determine if the partition is con­
sidered to be bootable or not. The boot script is given
file type "tbxi" and the root directory is marked as
"blessed", the blessing is important because OpenFirmware
will immediately consider a partition unbootable if no
directory is marked as blessed (you can still manually
execute a loader such as yaboot(8) with OpenFirmware even
without a blessed directory but it will not happen auto­
matically).

The MacOS System Folder is always marked as blessed, this
is required for MacOS as well as OpenFirmware. The MacOS
System Folder also contains its own boot loader which has
the tbxi file type, this makes installing yaboot(8) onto a
MacOS partition is difficult. The only way to install
yaboot(8) on a MacOS boot partition is to modify Open­
Firmware to boot the CHRP script directly. Given this it
is highly recommended that you create a dedicated boot­
strap partition for yaboot(8).

Since OpenFirmware boots the first partition it finds to
be bootable it is important that the bootstrap partition
be first on the disk before any MacOS partition, otherwise
MacOS will be booted instead of a dual boot menu used with
yaboot(8).

The bootstrap partition should also NOT be mountable by
MacOS, the reason is MacOS will (almost always) closely
inspect any blessed directories to make sure its real
MacOS, if it is not satisfied that the contents are a real
copy of MacOS it will unbless the directory, resulting in
OpenFirmware no longer considering it bootable. The best
way to protect against this is to create the bootstrap
partition with the partition type "Apple_Bootstrap" which
OpenFirmware accepts as a valid HFS partition, but MacOS
will ignore and refuse to mount. The bootstrap partition
need not be any larger then 800K. 800K is the minimum
size of an HFS filesystem, and is much more then enough
for this purpose. You need not, and should not keep ker­
nels on this partition, yaboot(8) will load them from your
ext2fs root partition just fine, as well as from any HFS
or HFS+ partitions (yaboot(8) uses OpenFirmware's HFS+
filesystem support).

To create the bootstrap partition, use GNU parted(8) or
mac-fdisk(8) to create a partiton of type "Apple_Boot­
strap". This is documented better in mac-fdisks-basics
(http://penguinppc.org/usr/ybin/doc/mac-fdisk-
basics.shtml).

The bootstrap need not and should not be mounted anywhere
on your filesystem, especially not on top of /boot.
Yaboot(8) is able to load the kernels from the ext2fs root
partition so that is where they should be kept.

OpenFirmware maintains a hierarchy of all the hardware it
is aware of. To access or specify a boot device you must
use the OpenFirmware path. For example: the path to a
SCSI hard disk partition might look like this:
/pci@80000000/pci-bridge@d/ADPT,2930CU@2/@2:2 . The first
part, pci@80000000, shows that the target device is
accessed through the PCI bus. The next part is the PCI
bridge, the next is the name of the SCSI host adapter
installed (this name is provided by a BootROM on the card
itself), and after that is the SCSI ID number. The colon
delimits the device from partition specification, so the
last 2 means the second partition of this device. After
the partition number we can specify pathnames to files in
two ways: lazy and absolute. The "," delimits the Open­
Firmware path from the location of the bootfile.
",\\:tbxi" specifies the file that has a HFS file type of
"tbxi" in the blessed directory. If there is not blessed
directory this will fail. The second is to specify a
absolute pathname to an arbitrary file on the disk, exam­
ple: 2:,yaboot would load the file named "yaboot" in the
root directory of the filesystem. It is possible to load
files in subdirectories but OpenFirmware does not always
do this reliably, and any special characters such as an
embedded space must be expressed like %20 (for a space)
the directory separator used by OpenFirmware is the back­
slash \. Example: 2:,\boot\yaboot. Determining the Open­
Firmware path to a given device is unfortunately not a
trivial task. If you are using the built in ATA hard disk
you can use the alias "hd:".

Ybin also includes a utility ofpath(8) which can in most
cases find the OpenFirmware device path from a unix device
node (ie /dev/hda2).

In addition to binary executables OpenFirmware can also
execute a CHRP script. This is somewhat similar to a
shell script. A CHRP script is useful to create simple
boot menus, among other things. CHRP scripts are divided
into sections in a way similar to HTML. Here is a basic
example of a CHRP script used as a wrapper to yaboot(8)
(since OpenFirmware will only load a file with type "tbxi"
if it is a CHRP script).

<CHRP-BOOT>
<COMPATIBLE>
MacRISC
</COMPATIBLE>
<DESCRIPTION>
GNU/Linux PowerPC bootloader
</DESCRIPTION>
<BOOT-SCRIPT>
boot hd:,\\yaboot
</BOOT-SCRIPT>
</CHRP-BOOT>


The COMPATIBLE section defines what machines this script
is compatible with, if the machine name encoded into the
ROM does not match one of these entries OpenFirmware will
print out a lot of incomprehensible junk and fail to load
the script. The DESCRIPTION is ignored by OpenFirmware as
far as I know. The BOOT-SCRIPT section is where arbitrary
OpenFirmware Forth commands may go. They are executed the
same way as you would enter them on the OpenFirmware com­
mand line. The entire script is wrapped with the CHRP-
BOOT tags so that such a script may be attached as a
header to a binary file. Much more complicated and elabo­
rate CHRP scripts are possible but that is beyond the
scope of this document.

Ybin as of version 0.17 includes a more robust script that
is automatically configured with the correct OpenFirmware
paths based on /etc/yaboot.conf. This new script need not
and should not be edited by the user.

If you have G4 hardware then your OpenFirmware may already
have a graphical boot selector built in. This selector can
be accessed by holding down the option key when booting
the machine. You should see a screen with buttons for
each bootable partition. The current version (as of
ybin(8) 0.13) of ofboot includes a badge icon, the button
with a penguin icon is your bootstrap partition. If you
decide to use this built in selector you really do not
need to use a CHRP script that provides a boot menu.
Thanks to Nicholas Humfrey for creating the Badge icon.

2 Comments:

At 10:44 PM, Anonymous Anonymous said...

How about crediting the source of this material.

 
At 10:45 PM, Anonymous Anonymous said...

Excellent guide.

 

Post a Comment

<< Home