mkbootimg icon indicating copy to clipboard operation
mkbootimg copied to clipboard

mkbootimg: Add the hability to use the files generated by unpackbootimg

Open osvcos opened this issue 2 years ago • 12 comments

Added the parameter --from-unpackbootimg-files in order to use the files generated by the tool instead of typing each parameter one by one

osvcos avatar Mar 23 '22 19:03 osvcos

Thanks! I had planned something similar using a directory as the input arg to read things from. Not sure when I'll have time to review this since I'm working full time and have a 2 month old baby at home I need to help out with, but I'll take a look when I can!

osm0sis avatar Apr 19 '22 05:04 osm0sis

I understand. Thank you for your time.

osvcos avatar Apr 19 '22 11:04 osvcos

hi @osvcos, I fetched your PR and when run unpack and repack.

➜ redmi_cactus git:(master) ✗ ./mkbootimg/unpackbootimg -i boot.img -o boot2
ANDROID! magic found at: 0
BOARD_KERNEL_CMDLINE bootopt=64S3,32S1,32S1 buildvariant=user
BOARD_KERNEL_BASE 0x40000000
BOARD_NAME
BOARD_PAGE_SIZE 2048
BOARD_HASH_TYPE sha1
BOARD_KERNEL_OFFSET 0x00008000
BOARD_RAMDISK_OFFSET 0x11b00000
BOARD_SECOND_OFFSET 0x00f00000
BOARD_TAGS_OFFSET 0x07880000
BOARD_OS_VERSION 9.0.0
BOARD_OS_PATCH_LEVEL 2020-08
BOARD_HEADER_VERSION 1
BOARD_HEADER_SIZE 1648
➜ redmi_cactus git:(master) ✗ ./mkbootimg/mkbootimg --from-unpackbootimg-files boot2/boot.img -o booty.img
error: could not load second 'boot2/boot.img-second'

There is no second stage in unpacked folder. Im doing with device readmi6a.

➜ redmi_cactus git:(master) ✗ tree boot2/
boot2/
├── boot.img-base
├── boot.img-board
├── boot.img-cmdline
├── boot.img-hashtype
├── boot.img-header_version
├── boot.img-kernel
├── boot.img-kernel_offset
├── boot.img-os_patch_level
├── boot.img-os_version
├── boot.img-pagesize
├── boot.img-ramdisk
├── boot.img-ramdisk_offset
├── boot.img-second_offset
└── boot.img-tags_offset

0 directories, 14 files

How to skip not exists file? Sorry to raise issue in here.

yetnelson avatar May 05 '22 10:05 yetnelson

Hi @yetnelson, thank you. I assumed that second stage should exists.

osvcos avatar May 05 '22 11:05 osvcos

Thanks @osvcos , It works now;)

I noticed the size of output file is smaller than original file.

➜ redmi_cactus git:(master) ✗ ls -l *.img
-rw-r--r--@ 1 Nelson  staff    67108864  5  5 09:16 boot.img
-rw-r--r--  1 Nelson  staff     9078784  5  5 20:08 booty.img

Im worry about to flash the new img. Could u give some suggest or help check it? The original img uploaded at Google Driver

yetnelson avatar May 05 '22 12:05 yetnelson

To test my changes I downloaded a patched image of your device, and the sizes are very similar. You don't have to flash it to your device, you could test it withfastboot boot <image> in fastboot mode.

osvcos avatar May 05 '22 13:05 osvcos

Pass test with fastboot boot <image>. Thanks the project and @osvcos really solved me.

yetnelson avatar May 05 '22 14:05 yetnelson

Hello. Great work guys. The binary is very easy to compile even for beginners like myself ;)

It works great on most boot.imgs that I've tested it with but unfortunately I ran into a problem with one particular Xiaomi device (Poco X3 NFC). I tried to unpack its boot.img and repack it using mkbootimg binary but sadly it throws this error when trying to repack everything.

error: unsupported page size 0

This is how I am calling the mkbootimg binary

mkbootimg --header_version 2 --os_version 10.0.0 --os_patch_level 2020-08 --kernel out/kernel --ramdisk out/ramdisk --dtb out/dtb --pagesize 0x00001000 --base 0x00000000 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --second_offset 0x00f00000 --tags_offset 0x00000100 --dtb_offset 0x0000000001f00000 --cmdline "$cmdline" -o test.img

Here is the stock boot.img in question: https://mega.nz/file/uMJkDZzY#uhI7W-9tvDC3wFVnznBp2iYUqrBfhPvT5vwLY7gevh4

I'm not expert but I have reasons to believe that 0x00001000 is actually equivalent to 2048 and not 0. Then why is mkbootimg complaining about a pagesize value of 0 ? Thanks for your assistance!

Kind regards

lebigmac1 avatar Mar 21 '23 18:03 lebigmac1

Hello @lebigmac1. The --pagesize parameters expects a base 10 number. You provided a hexadecimal number (base 16). The correct form would be: --pagesize 4096

osvcos avatar Mar 22 '23 12:03 osvcos

WORKS! Thank you very much!

@osvcos do you have any idea how to run the mkbootimg in a bash script? I always get error: unknown argument 'androidboot.hardware=qcom' on --cmdline parameter when trying to pipe all those arguments back into the mkbootimg binary dynamically... For some reason when I do that in a script mkbootimg doesn't properly understand the cmdline string but when I copy paste the same arguments into terminal and try it manually it works?!

I guess I am searching for something like this: https://github.com/xiaolu/mkbootimg_tools

Do you think that old bash script could still work with this latest mkbootimg binary? Or do you have something similar in your repository that I could try? Thanks!

I originally wanted to use AIK-mobile by the very talented Mr. Osm0sis to unpack and repack the boot.img dynamically on the fly but sadly I failed at installing it systemfully on my Android device :(

lebigmac1 avatar Mar 22 '23 18:03 lebigmac1

Nevermind I fixed it by coming up with my own RepackBoot program :D Thanks for your great work guys! @osm0sis @osvcos

More info here: (for some reason the credits don't show up in the program itself?! - need to update that...) https://github.com/lebigmac1/Universal-RepackBoot-for-Android-by-lebigmac

lebigmac1 avatar Apr 05 '23 02:04 lebigmac1

unpackbootimg

darker16 avatar Sep 24 '23 21:09 darker16