How to compile your own kernel.

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5

!!! This is only for Advanced Users !!!
Do not try unless you know what this stuff even means
and you have all the requirements!!
And don't expect support questions to be answered immediately.

!!!! Use this at YOUR OWN RISK !!!!


Neither the Author or DroidForums can be Held Responsible in how you use this information !!!
========================Good Luck and Have Fun==============================​

This is a wip, so...
Credit to Sticky: How to Compile the Droid kernel for some of the sections I borrowed.

Part 1
Installing GNU/Linux


First, you will need GNU/Linux. Use any distro you like, but for ease, Ubuntu will work fine. Unless you plan on making a dual boot or using it as a main OS, wubi will be one of the easiest ways. It will install Ubuntu onto your Windows partition in a folder of its own. Uninstall is easy as well, you can do it from the control panel. You can also do this under a VM, but wubi is going to be easiest to set up.

Getting Ubuntu
Download Ubuntu | Ubuntu

Then, burn the iso to a CD. To install with Wubi, simply start the setup on the CD from within windows. Follow the directions and you are on your way to installing Ubuntu. When you reboot you will be presented with the choice to boot Windows, or Ubuntu.
 
OP
adrynalyne

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5
Part 2
Setting up Git and kernel source

Getting the kernel source will be done by using this code below. You can literally copy and paste it from here into the ubuntu terminal.
Code:
mkdir -p ~/kernel/droid
cd ~/kernel/droid
git clone git://android.git.kernel.org/kernel/omap.git
git clone git://android.git.kernel.org/platform/system/wlan/ti.git
git clone git://android.git.kernel.org/platform/prebuilt.git

This does take a bit.

The next part is to set git to the version of kernel we want to use. In this case, we will want the latest Eclair source, as its the only kernel that works on ESE53+.

Code:
cd ~/kernel/droid/omap
git checkout --track -b android-omap-2.6.29-eclair origin/android-omap-2.6.29-eclair
cd ~/kernel/droid/ti
git checkout --track -b eclair origin/eclair
cd ~/kernel/droid/prebuilt
git checkout --track -b eclair origin/eclair
 
OP
adrynalyne

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5
Part 3
Configuring kernel options (like tethering and overclocking)

First, lets setup the build environment.
Code:
cd ~/kernel/droid/omap
export ARCH=arm
export CROSS_COMPILE=~/kernel/droid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
make sholes_defconfig
Kernel configuration happens a few ways. You can use menuconfig (gotta install ncurses dev tools)
Code:
cd ~/kernel/droid/omap
make menuconfig
or the more advanced method of modifying the .config file.
The .config file is a hidden file in the ~/kernel/droid/omap. I wil attach mine. Here is where much of the kernel config takes place.
Other more advanced things, such as overclocking, take place in the ~/kernel/droid/omap/arch//arm/mach-omap 2 directory.

To overclock, check out the board.sholes.c file, specifically this part:
Code:
static struct omap_opp sholes_mpu_rate_table[] = {
    {0, 0, 0},
    /*OPP1*/
    {S125M, VDD1_OPP1, 0x20},
    /*OPP2*/
    {S250M, VDD1_OPP2, 0x27},
    /*OPP3*/
    {S500M, VDD1_OPP3, 0x32},
    /*OPP4*/
    {S550M, VDD1_OPP4, 0x38},
    /*OPP5*/
    {S600M, VDD1_OPP5, 0x3E},
};
Speeds slots are shown here, as well as voltages. I haven't messed with this too much yet. This is also linked to the file omap3-opp.h, where the speed settings are defined.
Code:
/* MPU speeds */
#define S600M   600000000
#define S550M   550000000
#define S500M   500000000
#define S250M   250000000
#define S125M   125000000
Enabling the 600mhz mode (and the fifth cpu slot) requires modifcations to the clock34xx.c file. I will upload mine.

So if you wanted to overclock (for example), you would modify the above:
Code:
/* MPU speeds */
#define S600M   800000000
#define S550M   600000000
#define S500M   500000000
#define S250M   250000000
#define S125M   125000000

That would top out at 800mhz, stock voltage. There are a few ways to do this that I have seen, this is the one I have used. USE AT YOUR OWN PERIL!

To tether, you will need to enable netfilter and iptables stuff in the kernel. Most of this stuff is NOT in .config, but you can add it. It only requires three lines to enable it, but then the questions that come during compilation are annoying, long, and make it easy to make errors. The .config file I loaded has this already, but I will list the sections as well. These get added to .config. Be careful not to duplicate sections.

Code:
# Networking options
#
CONFIG_COMPAT_NET_DEV_OPS=y
CONFIG_PACKET=y
CONFIG_PACKET_MMAP=y
CONFIG_UNIX=y
CONFIG_XFRM=y
CONFIG_XFRM_USER=y
# CONFIG_XFRM_SUB_POLICY is not set
CONFIG_XFRM_MIGRATE=y
# CONFIG_XFRM_STATISTICS is not set
CONFIG_NET_KEY=y
CONFIG_NET_KEY_MIGRATE=y
CONFIG_INET=y
CONFIG_IP_MULTICAST=y
# CONFIG_IP_ADVANCED_ROUTER is not set
CONFIG_IP_FIB_HASH=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
CONFIG_IP_PNP_BOOTP=y
CONFIG_IP_PNP_RARP=y
# CONFIG_NET_IPIP is not set
# CONFIG_NET_IPGRE is not set
# CONFIG_IP_MROUTE is not set
# CONFIG_ARPD is not set
# CONFIG_SYN_COOKIES is not set
# CONFIG_INET_AH is not set
# CONFIG_INET_ESP is not set
# CONFIG_INET_IPCOMP is not set
# CONFIG_INET_XFRM_TUNNEL is not set
# CONFIG_INET_TUNNEL is not set
# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
# CONFIG_INET_XFRM_MODE_TUNNEL is not set
# CONFIG_INET_XFRM_MODE_BEET is not set
# CONFIG_INET_LRO is not set
CONFIG_INET_DIAG=y
CONFIG_INET_TCP_DIAG=y
# CONFIG_TCP_CONG_ADVANCED is not set
CONFIG_TCP_CONG_CUBIC=y
CONFIG_DEFAULT_TCP_CONG="cubic"
# CONFIG_TCP_MD5SIG is not set
# CONFIG_IPV6 is not set
CONFIG_ANDROID_PARANOID_NETWORK=y
# CONFIG_NETWORK_SECMARK is not set
CONFIG_NETFILTER=y
# CONFIG_NETFILTER_DEBUG is not set
CONFIG_NETFILTER_ADVANCED=y

#
# Core Netfilter Configuration
#
# CONFIG_NETFILTER_NETLINK_QUEUE is not set
# CONFIG_NETFILTER_NETLINK_LOG is not set
CONFIG_NF_CONNTRACK=y
# CONFIG_NF_CT_ACCT is not set
# CONFIG_NF_CONNTRACK_MARK is not set
# CONFIG_NF_CONNTRACK_EVENTS is not set
# CONFIG_NF_CT_PROTO_DCCP is not set
CONFIG_NF_CT_PROTO_GRE=y
# CONFIG_NF_CT_PROTO_SCTP is not set
# CONFIG_NF_CT_PROTO_UDPLITE is not set
# CONFIG_NF_CONNTRACK_AMANDA is not set
CONFIG_NF_CONNTRACK_FTP=y
# CONFIG_NF_CONNTRACK_H323 is not set
CONFIG_NF_CONNTRACK_IRC=y
# CONFIG_NF_CONNTRACK_NETBIOS_NS is not set
CONFIG_NF_CONNTRACK_PPTP=y
# CONFIG_NF_CONNTRACK_SANE is not set
# CONFIG_NF_CONNTRACK_SIP is not set
# CONFIG_NF_CONNTRACK_TFTP is not set
# CONFIG_NF_CT_NETLINK is not set
CONFIG_NETFILTER_XTABLES=y
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
# CONFIG_NETFILTER_XT_TARGET_CONNMARK is not set
# CONFIG_NETFILTER_XT_TARGET_MARK is not set
# CONFIG_NETFILTER_XT_TARGET_NFLOG is not set
# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
# CONFIG_NETFILTER_XT_TARGET_RATEEST is not set
# CONFIG_NETFILTER_XT_TARGET_TCPMSS is not set
# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
# CONFIG_NETFILTER_XT_MATCH_CONNBYTES is not set
# CONFIG_NETFILTER_XT_MATCH_CONNLIMIT is not set
# CONFIG_NETFILTER_XT_MATCH_CONNMARK is not set
# CONFIG_NETFILTER_XT_MATCH_CONNTRACK is not set
# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
# CONFIG_NETFILTER_XT_MATCH_DSCP is not set
# CONFIG_NETFILTER_XT_MATCH_ESP is not set
# CONFIG_NETFILTER_XT_MATCH_HASHLIMIT is not set
# CONFIG_NETFILTER_XT_MATCH_HELPER is not set
CONFIG_NETFILTER_XT_MATCH_IPRANGE=y
# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
# CONFIG_NETFILTER_XT_MATCH_LIMIT is not set
CONFIG_NETFILTER_XT_MATCH_MAC=y
# CONFIG_NETFILTER_XT_MATCH_MARK is not set
CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y
# CONFIG_NETFILTER_XT_MATCH_OWNER is not set
# CONFIG_NETFILTER_XT_MATCH_POLICY is not set
# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
# CONFIG_NETFILTER_XT_MATCH_RATEEST is not set
# CONFIG_NETFILTER_XT_MATCH_REALM is not set
CONFIG_NETFILTER_XT_MATCH_RECENT=y
# CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT is not set
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
CONFIG_NETFILTER_XT_MATCH_STATE=y
# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
# CONFIG_NETFILTER_XT_MATCH_TIME is not set
# CONFIG_NETFILTER_XT_MATCH_U32 is not set
# CONFIG_IP_VS is not set

#
# IP: Netfilter Configuration
#
CONFIG_NF_DEFRAG_IPV4=y
CONFIG_NF_CONNTRACK_IPV4=y
CONFIG_NF_CONNTRACK_PROC_COMPAT=y
# CONFIG_IP_NF_QUEUE is not set
CONFIG_IP_NF_IPTABLES=y
# CONFIG_IP_NF_MATCH_ADDRTYPE is not set
# CONFIG_IP_NF_MATCH_AH is not set
# CONFIG_IP_NF_MATCH_ECN is not set
# CONFIG_IP_NF_MATCH_TTL is not set
CONFIG_IP_NF_FILTER=y
CONFIG_IP_NF_TARGET_REJECT=y
CONFIG_IP_NF_TARGET_LOG=y
# CONFIG_IP_NF_TARGET_ULOG is not set
CONFIG_NF_NAT=y
CONFIG_NF_NAT_NEEDED=y
CONFIG_IP_NF_TARGET_MASQUERADE=y
CONFIG_IP_NF_TARGET_NETMAP=y
CONFIG_IP_NF_TARGET_REDIRECT=y
# CONFIG_IP_NF_TARGET_IDLETIMER is not set
# CONFIG_NF_NAT_SNMP_BASIC is not set
CONFIG_NF_NAT_PROTO_GRE=y
CONFIG_NF_NAT_FTP=y
CONFIG_NF_NAT_IRC=y
# CONFIG_NF_NAT_TFTP is not set
# CONFIG_NF_NAT_AMANDA is not set
CONFIG_NF_NAT_PPTP=y
# CONFIG_NF_NAT_H323 is not set
# CONFIG_NF_NAT_SIP is not set
# CONFIG_IP_NF_MANGLE is not set
# CONFIG_IP_NF_RAW is not set
# CONFIG_IP_NF_ARPTABLES is not set
# CONFIG_IP_DCCP is not set
# CONFIG_IP_SCTP is not set
# CONFIG_TIPC is not set
# CONFIG_ATM is not set
# CONFIG_BRIDGE is not set
# CONFIG_NET_DSA is not set
# CONFIG_VLAN_8021Q is not set
# CONFIG_DECNET is not set
# CONFIG_LLC2 is not set
# CONFIG_IPX is not set
# CONFIG_ATALK is not set
# CONFIG_X25 is not set
# CONFIG_LAPB is not set
# CONFIG_ECONET is not set
# CONFIG_WAN_ROUTER is not set
# CONFIG_NET_SCHED is not set
# CONFIG_DCB is not set
When you are done configuring your .config file, BACK IT UP. Each time you setup the build environment, it erases it and makes a default copy. Just watch the prompts and when it does that, replace the new .config file with your own.
 
OP
adrynalyne

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5
Part 4
Compiling kernel and wifi driver

Ready for this? While still in the omap directory (~/kernel/droid/omap)
Code:
make
Now watch the initial prompts. Sometimes it once again nukes your .config file. I have no idea why. So just hit ctrl-x and cancel the compile, and then put your .config file back and make it again.

Now for the wifi.

Code:
cd ~/kernel/droid/ti/wilink_6_1/platforms/os/linux
export ARCH=arm
export CROSS_COMPILE=~/kernel/droid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
export HOST_PLATFORM=zoom2
export KERNEL_DIR=~/kernel/droid/omap
make

The driver will be located under ~/kernel/droid/ti/wilink_6_1/platforms/os/linux.

Put it on your sd card for safe keeping. You need to build this driver, every time you recompile the kernel.
 
OP
adrynalyne

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5
Part 5
Packaging kernel

Make a new directory under your home folder called bin. Log out and back in to get it into your path.
Attached is a zip file of two files you need. Copy mkbootimg into your bin folder, and boot.img-ramdisk.gz into the ~/kernel/droid folder.

To package the kernel into a boot.img file:

Code:
cd ~/kernel/droid
mkbootimg --kernel omap/arch/arm/boot/zImage --ramdisk boot.img-ramdisk.gz --cmdline "console=ttyS2,115200n8 rw mem=244M@0x80C00000 init=/init ip=off brdrev=P3A_CDMA mtdparts=omap2-nand.0:640k@128k(mbm),384k@1408k(cdt),384k@3328k(lbl),384k@6272k(misc),3584k(boot),4608k(recovery),143744k(system),94848k(cache),268032k(userdata),2m(kpanic)" -o boot.img

File will be located in ~/kernel/droid folder. Copy this to your sd card.
 
OP
adrynalyne

adrynalyne

Premium Member
Premium Member
Developer
Joined
Dec 21, 2009
Messages
2,895
Reaction score
5
Part 6
Flashing kernel and hosing your phone


You cannot do this from within Android, so reboot to recovery mode.
You will also need adb setup for this. In SPRecovery, go to mount options and mount the sd card.

Code:
adb shell
flash_image boot /sdcard/boot.img
Reboot.

Once back up (assuming you booted), install the wifi driver.
Code:
adb shell
su
mount -o remount,rw -t yaffs2 /dev/block/mtdblock4 /system
busybox cp /sdcard/tiwlan.ko /system/lib/modules/tiwlan.ko
sync
reboot
Thats the main meat of it. Many things can be added and modified that go beyond this tutorial. The sky is the limit.

Here is a sample kernel I made. Its not meant for regular use, just an example :)
 

natediddy1120

Silver Member
Joined
Jan 4, 2010
Messages
3,177
Reaction score
1
Location
???


!!! This is only for Advanced Users !!!
Do not try unless you know what this stuff even means
and you have all the requirements!!
And don't expect support questions to be answered immediately.

!!!! Use this at YOUR OWN RISK !!!!
 

kevdog

Member
Joined
Nov 14, 2009
Messages
721
Reaction score
0
Where did you get the ramdisk images? I used to download mine from the now defunct sholes site, however Im interested in getting both the koush and sholes ramdisk boot loaders.
 

jamezelle

Premium Member
Premium Member
Developer
Joined
Apr 11, 2010
Messages
620
Reaction score
0
Where did you get the ramdisk images? I used to download mine from the now defunct sholes site, however Im interested in getting both the koush and sholes ramdisk boot loaders.

just download there kernel and use the split_bootimg.pl script

to extract the boot.img

i attached it for you below
 

nphil

Member
Joined
Feb 16, 2010
Messages
344
Reaction score
0
Location
Atlanta, GA
Thank you! Guess I can stop working on my guide to compile a complete ROM from source, because I know you're on it next!
 

teddyearp

Senior Member
Joined
Jan 13, 2010
Messages
1,816
Reaction score
12
Location
Pinetop, AZ
Current Phone Model
Motorola Razr 5g Rooted
First off, my thanks to adrynalyne also for putting this together. I have done this successfully from the guide written by matt graham and sniffle, but when I asked how to change the overclock settings, either they didn't know at the time or wanted to watch me squirm while they knew and I didn't. But, I still have a couple of questions (of course).

I am just curious if this code:

Code:
cd ~/android/kernel/omap
git checkout -b stable 0dd7e0b
cd ~/android/kernel/ti
git checkout -b stable 846ab56
cd ~/android/kernel/prebuilt
git checkout -b stable 06b921b
would still give me a checkout of a pre ESE53+ branch. I would like to create an OC WiFi AND wired tether LV kernel that I can try plugging into my old DroidMod 1.0 ROM. Plus, any hints on how to add a couple of OC slots the right way?

TIA
 
Last edited:

jamezelle

Premium Member
Premium Member
Developer
Joined
Apr 11, 2010
Messages
620
Reaction score
0
also you might want to add that for compiling for 2.0.1

the 2 occurances in pvrversion.h

should be 2152 like so
Code:
#define PVRVERSION_BUILD 2152
#define PVRVERSION_STRING "1.5.15.2152"

and compiling for 2.1 they should be

Code:
#define PVRVERSION_BUILD 2592
#define PVRVERSION_STRING "1.5.15.2592"

just in case you ran into the problem i had
 

teddyearp

Senior Member
Joined
Jan 13, 2010
Messages
1,816
Reaction score
12
Location
Pinetop, AZ
Current Phone Model
Motorola Razr 5g Rooted
also you might want to add that for compiling for 2.0.1

the 2 occurances in pvrversion.h

should be 2152 like so
Code:
#define PVRVERSION_BUILD 2152
#define PVRVERSION_STRING "1.5.15.2152"
and compiling for 2.1 they should be

Code:
#define PVRVERSION_BUILD 2592
#define PVRVERSION_STRING "1.5.15.2592"
just in case you ran into the problem i had

Nice info, but suffer my n00bness. Adrenalyn was kind enough to point out in his post #3 the exact path in the source where to find the files to edit for OC, etc., where in the path do I find this file you mention? Also, is this your way to verify (as you did not spell it out) that if I do the 'checkout' commands that I indicated, I would git the kernel version I am wanting?

TIA
 
Top