Mkbootimg: Repacking Android recovery produce corrupted image
1
vote
0
answers
414
views
I want to replace the kernel inside twrp 12.1 recovery with my kernel that I built.
Now with only unpacking and repacking the recovery image I end up with an image of different size
The recovery image size is 128M
root@localhost:~/mkbootimg# ls -alth recovery.img
-rw-r--r--. 1 root root 128M Jul 15 12:40 recovery.img
The tool I'm using is google mkbootimg
mkbootimg -h
usage: unpack_bootimg.py [-h] --boot_img BOOT_IMG [--out OUT] [--format {info,mkbootimg}] [-0]
Unpacks boot, recovery or vendor_boot image.
options:
-h, --help show this help message and exit
--boot_img BOOT_IMG path to the boot, recovery or vendor_boot image
--out OUT output directory of the unpacked images
--format {info,mkbootimg}
text output format (default: info)
-0, --null output null-terminated argument strings
Output format:
* info
Pretty-printed info-rich text format suitable for human inspection.
* mkbootimg
Output shell-escaped (quoted) argument strings that can be used to
reconstruct the boot image. For example:
$ unpack_bootimg --boot_img vendor_boot.img --out out --format=mkbootimg |
tee mkbootimg_args
$ sh -c "mkbootimg $(cat mkbootimg_args) --vendor_boot repacked.img"
vendor_boot.img and repacked.img would be equivalent.
If the -0 option is specified, output unescaped null-terminated argument
strings that are suitable to be parsed by a shell script (xargs -0 format):
$ unpack_bootimg --boot_img vendor_boot.img --out out --format=mkbootimg \
-0 | tee mkbootimg_args
$ declare -a MKBOOTIMG_ARGS=()
$ while IFS= read -r -d '' ARG; do
MKBOOTIMG_ARGS+=("${ARG}")
done
Running the commands the tools suggests
root@localhost:~/mkbootimg# ./unpack_bootimg.py --boot_img recovery.img --out out --format=mkbootimg | tee mkbootimg_args
--header_version 2 --os_version 16.1.0 --os_patch_level 2127-12 --kernel out/kernel --ramdisk out/ramdisk --recovery_dtbo out/recovery_dtbo --dtb out/dtb --pagesize 0x00001000 --base 0x00000000 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --second_offset 0x00000000 --tags_offset 0x00000100 --dtb_offset 0x0000000001f00000 --board '' --cmdline 'console=ttyMSM0,115200n8 earlycon=msm_geni_serial,0xa90000 androidboot.hardware=qcom androidboot.console=ttyMSM0 androidboot.memcg=1 lpm_levels.sleep_disabled=1 video=vfb:640x400,bpp=32,memsize=3072000 msm_rtb.filter=0x237 service_locator.enable=1 androidboot.usbcontroller=a600000.dwc3 swiotlb=2048 cgroup.memory=nokmem,nosocket reboot=panic_warm buildvariant=eng'
root@localhost:~/mkbootimg# nano mkbootimg_args
root@localhost:~/mkbootimg# sh -c "./mkbootimg.py $(cat mkbootimg_args) -o repacked.img" root@localhost:~/mkbootimg# ls -alth repacked.img
-rw-r--r--. 1 root root 67M Jul 15 22:20 repacked.img
root@localhost:~/mkbootimg#
I had to modify mkbootimg_args and change --header_version
to 3 because the tool didn't like it
but you can see the repacked.img
is 67M where the original recovery.img
is 128M
Flashing the repacked image to recovery partition I end up with destroyed boot/recovery screen
Asked by amera
(21 rep)
Jul 15, 2023, 10:39 PM