Creating a Livesuit image for my tablet

It's time to bring everything together, at last! We're going to create (well, modify) a complete Livesuit image which will recreate the partitions, contents, and configuration of my tablet.

Here is a list of the modifications we'll make:

Note that all partition sizes are for my particular configuration - yours will probably be different.

Note: in several cases, I have chosen to use a hex editor to reduce the size of partition files by removing excess padding bytes. The same effect could probably be achieved by unpacking and repacking the actual image file, but this just involves more work. Direct editing with the hex editor seems to work fine. In each case, I have done a byte comparison of the resulting partition created on the tablet and it is identical to that from the original good tablet.

Step 1: Getting the partitions from the good tablet

I actually have another tablet, which has never been used, and is identical to "Mum's tablet". I'll use it to get the good partitions. First, I boot it up and do a factory reset to wipe any extraneous stuff.

Next, connect the tablet to a PC and insert an SD card (in the tablet, duh). We will do a dump of the partitions nanda to nande (bootloader, environment, boot, system, data). These are the only ones which are relevant to creating a Livesuit image. For each partition, we do

adb shell "cat /dev/block/nanda > /mnt/extsd/nanda.img"

Step 2: Unpack stock image

Using the unimg tool, unpack the stock Livesuit image.

Step 3: Modify the partition sizes

From a previous comparison of the partition sizes (see here), the sizes of the nandd (system) and nandi (emmc/databk) partitions need to be changed to match those on the good tablet. To find these, do a cat /proc/partitions on the good tablet.

Open the COMMON_SYS_CONFIG000000 file in a text editor. Scroll down to find the section:

;------------------------------>nandd, android real rootfs 
[partition3]
    class_name  = DISK
    name        = system
    size_hi     = 0
    size_lo     = 393216
    user_type   = 0
    ro          = 0

Change 393216 to 524288 (this is the size, in blocks of 1024 bytes, of the final partition). Next, scroll down to

;------------------------------>nandi, data image backup
[partition8]
    class_name  = DISK
    name        = databk
    size_hi     = 0
    size_lo     =262144
    user_type   = 0
    ro          = 0

and change 262144 to 131072. What we added to the system partition was removed from the nandi partition. Save changes to the file.

Step 4: Prepare RFSFAT16_BOOTLOADER_00000 and COMMON_SYS_CONFIG100000

The nanda.img image file (in my case) only contains relevant data up to offset 0x5523FF - the rest is padded with 0xFF bytes. To save a bit on space, copy the first 0x552400 bytes from nanda.img to a new file and call it RFSFAT16_BOOTLOADER_00000. In my case, this reduces the size from 16MB to around 5MB. Overwrite the original RFSFAT16_BOOTLOADER_00000 with the new one.

Copy the image file over to the Ubuntu machine and mount it. Copy the script.bin file to the Desktop and then use bin2fex to convert it:

sunxi-tools-master/bin2fex script.bin script.fex

Copy the script.fex back to the Windows machine. Delete the original COMMON _SYS_CONFIG100000 and rename script.fex to COMMON _SYS_CONFIG100000 in its place (note the two spaces between COMMON and _SYS).

Step 5: Prepare RFSFAT16_ENVIROMENT_00000

RFSFAT16_ENVIROMENT_00000 is only 256 blocks in size, but nandb.img is 16384. The remainder of nandb.img is padded with 0xFF.

Open nandb.img in a hex editor and copy the bytes up to offset 0x3FFFF from nandb.img over to RFSFAT16_ENVIROMENT_00000.

Step 6: Prepare RFSFAT16_BOOT_00000000000

Again, let's save some space here by trimming off the needless data. Looking at nandc.img, there is only valid data up to offset 0x981799. Copy the first 0x981800 bytes to a new file and overwrite RFSFAT16_BOOT_00000000000 with it.

Step 7: Prepare RFSFAT16_SYSTEM_000000000

To do this, we'll mount nandd.img then use mkuserimg to create a sparse ext4 image (as described here). Summary of commands:

mkdir nandd
sudo mount -o loop -t ext4 nandd.img system
cd ext4_utils
sudo ./mkuserimg.sh -s ../system ../RFSFAT16_SYSTEM_000000000 ext4 ../tmp 536870912

Then, copy the new RFSFAT16_SYSTEM_000000000 file back to the PC and overwrite the corresponding file in the Livesuit files.

Step 8: Prepare RFSFAT16_DATA_00000000000

Exactly the same procedure as for the system partition - copy to Ubuntu, mount, create sparse image, copy back to PC and overwrite.

Step 8: Prepare RFSFAT16_RECOVERY_0000000

We want to use CWM recovery instead of stock recovery. Copy the recovery.img file from Uberizer's "changer_files" folder and rename it to RFSFAT16_RECOVERY_0000000, overwriting the old file.

Step 9: Modify the repack_ics.bat script

The default repack script looks like this:

@echo off

set IMG=%1

FileAddSum "image.img.dump\RFSFAT16_BOOT_00000000000" "image.img.dump\RFSFAT16_VBOOT_0000000000"
FileAddSum "image.img.dump\RFSFAT16_BOOTLOADER_00000" "image.img.dump\RFSFAT16_VBOOTLOADER_0000"
FileAddSum "image.img.dump\RFSFAT16_ENVIROMENT_00000" "image.img.dump\RFSFAT16_VENVIROMENT_0000"
FileAddSum "image.img.dump\RFSFAT16_RECOVERY_0000000" "image.img.dump\RFSFAT16_VRECOVERYFS_0000"
FileAddSum "image.img.dump\RFSFAT16_SYSTEM_000000000" "image.img.dump\RFSFAT16_VSYSTEMFS_000000"

unimg -e image.img
ren image.img %IMG%

if exist image.img.dump rd /q /s image.img.dump

Remember, the FileAddSum lines recaculate the checksum for the particular file. Since we also changed the data partition, we need to add an extra line for this. In addition, the last line of the batch file deletes all of the Livesuit files once the image has been repacked! This would destroy all our hard work, so we'll comment out that line. The new batch file now reads:

@echo off

set IMG=%1

FileAddSum "image.img.dump\RFSFAT16_BOOT_00000000000" "image.img.dump\RFSFAT16_VBOOT_0000000000"
FileAddSum "image.img.dump\RFSFAT16_BOOTLOADER_00000" "image.img.dump\RFSFAT16_VBOOTLOADER_0000"
FileAddSum "image.img.dump\RFSFAT16_ENVIROMENT_00000" "image.img.dump\RFSFAT16_VENVIROMENT_0000"
FileAddSum "image.img.dump\RFSFAT16_RECOVERY_0000000" "image.img.dump\RFSFAT16_VRECOVERYFS_0000"
FileAddSum "image.img.dump\RFSFAT16_SYSTEM_000000000" "image.img.dump\RFSFAT16_VSYSTEMFS_000000"
FileAddSum "image.img.dump\RFSFAT16_DATA_00000000000" "image.img.dump\RFSFAT16_VDATA_0000000000"

unimg -e image.img
ren image.img %IMG%

REM if exist image.img.dump rd /q /s image.img.dump

Step 10: "Do I feel lucky?" Well do ya, punk?

You should now be able to repack the Livesuit image! Do:

repack_ics.bat new_image.img

This should create a new Livesuit image, which can then be flashed to the tablet in the usual manner.

Back to index