[How-To] compile the Nexus S kernel from source

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
android.git.kernel.org Git - kernel/samsung.git/summary

If you're reading this, you're probably like me and love to mess with things until they break. Then fix them, and do it again. The Nexus S may not have an SDcard slot, and it may not be HSPA+, but if you like to hack and twist your phone into the shape you want, it's the phone to have.

But where to start? That's what this post is all about -- getting a development computer up and running to build the Kernel source. There's lots of ways to get going, but we're going to stick to what Google recommends, and what has worked for me. If you're a bit more advanced, by all means change what you like, it's all about choice.

The OS
You're going to need a 64bit version of Linux. I recommend Ubuntu 10.10. Download it and install it on your development computer. Take the time to read some guides and get everything working, especially all your Internet tools and plug-ins. You'll need them. Once you have it set up, it's time to start development.

You'll need some tools first.
Sun/Oracle Java 6

Code:
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6-jdk

Next are the 32 bit headers

Code:
sudo apt-get install ia32-libs

Next, some compilation tools

Enable the multiverse repo (UbuntuGeek has a great tutorial, as well as many others. Bookmark it) and open your terminal. At the prompt, type:
Code:
sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

this may take a while, it's a lot to download.

Next, we want to install valgrind, for the inevitable bug tracking that we'll have to do:
Code:
sudo apt-get install valgrind
 
Last edited:

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
Next, we need to set up our machine to pull and keep files up to date with Google's git repo. It's easier to do than you think:
Code:
$ cd ~
$ mkdir bin

Now make sure your ~/bin directory is in your PATH. Open your .bashrc file and add the following line at the end of the file:
Code:
PATH=$PATH:/home/*YOUR-USER-NAME*/bin
export PATH
Of course, substitute your user name above.

Now download the repo script, and set permissions:
Code:
$ curl http://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo

We need somewhere to put the files. Personally, I hate this naming convention, but that's what Android uses so we're going to use it too.
Code:
$ mkdir mydroid 
$ cd mydroid 
$ repo init -u git://android.git.kernel.org/platform/manifest.git
When asked for your name and email, don't be shy. Open source is about sharing. Be sure to use a Gmail address, you'll need it if you ever contribute back.
 

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
The long part is next -- getting all the code. It's really easy, but takes forever.

Code:
$ cd ~/mydroid
$ repo sync

Go make a sandwich, or take a walk, anything to pass the time it takes to download several Gigabytes of data from often slow servers. When it's done downloading, we're almost finished, we only have to import Google's gpg keys.

Code:
$ gpg --import
then copy and paste the following into your terminal:
Code:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV 
lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7
8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD 
u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z 
wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq 
/HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5
jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4
MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9
b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv 
aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k 
cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX 
gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI 
2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl 
QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up 
hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk 
C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX 
LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+
OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M 
pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s 
KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb 
N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA 
vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo 
G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ 
hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l 
EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
=Wi5D 
-----END PGP PUBLIC KEY BLOCK-----

Control + D will import and save it.

That's it -- you're now ready to build both Android (AOSP), and custom kernels.
 
Last edited:

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
Downloading the Nexus S kernel source

As of today, the above isn't going to get you the Nexus S kernel source. That's easy to fix:

Code:
$ cd ~/mydroid
$ git clone git://android.git.kernel.org/kernel/samsung.git

Now you can go into that directory in your Android source tree:

Code:
$ cd ~/mydroid/samsung
Now the building. Copy and paste these lines into your terminal. BE SURE TO EDIT YOUR EXPORT COMMAND WITH THE CORRECT PATH!

Code:
export PATH=$PATH:/home/[B][COLOR="Red"]<your username>[/COLOR][/B]/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/
make ARCH=arm clean
make ARCH=arm herring_defconfig
make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-

This builds the kernel, as well as the wireless module. It takes a few minutes, depending on your computer. If it hasn't stopped and spit out an error, it's not done :)
You find your kernel at:
~/mydroid/samsung/arch/arm/boot/zImage
The wlan module is at:
~/mydroid/samsung/drivers/net/wireless/bcm4329/bcm4329.ko

Next you need to package it up to test. I can't get a zImage to boot via fastboot on the NS, so you'll have to pack up a boot image. Download the attached file, and extract it. Put fastboot in your SDK/tools folder (if you don't have it) and place the unpack-bootimg.pl script and the mkbootimg binary into a folder in your home called NS-bootwork. Copy your zImage in there, too.

Now pull the boot image from your phone, either via adb or from a terminal app:
Code:
cat /dev/mtd/mtd2 > /sdcard/boot.img
Copy the boot.img from your Nexus S to your NS-bootwork folder, then it's time for more term c/p :)
Code:
cd ~/NS-bootwork
./unpack-bootimg.pl boot.img
cd boot.img-ramdisk/
find . | cpio -o -H newc | gzip > /home/[B][COLOR="Red"]<your username>[/COLOR][/B]/NS-bootwork/boot.img-ramdisk/ramdisk-repack.cpio.gz
cd ..
./mkbootimg --kernel zImage --ramdisk /home/[B][COLOR="Red"]<your username>[/COLOR][/B]/NS-bootwork/boot.img-ramdisk/ramdisk-repack.cpio.gz --base 0x30000000 --pagesize 4096 -o newtestboot.img
thanks to whoever originally created the unpack Perl script. If it was you, or you know who did, for the love of God let me know so I can thank them.

Now to test it :)
Take the newtestboot.img you just made, and put it in your SDK/tools folder. Shut your phone off, connect it to your computer, then hold volume up + power to enter fastboot. From the terminal (told you i love it)

Code:
cd ~/android-sdk-linux_86/tools
sudo fastboot boot newtestboot.img
<password>

If it boots, you won't have Wifi because we haven't pushed the kernel module over yet. But take the time to open settings>about phone and admire your own kernel showing there. Smoke a cig, have a beer, whatever you need to do to celebrate. If it doesn't boot, just pull the battery and reboot. We only told the phone to boot this one time from your new image, and the next boot will have you back where you started.

If it works well and you want to keep it, you need to put the bcm4329.ko (the kernel module) into /system/modules/. This will break wifi for any kernel except the one you have built, so only do it when you're ready to get final.

Then just like before, we're going to use fastboot to copy it over, except this time we flash it permanently.
Code:
sudo fastboot flash boot newtestboot.img
<password>
If you wanna play around with the boot image, and don;t feel like building your own kernel, there's one right here: NS-kernel_build.tar.bz2

Good luck!

Putting this here so i don't lose it (courtesy of Swetland -- a mighty Googler)
baseaddr 0x30000000
pagesize 4096
 
Last edited:

serpico

Well-known member
Apr 28, 2010
198
4
0
Visit site
I just want the skill to understand all this! Lol I always wanted to learn but hit hurdles when learning to code and quit.
 

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
I just want the skill to understand all this! Lol I always wanted to learn but hit hurdles when learning to code and quit.

Jump on in. This stuff looks harder on paper (or lcd lol) than it really is. If enough of us get together, we can have a blast with this!
 

bigbuss786

Member
Dec 6, 2010
7
0
0
Visit site
what is it for

Hey Jerry, I would love to do this, always wanted too. However I was wondering how we could use this? Do we have to have a Nexus S to make it useful, or can we do something with an existing phone, like an OG Droid for example...
Thanks
 

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
Hey Jerry, I would love to do this, always wanted too. However I was wondering how we could use this? Do we have to have a Nexus S to make it useful, or can we do something with an existing phone, like an OG Droid for example...
Thanks
The first three posts (getting the computer set up) is exactly the same. I just stuck it here, because the Nexus S is what I'm going to be working with mostly.

Go through the first 3 posts, then grab you some kernel source for your OG Droid. You'll be able to find some already overclocked and ready to go. Building it is the same process as we'll go through here -- the only difference will be your source code and packaging it for the phone (which we'll cover later)
 

ragnarokx

Well-known member
Apr 20, 2010
6,915
1,696
0
Visit site
If you can copy paste, you can learn. And trust me, when you hit about phone and see your kernel running the show, it feels good :)

Alrighty then, I'll give it a shot. Time to dust off that old spare Macbook and get some dual boot action going! If only the source code for the Epic 2.2 kernel was out..
 

bdotto14

Well-known member
Feb 9, 2010
52
0
0
Visit site
I got an error message when I tried the command to get the JDK.

E: Unable to locate package sun-java-5-jdk

not sure why I got the error, I am on Ubuntu 10.10 because I couldn't get wireless to work with the suggested version of Ubuntu. Any help would be greatly appreciated
 

beezy

Well-known member
Feb 27, 2010
2,434
1,010
0
Visit site
Just to help out cause you know I've had so much fun learning. ;)
After
chmod a+x ~/bin/repo

Might want to tell everyone to reboot or open new terminal,if not they will probably get bash repo errors.
If i can think or run into anything else ill add what i find.
 

tl1720

New member
Jan 13, 2011
3
0
0
Visit site
Thanks for this very illuminating article. Is there a conclusion to it somewhere. I set everything up but am unable to build. I get quite a few errors and make never ends.

Thanks for any and all help

The errors I get start with :
============================================
PLATFORM_VERSION_CODENAME=AOSP
PLATFORM_VERSION=AOSP
TARGET_PRODUCT=full_crespo
TARGET_BUILD_VARIANT=userdebug
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER

build/core/binary.mk:323: target `out/target/product/crespo/obj/STATIC_LIBRARIES/libc_common_intermediates/arch-arm/syscalls/eventfd.o' given more than once in the same rule.
find: `frameworks/base/frameworks/base/docs/html': No such file or directory
find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory
find: `out/target/common/docs/gen': No such file or directory
 

dirtmike

New member
Jan 13, 2011
3
0
0
Visit site
Thanks for this very illuminating article. Is there a conclusion to it somewhere. I set everything up but am unable to build. I get quite a few errors and make never ends.

Thanks for any and all help

The errors I get start with :
============================================
PLATFORM_VERSION_CODENAME=AOSP
PLATFORM_VERSION=AOSP
TARGET_PRODUCT=full_crespo
TARGET_BUILD_VARIANT=userdebug
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER

build/core/binary.mk:323: target `out/target/product/crespo/obj/STATIC_LIBRARIES/libc_common_intermediates/arch-arm/syscalls/eventfd.o' given more than once in the same rule.
find: `frameworks/base/frameworks/base/docs/html': No such file or directory
find: `out/target/common/docs/gen': No such file or directory
find: `frameworks/base/frameworks/base/docs/html': No such file or directory
find: `out/target/common/docs/gen': No such file or directory

I am also trying to figure out how to build this. Is there a config.gz in proc? There doesn't seem to be one in mine. My only problem is I don't know what the kernel configuration should be.

Edit - It looks like you are trying to build the AOSP, not the kernel. I think this thread was about building the kernel??
 

tl1720

New member
Jan 13, 2011
3
0
0
Visit site
Thanks

I intended to build the kernel. Guess i got something wrong. Can someone please point out the steps to build the kernel after the environment is set up.

Thanks
 

Jerry Hildenbrand

Space Cowboy
Staff member
Oct 11, 2009
5,567
2,792
113
Visit site
sorry guys. Google has changed the entire procedure, and while I can hack my way through it and make it work, I'm waiting on them to update their page with the new requirements and method.

In the meantime, anyone interested should subscribe to the android-kernel mailing list and the android-building mailing list to take part in the discussion.

It's likely going to be as easy as installing Sun-Java-6 and using the same methods --
pull config from /proc
make menuconfig
make

but I can;t say for sure what the recommended methods will be until we get them :)
 

tl1720

New member
Jan 13, 2011
3
0
0
Visit site
Thanks for the update

Just in case it helps - apparently they have added the requirement of building on a 64 bit environ and Sun java 6. I created my set up on a 64 bit 10.04 which
apparently is Google'w own build environment.

Thanks for all the help.