What is android kernel source code

How do I submit patches to Android Common Kernels

BEST: Make all of your changes to upstream Linux. If appropriate, backport to the stable releases. These patches will be merged automatically in the corresponding common kernels. If the patch is already in upstream Linux, post a backport of the patch that conforms to the patch requirements below.

  • Do not send patches upstream that contain only symbol exports. To be considered for upstream Linux, additions of EXPORT_SYMBOL_GPL() require an in-tree modular driver that uses the symbol — so include the new driver or changes to an existing driver in the same patchset as the export.
  • When sending patches upstream, the commit message must contain a clear case for why the patch is needed and beneficial to the community. Enabling out-of-tree drivers or functionality is not not a persuasive case.

LESS GOOD: Develop your patches out-of-tree (from an upstream Linux point-of-view). Unless these are fixing an Android-specific bug, these are very unlikely to be accepted unless they have been coordinated with kernel-team@android.com. If you want to proceed, post a patch that conforms to the patch requirements below.

Common Kernel patch requirements

  • All patches must conform to the Linux kernel coding standards and pass scripts/checkpatch.pl
  • Patches shall not break gki_defconfig or allmodconfig builds for arm, arm64, x86, x86_64 architectures (see https://source.android.com/setup/build/building-kernels)
  • If the patch is not merged from an upstream branch, the subject must be tagged with the type of patch: UPSTREAM: , BACKPORT: , FROMGIT: , FROMLIST: , or ANDROID: .
  • All patches must have a Change-Id: tag (see https://gerrit-review.googlesource.com/Documentation/user-changeid.html)
  • If an Android bug has been assigned, there must be a Bug: tag.
  • All patches must have a Signed-off-by: tag by the author and the submitter

Additional requirements are listed below based on patch type

Requirements for backports from mainline Linux: UPSTREAM: , BACKPORT:

  • If the patch is a cherry-pick from Linux mainline with no changes at all
    • tag the patch subject with UPSTREAM: .
    • add upstream commit information with a (cherry picked from commit . ) line
    • Example:
      • if the upstream commit message is
  • then Joe Smith would upload the patch for the common kernel as
  • If the patch requires any changes from the upstream version, tag the patch with BACKPORT: instead of UPSTREAM: .
    • use the same tags as UPSTREAM:
    • add comments about the changes under the (cherry picked from commit . ) line
    • Example:

Requirements for other backports: FROMGIT: , FROMLIST: ,

  • If the patch has been merged into an upstream maintainer tree, but has not yet been merged into Linux mainline
    • tag the patch subject with FROMGIT:
    • add info on where the patch came from as (cherry picked from commit
      ) . This must be a stable maintainer branch (not rebased, so don’t use linux-next for example).
    • if changes were required, use BACKPORT: FROMGIT:
    • Example:
      • if the commit message in the maintainer tree is
  • then Joe Smith would upload the patch for the common kernel as

Источник

What is android kernel source code

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.

Читайте также:  Steins gate android rus

/bin:$» \ make -j$(nproc —all) O=out \ ARCH=arm64 \ CC=clang \ CLANG_TRIPLE=aarch64-linux-gnu- \ CROSS_COMPILE=aarch64-linux-android- \ CROSS_COMPILE_ARM32=arm-linux-androideabi- «>

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:

  1. CLANG_TRIPLE is only needed when using AOSP’s version of Clang.
  2. export CC=clang does not work. You need to pass CC=clang to make like above.
  3. 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)

  1. Add the Clang commits to your kernel source
  2. Make sure your ROM has this commit
  3. Add the following to your BoardConfig.mk file in your device tree: TARGET_KERNEL_CLANG_COMPILE := true

To test and verify everything is working:

  1. Build a kernel image: m kernel or m bootimage
  2. 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:

  1. The core compilation support (if needed)
  2. Fixing Qualcomm specific drivers to compile with Clang
  3. Fixing warnings that come from code in mainline
  4. 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

Источник

[Guide][Noobs Familiar]How To Build Android Kernel With Features!

Albe96

Senior Member

What Is Kernel?
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.[1] It is the first program loaded on start-up. It handles the rest of start-up as well as input/output requests from software, translating them into data-processing instructions for the central processing unit. It handles memory and peripherals like keyboards, monitors, printers, and speakers.

Читайте также:  Хороший плеер для автомагнитолы андроид

Is There A Connection Between Kernel And Android?
Haha,Sorry but yes.Kernel is the main component for Android.Basically Android devices use the Linux kernel, but it’s not the exact same kernel other Linux-based operating systems use. There’s a lot of Android specific code built in, and Google’s Android kernel maintainers have their work cut out for them. OEMs have to contribute as well, because they need to develop hardware drivers for the parts they’re using for the kernel version they’re using. This is why it takes a while for independent Android developers and hackers to port new versions to older devices and get everything working. Drivers written to work with the Gingerbread kernel on a phone won’t necessarily work with the Ice Cream Sandwich kernel. And that’s important, because one of the kernel’s main functions is to control the hardware. It’s a whole lot of source code, with more options while building it than you can imagine, but in the end it’s just the intermediary between the hardware and the software. So basically if any instruction is given to mobile it first gives the command to kernel for the particular task execution.​

Open The Terminal and Paste following Command!

Upgrade The Built-In Environments!

Now When It Comes About Kernel Source,Where You’ll Find That?

No Worries,Search In Your Device Open Source Projects Websites To Get The Source OR You May Met With Github. Search In Github For Kernel Source For Your Device!

Here Are Some Sites,Where You Can Download Kernel Source Though:

Note: If You’ve Download The Source Then Extract It In A Directory. Or If You Want To Clone/Download Source From Github Then Follow Next Steps! ​

To Clone From Github,You Have To Install Repo Tool!

A. Open The Terminal and Paste Following Command!

2.Then Click On Clone Or Download Button,And Copy The Link!

B. Open A Terminal And Type This Command!

Explaination:
1. —>> Replace With The Link You Copied From Github To Clone The Source!
2. android/kernel ->> This Is My Directory Where I Want To Clone It!

Источник

[ULTIMATE GUIDE][Noob Friendly]Compile your own android kernel from source

Eliminator79

Senior Member

1.Installing Ubuntu
As we all know, Ubuntu is free open source OS that allows you to use it alongside your already installed OS without any problems, you will be promoted at every startup to choose whether your Default OS or Ubuntu OS
So, don’t get freaked guys no partitions are going to be formatted or no data loss is going to happen at all.

1)Get the Ubuntu ISO
Go to Ubuntu site (Downloads section)
Choose whether you are on 32-bit or 64-bit (We’ll be assuming that we are on 32-bit)

Choose «install Ubuntu alongside your windows OS version»
Manage the partitions yourself

You got your Ubuntu ready. Time for some business

Eliminator79

Senior Member

3.Installing Libraries and Preparing the Environment
As you know guys there are several libraries needed for any software to terminate properly so, if you want to succeed in compiling you have to get these libraries that we’re gonna write through the Linux terminal

1)Open the Linux Terminal
2)Write these commands

4.Preparing the toolchain
(You should download the whole toolchain of DoomLord, But to save our time I decided not to download the whole toolchain since that we’re going to use only one folder of it)
The folder will be: arm-eabi-4.33 (Took from Linaro 4.6) (So you can consider your kernel is compiled using Linaro 4.6
Download arm-eabi-4.4.3
and extract it in the root of your home
And if you want to download the whole source run these commands

Eliminator79

Senior Member

5.Adding Features to the Kernel

A)Automatic Way (Using the toolchain menu)

B)Manual Way
1)Adding Governors
The CPU is just 1 C file (Can be found at sources of any of kernel developers)
Get the Governor file
1.1 If you cant get it through github just view it and use other stock governor file like this
my kernel has already got performance governor, you are going to take it from Kernel Source/drivers/cpufreq/cpufreq_performance.c
Copy cpufreq_performance.c from kernel source to desktop then open it with text editor
delete all the lines in it then copy the lines from the viewed governor on github and rename the whole file name

1.2
Copy the governor C file to KernelSource/drivers/cpufreq and paste it
Open Kconfig
Then Add these lines with proper replacment

Читайте также:  Что может оставить след андроид

For BadAss (For Example)

Find endchoice
Add these lines below it

Open Kernel Source/include/linux.* now open cpufreq.h
Add these lines (With Proper Replacments)

2)Adding I/O Schedulers
Get the I/O .c file as the same way you got the Governor File
Paste it to Kernel Source/block

2.1
Now Open Kconfig.iosched
Let’s Assume that we now see SIO

We will put VR below it

We will put VR below it

Done We have added the VR I/O Scheduler !

3)Overclocking
Unfortunately, overclocking can’t be told the way i said the Governors and I/O Schedulers way because every device has its specific CPU frequencies
But, here is a little help
Go to KernelSource/arch/arm/mach-msm/acpuclock-XxXX.c
You will find files like these
acpuclock-7×30.c
acpuclock-8×50.c
You will see each one of them has only .c file
except one which will have .c and .o file
the one with both .c and .o files will be edited
Explanation will be added as soon as possible

Eliminator79

Senior Member

Replace with the number of cpu cores that the device has if you are on single core write 1 and if you are on dual core write 2[
Quad core=4
Octa core=8

Eliminator79

Senior Member

Wanna my help fast ?
Mention me or PM me
8.Additional Tips
*To find the number of cores of your CPU, just open terminal and type the following:

You will find the number of cores of CPU in a tag called «cpu cores» (Great Thanks to @#buzz)
*Some other useful packages from apt-get, especially on newer Qualcomm devices. (Might help you if you want to compile whole AOSP ROMs from source)

The Rules as they apply on XDA

As XDA has no legal power to uphold the GPL (and frankly we want to stay as far away from doing so as possible), we can’t force any of our users to abide by the GPL. However it is in XDA’s interests as well as the interests of our developer-base to ensure all GPL-derived materials hosted or linked on XDA comply fully with the GPL.

GPL-derived materials that do not come with the complete sources used to compile the GPL components are considered warez, and will be treated as such under forum rule 6 and 9.
If you use GPL components, but do not make any modifications to them whatsoever, you should provide a link to the original source of your GPL code.
Sources accompanying a release should be complete, and contain all the necessary source code for any modules, scripts or definition files. Complete sources will be defined as those which compile correctly and completely against the platform for which the software is distributed, and which contain any and all modifications made to the released General Public Licenced code. The source code supplied should be the exact version for which the source code is being requested, complete with all modifications.

EXAMPLE: Here’s a bit of code that could be used as a template to post your releases

The Very Quick Summary of General Public License (GPL)

The text of the GPL Licence itself will be used to reach any final conclusion regarding any disputes over GPL Licenced materials. The above is a summary of what XDA expects of members using GPL code, and the complete text can be read at the GNU website.

The GPL states that anyone who modifies GPL licenced code is required to make available the sources used to compile it. This is to further improve and encourage collaborative work, as well as to ensure that the best code possible is produced, and to encourage peer-review of all work. This benefits both developers and end users in numerous ways, including:

Allowing anyone to verify the code they are trusting with their data, and its authenticity
Encouraging community collaboration to produce faster fixes and updates, and better code
Helping bring new developments from other devices and fields to your own, letting you benefit from new code that wouldn’t have been available without this sharing.
The GPL imparts great freedom for GPL end users. It ensures innovation is never stifled and no project is dependent upon any single developer.

It is in everyone’s interest for the GPL to be adhered to, as it gives us all better ROMs, better transparency, and a better atmosphere for developers to work together to make great code.

Источник

Оцените статью