Error with repacking boot.img (Android)

2019-03-30 20:47发布

问题:

I have Nexus 5 with AOSP ROM 4.4.4.

I'm trying to "pull" boot.img from the device, unpack it, edit "init.rc", repack it to boot.img and flash it to the device.

I follow many guides but none of them have the same scenario as I have:

(http://droidcore.blogspot.co.il/2012/12/how-to-edit-initrc-in-android.html and http://www.digitalinternals.com/mobile/android-mmc-mmcblk-partition-layout/259/)

  1. The device partition is mmcblck so from ls -l /dev/block/platform/msm_sdcc.1/by-name/ I got that the boot is /dev/block/mmcblk0p19:

lrwxrwxrwx root root 1971-02-28 21:30 boot -> /dev/block/mmcblk0p19

  1. I created the boot.img with the command: cat /dev/block/mmcblk0p19 > /mnt/sdcard/boot.img and pull this boot.img to my pc. This boot.img is ~23 MB.

  2. I unmkbootimg the boot.img with the tool in http://droidcore.blogspot.co.il/2012/12/how-to-edit-initrc-in-android.html and got 2 files: initramfs.cpio.gz which is ~500 KB and kernel.gz which is ~8.4 MB. The details I got are:

Kernel size 8405280

Kernel address 0x8000

Ramdisk size 498992

Ramdisk address 0x2900000

Secondary size 0

Secondary address 0xf00000

Kernel tags address 0x2700000

Flash page size 2048

Board name is ""

Command line "console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1"

Extracting kernel.gz

... Extracting initramfs.cpio.gz ...

All done.


To recompile this image, use:

mkbooting --kernel kernel.gz --ramdisk initramfs.cpio.gz --base 0x26fff00 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' -o new_boot.img

  1. I unpack initramfs.cpio.gz with the command: gunzip -c initramfs.cpio.gz | sudo sh -c 'cd ../ && cpio -i' (from http://www.wiki.xilinx.com/Build+and+Modify+a+Rootfs) and got many files, init.rc among them. I edited this file.

  2. I repack initramfs.cpio.gz with the command: sh -c 'cd ../ && sudo find . | sudo cpio -H newc -o' | gzip -9 > new_initramfs.cpio.gz and got this file ~500KB.

  3. Now I mkbootimg those 2 files with the command: ./mkbooting --kernel kernel.gz --ramdisk initramfs.cpio.gz --base 0x26fff00 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' -o new_boot.img and I got boot.img which is ~8.5 MB

  4. Now flash the boot to the device and the device is stuck on the first screen (not boot up)

My questions are:

  1. What's wrong?

  2. Is that normal that my new boot.img is only 8.5 MB instead of 23 MB (the original)?

Thank you guys!

************* I FOUND THE PROBLEM *************

THE SOLUTION IS: I used unmkbootimg from here: http://whiteboard.ping.se/Android/Unmkbootimg After I run unmkbootimg I got this comment:

*** WARNING **** This image is built using NON-standard mkbootimg! OFF_KERNEL_ADDR is 0xFD908100 OFF_RAMDISK_ADDR is 0x00200100 OFF_SECOND_ADDR is 0xFE800100 Please modify mkbootimg.c using the above values to build your image.


so I follow the instructions here: https://gist.github.com/jberkel/1087757 and now it works!!!

回答1:

I can't give the answer to the first question, but if I were you I'd skip step 4&5 and verify whether the unmkbootimg/mkbootimg process is correct. Only after it's verified, I till tackle with the cpio process, and finally the init.rc editing.

For the second question, google's official boot.img is 8.64MB, so I guess there is nothing wrong with the size.



回答2:

Ubuntu's abootimg worked for me. I used the update (-u) option.