Difference between revisions of "ROM Android: Compile Kernel untuk ROM Android"
Onnowpurbo (talk | contribs) (New page: Building Kernels In this document Figuring out which kernel to build Identifying kernel version Downloading sources Downloading a prebuilt gcc Building If you are onl...) |
Onnowpurbo (talk | contribs) |
||
Line 112: | Line 112: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Hello everyone, want to compile an Android kernel on your own? Than why not begin doing it so by following the simple guide below? | ||
+ | 1) Setup Environment: | ||
+ | |||
+ | First you will need these things, | ||
+ | |||
+ | A Linux PC (32 bit will work for compilation of kernel) | ||
+ | Basic knowledge of using terminal in Unix based operating system | ||
+ | Few packages for compilation | ||
+ | Tool chains for compilation | ||
+ | Kernel source code | ||
+ | Patience :p | ||
+ | |||
+ | So now we begin, First of all open terminal in your Linux PC. I am using here Linux Mint 16, a Debian based Linux Distribution. You can use any Linux distro for it such as Ubuntu, fedora, Arch Linux, etc. procedure will be same just you need to use different commands with terminal as per your distro. Now type this code in your terminal: | ||
+ | |||
+ | sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git | ||
+ | |||
+ | |||
+ | |||
+ | 1 | ||
+ | |||
+ | This will install required packages for kernel compilation. Now last thing, we need tool chains for compiling kernel. You can get it from here: https://github.com/crossfire77/Android_Toolchains Download it and extract it somewhere. Then, We have to setup path of our tool chains, so type this in terminal: | ||
+ | |||
+ | gedit .bashrc | ||
+ | |||
+ | It will open one document, then put this codes at the end of it. | ||
+ | |||
+ | export PATH=${PATH}:path/to/toolchain/folder/arm-eabi-4.4.3/bin | ||
+ | |||
+ | 2 | ||
+ | |||
+ | Now we are done with downloading and setting up things. Let’s move to next step! | ||
+ | 2) Download Source Code: | ||
+ | |||
+ | Kernel source codes are under GNU GPL open source license so vendors (ex. Sony, HTC, Samsung, LG) have to release it. You can find your appropriate kernel source code from mentioned websites: | ||
+ | |||
+ | For Sony: http://developer.sonymobile.com/ | ||
+ | |||
+ | For Samsung: http://opensource.samsung.com/ | ||
+ | |||
+ | For HTC: http://www.htcdev.com/ | ||
+ | |||
+ | For LG: http://www.lg.com/global/support/opensource/index | ||
+ | |||
+ | Just download it from mentioned websites as per your device and extract it somewhere in your computer. | ||
+ | 3) Getting Config file: | ||
+ | |||
+ | Now this is where you should put your focus. For building a kernel you need config file. There is two ways for it: | ||
+ | |||
+ | You can either get it from your phone with help of ADB (Android Debug Bridge) or | ||
+ | You can get it from your kernel source code. | ||
+ | |||
+ | I will show you both the ways of doing it so. | ||
+ | |||
+ | 1) Getting config file from your phone with the help of ADB: | ||
+ | |||
+ | First of all connect your phone to your computer. | ||
+ | Then type the mentioned code below: | ||
+ | |||
+ | adb pull proc/config.gz ~/home/crossfire77/kernel | ||
+ | |||
+ | This will pull your existing config file from your phone and put it in kernel folder. Now extract it, | ||
+ | |||
+ | zcat config.gz > .config | ||
+ | |||
+ | So we have directly config for building our kernel. | ||
+ | |||
+ | NOTE: Many times users’ faces errors while connecting phone with computer via ADB, it’s mostly issue of a permission. There is two solutions for it. | ||
+ | |||
+ | 1.) Using ADB as root user: $sudo -s $ adb kill-server $ adb start-server $ adb devices And you will see your device now in terminal, it is a temporary solution meaning you have to do every time you connect your phone. | ||
+ | |||
+ | 2.) Solve permission problem permanently: | ||
+ | |||
+ | Open terminal and type this: $ sudo gedit /etc/udev/rules.d/51-android.rules and copy content from this file, http://goo.gl/bldQS9 In this file, please replace “crossfire77” with your username. | ||
+ | |||
+ | Now last thing to do is, giving executing permission to file, and we are good to go. | ||
+ | |||
+ | $ sudo chmod a+r /etc/udev/rules.d/51-android.rules $ sudo service udev restart | ||
+ | |||
+ | This will solve your problem with ADB and FASTBOOT while connecting through them your phone with computer. | ||
+ | |||
+ | 2) Getting config file from kernel source code: | ||
+ | |||
+ | This part is little tricky. For this you have to have little knowledge about your device chipset number. In kernel source code there are lots of config files so from your chipset number you can find your config file. As example, My device is HTC Wildfire S and it has MSM7227 chipset so I can find its config in mentioned path: arch/arm/configs/msm7227_defconfig3 | ||
+ | |||
+ | So now just type this code in terminal: | ||
+ | |||
+ | make ARCH=arm CROSS_COMPILE=arm-eabi- msm7227_defconfig | ||
+ | |||
+ | 4 | ||
+ | |||
+ | It will create .config file from your existing chipset config and then we are good to go. As I told you before you need to have little knowledge about your device chipset then you can able to tell what is your correct config file, so be careful while doing this step. Everything is done now so shall we start building? | ||
+ | |||
+ | 4) Building: | ||
+ | |||
+ | Type this in your terminal, | ||
+ | |||
+ | make ARCH=arm CROSS_COMPILE=arm-eabi- -jX | ||
+ | |||
+ | 5 It is main command for compilation and here X can be replaced by maximum numbers of jobs your computer can handle simultaneously. For ease just enter the twice number of your cores. Ex. If your computer has two cores enter four. | ||
+ | |||
+ | NOTE: Please do not enter high number or your computer will explode due to overheating. | ||
+ | |||
+ | It will take around ~15-1 hour as per your computer hardware specs.so keep sit down and keep patience. After completing this procedure we will have our zImage (kernel)! afafaLet’s create one working directory: | ||
+ | |||
+ | mkdir kernell | ||
+ | |||
+ | Now, we will copy our zImage to our working directory: | ||
+ | |||
+ | cp arch/arm/boot/zImage kernell | ||
+ | |||
+ | Next step, modules (modules builds with kernel and we need it for Wi-Fi and etc. as per your device requirement) | ||
+ | |||
+ | find . -name '*ko' -exec cp '{}' kernell \; | ||
+ | |||
+ | 7 So we are done with the main part, now last step to make flash able zip out of this to flash our kernel. | ||
+ | |||
+ | 5) Making Flashable Zip: We are done with compiling and building task and at the end we have our zImage (kernel) and modules. Screenshot from 2014-03-05 14:22:03 Now time to flash it to your phone, for it we have one very easy method, “any kernel updater” by koush. So download this file from here: http://goo.gl/mQpHhC ffafa | ||
+ | |||
+ | So, this was all about compiling an Android Kernel. Share me your any doubts or acknowledgements if you have. | ||
+ | |||
+ | Have fun compiling Android Kernel. | ||
Line 121: | Line 251: | ||
* https://source.android.com/source/building-kernels.html | * https://source.android.com/source/building-kernels.html | ||
+ | * http://www.movzio.com/howto/compile-android-kernel-source-beginners-guide-2/ |
Revision as of 09:01, 10 November 2014
Building Kernels In this document
Figuring out which kernel to build Identifying kernel version Downloading sources Downloading a prebuilt gcc Building
If you are only interested in the kernel, you may use this guide to download and build the appropriate kernel.
The following instructions assume that you have not downloaded all of AOSP. If you have downloaded all of AOSP, you may skip the git clone steps other than the step to download the actual kernel sources.
We will use the Pandaboard kernel in all the following examples. Figuring out which kernel to build
This table lists the name and locations of the kernel sources and binaries: Device Binary location Source location Build configuration
hammerhead device/lge/hammerhead-kernel kernel/msm hammerhead_defconfig flo device/asus/flo-kernel/kernel kernel/msm flo_defconfig deb device/asus/flo-kernel/kernel kernel/msm flo_defconfig manta device/samsung/manta/kernel kernel/exynos manta_defconfig mako device/lge/mako-kernel/kernel kernel/msm mako_defconfig grouper device/asus/grouper/kernel kernel/tegra tegra3_android_defconfig tilapia device/asus/grouper/kernel kernel/tegra tegra3_android_defconfig maguro device/samsung/tuna/kernel kernel/omap tuna_defconfig toro device/samsung/tuna/kernel kernel/omap tuna_defconfig panda device/ti/panda/kernel kernel/omap panda_defconfig stingray device/moto/wingray/kernel kernel/tegra stingray_defconfig wingray device/moto/wingray/kernel kernel/tegra stingray_defconfig crespo device/samsung/crespo/kernel kernel/samsung herring_defconfig crespo4g device/samsung/crespo/kernel kernel/samsung herring_defconfig
You will want to look at the git log for the kernel binary in the device project that you are interested in.
Device projects are of the form device/<vendor>/<name>.
$ git clone https://android.googlesource.com/device/ti/panda $ cd panda $ git log --max-count=1 kernel
The commit message for the kernel binary contains a partial git log of the kernel sources that were used to build the binary in question. The first entry in the log is the most recent, i.e. the one used to build that kernel. You will need it at a later step. Identifying kernel version
To determine the kernel version used in a particular system image, run the following command against the kernel file:
$ dd if=kernel bs=1 skip=$(LC_ALL=C grep -a -b -o $'\x1f\x8b\x08\x00\x00\x00\x00\x00' kernel | cut -d ':' -f 1) | zgrep -a 'Linux version'
For Nexus 5 (hammerhead), this can be accomplished with:
$ bzgrep -a 'Linux version' vmlinux.bz2
Downloading sources
Depending on which kernel you want,
$ git clone https://android.googlesource.com/kernel/common.git $ git clone https://android.googlesource.com/kernel/exynos.git $ git clone https://android.googlesource.com/kernel/goldfish.git $ git clone https://android.googlesource.com/kernel/msm.git $ git clone https://android.googlesource.com/kernel/omap.git $ git clone https://android.googlesource.com/kernel/samsung.git $ git clone https://android.googlesource.com/kernel/tegra.git
The goldfish project contains the kernel sources for the emulated platforms. The msm project has the sources for ADP1, ADP2, Nexus One, Nexus 4, and can be used as a starting point for work on Qualcomm MSM chipsets. The omap project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets. The samsung project is used for Nexus S, and can be used as a starting point for work on Samsung Hummingbird chipsets. The tegra project is for Xoom and Nexus 7, and can be used as a starting point for work on NVIDIA Tegra chipsets. The exynos project has the kernel sources for Nexus 10, and can be used as a starting point for work on Samsung Exynos chipsets.
Downloading a prebuilt gcc
Ensure that the prebuilt toolchain is in your path.
$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
or
$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH
On a linux host, if you don't have an Android source tree, you can download the prebuilt toolchain from:
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
Building
As an example, we would build the panda kernel using the following commands:
$ export ARCH=arm $ export SUBARCH=arm $ export CROSS_COMPILE=arm-eabi- $ cd omap $ git checkout <commit_from_first_step> $ make panda_defconfig $ make
To build the tuna kernel, you may run the previous commands replacing all instances of "panda" with "tuna".
The kernel binary is output as: `arch/arm/boot/zImage` It can be copied into the Android source tree in order to build the matching boot image.
Or you can include the TARGET_PREBUILT_KERNEL variable while using make bootimage or any other make command line that builds a boot image.
$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage
That variable is supported by all devices as it is set up via device/common/populate-new-device.sh
Hello everyone, want to compile an Android kernel on your own? Than why not begin doing it so by following the simple guide below?
1) Setup Environment:
First you will need these things,
A Linux PC (32 bit will work for compilation of kernel) Basic knowledge of using terminal in Unix based operating system Few packages for compilation Tool chains for compilation Kernel source code Patience :p
So now we begin, First of all open terminal in your Linux PC. I am using here Linux Mint 16, a Debian based Linux Distribution. You can use any Linux distro for it such as Ubuntu, fedora, Arch Linux, etc. procedure will be same just you need to use different commands with terminal as per your distro. Now type this code in your terminal:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git
1
This will install required packages for kernel compilation. Now last thing, we need tool chains for compiling kernel. You can get it from here: https://github.com/crossfire77/Android_Toolchains Download it and extract it somewhere. Then, We have to setup path of our tool chains, so type this in terminal:
gedit .bashrc
It will open one document, then put this codes at the end of it.
export PATH=${PATH}:path/to/toolchain/folder/arm-eabi-4.4.3/bin
2
Now we are done with downloading and setting up things. Let’s move to next step! 2) Download Source Code:
Kernel source codes are under GNU GPL open source license so vendors (ex. Sony, HTC, Samsung, LG) have to release it. You can find your appropriate kernel source code from mentioned websites:
For Sony: http://developer.sonymobile.com/
For Samsung: http://opensource.samsung.com/
For HTC: http://www.htcdev.com/
For LG: http://www.lg.com/global/support/opensource/index
Just download it from mentioned websites as per your device and extract it somewhere in your computer. 3) Getting Config file:
Now this is where you should put your focus. For building a kernel you need config file. There is two ways for it:
You can either get it from your phone with help of ADB (Android Debug Bridge) or You can get it from your kernel source code.
I will show you both the ways of doing it so.
1) Getting config file from your phone with the help of ADB:
First of all connect your phone to your computer. Then type the mentioned code below:
adb pull proc/config.gz ~/home/crossfire77/kernel
This will pull your existing config file from your phone and put it in kernel folder. Now extract it,
zcat config.gz > .config
So we have directly config for building our kernel.
NOTE: Many times users’ faces errors while connecting phone with computer via ADB, it’s mostly issue of a permission. There is two solutions for it.
1.) Using ADB as root user: $sudo -s $ adb kill-server $ adb start-server $ adb devices And you will see your device now in terminal, it is a temporary solution meaning you have to do every time you connect your phone.
2.) Solve permission problem permanently:
Open terminal and type this: $ sudo gedit /etc/udev/rules.d/51-android.rules and copy content from this file, http://goo.gl/bldQS9 In this file, please replace “crossfire77” with your username.
Now last thing to do is, giving executing permission to file, and we are good to go.
$ sudo chmod a+r /etc/udev/rules.d/51-android.rules $ sudo service udev restart
This will solve your problem with ADB and FASTBOOT while connecting through them your phone with computer.
2) Getting config file from kernel source code:
This part is little tricky. For this you have to have little knowledge about your device chipset number. In kernel source code there are lots of config files so from your chipset number you can find your config file. As example, My device is HTC Wildfire S and it has MSM7227 chipset so I can find its config in mentioned path: arch/arm/configs/msm7227_defconfig3
So now just type this code in terminal:
make ARCH=arm CROSS_COMPILE=arm-eabi- msm7227_defconfig
4
It will create .config file from your existing chipset config and then we are good to go. As I told you before you need to have little knowledge about your device chipset then you can able to tell what is your correct config file, so be careful while doing this step. Everything is done now so shall we start building?
4) Building:
Type this in your terminal,
make ARCH=arm CROSS_COMPILE=arm-eabi- -jX
5 It is main command for compilation and here X can be replaced by maximum numbers of jobs your computer can handle simultaneously. For ease just enter the twice number of your cores. Ex. If your computer has two cores enter four.
NOTE: Please do not enter high number or your computer will explode due to overheating.
It will take around ~15-1 hour as per your computer hardware specs.so keep sit down and keep patience. After completing this procedure we will have our zImage (kernel)! afafaLet’s create one working directory:
mkdir kernell
Now, we will copy our zImage to our working directory:
cp arch/arm/boot/zImage kernell
Next step, modules (modules builds with kernel and we need it for Wi-Fi and etc. as per your device requirement)
find . -name '*ko' -exec cp '{}' kernell \;
7 So we are done with the main part, now last step to make flash able zip out of this to flash our kernel.
5) Making Flashable Zip: We are done with compiling and building task and at the end we have our zImage (kernel) and modules. Screenshot from 2014-03-05 14:22:03 Now time to flash it to your phone, for it we have one very easy method, “any kernel updater” by koush. So download this file from here: http://goo.gl/mQpHhC ffafa
So, this was all about compiling an Android Kernel. Share me your any doubts or acknowledgements if you have.
Have fun compiling Android Kernel.