patching the kernel for use with ps2stuff (and ps2gl)

why do we have to patch the kernel?!

ps2stuff is a very low-level library and one of its most important parts talks to a memory controller chip called the dmac. The dmac basically moves data around the system (into/out of main RAM) without bothering the CPU, which frankly needs all the help it can get. Unfortunately the dmac doesn't understand Linux's ideas on virtual memory and so needs plain-old, raw RAM, but by default Linux can't give a program very big chunks of raw RAM, which we want for graphics. So anyway, I use the bigphysarea patch to reserve some RAM at startup for use by ps2stuff. The disadvantages are that 1) only ps2stuff can use the memory, making it lost to the rest of the system, and 2) the amount of memory can't be changed without rebooting.

Let's get to it:

Install the kernel sources

If you did this during the system install the sources will be in /usr/src/linux. Otherwise install the kernel source rpm from the dvd.

configure and build the kernel

Ideally you should check the Kernel-HOWTO if you've never built a kernel before, but although I'll assume some familiarity here you can probably figure it out.

I recommend building the kernel once and rebooting before patching just to make sure everything is working correctly..so:

Do a 'make xconfig' or 'make menuconfig' to change any options you'd like (the defaults should be fine) then 'save & exit.'

Now you should have a configured kernel source tree, and you're ready to build. The whole process should take 20-30 mins:

  1. make dep
  2. make
  3. make modules

When make finishes there should be a shiny new kernel called vmlinux in /usr/src/linux ready to be installed to your boot memory card:

Note: you may also need to do a 'make modules_install' if you changed the options and added new modules. Since it will overwrite the default modules in /lib/modules/2.2.1, you may want to make a backup.

install the new kernel

  1. su
  2. mnt /mnt/mc00
  3. cd /mnt/mc00
  4. cp vmlinux vmlinux.original (just to be really safe)
  5. cp /usr/src/linux/vmlinux vmlinux.recompiled_no_ps2stuff
Now you need to edit the file 'p2lboot.cnf' to add a boot option for your new kernel. I added the following line:
"New Kernel" vmlinux.recompiled_no_ps2stuff "" 203 /dev/hda5 "" Recompiled kernel
At this point try rebooting and selecting the new kernel as a sanity check.

now patch and do it again...

Assuming that your system came up, you need to apply the ps2stuff kernel patch, build, and install the new kernel. (This won't rebuild quite everything, but it will take a little under 10 minutes.)

The kernel patch is located in the ps2stuff source tarball in ps2stuff/linux/patches. Apply the patch like this:

  1. cd /usr/src/linux
  2. patch -p1 < ~/kernel-ps2stuff-bigphysarea.beta.patch
Now do a 'make xconfig' (or 'make menuconfig' ...). Under "Code Maturity Level Options" select "Prompt for development ... drivers", and under "General Setup" select "support for big physical area reservation." Now do "Save & Exit" and you're ready to build.

Build just like above with 'make' (no need to mess with modules this time).

After make finishes, copy vmlinux to /mnt/mc00/vmlinux.ps2stuff_patched (make sure there's enough space). Now you'll need to add entries to boot from the new kernel to p2lboot.cnf. Because we have to specify the amount of memory for ps2stuff at boot time, I like to make a bunch of menu selections with different amounts of RAM, like this. Note that you'll need to change "/dev/hda5" to whatever your root partition is.

Now you should be all set to reboot and give ps2stuff (and hence ps2gl) some memory. If you see 'bigphysarea' in /proc then the patch is working. 'cat /proc/bigphysarea' will show you the status of the allocated memory.