FORUMS
Remove All Ads from XDA

[DEV][TEMPLATE] AnyKernel3 - Easily Mod ROM Ramdisk + Pack Image.gz [Flashable Zip]

13,800 posts
Thanks Meter: 30,579
 
By osm0sis, Recognized Developer / Recognized Contributor on 5th March 2014, 03:32 AM
Post Reply Email Thread
19th April 2017, 07:27 AM |#451  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 30,579
 
Donate to Me
More
AVBv1, A/B slot and system-as-root (SAR)/2-stage init (2SI) device support updates:

Putting latest edits at the top since they're all that's necessary now.

Edit 4: Magisk now has a SAR mode (default in latest canaries) where nothing in / can be changed anymore, but you can add things to /overlay.d/sbin and they'll show up in /sbin when booted, and you can add .rc files to /overlay.d and they'll be appended to init.rc in memory at boot time when it's being parsed.

You can also trigger a fallback to Magisk's SARCompat mode (i.e. how Magisk used to work) by putting stuff in /overlay which will result in it ending up in / or wherever as before.

SAR Magisk is naturally where it's going, is technically better for all, and I won't recommend forcing SARCompat on users, so devs will just have to learn to work within the limits of SAR Magisk.

I don't imagine kernel developers will switch to /overlay.d until they have to target Android Q (where SAR will be forced for all devices by Google) or at least once Magisk goes stable with the new SAR mode.

Edit 3: Magisk uses skip_initramfs -> want_initramfs, and since it's ostensibly the only root method for A/B devices going forward, and in retrospect messing with @flar2's skip_override patch is needlessly overcomplicated when Magisk's installer might then also be flashed after a kernel and do the same thing (to no effect), or worse, the ramdisk might be unrooted by the TWRP zip causing a bootloop to recovery, current best practice going forward will be to either use sed or magiskboot's hexpatch feature to change skip to want.

https://github.com/freak07/AnyKernel...nel.sh#L32-L75
https://github.com/franciscofranco/r...nel.sh#L79-L88

Edit 2: Magisk will respect the existence of an /overlay directory and act appropriately, layering these over the booted / directory, as SuperSU does with /boot, but there won't be any files in /overlay unless you put them there.

Best practice for this setup, and least invasive is to use Android's listed init.rc imports to add your own /init.${ro.hardware}.rc file, since A/B and/or Treble devices have moved that file to /vendor, letting us place one in the ramdisk which will automatically be used as well. For example on the OP6T this file is init.qcom.rc and you could place this I'm /overlay to then import/run any number of .rc files or scripts.

For anything more invasive that requires pulling files from current /system (booted / directory) AK2 automatically has /system mounted read-only during the flashing process, so something like the following for each file we intend to modify e.g. init.rc will be necessary:

Code:
if [ -d $ramdisk/.backup ]; then
  overlay=$ramdisk/overlay;
elif [ -d $ramdisk/.subackup ]; then
  overlay=$ramdisk/boot;
fi;

list="init.rc";
for rdfile in $list; do
  rddir=$(dirname $rdfile);
  mkdir -p $overlay/$rddir;
  cp -rfp /system_root/$rdfile $overlay/$rddir/;
done;
So add the files you need with relative paths to root in list="" separated by spaces, then you can simply perform the AK2 changes on e.g. $overlay/init.rc.

Please note in addition, is_slot_device=1 or =auto must be set in anykernel.sh:
https://forum.xda-developers.com/sho...postcount=413;

and AVB signing is also required for proper Pixel support:
https://forum.xda-developers.com/sho...1#post72571741

Pixel 2 and newer devices can follow the same setup, but don't require avb since the AVBv2 on them isn't being enforced on unlocked bootloaders and also currently requires Python so can't easily be done on-device.

Background/older information, for posterity:
Things should be fully supported currently, please read through so you understand the requirements.

Initially there was a caveat; the zImage was flashing, changes were being made to the boot part of the rooted ramdisk but the ramdisk was reverting to unrooted.

So I was looking into this a bit more, and the clue was hidden back in @Chainfire's SuperSU v2.78-SR2 Release Notes..
Quote:

This change to the boot sequence requires a small patch [to] the kernel binary (inside the boot image), but does not require a kernel recompile. It should be portable to other kernels and thus remains a generic solution, though SuperSU's installer only supports uncompressed and GZIP compressed kernel binaries at this time.

Then I compared an output stock Pixel gunzipped zImage that was run though his sukernel utility with the --patch-slot-kernel argument and found it was a very simple replacement; skip_initramfs -> trip_initramfs.

So simple that even busybox sed can handle it safely:
Code:
sed -i 's/skip_initramfs/trip_initramfs/g' kernel
The problem being that this should only be added when the Pixel is rooted, otherwise it won't boot. And, when we're talking about custom kernels, you'd think they should have a patch for this anyway, right?

So this brings us to the other option, which comes from @flar2's Pixel zip/kernel, where he has added a patch to allow toggling skip_initramfs with a cmdline addition ("skip_override").

Then the zip detects whether the ramdisk is rooted (existence of "boot/" subdir) and adds to the cmdline and makes the ramdisk changes, otherwise leaving things alone for unrooted use.

It seems like the best thing to do is to leave it up to the kernel devs to apply flar's patch, and I'll add a new function to simplify cmdline editing. That way all the common scenarios are covered:

1) on unrooted Pixel with no zImage (ie. recovery ramdisk-only changes), things stay untouched.

2) on rooted Pixel with no zImage (ie. boot and/or recovery ramdisk-only changes), things stay as they were when flashed.

3) on rooted (and unrooted) Pixel with a zImage (ie. a custom kernel install) the dev is aware they need rooted ramdisk "boot/” detection in their script that will add skip_override to the cmdline as necessary.

It makes more sense to disable it properly with the cmdline flag than hack each kernel on-the-fly, even though the script-side logic is the same.



TL; DR

Okay, a preliminary patch_cmdline function is added in the latest commits. This is verified working on Pixel, thanks to @franciscofranco.

So, once flar's commit is in the kernel, this logic should be added to anykernel.sh, after dump_boot and before ramdisk changes:
Code:
if [ -d $ramdisk/.subackup -o -d $ramdisk/.backup ]; then
  patch_cmdline "skip_override" "skip_override";
else
  patch_cmdline "skip_override" "";
fi;
(We check for /.subackup since it's not something that should ever exist when not rooted by SuperSU, ditto /.backup for Magisk.)
The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ View ]
23rd April 2017, 07:19 PM |#452  
Senior Member
Thanks Meter: 1,992
 
More
Hi everyone, I am currently facing an issue with anykernel2, I can't boot if the data partition is wiped. Device Xiaomi Mipad(mocha). Kernel is OK, checked it by compiling stock boot IMG with mine zImage and ramdisc.
notauseranymore
23rd April 2017, 07:25 PM |#453  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by Star_king12

Hi everyone, I am currently facing an issue with anykernel2, I can't boot if the data partition is wiped. Device Xiaomi Mipad(mocha). Kernel is OK, checked it by compiling stock boot IMG with mine zImage and ramdisc.


You're not supposed to wipe data, that's why it won't boot.
23rd April 2017, 07:47 PM |#454  
Senior Member
Thanks Meter: 1,992
 
More
Quote:
Originally Posted by AutumQueen92

You're not supposed to wipe data, that's why it won't boot.

Really? Are you sure? Than tell me please how to install new roms.
24th April 2017, 07:09 AM |#455  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 30,579
 
Donate to Me
More
Quote:
Originally Posted by Star_king12

Hi everyone, I am currently facing an issue with anykernel2, I can't boot if the data partition is wiped. Device Xiaomi Mipad(mocha). Kernel is OK, checked it by compiling stock boot IMG with mine zImage and ramdisc.

Not sure how this is an AnyKernel2 problem? If you changed something in the ramdisk then.. don't change it? If you want help post your zip so someone can take a look because otherwise how can we?
The Following User Says Thank You to osm0sis For This Useful Post: [ View ]
24th April 2017, 10:42 AM |#456  
Senior Member
Thanks Meter: 1,992
 
More
Quote:
Originally Posted by osm0sis

Not sure how this is an AnyKernel2 problem? If you changed something in the ramdisk then.. don't change it? If you want help post your zip so someone can take a look because otherwise how can we?

Solved it, i took anykernel2.sh from other similar device, but forgot to delete some parts from it.
4th May 2017, 11:28 PM |#457  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 30,579
 
Donate to Me
More
May the fourth be with you!

A number of fixes, clean-ups, sha256 and SignBlob support, and new patch_cmdline and patch_prop functions added over the last couple of weeks! Please see the individual commit messages and updates to the OP for more details.

anykernel: isolate props:
https://github.com/osm0sis/AnyKernel...23de9f9ea0952e

AK2: misc cleanups:
https://github.com/osm0sis/AnyKernel...5e10fb85ac2432

AK2: add boot partition sanity check:
https://github.com/osm0sis/AnyKernel...3940b5493299ec

AK2: introduce cmdline patching function, misc cleanup:
https://github.com/osm0sis/AnyKernel...c82a4ef38ea5aa

README update:
https://github.com/osm0sis/AnyKernel...424c2471f690bc

AK2: add support for sha256 hashed boot.img:
https://github.com/osm0sis/AnyKernel...c242c6fcc761c9

AK2: add SignBlob support:
https://github.com/osm0sis/AnyKernel...d43cac46a16533

tools: update to latest builds, including busybox (1.26.2):
https://github.com/osm0sis/AnyKernel...582de224d8a338

AK2: introduce .prop files patching function:
https://github.com/osm0sis/AnyKernel...4c89e66c61bc23

README update:
https://github.com/osm0sis/AnyKernel...a39f577e0fc20c

README: properly document all the optional binaries, add some tips:
https://github.com/osm0sis/AnyKernel...52e2adb7cd951d

Apologies again for the anykernel.sh changes, it was time to clean up the output from those props since many misinterpreted it as an actual error. It's a fairly simple merge though, so nothing to fear. The new blobpack binary necessary to enable SignBlob support, as well as updated binaries for architectures other than ARM are, as always, available in my latest AIK-mobile package.
The Following 14 Users Say Thank You to osm0sis For This Useful Post: [ View ]
7th May 2017, 08:47 PM |#458  
brymaster5000's Avatar
Inactive Recognized Contributor
Flag New Hampshire
Thanks Meter: 3,167
 
Donate to Me
More
Quote:
Originally Posted by osm0sis

May the fourth be with you!

A number of fixes, clean-ups, sha256 and SignBlob support, and new patch_cmdline and patch_prop functions added over the last couple of weeks! Please see the individual commit messages and updates to the OP for more details.


Apologies again for the anykernel.sh changes, it was time to clean up the output from those props since many misinterpreted it as an actual error. It's a fairly simple merge though, so nothing to fear. The new blobpack binary necessary to enable SignBlob support, as well as updated binaries for architectures other than ARM are, as always, available in my latest AIK-mobile package.

Don't apologize. Anyone who is in the position to use your tools, should know how to manage a messy commit if that's what happens. Appreciate you work man!
The Following 2 Users Say Thank You to brymaster5000 For This Useful Post: [ View ] Gift brymaster5000 Ad-Free
14th May 2017, 05:31 PM |#459  
rachanta's Avatar
Senior Member
Thanks Meter: 4,129
 
Donate to Me
More
Does it support verified boot image? I use anykernel template for racer kernel for pixel and bullhead. Thanks for your awesome work.
The Following User Says Thank You to rachanta For This Useful Post: [ View ] Gift rachanta Ad-Free
14th May 2017, 07:08 PM |#460  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 30,579
 
Donate to Me
More
Quote:
Originally Posted by rachanta

Does it support verified boot image? I use anykernel template for racer kernel for pixel and bullhead. Thanks for your awesome work.

Not yet! I'm actually looking for some help from a Pixel owner first; can you please check out my post in my Android Image Kitchen thread?

https://forum.xda-developers.com/sho...7#post72198927

Until then you can always tack on Chainfire's PoC script if you like.
The Following 2 Users Say Thank You to osm0sis For This Useful Post: [ View ]
notauseranymore
21st May 2017, 11:37 AM |#461  
Guest
Thanks Meter: 0
 
More
I built an arm64 device and renamed the image.gz-dtb to zImage and flashed, but it immediately booted into fastboot mode. Any resolution for this?

Device is for the Redmi Note 4, zip file is attached.
Attached Files
File Type: zip Mido.zip - [Click for QR Code] (9.93 MB, 20 views)
Post Reply Subscribe to Thread

Tags
anykernel, flashable zip, kernel, scripting, template

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes