#################################################################### # Document: HOWTO-BUILD-LINUX-2.4 # Purpose : Document how to build a Linux Kernel for use on an # Acorn StrongARM RiscPC. # Author..: Stuart Winter # Date....: 06-July-2004 # Version : 1.02 #################################################################### ---------------------------------------------- Notes ---------------------------------------------- I have had trouble with building a fully working Linux 2.4.26 kernel with different versions of gcc. Natively I have tried: gcc 3.4.0, gcc 3.4.1: the Kernel can't find the root partition. gcc 3.3.4...........: INIT tries to run mgetty and fails trying to open /dev/console Cross compilations: gcc 3.3.2...........: Without the RapIDE driver A working Kernel was produced; the system booted off a disk on the motherboard IDE. ---------------------------------------------------------------------------------------- Cross compiling a Kernel using gcc 3.3 ---------------------------------------------------------------------------------------- # Don't build a kernel inside scratchbox. But if you *were* to do # so, you'd to something like this: make HOSTCC=host-gcc menuconfig make HOSTCC=host-gcc dep && \ make HOSTCC=host-gcc clean && \ make HOSTCC=host-gcc zImage && \ make HOSTCC=host-gcc modules && \ make HOSTCC=host-gcc modules_install make modules_install INSTALL_MOD_PATH=/tmp/package-kernel ---------------------------------------------------------------------------------------- Cross compiling a Kernel using gcc 3.3 ---------------------------------------------------------------------------------------- # Download the handhelds.org gcc-3.3 ARM toolchain: # cd /tmp # wget http://handhelds.org/download/toolchain/arm-linux-gcc-3.3.2.tar.bz2 # tar jxf arm-linux-gcc-3.3.2.tar.bz2 -C/ # chown -R root.root /usr/local/arm # Update with Kernel version: KVER=2.4.26 export PATH=/usr/local/arm/3.3.2/bin:$PATH PKG=/tmp/package-kernel cd /tmp rm -rf {kernel,package-kernel} mkdir -p {kernel,package-kernel} && cd kernel # Update this path with the one where your ARM kernel bits are (source, patches & config): KPTH=/scratchbox/users/build/home/build/armedslack-current/source/k tar jxf $KPTH/sources/linux-2.4/linux-$KVER.tar.bz2 ln -fs linux-$KVER linux cd linux chown -R root:root . # Apply ARM patches: bzcat $KPTH/sources/linux-2.4/patches/patch-$KVER-vrs1.bz2 | patch -p1 # Install ARMedslack Kernel config file (this is always the latest .config) install -m644 $KPTH/configs/config-riscpc-linux-2.4 .config # RapIDE driver. patch -p1 < $KPTH/sources/linux-2.4/patches/rapide_patch # Apply FastFPE patch (this is in Linux 2.4.27): patch -p1 < $KPTH/sources/linux-2.4/patches/fastfpe.patch # Fix up Makefile so we're compiling for ARM & it knows we're cross compiling: perl -pi -e 's?^ARCH.*=.*?ARCH = arm?;' Makefile perl -pi -e 's?^CROSS_COMPILE.*=.*?CROSS_COMPILE = arm-linux-?;' Makefile # Fix hw/sw FP thing (http://lists.debian.org/debian-arm/2002/07/msg00028.html): grep -lr -- "-mno-cpu" . | xargs sed -i 's?\-mno\-cpu?\ ?g' grep -lr -- "-msoft-float" . | xargs sed -i 's?\-msoft\-float?\ ?g' # Compile Kernel: make oldconfig make dep && make clean && make zImage && make modules # Archive the compiled source (esp useful to shove into /usr/src on # a devbox when building alsa or something else that wants kernel source) ( cd .. tar jcf /scratchbox/users/build/home/build/kernel-riscpc-srcbuilt-$KVER.tar.bz2 . ) # Install Kernel modules into a packageable directory: make modules_install INSTALL_MOD_PATH=$PKG mkdir -p /tmp/package-kernel/{install,boot} install -m644 System.map $PKG/boot/System.map-riscpc-$KVER install -m644 arch/arm/boot/zImage $PKG/boot/zImage-riscpc-$KVER # Now make the package (following the Slackware standard here): install -m644 .config $PKG/install/config-riscpc-$KVER # The description: install -m644 $KPTH/slack-desc $PKG/install # Make symlinks: cd $PKG/boot ln -s System.map-riscpc-$KVER System.map ln -s zImage-riscpc-$KVER zImage cd $PKG chown -R root:root . chmod -R og-w . # Move the libs out of the way -- they go in a/kernel-modules package mv lib /tmp/$$lib makepkg -l y -c y /tmp/kernel-riscpc-$KVER-arm-1.tgz # Now put the libs back (we need them for the a/kernel-modules package): mv /tmp/$$lib lib # Now go into a/kernel-modules and run the build script. # Then take the zImage, copy it to prisere, reboot a devbox, copy the zImage # from prisere and boot it. If it works, put it into !SlackBt and re-zip it. ---------------------------------------------------------------------------------------- Building a kernel natively ---------------------------------------------------------------------------------------- # 03-July-2004 # gcc 3.4 doesn't build a fully functional Kernel - Kernels built with it cannot mount # the root partition unless you compile the path into the Kernel itself # It's easier to cross compile it - see the section above. # Extract the vanilla 2.4 Kernel: KPTH=~/armedslack-current/armedslack-current/source/k cd /usr/src rm -rf linux* tar jxf $KPTH/sources/linux-2.4/linux-2.4.27.tar.bz2 ln -fs linux-2.4.27 linux cd linux # Apply the ARM patches: bzcat $KPTH/sources/linux-2.4/patches/patch-2.4.27-vrs1.bz2 | patch -p1 chown -R root:root . # Install the default config ARMedslack uses: install -m644 $KPTH/config-riscpc .config # You may think that this is a little crazy, having little patch files # but I prefer it this way at the moment. Obviously I'd like one single diff # but I'm not going to maintain such a diff and it's easier (for me) to deal # with single patch rejections than a large one. # # RapIDE driver: patch -p1 < $KPTH/sources/linux-2.4/patches/rapide_patch # Apply FastFPE patch (this will be in Linux 2.4.27): #patch -p1 < $KPTH/sources/linux-2.4/patches/fastfpe.patch # Patch for gcc 3.4. Don't do this for gcc 3.3. # http://sources.redhat.com/ml/crossgcc/2004-05/msg00125.html grep -lr -- "-mshort-load-bytes" . | xargs sed -i 's/\-mshort\-load\-bytes/\-malignment\-traps/g' # Patch keyboard for gcc 3.4: (thanks to Jim Hawkins) ( cd drivers/char patch -p0 < $KPTH/sources/linux-2.4/patches/keyboard.c.patch ) # Patch for vidc for gcc 3.4: (thanks to Jim Hawkins) ( cd drivers/sound patch -p0 < $KPTH/sources/linux-2.4/patches/sound.Makefile.patch ) # Fix hw/sw FP thing (http://lists.debian.org/debian-arm/2002/07/msg00028.html): grep -lr -- "-mno-cpu" . | xargs sed -i 's?\-no\-cpu?\ ?g' grep -lr -- "-msoft-float" . | xargs sed -i 's?\-msoft\-float?\ ?g' # Build: make oldconfig make dep && make clean && \ make LDFLAGS="--no-warn-mismatch" zImage && \ make LDFLAGS="--no-warn-mismatch" modules && \ make modules_install # If building a Kernel version < 2.4.26, copy the fixed ether1.{c,h} # DON'T build a kernel < 2.4.26. #( cd drivers/acorn/net # rm -f ether1.* # cp -fa /tmp/kernel/linux-2.4.26/ether1.{c,h} . ) #( cd arch/arm/kernel # cp -fa /tmp/kernel/linux-2.4.26/fiq.c . )