Cross-Compiling Linux/390

This paper will explain how to build and use a cross-compilation environment for the zSeries or S/390 Linux kernel on a non-mainframe host.

 

Contents

Assumptions

We make the assumption here that the cross-compilation environment will be residing in the /home/S390 directory. If a different location is required, the instructions below will need some tweaking wherever /home/S390 is mentioned.

Rather than downloading the entire set of independent patches from the IBM DeveloperWorks site, we are providing a unified patch for the various kernel releases that we have tried. Note that the instructions work fine also if you choose to go with the independent patches from IBM. You just have to apply a whole bunch of them rather than a single big one.

It is also assumed that the instructions are executed as root.

Create a download/source directory

Create the directory /home/S390/usr/src as download location for source code and patches. This will also be the place where the cross-compilation tools will be compiled from.

Download everything that will be needed

The following files need to be retrieved. The sites (and links) below are the main locations to download the files from. It is usually better and faster to use alternate mirror locations for the actual download. Make sure that the files are placed in the /home/S390/usr/src directory during the download.

Extract the source code

The source code packages should be extracted in the directory where they got placed during the download (/home/S390/usr/src). At this time the various patches should also be applied to the base source code.

Binary utilities (binutils)

Use the following set of commands to extract and patch the binutils sources:

	tar -zxpSf binutils-2.11.90.0.27.tar.gz
	tar -zxpSf binutils-2.11.90.0.27-s390.tar.gz
	tar -zxpSf binutils-2.11.90.0.27-s390-1.tar.gz
	cd binutils-2.11.90.0.27
	patch -p1 < ../binutils-2.11.90.0.27-s390.diff
	patch -p1 < ../binutils-2.11.90.0.27-s390-1.diff
	patch -p1 < ../binutils-2.11.90.0.27-s390magic.diff

GNU Compiler Collection (gcc)

Use the following set of commands to extract and patch the gcc sources:

	tar -zxpSf gcc-2.95.3.tar.gz
	tar -zxpSf gcc-2.95.3-s390.tar.gz
	tar -zxpSf gcc-2.95.3-s390-1.tar.gz
	tar -zxpSf gcc-2.95.3-s390-2.tar.gz
	cd gcc-2.95.3
	patch -p1 < ../gcc-2.95.3-s390.diff
	patch -p1 < ../gcc-2.95.3-s390-1.diff
	patch -p1 < ../gcc-2.95.3-s390-2.diff

GNU C Library (glibc)

Use the following set of commands to extract and patch the glibc sources:

	tar -zxpSf glibc-2.2.4.tar.gz
	tar -zxpSf glibc-2.2.4-s390.tar.gz
	tar -zxpSf glibc-2.2.4-s390-1.tar.gz
	cd glibc-2.2.4
	tar -zxpSf ../glibc-linuxthreads-2.2.4.tar.gz
	patch -p1 < ../glibc-2.2.4-s390.diff
	patch -p1 < ../glibc-2.2.4-s390-1.diff

Linux kernel

Use the following set of commands to extract and patch the Linux kernel sources:

	tar -IxpSf linux-2.2.16.tar.bz2
	gunzip linux-2.2.16-s390.diff.gz
	mv linux linux-2.2.16
	ln -s linux-2.2.16 linux
	cd linux-2.2.16
	patch -p1 < ../linux-2.2.16.diff

If you are using any of the alternative Linux kernel sources and patch, just substitute the version number in place of 2.2.16 in the above instructions.

Install the binary utilities

Use the following set of commands to configure and compile the binary utilities to generate S/390 executables and libraries:

	mkdir obj-binutils
	cd obj-binutils
	../binutils-2.11.90.0.27/configure --prefix=/home/S390 \
					   --target=s390-ibm-linux \
					   --host=i386-pc-linux
	make
	make install
	cd ..

Install the GNU Compiler Collection

Use the following set of commands to configure and compile the GNU Compiler Collection (ignore the error while trying to compile libiberty):

	mkdir obj-gcc
	cd obj-gcc
	../gcc-2.95.3/configure --prefix=/home/S390 \
				--enable-languages="C" \
				--enable-shared \
				--enable-threads \
				--with-newlib \
				--target=s390-ibm-linux \
				--host=i386-pc-linux
	make
	make install
	cd ..

Configure the Linux kernel

The kernel source code needs to be configured before the GNU C Library can be compiled. In addition, the GNU Compiler Collection cannot be compiled in its final version without the GNU C Library being in place.

First go into the Linux kernel source hierarchy:

	cd linux-2.2.16

Now modify the top level Makefile to hard code the architecture identifier (ARCH) to have the value s390. Then set the CROSS_COMPILE variable to the value s390-ibm-linux-.

Now configure the kernel:

	make menuconfig

Copy the Linux kernel header files

Use the following set of commands to copy the Linux kernel header files to the cross-compilation environment:

	cp -ra include/linux /home/S390/usr/s390-ibm-linux/include/linux
	cp -ra include/asm-s390 /home/S390/usr/s390-ibm-linux/include/asm
	cd ..

Install the GNU C Library

Use the following set of commands to configure and compile the GNU C Library:

	mkdir obj-glibc
	cd obj-glibc
	../glibc-2.2.4/configure --prefix=/home/S390/s390-ibm-linux \
				 --host=s390-ibm-linux \
				 --build=i386-pc-linux \
				 --enable-omitfp \
				 --enable-add-ons=linuxthreads
	make
	make install
	cd ..

Install the final GNU Compiler Collection

Use the following set of commands to configure and compile the final GNU Compiler Collection:

	cd obj-gcc
	../gcc-2.95.3/configure --prefix=/home/S390 \
				--enable-languages="C,C++" \
				--enable-shared \
				--enable-threads \
				--target=s390-ibm-linux \
				--host=i386-pc-linux
	make
	make install
	cd ..

Compile the Linux kernel

Use the following set of commands to compile the Linux kernel for S/390 using the cross-compilation environment. The specification of the INSTALL_MOD_PATH variable in the last command is important to ensure that the modules are copied to a location within the cross compilation environment rather than to the host system.

	cd linux-2.2.16
	make image
	make modules
	make modules_install INSTALL_MOD_PATH=/home/S390
	cd /home/S390/lib/modules
	tar -zcpSf mods-2.2.16.tgz ./2.2.16

And then...

And finally... the files you need to copy to the S/390 system are:

	/home/S390/usr/src/linux/arch/s390/boot/image
	/home/S390/usr/src/linux/System.map
	/home/S390/lib/modules/mods-2.2.16.tgz