• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[Guide] - How to compile the CDMA kernel source and Flash it to your phone (Updated)

Search This thread

cteneyck

Senior Member
Jun 24, 2009
520
169
Dallas
You should do a nandroid backup and reboot your phone before trying to flash anything to your phone. This how to involves flashing directly to mtd2, if you don't know what you are doing then please use one of the custom roms available in the Sticky Wiki.

#### Update One Fixed scripts
#### Update Two Added instructions to compile and install the wlan.ko module
#### Update Three Fixed get-CDMAHero-source.sh typo
#### Update Four Added Instructions for Jaunty repo's for Ubunut 9.10

First off i would like to give credit to all the people who have made information and scripts available. I used bits and peices of info and tools written by and or made available by these people.

Armin Coralic http://blog.coralic.nl for creating some nice scripts and making them available
chuckhriczko for helping me out in the middle of the night.
LoxDev for creating a wonderfull how to about creating img's and zip's
tkirkton for helping out with enabling legacy jaunty repos to install java 1.5

Second I am writing this How To, so a complete newbie would be able to understand.

REQUIREMENTS....
Ubuntu Desktop 9.04 or better 32bit (cause thats what i used)

Android SDK (Needed to push and pull files as well as shell access to the phone. You will need to set this up by following the instructions found at http://www.android.com)

Legacy repo's enabled in apt to allow java 1.5 to install

Root access. I ran all commands below as root

I created a dir called "heroc" in my /root directory.

Download zip file below and unzip it in the heroc dir that you should have created.

STEPS

.5 Enable Legacy Repo's to allow java 1.5 to install (below is a cut from tkirktons post on page 7)

Code:
in Ubuntu 9.10, the Java 1.5 package doesn't even list.  Here's what I had to do to get it to load:

1.  Access a repository from the previous build (9.04 Jaunty will work:  commands to put into /etc/apt/sources.list -

deb [URL]http://mirrors.us.kernel.org/ubuntu[/URL] jaunty main restricted universe multiverse
deb [URL]http://mirrors.us.kernel.org/ubuntu[/URL] jaunty-backports main restricted universe multiverse
deb [URL]http://mirrors.us.kernel.org/ubuntu[/URL] jaunty-security main restricted universe multiverse
deb [URL]http://mirrors.us.kernel.org/ubuntu[/URL] jaunty-updates main restricted universe multiverse

2. Set the max age higher than the default. This can be accomplished by editing the /etc/apt/apt.conf.d/20archive. Here's what my lines in that file look like:

APT::Archives:MaxAge "2880";
APT::Archives:MinAge "2";
APT::Archives:MaxSize "1000";

Making these two changes should work...although I have the Intrepid, Hardy and Dapper repositories in mine as well (didn't know which one would work, so I overkilled it).

Run the script again after making the changes and let me know if it works.
.

to update just run

Code:
# apt-get update

1. Create your work environment by running createandroidRepo.sh. This will take some time depending on your internet connection. Make sure you are in the heroc dir.

Code:
# unzip Scripts.zip
# chmod a+x *
# ./createAndroidRepo.sh
This will create a dir call my android and setup all the files and programs needed to compile the kernel. This will take some time to complete.

2. You need to download the source using the get-CDMAHero-source.sh

Code:
# ./get-CDMAHero-source.sh
This will download the source, and extract it to its own directory.

3. you will need to have your .config file handy for the next steps. If you don't have it then you will need to get it by doing the following

Code:
# adb pull /proc/config.gz /root/heroc/config.gz
# gunzip config.gz
The first command will pull the gzipped config from your phone and place it into the heroc dir. the second command will extract the file as "config"

4. This is where it gets fun. We now have everything downloaded and are going to start the process of compiling our kernel.

Code:
# cd heroc_ef05d31a
# export ARCH=arm
# export CROSS_COMPILE=arm-eabi-
# export PATH=$PATH:~/heroc/myandroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin

# make menuconfig
After you run "make menuconfig" it will bring up a the config menu for our kernel. Go to the bottom and select "Load an alternate configuration file". It will then prompt you to select the config file you want to use. You will need to point it to where you have the config file. So type in "/root/heroc/config"

After you have loaded the config file you can edit what ever you want. however if you don't know what do disable or enable then i wouldn't mess around to much.

Next you will need to save your config file. Choose "Save an alternate configuration file", and save it as "/root/heroc/heroc_ef05d31a/.config"

You can now exit menuconfig

5. Time To Compile the kernel and wlan.ko module

Code:
# make
# export KERNEL_DIR=/root/heroc/heroc_ef05d31a/
# cd myandroid/system/wlan/ti/sta_dk_4_0_4_32/
# make
The kernel will take some time. go grab a drink and have a snack. If all goes well you should end up with a zImage file in "~/heroc//arch/arm/boot/". After the kernel is compiled you need to compile the wlan.ko module by executing the last three commands

6. Next we need to copy the zImage back to the heroc dir

Code:
# cp /root/heroc/heroc_ef05d31a/arch/arm/boot/zImage /root/heroc/zImage
7. Ok so now we need to get the boot image from our phone. We need this cause it has more than just the kernel. I contains the ramdisk image as well. and we need to take the boot image and decompress it and remove the old kernel and add our new compiled kernel, then recompress it to newboot.img

Code:
# adb shell
# cat /dev/mtd/mtd2 > /sdcard/mtd2.img
# exit
# adb pull /sdcard/mtd2.img /root/heroc/mtd2.img
# mv mtd2.img boot.img
The first two commands will open a terminal shell to your phone and copy the boot image to your sdcard. the last two commands will pull the the boot image from your phone, place it in your heroc dir and rename the file to boot.img

8. Now we will split apart the boot.img using some scripts.

Code:
# ./extract-kernel.pl boot.img
# ./extract-ramdisk.pl boot.img
# rm boot.img-kernel
# cp zImage boot.img-kernel
# ./mkbootfs boot.img-ramdisk | gzip > ramdisk-boot
# ./mkbootimg --kernel boot.img-kernel --ramdisk ramdisk-boot --cmdline "no_console_suspend=1 console=null" -o newBoot.img --base 0x19200000
The first command extracts the stock kernel from boot.img. The second command extracts the ramdisk from boot.img. The third command will delete the stock kernel. the fourth command renames our zImage to boot.img-kernel. The fifth command takes boot.img-ramdisk folder and zips it up into ramdisk-boot. The sixth comand takes our kernel (renamed to "boot.img-kernel") and ramdisk-boot and combines it back to form a new file called newboot.img.


9. Now we need to flash our "newboot.img" file to our phone. You should reboot your phone before flashing this will insure that you don't get any out of memory errors and will keep your phone from booting into fastboot (Thx Obelisk79).

Code:
# adb push newBoot.img /sdcard/newBoot.img
# adb shell
# cat /dev/zero > /dev/mtd/mtd2 (you may get an error here. don't worry about it)
# flash_image boot /sdcard/newBoot.img
# reboot
The first command will push your boot image to the phone. the second command will bring up shell access to your phone. the third command will zero out mtd2 and get it ready to write your image. the fourth command will flash boot(mtd2) with newboot.img. the last command will reboot your phone

10. After the phone reboots we need to get the wlan.ko file to the phone so that wireless will work

Code:
# adb push /root/myandroid/system/wlan/ti/sta_dk_4_0_4_32/wlan.ko /sdcard/wlan.ko
# adb shell
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# cp /sdcard/wlan.ko /system/lib/modules/wlan.ko
# exit
Now you have a kernel that you compiles with everything work with the exception of power mgmt.
 

Attachments

  • Scripts.zip
    24.5 KB · Views: 744
Last edited:

cteneyck

Senior Member
Jun 24, 2009
520
169
Dallas
Just as soon as i figure out how to make an update.zip i will post instructions on how to do this
 
Last edited:

blehzz

Senior Member
Dec 2, 2009
142
0
Is there a way to get this to run on the Emulator? I tried to specify the zImage after I compiled it but it won't boot when specifying it. Or will that not work for the HTC zImage?
 

miamicanes

Senior Member
Nov 6, 2007
69
0
Has anybody tried this yet with Ubuntu running under VMware on a PC running Windows? I know that (in theory) VMware's USB compatibility is spectacularly good (it somehow manages to give the guest OS direct ownership and control of the host PC's USB root hub), but up to now I've only tried it to run XP/32 under Vista/64 and Windows 7/64.

FYI, you can download VMware player for free (as in beer) and use it to run Ubuntu 9.04 with their complete blessing. Just make sure you download a guest OS that configures the hardware (memory, cpu, etc) the way you want it to be, because changing the hardware config is one of the few things you genuinely can't do with the free player. If someone here has the full version (and can find somewhere to host it so the bandwidth charges didn't eat him alive), he could even create an Ubuntu distro that's already set up and configured to build Android kernels for others here to download and use.
 

mrinehart93

Senior Member
Oct 11, 2009
1,853
308
Chicago
To use the first script: open up Synaptics, then download "tofromdos". Now, run "fromdos createAndroidRepo.sh", and it should work then :)
 

bikcmp

Senior Member
Dec 8, 2009
321
4
ROM?

Can someone post how to compile a kernel, and make a ROM, and put it all together in a update.zip? Would be really REALLY nice!
Jason(bikcmp)
 

mrinehart93

Senior Member
Oct 11, 2009
1,853
308
Chicago
Thanks for this guide :) I'm compiling a kernel right now :) Just a question, how do I change the kernel version name... like you did in that one screenshot?