〖Linux〗联想K860/i Android 4.2及以上的Bootimg解压与打包工具

因为自己有需要,所以花了一点时间来写了一下。

1. 解压工具

#!/bin/bash - 
#===============================================================================
#
#          FILE: unpackszbboot
# 
#         USAGE: ./unpackszbboot 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: linkscue (scue), linkscue@gmail.com
#  ORGANIZATION: 
#       CREATED: 2014年02月01日 00时58分49秒 CST
#      REVISION:  ---
#===============================================================================

usage(){
    echo "Usage: ${0} bootimg extdir"
}

if [[ $# -lt 1 ]]; then
    usage && exit
fi

# 镜像文件位置
bootimg_org=$(readlink -f ${1})
[[ ! -e ${bootimg_org} ]] && exit

# 设置输出目录
extdir=$(dirname ${bootimg_org})/boot_extdir
[[ ${2} != "" ]] && extdir=${2}
echo ">> Will unpack to ${extdir}"

# 清除旧目录,创建新目录
rm -rf ${extdir} 2>/dev/null
mkdir -p ${extdir}
cd ${extdir}

# 解压bootimg和ramdisk
bootimg --unpack-bootimg ${bootimg_org}
dd if=ramdisk of=ramdisk.gz bs=64 skip=1
mkdir root && cd root
gunzip -c ../ramdisk.gz | cpio -i 
cd ../

2. 打包工具

#!/bin/bash - 
#===============================================================================
#
#          FILE: repackszbboot
# 
#         USAGE: ./repackszbboot 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: linkscue (scue), linkscue@gmail.com
#  ORGANIZATION: 
#       CREATED: 2014年02月01日 02时16分11秒 CST
#      REVISION:  ---
#===============================================================================

# 设置目录
boot_dir=${PWD}
[[ ${1} != "" ]] && boot_dir=$(readlink -f ${1})
root_dir=${boot_dir}/root
kernel_file=${boot_dir}/kernel
ramdisk_cpio=ramdisk.img.cpio
ramdisk_gz=ramdisk.img.cpio.gz
boot_output=boot.img.new

# 工具位置
mkbootfs=/media/Source/cm10.1/out/host/linux-x86/bin/mkbootfs
minigzip=/media/Source/cm10.1/out/host/linux-x86/bin/minigzip

[[ ! -e ${boot_dir} ]] && exit

# 打包
cd ${boot_dir}
${mkbootfs} ${root_dir} | ${minigzip} > ${ramdisk_cpio}

mkimage -A arm -O linux -T ramdisk -C none -a 0x40800000 -e 0x40800000 \
    -n "ramdisk" -d ${ramdisk_cpio} ${ramdisk_gz}
mkbootimg --kernel ${kernel_file} --ramdisk ${ramdisk_gz} \
    --base 0x10000000 --cmdline "" --pagesize 2048 -o ${boot_output}

# 显示结果
ls -l ${boot_output}

 

posted @ 2014-02-01 02:44  scue  阅读(903)  评论(0编辑  收藏  举报