Android Aosp Build

build Galaxy Nexus 4.2.2_r1(Jelly Bean API 17)

background

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?

https://source.android.com/source/build-numbers.html

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)

https://source.android.com/source/building-kernels.html

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/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
sudo apt-get install libswitch-perl
set up repo
mkdir -p ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/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 https://android.googlesource.com/platform/manifest -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 https://source.android.com/source/initializing.html instructed:

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

this page explains the proprietary files: *https://source.android.com/source/building-devices.html**,
you get them from: https://developers.google.com/android/nexus/drivers

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

run the following wget:

172 wget https://dl.google.com/dl/android/aosp/broadcom-maguro-jdq39-8edbeae8.tgz
  175  wget https://dl.google.com/dl/android/aosp/imgtec-maguro-jdq39-bb3c4e4e.tgz
  176  wget https://dl.google.com/dl/android/aosp/invensense-maguro-jdq39-5eeb2d51.tgz
  177  wget https://dl.google.com/dl/android/aosp/nxp-maguro-jdq39-a20a2cd1.tgz
  178  wget https://dl.google.com/dl/android/aosp/samsung-maguro-jdq39-556fc2c7.tgz
  179  wget https://dl.google.com/dl/android/aosp/widevine-maguro-jdq39-62276b32.tgz

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/BoardConfig.mk has a line to include non-open source parts.

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

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

$(call inherit-product-if-exists, vendor/nxp/pn544/nxp-pn544-fw-vendor.mk)
$(call inherit-product, hardware/ti/omap4xxx/omap4.mk)
$(call inherit-product-if-exists, vendor/ti/proprietary/omap4/ti-omap4-vendor.mk)
$(call inherit-product-if-exists, vendor/samsung/tuna/device-vendor.mk)
build source
cd ~/work
source build/envsetup.sh 
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

https://source.android.com/source/building-kernels.html

check the right kernel version & source commit
mkdir ~/kernel // DON'T put the kernel directory under ~/work.
cd ~/kernel
git clone https://android.googlesource.com/device/samsung/tuna 
// according the top table in page https://source.android.com/source/building-kernels.html, <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 https://source.android.com/source/building-kernels.html, omap project is the project for Galaxy Nexus.
git clone https://android.googlesource.com/kernel/omap.git  
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 https://source.android.com/source/building-kernels.html, tuna_defconfig is the Build configuration. the file is actually  
                               // in  ~/kernel/omap/arch/arm/configs/tuna_defconfig

make

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/post_process_props.py 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/device.mk has some conditions:

ifeq ($(TARGET_PREBUILT_KERNEL),)
  LOCAL_KERNEL := device/samsung/tuna/kernel
else
  LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
endif

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:

https://developers.google.com/android/nexus/images

  • get it by back up from a real device:

http://forum.xda-developers.com/galaxy-nexus/development/tutorial-complete-galaxy-nexus-kernel-t2174868

+++++++ 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 "ro.secure=1" to "ro.secure=0".
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:

wget https://dl.google.com/dl/android/aosp/hammerhead-krt16m-factory-bd9c39de.tgz
tar xzf hammerhead-krt16m-factory-bd9c39de.tgz
cd hammerhead-krt16m
unzip image-hammerhead-krt16m.zip

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/
or
mkyaffs2image sys/ ./new.img

Now you can simply type:

fastboot flash system new.img

Flash

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

~/work/device/samsung/tuna

would consist of the following make files:

1. Android.mk - 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. AndroidProducts.mk - basically it includes the device associated mk file. this creates one level of loose coupling

PRODUCT_MAKEFILES := \
    $(LOCAL_DIR)/full_tuna.mk

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

$(call inherit-product, device/samsung/tuna/device.mk)

# Set those variables here to overwrite the inherited values.
PRODUCT_NAME := full_tuna
PRODUCT_DEVICE := tuna
PRODUCT_BRAND := Android
PRODUCT_MODEL := Full AOSP on Tuna

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

5. BoardConfig.mk - 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.

mkimage.sh及cpio打包过程分析

http://blog.chinaunix.net/uid-26009923-id-4068594.html

references:

http://astro.temple.edu/~tue68607/resume/articles/customized-android-aospsystem-nexus4.html
http://nosemaj.org/howto-build-android-kitkat-nexus-5
http://stackoverflow.com/questions/11352709/android-device-configuration-for-aosp

build errors

mmm或mm出现以下提示的解决方法:
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’.
之间已经build并且没有改动,所以没有什么工作要做。

解决:
去相应的out文件夹下删掉生成文件,
或者修改要build的文件。

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