makeBootImages() {
    echo "Building boot images for kernel $kernelvers"
    FAKEARCH=""

    if [ "$KERNELARCH" = "ppc64" ]; then
	mkdir -p $TOPDESTPATH/ppc/ppc64
	echo "Building $KERNELARCH initrd"
	makeinitrd --initrdto $TOPDESTPATH/ppc/ppc64/ramdisk.image.gz \
	    --initrdsize 8192 \
	    --loaderbin loader \
	    --modules "$INITRDMODS spufs"

	cp $KERNELROOT/boot/vmlinuz-* $TOPDESTPATH/ppc/ppc64/vmlinuz
        sed -e "s/%BITS%/64/" -e "s/%PRODUCT%/$PRODUCT/" -e "s/%VERSION%/$VERSION/" \
	    $BOOTDISKDIR/yaboot.conf.in > $TOPDESTPATH/ppc/ppc64/yaboot.conf

    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$KERNELARCH]
kernel = ppc/ppc64/vmlinuz
initrd = ppc/ppc64/ramdisk.image.gz
__EOT__

	if [ -x $IMGPATH/usr/bin/mkzimage -a -r $IMGPATH/usr/share/ppc64-utils/zImage.stub ]; then
		mkdir -p $TOPDESTPATH/images/netboot
		pushd $TOPDESTPATH/ppc/ppc64
		cp $IMGPATH/usr/share/ppc64-utils/zImage.lds $TOPDESTPATH/ppc/ppc64/zImage.lds
		$IMGPATH/usr/bin/mkzimage $TOPDESTPATH/ppc/ppc64/vmlinuz no no $TOPDESTPATH/ppc/ppc64/ramdisk.image.gz $IMGPATH/usr/share/ppc64-utils/zImage.stub $TOPDESTPATH/images/netboot/ppc64.img
		ADDNOTE=$IMGPATH/usr/share/ppc64-utils/addnote
		if [ -x "$ADDNOTE" ] ; then
		    echo "Running addnote on $TOPDESTPATH/images/netboot/ppc64.img"
		    $ADDNOTE $TOPDESTPATH/images/netboot/ppc64.img
		else
		    echo "Could not find addnote at \"$ADDNOTE\", skipping"
		fi
		rmdir $TOPDESTPATH/images/netboot || :
		rm -f $TOPDESTPATH/ppc/ppc64/zImage.lds
		popd
        echo "zimage = images/netboot/ppc64.img" >> $TOPDESTPATH/.treeinfo
	fi
    echo >> $TOPDESTPATH/.treeinfo


    elif [ "$KERNELARCH" = "ppc64iseries" ]; then
	mkdir -p $TOPDESTPATH/ppc/iSeries
	mkdir -p $TOPDESTPATH/images/iSeries

	echo "Building iSeries initrd"
	makeinitrd --initrdto $TOPDESTPATH/ppc/iSeries/ramdisk.image.gz \
	    --initrdsize 8192 \
	    --loaderbin loader \
	    --modules "$INITRDMODS viocd"

	cp $KERNELROOT/boot/vmlinuz-* $TOPDESTPATH/ppc/iSeries/vmlinux
	cp $KERNELROOT/boot/System.map-* $TOPDESTPATH/ppc/iSeries/System.map

	$IMGPATH/usr/sbin/addSystemMap $TOPDESTPATH/ppc/iSeries/System.map $TOPDESTPATH/ppc/iSeries/vmlinux $TOPDESTPATH/ppc/iSeries/vmlinux.sm
	$IMGPATH/usr/sbin/addRamDisk $TOPDESTPATH/ppc/iSeries/ramdisk.image.gz $TOPDESTPATH/ppc/iSeries/System.map $TOPDESTPATH/ppc/iSeries/vmlinux.sm $TOPDESTPATH/images/iSeries/boot.img
	rm -f $TOPDESTPATH/ppc/iSeries/vmlinux.sm

    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$KERNELARCH]
kernel = ppc/iSeries/vmlinux
initrd = ppc/iSeries/ramdisk.image.gz

__EOT__
    elif [ "$KERNELARCH" = "ppc" ]; then
	FAKEARCH="ppc"
	mkdir -p $TOPDESTPATH/ppc/ppc32
	mkdir -p $TOPDESTPATH/ppc/mac

        echo "Building ppc initrd"
        makeinitrd --initrdto $TOPDESTPATH/ppc/ppc32/ramdisk.image.gz \
            --initrdsize 8192 \
            --loaderbin loader \
            --modules "$INITRDMODS"

        cp $KERNELROOT/boot/vmlinuz-* $TOPDESTPATH/ppc/ppc32/vmlinuz
        sed -e "s/%BITS%/32/" -e "s/%PRODUCT%/$PRODUCT/" -e "s/%VERSION%/$VERSION/" \
	    $BOOTDISKDIR/yaboot.conf.in > $TOPDESTPATH/ppc/ppc32/yaboot.conf

    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$KERNELARCH]
kernel = ppc/ppc32/vmlinuz
initrd = ppc/ppc32/ramdisk.image.gz
__EOT__
	if [ -x $IMGPATH/usr/bin/mkzimage -a -r $IMGPATH/usr/share/ppc64-utils/zImage.stub ]; then
		mkdir -p $TOPDESTPATH/images/netboot
		pushd $TOPDESTPATH/ppc/ppc32
		cp $IMGPATH/usr/share/ppc64-utils/zImage.lds $TOPDESTPATH/ppc/ppc64/zImage.lds
		$IMGPATH/usr/bin/mkzimage $TOPDESTPATH/ppc/ppc32/vmlinuz no no $TOPDESTPATH/ppc/ppc32/ramdisk.image.gz $IMGPATH/usr/share/ppc64-utils/zImage.stub $TOPDESTPATH/images/netboot/ppc32.img
		rmdir $TOPDESTPATH/images/netboot || :
		rm -f $TOPDESTPATH/ppc/ppc64/zImage.lds
		popd
        echo "zimage = images/netboot/ppc32.img" >> $TOPDESTPATH/.treeinfo
	fi
    echo >> $TOPDESTPATH/.treeinfo

    else
        echo "Unknown kernel arch: $KERNELARCH"
    fi
}

doPostImages() {
    # Create boot.iso here instead of above, so we can include it all
    mkdir -p $TOPDESTPATH/etc
    mkdir -p $TOPDESTPATH/ppc/chrp
	
    # Create ofboot.b and bootinfo.txt files, and yaboot binaries for Mac and CHRP
    cp $BOOTDISKDIR/bootinfo.txt $TOPDESTPATH/ppc/bootinfo.txt

    if [ -d $TOPDESTPATH/ppc/mac ]; then
	cp $BOOTDISKDIR/ofboot.b $TOPDESTPATH/ppc/mac/ofboot.b
	cp $IMGPATH/usr/lib/yaboot/yaboot $TOPDESTPATH/ppc/mac/yaboot
    fi

    if [ -d $TOPDESTPATH/ppc/chrp ]; then
	cp $IMGPATH/usr/lib/yaboot/yaboot $TOPDESTPATH/ppc/chrp/yaboot
	$IMGPATH/usr/lib/yaboot/addnote $TOPDESTPATH/ppc/chrp/yaboot
    fi

    # IBM firmware can't handle boot scripts properly, so for biarch installs
    # we use a yaboot.conf which asks the user to select 32-bit or 64-bit kernel. 
    if [ -r $TOPDESTPATH/ppc/ppc32/yaboot.conf -a -r $TOPDESTPATH/ppc/ppc64/yaboot.conf ]; then
        # Both kernels exist. Copy the biarch yaboot.conf into place.
        sed -e "s/%BITS%/32/" -e "s/%PRODUCT%/$PRODUCT/" -e "s/%VERSION%/$VERSION/" \
	    $BOOTDISKDIR/yaboot.conf.3264 > $TOPDESTPATH/etc/yaboot.conf
    else
	# Copy the one that exists, assuming one does exist
	cp $TOPDESTPATH/ppc/ppc??/yaboot.conf $TOPDESTPATH/etc
    fi

    # Copy it all into the isopath for the boot CD
    mkdir -p $TOPDESTPATH/isopath
    cp -r $TOPDESTPATH/{ppc,etc} $TOPDESTPATH/isopath

    # We want the ppc32 prep image in the boot.iso too.
    if [ -d $TOPDESTPATH/images/netboot ]; then
	mkdir -p $TOPDESTPATH/isopath/images
	cp -r $TOPDESTPATH/images/netboot $TOPDESTPATH/isopath/images
	rm -f $TOPDESTPATH/isopath/images/ppc64.img
    fi

    rm -rf $TOPDESTPATH/isopath/ppc/iSeries

    if [ -r $TOPDESTPATH/isopath/images/netboot/ppc32.img ]; then
	PREPBOOT="-prep-boot images/netboot/ppc32.img"
    fi

    if [ -d $TOPDESTPATH/isopath/ppc/mac ]; then
	MACBOOT="-hfs-volid $VERSION -hfs-bless $TOPDESTPATH/isopath/ppc/mac"
    fi

    # Create the boot.iso
    mkisofs -o $TOPDESTPATH/images/boot.iso -chrp-boot -U $PREPBOOT \
	-part -hfs -T -r -l -J -A "$PRODUCT $VERSION" -sysid PPC \
	-V "PBOOT" -volset "$VERSION" -volset-size 1 -volset-seqno 1 \
	$MACBOOT \
	-map $BOOTDISKDIR/mapping -magic $BOOTDISKDIR/magic \
	-no-desktop -allow-multidot $TOPDESTPATH/isopath
    rm -rf $TOPDESTPATH/isopath
}
