Linux – How do I debug my cross-compiled Linux kernel?

How do I debug my cross-compiled Linux kernel?… here is a solution to the problem.

How do I debug my cross-compiled Linux kernel?

I’ve cross-compiled a Linux kernel (for ARM on i686 – using Cross-LFS).
NOW I AM TRYING TO BOOT THIS KERNEL USING QEMU.

$ qemu-system-arm -m 128 -kernel /mnt/clfs-dec4/boot/clfskernel-2.6.38.2 --nographic -M versatilepb

Then, it displays this line and waits for an infinite amount of time!!

Uncompressing Linux... done, booting the kernel.

So, I want to debug the kernel in order to study what’s really going on.

I’m new to these kernel builds, can someone help me debug my custom kernel because it doesn’t even show anything after that statement. Is it possible for the kernel to be corrupted? (I don’t think so because it doesn’t give any error at compile time).

My goal is to build a custom-built very stripped Linux operating system. Any suggestions on any toolchain etc that will be simple and flexible based on my requirements (e.g. drivers, etc.).

Thanks

Solution

You can debug kernels with QEMU using GDB, and you can use the -s -S option. If you want a simple and reliable toolchain, you can use the ELDK for DENX (http://www.denx.de/wiki/DULG/ELDK).

You can install it like this (it’s not the latest version, but you get the idea):

wget http://ftp.denx.de/pub/eldk/4.2/arm-linux-x86/iso/arm-2008-11-24.iso

sudo mkdir -p/mnt/cdrom (if needed).

sudo mount -o loop arm-2008-11-24.iso /mnt/cdrom

/mnt/cdrom/install -d $HOME/EMBEDDED_TOOLS/ELDK/

The above command should install the toolchain under $HOLE/EMBEDDED_TOOLS/ELDK (which can be modified if needed).

echo "export PATH=$PATH:$HOME/EMBEDDED_TOOLS/ELDK/ELDK42/usr/bin" >> $HOME/.bashrc

You can then see the version of the ARM toolchain as follows:

arm-linux-gcc -v

You can test hello_world.c programs like this:

arm-linux-gcc hello_world.c -o hello_world

Then you type :file hello_wrold to see the target schema of the binary, which should look like this:

hello_wrold: ELF 32-bit LSB executable, ARM, version 1 (SYSV)

Now if you want

to compile a production kernel, you need to optimize it (I recommend using busybox), if you just want one for testing right now, try the following steps:

  1. Create a script to set up your chain tool set_toolchain.sh:

    #!/usr/bin/sh

    PATH=$PATH:$HOME/EMBEDDED_TOOLS/ELDK/ELDK42/usr/bin

    ARCH= ARM

    CROSS_COMPILE=arm-linux-gnueabi-

    Export the PATH ARCH CROSS_COMPILE

Then run your script (source./set_toolchain.sh).

  1. Download a Linux kernel and unzip it (assuming 2.6.x, it’s an old kernel, but it most likely works without compilation errors).

In the unzipped kernel:

cd ~/linux-2.6.29/arch/arm/configs
make versatile_defconfig

Here we use a generic chip, you may need to use make menuconfig to modify the option OABI, set to ARM EABI, so that the option is under the Kernel features menu

Once you have completed all these steps, you are ready to compile the kernel:

make

If you want lengthy compilation make v=1

After that, you get your kernel under arch/arm/boot/zImage.

Hope this helps you.

Greeting.

Related Problems and Solutions