3

I've been reading that it's possible to apply patches to your Android kernel to give them more features.

Here's an example: https://patchwork.kernel.org/patch/2254211/

But my question is, how exactly do I DEVELOP a patch from scratch? I'm confused on what language the patches are coded in and where the required documentation for developing a patch to a kernel is. I've already asked this on XDA developers but no one seems to know and that's why I asked it here.

1 Answer 1

5
+50

First of all you will need the source of the kernel you want to patch as it is explained here:

https://source.android.com/source/building-kernels.html

As you can see in your link these files are written in C. When you got the source you can change some lines in these files to create your own patch How you build your changed kernel is explained as well in the above link. You can also add new files for complete new functionality or features.

To create your .patch file you will have to do something like

diff -Naur old_file.c changed_old_file.c > patch.txt

or you could as well use eclipse or git to do so, as shown here:

https://docs.moodle.org/dev/How_to_create_a_patch

Another usefull tool to create patches and apply them is quilt. How to use it you can read here:

https://wiki.debian.org/UsingQuilt

The documentation is done in the code with comments. Depending on the developer there will be more or less comments to explain what happens in the code. Additional documentation can be found under:

https://www.kernel.org/doc/Documentation/

I think the Linux kernel coding style is used in Android kernel development as well. So you should stick to the coding style of the rest of the kernel to get your patch acknowledged by the maintainer.

https://www.kernel.org/doc/Documentation/CodingStyle

[EDIT]: If you want to participate in the community its a good idea to subscribe to the mailing list of the kernel part you are most interested in. You can also get a feeling for what is needed to be patched. The google groups are probably a good place to ask additional questions on how to go on.

https://source.android.com/source/community/index.html

You can also get the source for android here:

https://android.googlesource.com/?format=HTML

Did i leave something out?

3
  • Really helpful, thanks. But how do I know which file am I supposed to patch? If it was a battery patch, how do I know which file controls the battery part? Or in short, how do I figure out which file is old_file.c? Does that make sense? Commented Sep 11, 2014 at 4:56
  • @PrasanthLouis Linux kernel patches are coded in C. First get the source and be able to build and load it on your device successfully. Then, you can navigate the source tree to the subsystem that you are interested in. You will have to understand what specific hardware sub-components your device contains and find the driver code in the kernel subsystem that controls it. Change that code to print debug messages to the system logger and confirm that it controls your device. Then make changes and use 'git' change control software to generate your patch.
    – Peter L.
    Commented Sep 11, 2014 at 17:01
  • 2
    If you have an idea what you want to change, it can help you to search the source tree. For example the battery. Battery has something to do with power supply so i searched for power supply and found the power_supply.h lxr.free-electrons.com/diff/include/linux/… if you are working on a linux system, you could use grep to find every file in your source tree that has the #include <linux/power_supply.h> line. Have a close look to the file and its header file and you will probably find the right place to apply your patch
    – ikstream
    Commented Sep 11, 2014 at 18:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.