Building a GameCube Linux Kernel (ARCH=powerpc)

From gc-linux

Jump to: navigation, search

Contents

Introduction

This guide explains briefly the necessary steps to produce a Linux kernel suitable for the GameCube, using a Linux PC.

Requisites

HINT: You usually will build a non-ramdisk based kernel, unless you have a specific need for it.

Installing the toolchain and doltool

1. Uncompress the toolchain to a directory where you have write access.

  $ cd /home/isobel
  $ tar xjvf /tmp/downloads/buildroot-20090131gcn1-i686-cross-powerpc.tar.bz2

2. (Optional) Uncompress doltool sources there too.

  $ tar xzvf /tmp/downloads/doltool.0.3.2.linux-TenOfTen.tgz

3. (Optional) Build doltool, and copy the resulting binary to the toolchain bin directory.

  $ cd doltool.0.3.2.linux-TenOfTen
  $ g++ -o doltool *cpp
  $ cp doltool ../H-i686-pc-linux-gnu/cross-powerpc-linux-uclibc/usr/bin
  $ cd ..

(Conditional) Installing dtc for kernels prior to 2.6.26

1. Uncompress the dtc tool sources there too.

  $ tar xzvf /tmp/downloads/dtc-1.1.0.tgz

2. Build dtc, and copy the resulting binary to the toolchain bin directory.

  $ cd dtc
  $ make
  $ cp dtc ../H-i686-pc-linux-gnu/cross-powerpc-linux-uclibc/usr/bin/
  $ cd ..

Preparing to use the toolchain

1. Add the bin directory of your ppc toolchain tree to your PATH environment variable.

  $ export PATH=$PATH:/home/isobel/H-i686-pc-linux-gnu/cross-powerpc-linux-uclibc/usr/bin

NOTE: This will temporarily add the toolchain directory to your path. If you plan to frequently use the toolchain you may want to modify your login script accordingly.

Installing and patching the Linux kernel sources

1. Put the kernel tarball, and the GameCube Linux kernel patches, in a directory where you have permissions.

  $ ls
  linux-2.6.32.tar.bz2  mikep5-patch-2.6.32-gc.bz2

CAUTION: Do NOT use the /usr/src directory !!!

2. Unpack the kernel sources.

  $ tar xjvf linux-2.6.32.tar.bz2 

3. (Optional) If you plan to build a ramdisk based kernel, copy your ramdisk image into the kernel source tree.

  $ cp /tmp/downloads/ramdisk.image.gz linux-2.6.32/arch/powerpc/boot/ramdisk.image.gz

4. Apply the GameCube Linux patch corresponding to your kernel version.

  $ cd linux-2.6.32
  $ bzip2 -cd <../mikep5-patch-2.6.32-gc.bz2 | patch -p1

Building the kernel image

1. Change to the parent directory of your recently patched kernel source tree.

  $ cd ..
  $ ls
  linux-2.6.32  linux-2.6.32.tar.bz2  mikep5-patch-2.6.32-gc.bz2

2. (default) If you don't have already a kernel configuration, start with the default kernel configuration for your video game console as a base config.

2.1. If you are building a kernel for the Nintendo GameCube, use the following configuration:

  $ cp linux-2.6.32/arch/powerpc/configs/gamecube_defconfig linux-2.6.32/.config

2.2. If you are building a kernel for the Nintendo Wii, use the following configuration:

  $ cp linux-2.6.32/arch/powerpc/configs/wii_defconfig linux-2.6.32/.config

HINT: You can retrieve the exact kernel configuration from a specific kernel image file with the script scripts/extract-ikconfig. It can also be extracted from a running kernel by reading /proc/config.gz if enabled.

3. (Optional) If you require it, modify the kernel configuration.

  $ make -C linux-2.6.32 ARCH=powerpc CROSS32_COMPILE=powerpc-linux- CROSS_COMPILE=powerpc-linux- menuconfig

4. (Optional) If you require it, modify the kernel command line.

The kernel command line is currently specified in the 'bootargs' property of the 'choosen' node of the device tree source, like in the following example snippet.

       chosen {
               bootargs = "root=/dev/mmcblk0p2 rootwait udbg-immortal";
       };

4.1. If you are building a kernel for the Nintendo GameCube, edit the following device tree source file:

  $ vi linux-2.6.32/arch/powerpc/boot/dts/gamecube.dts

4.2. If you are building a kernel for the Nintendo Wii, edit the following device tree source file:

  $ vi linux-2.6.32/arch/powerpc/boot/dts/wii.dts

HINT: To change the initial IP settings of your kernel, modify the kernel command line. Please refer to the description of the ip= parameter in the nfsroot documentation.

5. Build your kernel image.

5.1 If you are building a kernel which loads the root filesystem from a block device then do a make for a zImage target:

  $ make -C linux-2.6.32 ARCH=powerpc CROSS32_COMPILE=powerpc-linux- CROSS_COMPILE=powerpc-linux- zImage
The resulting Linux kernel image in ELF format can be located at linux-2.6.32/arch/powerpc/boot/zImage

5.2 If you are building a ramdisk based kernel do a make for a zImage.initrd target:

  $ make -C linux-2.6.32 ARCH=powerpc CROSS32_COMPILE=powerpc-linux- CROSS_COMPILE=powerpc-linux- zImage.initrd
The resulting Linux kernel image in ELF format can be located at linux-2.6.32/arch/powerpc/boot/zImage.initrd

(Optional) Building a useable DOL

This is a hackish sample script "build-dol" to build a DOL file called zImage1.dol in the current directory from the ELF file generated by the kernel build. Note that doltool cannot be used to directly convert the elf into a dol file as it contains a number of sections that confuse poor's doltool.

 #!/bin/bash
 
 target=${1:-zImage}
 ofile=zImage1
 
 [ -r ${KSRC}/arch/powerpc/boot/${target} ] || {
   echo "Can't find target image ${KSRC}/arch/powerpc/boot/${target}"
   exit 1
 }
 
 cp ${KSRC}/arch/powerpc/boot/${target} ${ofile}
 
 CROSS=powerpc-linux-
 
 echo "+ building DOL"
 load=$(${CROSS}readelf -l "$ofile" | \
 	perl -lane'printf"%08x\n",hex($F[3])+0x80000000 if /LOAD/;')
 echo "  LOAD: $load"
 entry=$(${CROSS}readelf -l "$ofile" | \
 	perl -lane'printf"%08x\n",hex($F[2])+0x80000000 if /Entry point/;')
 echo "  EP  : $entry"
 
 ${CROSS}objcopy -O binary \
 	-R .comment -R .shstrtab -R .symtab -R .strtab \
 	-R .gnu.attributes \
 	${ofile} ${ofile}.bin
 doltool -c ${ofile}.bin $load $entry
 doltool -i ${ofile}.dol
 echo ""


If your kernel source is at linux-2.6.32/ you can invoke the script as follows:

 $ KSRC=linux-2.6.32/ ./build-dol
Personal tools