Difference between revisions of "ROM Android: Compile Kernel untuk ROM Android"
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 181: | Line 181: | ||
* Memperoleh dari kernel source code. | * Memperoleh dari kernel source code. | ||
− | + | Caranya adalah sebagai berikut: | |
− | + | ===Memperoleh .config melalui adb=== | |
− | + | * sambungkan komputer ke telepon | |
− | + | * tulis | |
− | adb pull proc/config.gz | + | cd ~/tempat-file-data-android-anda |
+ | adb pull proc/config.gz | ||
− | + | * extract menggunakan perintah | |
zcat config.gz > .config | zcat config.gz > .config | ||
− | + | Ya, kita memperoleh .config yang dibutuhkan untuk membuat kernel dari android kita. | |
+ | |||
+ | |||
+ | |||
+ | |||
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. | 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. | ||
Line 351: | Line 356: | ||
make -j# ARCH=arm | make -j# ARCH=arm | ||
+ | |||
Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type | Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type | ||
Code: | Code: | ||
Line 369: | Line 375: | ||
Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko | Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko | ||
− | You are ready all you need to do is flash it. | + | You are ready all you need to do is flash it. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Mengapa CM menginginkan kernel built bersama dengan Android?== | ==Mengapa CM menginginkan kernel built bersama dengan Android?== | ||
Line 442: | Line 438: | ||
=====Re-build===== | =====Re-build===== | ||
− | + | Untuk membuat ulang kernel sesudah kita melakukan beberapa perubah di file source atau file config, cukup menjalankan kembali | |
+ | |||
+ | <code>mka bootimage</code> | ||
+ | |||
+ | Proses build akan jauh lebih cepat karena caching, dan hanya build pada file yang dimodifikasi saja. Hati-hati akan error pada proses build ulang, seluruh proses build akan menggunakan object / module yang sebelumnya sudah di built jika beberapa object gagal di built, ini akan menyebabkan inkonsistensi. Jika kita ragu, jalankan | ||
+ | |||
+ | <code>mka clean</code>. | ||
+ | |||
+ | Perlu di catat bahwa kita tidak dapat menggunakan perintah <code>mm</code> untuk kernel modul. Karena perintah ini dibuat untuk modul yang menggunakan file Android.mk dan bukan file standard Makefile, seperti system modul (bukan kernel modul). | ||
+ | |||
+ | Tip '''keluar dari bootloop:''' Jika device kita stuck di bootloop sesudah di flash, flash lagi device tersebut dengan kernel yang jalan (atau dengan full ROM / nandroid backup). | ||
+ | |||
+ | Jika di directory building, kita dapat menemukan kernel zImage di ''$OUT/obj/KERNEL_OBJ/arch/arm/boot''. File ini dapat di flash ke device yang mendukungnya dengan menggunakan http://glassechidna.com.au/heimdall/ Heimdall untuk device Samsung atau menggunakan fastboot untuk device yang mendukung fastboot. | ||
− | + | Perlu di catat bahwa, | |
− | + | <code>mka bootimage</code> | |
− | + | tidak membuat file zip ClockWordMod atau TWRP yang dapat di flash, kita harus membuat file tersebut jika kita tidak dapat menggunakan zImage secara langsung. | |
− | + | ====HINDARI: Building hanya kernel dari kernel source==== | |
− | + | Sejak CyanogenMod 9, kita tidak lagi menggunakan prebuilt kernel image. System build sudah di modifikasi untuk meminta untuk membuat kernel source. | |
− | |||
− | + | Membuat kernel dari system build CyanogenMod akan menjamin bahwa kita akan menggunakan dengan benar Android toolchain. Cara ini juga akan memberikan garansi kompatibilitas antara kernel dan userspace (system calls, seperti ioctl, harus konsisten antara kernel dengan userspace). | |
− | + | Selanjutnya, Makefile kernel biasanya tidak melakukan hal seperti membuat device-specific ramdisk, embedding kernel image (zImage) dan ramdisk ke boot.img (yang strukturnya kadang kala spesifik device tertentu) dan mem-push berbagai hal, termasuk loadable kernel module, ke device. Dengan membuat CM sepenuhnya dari source, tool CM build akan meng-automasi semua langkah tersebut. | |
====TO AVOID: Building only a kernel module and importing it on a different kernel version==== | ====TO AVOID: Building only a kernel module and importing it on a different kernel version==== | ||
Line 572: | Line 579: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | As alluded to above, all I really wanted to do was tweak the kernel config to enable CONFIG_FTRACE. The way I did that was to enter the directory the kernel source is in: ~/android/system/kernel/samsung/smdk4412, then copied the default config for my phone (arch/arm/configs/cyanogenmod_t0lte_defconfig) to .config. After that I could run make menuconfig as normal. For ease of examination I forked the kernel repo and stored the distinct changes I made to the config here. | ||
+ | |||
+ | After making tweaks with make menuconfig, I copied .config back to arch/arm/configs/cyanogenmod_t0lte_defconfig. To build the boot image I ran the following set of commands (which I put in a bash script:) | ||
+ | |||
+ | #!/bin/bash | ||
+ | |||
+ | set -e | ||
+ | |||
+ | cd ~/android/system | ||
+ | make clean | ||
+ | cd kernel/samsung/smdk4412 | ||
+ | make mrproper | ||
+ | cd ~/android/system | ||
+ | make -j8 bootimage | ||
+ | |||
+ | Note that I do not use mka. Some of the android build manuals recommend mka, but I found it was much less reliable than regular make, so I abandoned it. | ||
Line 580: | Line 607: | ||
* http://forum.xda-developers.com/showthread.php?t=2152819 | * http://forum.xda-developers.com/showthread.php?t=2152819 | ||
* http://wiki.cyanogenmod.org/w/Doc:_integrated_kernel_building | * http://wiki.cyanogenmod.org/w/Doc:_integrated_kernel_building | ||
+ | * https://blog.afoolishmanifesto.com/posts/replacing-your-cyanogenmod-kernel-for-fun-and-profit/ |
Latest revision as of 14:57, 1 January 2015
Building Kernels In this document
Figuring out which kernel to build Identifying kernel version Downloading sources Downloading a prebuilt gcc Building
Jika anda hanya tertarik pada kernel, anda dapat menggunakan panduan ini untuk membuat 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?
Lingkungan yang dibutuhkan
Kita akan membutuhkan,
- Sebuah PC Linux (32 bit dapat digunakan untuk compile kernel).
- Pengetahuan tentang penggunaan terminal di Sistem Operasi Unix
- Compile beberapa paket.
- Compile Tool chain untuk melakukan cross compile.
- Source code kernel.
- Kesabaran:)
Mari kita mulai, pertama kali buka terminal di PC Linux anda. Anda dapat menggunakan Ubuntu / Mint / Fedora / Arch Linux dll. prosedur akan kira-kira mirip satu sama lain. Untuk distribusi yang berbasis debian, seperti Ubuntu / Mint, dapat mengetik:
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
Ini akan menginstalasi berbagai paket yang dibutuhkan untuk compile kernel. Selanjutnya, kita membutuhkan tool chain untuk compile kernel. Kita dapat memperolehnya dari
https://github.com/crossfire77/Android_Toolchains https://github.com/crossfire77/Android_Toolchains/archive/master.zip
Download dan extrak di salah satu folder. Selanjutnya, kita dapat mensetup path dari tool chain dengan cara mengedit
gedit .bashrc
Tambahkan di bagian bawah
export PATH=${PATH}:path/to/toolchain/folder/arm-eabi-4.4.3/bin
Selesai sudah dengan pekerjaan download dan setup. Lanjut ke langkah selanjutnya.
Download Source Code
Source code kernel menggunakan lisensi open source GNU GPL, oleh karenanya vendor (seperti Sony, HTC, Samsung, LG) harus melepas source cidenya. Kita dapat memperoleh kernel source code dari situs:
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
Download dari situs tersebut untuk device yang kita miliki dan ekstrak ke folder di komputer kita.
Memperoleh file config
Bagian ini adalah bagian yang paling penting dimana kita perlu memfokuskan diri. Untuk membuat kernel kita memerlukan file config. Ada beberapa cara untuk mendapatkannya:
- Memperoleh langsung dari handphone kita dengan pertolongan ADB (Android Debug Bridge)
- Memperoleh dari kernel source code.
Caranya adalah sebagai berikut:
Memperoleh .config melalui adb
- sambungkan komputer ke telepon
- tulis
cd ~/tempat-file-data-android-anda adb pull proc/config.gz
- extract menggunakan perintah
zcat config.gz > .config
Ya, kita memperoleh .config yang dibutuhkan untuk membuat kernel dari android kita.
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.
This is the quickest and easiest way to build your own Kernel using the Android NDK
Note:I will be reffering to the following Quote:
yourusername=the username that you are logged in to devicecode=The codename for the device you are building a kernel for(Google it on what is the code name Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.
What you will need Quote:
Ubuntu 12.04 or newer A lot of patience Step 1:Installing the required files
Open a terminal and type the following (copy-paste) Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
This will install the packages you need
Download the kernel source code for your device (This is important. We are going to build the kernel from this) Quote:
For HTC http://htcdev.com For Samsung http://opensource.samsung.com/ Find your device and click Download
Download The NDK
Move the NDK and your device Kernel source code in your home folder Extract both the NDK and your kernel source code Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel
Now we are ready to build.
Step 2:Tweaking the kernel
Navigate to the kernel folder Code:
cd /home/yourusername/Kernel
Next we need to point the NDK tools to the kernel folder Code:
export CROSS_COMPILE=/home/yourusername/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
We've pointed the NDK tolls and now we can use the NDK to tweak the kernel
Next we need to clean the previous work just incase: Code:
make clean && make mrproper
If everything goes well you are good to go. If you have an Error(s) then something is wrong.
Now we are ready. Next we need to add the kernel features to the NDK so we can modife them Firs open your kernel source code folder go to arch/arm/configs Here you will all the configs. We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig Rename it to maker.defconfig Now type this in your terminal Code:
make maker.defconfig
Now we need to tweak those configs. Code:
make menuconfig
A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space) When you are ready close the UI and click SAVE
Step 3 Building So we tweaked the Kernel and we are ready to build. Quote:
make -j# ARCH=arm
Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type Code:
make -j5 ARCH=arm
This will build the Kernel. It will take about 10 minutes.
Step 4: Finalizing Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it) Download the zip file and leave it in your home folder.
Now got to your kernel source and go to arch/arm/boot and copy zImage Paste your Zimage to the zip file and replace it.
Now we need the WI-FI modules otherwise your WI-FI will not be working Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko
You are ready all you need to do is flash it.
Mengapa CM menginginkan kernel built bersama dengan Android?
Sebelum CM9, CM tergantung pada prebuilt kernel di setiap repository device. Ini di compile terpisah dari framework dan membutuhkan device maintainer untuk secara manual mengupdate image dan module kernel setiap kali terjadi perubahan. Masalah lainnya, kernel tidak menggunakan scheme konvensi nama yang konsistan, dan kebanyakan tidak di manage oleh CyanogenMod Gerrit, dan sering kali menggunakan compiler yang lain dari yang ada di Android toolchain. Ini menyebabkan ketidak konsisten-an, dan kesulitan bagi maintainer. [More info here]
Catatan: Cek The CyanogenMod Learning Center untuk belajar lebih dalam tentang cara membuat CyanogenMod, terutama Envsetup help dan daftar dari perintah build.
Bagaimana cara (mengedit dan) build sebuah official kernel?
Pilihan A: Build full ROM (Kernel + Android) dari full CyanogenMod source
Ikuti CM Build Guides untuk device kita.
Kernel source akan secara automatis di download jika device kita di dukung oleh CyanogenMod. ROM akan di built untuk file zip yang dapat di flash menggunakan ClockworkMod Recovery.
Catatan: full CM Android dan Kernel source akan di download (beberapa GB) dan dengan build file kita akan membutuhkan sekitar ~40-50GB (untuk CM11.0, tergantung dari kernel kita) dan disk space yang ada.
Pilihan B: Build hanya Kernel dari full CyanogenMod source
Ikuti panduan CM Build Guides untuk device kita dengan perbedaan sedikit yang akan di jelaskan di bawah ini. Kernel device kita akan di download saat dijalankan perintah breakfast
atau lunch
seperti yang di jelaskan di panduan build. Perhatikan bahwa full CM Android dan Kernel source akan di download (beberapa GB) dan dengan build file-nya kita akan membutuhkan sekitar ~20GB (untuk CM11.0, tergantung dari kernel)
Ikuti panduan build dari device kita, tidak menggunakan:
$ brunch
jalankan (juga dari directory root CM Android (croot
), bukan dari directory kernel):
$ mka bootimage
Ini akan mengompile kernel source ke boot.img. Oleh karenanya kita akan menghemat banyak waktu compile.
File boot.img dapat di flash dengan fastboot atau secara langsung menggunakan command line. Catatan untuk menjamin compatibilitas kernal - ROM, telepon kita harus menjalakan ROM yang berbasis sama dengan versi kernel yang di flash, atau dia tidak akan jalan.
$ adb root
$ adb remount
$ installboot
$ adb reboot
Catatan: Jika device kita mendukung fastboot (Samsung tidak mendukung), kita dapat men-test kernel tanpa perlu memflash-nya:
$ adb reboot bootloader
$ fastboot boot "$OUT/boot.img"
Ubah konfigurasi kernel
File konfigurasi kernel yang digunakan saat proses build biasanya di acu di TARGET_KERNEL_CONFIG
variabel di device/vendor-name/device-name/BoardConfig.mk. Biasanya menunjuk pada kernel/vendor-name/kernel-name/arch/arm/configs/cyanogenmod_device-name_deconfig.
Untuk membuat file konfigurasi kernel yang custom, kita dapat menggunakan tool untuk build konfigurasi di directory kernel, misalnya,
make menuconfig
dan simpan hasilnya di file hidden .config di lokasi yang ditunjukan oleh TARGET_KERNEL_CONFIG
. Kemudian jalankan make mrproper
dari directory kernel dan kembali ke directory root CM android source (croot
) sebelum melakukan building.
Re-build
Untuk membuat ulang kernel sesudah kita melakukan beberapa perubah di file source atau file config, cukup menjalankan kembali
mka bootimage
Proses build akan jauh lebih cepat karena caching, dan hanya build pada file yang dimodifikasi saja. Hati-hati akan error pada proses build ulang, seluruh proses build akan menggunakan object / module yang sebelumnya sudah di built jika beberapa object gagal di built, ini akan menyebabkan inkonsistensi. Jika kita ragu, jalankan
mka clean
.
Perlu di catat bahwa kita tidak dapat menggunakan perintah mm
untuk kernel modul. Karena perintah ini dibuat untuk modul yang menggunakan file Android.mk dan bukan file standard Makefile, seperti system modul (bukan kernel modul).
Tip keluar dari bootloop: Jika device kita stuck di bootloop sesudah di flash, flash lagi device tersebut dengan kernel yang jalan (atau dengan full ROM / nandroid backup).
Jika di directory building, kita dapat menemukan kernel zImage di $OUT/obj/KERNEL_OBJ/arch/arm/boot. File ini dapat di flash ke device yang mendukungnya dengan menggunakan http://glassechidna.com.au/heimdall/ Heimdall untuk device Samsung atau menggunakan fastboot untuk device yang mendukung fastboot.
Perlu di catat bahwa,
mka bootimage
tidak membuat file zip ClockWordMod atau TWRP yang dapat di flash, kita harus membuat file tersebut jika kita tidak dapat menggunakan zImage secara langsung.
HINDARI: Building hanya kernel dari kernel source
Sejak CyanogenMod 9, kita tidak lagi menggunakan prebuilt kernel image. System build sudah di modifikasi untuk meminta untuk membuat kernel source.
Membuat kernel dari system build CyanogenMod akan menjamin bahwa kita akan menggunakan dengan benar Android toolchain. Cara ini juga akan memberikan garansi kompatibilitas antara kernel dan userspace (system calls, seperti ioctl, harus konsisten antara kernel dengan userspace).
Selanjutnya, Makefile kernel biasanya tidak melakukan hal seperti membuat device-specific ramdisk, embedding kernel image (zImage) dan ramdisk ke boot.img (yang strukturnya kadang kala spesifik device tertentu) dan mem-push berbagai hal, termasuk loadable kernel module, ke device. Dengan membuat CM sepenuhnya dari source, tool CM build akan meng-automasi semua langkah tersebut.
TO AVOID: Building only a kernel module and importing it on a different kernel version
Kernel modules (e.g. a Wi-Fi driver) are built for a specific kernel version. Indeed, the kernel module (.ko file) embed the version of the kernel it is built for (check modinfo module-name.ko
). The module will not load if its version is different than the running kernel version (check uname -a
from the device terminal prompt). One reason behind this version interdependency is that internal interfaces within the kernel (the interfaces used in your module to access other kernel resources/modules) can and do change between versions. [source: LKMPG]
Therefore you should build and flash a full kernel if you need to change a module.
Otherwise, and if you make no kernel configuration change, you can build a kernel module from the same exact kernel source version (i.e. Github commit) that you're planning to import the module into. If you've not built the kernel yourself, this becomes highly complicated and deprecated: you may need to rebase your CM repository to the exact Github commit that your kernel was built from, extract and use the .config from your device, and eventually trick the source files that take care of defining the magic version of the built kernel module.
How to reference a custom kernel for building?
This chapter is intended for people that want to use a totally different kernel than the officially supported ones.
If you only need to modify an officially supported firmware, go back to the previous chapter and play with the kernel files in kernel/vendor-name/kernel-name (the official kernel files for your device will be downloaded after running the breakfast
or lunch
commands as described in the Build Guides).
Step 0. Preparing the build environment
Depending on whether your device is supported or not, follow the Build Guides or Porting Guide to prepare the Build Environment and get CM Android source code, prebuilt apps, device-specific code and proprietary blobs.
Step 1. Deploying the kernel source at the proper location
The minimal requirement is that the kernel's source tree for that device be present at kernel/vendor-name/device-name of the CM Android source.
- Officially supported devices:
- For devices which are part of mainline CyanogenMod and have their kernels in CM's github, this can be accomplished by usage of CyanogenMod's roomservice feature. Create a device/vendor-name/device-name/cm.dependencies file (if it doesn't exist yet), with the following syntax. This will take care of downloading the source automatically into the right location.
[ { "repository": "name-of-repository-in-the-CyanogenMod-github", "target_path": "kernel/vendor-name/device-name", "branch": "name-of-branch" } ]
- Work-in-progress, unofficial, or otherwise non-integrated devices:
- For devices which don't have their kernel source at the CM github, usage of local_manifest.xml is recommended in order to deploy the source at the right location, and keeping it synchronized.
- Devices using shared kernel repositories:
- If your device shares a kernel with others, the default kernel/vendor-name/device-name path will lead to unnecessary duplication of source trees, so usage of the TARGET_KERNEL_SOURCE configuration variable in device/vendor-name/device-name/BoardConfig.mk is advised. All devices sharing that source should have the following line in their BoardConfig.mk files:
TARGET_KERNEL_SOURCE := kernel/vendor-name/unique-shared-source-name
Step 2. Configuring the device to build the kernel
After the source is in place, configuration of the device to build the kernel is trivial. Just add the TARGET_KERNEL_CONFIG variable to your device/vendor-name/device-name/BoardConfig.mk file, pointing to the configuration file name for your device (as present in kernal/vendor-name/kernel-name/arch/arm/configs). For example:
TARGET_KERNEL_CONFIG := cyanogenmod_device-name_defconfig
This will trigger the full kernel build, including the modules (if present) as specified in that configuration. Any modules built will be deployed at /system/lib/modules/ in the final image
If your device requires uImage, also ensure the following is present in your 'BoardConfig.mk'
BOARD_USES_UBOOT := true
Step 3. Configuring the build of out-of-tree kernel modules
If your device needs modules that aren't part of the kernel source tree, those can also be built automatically. Some hardware (Texas Instruments' TIWLAN adapters, Broadcom's BCM adapters) is directly supported by CM repositories, but if that isn't your case we suggest you add your module's source to either your device repository, or an isolated path in your kernel source.
To build these modules, the TARGET_KERNEL_MODULES variable can be used, pointing to a make target that will build and install such modules. Definition of such a target is the device author's responsibility, the only restriction is that it is a normal makefile recipe. To include, for example, the TI WLAN modules, this can be used:
TIWLAN_MODULES: make -C hardware/ti/wlan/wl1283/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 RANDOM_MAC=n REPORT_LOG=n mv hardware/ti/wlan/wl1283/platforms/os/linux/tiwlan_drv.ko $(KERNEL_MODULES_OUT) make -C hardware/ti/wlan/wl1283_softAP/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 REPORT_LOG=n mv hardware/ti/wlan/wl1283_softAP/platforms/os/linux/tiap_drv.ko $(KERNEL_MODULES_OUT) TARGET_KERNEL_MODULES := TIWLAN_MODULES
As a rule of thumb, you can just paste your current standalone build commands into a make recipe, replacing the kernel source path with the $(KERNEL_OUT) variable.
Step 4. Configuring the fallback to prebuilts
If for some reason the kernel source can't be present, you can still fall back to prebuilt binaries, by defining the TARGET_PREBUILT_KERNEL variable, like this:
TARGET_PREBUILT_KERNEL := device/vendor-name/device-name/kernel
Step 5. Building the kernel or full ROM
Now that your custom kernel is linked to your device, you can build the device kernel or the device full ROM as you would do with an official kernel, as described in the first part of this page.
Full configuration example
The following is the p920's configuration (device/vendor-name/device-name/BoardConfig.mk), which attempts to build the kernel, uses external modules, and has a prebuilt fallback:
# Try to build the kernel TARGET_KERNEL_CONFIG := cyanogenmod_cosmo_defconfig # Keep this as a fallback TARGET_PREBUILT_KERNEL := device/lge/p920/kernel KERNEL_EXTERNAL_MODULES: make -C hardware/ti/wlan/wl1283/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 RANDOM_MAC=n REPORT_LOG=n mv hardware/ti/wlan/wl1283/platforms/os/linux/tiwlan_drv.ko $(KERNEL_MODULES_OUT) make -C hardware/ti/wlan/wl1283_softAP/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 REPORT_LOG=n mv hardware/ti/wlan/wl1283_softAP/platforms/os/linux/tiap_drv.ko $(KERNEL_MODULES_OUT) TARGET_KERNEL_MODULES := KERNEL_EXTERNAL_MODULES
As alluded to above, all I really wanted to do was tweak the kernel config to enable CONFIG_FTRACE. The way I did that was to enter the directory the kernel source is in: ~/android/system/kernel/samsung/smdk4412, then copied the default config for my phone (arch/arm/configs/cyanogenmod_t0lte_defconfig) to .config. After that I could run make menuconfig as normal. For ease of examination I forked the kernel repo and stored the distinct changes I made to the config here.
After making tweaks with make menuconfig, I copied .config back to arch/arm/configs/cyanogenmod_t0lte_defconfig. To build the boot image I ran the following set of commands (which I put in a bash script:)
- !/bin/bash
set -e
cd ~/android/system make clean cd kernel/samsung/smdk4412 make mrproper cd ~/android/system make -j8 bootimage
Note that I do not use mka. Some of the android build manuals recommend mka, but I found it was much less reliable than regular make, so I abandoned it.
Referensi
- https://source.android.com/source/building-kernels.html
- http://www.movzio.com/howto/compile-android-kernel-source-beginners-guide-2/
- http://forum.xda-developers.com/showthread.php?t=2152819
- http://wiki.cyanogenmod.org/w/Doc:_integrated_kernel_building
- https://blog.afoolishmanifesto.com/posts/replacing-your-cyanogenmod-kernel-for-fun-and-profit/