- Published on
Building CyanogenMod for Google Nexus 4
- Authors
- Name
- Lucas Xu
- @xianminx
Android Derivative ROMs
AOSP
CyanogenMod
Kandroid
MIUI
Aliyun OS
AOKP
Baidu Yi
LeWa OS
OPhone
Replicant
XobotOS
Stock
HTC Sense
Samsung TouchWiz
LG Optimus UI
Sony UI
For more, check Wikipedia.
An excellent video tutorial on Youtube
Components
Hardware driver (proprietary)
Using ./extract-files
to extract vendor drivers from real device.
/media/android/cm/system/device/lge/mako$ ll extract-files.sh
-rwxrwxr-x 1 lucas lucas 354 Nov 18 23:19 extract-files.sh*
This pulls data from device's /system
directory to /vendor/lge/mako/proprietary
directory.
lucas@lucas-ubuntu:/media/android/cm/system/vendor/lge/mako/proprietary$ ll
total 24
drwxr-xr-x 6 lucas lucas 4096 Nov 19 11:29 ./
drwxr-xr-x 3 lucas lucas 4096 Nov 19 10:17 ../
drwxr-xr-x 2 lucas lucas 4096 Nov 19 11:29 bin/
drwxr-xr-x 3 lucas lucas 4096 Nov 19 11:29 etc/
drwxr-xr-x 5 lucas lucas 4096 Nov 19 11:29 lib/
drwxr-xr-x 4 lucas lucas 4096 Nov 19 11:29 vendor/
These include drivers for CPU, NFC from Broadcom, Camera, Sensors, Audio, DRM, Cryptography from LG, and imgs, GSM, Camera, GPS, Wi-Fi, Bluetooth, Sensors, Media, DRM, DSP, USB from Qualcomm. All these drivers are proprietary.
Kernel
The next thing is to build the kernel source. Use breakfast mako
(code name for Nexus 4) to download kernel source code from GitHub.
Android
Building
Environment setup
Ubuntu 64 bit
Android SDK
JDK
Python
Download source
repo
mkdir,
/media/android/cm/system/
CM source file structure
link: http://wiki.cyanogenmod.org/w/Doc:_the_cm_source
bionic
build
bootable: cwm recovery
dalvik
art, replacement of dalvik, android runtime
device, board support packages and configurations for a particular device.
device/<vendor>/<codename>, /device/asus/grouper, device/lge/mako
, where to put customized stuff for each device.breakfast grouper && repo sync
docs: android open source website
external, non-android utilities, with Android.mk to work with android build system
frameworks, Android core
hardware, platform/hardware specific libs
kernel,
/kernel/<vendor>/<codename>
ndk
out, make clobber
packages, Android standalone apps, like Settings, Browser, Launcher, etc
prebuilt(s)
system: linux shell, etc.
vendor: cm, lge, htc, etc
For Nexus 4:
vendor: cm
hardware: ti
kernel: google/msm
device: lge/mako
Repo manifest format
top level ./.repo/default.xml
XML file.
manifest: the root element of the file.
remote: git url shared by one or more projects and the gerrit review server those projects upload changes through.
name: short git remote name
alias: override name if specified in each project's .git/config
fetch: git url prefix for all projects which use this remote
review: gerrit review server used by repo update
default: used when a project does not specify remote and revision.
manifest-server
project: single git repo.
annotation
remove-project
include
Local Manifests
.repo/local_manifests/*.xml
/device/lge/mako/extract-files.sh
adb pull /system/* to /vendor/lge/mako/proprietary
The problems encountered during downloading the cm source
Since the source repo is huge, the downloading process can be intermittent.
- build
breakfast
brunch
lunch
build files
.mk Makefiles /build
Each module/subproject has an Android.mk file, telling the build system how to build the module, and where to put the output in the Android directory.
The built files are put in /out/target/project/CODENAME
, with zipped flashable recovery*.zip
and fastboot*.img
files.
$OUT directory
$OUT= /out/target/project/CODENAME
- kernel
- /system, the /system folder on Android
- /root, contains the files that will be turned into ramdisk loaded and run by the kernel, including init, init.rc, init.CODENAME.rc
- /recovery/root, ramdisk contains the recovery mode
mm: make modules, mm -B
adb sync system
adb remount= adb shell mount -o rw,remount /system
Build Success
/media/android/cm/system/out/target/product/mako
➜ mako ls -la
total 803408
drwxrwxr-x 10 lucas lucas 4096 Nov 19 21:15 .
drwxrwxr-x 3 lucas lucas 4096 Nov 19 18:33 ..
-rw-rw-r-- 1 lucas lucas 19 Nov 19 18:34 android-info.txt
-rw-r--r-- 1 lucas lucas 6436864 Nov 19 21:02 boot.img
-rw-rw-r-- 1 lucas lucas 34552 Nov 19 18:33 clean_steps.mk
-rw-rw-r-- 2 lucas lucas 189761342 Nov 19 21:15 cm-10.2-20131119-UNOFFICIAL-mako.zip
-rw-rw-r-- 1 lucas lucas 120 Nov 19 21:15 cm-10.2-20131119-UNOFFICIAL-mako.zip.md5sum
-rw-rw-r-- 2 lucas lucas 189761342 Nov 19 21:15 cm_mako-ota-3f402468d6.zip
drwxrwxr-x 2 lucas lucas 4096 Nov 19 20:46 data
drwxrwxr-x 4 lucas lucas 4096 Nov 19 18:39 external
drwxrwxr-x 2 lucas lucas 4096 Nov 19 21:10 fake_packages
-rw-rw-r-- 1 lucas lucas 71456 Nov 19 21:13 installed-files.txt
-rwxrwxr-x 1 lucas lucas 5997088 Nov 19 20:36 kernel
drwxrwxr-x 18 lucas lucas 4096 Nov 19 21:13 obj
-rw-rw-r-- 1 lucas lucas 49 Nov 19 21:14 ota_script_path
-rw-rw-r-- 1 lucas lucas 669 Nov 19 18:33 previous_build_config.mk
-rw-rw-r-- 1 lucas lucas 434701 Nov 19 21:01 ramdisk.img
-rw-rw-r-- 1 lucas lucas 3845120 Nov 19 21:03 ramdisk-recovery.cpio
-rw-rw-r-- 1 lucas lucas 2510001 Nov 19 21:04 ramdisk-recovery.img
drwxrwxr-x 3 lucas lucas 4096 Nov 19 21:02 recovery
-rw-r--r-- 1 lucas lucas 8511488 Nov 19 21:04 recovery.img
drwxrwxr-x 9 lucas lucas 4096 Nov 19 21:01 root
drwxrwxr-x 5 lucas lucas 4096 Nov 19 20:59 symbols
drwxrwxr-x 15 lucas lucas 4096 Nov 19 21:01 system
-rw-r--r-- 1 lucas lucas 314466532 Nov 19 21:14 system.img
-rw-r--r-- 1 lucas lucas 100775392 Nov 19 20:46 userdata.img
➜ mako
Flashing
- Flash ClockworkMod recovery img.
fastboot flash recovery recovery.img
- Flash
fastboot -w flashall
Building Kernel
Building kernel from source https://android.googlesource.com/device/lge/mako/
Or, using prebuilt kernel image https://android.googlesource.com/device/lge/mako-kernel/
Device
Proprietary Drivers
Binaries for Nexus Devices
https://developers.google.com/android/nexus/drivers
extract-files.sh
extract-broadcom-mako.sh
Restoring to factory state
Upgrade to Android 4.4 on Nexus 4
https://developers.google.com/android/nexus/images?hl=fr-FR#occamkrt16s
Note: codename for factory image of Nexus 4 is occam.
Android product naming rules.
Questions
http://source.android.com/source/known-issues.html