Android Aosp Build

build Galaxy Nexus 4.2.2_r1(Jelly Bean API 17)


The Galaxy Nexus family is codenamed "tuna". Using fish names in relationship to devices isn't quite new, since in the past we've had goldfish (emulator), trout (G1), mahimahi (Nexus One), herring (Nexus S) and stingray (Xoom).

There are two actual Galaxy Nexus devices, codenamed maguro and toro. Maguro is the GSM/HSPA+ variant, and Toro is the CDMA/LTE variant.
Toro is a bit fatter, hence its name.

In the source tree released yesterday, there are two directories called device/samsung/tuna and device/samsung/maguro. The former contains all the files that are common to both toro and maguro, while the latter contains the maguro-specific files. There's no device/samsung/toro in AOSP yet, that directory will get created when
we release the exact code that actually ships on toro.

which branch to pick for the device?

I choose : JDQ39 android-4.2.2_r1 Jelly Bean Galaxy Nexus, Nexus 7, Nexus 4, Nexus 10
because it works for Galaxy Nexus and many other devices and it is API 17.

build set up (Ubuntu 14.04 64 bit)

Prepare software components
prepare jdk:
sudo apt-get install openjdk-7-jdk
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer

build Galaxy Nexus 4.4.2_r1, we need oracle java6:

sudo update-alternatives --config java
sudo update-alternatives --config javac
install other components:
sudo apt-get install git gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/ /usr/lib/i386-linux-gnu/
sudo apt-get install libswitch-perl
set up repo
mkdir -p ~/bin
curl > ~/bin/repo
chmod a+x ~/bin/repo
init source
mkdir ~/work //work will be the directory to build source. i would prefer the branch name , such as mkdir ~/4.2.2_r1
mkdir -p ~/build/cache
cd ~/work
~/bin/repo init -u -b android-4.2.2_r1
repo sync -j 28
setup environment

vim ~/.bashrc with the following content:

export PATH=~/bin:~/work/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
export USE_CCACHE=1
export CCACHE_DIR=~/build/cache
source ~/.bashrc
./prebuilts/misc/linux-x86/ccache/ccache  -M 50G
Configuring USB Access

edit as instructed:

sudo vim /etc/udev/rules.d/51-android.rules
get proprietary device files:

this page explains the proprietary files: ***,
you get them from:

mkdir ~/work/proprietary 
cd ~/work/propietary

run the following wget:

172 wget
  175  wget
  176  wget
  177  wget
  178  wget
  179  wget

then from command line run the following two lines separately:

for f in *.tgz; do tar xzf $f; done
for extractor_script in *.sh; do bash $extractor_script; done

in the above command line , after you go through the EULAs and type “I ACCEPT”, once for each extractor, you’ll have directory ~/work/proprietary/vendor

mv ~/work/proprietary/vendor ~/work/vendor

How the proprietary parts picked up in build process?

because ~/work/device/samsung/tuna/ has a line to include non-open source parts.

# Use the non-open-source parts, if they're present
-include vendor/samsung/tuna/

and ~/work/device/samsung/tuna/ also includes vendor non open source parts:

$(call inherit-product-if-exists, vendor/nxp/pn544/
$(call inherit-product, hardware/ti/omap4xxx/
$(call inherit-product-if-exists, vendor/ti/proprietary/omap4/
$(call inherit-product-if-exists, vendor/samsung/tuna/
build source
cd ~/work
source build/ 
make clobber  // optional step, to remove all previous build output files.
lunch full_maguro-userdebug
make -j 28

adb/fastboot/emulator tool will be generated under: ~/work/out/host/linux-x86/bin

the images ramdisk.img, boot.img, recovery.img, system.img, userdata.img will be under: ~/work/out/target/product/maguro/

please note, the boot.img/recovery.img generation process picks up a default kernel from: ~/work/device/samsung/tuna/kernel

optional: what if you want to build kernel and use the kernel for your boot.img and recovery.img

check the right kernel version & source commit
mkdir ~/kernel // DON'T put the kernel directory under ~/work.
cd ~/kernel
git clone 
// according the top table in page, <vendor> is samsung, device <name> is tuna.

cd ~/kernel/tuna
git log --max-count=1 kernel

it shows something like:

master@master-desktop:/tmp/tuna$ git log —max-count=1 kernel
commit 8c9a241892d74ecb09c1c9a5eef0848c354f3fb6
Author: Todd Poynor <moc.elgoog|ronyopddot#moc.elgoog|ronyopddot>
Date: Mon Jun 10 18:09:53 2013 -0700

tuna: prebuilt kernel (ashmem deadlock)

fb3c9ac ashmem: avoid deadlock between read and mmap calls

Bug: 9261835
Change-Id: Idee2ef89aa2d1cb88bd39cdadf6f1e1630c2ae40

you will need the value: fb3c9ac

pull the actual kernel source
cd ~/kernel
// according the git clone lists table in page, omap project is the project for Galaxy Nexus.
git clone  
cd ~/kernel/omap
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
git checkout fb3c9ac  // the value  fb3c9ac is what you found in last step.  you can also find all branches here via: git branch -a
make tuna_defconfig // according the top table in page, tuna_defconfig is the Build configuration. the file is actually  
                               // in  ~/kernel/omap/arch/arm/configs/tuna_defconfig


if the build is fine, a new kernel will be generated as ./arch/arm/boot/zImage

use the new kernel for boot.img and recovery.img
export TARGET_PREBUILT_KERNEL=~/kernel/omap/arch/arm/boot/zImage
cd ~/work
make bootimage

it will show output:

Copy: out/target/product/maguro/kernel
Target buildinfo: out/target/product/maguro/root/default.prop
build/tools/ out/target/product/maguro/root/default.prop
Target ram disk: out/target/product/maguro/ramdisk.img
Target boot image: out/target/product/maguro/boot.img

why the above works?
because ~/work/device/samsung/tuna/ has some conditions:

  LOCAL_KERNEL := device/samsung/tuna/kernel

that means if TARGET_PREBUILT_KERNEL is not defined, local kernel will be used, otherwise, the environment variable defined kernel will be used.

what if you build the kernel and what to replace it in an existing boot.img?

+++++++ different ways to get a boot.img

  • If you build the source of AOSP. you can get it from: ~/work/out/target/product/maguro/boot.img
  • get a boot.image from all google factory rom:

  • get it by back up from a real device:

+++++++ replace the kernel

sudo apt-get install abootimg
mkdir /tmp/b
cd tmp/b
// copy the boot.img into here
abootimg -x boot.img
ls -l
vim ./bootimg.cfg

Remove the bootsize property in bootimg.cfg as our kernel image can be larger than the one from the factory image.

Now we can create our boot image by:

abootimg --create myboot.img -f boot.cfg -k [path-to-your-zImage] -r initrd.img

// in our case, the our zImage file is ~/kernel/omap/arch/arm/boot/zImage

Verify the boot image without flashing it:

fastboot boot myboot.img

+++++++ you can also edit the ramdisk too

You can root Android by modify the official ramdisk image. First, un-gzip and un-cpio the official ramdisk image extracted from boot.img.

mkdir ramdisk && cd ramdisk
gunzip -c ../initrd.img | cpio -i

Edit default.prop file in the ramdisk, set "" to "".
Repack the ramdisk:

find . | cpio -o -H newc | gzip > ../myramdisk.gz

Now create the insecure boot image with this ramdisk image, which allows you to login as root.

abootimg --create myboot-rooted.img -f boot.cfg -k [path-to-your-zImage] -r myramdisk.gz
How do I update system image?

Get the factory image release or back from from a device. untar it:

tar xzf hammerhead-krt16m-factory-bd9c39de.tgz
cd hammerhead-krt16m

At this point, you will see the system partition, system.img. To convert it to something mountable, you need to run it through the simg2img tool that is built with AOSP by default. (When you build android, it shows up at $TOP/out/host/linux-x86/bin/simg2img):

mkdir sys
simg2img system.img system.img.raw
sudo mount -o loop -t ext4 system.img.raw sys/

Then you have all your system partition mouned in 'sys' and you can modify whatever you want in 'sys'. For example de-odex apks and framework jars.

Then, create a new flash-able system image. make_ext4fs is available from ~/work/out/host/linux-x86/bin/make_ext4fs

sudo make_ext4fs -s -l 685768704 -a system new.img sys/
sudo umount sys
rm -rf sys

685768704 value is got from the size of ls -l system.img.raw

if not work, try:

sudo ./make_ext4fs -s -l 512M -a system new.img sys/
mkyaffs2image sys/ ./new.img

Now you can simply type:

fastboot flash system new.img


We'll use fastboot to flash the system image. This requires a unlocked bootloader. The default bootloader is locked, but you can turn it to unlocked in the fastboot mode.

~/work/out/host/linux-x86/bin/adb reboot-bootloader 
~/work/out/host/linux-x86/bin/fastboot oem unlock

then flash the images:

cd ~/work/out/target/product/maguro
~/work/out/host/linux-x86/bin/adb flashall -w
or ~/work/out/host/linux-x86/bin/fastboot flash boot myboot-rooted.img

Device specific directory


would consist of the following make files:

1. - this will tell the build system to include and to build sources specifically for your device. See below, for an example. This is dependant on the device and hardware, you could have libsensors, liblight sub-directories under the example device tree, i.e. device/samsung/tuna/libsensors, device/samsung/tuna/liblight, etc.

2. - basically it includes the device associated mk file. this creates one level of loose coupling


3. it defines the product name and includes device specific builds properties.

$(call inherit-product, device/samsung/tuna/

# Set those variables here to overwrite the inherited values.
PRODUCT_NAME := full_tuna

4. - specifies the properties and extras to copy over into the final output. it also handles of vendor non-open source files.

5. - This is the meat of it all, this is where compiler conditional flags are set, partition layouts, boot addresses, ramdisk size, and so on. this file also handles include non-open source parts.



build errors

Terminal log:
No private recovery resources for TARGET_DEVICE xxxxxx
make: Entering directory ‘/xxxxx/android’
make: Nothing to be done for ‘all_modules’.
make: Leaving directory ‘/xxxxx/android’

make: Nothing to be done for ‘all_modules’.


Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License