Home > Articles > Mobile Application Development & Programming

  • Print
  • + Share This
This chapter is from the book

Prebuilt Toolchain and Kernel Source Code

The latest information about how to build an Android kernel using a prebuilt toolchain can be found at https://source.android.com/. Given that AOSP changes from time to time, be aware that the procedure in this chapter is what was available at the time of this book’s writing—and that a newer version may have been released since then.

You can download the prebuilt toolchain from the AOSP git repository using the following command:

$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/
arm/arm-eabi-4.7

It may take a while for this command to complete its work. After the prebuilt toolchain is downloaded, we can set up the path environment variable to include it:

$ export PATH=$(pwd)/arm-eabi-4.7/bin:$PATH

The next step is to get the goldfish kernel source code. We can use the following command to get a copy of kernel from AOSP repository:

$ git clone https://android.googlesource.com/kernel/goldfish.git
$ cd goldfish
$ git branch –a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-goldfish-2.6.29
  remotes/origin/android-goldfish-3.4
  remotes/origin/linux-goldfish-3.0-wip
  remotes/origin/master
$ git checkout -t origin/android-goldfish-2.6.29 -b goldfish

To build the kernel, use the following commands:

$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ make goldfish_armv7_defconfig
$ make

After the build is completed, we have a release build of the goldfish kernel by default.

To debug the kernel, we need to turn on debugging options in the kernel configuration file. To do so, we can either edit the .config file directly or run menuconfig. To run menuconfig, you have to install the package libncurses5-dev first, if you haven’t already installed it:

$ sudo apt-get install libncurses5-dev
$ make menuconfig CROSS_COMPILE=arm-eabi-

After menuconfig starts, we can select Kernel hacking, Compile the kernel with debug info, as shown in Figure 10.1.

Figure 10.1

Figure 10.1 Enabling debugging in menuconfig

An alternative approach, as mentioned earlier, is to edit the .config file directly. In the .config file, we can set CONFIG_DEBUG_INFO=y.

Even though these steps look quite simple, problems may occasionally occur. Yet another alternative is to follow the instructions in Appendix B to set up the development environment and build everything in this book using the Makefile and scripts in the repository build in GitHub.

  • + Share This
  • 🔖 Save To Your Account