Building CyanogenMod for Google Nexus 4

Android Derivative ROMs

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 includes drivers for CPU, NFC fromBroadcom, 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

Enviroment setup

Download source

CM source file structure

link: http://wiki.cyanogenmod.org/w/Doc:_the_cm_source

For Nexus 4:

Repo manifest format

top level ./.repo/default.xml XML file.

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 intermittant




3. build

breakfast
brunch
lunch


build files

.mk
Makefiles
/build

each module/ subproject has a 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 


```sh
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

  1. Flash ClockworkMod recovery img. fastboot flash recovery recovery.img
  2. Flash
fastboot -w flashall

Building Kernel

  1. Building kernel from source https://android.googlesource.com/device/lge/mako/

  2. 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

References

  1. http://source.android.com/devices/index.html
  2. Youtube //www.youtube-nocookie.com/embed/1_H4AlQaNa0?rel=0