FORUMS
Remove All Ads from XDA

[DEV][TEMPLATE] AnyKernel2 - Easily Mod ROM Ramdisk + Pack zImage [Flashable Zip]

9,923 posts
Thanks Meter: 19,137
 
By osm0sis, Recognized Developer / Recognized Contributor on 5th March 2014, 02:32 AM
Post Reply Subscribe to Thread Email Thread
AnyKernel2 -- Flashable Zip Template for Kernel Releases with Ramdisk Modifications

"AnyKernel is a template for an update.zip that can apply any kernel to any ROM, regardless of ramdisk." - Koush

The concept of AnyKernel has been around for awhile, (originally by Koushik Dutta/ClockworkMod,) which allowed a device-specific kernel zImage to be flashed over device-specific ROM and use the ramdisk that came with the ROM to reduce the chance of any issues arising from the custom kernel pairing.

The drawback to this was that some kernels require modifications to the ramdisk to enable/set up kernel features, and in the old AnyKernel format there was no way to do this. Until now.

AnyKernel2 pushes the format even further by allowing kernel developers to modify the underlying ramdisk for kernel feature support easily using a number of included command methods along with properties and variables to customize the installation experience to their kernel.

A working script based on DirtyV Kernel (by bsmitty83) for Galaxy Nexus (tuna) is included for reference. An example of ramdisk-only changes can be seen in my GN Synapse Injector repo. Other working AK2 examples for more recent devices may be found on the franco.Kernel download repo in the 6.0 subfolders.

My development work on my many projects comes out of my free time, so if you enjoy this project or anything else I've done on xda, please do hit the donate link from my profile. Thank you for your support!


Source: https://github.com/osm0sis/AnyKernel2/
Download: https://github.com/osm0sis/AnyKernel...ive/master.zip


Instructions

1) Place zImage in the root (dtb should also go here for devices that require a custom one, both will fallback to the original if not included)
2) Place any required ramdisk files in /ramdisk, and modules in /modules
3) Place any required patch files (generally partial files which go with commands) in /patch
4) Modify the anykernel.sh to add your kernel's name, boot partition location, permissions for included ramdisk files, and use methods for any required ramdisk modifications
5) zip -r9 UPDATE-AnyKernel2.zip * -x README UPDATE-AnyKernel2.zip

If supporting a recovery that forces zip signature verification (like Cyanogen Recovery) then you will need to also sign your zip using the method I describe here:
[DEV][TEMPLATE] Complete Shell Script Flashable Zip Replacement + Signing [SCRIPT]

Not required, but any tweaks you can't hardcode into the source should be added with a bootscript.sh like is done in the example provided.

Enjoy!
Questions, comments and feedback welcome.



Credits & Thanks: All authors of the included binaries and the tools I used to port them over for their amazing work. koush for the original AnyKernel concept.

Disclaimer: Naturally, you take all the responsibility for what happens to your device when you start messing around with things.


XDA:DevDB Information
AnyKernel2, Tool/Utility for the Android General

Contributors
osm0sis

Version Information
Status: Stable
Stable Release Date: 2016-03-30

Created 2014-03-05
Last Updated 2016-04-01
Last edited by osm0sis; 5th March 2014 at 02:36 AM.
The Following 95 Users Say Thank You to osm0sis For This Useful Post: [ View ] Gift osm0sis Ad-Free
 
 
5th March 2014, 02:33 AM |#2  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 19,137
 
Donate to Me
More
Script Commands Reference
Everything to edit is self-contained in anykernel.sh. A quick-reference for the commands and properties included are as follows.

Properties / Variables

These are some properties the EDIFY updater-script will read during the install process, allowing you to customize your installation. block is a shell variable to specify the kernel/boot block partition that the dump_boot command method will dd and unpack.

Code:
kernel.string=KernelName by YourName @ xda-developers
do.devicecheck=1
do.initd=1
do.modules=1
do.cleanup=1
device.name1=maguro
device.name2=toro
device.name3=toroplus

block=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot;
do.devicecheck=1 specified requires at least device.name1 to be present. This should match ro.product.device or ro.build.product from build.prop for your device. There is support for up to 5 device.name# properties. You may remove any empty ones that aren't being used.

do.initd=1 will create the init.d directory in /system/etc/init.d/ and apply 755 permissions.

do.modules=1 will push the contents of the module directory to /system/lib/modules/ and apply 644 permissions.

do.cleanup=0 will keep the zip from removing it's working directory in /tmp/anykernel - this can be useful if trying to debug in adb shell whether the patches worked correctly.

Command Methods

Code:
dump_boot
backup_file <file>
replace_string <file> <if search string> <original string> <replacement string>
replace_section <file> <begin search string> <end search string> <replacement string>
remove_section <file> <begin search string> <end search string>
insert_line <file> <if search string> <before|after> <line match string> <inserted line>
replace_line <file> <line replace string> <replacement line>
remove_line <file> <line match string>
prepend_file <file> <if search string> <patch file>
insert_file <file> <if search string> <before|after> <line match string> <patch file>
append_file <file> <if search string> <patch file>
replace_file <file> <permissions> <patch file>
patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>
write_boot
"if search string" is the string it looks for to decide whether it needs to add the tweak or not, so generally something to indicate the tweak already exists.

Similarly, "line match string" and "line replace string" are the search strings that locate where the modification needs to be made for those commands, "begin search string" and "end search string" are both required to select the first and last lines of the script block to be replaced for replace_section, and "mount match name" and "fs match type" are both required to narrow the patch_fstab command down to the correct entry.

"before|after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string".

"block|mount|fstype|options|flags" requires you specify which part (listed in order) of the fstab entry you want to check and alter.

You may also use ui_print "<text>" to write messages back to the recovery during the modification process, and contains "<string>" "<substring>" to simplify string testing logic you might want in your script.

Note: the "begin search string" and "end search string" arguments of replace_section and remove_section require any forward slashes (/) to be escaped.
Last edited by osm0sis; 16th March 2016 at 06:16 PM.
The Following 49 Users Say Thank You to osm0sis For This Useful Post: [ View ] Gift osm0sis Ad-Free
5th March 2014, 04:25 AM |#3  
bsmitty83's Avatar
Recognized Contributor
Flag Detroit
Thanks Meter: 10,055
 
More
Boom . dibs on first
You get 2 thank button presses fro me lol
Awesome work man as always
Last edited by bsmitty83; 5th March 2014 at 04:28 AM.
The Following 5 Users Say Thank You to bsmitty83 For This Useful Post: [ View ] Gift bsmitty83 Ad-Free
5th March 2014, 04:32 AM |#4  
Hetalk's Avatar
Recognized Contributor
Flag Ahmedabad
Thanks Meter: 3,125
 
Donate to Me
More
Good thing that this amazing work has it's own thread. Congrats buddy.

Sent from my Galaxy Nexus using XDA Premium 4 mobile app
The Following User Says Thank You to Hetalk For This Useful Post: [ View ] Gift Hetalk Ad-Free
5th March 2014, 04:52 AM |#5  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 19,137
 
Donate to Me
More
Thanks guys!

I figured it would be nice to get it out there and also have it as a "Help Desk" thread for kernel devs who have questions about implementation, etc. too. Some devices might require switching it from dd to MTD-Utils, so I can help with that. So on and so forth.

Once we get a few devs who know how to use it, it should be pretty easy to help others. I'm looking at you Smitty. No pressure.
Last edited by osm0sis; 5th March 2014 at 04:55 AM.
The Following 6 Users Say Thank You to osm0sis For This Useful Post: [ View ] Gift osm0sis Ad-Free
5th March 2014, 05:36 AM |#6  
ak's Avatar
Recognized Contributor
Flag Ak Land Valley
Thanks Meter: 69,751
 
Donate to Me
More
I finished my thanks ... but as always a great job.
The Following User Says Thank You to ak For This Useful Post: [ View ] Gift ak Ad-Free
5th March 2014, 06:12 AM |#7  
milojoseph's Avatar
Senior Member
Flag Brooklyn
Thanks Meter: 564
 
More
Quote:
Originally Posted by ak

I finished my thanks ... but as always a great job.

So wait im confused. ?.. so 1) those that mean I can flash ak kerenl 4.2 with ur any kernel to my 4.4 o.O.
2) those it have to be same kerenl for same phone manufacturer. Meaning can I be stupid enought to flash a nexus 4 kernel in my gnexus?
I understand any kernel cause I have been using smitty so thanks
The Following 2 Users Say Thank You to milojoseph For This Useful Post: [ View ] Gift milojoseph Ad-Free
5th March 2014, 06:17 AM |#8  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 19,137
 
Donate to Me
More
Quote:
Originally Posted by milojoseph

So wait im confused. ?.. so 1) those that mean I can flash ak kerenl 4.2 with ur any kernel to my 4.4 o.O.
2) those it have to be same kerenl for same phone manufacturer. Meaning can I be stupid enought to flash a nexus 4 kernel in my gnexus?
I understand any kernel cause I have been using smitty so thanks

Haha I wrote "device-specific" in the OP to try and avoid this very confusion.

Since I answered this same question earlier tonight in my Odds and Ends thread I'll just paste it here:
Quote:
Originally Posted by caspboy

so now devs can use kernels from other devices with their roms?

Quote:
Originally Posted by osm0sis

No. That's crazy talk.

The concept of AnyKernel has been around for awhile, (originally by Koushik Dutta/ClockworkMod,) which allows device-specific kernels to be flashed over device-specific ROMs and use the ramdisk that came with the ROM to reduce the chance of any issues arising from the custom kernel pairing.

The drawback to this is that some kernels require modifications to the ramdisk to enable/set up kernel features, but in the old AnyKernel format there was no way to do this. Until now.

AnyKernel 2.0 makes it easy for kernel devs to use a number of simple command methods to automate the process of adding tweaks into a ROM's underlying ramdisk during the flashing process.

Hopefully that helps. Basically exactly what's in the OP since that's where I edited it in from.

The only way I can explain it any further is with the very basics: that kernel boot.img files contain a zImage and a ramdisk. "AnyKernel Classic" just slaps the custom kernel zImage on top of the ROM's untouched default kernel boot.img ramdisk. AnyKernel 2.0 allows kernel devs to also modify the ramdisk to add anything required for kernel features in addition to the usual repacking it with the custom zImage and flashing it.
Last edited by osm0sis; 5th March 2014 at 06:25 AM.
The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ View ] Gift osm0sis Ad-Free
5th March 2014, 06:32 AM |#9  
wisefreakz's Avatar
Senior Member
Flag Sampa City
Thanks Meter: 626
 
More
Great thread!! Best of lucky bro!!!

Sent from my Galaxy Nexus using xda app-developers app
The Following User Says Thank You to wisefreakz For This Useful Post: [ View ] Gift wisefreakz Ad-Free
5th March 2014, 06:54 AM |#10  
aosp's Avatar
Recognized Developer
Thanks Meter: 5,013
 
Donate to Me
More
AnyKernel will work on my phone now 😱 Thanks for enhancing awesome @osm0sis but DrRamdisk to the rest of you guys 😁
The Following User Says Thank You to aosp For This Useful Post: [ View ] Gift aosp Ad-Free
Post Reply Subscribe to Thread

Tags
anykernel, flashable zip, kernel, scripting, template
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes