close

 

 

Build Mkbootimg / Unmkbootimg

 

https://github.com/pbatard/bootimg-tools/tree/master/mkbootimg
 

# gcc mkbootimg.c -o mkbootimg
# gcc unmkbootimg.c -o unmkbootimg
# cp ./mkbootimg /usr/local/bin/
# cp ./unmkbootimg /usr/local/bin/

 

Structure of Recovery.img

 

+-----------------+ 
| boot header     | 1 page
+-----------------+
| kernel          | n pages  
+-----------------+
| ramdisk         | m pages  
+-----------------+
| second stage    | o pages
+-----------------+

n = (kernel_size + page_size - 1) / page_size
m = (ramdisk_size + page_size - 1) / page_size
o = (second_size + page_size - 1) / page_size

0. all entities are page_size aligned in flash
1. kernel and ramdisk are required (size != 0)
2. second is optional (second_size == 0 -> no second)

 

# cat /proc/mtd

 

rk_mtd.png


 

Unmkbootimg

 

# mkdir -p unpacked-recovery && rm -rf unpacked-recovery/* && cd unpacked-recovery

 

# unmkbootimg -i ../recovery.img 
kernel written to 'kernel' (4528360 bytes)
ramdisk written to 'ramdisk.cpio.gz' (4202750 bytes)

To rebuild this boot image, you can use the command:
  mkbootimg --base 0 --pagesize 16384 --kernel_offset 0x60408000 --ramdisk_offset 0x62000000 --second_offset 0x60f00000 --tags_offset 0x60088000 --kernel kernel --ramdisk ramdisk.cpio.gz -o ../recovery.img

 

The "unmkbootimg" command will split the image file into kernel and ramdisk parts. 
 

# ls -l
total 8532
-rw-r--r-- 1 root root 4528360 12月 14 14:22 kernel
-rw-r--r-- 1 root root 4202750 12月 14 14:22 ramdisk.cpio.gz

 

Decode Ramdisk

 

# mkdir -p ramdisk && rm -rf ramdisk/*
# cd ramdisk
# gunzip -c ../ramdisk.cpio.gz | cpio -i
12039 blocks

# ls
charger                           property_contexts
default.prop                      res
etc                               rk30xxnand_ko.ko.3.10.0
file_contexts                     sbin
fstab.rk30board.bootmode.emmc     seapp_contexts
fstab.rk30board.bootmode.unknown  sepolicy
init                              tmp
init.bootmode.emmc.rc             ueventd.rc
init.bootmode.unknown.rc          ueventd.rk30board.rc
init.rc

 

For now you can hack the ramdisk (initramfs) in the recovery.img . 


 

Compress the Files Back into Ramdisk

 

# find . | cpio -o -H newc | gzip > ../ramdisk.cpio.gz
12039 blocks
# rm -rf ramdisk

 

Mkbootimg

 

# cd unpacked-recovery
# mkbootimg --base 0 --pagesize 16384 --kernel_offset 0x60408000 --ramdisk_offset 0x62000000 --second_offset 0x60f00000 --tags_offset 0x60088000 --kernel kernel --ramdisk ramdisk.cpio.gz -o ../recovery.img

 

Flash Recovery.img

 

adb shell chmod 777 /mnt/asec/
adb push recovery.img /mnt/asec/recovery.img
adb shell dd if=/mnt/asec/recovery.img of=/dev/block/rknand_recovery
adb shell rm -rf /mnt/asec/recovery.img
adb reboot

 

參考資料: 
http://www.imajeenyus.com/computer/20130301_android_tablet/android/unpack_repack_recovery_image.html

 

z.png
Email: jasonc@mail2000.com.tw

 

 

 

arrow
arrow
    創作者介紹
    創作者 Lexra 的頭像
    Lexra

    Lexra Pixnet

    Lexra 發表在 痞客邦 留言(0) 人氣()