[Guide] Building from sources [Kernel only for now]

Search This thread

cdesai

Inactive Recognized Developer
Jan 16, 2011
2,296
4,088
IN YOUR HEAD
Hello everyone.

This guide will help you in building a kernel from source for your Nexus 10

Later, when 4.2 hits AOSP, i'll add a guide for building that too :)

You will need a computer running Linux / OSX to build the kernel, natively, or via a VM.
This guide assumes you’re running any Linux distro.

Getting a toolchain:
You need a toolchain to build the kernel.
The preferred one is Google’s toolchain, the same they use to build AOSP.

In a terminal, type:
Code:
git clone [url]https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/[/url]
export PATH=$PATH:$(pwd)/arm-linux-androideabi-4.6/bin
export CROSS_COMPILE=arm-linux-androideabi-

TIp: paste the export statements in your ~/.bashrc to have them exported each login.

Getting the kernel source:
The kernel source for Nexus devices is available from Google’s servers.

Source : https://android.googlesource.com/kernel/exynos
Github Mirror: https://github.com/chirayudesai/android_kernel_exynos

Open the terminal, and type the below commands to get the kernel source on your computer.

Code:
mkdir -p android/kernel
cd android/kernel

For Nexus 10, we get the exynos kernel sources.
Code:
git clone [url]https://android.googlesource.com/kernel/exynos[/url]

Next, we change our directory to the newly fetched source.

Type
Code:
cd exynos

Figuring out what to build:
Now, we need to figure out which revision to build.
You need to be exactly sure about this, otherwise there are chances that the compiled kernel won’t work.

The commit to build upon can be found by a few ways.
To get the kernel sources matching the device tree, type the below in the device tree.
Code:
git log kernel

Then type the below in the kernel tree
Code:
git checkout <commit>

The commit of the version running on the current review units is 52f6ab1 (probably), which is same as branch android-exynos-manta-3.4-jb-mr1-fr .

Compiling:

Name of defconfig: manta_defconfig

cd to the directory of the kernel source, then type the below in a terminal.

Code:
export ARCH=arm
export SUBARCH=arm

Code:
make <name_of_defconfig>
make

The kernel image will be ready at arch/arm/boot/zImage

To flash it, you need to make it into a boot.img, more on that later. when we have more sources.
 

alias_neo

Senior Member
Jun 9, 2006
2,081
205
London
Nice work, it's been nice to see some instructions on building additional kernel modules too.

Sent from my GT-I9300 using Tapatalk 2
 

shimp208

Inactive Recognized Contributor
Jan 25, 2011
2,613
3,089
Boston
Great guide! I look forward to seeing your tutorial on compiling 4.2 from source :).

Sent from my SCH-I535 using xda premium
 

jdbeitz

Senior Member
Jul 19, 2010
1,113
505
Cincinnati
Super awesome! :D I'm currently thoroughly:good: learning the rom building process with my nexus... ill get to this!
 

matt95

Senior Member
Aug 8, 2010
5,962
2,370
Milan
hey man, i got stuck at this point
Code:
 git log kernel

it gives me this error

Code:
fatal: ambiguous argument 'kernel': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

didn't really get that point... thanks :good:
 

cdesai

Inactive Recognized Developer
Jan 16, 2011
2,296
4,088
IN YOUR HEAD
hey man, i got stuck at this point
Code:
 git log kernel

it gives me this error

Code:
fatal: ambiguous argument 'kernel': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

didn't really get that point... thanks :good:

It has to be typed in the device tree, which hasn't hit AOSP yet, but should soon.

Sent from my GT-P1000
 

renzyyy

Member
Aug 6, 2010
38
28
Milwaukee, WI
renzy.land
i was able to make a build tonight from aosp, waiting for my device to arrive & then ill be able to test. but as far as i could tell the output sizes were pretty on compared to the factory image files i extracted http://renzy.me/aoi

...just realized i didnt extract proprietary binaries.
 
Last edited:

jrod091

Senior Member
Feb 13, 2012
337
88
Atlanta, GA
so you say that you need to make the zImage into a boot.img (being a noob about this...) on my SGSII, I can flash zImages and boot.img, so I'm confused, lol
 

renzyyy

Member
Aug 6, 2010
38
28
Milwaukee, WI
renzy.land
so you say that you need to make the zImage into a boot.img (being a noob about this...) on my SGSII, I can flash zImages and boot.img, so I'm confused, lol

i think it depends on how youre flashing. with the sgsii youre prob using odin/heimdall & it might just overwrite the kernel. flashing with fastboot might require the boot.img cause it contains a ramdisk image after the kernel & is writing a partition. thats just my guess at least, someone else might have a better/more accurate answer for ya
 
  • Like
Reactions: jrod091

matt95

Senior Member
Aug 8, 2010
5,962
2,370
Milan
i think it depends on how youre flashing. with the sgsii youre prob using odin/heimdall & it might just overwrite the kernel. flashing with fastboot might require the boot.img cause it contains a ramdisk image after the kernel & is writing a partition. thats just my guess at least, someone else might have a better/more accurate answer for ya

yeah that's true, but for instance with HTC S-OFFed devices you don't even need to flash the boot.img....
 

renzyyy

Member
Aug 6, 2010
38
28
Milwaukee, WI
renzy.land
... To flash it, you need to make it into a boot.img, more on that later. when we have more sources.

you can extract the contents from the factory image & use getramdisk.py to get the ramdisk.img out of the current boot.img (or use this ramdisk.img)

then once youve compiled the kernel successfully, use mkbootimg from android_bootimg_tools.tar.gz to repack your boot.img.

if you want to just test...
fastboot boot [new-boot.img]

and flash if satisfied...
fastboot flash boot [new-boot.img]

just tested out if anyone wants some verification... screenshot
 
Last edited:
  • Like
Reactions: ridobe and Vlad_z

craigacgomez

Senior Member
Jan 29, 2010
2,215
3,924
Tustin
@cdesai, shouldn't we be using arm-eabi- instead of arm-linux-androideabi- as CROSS_COMPILE

Code:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/
export PATH=$PATH:$(pwd)/arm-eabi-4.6/bin
export CROSS_COMPILE=arm-eabi-

Building with arm-linux-androideabi- causes issues with kernel modules... here's an example of such an issue https://groups.google.com/forum/?fromgroups=#!topic/android-kernel/dzEIOVuxtEo

And the most updated kernel branch is android-exynos-manta-3.4-jb-mr1 not android-exynos-manta-3.4-jb-mr1-fr
 
  • Like
Reactions: renzyyy

sam3000

Senior Member
Jul 11, 2009
365
421
Seattle
@cdesai, shouldn't we be using arm-eabi- instead of arm-linux-androideabi- as CROSS_COMPILE

Code:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/
export PATH=$PATH:$(pwd)/arm-eabi-4.6/bin
export CROSS_COMPILE=arm-eabi-

Building with arm-linux-androideabi- causes issues with kernel modules... here's an example of such an issue https://groups.google.com/forum/?fromgroups=#!topic/android-kernel/dzEIOVuxtEo

And the most updated kernel branch is android-exynos-manta-3.4-jb-mr1 not android-exynos-manta-3.4-jb-mr1-fr

Yes, I couldn't get md4 and cifs modules to load with arm-linux-androideabi-4.6:
<3>[ 1250.492203] md4: unknown relocation: 27
<4>[ 1260.230901] cifs: Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)

However, with this:
git clone https://android.googlesource.com/platform/prebuilt
export PATH=$PATH:$PWD/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
export CROSS_COMPILE=arm-eabi-

The modules load okay:
shell@android:/mnt/shell/emulated/0 # lsmod
cifs 269223 0 - Live 0x00000000
md4 3442 0 - Live 0x00000000

(Now I have to work out why neither mount nor cifsmanager are working as expected...)
 

craigacgomez

Senior Member
Jan 29, 2010
2,215
3,924
Tustin
Yes, I couldn't get md4 and cifs modules to load with arm-linux-androideabi-4.6:
<3>[ 1250.492203] md4: unknown relocation: 27
<4>[ 1260.230901] cifs: Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)

However, with this:
git clone https://android.googlesource.com/platform/prebuilt
export PATH=$PATH:$PWD/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
export CROSS_COMPILE=arm-eabi-

The modules load okay:
shell@android:/mnt/shell/emulated/0 # lsmod
cifs 269223 0 - Live 0x00000000
md4 3442 0 - Live 0x00000000

(Now I have to work out why neither mount nor cifsmanager are working as expected...)

I know the reason... busybox needs to be patched... i guess it's something new in 3.4.5 kernel... I haven't done the patch yet

https://github.com/OpenELEC/OpenELEC.tv/commit/f66041febdb07d13a158dab5da901d208cf4fff9
 

sam3000

Senior Member
Jul 11, 2009
365
421
Seattle

Top Liked Posts

  • There are no posts matching your filters.
  • 11
    Hello everyone.

    This guide will help you in building a kernel from source for your Nexus 10

    Later, when 4.2 hits AOSP, i'll add a guide for building that too :)

    You will need a computer running Linux / OSX to build the kernel, natively, or via a VM.
    This guide assumes you’re running any Linux distro.

    Getting a toolchain:
    You need a toolchain to build the kernel.
    The preferred one is Google’s toolchain, the same they use to build AOSP.

    In a terminal, type:
    Code:
    git clone [url]https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/[/url]
    export PATH=$PATH:$(pwd)/arm-linux-androideabi-4.6/bin
    export CROSS_COMPILE=arm-linux-androideabi-

    TIp: paste the export statements in your ~/.bashrc to have them exported each login.

    Getting the kernel source:
    The kernel source for Nexus devices is available from Google’s servers.

    Source : https://android.googlesource.com/kernel/exynos
    Github Mirror: https://github.com/chirayudesai/android_kernel_exynos

    Open the terminal, and type the below commands to get the kernel source on your computer.

    Code:
    mkdir -p android/kernel
    cd android/kernel

    For Nexus 10, we get the exynos kernel sources.
    Code:
    git clone [url]https://android.googlesource.com/kernel/exynos[/url]

    Next, we change our directory to the newly fetched source.

    Type
    Code:
    cd exynos

    Figuring out what to build:
    Now, we need to figure out which revision to build.
    You need to be exactly sure about this, otherwise there are chances that the compiled kernel won’t work.

    The commit to build upon can be found by a few ways.
    To get the kernel sources matching the device tree, type the below in the device tree.
    Code:
    git log kernel

    Then type the below in the kernel tree
    Code:
    git checkout <commit>

    The commit of the version running on the current review units is 52f6ab1 (probably), which is same as branch android-exynos-manta-3.4-jb-mr1-fr .

    Compiling:

    Name of defconfig: manta_defconfig

    cd to the directory of the kernel source, then type the below in a terminal.

    Code:
    export ARCH=arm
    export SUBARCH=arm

    Code:
    make <name_of_defconfig>
    make

    The kernel image will be ready at arch/arm/boot/zImage

    To flash it, you need to make it into a boot.img, more on that later. when we have more sources.
    2
    ... To flash it, you need to make it into a boot.img, more on that later. when we have more sources.

    you can extract the contents from the factory image & use getramdisk.py to get the ramdisk.img out of the current boot.img (or use this ramdisk.img)

    then once youve compiled the kernel successfully, use mkbootimg from android_bootimg_tools.tar.gz to repack your boot.img.

    if you want to just test...
    fastboot boot [new-boot.img]

    and flash if satisfied...
    fastboot flash boot [new-boot.img]

    just tested out if anyone wants some verification... screenshot
    1
    so you say that you need to make the zImage into a boot.img (being a noob about this...) on my SGSII, I can flash zImages and boot.img, so I'm confused, lol

    i think it depends on how youre flashing. with the sgsii youre prob using odin/heimdall & it might just overwrite the kernel. flashing with fastboot might require the boot.img cause it contains a ramdisk image after the kernel & is writing a partition. thats just my guess at least, someone else might have a better/more accurate answer for ya
    1
    @cdesai, shouldn't we be using arm-eabi- instead of arm-linux-androideabi- as CROSS_COMPILE

    Code:
    git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/
    export PATH=$PATH:$(pwd)/arm-eabi-4.6/bin
    export CROSS_COMPILE=arm-eabi-

    Building with arm-linux-androideabi- causes issues with kernel modules... here's an example of such an issue https://groups.google.com/forum/?fromgroups=#!topic/android-kernel/dzEIOVuxtEo

    And the most updated kernel branch is android-exynos-manta-3.4-jb-mr1 not android-exynos-manta-3.4-jb-mr1-fr