About| Kernel| Specs| Links

Cross Compiling a Kernel

The first step to building a 64-bit system is building a kernel. Basically, this involves first having or building a compiler toolchain (binutils, gcc, and glibc) that can cross-compile a 64-bit kernel. I created a set of lunar mudules to do this. For non-Lunar users here's a rundown:

binutils-2.15:
  export CFLAGS=''
  export CXXFLAGS=''
  export _POSIX2_VERSION='199209'
  export PATH=$PATH:/opt/x86-64/bin

  ./configure  --prefix=/opt/x86-64 \ 
               --target=x86_64-unknown-linux &&
  make &&
  make install

gcc-3.2.3:
  export CFLAGS='-Dinhibit_libc'
  export CXXFLAGS=''
  export _POSIX2_VERSION='199209'
  export PATH=$PATH:/opt/x86-64/bin

  mkdir gcc-BUILD
  cd gcc-BUILD
  ../gcc-3.2.3/configure    --prefix=/opt/x86-64 \ 
                            --target=x86_64-unknown-linux \ 
                            --enable-languages=c \ 
                            --disable-shared \ 
                            --disable-multilib \ 
                            --enable-threads=single &&
  make -j4 &&
  make install

2.6-kernels-headers:
  FILE=linux-libc-headers-2.6.6.0.tar.bz2
  wget http://ep09.pld-linux.org/~mmazur/linux-libc-headers/${FILE} &&
  tar xvjf ${FILE} &&
  mkdir -p /opt/x86-64/x86_64-unknown-linux/include &&
  cd linux-libc-headers-2.6.6.0 &&
  cp -r include/linux/ include/asm-x86_64/ /opt/x86-64/x86_64-unknown-linux/include &&
  ln -s asm-x86_64 /opt/x86-64/x86_64-unknown-linux/include/asm &&
  chmod -R 755 /opt/x86-64/x86_64-unknown-linux/include/*

glibc-2.3.1:
  wget http://lfs.oregonstate.edu/patches/lfs/5.0/glibc-2.3.2-sscanf-1.patch
  cd glibc-2.3.1
  tar xvjf glibc-linuxthreads-2.3.1.tar.gz
  patch -Np1 -i ../glibc-2.3.2-sscanf-1.patch

  INSTALL_ROOT=$SOURCE_DIRECTORY/glibcroot &&
  mkdir -p $INSTALL_ROOT &&
  cd $INSTALL_ROOT &&

  export CFLAGS=''
  export CXXFLAGS=''
  export _POSIX2_VERSION='199209'
  export PATH=$PATH:/opt/x86-64/bin
  export LD_LIBRARY_PATH=""

  echo 'BUILD_CC=gcc' > configparms
  echo 'CC=x86_64-unknown-linux-gcc' >> configparms

  ../configure --prefix=/opt/x86-64 \ 
               --with-headers=/opt/x86-64/x86_64-unknown-linux/include \ 
               --without-cvs \ 
               --enable-kernel=2.6 \ 
               --enable-add-ons \ 
               --disable-profile \ 
               --build=i686-pc-linux-gnu \ 
               --host=x86_64-unknown-linux &&
  make &&
  make install &&
  ln -s /opt/x86-64/lib/ /lib64

Linux-2.6.6:
    wget http://www.muru.com/linux/amd64/patches/patch-2.6.6-powernow-k8-buggy-bios
    wget http://www.muru.com/linux/amd64/patches/patch-m680x-pcmcia-acpi-fix

    cd linux
    patch -Np1 -i ../patch-2.6.6-powernow-k8-buggy-bios
    patch -Np1 -i ../patch-m680x-pcmcia-acpi-fix

    EXTRAVERSION=`grep -m 1 "EXTRAVERSION =" Makefile`
    sed -i "s/$EXTRAVERSION/$EXTRAVERSION-beta/g" Makefile
    sed -i "s/ARCH\t\t?= \$(SUBARCH)/ARCH=x86_64/g" Makefile
    sed -i "s/CROSS_COMPILE\t?=/CROSS_COMPILE=x86_64-unknown-linux-/g" Makefile

    export CFLAGS=''
    export CXXFLAGS=''
    export _POSIX2_VERSION='199209'
    export PATH=/opt/x86-64/bin:$PATH
    export ARCH=x86_64
    export CROSS_COMPILE=x86_64-unknown-linux-
    
    rm -f arch/x86_64/boot/bzImage

    make bzImage          &&
    make modules          &&
    make modules_install 

    cp arch/x86_64/boot/bzImage /boot/x86_64-${VERSION} 
    cp System.map /boot/System.map-${VERSION}