PS2Linux SPS2 on memorycard tutorial

This tutorial is about getting SPS2 working on memorycards with no harddisk available. Before you can use it, you need a working no-hdd memorycard. If you do not have one yet, you should go through the tutorial at

http://playstation2-linux.com/download/nohdd/ps2nohdd.html
You also need to have a working sps2_mod.o available. (If you have installed the sps2-kernel-module on your harddisk, you can find it in /lib/modules/2.2.1/misc/ ) If you do not have one, install the sps2 kernel module from
http://playstation2-linux.com/projects/sps2/

Copying the files

If you have done the cloop-tutorial, you should put all mentioned files into the romimage and not into the initrd. Otherwise simply put all mentioned files into your initrd.

Create the directory "modules" on your initrd or your romimage.
Then copy sps2_mod.o from /lib/modules/2.2.1/misc into the directory.

For a little script-action we need the following executables:

Make sure that you have them in your "bin"-directory on your initrd or romimage.
Afterwards create the directory "/proc" on your initrd.

Last but not least you have to make sure that the kernel on the memorycard has /proc support. (If do not know what /proc is, or are unsure whether your kernel has /proc support, it most probably has.)

Creating the special files

SPS2 needs some of the ps2 special files for working properly. Since device-files do not consume space, we will simply copy over all of them.

Execute "cp -R /dev/ps2* ./" in the "dev"-directory of your initrd. (the "-R" must be uppercase)

Program for extracting sps2 major number

Unfortunately you are not done with simply loading the sps2 kernel module. You have to extract the major number of the module from /proc/devices after you have inserted it and create a device-special-file with this number.
Usually sps2_load does all this, but this time we cannot use it, because we neither have bash nor awk available. (and including them would be a waste of space). So we will have to create our own "awk" to extract the number.

Create the file "getsps2major.c" somewhere in your home-directory and put the following code into it.

#include <stdio.h>
int main()
{
  FILE * devices = fopen("/proc/devices", "r");
  char line[100];
  while (fgets(line, 100, devices) != 0)
  {
    strcpy(line, &line[strspn(line, " ")]);
    if (  (strrchr(line, ' ')!=0)    )
    {
      if (strcmp(strrchr(line, ' ')," sauce_char\n")==0)
      {
        line[strspn(line, "0123456789")] = 0;
        printf("%s", line);
      }
    }
  }
  fclose(devices);
  return 0;
}
//end of file

Compile the prog with "gcc getsps2major.c -o getsps2major" and copy "getsps2major" over to the "bin"-directory of your initrd or romimage.
Afterwards use "strip getsps2major" to make the executable smaller.

Loading the SPS2 kernel module at startup

Now we will do what sps2_load usually does: some script-action.
Create or edit the file "startscript" on your initrd or romimage and put the following into it:

#!/bin/sh

#mount proc to get access to /proc/devices
mount -t proc none /proc

#load the sps2-kernel module
insmod ./modules/sps2_mod.o

#create the sps2 special-file
mknod /dev/sps2 c `getsps2major` 0

#--end of file--#
Don't forget to make the startscript executable with "chmod 755 startscript".
Finally you must make making sure that the script gets executed during startup.

That's all. Have fun.
(You do not need any libraries for sps2, because it is statically linked into your programs.)

Mr.M

Copyright (C) 2004 Michael Mahr (Michael.Mahr@fh-joanneum.at)