Skip to content

kernel_build_instructions

dileks edited this page May 5, 2011 · 49 revisions

Intro

This document describes how to build a kernel from lll-project GIT repository. Currently, we support only X86_32 and X86_64 architectures.

PreReq: Toolchain from lll-project

WARNING: Update your toolchain before building the lll-kernel (click here for instructions).

Preps before build

Preps #1: Create a project-directory

PRJ_DIR="$HOME/src/lll-project"
mkdir -p $PRJ_DIR

Preps #2: Clone the kernel repository

cd $PRJ_DIR
git clone https://github.com/lll-project/kernel

Preps #3: Some useful variables

export LANG=C
export LC_ALL=C

MAKE="make"
MAKE_VERBOSE="make V=1"

CC_FOR_BUILD="clang"
HOSTCC_FOR_BUILD="clang"

NOTE-1: Please, adapt /path/to/clang if necessary.

NOTE-2: "make V=1" gives you the full line of each compiler/binutils call which might be helpful to dig into build issues.

Preps #4: Configure kernel-options

cd kernel
cp -v /path/to/kernel-config-file .config
yes "" | $MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD oldconfig

HINT: Use the kernel-config of the running kernel /boot/config-$(uname -r) as .config file.

[ OPTIONAL ]

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD menuconfig

Useful and BROKEN kernel-config options

TODO-1: This list is still incomplete!

TODO-2: Offer "working" kernel-config files for download (be user-friendly as possible)!

Useful DEBUG options

  1. CONFIG_DEBUG_INFO=y (required for gdb)
  2. CONFIG_EARLY_PRINTK=y (helpful for qemu + gdb)

BROKEN options on x86_32

  1. CONFIG_PARAVIRT_GUEST is not set (confirmed by dileks)

BROKEN options on x86_64

XXX: Currently empty

Build and install the kernel

Build and install kernel #1: The normal way

The normal way #1: Build kernel and modules

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD 2>&1 | tee ../make.log

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD modules 2>&1 | tee ../modules.log

OR ALTERNATIVELY:

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD all 2>&1 | tee ../make-all.log

The normal way #2: Install kernel and modules

root# $MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD modules_install 2>&1 | tee ../modules_install.log

root# $MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD install 2>&1 | tee ../install.log

OR ALTERNATIVELY:

root# $MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD all install 2>&1 | tee ../install-all.log

The normal way #3: Initial RAM-Disk

Create Initial RAM-Disk (initrd.img) file:

mkinitramfs -o initrd.img $(make kernelversion)+

Move (and rename) initrd.img to /boot directory:

root# mv initrd.img /boot/initrd.img-$(make kernelversion)+

INFO: "$(make kernelversion)+" results currently in "2.6.38.2-lll+"

NOTE: An Initial RAM-Disk is optional. It highly depends on your kernel-config settings, especially if you build essential parts of the kernel - like the filesystem of the root-partition - as a kernel-module or leave built-in.

The normal way #4: Update bootloader config file (here: grub2)

root# update-grub

Build and install kernel #2: Build with deb-pkg

Some useful variables

export DEBFULLNAME="Sedat Dilek"
export DEBEMAIL="sedat.dilek@gmail.com"

uploader="dileks"

version=$(awk '/^VERSION = / {print $3}' Makefile)
patchlevel=$(awk '/^PATCHLEVEL = / {print $3}' Makefile)
sublevel=$(awk '/^SUBLEVEL = / {print $3}' Makefile)
extraversion=$(awk '/^EXTRAVERSION = / {print $3}' Makefile)
kversion="${version}.${patchlevel}.${sublevel}${extraversion}"

DEBIAN_VERSION="${kversion}-1~${uploader}.1"

Start the build with deb-pkg

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD deb-pkg KDEB_PKGVERSION="${DEBIAN_VERSION}" 2>&1 | tee ../deb-pkg.log

NOTE: This produces linux-image, linux-headers, linux-firmware-image and linux-libc-dev Debian packages.

Build with own EXTRAVERSION

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD EXTRAVERSION="${extraversion}-dbg" deb-pkg KDEB_PKGVERSION="${DEBIAN_VERSION}" 2>&1 | tee ../deb-pkg.log

...which is equivalent to hardcoded EXTRAVERSION:

$MAKE CC=$CC_FOR_BUILD HOSTCC=$HOSTCC_FOR_BUILD EXTRAVERSION=".2-lll-dbg" deb-pkg KDEB_PKGVERSION="${DEBIAN_VERSION}" 2>&1 | tee ../deb-pkg.log

INFO: EXTRAVERSION=.2-lll is currently default.

WARNING: With CONFIG_DEBUG_INFO=y the linux-image Debian package can have a huge filesize (minimal kernel-config: >=40MiB vs. >=8MiB without debug-info)!

Install Debian packages

root# dpkg -i ../linux-image*.deb ../linux-headers*.deb

Archive important files

Find and list important files:

cd kernel
for i in bzImage vmlinux System.map ; do find ./ -name $i -exec ls -l "{}" ";" ; done 

Archive important files:

mkdir ../archive
cp -av arch/x86/boot/bzImage vmlinux System.map ../archive