How to enable sparse image in android

Document created by Sanshan Zhang Employee on May 21, 2015Last modified by Sanshan Zhang Employee on Oct 5, 2015
Version 10Show Document
  • View in full screen mode

There are two format system image(ext4): raw and sparse. The raw image is  larger, you can mount it to ext4 directly(mount -t ext4 system.img system). The sparse image is supported lp5.0, it is a bit smaller. The below part will take IMX7D SDB board as example. You can change the setting according your platform hardware.


1 generate sparse image


In Lollipop 5.0 and 5.1, both raw image and sparse image will be generated by default.

sparse system image is located in: out/target/product/sabresd_7d/system_sparse.img

raw system image is located in:out/target/product/sabresd_7d/system.img

Below are the steps used in android build system to generate system.img

  • build out sparse image(-s means the building system image is sparse)

          make_ext4fs -s -T -1 -S out/target/product/sabresd_7d/root/file_contexts -l 374476800 -a system           out/target/product/sabresd_7d/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/sabresd_7d/system

  • transform sparse image to raw image

          simg2img out/target/product/sabresd_7d/system_sparse.img out/target/product/sabresd_7d/system.img


2 burn sparse image to sd/emmc

     There are two ways to program the sparse image into android boot storage

  • Transform the sparse image into raw image in host Linux PC. And use the commands dd commands to program the raw image into the boot storage.
  • Program the sparse image with MFG Tool in i.MX Android release package.


      • copy system_sparse.img to files/android/sabresd/.
      • copy simg2img binary (in to files/android/.
      • You also need update mfgtools-without-rootfs.tar\mfgtools\Profiles\Linux\OS Firmware\ucl2.xml


     diff --git a/Profiles/Linux/OS Firmware/ucl2.xml b/Profiles/Linux/OS Firmware/ucl2.xml
     index 3b15ddd..3c3d2ae 100755
     --- a/Profiles/Linux/OS Firmware/ucl2.xml
     +++ b/Profiles/Linux/OS Firmware/ucl2.xml

     @@ -621,8 +621,12 @@
             <CMD state="Updater" type="push" body="$ mkfs.ext4 /dev/mmcblk%mmc%p6">Formatting cache partition</CMD>

             <CMD state="Updater" type="push" body="$ mkfs.ext4 /dev/mmcblk%mmc%p7">Formatting device partition</CMD>
     -       <CMD state="Updater" type="push" body="pipe dd of=/dev/mmcblk%mmc%p5 bs=512" file="files/android/sabresd/system.img">Sending and writting system.img</CMD>
     +       <CMD state="Updater" type="push" body="send" file="files/android/simg2img" ifdev="MX7D">Sending simg2img</CMD>
     +       <CMD state="Updater" type="push" body="$ cp $FILE /tmp/simg2img ">cp simg2img</CMD>
     +       <CMD state="Updater" type="push" body="$ chmod  777 /tmp/simg2img ">chmod 777</CMD>
     +       <CMD state="Updater" type="push" body="$  mount -o remount,size=512M rootfs /">change size of tmpfs</CMD>
     +       <CMD state="Updater" type="push" body="send" file="files/android/sabresd/system_sparse.img" ifdev="MX7D">Sending system_sparse.img</CMD>
     +       <CMD state="Updater" type="push" body="$ /tmp/simg2img $FILE /dev/mmcblk%mmc%p5">Sending and writting system_sparse.img</CMD>
             <!-- Write userdata.img is optional, for some customer this is needed, but it's optional. -->
             <!-- Also, userdata.img will have android unit test, you can use this to do some auto test. -->
             <!--    <CMD state="Updater" type="push" onError="ignore" body="pipe dd of=/dev/mmcblk0p7" file="file/android/userdate.img"> Sending userdata.


3 Support sparse image in uboot(v2014.04)

     Cheery-pick sparse image related patches. Use write_sparse_image to burn sparse system image.

     For detail information, Please check the attached file(uboot(v2014.04)which support )


     The step of apply these patches:

  • cd myandroid/bootable/bootloader/uboot-imx/
  • copy uboot(v2014.04) which support to myandroid/bootable/bootloader/uboot-imx/

        unzip uboot(v2014.04) which support

  • git am 0001-add-header-for-Android-sparse-image-format.patch

        git am 0002-add-code-to-handle-Android-sparse-image-format.patch

        git am 0003-update-code-which-handles-Android-sparse-image-forma.patch

        git am 0004-cleanup-code-which-handles-the-Android-sparse-image-.patch

        git am 0005-implement-the-Android-sparse-image-format.patch

        git am 0006-aboot-fix-block-addressing-for-don-t-care-chunk-type.patch

        git am 0007-MA-6732-Add-sparse-image-flash-support-for-uboot-s-f.patch





The page will keep updating.



     How to enable userdata.img and cache.img in lollipop

1 person found this helpful