Themes / Apps / Mods [DEV] Kernel Flasher

Search This thread

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
A new version is up. Here's the changelog:

added Hashtree Patcher for mount and unmount
added additional optional partitions
hid vendor_dlkm elements on devices without

I didn't make an update post for it, but alpha07 fixed a bug in the flash shell, which affected the newest AK3 on some devices. Also, the splash screen issue in alpha07 has been fixed.

Kernel update URLs and manual partition flashing are both on my shortlist for the next update.

Got some errors trying to backup on my 8T since there's no vendor_boot, so I guess some logic will be needed for whether they exist.

I had vendor_boot set to required, so I made it optional. The whole required/optional thing will go away when I've added partition selection to backup and restore.

Probably the feature should be like "backup slot" and save init_boot, boot, vendor_boot, dtbo, recovery, vendor_dlkm and vbmeta from the chosen slot if any of them exist.

I added dtbo, init_boot, and recovery to the optional partitions list.
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,049
34,157
Halifax
GT-i9250
Google Nexus 4
I added dtbo, init_boot, and recovery to the optional partitions list.

Thanks! Not seeing dtbo and recovery get backed up when I make a backup on my 8T though. Both are slotted partitions. Looks like it only backs up boot now. I guess once it's optional this'll all get ironed out. 🤞

Hopefully advanced reboot menu is still on the to-do as well. 😋
 

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
Thanks! Not seeing dtbo and recovery get backed up when I make a backup on my 8T though. Both are slotted partitions. Looks like it only backs up boot now. I guess once it's optional this'll all get ironed out. 🤞

It initially looks for boot in /dev/block/by-name, then it looks there for all physical partitions, as well. It looks for all logical partitions in /dev/block/mapper. vendor_dlkm is assumed to be the only logical partition in that list.

I may need to make some of that more generic. Let me know the details for the 8T, and I'll see what I can do. I've already added Hashtree Patcher to the latest builds, so I may just refactor everything to read from fstab.

Marking a partition as optional just prevents it from throwing an exception if it doesn't find it.

Hopefully advanced reboot menu is still on the to-do as well. 😋

I just gave this a go and it seems to be working fine. I'll clean it up and get it into the next release. The commit message for this didn't give any context and a quick test without it didn't yield any interesting results, so I'm going to ignore it for now.
 
  • Like
Reactions: osm0sis

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,049
34,157
Halifax
GT-i9250
Google Nexus 4
It initially looks for boot in /dev/block/by-name, then it looks there for all physical partitions, as well. It looks for all logical partitions in /dev/block/mapper. vendor_dlkm is assumed to be the only logical partition in that list.

I may need to make some of that more generic. Let me know the details for the 8T, and I'll see what I can do. I've already added Hashtree Patcher to the latest builds, so I may just refactor everything to read from fstab.

Marking a partition as optional just prevents it from throwing an exception if it doesn't find it.

I just gave this a go and it seems to be working fine. I'll clean it up and get it into the next release. The commit message for this didn't give any context and a quick test without it didn't yield any interesting results, so I'm going to ignore it for now.

Ah, I'd suggest /dev/block/by-name then /dev/block/bootdevice/by-name then /dev/block/platform/*/*/by-name or /dev/block/platform/*/by-name to cover all eras of devices.

8T has all of those (except the /*/ version of the last one, devices either have one or the other there), and the partitions in question are:

/dev/block/by-name/boot_a
/dev/block/by-name/boot_b
/dev/block/by-name/dtbo_a
/dev/block/by-name/dtbo_b
/dev/block/by-name/recovery_a
/dev/block/by-name/recovery_b

It also does have logical partitions, but no vendor_dlkm on OOS11 at least.

About that screen blanking code for reboot recovery, it's necessary on some OEM devices since with the screen on reboot recovery shows a scary "Rebooting to factory reset..." type message. Conversation on same here, for reference: https://github.com/topjohnwu/Magisk/pull/5637#issuecomment-1076060764
 
Last edited:
  • Like
Reactions: capntrips

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
Ah, I'd suggest /dev/block/by-name then /dev/block/bootdevice/by-name then /dev/block/platform/*/*/by-name or /dev/block/platform/*/by-name to cover all eras of devices.

I changed the detection function to use the fstab entries. vendor_boot does not appear in fstab, so I had to keep the path search as a fallback. I tried to find the code that loads vendor_boot in AOSP, so I could use the same magic, but I had no luck.

/dev/block/by-name/boot_a
/dev/block/by-name/boot_b
/dev/block/by-name/dtbo_a
/dev/block/by-name/dtbo_b
/dev/block/by-name/recovery_a
/dev/block/by-name/recovery_b

Since dtbo and recovery are in the same place as boot, I'm not sure why it didn't save them. I was previously using the standard File.exists(), so I changed everything to use SuFile, so we'll see if that gets it fixed.

About that screen blanking code for reboot recovery, it's necessary on some OEM devices since with the screen on reboot recovery shows a scary "Rebooting to factory reset..." type message. Conversation on same here, for reference: https://github.com/topjohnwu/Magisk/pull/5637#issuecomment-1076060764

Thanks for the context. I'll include it.

I'll try to get the build out tomorrow.
 
  • Like
Reactions: osm0sis

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,049
34,157
Halifax
GT-i9250
Google Nexus 4
I changed the detection function to use the fstab entries. vendor_boot does not appear in fstab, so I had to keep the path search as a fallback. I tried to find the code that loads vendor_boot in AOSP, so I could use the same magic, but I had no luck.

Since dtbo and recovery are in the same place as boot, I'm not sure why it didn't save them. I was previously using the standard File.exists(), so I changed everything to use SuFile, so we'll see if that gets it fixed.

Thanks for the context. I'll include it.

I'll try to get the build out tomorrow.

There are lots of things not in the fstab, so those fallback paths are important for sure. Thanks for your ongoing efforts! This is awesome. 😁
 
  • Like
Reactions: capntrips

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
I pushed a new build, and here are the changes:

added fstab entries as primary source of block devices
added resize fallback when not enough room for temporary partition
moved backups to /sdcard/KernelFlasher
replaced backup prop metadata with json and data classes
added backup partition hashes to backup metadata
restored AK3 zip filename to flash log
added advanced reboot menu

There were significant changes to the backup and restore functions, most notably they moved to /sdcard/KernelFlasher for ease of access from a file manager, and the metadata file is now JSON. As this breaks the old backups, I added a Migrate button on the Backups page, which I'll drop when the app goes stable.

I finally got around to reading the libsu 5.0.0 changelog and javadoc, and SuFile is eventually going away, so I started migrating to ExtendedFile. This is still a WIP, but all of the pieces are there.

I ended up doing basically all of the planned features except the ones I had previously planned to work on. Assuming this build doesn't crash and burn, once I get the remaining features added, I'll probably mark the next build as beta or rc.

P.S. I got a Pixel 6a today, so I'll likely make my Pixel 6 my daily driver (a year later) and the 6a my primary development device.

There are lots of things not in the fstab, so those fallback paths are important for sure.

Any idea where/how those partitions are defined?
 
Last edited:

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,049
34,157
Halifax
GT-i9250
Google Nexus 4
Any idea where/how those partitions are defined?

Code:
/dev/block/by-name
/dev/block/bootdevice/by-name
/dev/block/platform/*/*/by-name
/dev/block/platform/*/by-name

Probably Qualcomm or whoever defined these at some point, especially the old platform ones, then the bootdevice and direct by-name one were created by Google, Qualcomm or someone to simplify accessing them on newer devices.

On my 8T /vendor/etc/fstab.qcom contains:
Code:
system                                                  /system                ext4    ro,barrier=1,discard                                 wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey
system_ext                                              /system_ext            ext4    ro,barrier=1,discard                                 wait,slotselect,avb=vbmeta_system,logical,first_stage_mount
product                                                 /product               ext4    ro,barrier=1,discard                                 wait,slotselect,avb=vbmeta_system,logical,first_stage_mount
vendor                                                  /vendor                ext4    ro,barrier=1,discard                                 wait,slotselect,avb,logical,first_stage_mount
odm                                                     /odm                   ext4    ro,barrier=1,discard                                 wait,slotselect,avb,logical,first_stage_mount
/dev/block/by-name/metadata                             /metadata              ext4    noatime,nosuid,nodev,discard,sync                    wait,check,formattable,first_stage_mount
/dev/block/bootdevice/by-name/op2                       /mnt/vendor/op2        ext4    noatime,nosuid,nodev,barrier=1,data=ordered          wait,check
/dev/block/bootdevice/by-name/userdata                  /data                  f2fs    noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt   latemount,wait,check,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized+wrappedkey_v0,metadata_encryption=aes-256-xts:wrappedkey_v0,keydirectory=/metadata/vold/metadata_encryption,quota,reservedsize=512M,sysfs_path=/sys/devices/platform/soc/1d84000.ufshc,checkpoint=fs
/dev/block/bootdevice/by-name/persist                   /mnt/vendor/persist    ext4    noatime,nosuid,nodev,barrier=1                       wait
/dev/block/bootdevice/by-name/misc                      /misc                  emmc    defaults                                             defaults
#/devices/platform/soc/8804000.sdhci/mmc_host*           /storage/sdcard1       vfat    nosuid,nodev                                         wait,voldmanaged=sdcard1:auto,encryptable=footer
#/devices/platform/soc/1da4000.ufshc_card/host*          /storage/sdcard1       vfat    nosuid,nodev                                         wait,voldmanaged=sdcard1:auto,encryptable=footer
/devices/platform/soc/*.ssusb/*.dwc3/xhci-hcd.*.auto*   /storage/usbotg        vfat    nosuid,nodev                                         wait,voldmanaged=usbotg:auto
#/dev/block/bootdevice/by-name/spunvm                    /mnt/vendor/spunvm     vfat    rw,noatime,shortname=lower,uid=1000,gid=1000,dmask=007,fmask=007,context=u:object_r:vendor_spunvm_file:s0 wait
/dev/block/bootdevice/by-name/modem                     /vendor/firmware_mnt   vfat    ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait,slotselect
/dev/block/bootdevice/by-name/dsp                       /vendor/dsp            ext4    ro,nosuid,nodev,barrier=1                            wait,slotselect
/dev/block/bootdevice/by-name/bluetooth                 /vendor/bt_firmware    vfat    ro,shortname=lower,uid=1002,gid=3002,dmask=227,fmask=337,context=u:object_r:bt_firmware_file:s0 wait,slotselect

But the fstab is only for things with somewhat defined mount points I guess?

Code:
:/ # ls /dev/block/by-name
ALIGN_TO_128K_1  keymaster_a      qupfw_a
ALIGN_TO_128K_2  keymaster_b      qupfw_b
ALIGN_TO_512K    keystore         rawdump
abl_a            limits           recovery_a
abl_b            limits-cdsp      recovery_b
abl_log          logdump          reserve1
aging_kernel     logfs            reserve2
aging_mod        logo_a           reserve3
android_log      logo_b           reserve4
aop_a            mdm1m9kefs1      sda
aop_b            mdm1m9kefs2      sdb
apdp             mdm1m9kefs3      sdc
bluetooth_a      mdm1m9kefsc      sdd
bluetooth_b      mdm1oemnvbktmp   sde
boot_a           mdm_oem_dycnvbk  sdf
boot_b           mdm_oem_stanvbk  secdata
carrier          mdmddr           spunvm
cdt              mdtp_a           ssd
cmnlib64_a       mdtp_b           storsec_a
cmnlib64_b       mdtpsecapp_a     storsec_b
cmnlib_a         mdtpsecapp_b     super
cmnlib_b         metadata         tz_a
config           misc             tz_b
ddr              modem_a          uefisecapp_a
devcfg_a         modem_b          uefisecapp_b
devcfg_b         modemdump        uefivarstore
devinfo          modemst1         userdata
dip              modemst2         vbmeta_a
dsp_a            msadp            vbmeta_b
dsp_b            multiimgoem_a    vbmeta_system_a
dtbo_a           multiimgoem_b    vbmeta_system_b
dtbo_b           multiimgqti_a    vm-data
featenabler_a    multiimgqti_b    vm-keystore
featenabler_b    oem_cust1_a      vm-linux_a
frp              oem_cust1_b      vm-linux_b
fsc              oem_cust2_a      vm-system_a
fsg              oem_cust2_b      vm-system_b
hyp_a            op1              xbl_a
hyp_b            op2              xbl_b
hyp_log          param            xbl_config_a
imagefv_a        persist          xbl_config_b
imagefv_b        persist_bkp
kernel_log       qsee_log
:/ #
 
Last edited:
  • Like
Reactions: capntrips

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,049
34,157
Halifax
GT-i9250
Google Nexus 4
Ah I see boot, dtbo, recovery and vbmeta are indeed backed up, but there's no indication in the app what partitions are present in a backup. Working well though! This is excellent! 🤘
 
Last edited:
  • Like
Reactions: capntrips

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
Code:
/dev/block/by-name
/dev/block/bootdevice/by-name
/dev/block/platform/*/*/by-name
/dev/block/platform/*/by-name

Probably Qualcomm or whoever defined these at some point, especially the old platform ones, then the bootdevice and direct by-name one were created by Google, Qualcomm or someone to simplify accessing them on newer devices.

But the fstab is only for things with somewhat defined mount points I guess?

I was looking more for where they are defined offline.

I suppose they could just be directly from the partition table. I'll see if that turns up anything.

Ah I see boot, dtbo recovery and vbmeta are indeed backed up, but there's no indication in the app what partitions are present in a backup.

I'm planning to add on-screen logging and the save capability to the backup and restore functions, as with flash. I'm planning to display the partition and image hashes somehow, as well.
 

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
A new build is up, It adds the ability to check for and download updates from FKM style update URLs. There are still a few things that need to be added in a future build:
  • it does not provide the option to flash directly
  • it does not check for updates automatically (either on-load or in the background)
  • it does not validate the input in the url field
I'm still undecided on doing periodic checks in the background. If this is something you want, feel free to comment.

I'm planning to add manual image flashing next.
 

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
HELLO! PIXEL6 Kirisakura-Kernel 4.1.0, need to flash on both sides(slotA slot B)? tk
I have seen it suggested that you at least flash the bootloader to both slots for Android 13 on Pixel 6, so you don't end up in an unbootable state if your current slot fails to boot, otherwise there is no need to flash both slots to install a kernel.

Edit: Also, Kernel Flasher will only allow you to flash to the active slot.
 
Last edited:

capntrips

Senior Member
Aug 29, 2020
235
462
OnePlus 6T
Google Pixel 6
A new build is up, and here are the changes:

added partition image flashing
added selective backup and restore
added output console for backup and restore
listed partition hashes

While the app now displays the hashes of the backed up images, it does not display the live partition hashes. If this is something you might find useful, feel free to comment.

This build wraps up all of the major planned features, and assuming no significant issues arise, this will be the last alpha build, and the next few builds will likely focus on cleaning things up a bit.

The biggest remaining changes are related to the Updates feature, and I imagine they'll be the bulk of the next build.

Note: This build does not include the latest build of lptools, so be careful with the restore function after an OTA. See here for details. It will be included in the next build.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 32
    kernel-flasher-1.jpg
    kernel-flasher-2.jpg
    kernel-flasher-3.jpg


    Kernel Flasher is an Android app to flash, backup, and restore kernels.

    Features
    • Flash partition images and AK3 kernel zips
    • Backup and Restore kernel partitions
    • Mount, Map, and Resize vendor_dlkm
    • Save dmesg, logcat, and ramoops
    • Check for kernel updates

    Notes

    When making a backup of the active slot, to save time, it is assumed that the kernel on disk is the same as the running kernel. The Check Kernel Version button can retrieve it from disk prior to backup.

    Depending on the method used, the updated contents of vendor_dlkm may not be immediately available for backup after flash or restore. This can be resolved by unmounting, unmapping, then remapping it.

    AK3 helper modules are not backed up.


    Credits

    @osm0sis for AK3, feedback, and general guidance
    @eng.stk & @Freak07 for feedback, advice, and encouragement
    @phhusson for lptools
    @topjohnwu for Magisk and libsu


    Latest Update

    2022-08-31 v1.0.0-alpha11
    6
    This is looking great! My only feedback is that it would be nice if when displaying kernel version it would also show the build # a lot of developers use to show their versions/revisions.

    E.g. 4.19.110+blu-spark-OOS #130

    This is done in my personal build, will be included in the next release. For long kernel strings, you can tap the text to reveal the whole thing. The full string will be included in any new backups, as well.

    Hi , thanks for the great app
    Supports flashing vendor_ dlkm , vendor_ boot img also?..( asking because if yes ..i can restore stock kernel on my p6pro without using a pc)..it could be useful

    Yes, it supports boot, vbmeta, dtbo, vendor_boot, vendor_dlkm, init_boot, and recovery on the devices that include them. For logical partitions (vendor_dlkm), it uses the same method as AK3 to flash it. The note about lptools from my last message applies.
    6
    Can you please leave the kernel installation log opened after the process ends with an error? Currently it's impossible to see what went wrong since the log disappears instantly and is being replaced by an error screen.
    That is already done in my own personal test version of the app, but I haven't had a chance to clean it up and get it released. I'll make an effort to get that done this evening.

    I've got several other enhancements planned, but most of my focus has been on Hashtree Patcher lately, though I think that is nearly wrapped up. I'll try to get the installation log issue fixed asap, then I'll work on the rest over the next few days.
    6
    A new build is up, and here are the changes:

    added partition image flashing
    added selective backup and restore
    added output console for backup and restore
    listed partition hashes

    While the app now displays the hashes of the backed up images, it does not display the live partition hashes. If this is something you might find useful, feel free to comment.

    This build wraps up all of the major planned features, and assuming no significant issues arise, this will be the last alpha build, and the next few builds will likely focus on cleaning things up a bit.

    The biggest remaining changes are related to the Updates feature, and I imagine they'll be the bulk of the next build.

    Note: This build does not include the latest build of lptools, so be careful with the restore function after an OTA. See here for details. It will be included in the next build.
    6
    A new build is up, It adds the ability to check for and download updates from FKM style update URLs. There are still a few things that need to be added in a future build:
    • it does not provide the option to flash directly
    • it does not check for updates automatically (either on-load or in the background)
    • it does not validate the input in the url field
    I'm still undecided on doing periodic checks in the background. If this is something you want, feel free to comment.

    I'm planning to add manual image flashing next.