inux下 解包/打包 Android 映像文件 system.img, boot.img, ramdisk.img, userdata.img.

Android eMMC Booting

Contents

  [hide]

[edit]eMMC binaries

This is the efi partition table as exists on the emmc

Sector#    Size Name
    256     128K xloader
    512     256K bootloader
   2048       8M recovery                                                      
  18432       8M boot                                                          
  34816     512M system                                                        
1083392     256M cache                                                         
1607680     512M userdata                                                      
2656256    2183M media

[edit]Creating the GPT table

On Target
  1. Connect a USB cable to the OTG port on your platform
  2. Boot your platform up with a stock u-boot and MLO
  3. Once you platform is booted you will see the following:
Fastboot entered...
On Host Machine

locate fastboot in you android filesystem

cd $mydroid/out/host/linux-x86/bin/fastboot

Search for fastboot devices

fastboot devices

Create GPT table on eMMC/SD card

fastboot oem format

From the android build these are the binaries that go into each partition:

 Sector#    Size Name            Binary
    256     128K xloader         MLO
    512     256K bootloader      u-boot.bin
   2048       8M recovery        recovery.img                                                    
  18432       8M boot            boot.img                                  
  34816     512M system          system.img                                      
1083392     256M cache           cache.img                                    
1607680     512M userdata        userdata.img                                     
2656256    2183M media           none


File locations
  • MLO --> x-loader/MLO
  • u-boot --> u-boot/u-boot.bin
  • boot.img --> need to create using zImage + ramdisk.img
  • recovery.img ---> need to create using zImage + ramdisk-recovery.img
  • system.img --> $mydroid/out/target/product/<platform>/system.img
  • cache.img -->
  • userdata.img --> $mydroid/out/target/product/<platform>/userdata.img


All these partitions can be flashed with the given binary using fastboot.

 fastboot flash <name> <binary>

Example flashing of all partitions

 fastboot flash xloader     MLO
 fastboot flash bootloader  u-boot.bin
 fastboot flash recovery    recovery.img
 fastboot flash boot        boot.img
 fastboot flash system      system.img
 fastboot flash cache       cache.img
 fastboot flash userdata    userdata.img

[edit]Modifying .IMG Files

Typically when you want to modify any of the partitions, you would need to unzip-modify-rezip and then fastboot flash.

Following section talks about how to do that for each partition

BOOT.IMG

 boot.img = zImage + ramdisk.img
 zImage = kernel image
 ramdisk.img = out/target/product/blaze/root/
 %./out/host/linux-x86/bin/mkbootimg 
 --kernel zImage 
 --ramdisk ramdisk.img 
 --base 0x80000000 
 --cmdline "console=ttyO2,115200n8 mem=456M@0x80000000 mem=512M@0xA0000000 init=/init vram=10M omapfb.vram=0:4M androidboot.console=ttyO2" 
 --board omap4 
 -o boot.img.new
 Output: boot.img.new
 **Note: bootarg is passed to kernel via --cmdline option above
 **Note:For Pandaboard ES,--cmdline should be mmodified as "console=ttyO2,115200n8 mem=456M@0x80000000 mem=512M@0xA0000000 init=/init vram=32M omapfb.vram=0:16M androidboot.console=ttyO2"

To "just" boot boot.img (before flashing) you can use:

%fastboot boot boot.img

RAMDISK.IMG

 %mkdir root
 %cd root
 %gunzip -c ../ramdisk.img | cpio -i
 <make changes to root/ contents...>
 %./out/host/linux-x86/bin/mkbootfs root/ | ./out/host/linux-x86/bin/minigzip >ramdisk.img.new
 #output: ramdisk.img.new
 ** Note: any init.rc changes will need to use this method

RECOVERY.IMG

Is just like boot.img. 
recovery.img = zImage + ramdisk-recovery.img
*Follow the same steps as boot.img for packing/unpacking

SYSTEM.IMG

 #uncompress
 %./out/host/linux-x86/bin/simg2img system.img system.img.raw
 #mount to directory mnt-point/
 %mkdir mnt-point
 %sudo mount -t ext4 -o loop system.img.raw mnt-point/
 #modify any .so or apk in the mnt-point/ directory
 #rezip
 %sudo out/host/linux-x86/bin/make_ext4fs -s -l 512M -a system system.img.new mnt-point/
 %sudo umount mnt-point/
 Output: system.img.new

Instead of having to reflash the whole big system.img, one can selective update any binary in /system folder on running target

%adb remount
%adb push <local> <remote>
Eg: 
%adb remount
%adb push out/target/product/blaze/obj/lib/overlay.omap4.so /system/lib/hw/overlay.omap4.so
%adb sync

USERDATA.IMG

 #uncompress
 %./out/host/linux-x86/bin/simg2img userdata.img userdata.img.raw
 #mount to directory mnt-point/
 %mkdir mnt-point
 %sudo mount -t ext4 -o loop userdata.img.raw mnt-point/
 #modify any .so or apk in the mnt-point/ directory
 #rezip
 #%sudo ./out/host/linux-x86/bin/make_ext4fs -s -l 512M -a userdata userdata.img.new mnt-point/
 # Above command won't work on GB/HC. For GB/HC, please use the following updated command
 %sudo ./out/host/linux-x86/bin/make_ext4fs -s -l 512M -a data userdata.img.new mnt-point/
 %sudo umount mnt-point/
 Output: userdata.img.new

CACHE.IMG

 #This is empty ext4 fs image
 %mkdir mnt-point/
 %sudo ./make_ext4fs -s -l 256M -a cache cache.img mnt-point/
 Output: cache.img

[edit]TI Android build setup

Copy kernel zImage, u-boot.bin and MLO for your board in folder device/ti/blaze/boot/.

Rename as:

 %mv MLO MLO_es2.2_emu 
 or 
 %mv MLO MLO_es2.2_gp 
 (based on your board being GP or EMU)

Next start standard android build and all img files are generated in:

out/target/product/blaze/*.img

A script is introduced in TI Android release to make this flashing process easier: device/ti/blaze/boot/fastboot.sh

Usage:
cd device/ti/blaze/boot/
%fastboot.sh --emu
or
%fastboot.sh --gp

Running this script will flash whole android system on your board.

http://omappedia.org/wiki/Android_eMMC_Booting#Modifying_.IMG_Files



inux下 解包/打包 Android 映像文件 system.img, boot.img, ramdisk.img, userdata.img.

Linux下 解包/打包 Android 映像文件 system.img, boot.img, ramdisk.img, userdata.img.

2014年10月20日 ⁄ 计算机视觉 ⁄ 共 1372字⁄ ⁄ 暂无评论

转自: http://blog.csdn.net/yulix/article/details/12968705

Android源码编译成功后会输出映像文件:system.img,boot.img, ramdisk.img,userdata.img等等。有时我们需要修改里面的内容,下面列出在Linux下如何解包/打包这些映像文件。

ramdisk.img

ramdisk.img是经cpio打包、并用gzip压缩的文件。

解包: 新建一个工作目录,把当前目录更改为该工作目录,执行下面命令(注意: img文件位置可能不同).

[plain] view plaincopy

  1. gunzip -c  $HOME/img/ramdisk.img | cpio -i

打包:在工作目录下,把该目录下的所有内容打包

[plain] view plaincopy

  1. find . | cpio -o -H newc | gzip > ../newramdisk.img

参考文档:  http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

boot.img

boot.img包含2K字节头部,后面跟着的是zImage格式内核和和ramdisk格式的根文件系统。

解包工具: Android自带的unpackbootimg,以及一些脚本工具比如split_bootimg.pl

打包工具: Android自带的mkbootimg。

参考资料 :

中文请看: http://blog.csdn.net/wh_19910525/article/details/8200372

  英文请看:  http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images
system.img (EXT4)

system.img 是 sparse image格式文件,现有的mount命令无法直接处理。

我们得把sparse image格式转变为普通的img格式,Android源码中带的ext4_utils可以做这个,没有Android源码也不用担心,该工具的源代码已被剥离出来,可以自行下载编译,地址是:http://forum.xda-developers.com/showthread.php?t=1081239

我们得到工具有: simg2img,make_ext4fs等等:

解包:

[plain] view plaincopy

  1. simg2img system.img system.img.ext4
  2. mkdir mnt_dir
  3. sudo mount -t ext4 -o loop system.img.ext4 mnt_dir

打包:

[plain] view plaincopy

  1. sudo make_ext4fs -s -l 512M -a system system_new.img mnt_dir

注意:在我的机器上必须用root权限执行make_ext4fs,否则新生成的image文件无法使用。

userdata.img (EXT4)

和system.img(EXT4) 一样处理

 

 

( file_context_open: Error getting file context handle (No such file or directory) 
No such file or directory )

参考下面链接:

http://forum.xda-developers.com/galaxy-s2/general/ref-unpacking-repacking-stock-rom-img-t1081239/page23

the problem is that this version requires a file_contexts file. This can be extracted from boot.img. The filename is file_contexts 
1. extract boot.img (i used AndroidImageKitchen for this) 
2. call make_ext4fs with -S parameter 
i.e.

Code:

make_ext4fs -l -s 2690M -a system -S <PATH_TO_FILE_CONTEXTS_FILE> system.img.ext4 <WHEREEVER_YOU_MOUNTED_SYSTEM_TO>

btw: the name of the mountpoint doesnt matter. So calling your mountpoint sys was no problem

If you have extracted boot.img the file_contexts-file should be located in the ramdisk folder. 
Don't panic if there is no such file. In this case you just have to use an earlier version of make_ext4fs.

The file_contexts file is used by versions of android which use SELinux. I only found this on android versions >= 4.3.

 

 

所以最终的命令是:

./make_ext4fs -s -l 550M -a system -S ./file_contexts system_new.img mnt_dir

 

make_ext4fs [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ] 
    [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ] 
    [ -L <label> ] [ -f ] [ -a <android mountpoint> ] 
    [ -S file_contexts ] 
    [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] 
    <filename> [<directory>]

 

参数解析

#make_ext4fs -s -l 512M -a root -L linux  ./rootfs_qt.img  ./root

执行之后即会将root文件打包成  rootfs_qt.img 文件系统镜像。

-l 512M"是分区大小,i9100的system分区是512M; 
-s就是生成ext4的S模式制作;

-s  就是生成ext4的S模式制作;

-l 512M 是分区大小;

-a root 是指这个img用于Linux系统若为-a system即表示为android系统,挂载点即是/system。使用这个参数,make_ext4fs会根据private/android_filesystem_config.h里定义好的权限来给文件夹里的所有文件重新设置权限,如果你刷机以后发现有文件权限不对,可以手工修改android_filesystem_config.h来添加权限,重新编译make_ext4fs,也可以不使用 “-a system”参数,这样就会使用文件的默认权限

./rootfs_qt.img 表示在当前目录下生成镜像文件。

./root 指定源路径


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值