Friday, January 2, 2009

Linux kernel development using Eclipse/CDT and QEMU

Steps to build, install and run Linux kernel using QEMU.
  • Download Linux kernel tree
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6.git
  • Update Linux kernel tree
$ cd linux-2.6.git
$ git pull
  • Prepare to build Linux kernel by reusing old Linux kernel config
$ cp /boot/config-`uname -r` .config
$ make oldconfig
  • View Linux kernel config
$ make menuconfig
  • Build Linux kernel
$ make
  • Install Linux kernel modules
$ make modules_install
  • Install Linux kernel
$ make install
  • Build initial ramdisk
$ update-initramfs -k 2.6 -c
  • Update GRUB
$ update-grub
  • Browse source code
$ cscope -Rk
  • Run new Linux kernel in QEMU
$ qemu -kernel /boot/vmlinuz-2.6 -initrd /boot/initrd.img-2.6 -hda /dev/zero -m 1024
  • In QEMU, enter Ctrl+Alt+2 to get into QEMU monitor
  • To check everything is ok
(qemu) info status

Steps to build and run Linux kernel using Eclipse/CDT and QEMU
  • Install Eclipse/CDT and disable indexer
  • Create new C Makefile project with default location pointing to linux-2.6
  • Build Linux kernel in Eclipse
  • Configure Eclipse debugger to use C/C++ application as vmlinuz, stop on startup at start_kernel(), use gdbserver with connection type tcp/1234
  • Run QEMU with GDB-stub
$ qemu -S -s -kernel /boot/vmlinuz-2.6 -hda /dev/zero -m 1024
  • Run Linux kernel in Eclipse
  • Debug in Eclipse will stop at start_kernel

No comments:

Post a Comment