Skip to main content

πŸ“€ Boot Patch v1.0.0

Allows unpacking and packing the boot.img or recovery.img of most Android devices.

Credits
note

You can design your own plugins. Check this.


Installation​

  1. Download the plugin here.
  2. Add boot-patch file in your META-INF/addons.
  3. Import it:
    import_module "$addons/boot-patch"
  4. Enjoy your new functions!

unpack_boot​

Unpacks an existing IMG/Partition.

ArgumentDescription
IMG/PartitionPath to the IMG file or partition to extract
FOLDERDirectory where the extracted contents will be saved
NUMBEROptional: Set to 1 to skip unpacking the ramdisk
# Unpack some existing IMG
unpack_boot "$TMP/boot.img" "$TMP/first_boot"

# Unpack from some Partition
unpack_boot $(find_block boot) "$TMP/second_boot"

# Unpack without unpacking the Ramdisk
unpack_boot $(find_block boot) "$TMP/second_boot" 1
tip

You can check if there were any problems during unpacking:

if unpack_boot $(find_block boot) "$TMP/first_boot"; then
ui_print "Success"
else
abort "Some error"
fi

repack_boot​

Rebuilds the IMG unpacked by unpack_boot.

ArgumentDescription
FOLDERDirectory containing the unpacked contents
OUTPUTPath to save the rebuilt IMG or partition to write to
OPTIONOptional: Set to recovery to use AVB1 signing for recovery images
# Repack some unpacked IMG
repack_boot "$TMP/first_boot" "$TMP/result.img"

# Repack and send it to some Partition
repack_boot "$TMP/second_boot" $(find_block boot)

# Repack some unpacked Recovery image
repack_boot "$TMP/second_boot" $(find_block recovery) recovery
note

Automatic Behaviors:

  • If Magisk is detected in the original boot.img, a restore will be attempted.
  • If the restore fails (for example, due to complete Ramdisk replacement), Magisk will be completely removed.
tip

You can check if the resulting IMG lost Magisk. Verification of other ROOT methods is not supported.

repack_boot "$TMP/first_boot" $(find_block boot)
result=$?

if is_equal $result 0; then
ui_print "No error and Magisk ensured"
elif is_equal $result 1; then
ui_print "Some fatal problem! and no changes were made"
elif is_equal $result 2; then
ui_print "No error but Magisk is not present"
fi

update_ramdisk​

Updates the ramdisk of an existing IMG or partition.

ArgumentDescription
NEW RAMDISKPath to the new ramdisk file
IMG/PartitionPath to the IMG file or partition to update
# Update the Ramdisk in some existing IMG
update_ramdisk "$TMP/new_ramdisk.cpio" "$TMP/boot.img"

# Update the Ramdisk in some Partition
update_ramdisk "$TMP/new_ramdisk.cpio" $(find_block boot)
note

You can save the error code to know if the IMG lost Magisk. Check repack_boot.


update_kernel​

Updates the kernel of an existing IMG or partition.

ArgumentDescription
NEW KERNELPath to the new kernel file
IMG/PartitionPath to the IMG file or partition to update
# Update the Kernel in some existing IMG
update_kernel "$TMP/new_kernel" "$TMP/boot.img"

# Update the Kernel in some Partition
update_kernel "$TMP/new_kernel" $(find_block boot)
note

You can save the error code to know if the IMG lost Magisk. Check repack_boot.


patch_cmdline​

Patches properties of the cmdline of an IMG unpacked by unpack_boot.

ArgumentDescription
PROPERTYProperty to add or replace (Multiple allowed)
# It is necessary to be in the directory
cd "$TMP/first_boot"

patch_cmdline androidboot.selinux=permissive
note

Automatically replaces or adds props (if you patch the same prop twice, it won’t repeat).


remove_cmdline​

Removes properties of the cmdline of an IMG unpacked by unpack_boot.

ArgumentDescription
PROPERTYProperty to remove (Multiple allowed)
# It is necessary to be in the directory
cd "$TMP/first_boot"

remove_cmdline skip_override

flash_image​

Installs an IMG to a partition or saves it to a file.

ArgumentDescription
IMGPath to the IMG file to install
OUTPUTPartition to write to or file to save
flash_image "$TMP/boot.img" $(find_block boot)
note

This function is provisional for this plugin, it is not strictly necessary to use it. DI already provides specific functions to do the same.