S5P4418与S5P6618的Android boot.img的解压与压缩, Sparse ext4文件系统

文件类型

4418的boot.img是由kenrel + uramdisk组成的ext4 并且是sparse形式的image, 这里面的sparse是紧凑的意思,即将ext4文件系统中的内容为zero的地方“压缩”起来, 从而减少size。

制作

这种类型的image,使用make_ext4fs, 并使用-s选项制作而成,例如在4418中(其他Android或者文件系统也是类似),命令如下:

  1. make_ext4fs -s -l 67108864 -a boot /home/XXX/g4418_linux/out/boot.img /home/hexiongjun/EmbProj/4418_Yu/g4418_linux/out/boot

其中-a为lable,最后的参数是制作到文件系统中的目录,因此,制作完成后,可以看到file工具识别到的是data 数据文件:

  1. file boot.img   
  2. boot.img: data  

转化

对此我们可以使用simg2img工具来转换成标准的ext4文件系统的文件:

  1. simg2img boot.img boot_ext4.img  

此时file工具即可识别:

  1. $ file boot_ext4.img  
  2. boot_ext4.img: Linux rev 1.0 ext4 filesystem data, UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (extents) (large files)  

也可以看到两者的size变化:

[plain] view plain copy print?

  1. $ ls -lh boot*  
  2. -rw-rw-r-- 1 hexiongjun hexiongjun 64M Jul 12 11:21 boot_ext4.img  
  3. -rwxr--r-- 1 hexiongjun hexiongjun 14M Jul 12 11:15 boot.img  

sparse型是14M,而其filesystem其实是64M。

boot.img的解压与压缩

我们可以直接mount并查看,以及更改内部的内容,就像disk中的partition with ext4 FS一样,例如下面是命令:

  1. $mkdir Test  
  2. $sudo mount boot_ext4.img Test  
  3. $ls Test/  
  4. battery.bmp  logo.bmp  lost+found  ramdisk-recovery.img  root.img.gz  uImage  update.bmp  

可以看到里面有uImage,以及root.img.gz,前者为kernel后者为uramdisk,同样也可以查看其类型:

  1. $ file Test/root.img.gz   
  2. Test/root.img.gz: gzip compressed data, from Unix, last modified: Mon Jul  4 17:32:32 2016  

如果我们需要更改uramdisk,那么可以按照如下方式进行:

  1. mkdir Temp_root  
  2. cp Test/root.img.gz Temp_root  
  3. gzip -d root.img.gz  

然后得到一个cpio文件:

[plain] view plain copy print?

  1. $file root.img   
  2. root.img: ASCII cpio archive (SVR4 with no CRC)  

使用cpio解压即可:

  1. $ cpio -i -F root.img   
  2. 2364 blocks  

可以看到内容如下,包含原来的root.img:

  1. $ ls   
  2. adj_lowmem.sh  default.prop   fstab.g4418      init.g4418.rc      init.recovery.g4418.rc  init.zygote32.rc   root.img        selinux_version   sys               ueventd.rc  
  3. charger        dev            init             init.g4418.usb.rc  init.trace.rc           proc               sbin            sepolicy          system  
  4. data           file_contexts  init.environ.rc  init.rc            init.usb.rc             property_contexts  seapp_contexts  service_contexts  ueventd.g4418.rc  

也可以再次压缩与制作uramdisk:

  1. find . | cpio -ov -H newc | gzip > ../root.img.gz  

然后拷贝到mount了的ext4文件系统中,然后再umount raw ext4,最后还需要转换成sparse image:

  1. mv boot.img boot_ori.img && img2simg boot_ext4.img boot.img  

猜你喜欢

转载自blog.csdn.net/hktkfly6/article/details/80752194
今日推荐