Compile our own Android Kernel in 5 Simple Steps
The Android kernel helps the applications to communicate with the hardware components of the device.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
- Most of us are familiar with game mode. What it does is instructs the processor and the graphics processing unit to run at their maximum frequencies.
- Another example is power saver mode. It instructs the processor and the graphics processing unit to run at their minimum frequencies.
Need to compile our own kernel: Compiling our own kernel might prove very useful as:
- The user experience can be further optimized as per the need using our own kernel
- It can also help in Open Source Development.
Steps to compile our own kernel:
- Prerequisites: Below are the prerequisites required to compile our own Android Kernel:
- Ubuntu or any other Linux based OS
- Familiar with basic Linux Commands
- Familiar with Github
- Device source code
Note: This article is for a device with a 64bit Snapdragon SOC
Install Dependencies Open the terminal and paste the following:
Источник
Clang сборка ядра android
Compiling an Android kernel with Clang
Google compiles the Pixel 2 kernel with Clang. They shipped the device on Android 8.0 with a kernel compiled with Clang 4.0 (build.config commit and prebuilt kernel commit) and upgraded to Android 8.1 with a kernel compiled with Clang 5.0 (build.config commit and prebuilt kernel commit).
Google uses Clang’s link-time optimization and control flow integrity in the Pixel 3 kernel, hardening it against return oriented programming attacks (LTO commit, CFI commit).
Google started compiling all Chromebook 4.4 kernels with Clang in R67 (commit, LKML) and going forward, Clang is the default compiler for all future versions of the kernel (commit).
Further information including videos of talks on the motive behind compiling with Clang can be found in the ClangBuiltLinux wiki.
TL;DR: Helps find bugs, easier for Google since all of AOSP is compiled with Clang, compiler specific features such as link-time optimization, and better static analysis for higher code quality.
- A compatible kernel (4.4 or 4.9 LTS work best)
- arm64 or x86_64
- Patience
msm-4.14 and newer uses clang by default so there is no need for a patch stack.
How to compile the kernel with Clang (standalone)
NOTE: I am not going to write this for beginnings. I assume if you are smart enough to pick some commits, you are smart enough to know how to run git clone and know the paths of your system.
/bin:$
After compiling, you can verify the toolchain used by opening out/include/generated/compile.h and looking at the LINUX_COMPILER option.
A couple of notes:
- CLANG_TRIPLE is only needed when using AOSP’s version of Clang.
- export CC=clang does not work. You need to pass CC=clang to make like above.
- CROSS_COMPILE_ARM32 is needed in recent kernels to support the new compat vDSO.
How to compile the kernel with Clang (inline with a custom ROM)
- Add the Clang commits to your kernel source
- Make sure your ROM has this commit
- Add the following to your BoardConfig.mk file in your device tree: TARGET_KERNEL_CLANG_COMPILE := true
To test and verify everything is working:
- Build a kernel image: m kernel or m bootimage
- Open the out/target/product/*/obj/KERNEL_OBJ/include/generated/compile.h file and look at the LINUX_COMPILER option.
Getting the Clang patchset
The core Clang patchset comes from mainline. It has been backported to three places:
If your kernel has 4.4.165 or 4.9.139 and newer, you automatically have the patchset and can start building with Clang!
The branches in this repository will be dedicated to adding this patchset when it does not exist and enhancing it by fixing all of the warnings from Clang (from mainline, the Pixel 2 and 3, msm-4.9/msm-4.14, and my own knowledge).
msm-3.18-android-10 — based on kernel.lnx.3.18.r41-rel. All relevant configs should build with -Werror .
msm-4.4-android-10 — based on kernel.lnx.4.4.r38-rel. All relevant configs should build with -Werror .
msm-4.9-oreo — based on the latest Oreo branch for the Snapdragon 845 kernel.lnx.4.9.r7-rel. Uses sdm845-perf_defconfig .
msm-4.9-pie — based on the latest Pie branch for the Snapdragon 845 kernel.lnx.4.9.r11-rel. Uses sdm845-perf_defconfig .
msm-4.9-android-10 — based on kernel.lnx.4.9.r25-rel. All relevant configs should build with -Werror .
The general structure of these commits is as follows:
- The core compilation support (if needed)
- Fixing Qualcomm specific drivers to compile with Clang
- Fixing warnings that come from code in mainline
- Fixing warnings that come from code outside of mainline
You should pick the commits that I have committed (nathanchance).
Additionally, there are fixes for:
Every time there is a branch update upstream, the branch will be rebased, there is no stable history here! Ideally, I will not need to add any commits but I will do my best to keep everything in the same order.
NOTE: 3.18 Clang is not supported officially by an OEM. I’ve merely added it here as I decided to support it with my Pixel XL kernel.
How to get a Clang toolchain
You can either use a prebuilt version of Clang (like from AOSP) or build a version yourself from the upstream sources.
For prebuilts, I recommend AOSP’s Clang, which is used for both the kernel and the platform so it is highly tested. You can git clone that repo to always have access to the latest version available, which is what I recommend. That is currently Clang 9.0.8. If you would like to just download the minimum version of Clang supported for the branches in this repo, direct tarball links are provided below:
If you would like to build the latest version of Clang, you can do so with tc-build . There are a lot of fixes for the Linux kernel that happen in LLVM/Clang so staying up to date is critical. If you experience any issues with Clang and an Android kernel, please report them to this repo.
How to get binutils
binutils are used for assembling (and usually linking) the Linux kernel right now. When using AOSP Clang, you should use AOSP’s GCC to avoid weird incompatibility issues. If you want source-built binutils, there is a build-binutils.py script available in tc-build .
The preferred method for getting help is either opening an issue on this repository or joining the Linux kernel newbies chat on Telegram.
Источник
Clang сборка ядра android
Инструкции по сборке Android из исходников
Мануалы в помощь новичку и обсуждение для гуру!
Описание | Старая шапка | Собираем ядро для MTK | Первая помощь | Редактирование системных ресурсов Android | Средство обработки прошивок
Что такое ADB и с чем его едят, читаем тут. Отследить новую версию ADB можно в репо от Google.
ADB для Winodws — Скачать sha1:52b4816990d2d18a34645bbf20a31b38a7859d4c
ADB для Linux — Скачать sha1:31078104e5927d823c28550c01275c437a87def7
ADB для MacOSx — Скачать sha1:1403fa0d1bb57ec31170d7905e8505e3b0ed05ee
Что такое маркет и с чем его едят, читайте в этой теме.
Android 4.1.*: microgapps скачать
Android 4.2.*: microgapps Скачать
Android 4.3.*: microgapps Скачать
Android 4.4 : ART microgapps Скачать
Android 4.4.1: ART microgapps Скачать
Android 4.4.2: ART microgapps Скачать
Android 5.0.2: ART microgapps Скачать
Android 5.0.2: ART microgapps Скачать By Mansi
Android 5.1.0: ART minigapps Скачать faq
microgapps — пакет Google Apps с самым основным, только Google Play и framework. Остальное можно установить из Google Play.
minigapps — Пакет Google Apps с самым основным набором ПО от Google.
ART — совместимы с ART режимом, появился в версиях Android 4.4 KitKat.
FlymeOS 5/6 от rocker123
Скачать Огромная коллекция на XDA 4.x-6.x
Скачать OmniRom + Prebuilts 4.x-6.x От ctavropoholb
Скачать Qualcomm MSM8974 и MSM8939 От acdev
Скачать MIUI PatchRom miui5-7 От ctavropoholb
Скачать CyanogenMod 10.1 — 13 4.х.х-6.х.х От ctavropoholb
Скачать CyanogenMod 12.1 android-5.1.1_r18 От SteelBreaker
Скачать Prebuilts AOSP 5.0.x От assusdan
Скачать MIUI PatchRom KitKat v6 От vgdn1942
Скачать AOSP mirror repo От wladimir_tm
Скачать AOSP, AOKP, CM, MIUI 4.4.4 От vaibhavpandeyvpz
Скачать CyanogenMod 11 4.4.4 От Никита Pro Android
Скачать CyanogenMod 10 4.1 От Scorpio92666
Скачать CyanogenMod 7.2.0 2.3.x От pryanya96
Скачать AOSPA ParanoidAndroid 4.4.4 От mrAlmid
Скачать Ubuntu phablet 4.4.2_r1 От Каточимото
Скачать repo snapshots cm-10.2 — android5.1 От wladimir_tm
После чего, качаем исходники командой repo sync
Источник
Clang сборка ядра android
Инструкции по сборке Android из исходников
Мануалы в помощь новичку и обсуждение для гуру!
Описание | Старая шапка | Собираем ядро для MTK | Первая помощь | Редактирование системных ресурсов Android | Средство обработки прошивок
Что такое ADB и с чем его едят, читаем тут. Отследить новую версию ADB можно в репо от Google.
ADB для Winodws — Скачать sha1:52b4816990d2d18a34645bbf20a31b38a7859d4c
ADB для Linux — Скачать sha1:31078104e5927d823c28550c01275c437a87def7
ADB для MacOSx — Скачать sha1:1403fa0d1bb57ec31170d7905e8505e3b0ed05ee
Что такое маркет и с чем его едят, читайте в этой теме.
Android 4.1.*: microgapps скачать
Android 4.2.*: microgapps Скачать
Android 4.3.*: microgapps Скачать
Android 4.4 : ART microgapps Скачать
Android 4.4.1: ART microgapps Скачать
Android 4.4.2: ART microgapps Скачать
Android 5.0.2: ART microgapps Скачать
Android 5.0.2: ART microgapps Скачать By Mansi
Android 5.1.0: ART minigapps Скачать faq
microgapps — пакет Google Apps с самым основным, только Google Play и framework. Остальное можно установить из Google Play.
minigapps — Пакет Google Apps с самым основным набором ПО от Google.
ART — совместимы с ART режимом, появился в версиях Android 4.4 KitKat.
FlymeOS 5/6 от rocker123
Скачать Огромная коллекция на XDA 4.x-6.x
Скачать OmniRom + Prebuilts 4.x-6.x От ctavropoholb
Скачать Qualcomm MSM8974 и MSM8939 От acdev
Скачать MIUI PatchRom miui5-7 От ctavropoholb
Скачать CyanogenMod 10.1 — 13 4.х.х-6.х.х От ctavropoholb
Скачать CyanogenMod 12.1 android-5.1.1_r18 От SteelBreaker
Скачать Prebuilts AOSP 5.0.x От assusdan
Скачать MIUI PatchRom KitKat v6 От vgdn1942
Скачать AOSP mirror repo От wladimir_tm
Скачать AOSP, AOKP, CM, MIUI 4.4.4 От vaibhavpandeyvpz
Скачать CyanogenMod 11 4.4.4 От Никита Pro Android
Скачать CyanogenMod 10 4.1 От Scorpio92666
Скачать CyanogenMod 7.2.0 2.3.x От pryanya96
Скачать AOSPA ParanoidAndroid 4.4.4 От mrAlmid
Скачать Ubuntu phablet 4.4.2_r1 От Каточимото
Скачать repo snapshots cm-10.2 — android5.1 От wladimir_tm
После чего, качаем исходники командой repo sync
Источник
Clang сборка ядра android
Compiling an Android kernel with Clang
Google compiles the Pixel 2 kernel with Clang. They shipped the device on Android 8.0 with a kernel compiled with Clang 4.0 (build.config commit and prebuilt kernel commit) and upgraded to Android 8.1 with a kernel compiled with Clang 5.0 (build.config commit and prebuilt kernel commit).
Google uses Clang’s link-time optimization and control flow integrity in the Pixel 3 kernel, hardening it against return oriented programming attacks (LTO commit, CFI commit).
Google started compiling all Chromebook 4.4 kernels with Clang in R67 (commit, LKML) and going forward, Clang is the default compiler for all future versions of the kernel (commit).
Further information including videos of talks on the motive behind compiling with Clang can be found in the ClangBuiltLinux wiki.
TL;DR: Helps find bugs, easier for Google since all of AOSP is compiled with Clang, compiler specific features such as link-time optimization, and better static analysis for higher code quality.
- A compatible kernel (4.4 or 4.9 LTS work best)
- arm64 or x86_64
- Patience
msm-4.14 and newer uses clang by default so there is no need for a patch stack.
How to compile the kernel with Clang (standalone)
NOTE: I am not going to write this for beginnings. I assume if you are smart enough to pick some commits, you are smart enough to know how to run git clone and know the paths of your system.
/bin:$
After compiling, you can verify the toolchain used by opening out/include/generated/compile.h and looking at the LINUX_COMPILER option.
A couple of notes:
- CLANG_TRIPLE is only needed when using AOSP’s version of Clang.
- export CC=clang does not work. You need to pass CC=clang to make like above.
- CROSS_COMPILE_ARM32 is needed in recent kernels to support the new compat vDSO.
How to compile the kernel with Clang (inline with a custom ROM)
- Add the Clang commits to your kernel source
- Make sure your ROM has this commit
- Add the following to your BoardConfig.mk file in your device tree: TARGET_KERNEL_CLANG_COMPILE := true
To test and verify everything is working:
- Build a kernel image: m kernel or m bootimage
- Open the out/target/product/*/obj/KERNEL_OBJ/include/generated/compile.h file and look at the LINUX_COMPILER option.
Getting the Clang patchset
The core Clang patchset comes from mainline. It has been backported to three places:
If your kernel has 4.4.165 or 4.9.139 and newer, you automatically have the patchset and can start building with Clang!
The branches in this repository will be dedicated to adding this patchset when it does not exist and enhancing it by fixing all of the warnings from Clang (from mainline, the Pixel 2 and 3, msm-4.9/msm-4.14, and my own knowledge).
msm-3.18-android-10 — based on kernel.lnx.3.18.r41-rel. All relevant configs should build with -Werror .
msm-4.4-android-10 — based on kernel.lnx.4.4.r38-rel. All relevant configs should build with -Werror .
msm-4.9-oreo — based on the latest Oreo branch for the Snapdragon 845 kernel.lnx.4.9.r7-rel. Uses sdm845-perf_defconfig .
msm-4.9-pie — based on the latest Pie branch for the Snapdragon 845 kernel.lnx.4.9.r11-rel. Uses sdm845-perf_defconfig .
msm-4.9-android-10 — based on kernel.lnx.4.9.r25-rel. All relevant configs should build with -Werror .
The general structure of these commits is as follows:
- The core compilation support (if needed)
- Fixing Qualcomm specific drivers to compile with Clang
- Fixing warnings that come from code in mainline
- Fixing warnings that come from code outside of mainline
You should pick the commits that I have committed (nathanchance).
Additionally, there are fixes for:
Every time there is a branch update upstream, the branch will be rebased, there is no stable history here! Ideally, I will not need to add any commits but I will do my best to keep everything in the same order.
NOTE: 3.18 Clang is not supported officially by an OEM. I’ve merely added it here as I decided to support it with my Pixel XL kernel.
How to get a Clang toolchain
You can either use a prebuilt version of Clang (like from AOSP) or build a version yourself from the upstream sources.
For prebuilts, I recommend AOSP’s Clang, which is used for both the kernel and the platform so it is highly tested. You can git clone that repo to always have access to the latest version available, which is what I recommend. That is currently Clang 9.0.8. If you would like to just download the minimum version of Clang supported for the branches in this repo, direct tarball links are provided below:
If you would like to build the latest version of Clang, you can do so with tc-build . There are a lot of fixes for the Linux kernel that happen in LLVM/Clang so staying up to date is critical. If you experience any issues with Clang and an Android kernel, please report them to this repo.
How to get binutils
binutils are used for assembling (and usually linking) the Linux kernel right now. When using AOSP Clang, you should use AOSP’s GCC to avoid weird incompatibility issues. If you want source-built binutils, there is a build-binutils.py script available in tc-build .
The preferred method for getting help is either opening an issue on this repository or joining the Linux kernel newbies chat on Telegram.
About
Information on compiling Android kernels with Clang
Источник