Friday, June 24, 2011

kernel development using Eclipse (OMAP4 pandaboard + 2.6.35 + Android)

Working with kernel sources

Just found out that guys in my team are using all different editors for kernel code debugging - and all not very effective enough... Of course the best solution IMHO is till gvim + ctags, but if you wish something more fancy :) you can go with Eclipse - so I've tried to set it up on my fresh Ubuntu 11.04 x64

1. Download and install toolchain
For the reasons unknown I have decided to use Linaro toolchain for my games. According to Linaro HOWTO this is as simple as entering one command for natty:
  sudo apt-get install gcc-arm-linux-gnueabi
of course, I have all my Ubuntu build tools preinstalled.

2. Download the kernel sources
Since I am going to use OMAP4 pandaboard with 2.6.35 kernel on Android - I am following instructions on OMAPpedia wiki to pull the kernel:

  git clone git:// kernel
  git checkout -b p-android-omap-2.6.35_local remotes/origin/p-android-omap-2.6.35

Before building the kernel with latest Linaro toolchain I need to apply a patch that resolves binutils architecture issues with 2.6.35 kernel.

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 884eb1f..6854066 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -30,8 +30,10 @@ obj-$(CONFIG_HOTPLUG_CPU) += omap-hotplug.o
  obj-$(CONFIG_ARCH_OMAP4) += omap44xx-smc.o omap4-common.o \

-AFLAGS_omap44xx-smc.o :=-Wa,-march=armv7-a
+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_omap-headsmp.o :=-Wa,-march=armv7-a$(plus_sec)
+AFLAGS_omap44xx-smc.o :=-Wa,-march=armv7-a$(plus_sec)
 # Functions loaded to SRAM
 obj-$(CONFIG_ARCH_OMAP2420) += sram242x.o

 obj-$(CONFIG_ARCH_OMAP2430) += sram243x.o
@@ -69,6 +71,7 @@ obj-$(CONFIG_OMAP_SMARTREFLEX_CLASS1P5) += smartreflex-class1p5.o

 AFLAGS_sleep24xx.o :=-Wa,-march=armv6
 AFLAGS_sleep34xx.o :=-Wa,-march=armv7-a
+AFLAGS_sleep44xx.o :=-Wa,-march=armv7-a$(plus_sec)

 ifeq ($(CONFIG_PM_VERBOSE),y)
 CFLAGS_pm_bus.o += -DDEBUG

diff --git a/security/smc/omap4/Makefile b/security/smc/omap4/Makefile
index af345a1..af545a2 100644
--- a/security/smc/omap4/Makefile
+++ b/security/smc/omap4/Makefile
@@ -38,4 +38,7 @@ tf_driver-objs += tf_comm_mshield.o
 tf_driver-objs += tf_device_mshield.o
 tf_driver-objs += bridge_pub2sec.o

+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_bridge_pub2sec.o :=-Wa,-march=armv7-a$(plus_sec)

This was already fixed on the latest kernels, refer to this thread for details. If you are using CodeSourcery toolchain referred in OMAPpedia wiki - you don't need it.
Compile the kernel with pandaboard defconfig (as per latest available L27.12.1-P2 release notes) with modified toolchain

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- distclean
  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- android_4430_defconfig
  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage

Later we will need to follow full instructions - patches, folders, environment variables, but to start working with kernel this should be pretty enough.

3. Download and install Eclipse
I prefer not to use one that is supplied with Ubuntu so I am just downloading Eclipse IDE for C/C++ Linux Developers 64-bit  from Prefer to keep it in the opt folder usually...

  cd /opt
  sudo mkdir eclipse
  sudo chmod a+rwx eclipse
  tar -xvzf ~/Downloads/eclipse-linuxtools-indigo-incubation-linux-gtk-x86_64.tar.gz 

There is an ugly bug in the latest eclipse when it crashes during index rebuilding so I had to use a workaround offered by Marc-Andre Laperle with adding
to eclipse.ini file. Probably I will also need to increase the maximum memory usage limitations later.

4. Configuring Eclipse to work with Linux kernel
Some time ago I used to use one python script to generate kernel symbols for the .project file, but today I have found a very nice article on how to correctly index kernel with Eclipse on the wiki. My customizations:
  • Step 14: since we are doing cross compilation, I need to add custom build variables in the corresponding menu of the C/C++ Build options. Add ARCH with value arm and CROSS_COMPILE with value arm-linux-gnueabi- to all configurations. Maybe I will need to add some compiler options later here, but for now it is quite enough
  • Step 15: use arm-linux-gnueabi-gcc for compiler command
  • Step 25: here I have arch/arm/include, also I had to add arch/arm/plat-omap/include and arch/arm/mach-omap2/include
  • Step 33: here I have everything except arch/arm
  • Additionally in C/C++ Build options I am setting Build target in the Behavior tab to uImage and Build command in the Builder Settings tab to make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE}
  • In the end you will need to clean and rebuild from Eclipse to get the list of issues 
Your Eclipse is ready to work with OMAP4 2.6.35 Android kernel code. Enjoy...


Artem Mygaiev said...

BTW, TI has 2.6.39 kernel already available and 3.0RC in development

Artem Mygaiev said...

Update: Eclipse memory configuration changes for my 4GB HP z200:

id said...

hooray!!! Linux is the easiest environment to ... have sex :)

wcunning said...

I think that the marriage of the two solutions (gvim and eclipse) can be found here: Give it a try sometime, it's truly a beautiful tool.

Artem Mygaiev said...

Nice! I really love to use gvim, will try integrating it