[GUIDE] How to build kernel from source

Search This thread

thederekjay

Inactive Recognized Developer
Nov 15, 2010
4,628
8,913
DARKSIDE
G1ForFun said:
Damn man I try to like you but you act like such a condescending know it all 99% of the time. You need to chill out. Your answers in here are always talking down to people and you never offer anything useful. In fact, you act like this in most threads that are not yours. Really shows the kind of person that you are.

Sent from my SGH-T989 using XDA

Yeah you are exactly right. I mean this internet forum really show the exact person I am. I mean I am the most condescending, disrespectful, know it all of the board. I could careless if you don't like me or want to perceive what I say in a negitive manner. The info i offered was spot on and what was explaining was 100% correct. You want to comment on my post but seems you neglect the ones before it...

:: LOVE MY HATERS :: DARKSIDE ::
 

thederekjay

Inactive Recognized Developer
Nov 15, 2010
4,628
8,913
DARKSIDE
Orical said:
Long time no see man, looks like love is a distant dream over here huh?

Its terrible over here.. everyone knows more than the next. Complete waste of my time and effort over here. Not much love or appreciation for what you bring to the table and for the contributions to the community. Oh well, not my first rodeo and could careless how other people run their devices.. I know mine runs good..

:: LOVE MY HATERS :: DARKSIDE ::
 

Orical

Senior Member
May 22, 2011
2,211
731
Boston
Its terrible over here.. everyone knows more than the next. Complete waste of my time and effort over here. Not much love or appreciation for what you bring to the table and for the contributions to the community. Oh well, not my first rodeo and could careless how other people run their devices.. I know mine runs good..

:: LOVE MY HATERS :: DARKSIDE ::

Well it wasn't all peaches and cream over at the MT4G forum either but it looks like a tough crowd over here man, I thought you would have won over people here by now with the time you put in on the work but I guess that's not a big seller either.

It's gotta be the device dude, the old one still has at least 3 threads in the top ten and you haven't been over there in how long? Grain of salt and directions to the complaint department is all you can do lol...... I'll catch you later man.
 

JaZart

Senior Member
Jan 8, 2012
1,037
210
Columbus
Its terrible over here.. everyone knows more than the next. Complete waste of my time and effort over here. Not much love or appreciation for what you bring to the table and for the contributions to the community. Oh well, not my first rodeo and could careless how other people run their devices.. I know mine runs good..

:: LOVE MY HATERS :: DARKSIDE ::

I for one and many others love your work.

You've given us a lot. Please continue support :(
 

Racing19969

Senior Member
Aug 11, 2011
632
1,236
Columbus
www.cell-dr.com
I follow you right up untill here. I have my boot.img in the folder but when I try I get "extractboot: command not found" any help on this? I might have just missed something.

Did you download the extractboot files and put them in your system path? If not, that is why. You are using a command and the file is not there to execute....
Hope this helps you...
 

Omnicide

Senior Member
Mar 7, 2012
89
5
Did you download the extractboot files and put them in your system path? If not, that is why. You are using a command and the file is not there to execute....
Hope this helps you...

Well im very new to this I just wanted to play around i learn hands on. But I am 99% sure I put it were it need to be. I was able to unzip it useing UXTerm my stock boot.img is in there as well. I even tryed the downloading the other extractboot of the ref. site and still no luck.
 

Racing19969

Senior Member
Aug 11, 2011
632
1,236
Columbus
www.cell-dr.com
Did you make sure the files are executable?
What OS are you using?
How are you executing the command?



open a terminal in the folder containing your file and execute: ./extractboot bootimg
 

Omnicide

Senior Member
Mar 7, 2012
89
5
Did you make sure the files are executable?
What OS are you using?
How are you executing the command?



open a terminal in the folder containing your file and execute: ./extractboot bootimg

I am just going by this thread. I am a 100% newb to this. I downloaded ubuntu witch I have never used before but getting the hang of it. (kinda thinking this is just dos.) I also don't know how to see if it is executable. For the command after extractboot was tar xzf in I did just as it says and "extractboot boot.img. Now I know the file is there because when I type in the "directory"/boot.img it says permission denied. This is why I am lost I seem to have everything right but it just not working for me. Something small and dumb I am missing I know it.
 

datzstr8

Senior Member
Aug 30, 2008
86
97
Make sure it is executable. Type this:

chmod a+x extractboot

It seems like you are new to linux in general. Here is a list of things I recommend reading to get up to speed and make your life easier when working with this kind of stuff:

- read up on the "chmod" command
- read up on the "ls" command. with this you can check to see if the file is executable (use -l option)
- read up on how to modify your path (environment variable is $PATH)
- read up on ".bashrc" (can set path variable in here)

good luck
 
Last edited:

Omnicide

Senior Member
Mar 7, 2012
89
5
Make sure it is executable. Type this:

chmod a+x extractboot

It seems like you are new to linux in general. Here is a list of things I recommend reading to get up to speed and make your life easier when working with this kind of stuff:

- read up on the "chmod" command
- read up on the "ls" command. with this you can check to see if the file is executable (use -l option)
- read up on how to modify your path (environment variable is $PATH)
- read up on ".bashrc" (can set path variable in here)

good luck

I tryed the executable code nothing happen no error and nothing changed. tryed the boot.img
still got command not found. but thank you I will read up on this I am new to it all seens i got galaxy i found this and found a new insterent and witch i will figure this all out. Thanks for putting up with me,



Edit: Well by putting in ""Directory"/extractboot" I was able to make the folders I needed Out/Ramdisk now if I can just make it run on boot.img lol
 
Last edited:

Omnicide

Senior Member
Mar 7, 2012
89
5
Alright so I have made it a step forward in this issue I have. And now I havent finshed reading up on all the stuff from the above post. This is what I am getting know if this might help someone help me.

Code:
./extractboot boot.img
./extractboot: line 12: ./split_bootimg.pl: Permission denied
gzip: ../../boot.img-ramdisk.gz: No such file or directory
cpio: permature end of archive

I am starting to think my stock boot.img I backed up doesn't work.
 

datzstr8

Senior Member
Aug 30, 2008
86
97
I think you need to set the permission for the split_bootimg.pl (perl script) to be executable also. Try "chmod a+x split_bootimg.pl" and try again. Either that or you don't have perl. You can install with this:

sudo apt-get install perl
 

Omnicide

Senior Member
Mar 7, 2012
89
5
I think you need to set the permission for the split_bootimg.pl (perl script) to be executable also. Try "chmod a+x split_bootimg.pl" and try again. Either that or you don't have perl. You can install with this:

sudo apt-get install perl

That was the whole problem set the permission thank you very much problem fixed for the next person that has this issue.
 

interloper

Inactive Recognized Developer
Feb 17, 2008
644
420
El Paso
Usually permission denied errors are caused by improper permissions. Change all permission of all files you are working with to owner/rw/executable. As forall the rest of the questions, I'm pressed for time right now but an answer back later. Don't give up, we can work it out.
 

Omnicide

Senior Member
Mar 7, 2012
89
5
I am a big pain I know this, but I ran into another problem.

Code:
cp crypto/ansi_cprng.ko $INITRAMFSDIR/lib/modules/

When I do this code I get

Code:
cp: cannot stat `crypto/ansi_cprng.ko` : No such file or directory

So I went in the kernel directory to find out whats going on. my file in the kernel is ansi_cprng.c in fact all the file in this directory have the .c. I don't know if I messed something up or I got another not normal issue going on here. I try to work with this but im stuck so I figured I would post again.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 46
    Overview

    Here are the steps to build your own kernel from source. This example does nothing special. It just shows you how to build the stock kernel. It is a good starting point to making your own stuff. Experts, please correct me where I am wrong. This stuff is still new to me also.

    These instructions work for both T989 (T-Mobile) and I727 (AT&T) variants of the Samsung Galaxy S2 phones.


    Special Thanks

    Special thanks to "interloper" and "dtm_stretch" for helping me learn all of this. Couldn't have done it without them.


    Requirements

    I am using Ubuntu 10.10 32-bit to do all my builds


    Instructions

    1) Get Samsung Source Code

    First you need to get a copy of the kernel source code from Samsung. You can download it from the link below.

    For T-Mobile users download the one that says T989:
    https://opensource.samsung.com/reception/receptionSub.do?method=search&searchValue=SGH-T989

    For AT&T users download the one that says SGH-I727:
    https://opensource.samsung.com/reception/receptionSub.do?method=search&searchValue=SGH-I727


    2) Unzip Samsung Source Code

    Unzip the source code you just download with this command:

    For T989:
    Code:
    unzip SGH-T989_GB_Opensource.zip

    For I727:
    Code:
    unzip SGH-I727_ATT_Opensource.zip

    There will be 4 files extracted. The one we are interested in for this exercise is SGH-T989_Kernel.tar.gz for T989 devicees or SGH-I727_ATT_Kernel.tar.gz for I727 devices.


    3) Extract Kernel

    Next we need to extract the kernel into a directory.

    For T989:
    Code:
    mkdir kernel
    tar xzf SGH-T989_Kernel.tar.gz -C kernel

    or

    For I727:
    Code:
    mkdir kernel
    tar xzf SGH-I727_ATT_Kernel.tar.gz -C kernel


    4) Get a Copy of initramfs

    Next you need to get a copy of the initramfs for your phone. For T989 users you can get the stock initramfs from bubby323's github here: https://github.com/bubby323/anomaly_kernel_platform_SGH-T989

    For I727 users you must use the alternate method below to get the initramfs. T989 users can choose to use the link above or go with the alternate method below.

    Alternate method:

    You can extract it yourself from an existing boot.img file. I got mine off of my phone using clockworkmod backup (boot.img file) and using the extractboot tool to extract the initramfs. The tool can be downloaded here: http://www.mediafire.com/?lc12eceeh617b97

    Extract extractboot.tar.gz
    Code:
    tar xzf extractboot.tar.gz

    Call this to extract your boot.img to get the initramfs folder
    Code:
    extractboot boot.img

    If you get any errors with calling extractboot, make sure "extractboot" and "split_bootimg.pl" are executable first. If not, use "chmod a+x extractboot" (do the same for split_bootimg.pl).

    Once extracted, the "out/ramdisk" folder is your extracted initramfs folder.

    reference: http://www.freeyourandroid.com/guide/extract-edit-repack-boot-img-windows


    5) Download Arm Toolchain

    This toolchain will allow you to cross compile for your phone. There are several versions to choose. I currently use the 2010q1 version here: https://sourcery.mentor.com/sgpp/li...1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

    Or choose another version if you like (version 2009q3 seems to be popular): https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription3053


    6) Extract Toolchain

    Code:
    tar xjf arm-2010q1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2


    7) Download mkbootimg Tools

    Download mkbootimg tools from here: http://www.mediafire.com/?w06d1m6n1dgo4op

    Extract the file with
    Code:
    tar xzf mkboottools.tar.gz

    There will be three files
    Code:
    mkbootfs  
    mkbootimg  
    mkbootimg-sg2x

    "mkbootimg" is the original program to make the boot image but is not used for our phone. Our phone requires an edit to the ramdisk address which is why I also included "mkbootimg-sg2x" which we will use instead.

    *Extra Info: the default ramdisk offset is 0x01000000 while our phone needs 0x01400000.

    Move the three files to somewhere in your system PATH.


    8) Compile Script

    Now we are ready to compile the kernel. I have provided a script below to automate the process. You will need to change the paths to work with your environment.

    *For I727 users only: change "msm8660_celox_usa_tmo_defconfig" to "msm8660_celox_usa_att_defconfig" in the script below.

    *Update: Thanks to InstigatorX for his comment:
    Also, for ATT the celox make command should be "make msm8660_celox_usa_att_rev02_defconfig" to make the latest 2.3.6 kernel.

    Code:
    INITRAMFSDIR=~/t989/initramfs
    
    export ARCH=arm
    export CROSS_COMPILE=~/arm-2010q1/bin/arm-none-eabi-
    
    cd kernel
    make clean
    make mrproper
    make msm8660_celox_usa_tmo_defconfig
    make -j4
    
    # copy the freshly compiled modules to the initramfs.
    cp crypto/ansi_cprng.ko $INITRAMFSDIR/lib/modules/
    cp drivers/bluetooth/bthid/bthid.ko $INITRAMFSDIR/lib/modules/
    cp arch/arm/common/cpaccess.ko $INITRAMFSDIR/lib/modules/
    cp arch/arm/mach-msm/dal_remotetest.ko $INITRAMFSDIR/lib/modules/
    cp drivers/net/wireless/bcm4330/dhd.ko $INITRAMFSDIR/lib/modules/
    cp arch/arm/mach-msm/dma_test.ko $INITRAMFSDIR/lib/modules/
    cp drivers/input/evbug.ko $INITRAMFSDIR/lib/modules/
    cp drivers/media/video/gspca/gspca_main.ko $INITRAMFSDIR/lib/modules/
    cp arch/arm/perfmon/ksapi.ko $INITRAMFSDIR/lib/modules/
    cp drivers/video/backlight/lcd.ko $INITRAMFSDIR/lib/modules/
    cp drivers/net/wireless/libra/librasdioif.ko $INITRAMFSDIR/lib/modules/
    cp drivers/misc/msm_tsif.ko $INITRAMFSDIR/lib/modules/
    cp arch/arm/oprofile/oprofile.ko $INITRAMFSDIR/lib/modules/
    cp drivers/crypto/msm/qcedev.ko $INITRAMFSDIR/lib/modules/
    cp drivers/crypto/msm/qce.ko $INITRAMFSDIR/lib/modules/
    cp drivers/crypto/msm/qcrypto.ko $INITRAMFSDIR/lib/modules/
    cp drivers/scsi/scsi_wait_scan.ko $INITRAMFSDIR/lib/modules/
    cp drivers/spi/spidev.ko $INITRAMFSDIR/lib/modules/
    cp drivers/misc/tsif_chrdev.ko $INITRAMFSDIR/lib/modules/
    cp drivers/misc/vibetonz/vibrator.ko $INITRAMFSDIR/lib/modules/


    9) Get Compiled Kernel

    The compiled kernel image is in the kernel source folder under "arch/arm/boot/zImage"

    Copy the zImage file to a working area, preferably where you keep your initramfs folder.

    Here is an example folder structure:

    Code:
    work
      - zImage
      - initramfs


    10) Make boot.img File

    Next we need to merge the kernel and initramfs directory into a boot.img file.

    zip up ramdisk
    Code:
    mkbootfs initramfs | gzip > ramdisk.gz

    make boot image
    Code:
    mkbootimg-sg2x --kernel zImage --ramdisk ramdisk.gz --cmdline "androidboot.hardware=qcom msm_watchdog.appsbark=0 msm_watchdog.enable=1 loglevel=4" -o boot.img --base 0x40400000 --pagesize 2048


    11) tar boot.img

    Tar your boot.img file so it can be flashed with Odin.
    Code:
    tar cvf MyKernel.tar boot.img 
    md5sum -t MyKernel.tar >> MyKernel.tar
    mv MyKernel.tar MyKernel.tar.md5


    12) Flash with Odin

    Flash MyKernel.tar.md5 with odin under PDA. Please follow the flashing guides found in other posts. They do a better job at explaining.


    13) Experiment *

    Now try to customize your kernel to add in new features and experiment. I am going to learn how to compile the stock platform also. Once I know how I will post up a guide for that also. If someone already has a guide to build the platform please post. Also it would be great if you can post sources for me to read so I can learn how to build the platform. Thanks.


    Optional

    You might notice that the modules you compiled are significantly bigger than the original stock modules that came with the phone. That is because the stock modules were stripped of all debug info. To do this you need to run the below command at the end to get the "stripped" modules. Change INSTALL_MOD_PATH to point to any folder you like to hold the modules. You then need to copy these modules instead of the ones in the build script above.

    Code:
    make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=~/stripped/modules modules_install


    What's Next?

    Go here to learn how to start making changes to your ROM: http://xdaforums.com/showthread.php?p=23343879
    1
    Great info !! Super !

    Some questions: 1. How does one allow for SELECTION of custom boot animation? Is that a kernel thing or some thing else?

    2. What about adding things like Voodoo Sound or some mod like that?

    Thanks for any info !!

    I am glad you like it. I wanted to post this guide up so that noobs like me have a good starting point to learn this stuff.

    I can take a crack at answering your questions, but do note that I am also a noob:

    1) I would think a custom boot animation would be part of the ROM but not sure

    2) I do not know what Voodoo Sound is but if it is an application then it would be modifying the ROM. If it is an enhancement to the audio drivers then it is kernel. Either way I would not know what to change. Sorrry.

    I know I wasn't much help. But I tried :D

    By the way, I am currently trying to learn how to make my own custom ROM. If you know of any guides that would be great if you can post them here. I will definitely post what I find. Currently I am downloading ROMs from this forum and seeing what they did to learn. One thing I am still confused about is if these guys built these ROM from source or used the binaries from the Stock ROM as base.

    Thanks.
    1
    They r not getting compiled into initramfs.

    :: LOVE MY HATERS :: DARKSIDE ::

    They are there. I just ran my script, then decompressed everything again. There's a bunch of modules with this kernel, a lot more than the e4gt. InstigatorX, good work.

    EDIT: Try theses threads to give yo an idea about adding stuff to the kernel:

    http://xdaforums.com/showthread.php?t=1442870
    http://xdaforums.com/showthread.php?t=1494804
    1
    I grabbed the toolchain from this thread and replaced the NDK version I was using. Seems to be working now. Any ideas/pointers on how to add new governor or scheduler?

    Please create a GUIDE thread when you know how to do this. It will help the community out a lot. Thanks.
    1
    That was the whole problem set the permission thank you very much problem fixed for the next person that has this issue.

    I'll put a note in the guide to remind people to set the permissions. Thanks.