- EduApps-CDG / Building Linux Kernel With Android.md
- Android Kernel Development using linux [closed]
- 1 Answer 1
- [REFERENCE] How to compile an Android kernel
- Breadcrumb
- nathanchance
- mosimchah
- NoNameMi
- Subham
- NZnewbie
- jacbarahona72
- karandpr
- kevintm78
- nathanchance
- nathanchance
- Which Android runs which Linux kernel?
- 1 Answer 1
- Linux version in AOSP
- Why Android OS/kernel version mismatches
- Vendor Test Suite (VTS) requirements on Linux version
EduApps-CDG / Building Linux Kernel With Android.md
How to Build Linux Kernel with Android
This guide shows how to build Linux on a Android Device and was made for people that doesn’t have s Computer.
- 4GB of free space (2GB if delete the temp files)
- Android 5.0
Preparing the Environment
You need to install Termux from Google Play Store. Now we will download the Kernel so we need WGET:
The next step is decompress that tarball with UNXZ and TAR (integrated with Termux):
(Optional) Delete the Linux tarball:
Now we have the Linux Source on our Android, lets compile!
In Android, compile is a terror for Linux Kernel. First we need to create a config file.
The .config file dilemma
If you had an Linux PC you could simply do this:
But you dont have so we need to do this:
If you have a Rooted Potato Phone you can simply:
No Root mode (medium)
If else, first you need to download it from our repository:
No Root mode (hard)
If the file was not found, you must generate it. It has only one command, but this command is the worst! It’s the best choice if you are developing a new device. Complete the first command of Building and type:
Once solved the dilemma, you will not need to do it again. the next step is install the compilers:
This command will setup to build the Kernel with full power, if you have a single core device, it doesn’t help so much but works:
And finally, the Last Step is: Enjoy the building time and drink a coffee!
Источник
Android Kernel Development using linux [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago .
I am interested in developing kernel for android phones. I searched on internet about android kernel development and i got how to build kernel on linux machine means only how to use tools for create a custom kernel but i want to know how to write code to make android kernel. How to start with c programming and ALP. Please guide me.
1 Answer 1
Android uses Linux kernel and that is why you should get familiar with Linux first.
From you post I am guessing that you don’t know much of C programming language. Before you start doing any kernel work you should be able to write an application in C because if you cannot write an application you probably will not understand a kernel.
To start leaning C there are dozens of resources everywhere, I would recommend the book «C programming language» by Brian W. Kernighan. and Denis M. Ritchie (inventor of C).
Application runs in so called «User mode» and have only access to Virtual Memory that is given to them by the kernel. If the application tries to access memory that is not in its Virtual Space the kernel sends an abort signal. This prevents the system from crashing. In kernel the is not the case because the kernel runs in «Kernel mode» and thus has access to the whole address space when you do something wrong the consequences can range from halting the system to wiping permanent storage and more.
So first learn how to write applications, maybe a native applications, try to use the functionality that is provided by the kernel by learning about «System calls». For this purpose I would recommend the books «Advanced Linux Programming» by Mark Mitchel, it is freely hosted on its website http://advancedlinuxprogramming.com/. You can find some reference here https://en.wikibooks.org/wiki/The_Linux_Kernel.
If you are comfortable with both C and the Services the Linux kernel provides. Than you can start thinking about diving into the kernel. Very popular book is «Linux kernel development» by Robert Love. Although I don’t think it is very up to date It should cover the major topics related to that subject,there are probably resources out there that are more up to date.
This is a long journey and you should really think about it first, depending on what you want to do you may actually be able to do it in «User Space».
Источник
[REFERENCE] How to compile an Android kernel
Breadcrumb
nathanchance
Senior Recognized Developer / Contributor
Hello everyone, I will be going over how to compile a kernel from beginning to end!
Prerequisites:
- A Linux environment (preferably 64-bit)
- Knowledge of how to navigate the command line
- Common sense
- A learning spirit, there will be no spoonfeeding here
What this guide will cover:
- Downloading the source
- Downloading a cross compiler
- Building the kernel
- Flashing the kernel
What this guide will NOT cover:
- Setting up a build environment (plenty of existing Linux installation guides)
- Adding features to the kernel (plenty of git cherry-picking guides)
I know this has been done before but on a cursory search, I have not seen a guide that was recently updated at all.
1. Downloading the source
If you have a custom kernel you want to build, move along after cloning the kernel using the git clone command below.
If you are compiling your stock kernel, it is ultimately up to you to know where to get your kernel source from but here are some common places:
To download the kernel, you can either use git clone or download the tarball and extract it:
This will clone the kernel/msm repo into an angler folder and checkout the android-msm-angler-3.10-nougat-mr2 automatically.
I can try and help you locate your source if necessary.
2. Downloading a cross compiler
Since most Android devices are ARM based, we need a compiler that is targeting ARM devices. A host (or native) compiler will not work unless you are compiling on another ARM device.
You can either compile one yourself if you know how (crosstool-NG is a great tool for this) or download a prebuilt one. Luckily Google provides a high quality toolchain for this, in both an arm (32-bit) and arm64 (64-bit). It’s up to you to know the architecture of your device. Typically speaking, most devices in the past two-three years are 64-bit.
Another popular toolchain is UberTC, which can be found here: https://bitbucket.org/matthewdalex/. Most kernels will need patches for anything higher than 4.9 and while I don’t mind assisting with finding them, you should compile with Google’s toolchain first.
Once you have decided, clone the toolchain:
3. Compile the kernel
NOTE #1: For kernels that can be compiled with Clang (like the Pixel 2), see this guide. I will support it here if there are any questions.
NOTE #2: Pixel and Pixel 2 users, you will need to follow these steps as well if compiling for Android Pie.
2. Tell the Makefile the architecture of the device
4. Build the kernel
If those commands succeed, you will have an Image, Image-dtb, Image.gz, or Image.gz-dtb file at the end.
If it failed, as was pointed out to me by @flar2 while making a complete idiot of myself, you may need to specify an output directory while making new CAF based kernels, like so:
Assuming you were able to compile the kernel successfully, you now need to flash it! I will be covering two different ways to flash a compiled kernel: unpacking and repacking the boot image by hand using Android Image Kitchen or AnyKernel2, both by the brilliant @osm0sis. If there are any per-device nuances, please let me know and I’ll add them here! Additionally, this section can vary drastically by device, you may need to consult developers of your device for assistance if necessary.
Android Image Kitchen
A lot of kernels from CAF include a Python script that will essentially turn on -Werror, causing your build to error at the most benign stuff. This is necessary with higher GCC versions as there are a lot more warnings.
Here is the diff of what you need to change in the Makefile:
Using a higher GCC toolchain (5.x, 6.x, 7.x or even 8.x) will require you to nuke the GCC wrapper script as above and use a unified GCC header file (pick the following if you have an include/linux/compiler-gcc#.h file):
You may get a lot of warnings but they are not entirely necessary to fix.
3. Adding upstream Linux to kernel source
I am happy to answer anything that I touched on in this guide. I may point you to another thread if it’s better suited but I don’t mind off topic (within reason) within the thread. I also want this to be a collaborative effort; other developers, if you have something to add, correct, or improve upon, please let me know!
I am particular in how people ask for help. I do NOT respond to posts asking for a hand out («How do I fix this?», «Please fix this!», etc.). I only respond to posts with clear logs and steps that you have tried. Basically, show me that you have read this guide and have a specific issue. I am not here to hold your hand through this, this is a developers’ forum.
mosimchah
Senior Member
You’re on fire with this kernel stuff
Sent from my LEX727 using XDA Labs
NoNameMi
Member
Subham
Senior Member
A really helpful guide much needed around for upcoming developers. This is the perfect guide for them. Nice work ?
Sent from my ONE A2003 using Tapatalk
NZnewbie
Senior Member
The guys a Feckn Champ.
jacbarahona72
Senior Member
Enviado desde mi Nexus 6 mediante Tapatalk
karandpr
Senior Moderator | DC Lead | MC
I am happy to answer anything that I touched on in this guide. I may point you to another thread if it’s better suited but I don’t mind off topic (within reason) within the thread. I also want this to be a collaborative effort; other developers, if you have something to add, correct, or improve upon, please let me know!
I am particular in how people ask for help. I do NOT respond to posts asking for a hand out («How do I fix this?», «Please fix this!», etc.). I only respond to posts with clear logs and steps that you have tried. Basically, show me that you have read this guide and have a specific issue. I am not here to hold your hand through this, this is a developers’ forum.
On a scale of 1-10 how much Off-Topic is allowed ? :highfive::laugh::silly:
kevintm78
Senior Member
I have been using ./build_kernel.sh to compile kernels as was suggested by another guide and I’m wondering if there’s any pros or cons doing it that way as opposed to using the make defconfig way.
They seem to be working ok but this is the second guide on xda that suggest the way you’re doing it and I’m definitely open to change if this way is better. Any thoughts on the two methods would be much appreciated. I also would like to say thanks for these new guides as finding kernel dev info for newbies is very scarce and mostly outdated. I really look forward to seeing this thread take off. :good:
nathanchance
Senior Recognized Developer / Contributor
I have been using ./build_kernel.sh to compile kernels as was suggested by another guide and I’m wondering if there’s any pros or cons doing it that way as opposed to using the make defconfig way.
They seem to be working ok but this is the second guide on xda that suggest the way you’re doing it and I’m definitely open to change if this way is better. Any thoughts on the two methods would be much appreciated. I also would like to say thanks for these new guides as finding kernel dev info for newbies is very scarce and mostly outdated. I really look forward to seeing this thread take off. :good:
nathanchance
Senior Recognized Developer / Contributor
I have updated the OP with a note about compiling newer CAF releases (3.18 and 4.4 to my knowledge). As was pointed out by @flar2 while I was making an idiot of myself accusing him of violating the GPL (for which I truly do apologize), you may need to specify an output directory (by adding an O= flag). This is actually done automatically when a ROM compiles a kernel inline so you will only run into this while compiling standalone.
I have added it to my script here if you want an idea of how to add it to yours.
Источник
Which Android runs which Linux kernel?
Is there a list of which kernel version comes in each Android AOSP version?
Or lets say, which version /proc/version would spit out.
1 Answer 1
Linux version in AOSP
Table compiled from:
Note: other “distributions” of Android might run different kernel versions.
Anyone is welcome to correct and expand this table. Please keep formatting.
Why Android OS/kernel version mismatches
OEMs tend to ship their major Android updates with a similar kernel to the one the device was initially released with. This is most likely to avoid hardware and driver incompatibility issues with a newer kernel. For example, a device that has been updated to run Android 8.0 Oreo but originally shipped with 6.0 Marshmallow may still be running Linux 3.18.x instead of Linux 4.10.x.
Vendor Test Suite (VTS) requirements on Linux version
One aspect that has been up to the OEM is the Linux kernel version but this is changing with Android Oreo.
As long as the OEM was able to pass the certification tests that Google lays out, then they didn’t care what kernel version was used in a new device. This generally wasn’t an issue as most OEMs would use the same version of the kernel for that generation that other OEMs were using, as it is tied heavily to what the hardware drivers support. However, some had been falling through the cracks and this started to cause security issues. This is something that Google has been taking seriously lately so it makes sense that they would want to start mandating this.
Starting this year with smartphones which ship with Android Oreo, Google is requiring that all SoCs productized in 2017 must launch with kernel 4.4 or newer.
Currently existing devices that are upgraded to Android Oreo are only required to run kernel version 3.18 or newer, and will not have to be upgraded to support Project Treble.
Источник