FORUMS
Remove All Ads from XDA

[GUIDE] Compile CM from source, source basics & FAQ - Very detailed and noob friendly

2,282 posts
Thanks Meter: 7,159
 
By galaxyfreak, Recognized Contributor on 23rd February 2013, 10:20 PM
Post Reply Email Thread
Hey guys, I know there is already a tutorial about compiling CyanogenMod by sakindia123 but it requires basic Linux knowdlegde and he missed some things. I wrote this tutorial very detailed and simple.

This Guide have 4 parts:

Quote:

1. How to compile CyanogenMod from source
2. Hardware Requirments and using SWAP memory
3. CyanogenMod source and device tree basics
4. FAQ

Before we start, I would like to thank these guys:

sakindia123, derefas, lirokoa, cute_prince - for amazing work on CM7-10.1 and Kernel 3.0

Nihar G. and bhargz16 that never refused to help me


How to compile CyanogenMod from source

Lets assume you are new in Linux world and you just installed a fresh Ubuntu installation.

I will use:
- Ubuntu 12.10 64bit
- CyanogenMod 10.1 (sakindia123 device tree) - because its newest, and currently WIP, so its exciting to get new bulid with something fixed before release!
- Kernel 3.0.16 for Pico (sakindia123 github tree)

Lets get it started.

1. Open the Terminal (Press CTRL+ALT+T).

2. Get rid of administrator permissions ****.
Type:

Quote:

sudo su

then type your password you set up during Ubuntu installation (password will be invisible) and hit enter

3. Download, install and setup Java:

Quote:

add-apt-repository ppa:webupd8team/java

apt-get update

apt-get install oracle-java6-installer

apt-get install oracle-java6-set-default



4. Install a needed packages:

Quote:

apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev \
libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown \
libxml2-utils xsltproc pngcrush gcc-multilib lib32z1 schedtool

5. Download a Google Repo tool. Type these commands:

Quote:

mkdir ~/bin

curl http://commondatastorage.googleapis....downloads/repo > ~/bin/repo

chmod a+x ~/bin/repo

6. Reboot your computer. (No need for sudo su after reboot)

If you are building for HTC Explorer

7. Initalize the CyanogenMod 10.1 repository (with included pico stuff):

Quote:

mkdir -p ~/CM10.1/android/system

cd ~/CM10.1/android/system

PATH=~/bin:$PATH

repo init -u git://github.com/TeamPico/manifest -b cm-10.1

8. Start source downloading (repository syncing):
Quote:

repo sync

9. Get Terminal Emulator prebulit APK:

Quote:

cd ~/CM10.1/android/system/vendor/cm/
./get-prebuilts

10. Start compiling bulid!

Quote:

. build/envsetup.sh

brunch cm_pico-userdebug -jX

X is a number of your CPU cores + 1 or 2

Your bulid will be located at /CM10.1/android/system/out as cm-10.1-year/month/date-UNOFFICIAL-pico.zip


If you are building for other devices

7. Initalize the CyanogenMod 10.1 repository:

Quote:

mkdir -p ~/CM10.1/android/system

cd ~/CM10.1/android/system

PATH=~/bin:$PATH

repo init -u git://github.com/CyanogenMod/android.git -b cm-10.1

8. Start source downloading (repository syncing):
Quote:

repo sync

9. Get Terminal Emulator prebulit APK:

Quote:

cd ~/CM10.1/android/system/vendor/cm/
./get-prebuilts


How to get vendor, kernel, and device tree - search for developers github, its ofter mentioned on dev-thread or his xda profile..

manufacturer - htc, samsung,lge...
codename - device model codename (codename you can easily find on name of github repos of device tree,vendor and kernel)

Examples:

Explorer - pico
Desire - bravo
Galaxy Mini - tass
Galaxy Mini 2 - jena
Nexus 4 - mako

For some devices, example some LGs it can be model number like LG Optimus Me - p350

10. Setup a vendor tree:

Quote:

Download the vendor tree and extract proprietary folder inside <something>-master folder in archive to /CM10.1/android/system/vendor/manufacturer/codename (you need to manually create folders)

11. Setup a device tree:

Quote:

Download the device tree and extract files and folders inside <something>-master folder in archive to /CM10.1/android/system/device/manufacturer/codename (you will need to manually create folders)

12. Setup a kernel source:

Quote:

Download the kernel source and extract files and folders inside <something>-master folder in archive to /CM10.1/android/system/kernel/manufacturer/codename (you will need to manually create folders)

13. If you are building for older device you will probably need to add display legacy support, as it's dropped in CM10.1:

Quote:

Download the legacy display zip and extract files and folders inside android_hardware_qcom_display-legacy-cm-10.1 folder in archive to /CM10.1/android/system/hardware/qcom/display-legacy folder (you will need to manually create folder)

14, If you are building qualcomm (msm) device, apply singleton.h patch

Type in Terminal:
Quote:

cd ~/CM10.1/android/system/frameworks/native

git fetch http ://review.cyanogenmod.org/CyanogenMod/android_frameworks_native/refs/changes/69/30269/1 && git format-patch -1 --stdout FETCH_HEAD

(delete space between http and :

15. Start compiling bulid!

Quote:

. build/envsetup.sh

brunch cm_codename-userdebug -jX

X is a number of your CPU cores + 1 or 2

Your bulid will be located at /CM10.1/android/system/out as cm-10.1-year/month/date-UNOFFICIAL-codename.zip


If I missed something, feel free to report!
The Following 71 Users Say Thank You to galaxyfreak For This Useful Post: [ View ] Gift galaxyfreak Ad-Free
 
 
23rd February 2013, 10:21 PM |#2  
galaxyfreak's Avatar
OP Recognized Contributor
Flag Split
Thanks Meter: 7,159
 
More
Hardware Requirments and using SWAP Memory

Compiling uses alot of CPU power, but when you run out of RAM memory, you will get "Killed." error. No, you dont need to buy more RAM. You can use SWAP. Quickest and easiest way is to format USB drive to linux-swap and enable SWAP.

Less than 4GB of RAM - You will need SWAP

4GB - Just enough, but if you want to do something other on PC during compiling, its recommemend to make SWAP, just in case.

More than 4GB - You dont need SWAP.

1. Optionally, Copy your USB files to PC as a backup.
2. Go to GParted (preinstalled on Ubuntu)
3. Right-click on your USB drive -> Format -> linux-swap
4. Right-click on your USB drive -> Swap-on
5. Done!

After you are done right-click on your USB drive -> Swap-off, reformat your partition to FAT32 or NTFS and restore data you copied before (if you have any)
The Following 26 Users Say Thank You to galaxyfreak For This Useful Post: [ View ] Gift galaxyfreak Ad-Free
23rd February 2013, 10:21 PM |#3  
galaxyfreak's Avatar
OP Recognized Contributor
Flag Split
Thanks Meter: 7,159
 
More
CyanogenMod Source and Device Tree basics


Basic source folders:

/packages - apps
/frameworks - framework (UI look)
/kernel - kernel source folder when using inline kernel buliding (can be changed in BoardConfig.mk, and I'm going to explain that later in this post)
/device - device config
/hardware - drivers for display. audio etc...

What is BoardConfig?

It's a file where you setup pathes to files and enable/disable stuff, its very easy to understand - https://github.com/sakindia123/cm10....BoardConfig.mk

--

How to use prebulit kernel:

1. Unpack boot.img using boot image tools (check sakindia123's compiling tutorial for step-by-step unpacking boot.img)
2. Rename zimage to 'kernel'
3. Put it in any folder u like you like (example: /prebulitkernel)
4. In BoardConfig.mk add this:

Quote:

TARGET_PREBUILT_KERNEL := /prebulitkernel/kernel

and comment out these lines:

TARGET_KERNEL_SOURCE := kernel/htc/pico
TARGET_KERNEL_CONFIG := pico_defconfig
TARGET_KERNEL_CUSTOM_TOOLCHAIN := arm-eabi-4.4.3

5. Done!

--

How to remove ringtones, video editor, CM wallpapers from bulid:

1. Go to device/releasetools/extras.txt
2. Delete anything you don't want/doesn't need. So easy

--

Where are "bulid.prop tweaks"?

bulid.prop settings is located in device/system.prop

--

What is pico.mk?

In pico.mk (device/pico.mk) you can:
- define what libs (drivers) will be compiled (PRODUCT_PACKAGES)

- add prebulits (PRODUCT_COPY_FILES)
you add them in format: path-to-file-in-source: path-to file in compiled bulid (zip),
example: device/htc/pico/prebuilt/etc/media_codecs.xml:system/etc/media_codecs.xml

- change some usb settings (ADDITIONAL_DEFAULT_PROPERTIES)

- play with some "misc" settings
(PRODUCT_PROPERTY_OVERRIDES)

- Set default resolution (PRODUCT_AAPT_CONFIG := ... and PRODUCT_AAPT_PREF_CONFIG := ...)


I'm not an expert, If I made some mistake, feel free to report, or tell if you have something interesting I can add!
The Following 29 Users Say Thank You to galaxyfreak For This Useful Post: [ View ] Gift galaxyfreak Ad-Free
23rd February 2013, 10:22 PM |#4  
galaxyfreak's Avatar
OP Recognized Contributor
Flag Split
Thanks Meter: 7,159
 
More
FAQ
Frequently asked questions


Q: What's the repository size?
A: CM9 - 4.9GB
CM10 - 9.6GB
CM10.1 - cca. 16GB

Q: Can I compile any other ROM than CyanogenMod with this tutorial?
A: Yes, you will need to, of course, repo init other repo, and maybe change few things in device tree, and probably you can skip part with adding legacy display and patching singleton.

Q: I have "_____ command not found error."

A: Make sure you done all steps, are you in right directory, and did you downloaded all packages.

Q: I have "Killed." error during compiling.
A: Check if you met have enough RAM (read 2nd post of this thread)

Q: I have any other error during compiling
A: Post your problem on this thread
The Following 18 Users Say Thank You to galaxyfreak For This Useful Post: [ View ] Gift galaxyfreak Ad-Free
23rd February 2013, 10:23 PM |#5  
#define's Avatar
Senior Member
Thanks Meter: 2,203
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source
Nice work bro...

Sent from my Nexus 7
The Following User Says Thank You to #define For This Useful Post: [ View ] Gift #define Ad-Free
23rd February 2013, 10:43 PM |#6  
hsn97's Avatar
Senior Member
Flag Karachi
Thanks Meter: 472
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
Great work bro, very helpfull! :thumbup:

Sent from my HTC Explorer A310e using xda app-developers app
23rd February 2013, 11:27 PM |#7  
Senior Member
Thanks Meter: 31
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
Cm10 will complile on 32 bit system?

Sent from my HTC Explorer A310e using xda app-developers app
23rd February 2013, 11:28 PM |#8  
#define's Avatar
Senior Member
Thanks Meter: 2,203
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
Quote:
Originally Posted by wmapt

Cm10 will complile on 32 bit system?

Sent from my HTC Explorer A310e using xda app-developers app

no rom will compile on 32 bit system... you can only compile kernels on 32 bit systems..

Sent from my Nexus 7
The Following User Says Thank You to #define For This Useful Post: [ View ] Gift #define Ad-Free
24th February 2013, 12:17 AM |#9  
Red Devil's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 2,538
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
Awesome work bro. Glued to this thread. BTW ICS and higher require 64 bit right ?

Sent from my HTC Explorer A310e using xda app-developers app
24th February 2013, 12:29 AM |#10  
galaxyfreak's Avatar
OP Recognized Contributor
Flag Split
Thanks Meter: 7,159
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
Quote:
Originally Posted by akshat.shenoy

Awesome work bro. Glued to this thread. BTW ICS and higher require 64 bit right ?

Sent from my HTC Explorer A310e using xda app-developers app

Tnx. AFAIK Yes.

Sent from a chocolate cake.
24th February 2013, 01:49 AM |#11  
abhiparmar92's Avatar
Senior Member
Flag Gujarat,Valsad
Thanks Meter: 83
 
More
Re: [TUT][REMAKE] Compile CyanogenMod from source - Very detailed and noob friendly
+1 brooo,
How much size of the stuffs like repository and other things u mention to download in various steps....based on that I can manage to download.....

Sent from my HTC Explorer A310e using xda premium
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes