Remove All Ads from XDA

Guide to compiling (covers cm7)

15,305 posts
Thanks Meter: 29,233
By sykopompos, Developer Relations/Recognized Developer on 16th January 2011, 12:51 AM
Post Reply Email Thread
This guide is geared to people that are new to ubuntu but would like to start playing with the internals of their android device and maybe even make themselves a rom,

disclaimer: if you break your equipment well that just plain sucks

If you are new to linux or wanna learn more about ubuntu, here is a link to the ubuntu 10.10 wiki and is full of great info

So you got yourself a nice copy of Ubuntu 9.10/10.04/10.10 and you have every intention of building a rom for yourself or maybe you just wanna learn the inside workings of android, well there are a few extra steps for getting it set up in 9.10/10.04. Gonna try to make this an easy transition since most of you are coming from a windows based machine. Make sure that you have at least a 30 gb partition set up to follow along with this guide, more is better but I know some don't have the hard drive space to spare.

So let's get our hands dirty

First we need to set up java and get a few programs, but first we need to open up our software settings, this is achieved by going up to our MENU BAR, going to SYSTEM and then then ADMINISTRATION. We will then go into SOFTWARE SOURCES. On 9.10/10.04, the repository for java 5 was removed so we need to add 9.04's repository. So let's go to our second tab marked “other software” and click ADD. A small box will open up asking us to add a apt line. So we have two software lines to add individually.

(on 10.10 software sources is inside update manager, clicking settings gets you into it)

deb jaunty multiverse


deb jaunty-updates multiverse

Now, make sure that both are checked to be used in software sources and close the window. It should ask to update your sources, allow it to (insert screenshot)

Some people have problems with internal wireless cards so this might be a fix for you which was an issue for me and thankfully Garok89 had the answer. This fix works on Broadcom based cards only (including Dell wireless cards).

For the wireless card (plug in via ethernet of course)

Open up a terminal and type

sudo apt-get install bcmwl-kernel-source bcmwl-modaliases

Reboot and then enable via System>Administration>Hardware Drivers

and see if it now says that you have proprietary drivers now

gingerbread is 64 bit only

Let's open up a pretty little terminal and let's get some debs (debs are Linux distribution specific packages like we have apks in android). After entering this command it will ask you to input the "[sudo] Password for xxxxx", this is the password you use to logon. (When you type your password you will not see anything, this is for security purposes)

sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev sun-java6-jdk gitg qt3-dev-tools libqt3-mt-dev eclipse valgrind

NOTE: If we want to build with a x64-bit system we must also do the following

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl sun-java5-jdk zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev sun-java6-jdk gitg qt3-dev-tools libqt3-mt-dev eclipse valgrind pngcrush wput

It is quite a lot but it will download quickly depending on your internet connection, but almost all are needed, and yes, I did put in both java 5 and 6 because for some reason it helps having both installed side by side.

(don't forget to run update manager again and get your system up to date)

well while we are here we midas well set up our tool for downloading the source


Repo is a tool that makes it easier to work with Git in the context of Android. It is a almost the same as Git and we will go into the differences at a later time

we are gonna make sure that we are in our right directory so

cd ~

~ means home/user dir, so in my case it would be /home/sykopompos/ but using ~ allows us to simplify our use.

Mkdir bin

export PATH=${PATH}:~/bin

by typing echo $PATH we can see the all of what is in our path

curl > ~/bin/repo

to get the repo script

then we give it executable permissions so we can run it as a program

chmod a+x ~/bin/repo

Now we have repo set up we can move on to other things. Let's get going with setting up the android sdk. Let's go to the sdk's page in our web browser

and select the newest linux version and download. When it is finished downloading open it up and extract it to your home/user folder and rename it to androidsdk for guide following ease purposes

next let's set up eclipse

open up eclipse, it will be in your menu bar under programming. just let it save to the workspaces folder that it defaults to and open up the help tab up on the top bar and go down to install new software

and add this line into the open text bar and type this

now click add and in the box down below you will see it says developer tools. Click on the little check box and hit next. You should see android development tools hit next and follow the prompts and wait for it to download and install. You will have to agree to the terms to download, You will get a warning about unsigned content, just say yes. Once it is done click to restart Eclipse then go up to the window tab and go down to preferences, in the new window that pops up, go to android and add in where your android sdk is. Just hit ok and not apply or it will complain.

close out of that window than go down to in the window tab again and go into android sdk and avd manager. Go down to available packages and click on the little check box again. Download all available packages (you can prob get away without downloading anything pre 1.5/cupcake. Let that download and exit out


go up to places on your desktop menu bar and go into your home folder. Press Ctrl and h together on your keyboard to show hidden folders. Anything marked with a . in front of it is hidden, we are looking for a folder name .gnome2, go into it and look for nautilus-scripts. Once inside this folder, right click on a empty space and select create document and then empty file and name it sign. Open up that empty document and copy and paste this script from dumbfaq on xda


# Update the Loc var to where YOU stored the testsign.jar file !



for arg


TMP=$(ls $arg | sed 's/\(.*\)\..*/\1/')


java -classpath "$Loc"testsign.jar testsign "$arg" "$arg"-signed 2> /tmp/signTmp


if [ $SUCCESS -eq 1 ]


zenity --info --title "Sign APK" --text "signing FAILED! \n`cat /tmp/signTmp`"

exit 1


mv $TMP.$EXT-signed $TMP-signed.$EXT


zenity --info --title "Sign APK" --text "signing completed!"

save and exit out and right click on our new script and select properties. select thru the tabs and look for a check box that says allow executing as a program. click on it and now we have a pretty little script that we can just right click on a file and sign with our test keys for flashing. but first we need to download the testsign java file and add it to our androidsdk/tools folder do not extract this just add it to the tools folder.

Last but not least, we need to set up adb

Open up a terminal (you might still have the previous one open, you can use that just make sure you are at ~/) and type

gedit .bashrc

paste this in the top

#AndroidDev PATH
export PATH=${PATH}:~/androidsdk/tools
export PATH=${PATH}:~/androidsdk/platform-tools

save and exit

we will check what our phone's vendor id is, this is helpfull to see if our phone is on the list, with all the growing numbers of new manufacturs producing android it is hard know every vendor's id so type


while your phone is connected to see our vendor id and you will see something like this, if you have a device not listed please send me the vendor id at so i can update in for others

Bus 002 Device 004: ID 0bb4:0c91 High Tech Computer Corp. (example is G2)

In this case the Vendor Id is “18d1″ and the Product ID is “4e12″. Please keep in mind that the Vendor ID for HTC changed from “0bb4″ to “18d1″. The older HTC phones like the G1 have a Vendor ID of “0bb4″.

in most cases as seen below we only need the vendor id and with a new device you can just c+p the line and replace the vendor id

so now we can make our rules file for connecting for adb so

sudo gedit /etc/udev/rules.d/51-android.rules


SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666", GROUP="plugdev"

save and exit

reboot your computer to have the new changes take effect otherwise adb will not be in your $PATH

let's check to make sure our device is seen by adb by typing

adb devices

it should give you info back that you are connected if you are not or it doesn't read the vendor id than it might be a little bit more complicated, note adb will not read if you have usb mass storage mounted, also need usb debugging on in settings/apllications/development on your phone

Now we have a complete android development environment, aren't you proud of yourself. You are well on your way to making your own custom rom

it is a wise idea to have a backup of a system dump for stock apps and to get a feel for the way android is set up and also to pull any needed files from that are easily viewed on your computer at least as refefence connect your phone in adb in the terminal type

cd ~/

mkdir stock

cd stock

adb pull /system/ ~/stock/

this will make a system dump of your systems folder of your device, a wise idea would be to make a zipped versions of it and put it someplace secure
The Following 35 Users Say Thank You to sykopompos For This Useful Post: [ View ]
16th January 2011, 12:51 AM |#2  
sykopompos's Avatar
OP Developer Relations/Recognized Developer
Flag flithydelphia
Thanks Meter: 29,233
Donate to Me
Compiling cyanogenmod 7 source

Now we work on actually pulling sources and compiling source code. Since Cyanogenmod 7 is the most popular we will work with this (as of writing 1/15/11, cm7 source does not have a Rc1 yet so non official builds after the bacon script has the KANG attached to them)

So let’s pull cm7, open a terminal and type these commands

(you can name your source folder whatever you like but for guide purposes it will be cm7)

(make sure you are at ~)

mkdir cm7

cd cm7

repo init -u git:// -b gingerbread

It will ask you to enter your name and email (this is completely optional and you can just press enter to skip)

Press y and enter to confirm that your identity is correct, press y again to enable user color

You will now see repo initialized in our in our cm7 folder

Now we can use repo sync (this acts as a git clone to copy the source to our local branch)

In the terminal type

repo sync

This will take a while to download depending on your internet connection since it is pulling in over 2gb of source code (don’t use tethering during this as it will eat up your data for the month)

(you can use -j`grep 'processor' /proc/cpuinfo | wc -l` to run at full cpu speed. -j# (# means twice the amount of cores in your computer) means jobs. I will compare this to workers, your cpu could be a dual core, quad core and/or have hyperthreading (hyperthreading means a quad core will be seen as having 8 cores, I7 are considered this) well each one of your cores is a worker so one worker would be -j2 meaning the worker will handle 2 jobs. If you tell your workers to do more jobs then they won’t be happy being overloaded just like how any worker would be and will actually be slower. Now -j`grep 'processor' /proc/cpuinfo | wc -l` means read your computer’s info and run at optimal speed, now why choose between the 2 well you might not wanna run at max speed and just wanna use only half your power so you use your computer for other things during)

When we are done syncing we can get back to work

I am gonna use vision as an example but you can change it to suit the device you are working on

connect your phone you are gonna work for adb and open a terminal or use current previous terminal

(note, the proprietary vendors have been modified to work for gingerbread so make sure you have either the most up to date cm7src build or when rc1/stable comes out on your phone to get the proper files)

(this assumes you are using a previous and are in cm7)

cd device

cd htc/vision


cd ~/cm7

cd vendor/cyanogen/

bash get-rommanager

cd ~/cm7

We now have pull the proprietary files for our phone so we can inject them into our build along with rom manager since it is required and will fail the build if you don’t

(if you look in your cm7 source you will now see inside vendor a folder called htc (our manufactor, if you are working on a samsung or motorola you will see that) and inside it you will see your device)

We are actually now ready to build so in our terminal

source build/

lunch cyanogen_vision-eng

make clean

make bacon -j`grep 'processor' /proc/cpuinfo | wc -l`

Now our build is compiling

(the lunch command pulls target specific info so there is no need for a to be made as lunch does this for us)

(always make clean between builds to remove old compiled files and make sure you have a fully working build with each update, it takes a bit longer but it is worth it)

(make bacon is a script that runs make otapackage and the squisher script which uses pngcrush to cut down the size and also removes unneeded things added by doing a -eng build, it also resigns it)

When your build is complete you should have a in your cm7/out/target/product folder, this is your new build.

Congratulations on your first build from cm7 source

Now for a new build you would repo sync again, make clean and make bacon again
The Following 19 Users Say Thank You to sykopompos For This Useful Post: [ View ]
16th January 2011, 12:52 AM |#3  
sykopompos's Avatar
OP Developer Relations/Recognized Developer
Flag flithydelphia
Thanks Meter: 29,233
Donate to Me
Kernel compiling

We are gonna be pulling the cyanogenmod htc msm 7x30 kernel source, this covers ace, vision and glacier

so let’s open up a terminal and clone the kernel source so we can work with it

cd ~/

mkdir kernel

cd kernel

git clone git://

cd htc-kernel-msm7x30

We now have our source pulled and now need to set up our cross-compilier so we can make our kernel

export CROSS_COMPILE=~/cm7/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-

export ARCH=arm

Now have our cross compilier toolchain set up and will need to now tell it what to build, I find that make menuconfig is just plain ugly and rough to work with so

make xconfig

This will load a nice menu UI for us to work with, we are not gonna get into modifying the kernel but just a default config so go up to file and click load and select arch, then arm, then configs.

select cyanogen_vision_defconfig and click open, this will load the default cyanogen kernel config and is what you will find in a cm7 build (or glacier or ace depending what you are building for)

You can just click the x button in the corner to close it and collect save changes

Now we can compile our kernel, we can us the -j command like before to speed it up

make -j`grep 'processor' /proc/cpuinfo | wc -l`

Once the kernel compiles we have to grab our zimage and our wifi module (the couple lines up will show you the modules made and the location)

The zimage is our kernel and it can it can be found at /kernel/htc-kernel-msm7x30/arch/arm/boot/ and our wifi module name as bcm4329.ko (modules have a .ko extension) is found at /kernel/htc-kernel-msm7x30/drivers/net/wireless/bcm4329/

These are the only things we need to worry about. Now you can adb push the wifi module onto your phone and fastboot the zimage or we can have it built into our build by going to cm7/device/htc/vision/ and replacing the kernel with our zimage (will need to rename zimage to kernel) and putting our wifi module in modules and overwriting the one currently there (Make a backup of the stock kernel and wifi modules to replace your’s just in case)

Now you have your own kernel and you can compile it into your build

The Following 17 Users Say Thank You to sykopompos For This Useful Post: [ View ]
16th January 2011, 12:52 AM |#4  
sykopompos's Avatar
OP Developer Relations/Recognized Developer
Flag flithydelphia
Thanks Meter: 29,233
Donate to Me
reserved jhjlkk,mlkjnl;klm
16th January 2011, 12:53 AM |#5  
sykopompos's Avatar
OP Developer Relations/Recognized Developer
Flag flithydelphia
Thanks Meter: 29,233
Donate to Me
reserved for future use

you guys can post now
16th January 2011, 01:28 AM |#6  
Retired Recognized Developer
Thanks Meter: 720
Instead of make bacon -j`grep 'processor' /proc/cpuinfo | wc -l`, you can type mka bacon. mka uses schedtool (may have to install the package) as well as auto doing the correct number of jobs.

And after you do a ". build/", you can just type reposync, rather than repo sync do do a faster sync of the repos because it will do a -j10. (repo supports multiple simultaneous jobs (ie -j#)
The Following 6 Users Say Thank You to persiansown For This Useful Post: [ View ] Gift persiansown Ad-Free
16th January 2011, 01:33 AM |#7  
bobsbbq's Avatar
Senior Member
Flag Covington, LA
Thanks Meter: 357
Donate to Me
Wow a lot to learn. Now I have to kick the dust off my Linux and see what version it is and how much of a partition I made. Now I have something to do along with being a flash junkie.

I want to really Thank You for this guide. I really commend those that try to help others. Some people might not be able to do this no matter how easy you make it. But some including myself will find this information very useful.

A big thanks.
The Following User Says Thank You to bobsbbq For This Useful Post: [ View ] Gift bobsbbq Ad-Free
16th January 2011, 01:52 AM |#9  
notxel21's Avatar
Senior Member
Flag Jacksonville
Thanks Meter: 104
Thank you for sharing this with the Community.
16th January 2011, 02:10 AM |#10  
jlevy73's Avatar
Senior Member
Los Angeles
Thanks Meter: 1,319
Holy mother of matrimony, with corpses
The Following User Says Thank You to jlevy73 For This Useful Post: [ View ] Gift jlevy73 Ad-Free
16th January 2011, 02:45 AM |#11  
Senior Member
Thanks Meter: 6
You say 2.3 is 64-Bit only. Is that referring to the OS on the computer?
Post Reply Subscribe to Thread

android, cm7, compiling

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

Advanced Search
Display Modes