当前位置:   article > 正文

几种解包/打包启动镜像boot.img的方法(bootimg.exe,unpackbootimg, unmkbootimg,split_bootimg,obooting)

bootimg.exe

这几种方法都适用于android的boot.img解/打包

几个重要的打包时用到的参数:

  • base
  • cmdline
  • page_size
  • padding_size

一、bootimg.exe(推荐)

用法说明:

C:\tmp\mstar-bin-tool-master\unpacked\ee\ramdisk2>bootimg.exe -h
bootimg:
        Modified:cofface@gmail.com
supported arguments:
        --add-head
        --cml
        --cpio-list
        --czlib
        --dml
        --dzlib
        --remove-head
        --repack-565
        --repack-bootimg
        --repack-ramdisk
        --repack-rle
        --repack-zte-bin
        --rml
        --to-ext4
        --to-img
        --uml
        --unpack-565
        --unpack-bootimg
        --unpack-qsb
        --unpack-ramdisk
        --unpack-rle
        --unpack-updata
        --unpack-yafffs
        --unpack-yaffs
        --unpack-yaffs2
        --unpack-zte-bin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

解包:

命令: bootimg.exe --unpack-bootimg
将boot.img与bootimg.exe置于同一目录下
如果要解包recovery.img,则先将recovery.img更名为boot.img

C:\tmp\mstar-bin-tool-master\unpacked\ee\ramdisk2>bootimg.exe --unpack-bootimg
arguments: [bootimg file]
bootimg file: boot.img
output: kernel[.gz] ramdisk[.gz] second[.gz]
base: 0x10000000
ramdisk_addr: 0x11000000
second_addr: 0x10f00000
tags_addr: 0x10000100
page_size: 2048
name: "27"
cmdline: "product.version=PD1304BT_A_1.10.0"
padding_size=2048
arguments: [ramdisk file] [directory]
ramdisk file: ramdisk
directory: initrd
output: cpiolist.txt
Found mtk magic, skip header.
Found header name ROOTFS
compress: True
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

共生产了4个新的文件或文件夹:
bootinfo.txt, kernel, initrd, cpiolist.txt, ramdisk
其中initrd和cpiolist.txt是ramdisk解包/解压后得到的
(把initrd和cpiolist.txt先用cpio备份,然后gzip压缩得到ramdisk)
在这里插入图片描述
修改:
通常修改权限时修改default.prop 、init.rc即可
(ro.secure=0 ,ro.debuggable=1 )
我们在initrd目录下增加一个测试文件jwjtest.txt
在这里插入图片描述
修改cpiolist.txt:
在最后加入一行:file jwjtest.txt initrd/jwjtest.txt 0750
在这里插入图片描述
打包:
命令格式 bootimg --repack-bootimg base cmdline page_size padding_size
命令:
bootimg --repack-bootimg 0x10000000 “product.version=PD1304BT_A_1.10.0” 2048 2048

C:\tmp\mstar-bin-tool-master\unpacked\ee\ramdisk2>bootimg --repack-bootimg 0x10000000 "product.version=PD1304BT_A_1.10.0" 2048 2048
arguments: [cpiolist file]
cpiolist file: cpiolist.txt
output: ramdisk.cpio.gz
compress_level: 6
mtk mode
arguments: [base] [cmdline] [page_size] [padding_size]
kernel: kernel
ramdisk: ramdisk.cpio.gz
second:
dt_image:
base: 0x10000000
ramdisk_addr: 0x11000000
second_addr: 0x10f00000
tags_addr: 0x10000100
name: 27
cmdline: product.version=PD1304BT_A_1.10.0
page_size: 2048
padding_size: 2048
output: boot-new.img
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

结果:
在这里插入图片描述

二、unpackbootimg

先在github或gitee上下载源码,然后linux下编译(make)
用法说明 :

usage: unpackbootimg
	-i|--input boot.img
	[ -o|--output output_directory]
	[ -p|--pagesize <size-in-hexadecimal> ]
  • 1
  • 2
  • 3
  • 4

解包:
命令:…/unpackbootimg -i ./boot-andr.img

biren@ubuntu:~/Downloads/android-unpackbootimg/jwj$ ../unpackbootimg -i ./boot-andr.img 
BOARD_KERNEL_CMDLINE product.version=PD1304BT_A_1.10.0
BOARD_KERNEL_BASE 10000000
BOARD_NAME 27
BOARD_PAGE_SIZE 2048
BOARD_HASH_TYPE sha1
BOARD_KERNEL_OFFSET 00008000
BOARD_RAMDISK_OFFSET 01000000
BOARD_SECOND_OFFSET 00f00000
BOARD_TAGS_OFFSET 00000100
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

解包后的文件:

$ ls
boot-andr.img          boot-andr.img-kerneloff   boot-andr.img-tagsoff
boot-andr.img-base     boot-andr.img-pagesize    boot-andr.img-zImage
boot-andr.img-board    boot-andr.img-ramdisk.gz  
boot-andr.img-cmdline  boot-andr.img-ramdiskoff
boot-andr.img-hash     boot-andr.img-secondoff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

打包:
用mkbootimg,与下同。

三、unmkbootimg

先在github或gitee上下载源码,然后linux下编译(make)
用法说明:

Usage: ./bin/unmkbootimg [OPTIONS] <src>

Extracts the kernel, ramdisk, and second-stage bootloader from the
provided Android boot image, and outputs them to the same directory.
Furthermore, this also creates a remake script that recombines these
extracted images into newboot.img, by running mkbootimg with the
parameters extracted from the original image header of src.

OPTIONS:
	<src>: The source Android boot image file to extract from.
	-d <destDir>: Output extracted images here instead.
	-v: Verbose.
	-i: Print header information only, then exit.
	-r <remakeScript>: Save the remake script using this filename
		instead.
	-m <mkbootimgCmd>: Use this command in the remake script for
		mkbootimg instead.
	-n <newBootImgName>: Direct the remake script to output the
		remade boot image using this filename instead, rather than
		newboot.img.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

解包:
命令:unmkbootimg ./boot-andr.img

android-unmkbootimg-master/jwj$ ../bin/unmkbootimg ./boot-andr.img 
  • 1

注意:被解包的boot-andr.img前一定要有**./(点和斜杠)**
否则会出现如下错误 :

android-unmkbootimg-master/jwj$ ../bin/unmkbootimg boot-andr.img 
Error in changeDir(): Failed to create directory "". No such file or directory
  • 1
  • 2

解包后文件:

biren@ubuntu:~/Downloads/android-unmkbootimg-master/jwj$ ls -l
total 14436
-rwxrw-rw- 1 biren biren 6291456 Dec  3  2014 boot-andr.img
-rw-rw-r-- 1 biren biren 4113352 May 18 20:26 kernel.img
-rw-rw-r-- 1 biren biren  682322 May 18 20:26 ramdisk.img
-rwxr-x--- 1 biren biren     370 May 18 20:26 remkbootimg.sh
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

remkbootimg.sh内容:

#!/bin/sh
mkbootimg \
 --kernel "kernel.img" \
 --ramdisk "ramdisk.img" \
 --cmdline "product.version=PD1304BT_A_1.10.0"\
 --base 0 \
 --kernel_offset 0x10008000 \
 --ramdisk_offset 0x11000000 \
 --second_offset 0x10f00000 \
 --os_version "0.0.0" \
 --os_patch_level "2000-00-01" \
 --tags_offset 0x10000100 \
 --board "27" \
 --pagesize 0x800 \
 --output "newboot.img"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

其中的base地址与上面的不一样,据说不指定base好像也没问题。

四、解包split_bootimg.pl, 打包mkbootimg

解包:
命令:./split_bootimg.pl boot.img

$ ls
boot.img   mkbootfs  mkbootimg  split_bootimg.pl

$ ./split_bootimg.pl boot.img
Page size: 2048 (0x00000800)
Kernel size: 4113352 (0x003ec3c8)
Ramdisk size: 682322 (0x000a6952)
Second size: 0 (0x00000000)
Board name: 27
Command line: product.version=PD1304BT_A_1.10.0
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

多了2个文件:boot.img-kernel , boot.img-ramdisk.gz
打包:
mkbootimg用法说明 :

biren@ubuntu:~/downloads$ ./mkbootimg --help
usage: mkbootimg
       --kernel <filename>
       --ramdisk <filename>
       [ --second <2ndbootloader-filename> ]
       [ --cmdline <kernel-commandline> ]
       [ --board <boardname> ]
       [ --base <address> ]
       [ --pagesize <pagesize> ]
       [ --ramdisk_offset <address> ]
       [ --dt <filename> ]
       -o|--output <filename>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

命令:mkbootimg --kernel boot.img-kernel --ramdisk newramdisk.gz -o boot-new.img

$ ./mkbootimg --kernel boot.img-kernel --ramdisk boot.img-ramdisk.gz --cmdline "product.version=PD1304BT_A_1.10.0" --base 0x10000000 --pagesize 2048  -o boot-new.img
  • 1

五、abootimg(推荐)

先安装2个包:build-essential abootimg

$ sudo apt-get install build-essential abootimg
  • 1

用法说明:

$ abootimg -h
 abootimg - manipulate Android Boot Images.
 (c) 2010-2011 Gilles Grandou <gilles@grandou.net> 0.6

 abootimg [-h]
      print usage
 abootimg -i <bootimg>
      print boot image information
 abootimg -x <bootimg> [<bootimg.cfg> [<kernel> [<ramdisk> [<secondstage>]]]]
      extract objects from boot image:
      - config file (default name bootimg.cfg)
      - kernel image (default name zImage)
      - ramdisk image (default name initrd.img)
      - second stage image (default name stage2.img)
 abootimg -u <bootimg> [-c "param=value"] [-f <bootimg.cfg>] [-k <kernel>] [-r <ramdisk>] [-s <secondstage>]
      update a current boot image with objects given in command line
      - header informations given in arguments (several can be provided)
      - header informations given in config file
      - kernel image
      - ramdisk image
      - second stage image

      bootimg has to be valid Android Boot Image, or the update will abort.

 abootimg --create <bootimg> [-c "param=value"] [-f <bootimg.cfg>] -k <kernel> -r <ramdisk> [-s <secondstage>]
      create a new image from scratch.
      if the boot image file is a block device, sanity check will be performed to avoid overwriting a existing
      filesystem.

      argurments are the same than for -u.
      kernel and ramdisk are mandatory.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

查boot.img配置信息:

$ abootimg -i boot-andr.img 

Android Boot Image Info:
* file name = boot-andr.img 
* image size = 6291456 bytes (6.00 MB)
  page size  = 2048 bytes
* Boot Name = "27"
* kernel size       = 4113352 bytes (3.92 MB)
  ramdisk size      = 682322 bytes (0.65 MB)
* load addresses:
  kernel:       0x10008000
  ramdisk:      0x11000000
  tags:         0x10000100
* cmdline = product.version=PD1304BT_A_1.10.0
* id = 0xac3936a1 0xba4262b4 0x71b59f89 0xdee58c3a 0x2ce40488 0x00000000 0x00000000 0x00000000 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

当然这些信息在解包后的bootimg.cfg文件中也有
解包:
命令:abootimg -x boot-andr.img

$ abootimg -x boot-andr.img 
writing boot image config in bootimg.cfg
extracting kernel in zImage
extracting ramdisk in initrd.img
  • 1
  • 2
  • 3
  • 4

这里的zlmage是kernel
initrd.img是ramdisk
打包:
命令:abootimg --create …

$ abootimg --create newboot.img -f bootimg.cfg -k zImage -r initrd.img
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/796026
推荐阅读
相关标签
  

闽ICP备14008679号