简体   繁体   中英

How to debug my Cross compiled Linux Kernel?

I 've cross compiled a Linux Kernel (for ARM on i686 - using Cross-LFS). Now I'm 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 shows this line and waits for infinite time !!

Uncompressing Linux... done, booting the kernel.

So, I want to debug the kernel, so that I can study what exactly is happening.

I'm new to these kernel builds, Can someone please help me to debug my custom built kernel as it is not even showing anything after that statement. Is there any possibility of the kernel being broken? ( I dont think so, b'se it didnot give any error while compiling )

And my aim is to generate a custom build very minimal Linux OS. Any suggestions regarding any tool-chains etc which would be easy & flexible depending on my requirements like drivers etc.,

ThankYou

You can use GDB to debug your kernel with QEMU you can use -s -S options. If you want a simple and reliable toolchain, you can use ELDK from DENX (http://www.denx.de/wiki/DULG/ELDK).

You can install it like this (It's not the last version, but you got 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 necessary)

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

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

The command above should install the toolchain under $HOLE/EMBEDDED_TOOLS/ELDK (modify it if you need)

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

You can then see the version of your ARM toolchain like this:

arm-linux-gcc -v

You can test a hello_world.c program like this:

arm-linux-gcc hello_world.c -o hello_world

And you type: file hello_wrold to see the target architecture of the binary, it should be something 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 suggest using busybox ) and if you want just one for testing now, try this steps:

  1. Create a script to set 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 PATH ARCH CROSS_COMPILE

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

  1. Download a linux kernel and unzip it (Let's assume 2.6.x, it's an old kernel, but there are a lot of chances that it work without compilation errors).

Inside your unzipped kernel:

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

Here we use versatile chip, you may need to use make menuconfig to modify the option OABI and set it to ARM EABI , this option is under Kernel features menu

After all this steps, you can compile you kernel:

make

if you want verbose compilation make v=1

After this you got your kernel under arch/arm/boot/zImage .

Hope this help.

Regards.

I would suggest to build your kernel by activating the option in the section Kernel hacking of your configuration file. Then you may use kdb or kgdb which is easier to use but requires another machine running gdb .

`

You can also connect Qemu and GDB. Qemu has the -s and -S options that run a GDB server and allow you to connect to it via TCP to localhost:1234. Then you can load your kernel image (the unzipped one) in GDB and see how far your kernel boots.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM