5,597,354 Members 31,244 Now Online
XDA Developers Android and Mobile Development Forum

[HOWTO] build nexus 4 kernel

Tip us?
 
yduck
Old
(Last edited by yduck; 2nd February 2013 at 10:58 PM.)
#1  
Member - OP
Thanks Meter 42
Posts: 31
Join Date: Feb 2011
Default [HOWTO] build nexus 4 kernel

environment: ubuntu 10.04 LTS 64bit

get some package
sudo apt-get install gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc

install git
first install some packages that git depends on:
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev

get the new git source code from http://code.google.com/p/git-core/downloads/list.
download git-1.8.0.tar.gz
tar -xvf git-1.8.0.tar.gz
cd git-1.8.0
./configure
make
sudo make install
this will install git to /usr/local/bin/

get the kernel source code:
mkdir -p ~/android/kernel
cd ~/android/kernel
git clone https://android.googlesource.com/kernel/msm

check which version of kernel to checkout
mkdir ~/work/android/nexus4-kernel
cd ~/work/android/nexus4-kernel
git clone https://android.googlesource.com/device/lge/mako-kernel
cd mako-kernel
git log kernel
get the commit rev, which is e039dcb (nov 25, 2012), this number seems to correspond to the latest commit revision in https://android.googlesource.com/ker...ako-3.4-jb-mr1

check out the kernel
cd ~/android/kernel/kernel_msm
git checkout <commit version>
note: commit version is e039dcb, which is the result of the git log kernel command in the previous step

install google toolchain
mkdir ~/android/toolchain
cd ~/android/toolchain
git clone https://android.googlesource.com/pla...ndroideabi-4.6
add “export PATH=$PATH:~/android/toolchain/arm-linux-androideabi-4.6/bin” to ~/.profile and run source ~/.profile

setup environment variables and build
cd ~/android/kernel/kernel_msm
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-linux-androideabi-
make mako_defconfig
make -j4

done


if you wanna thank me. go to google play and try out my app Wishlist
https://play.google.com/store/apps/d....wish.wishlist
The Following 37 Users Say Thank You to yduck For This Useful Post: [ Click to Expand ]
 
evaradar
Old
#2  
Senior Member
Thanks Meter 34
Posts: 256
Join Date: Aug 2010
Location: Toronto
So with this I can make my own kernel for the Nexus 4? Hmm... will be nice to make one and get people to test it out for me lol.

I can edit the CPU, GPU, UV settings, etc? Is this only on Ubuntu or can it be done on Windows?
Evaradar
~ The One & Only

Current Phones
---------------
Nexus 4 8GB:
ROM: Stock 4.4.2
Kernel: Stock
Recovery: Stock.


Current Tablets
__________

Nexus 7 32GB WiFi
ROM: ParanoidAndroid v4 Beta 1
Android version: 4.4.2
Kernel: Stock
Recovery: TWRP v2.6.3.1

Nexus 7 16GB FHD WiFi
ROM: Stock 4.4.2
Kernel: Stock
Recovery; Stock
 
yduck
Old
#3  
Member - OP
Thanks Meter 42
Posts: 31
Join Date: Feb 2011
the kernel source is from google, but you can modify it as you wish. this is only for ubuntu. other linux environment will also work. but not windows.
The Following User Says Thank You to yduck For This Useful Post: [ Click to Expand ]
 
matt73300
Old
#4  
Member
Thanks Meter 111
Posts: 97
Join Date: May 2011
Location: Drôme - France

 
DONATE TO ME
You could change "make -j4" by "make -j$(grep -c ^processor /proc/cpuinfo)" ...
Google Nexus 4 (8Gb)
The Following User Says Thank You to matt73300 For This Useful Post: [ Click to Expand ]
 
yduck
Old
#5  
Member - OP
Thanks Meter 42
Posts: 31
Join Date: Feb 2011
Quote:
Originally Posted by matt73300 View Post
You could change "make -j4" by "make -j$(grep -c ^processor /proc/cpuinfo)" ...
that's handy to use.
But should the general rule of N in make -jN be twice the number of cpu core? for example, on my computer, I have two cores, so I use -j4.
The Following User Says Thank You to yduck For This Useful Post: [ Click to Expand ]
 
matt73300
Old
#6  
Member
Thanks Meter 111
Posts: 97
Join Date: May 2011
Location: Drôme - France

 
DONATE TO ME
Quote:
Originally Posted by yduck View Post
that's handy to use.
But should the general rule of N in make -jN be twice the number of cpu core? for example, on my computer, I have two cores, so I use -j4.
Not really nice for lambda users. I think it's better when it written as I said (no need to know how many cores you have), or j# (and say replace # by 2xnumber_of_cores).

I have 8 cores on my computer, so I use j16 and it's much faster than j4, some people should know it
Google Nexus 4 (8Gb)
The Following 3 Users Say Thank You to matt73300 For This Useful Post: [ Click to Expand ]
 
yduck
Old
#7  
Member - OP
Thanks Meter 42
Posts: 31
Join Date: Feb 2011
for some reason, the kernel I built cannot be booted.
when I did:

fastboot boot zImage

the phone stuck at the google logo.

any idea? I have seen other people in the forum built the kernel and booted it. there must be something wrong with the way I compiled the kernel, or the config is incorrect, or do I need to sign the kernel?
The Following User Says Thank You to yduck For This Useful Post: [ Click to Expand ]
 
dsana123
Old
(Last edited by dsana123; 3rd December 2012 at 01:21 PM.) Reason: Corrected mis-typing plus extra edits:
#8  
Member
Thanks Meter 6
Posts: 36
Join Date: Sep 2010
Quote:
Originally Posted by yduck View Post
for some reason, the kernel I built cannot be booted.
when I did:

fastboot boot zImage

the phone stuck at the google logo.

any idea? I have seen other people in the forum built the kernel and booted it. there must be something wrong with the way I compiled the kernel, or the config is incorrect, or do I need to sign the kernel?

Is the zImage file the one found in "arch/arm/boot/zImage"? If so, then you can't use this directly in fastboot. You need to create a boot.img file.

Edit 2: You could possibly try this: " fastboot flash:raw boot <kernel> <ramdisk> ". I personally have not done, this. I created the boot.img file and flashed it.

Edit 3: Note that Edit 2 does perform a flash instead of boot, so be very wary of this. I recommend you create a boot.img file and use "fastboot boot boot.img" for testing --- it's safer that way.
The Following User Says Thank You to dsana123 For This Useful Post: [ Click to Expand ]
 
yduck
Old
#9  
Member - OP
Thanks Meter 42
Posts: 31
Join Date: Feb 2011
Quote:
Originally Posted by dsana123 View Post
Is the zImage file the one found in "arch/arm/boot/zImage"? If so, then you can't use this directly in fastboot. You need to create a boot.img file.

Edit 2: You could possibly try this: " fastboot flash:raw boot <kernel> <ramdisk> ". I personally have not done, this. I created the boot.img file and flashed it.

Edit 3: Note that Edit 2 does perform a flash instead of boot, so be very wary of this. I recommend you create a boot.img file and use "fastboot boot boot.img" for testing --- it's safer that way.
great suggestion. I just figured this out yesterday. as you said, fastboot boot does not work with just the zImage. it needs a boot.img.
so I created a newboot.img by packing my zImage and the ramdisk extracted from google's stock boot.img, and the newboot.img boots!

the command "fastboot flash:raw <kernel> <ramdisk>" seems simple to use. does it have an equivalent "fastboot boot: raw <kernel> <ramdisk"? so I don't need to worry about breaking my phone.
The Following User Says Thank You to yduck For This Useful Post: [ Click to Expand ]
 
dsana123
Old
(Last edited by dsana123; 4th December 2012 at 02:00 AM.) Reason: Edited for spelling
#10  
Member
Thanks Meter 6
Posts: 36
Join Date: Sep 2010
Quote:
Originally Posted by yduck View Post
the command "fastboot flash:raw <kernel> <ramdisk>" seems simple to use. does it have an equivalent "fastboot boot: raw <kernel> <ramdisk"? so I don't need to worry about breaking my phone.
The fasboot.c source file at

https://android.googlesource.com/pla...oot/fastboot.c

indicates that there is no equivalent, although if you want to start modifying the fastboot.c code, it is probably easy enough to do so. Below is the relevant flash:raw code in fastboot.c:

Quote:
} else if(!strcmp(*argv, "flash:raw")) {
char *pname = argv[1];
char *kname = argv[2];
char *rname = 0;
require(3);
if(argc > 3) {
rname = argv[3];
skip(4);
} else {
skip(3);
}
data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
if (data == 0) die("cannot load bootable image");
fb_queue_flash(pname, data, sz);
From your post it sounds like you're using mkbootimg to create the boot image so you have what you need anyway (as long as you call mkbootimg with all the parameters corresponding to the boot header info from the boot image you extracted --- base offset, kernel offset, ramdisk offset, page offset, kernel command line , etc).

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes