[Atrix 4G Android Development] sendust7:
Recently I became interested in dual booting my Atrix, mainly for the fun of it, and because I like the convenience of quickly reverting to a different ROM without having to restore it from backup. I would also like to evaluate the performance of my system with sdcard in the loop among other things.

From my web research, it appears that multiple attempts at dual booting the Atrix have been made without much success. I have heard of SafeStrap, but I'm the kind of person who wants to know what’s happening inside the black box. So I decided to try my hand by flashing CM9 to internal memory and CM7 to my Patriot 16GB Class 4 micro-SD card. I did all of this on Ubuntu 11.10 using GParted, Android SDK and several Perl and Bourne shell scripts that I either customized or created.

I probably could have done this on Windows (which for example has Atrix USB drivers whereas Ubuntu does not) and perhaps be able to use available space on my 10GB emmc to host additional ROMs. But in spite of the lack of drivers, I felt more comfortable having a full-up, dedicated *nix-based OS on hand to support the experiment.

I decided to to push a stable ROM to sdcard (in this case, CM7.2 RC1), one that runs well without any patches --- because a stock recovery tool wouldn't recognize it.

The experiment was successful as I now enjoy my 3GB CM7 build running from SD card with stable browser, keyboard and camera. And I can still use Joker's Kitchen Sink to explore some of the many possible ROM configurations without touching the CM7 build.

YouTube video (3:38) showing reboots from one ROM to the other: http://www.youtube.com/watch?v=31TPyAguQ60

Preliminaries (Ubuntu)

GParted and Perl installed

Android SDK for Linux (i386) installed http://developer.android.com/sdk/index.html

I download testsign.zip from http://xdaforums.com/showthread.php?t=551711 , copy to Ubuntu <android-sdk-linux/tools> directory and extract zip there. This creates a testsign subfolder with testsign.jar file inside.

Atrix Filesystem Analysis

I boot my phone to CWM 5.0.2.0, open an Ubuntu terminal, get root (sudo -s), run adb shell and invoke the “edify” and “df” commands to view the current filesystem:

~ # edify

recovery filesystem table

=========================

0 /tmp ramdisk (null) (null)

1 /boot emmc /dev/block/mmcblk0p11 (null)

2 /cache ext3 /dev/block/mmcblk0p15 (null)

3 /data ext3 /dev/block/mmcblk0p16 (null)

4 /sdcard vfat /dev/block/mmcblk1p1 (null)

5 /emmc vfat /dev/block/mmcblk0p18 (null)

6 /system ext3 /dev/block/mmcblk0p12 (null)

7 /recovery emmc /dev/block/mmcblk0p10 (null)

8 /osh ext3 /dev/block/mmcblk0p13 (null)

9 /preinstall ext3 /dev/block/mmcblk0p17 (null)

~ # df -a

Filesystem 1K-blocks Used Available Use% Mounted on

tmpfs 417804 32 417772 0% /dev

devpts 0 0 0 0% /dev/pts

proc 0 0 0 0% /proc

sysfs 0 0 0 0% /sys

/dev/block/mmcblk0p15 645056 69020 543268 11% /cache

/dev/block/mmcblk0p16 2064208 129052 1830300 7% /data

/dev/block/mmcblk0p12 322516 238496 84020 74% /system​

SD Card Partitioning

Next I get root on Ubuntu, connect SD card to PC, ensure SD card adapter switch is set to read/write, run GParted and shrink the vfat (fat32) partition to allow room for /system, /cache and /data in that order. Then I create these partitions as ext4 with sizes reasonably consistent with the existing filesystem on emmc.

Note: GParted did not see my internal (emmc) card, and it prefixed the sdcard partitions as “/dev/mmcblk0” instead of “/dev/mmcblk1”.

Now I exit GParted, pull sdcard from PC and reinsert into phone. Then I boot to CWM, connect phone to PC, enter adb shell and verify the new sdcard partition map using the onboard “parted” tool:

~ # parted /dev/block/mmcblk1

GNU Parted 1.8.8.1.179-aef3

Using /dev/block/mmcblk1

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) print

Model: SD SU16G (sd/mmc)

Disk /dev/block/mmcblk1: 15.9GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 4194kB 10.7GB 10.7GB primary fat32 lba

2 10.7GB 11.1GB 346MB primary ext4

3 11.1GB 11.8GB 692MB primary ext4

4 11.8GB 14.0GB 2217MB primary ext4

quit

~#​

Clone CM7 to SD Card

Presently I have CM7.2 RC1 installed in emmc, and I want to clone this ROM to sdcard. But I first ensure that my phone is adequately charged, especially if I will be in CWM for a long time. My experience is that CWM can drain the battery, even when phone is connected to a powered USB hub.

I boot to CWM 5.0.2.0, open Ubuntu terminal on PC, get root (sudo -s), run adb shell and mount the new CM7 sdcard partitions.

Then I clone ROM to sdcard. (I did this over ADB, though in retrospect I probably could have done it more quickly with terminal emulator.)

~ # dd if=/dev/block/mmcblk0p12 of=/dev/block/mmcblk1p2

655360+0 records in

655360+0 records out

335544320 bytes (320.0MB) copied, 140.786369 seconds, 2.3MB/s

~ # dd if=/dev/block/mmcblk0p15 of=/dev/block/mmcblk1p3

1310720+0 records in

1310720+0 records out

671088640 bytes (640.0MB) copied, 282.791984 seconds, 2.3MB/s

~ # dd if=/dev/block/mmcblk0p16 of=/dev/block/mmcblk1p4

4194304+0 records in

4194304+0 records out

2147483648 bytes (2.0GB) copied, 898.662170 seconds, 2.3MB/s​

Since the data partition is fairly large, I ending up using the “cat” command, which cut the transfer time to about 6 minutes….

~ # cat /dev/block/mmcblk0p16 > /dev/block/mmcblk1p4​

Flash CM9 to Internal Memory

Now I push Joker CM9 beta 0.6.0 zip to sdcard and install via CWM...

root@ubuntu:~/Desktop# adb push beta-0.6.0-cm-9.0.0-RC0-olympus-UNOFFICIAL-signed.zip /sdcard/Download

1286 KB/s (125162795 bytes in 95.013s)

root@ubuntu:~/Desktop#​

Modify CM7 Ramdisk, Re-pack ROM Zip and Re-sign

Now I modify ramdisk in the CM7 boot.img to mount the sdcard /system, /cache and /data partitions at boot time. To help streamline the mod, I wrote custom Perl scripts based on the ones linked here:

http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images

My Perl script “unpack-romzip.pl” actually starts with a baseline ROM, extracts boot.img and then p****s out kernel and ramdisk directory from boot.img. Here is the script in action...

root@ubuntu:~/Desktop# ./unpack-romzip.pl update-cm-7.2.0-RC1-olympus+gapps.zip

Extract boot.img from update-cm-7.2.0-RC1-olympus+gapps.zip

Archive: update-cm-7.2.0-RC1-olympus+gapps.zip

inflating: boot.img

Rename boot.img to update-cm-7.2.0-RC1-olympus+gapps.img

kernel written to update-cm-7.2.0-RC1-olympus+gapps.img-kernel

ramdisk written to update-cm-7.2.0-RC1-olympus+gapps.img-ramdisk.cpio.gz

Extract ramdisk zip to directory: update-cm-7.2.0-RC1-olympus+gapps.img-ramdisk

513 blocks

Delete intermediate file: update-cm-7.2.0-RC1-olympus+gapps.img-ramdisk.cpio.gz​

Results...

-rw-r--r-- 1 root root 2574336 2012-05-03 19:12 update-cm-7.2.0-RC1-olympus+gapps.img-kernel

drwxr-xr-x 8 root root 4096 2012-05-03 19:12 update-cm-7.2.0-RC1-olympus+gapps.img-ramdisk​

In this experiment, the only ramdisk file I will modify is init.olympus.rc: I do so by commenting out the /system, /cache and /data mount commands for the emmc partitions and creating equivalent mount commands for the sdcard partitions...

# mount ext4 /dev/block/mmcblk0p12 /system noatime nodiratime wait ro barrier=1

# mount ext4 /dev/block/mmcblk0p16 /data nosuid nodev noatime nodiratime wait barrier=1 noauto_da_alloc

# mount ext4 /dev/block/mmcblk0p15 /cache nosuid nodev noatime nodiratime wait barrier=1 noauto_da_alloc

mount ext4 /dev/block/mmcblk1p2 /system noatime nodiratime wait ro barrier=1

mount ext4 /dev/block/mmcblk1p4 /data nosuid nodev noatime nodiratime wait barrier=1 noauto_da_alloc

mount ext4 /dev/block/mmcblk1p3 /cache nosuid nodev noatime nodiratime wait barrier=1 noauto_da_alloc​

Now I back out of ramdisk and run my other Perl script: repack-romzip.pl, which combines ramdisk and kernel to obtain a new boot image and then generates a repacked ROM zip. Here is the script in action...

root@ubuntu:~/Desktop# ./repack-romzip.pl update-cm-7.2.0-RC1-olympus+gapps.zip

Repack Android boot image from kernel file and ramdisk directory and roll into new ROM zip

Run cpio and gzip on ramdisk directory

514 blocks

Make boot image from kernel file and ramdisk cpio zip

Updated boot.img...

-rw-r--r-- 1 root root 2725888 2012-05-03 19:20 update-cm-7.2.0-RC1-olympus+gapps-repack.img

Copy update-cm-7.2.0-RC1-olympus+gapps.zip to update-cm-7.2.0-RC1-olympus+gapps-repack.zip

Add updated boot.img to update-cm-7.2.0-RC1-olympus+gapps-repack.zip

updating: boot.img

zip warning: Local Entry CRC does not match CD: boot.img

(deflated 0%)​

I am almost ready to re-sign my CM7 ROM zip. But I first need to modify its updater-script to mount /system to /dev/block/mmcblk1p2 (sdcard) instead of /dev/block/mmcblk0p12 (emmc). So I edit the updater-script and change:

format("ext4", "EMMC", "/dev/block/mmcblk0p12");

mount("ext4", "EMMC", "/dev/block/mmcblk0p12", "/system");​

to

format("ext4", "EMMC", "/dev/block/mmcblk1p2");

mount("ext4", "EMMC", "/dev/block/mmcblk1p2", "/system");​

Now I invoke the java command below to re-sign the CM7 zip:

root@ubuntu:~/Desktop# java -classpath ~/android-sdk-linux/tools/testsign/testsign.jar testsign update-cm-7.2.0-RC1-olympus+gapps-repack.zip update-cm-7.2.0-RC1-olympus+gapps-repack-signed.zip

root@ubuntu:~/Desktop# ls -ld *.zip

-rw-rw-r-- 1 robert robert 125162795 2012-05-03 18:05 beta-0.6.0-cm-9.0.0-RC0-olympus-UNOFFICIAL-signed.zip

-rw-r--r-- 1 root root 105000424 2012-05-03 19:23 update-cm-7.2.0-RC1-olympus+gapps-repack-signed.zip

-rw-r--r-- 1 root root 104987732 2012-05-03 19:20 update-cm-7.2.0-RC1-olympus+gapps-repack.zip

-rw------- 1 robert robert 104999357 2012-05-01 20:10 update-cm-7.2.0-RC1-olympus+gapps.zip​

Then I transfer the re-signed zip to sdcard/Download, reboot to CWM and install.

Test Results

I do some preliminary testing by attempting to boot CM9 from Joker's CM9 1.0GHz v4 boot image file:

root@ubuntu:~/Desktop# fastboot boot cm9-1.0-atrixv4-boot.img

downloading 'boot.img'...

OKAY [ 0.204s]

booting...

OKAY [ 0.002s]

finished. total time: 0.206s​

Success. Now I try CM7...

root@ubuntu:~/Desktop# fastboot boot update-cm-7.2.0-RC1-olympus+gapps-repack.img

downloading 'boot.img'...

OKAY [ 0.182s]

booting...

OKAY [ 0.002s]

finished. total time: 0.185s​

And to my delight, CM7 boots :D

Finally I install Script Manager and push my custom boot-rom.sh to sdcard/Boot. This script offers four options: Current ROM (default), CM9, CM7 or CWM recovery. Rebooting to the other ROM is just a few keystrokes away, though I must configure Script Manager to run boot-rom.sh as superuser (press SU button on configuration screen).

Elapsed times…

Execution of boot-rom.sh on CM7 to CM9 welcome screen: 44 sec.

Execution of boot-rom.sh on CM9 to CM7 welcome screen: 45 sec.

Conclusions and Thoughts

My Atrix dual boot capability offers an efficient means to circumvent instabilities in CM9 by providing a stable CM7 ROM to run from my sdcard. Of course there are limitations here in that a stock recovery won't recognize my CM7 build. But I'm fine with that since I probably won't patch.

I think it would be kind of interesting to push identical ROMs on emmc and sdcard and compare performance. I heard from a fellow engineer that Class 16 cards are now available.

It would also be interesting to explore refinements like multiple-boot from emmc and various forms of automation.

This is a work in progress and I appreciate your constructive feedback. :)

YouTube video (3:38) showing reboots from one ROM to the other: http://www.youtube.com/watch?v=31TPyAguQ60

Credits

jokersax11 @ xda, ghost_og @ xda,

Photon Dev Team, Atrix Dev Team

Koush

Other credits embedded in this post