Skip to content

Building programs for PlayStation 2 Linux

Den edited this page May 13, 2022 · 6 revisions

Make sure that you have a working R5900 cross compiler, or begin by Installing an R5900 cross compiler.

To be able to build the programs for Playstation 2 Linux, you have to decide for yourself what will be a base for the Linux. If you want to use your Linux only for launching a pare of some specific programs, then in that case after the stage where you have the cross compiler, you can try to compile your program from it's sources like this:

export PATH=/usr/local/ps2/bin:$PATH (that should be done only once per your terminal session; paths presented here are correct for the cross compiler built using the Building an R5900 cross compiler with GNU libc from sources guide.)

./configure --prefix=/usr/local/ps2/mipsr5900el-unknown-linux-gnu --host=mipsr5900el-unknown-linux-gnu
make
make DESTDIR=/path/to/test/directory install
or
make install (that will installs (at least it should) everything from that source to your cross compiler directory)

That is correct for the dependencies only of your desired program. Dependencies of the programs, their libraries and header files, must be installed into cross compiler directory. To build the end program itself, the commands are almost the same, but you should make it using this command:

make CC="mipsr5900el-unknown-linux-gnu-gcc -static -static-libgcc" CXX="mipsr5900el-unknown-linux-gnu-g++ -static -static-libgcc"

then install it or just copy the static binary file of your program to the place where it will be launched from on your console device. You may prefer that place as the USB flash stick. In that case you may copy that file to the FAT32 partition of your USB flash stick, but for the better compatibility it is recommended to use EXT partition type such as ext2, ext3 or ext4.

To finally test it, you need to launch your kernel so eventually you can enter some commands. You already handled that part of initrd preparing, right? - if not, read the Installing a PlayStation 2 Linux initramfs root filesystem guide. Once you loaded to the moment where you can enter the commands, mount the partition of your USB flash stick and launch your program from there. It might be to mount the partition, to have it's file system type support, the appropriate module must be activated first. How to mount the partition... the guide about that should be searched somewhere not here...


If you'll decide that you want a fully functional Linux operating system, in which in the end you may compile a complicated programs with lots of dependencies, in their shared forms, then you have to build it from the scratch. The instruction below is got from reading the appropriate "building a linux from scratch" guide.

You must know how to download source archives, how to extract them, how to navigate using console terminal commands, how to apply a patch (mostly it's patch -p1 < /path/to/patch.patch). The one building algorithm to build everything is

export PATH=/usr/local/ps2/bin:$PATH (that should be done only once per your terminal session; paths presented here are correct for the cross compiler built using the [[Building an R5900 cross compiler from sources]] guide.)
./configure --prefix=/usr/local/ps2/mipsr5900el-unknown-linux-gnu --host=mipsr5900el-unknown-linux-gnu and_maybe_additions
make
make install (that will installs everything from that source to your cross compiler directory)

however, there might be a patch in a needence of be applied or/and additions to the configure command to be added. Let's go.

ncurses-5.9. Patch work_around_changed_output_of_GNU_cpp_5.x.patch.txt . Additions:

--without-cxx --without-cxx-binding --with-shared --without-debug --without-ada --enable-overwrite --enable-widec

Note that there will be no .pc files built without pkg-config, we'll rebuild ncurses for that purpose later.

bzip2-1.0.6 . Patch bzip2-1.0.6_compat.patch . No configure, instead build and install it with these commands:

make
make install PREFIX=/usr/local/ps2/mipsr5900el-unknown-linux-gnu

coreutils-8.31 . Additions, build and install commands:

--without-selinux --enable-threads=posix
make man1_MANS=""
make man1_MANS="" install

diffutils-3.7

gettext-0.17 . Patch gettext-0.17_compat.patch

e2fsprogs-1.45.4 . Addition:

--disable-defrag

findutils-4.7.0

gawk-4.0.1 . Addition:

ac_cv_func_working_mktime=yes

libiconv-1.13.1

grep-2.14 . Additions:

--disable-perl-regexp --without-included-regex

gzip-1.10

xz-5.2.4

m4-1.4.18 . Patch glibc-change-work-around.patch

make-3.81 . Patch make-3.81-alloca_unmiss.patch

patch-2.7 . Patch patch-2.7-incfix.patch

sed-4.2.1

tar-1.32

texinfo-6.3 . Patch texinfo-6.3_compat.patch

readline-6.2 . A command before configure, then build and install commands:

sed -i '/MV.*old/d' Makefile.in
./configure ... (usual)
make SHLIB_LIBS=-lncursesw
make install

bash-4.2 . Patch bash-4.2_uCompat.patch . The configure command:

CC="mipsr5900el-unknown-linux-gnu-gcc -static -static-libgcc" ./configure --prefix=/usr/local/ps2/mipsr5900el-unknown-linux-gnu --host=mipsel-unknown-linux-gnu --with-curses --without-bash-malloc --with-installed-readline --enable-largefile ac_cv_func_working_mktime=yes ac_cv_c_bigendian=no

make and install; then go to /usr/local/ps2/mipsr5900el-unknown-linux-gnu/bin and do

mipsr5900el-unknown-linux-gnu-strip bash
ln -s bash sh

which-2.1 . Patch which-2.1_compat.patch . No configure, instead build and "install" it with these commands:

make
cp -v which /usr/local/ps2/mipsr5900el-unknown-linux-gnu/bin/

pkg-config-0.29.1 . Patch pkg-config-0.29.1_gdate_pragma.patch . The configure command:

./configure --prefix=/usr/local/ps2 --target=mipsr5900el-unknown-linux-gnu --with-internal-glib --program-prefix=mipsr5900el-unknown-linux-gnu-

The afterinstallation launches should be ignored, pkg-config is installed.

ncurses-5.9, rebuilding to get it's .pc files. Go to ncurses-5.9 folder and do make distclean with further usual compile algorithm. Additions:

--without-cxx --without-cxx-binding --with-shared --without-debug --without-ada --enable-overwrite --enable-widec --enable-pc-files PKG_CONFIG_LIBDIR=/usr/local/ps2/mipsr5900el-unknown-linux-gnu/lib/pkgconfig

mingetty-1.08 . Patch mingetty-1.08_UTF8+compat.patch . No configure, instead build and "install" it with these commands:

make
cp -v mingetty /usr/local/ps2/mipsr5900el-unknown-linux-gnu/sbin/

iproute2-4.8.0 . Patch iproute2-4.8.0_incfix+compat.patch . After the moment it's installed, create the folders var , var/lib and var/lib/arpd in the /usr/local/ps2/mipsr5900el-unknown-linux-gnu directory.

procps-3.2.8 . Patch procps-3.2.8_incfix+compat.patch . No configure, instead build and install it with these commands:

make CC=mipsr5900el-unknown-linux-gnu-gcc
make DESTDIR=/usr/local/ps2/mipsr5900el-unknown-linux-gnu install

file-5.30 . No special additions or special way of compiling, but to be able to compile it, the same version must be built and installed to your PCLinux. You may try to compile the versions which are newer than 5.30.

flex-2.6.0 . Patch flex-2.6.0_teststrick.patch

inetutils-1.9.4 . Patch inetutils-1.9.4-PATH_PROCNET_DEV.patch . Additions (what is disabled is provided from iproute2):

--disable-tftpd --disable-dnsdomainname --disable-ping --disable-ping6

After the moment it is installed, you should replace gettext's hostname to inetutils'es one. For doing that, go to /usr/local/ps2/mipsr5900el-unknown-linux-gnu/lib/gettext and do next:

rm -f hostname
ln -s ../../bin/hostname hostname

cracklib-1.8.19 . No special additions or special way of compiling. But just know that because to the creator of this guide it is unknown how or where from to get the appropriated files for this lib, in the times he was testing fedora12_mips64el in qemu - he compiled the same cracklib version (that's 2.8.19 as you can see) and just copied the files from fedora12_mips64el from /usr/share/cracklib (cracklib.magic , cracklib-small.hwm , cracklib-small.pwd , cracklib-small.pwi , pw_dict.hwm , pw_dict.pwd pw_dict.pwi) to /usr/local/ps2/mipsr5900el-unknown-linux-gnu/share/cracklib . Those files are presented in the final-unpack archive .

Linux-PAM-1.3.0 . No special additions or special way of compiling, but to be able to compile it, the package of exact version (and not exact subversion) automake-1.13.4 must be built and/or installed to your PCLinux. In the moment you are compiling Linux-PAM-1.3.0 you may notice the errors about building something in doc/specs - just ignore those errors and proceed with the installation. After it is installed, go to /usr/local/ps2/mipsr5900el-unknown-linux-gnu/include and do:

ln -s . security

libcap-2.24 . Patch libcap-2.24_compat.patch . No special additions or special way of compiling, just notice that the afterinstallation launches should be ignored; libs and the appropriate are installed.

zlib-1.2.10 . Patch zlib-1.2.10_removechecktopass.patch . The configure command:

CC=mipsr5900el-unknown-linux-gnu-gcc ./configure --prefix=/usr/local/ps2/mipsr5900el-unknown-linux-gnu --shared

util-linux-2.34-rc2 . Additions, build and install commands:

PKG_CONFIG_PATH=/usr/local/ps2/mipsr5900el-unknown-linux-gnu/lib/pkgconfig --without-selinux  --disable-chfn-chsh --disable-login --disable-nologin --disable-su
make NCURSES_LIBS="-lncursesw"
make install 

chfn, chsh, login, nologin, su - all of them will be presented from the shadow package

shadow-4.1.5.1 . Additions:

--without-selinux --without-nscd --with-libpam --with-libcrack

After installation, there should make the appropriate files (passwd, group) in target-system's /etc and also edit target-system's /etc/pam.d/{su,login} - remove the lines which contains pam_selinux.so . Where is no file "system-auth", so the creator of this guide just copied these from the times of testing fedora12_mips64el and keep it nowadays. All these presented in final-unpack archive.

kbd-1.15.5

module-init-tools-3.15 . Patch module-init-tools-3.15_nomans.patch . No special additions or special way of compiling, just notice that the afterinstallation launches should be ignored; the binaries are installed.

psmisc-22.20 . Patch psmisc-22.20_muteallocchekcs+compat.patch

sysklogd-2.1.1 . Addition:

PKG_CONFIG_PATH=/usr/local/ps2/mipsr5900el-unknown-linux-gnu/lib/pkgconfig

sysvinit-2.88dsf . Patch sysvinit-2.88dsf_compat.patch . No configure, instead build and "install" it with these commands CAREFULLY (in mistake of typed make install you'll rewrite your PCLinux files which is... very bad...):

make CC=mipsr5900el-unknown-linux-gnu-gcc -C src || exit -1
cp -rdfv src/{fstab-decode,halt,init,killall5,runlevel,shutdown} /usr/local/ps2/mipsr5900el-unknown-linux-gnu/sbin/
cd /usr/local/ps2/mipsr5900el-unknown-linux-gnu/sbin
ln -s killall5 pidof

nano-2.2.6 . Additions:

--enable-color --enable-extra --enable-multibuffer --enable-utf8

openssl-1.1.0c . Patch openssl-1.1.0c_incfix+mipsr5900el-compat.patch . The configure command:

CROSS_COMPILE="mipsr5900el-unknown-linux-gnu-" RANLIB=mipsr5900el-unknown-linux-gnu-ranlib ./Configure linux-mips32 --prefix=/usr/local/ps2/mipsr5900el-unknown-linux-gnu

openssh-7.6p1 . Patches openssh-7.6p1-openssl-1.1.0-1.patch and openssh-7.6p1_changesshdconfigoption.patch . Additions:

PKG_CONFIG_PATH=/usr/local/ps2/mipsr5900el-unknown-linux-gnu/lib/pkgconfig --disable-strip

Notice that the afterinstallation launches should be ignored. sshd and the appropriate are installed.

The default config for sshd is ready for ssh connection since now... but the sshd user and group, and the ssh_host_xxxxx_key creation will be maded in the final-unpack stage. Also, note that you should load the ssh daemon not just with command 'sshd' but using it's full path with it, eg. '/sbin/sshd' . At last, do this:

mkdir /usr/local/ps2/mipsr5900el-unknown-linux-gnu/var/empty

fbset-2.1 . No configure, instead build and "install" it with these commands:

make CC=mipsr5900el-unknown-linux-gnu-gcc
cp -v fbset /usr/local/ps2/mipsr5900el-unknown-linux-gnu/sbin/

That should be enough to be the base. Instead of the various preparations of the various files for the various programs, everything is preconfigured and united into the one archive which you'll just unpack. Nevertheless, if the described building algorithm was simplified as automatized with .sh script files inside the scripts folder of the repository where you should be downloading patches from, it is impossible to automatize everything, so you'll have to make some actions by yourself.

When all scripts are passed, it is time to transfer target-system to the place where it will be loaded from.

Assume it is USB flash stick. If it is your HDD - edit /etc/fstab and /etc/init.d/rcS for a system and SWAP partitions in the end.

Suppose the example USB flash stick is 16Gb size. It's example partitions:

1 FAT32 9.6Gb

2 SWAP 2.0Gb

3 EXT4 4.3Gb

To do:

copy PS2Linux5.4.ELF to USB_FAT32/ps2linux

copy /usr/local/ps2/mipsr5900el-unknown-linux-gnu/* to USB_EXT4

copy lib/modules/5.4.X (you might have them installed into the initramfs) to USB_EXT4/lib/modules/

copy lib/firmware/ps2 (you might have them installed into the initramfs as well) to USB_EXT4/lib/firmware/

unpack PS2Linux-etc.tar.bz2 to USB_EXT4

go to USB_EXT4 and create folders:

/usr
/usr/local
/usr/local/ps2

go to /usr/local/ps2 and make a symlink:

ln -s ../../../ mipsr5900el-unknown-linux-gnu

go to /dev and make here a device nodes. There is a devcreator.sh script file placed here after PS2Linux-etc.tar.bz2 was unpacked, so you may do sh devcreator.sh for that purpose. If you need some other device nodes not presented in that script file, then you have to create them manually.

unmount USB_EXT4 partition and check it for the errors:

e2fsck -fy /dev/USB_EXT4_node

Plug this USB flash stick to PS2, launch PS2Linux5.4.ELF . Once booted, enter these commands:

mount -t ext4 -o rw /dev/USB_EXT4_node /mnt
mount --bind /proc /mnt/proc

busybox chroot /mnt
/sbin/pwconv
/sbin/grpconv
/sbin/groupadd bin
/sbin/groupadd daemon
/sbin/groupadd nobody
/sbin/useradd bin -u 1 -g bin -d /bin -s /sbin/nologin
/sbin/useradd daemon -u 2 -g daemon -d /sbin -s /sbin/nologin
/sbin/useradd nobody -u 99 -g nobody -d / -s /sbin/nologin
/sbin/groupmod -g 1 bin
/sbin/groupmod -g 2 daemon
/sbin/groupmod -g 99 nobody

umount /mnt/proc
umount /mnt

These will be needed when you successfully loaded to the system and want to use ssh connections

groupadd -g 33 sshd
useradd -u 33 -g 33 -c sshd -d / sshd
ssh-keygen -t rsa -f /etc/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh_host_dsa_key
ssh-keygen -t ecdsa -f /etc/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh_host_ed25519_key

Now you should have a fully functional operating system, a Linux what is actually a mess of the compiled (and afterward configured) packages :D Moreover, it is possible to return the target-system's installed files back to /usr/local/ps2/mipsr5900el-unknown-linux-gnu PCLinux directory, re-install the cross-compiler from the sources to /usr/local/ps2 and it will be ready as if you'd manually compiled it, and to continue the compiling having a base with libraries and headers. This also means you may share with it to someone else, so that person not only can launch your result work but he/she can some way continue it using your result work as a base.

To add more programs to the already prepared partition with target-system, make the program, install it using the command make DESTDIR=/path/to/some/place install, connect your USB flash stick with target-system partition and just copy those files there from that /path/to/some/place . Do not forget to safely unmount your exact target-system partition and the USB flash stick device after the changes.

P.S.: You might have noticed that here are the scripts.sh - they can be used to automatise the process of the cross compiler building. There are notes inside them which, no doubts, might be useful to know while building the related package if some problem appears with that package compiling.

Clone this wiki locally