Skip to content

pw4ever/aosp-hacking-helper

Repository files navigation

Table of Contents generated with DocToc

Android Open Source Project (AOSP) building/testing helper scripts

These scripts help set up AOSP building environment and, with the help of Linux kernel hacking helper, build and test Android emulator (goldfish) kernel and loadable kernel modules (LKMs).

Cheatsheet

One-time setup

mkdir -p $HOME/hacking/aosp
cd $HOME/hacking/aosp
git clone https://github.com/pw4ever/aosp-hacking-helper.git helper
# cd into AOSP source top directory, say, $HOME/project/aosp
$HOME/hacking/aosp/helper/install-links.sh

If you want to use the scripts to build Android emulator kernel (goldfish), go and set up Linux kernel hacking helper at $HOME/hacking/linux-kernel/helper (follow here for setup instructions).

AOSP building routine

Every time, before you start building AOSP, follow the following routine at the top-level directory of your downloaded AOSP source.

# suppose we are at top-level AOSP directory now
bash
source 00routine.sh
lunch aosp_arm-eng # or other lunch combo (tip: use `print_lunch_menu` to see the menu; ${TARGET_PRODUCT}-${TARGET_BUILD_VARIANT}) of your choice

For your convenience, source 00routine.sh will print out this instruction (and the instructions for building goldfish kernel and LKMs).

Build goldfish kernel

To build goldfish kernel, you must download it first (as of May 2014, Android kernel source requires separate download from the main AOSP source repo).

cd $(gettop)/99kernel/
git clone https://android.googlesource.com/kernel/goldfish.git goldfish
cd $(gettop)/99kernel/goldfish/
git checkout -t -b goldfish-3.4 origin/android-goldfish-3.4 # or other version of your choice

# initialize "linux kernel hacking helper" directories ($ARENA has been set up by "source 00routine.sh")
hack_init.sh 10 

Choose the target Kernel arch (ARM, x86_64, or i686) and kernel config you want to merge.

# build onto "linux kernel hacking helper" instance 1, on ARM arch, with 8 parallel jobs, and merging kernel configs for KGDB (kernel debugger) and LKM (loadable kernel module) support
$(gettop)/01build-goldfish-kernel.sh 1 arm 8 ${HOME}/hacking/linux-kernel/helper/config/kgdb ${HOME}/hacking/linux-kernel/helper/config/lkm

# build onto "linux kernel hacking helper" instance 2, on X86_64 arch, with 8 parallel jobs, and merging kernel configs for KGDB (kernel debugger) and LKM (loadable kernel module) support
$(gettop)/01build-goldfish-kernel.sh 2 x86_64 8 ${HOME}/hacking/linux-kernel/helper/config/kgdb ${HOME}/hacking/linux-kernel/helper/config/lkm

# build onto "linux kernel hacking helper" instance 3, on i686 arch, with 8 parallel jobs, and merging kernel configs for KGDB (kernel debugger) and LKM (loadable kernel module) support
$(gettop)/01build-goldfish-kernel.sh 3 i686 8 ${HOME}/hacking/linux-kernel/helper/config/kgdb ${HOME}/hacking/linux-kernel/helper/config/lkm

After building the kernel, the kernel image that can be loaded with emulator -kernel <kernel image> will be found at (take ARM for example, say the "linux kernel hacking helper" instance number is 1 in 01build-goldfish-kernel.sh) ${ARENA}/build/1/arch/arm/boot/zImage.

If you want to test the kernel with a virtual sdcard image, create the sdcard image first:

# create a 200M virtual sdcard image with label "label-test01" as the file "$(gettop)/99stuff/sdcard/test01.img" (the directory has been created by "source 00routine.sh"
mksdcar -l label-test01 200M $(gettop)/99stuff/sdcard/test01.img

Then, we can test the kernel:

emulator -kernel ${ARENA}/build/1/arch/arm/boot/zImage -sdcard $(gettop)/99stuff/sdcard/test01.img &

Build, install, and test a loadble kernel module

To build a LKM, cd into the directory (perhaps create a directory for your module under $(gettop)/99kernel/modules/, e.g., $(gettop)/99kernel/modules/hello/), which has your LKM source. The Makefile/Kbuild should have the usual obj-m += variable definitions; read the good old LDD3 or kernel documentation on this.

# build onto "linux kernel hacking helper" instance 1, on ARM arch, with 8 parallel jobs
$(gettop)/01build-goldfish-module.sh 1 arm 8

After this, you should have (suppose your kernel module has obj-m := hello.o in Makefile/Kbuild) hello.ko in your directory. Now you can push the kernel module onto your emulator instance:

adb -e push hello.ko /data/hello.ko

Then, you can test it with:

# load the module
adb shell insmod /data/hello.ko

# unload the module
adb shell rmmod hello

Build Android framework API JavaDoc documentation

cd $(gettop)
./02build-doc-javadoc.sh 2> /dev/null

Afterwards, the doc will be rooted under $(gettop)/90doc/javadoc/.

Bonus

This is what the build environment (with a running emulator) looks like.

The "Kernel version" and "Build number" show that it is running on my own builds. Also, the adb shell dmesg | tail -3 show that we have successfully loaded and unloaded a test module (loaded by the adb shell session on the right with insmod /data/hello.ko; rmmod hello).

Consider using my awesome config if you like the X Window manager.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages