[HD2 Android NAND Development] ph03n!x:
Misc & Changelog

Credits

All the Devs who are contributing their valuable time to get Android working on our phones

Proz0r for implementing something very similar to what I had wanted. He has essentially implemented the same thing, I am implementing this in a slightly different way, that's all. (To be clear, I did not borrow the idea even though a few others have had the same brainwave that I thought I got first :D - I only borrowed the part where we have the phone wait until the sd-ext partition is ready for being mounted)

Rick_1995 for the first hint to get this modification to work

Securecrt for showing that this modification is indeed possible

Xylograph for pointing me to another thread where this modification is already done

marco.palumbi - for showing me that I need not have an elaborate script to ensure /dev/block/mmcblk0p2 is available, and a mount... wait option is available in the CM source for init. Also for doing away with the need for extprep script and including the e2fsck routine complete with a fsck.log in init.rc itself.

kokotas - For the recovery-flashable version of this mod that simplifies migrating to DataOnEXT

Some of the benefits of this mod are:

Space - Obvisiouly. The 1GB/ 2GB/ 4GB sd-ext partition will be mounted as internal memory, instead of the usual /data partition from NAND

Reliability - EXT4 partition is arguably more reliable than YAFFS2

Working around Bad Blocks - Most of our phones would be having a bunch of bad blocks by now (lucky you, Hynix NAND folks!). With this method, the /data partition is mounted directly to the EXT partition in your SD Card, and the internal userdata NAND partition is untouched. This means you can create bigger system partitions to work your way around bad blocks. Incidently all the bad blocks my phone has is in the userdata partition - this might be so because that is the area that is written to the most.

Performance - A fast SD Card gives better transfer speeds than NAND (My ParanoidAndroid build is noticeably faster after this modification, with my Class 6 Transcend SD Card with 4GB sd-ext partition)

Simplicity - Don't have to worry about hoards of the a2sd scripts and their variants, and carry-out trial and error as to which ones work reliably with your ROM of choice. /data is transparently and natively mounted to sd-ext, so no more low-sound or other odd issues

/data/data can be in the sd-ext partition, and ROM updates will not corrupt it like in some a2sd scripts

Hassle-free - Whether an EU HD2 or TMoUS HD2, you set a large size (445 MB?!!) for /system and forget about partitioning, as the internal userdata partition is not used at all and can be of whatever size. I am using 300 MB system in both my phones. This is close to native Android phones, where we do not keep changing the system partition size for every ROM that is installed.

A proper multi-user setup - if you had to share the phone with someone else, all you have to do is swap out the SD Card you usually have in the phone to a fresh one that has the required FAT and EXT partitions. The other user will see a fresh Android install and configure whatever they want. When you get the phone back, all you have to do is put your usual SD Card back in, and voila! you have all your stuff just the way it was :D (Thanks to @teemoo for the tip!)

Trying a new ROM? Make sure you do not botch up your data! Just remove the SD Card you usually use and place one for testing. You can always mod the initrd.gz of your new ROM, flash the boot image or place the initrd,gz in /boot and replace your usual SD Card when you want all your apps, data and settings!

A Note on Cache

As many may remember (and some have pointed out), I had the initial trial with 8 MB of cache for SD Card interface. Over a period of time, I tried various sizes from 512 KB to 16 MB and found out that the cache size is dependant on the phone AND the SD Card that is in it. This experiment involves:

Setting a cache size in the extprep script

Booting from the boot.img using fastboot boot command

Waiting for my phone to connect to Google servers

Opening Root Explorer and confirming the cache size

Running SD Tools, testing the SD Card Read/ Write speeds thrice in a row

Changing the cache size in extprep script, recreating a boot,img, and starting from fastboot boot...

And here are my test results:

As you can see, the higher the cache, higher the difference between the Minimum and Maximum values for Reads. While this test does not consider ALL aspects (like random reads), this gives a good idea of what is the cache size that is the best for my phone and my SD Card. Note that I have two HD2 with 2 different brand/ class of SD Cards, and bot gave pretty different results. You may have to find the right cache size for your phone! Once you got the right cache, even a Class 2 card (the stock Sandisk 16 GB Class 2 that comes with the TMoUS HD2) performa pretty well - no deal-breaking lags even in games like Temple Run or Ninjump.

Also, you should be worried more about read speeds - that is what the phone does most of the time. Write speeds comes into picture mostly when you are installing something. All writes that happen after that are mostly incremental, and never something a major as what happens when you install an app.

Note to ROM Makers on ClockWorkMod Updater Script

While one of the benefits of this mod is that you can set a huge /system partition and forget trimming down anything, some ROMs mounts /data during CWM install to copy certain apps or parts of /system to the /data partition. For such a setup to work well with this mod, the /data partition should be mounted to the EXT partition in the SD Card. I am not sure if there is a straightforward mount command that can be used in updater-script to mount an MMC partition. Thanks to Looki75's post, I have made the script simpler...

The code in updater-script...

package_extract_dir("work", "/tmp");
format("MTD", "system");
format("MTD", "boot");
mount("MTD", "system", "/system");
mount("ext4","/dev/block/mmcblk0p2","/data");
ui_print("Copying files to /system");
package_extract_dir("system", "/system");
...
...
ui_print("Copying files to /data");
package_extract_dir("data", "/data");

FAQ

I will try and compile some sensible Questions from this thread in the FAQ Section. I request all to read the first three posts at least before asking any questions.

Q: I have an EXT2/ EXT3 partition. You are mounting it as EXT4. What gives?

A: Mounting as EXT4 is backwards compatible with EXT2/3 :)

Q: Where are the initrd.gz that you had posted earlier?

A: I have moved them to this post

Q: Will you modify the initrd.gz from the <name of ROM>?

A: I took more than 6 Hours on a Sunday Night to re-do the first three posts, and give a step-by-step guide. Do you still want me to modify the initrd.gz for you?!! I might post the initrd.gz of ROMs I use or try from time to time, but please don't post requests for modding <name of your ROM>'s initrd.gz. What is that saying about giving a man a fish vs. teaching how to fish...??!

Q: Is ClockWorkMod or 4EXT or TWRP compatible with this mod?

A: Before I answer, note that almost all Recovery tools available for HD2 will mount the SD Card's EXT partition to the sd-ext directory. After doing this mod, /data (in Android) = /sd-ext (in Recovery)

Any backup that includes the sd-ext partition will backup your /data.

At least CWM based recovery will delete dalvik-cache from NAND's data and /sd-ext. After this mod, /data/dalvik-cache (Android) = sd-ext/dalvik-cache (Recovery), so yes deleting Dalvik Cache works

CWN Recovery's Fix Permissions runs in both internal data and sd-ext, so yes that works too

Q: Will installing <name of script/ mod for ROM>, which involves flashing something in Recovery, work after this mod?

A: If whatever you are flashing is limited to modifications in /system, no problems - it will work.

If what you are flashing involves changing or adding content to any part of /data then it will probably not. The reason is when you mount data in Recovery, you will by default mount the internal NAND. After this method, the internal NAND is untouched. You must either modify the updater-script (See Note to ROM Makers on ClockWorkMod Updater Script), or use QtADB/ ADB shell to do what the flashing is supposed to do.

Q: I am getting stuck at boot animation/ getting "Encryption Unsuccessful" message when Android boots...

A: Your ROM's init binary may not support the mount... wait option that I am using. There are other variants like wait <device>, and then mount <device>, see if you can find what it is from the source code of your ROM's init binary (init.c). If all else fails, you may have to include a copy of busybox in sbin, point all commands in extprep script to that busybox, and increase the sleep time using /sbin/busybox sleep 25 (that is an example). In any case, you DO NOT HAVE TO WIPE DATA or WIPE ANYTHING AS SUGGESTED BY THE INSTRUCTIONS IN "Encryption Unsuccessful" message

Q: Can I move part of /data from EXT partition to NAND?

A: You don't have to move anything - that is the beauty of this mod. If, for example, you want dalvik-cache to be in NAND, all you have to do is create a directory, mount NAND to that directory, and symlink /data/dalvik-cache to that directory. Example: In init.rc, make sure /data/dalvik-cache is NOT getting created (comment that line out with a #)

mkdir /dalvik 0771 system system
mount yaffs2 mtd@userdata /dalvik nodev nosuid noatime nodiratime
symlink /dalvik /data/dalvik-cache

Q: How do I improve performance?

SD Card interface by design cannot handle multiple read/ write activities simultaneously. An example: Put the SD Card in a card reader attached to your computer. Copy a ~500MB file to it, see what write speeds your get (Win 7 shows an approx value). Now, while the first file is still being copied, copy another similar sized file - what happens to the write speed? It crawls, right?

When you have DataOnEXT, the SD Card is continuously being read from and written to because all your apps, their data, system data and configuration, etc. resides in the EXT partition. You SHOULD NOT expect the same speeds like a full-NAND setup. That said, there a few things you can do to improve performance:

Get a performance SD Card like SanDisk Ultra® microSDXC™UHS-I card

ODEX your ROM

See the previous question's answer for moving dalvik cache to NAND

Increase the NAND's read ahead cache from 4KB to 128 ot 256KB (in init.htcleo.rc)

Set your IO Scheduler to Deadline (use No frills CPU Control)

Q: My ROM slows to a crawl after installing this mod when I install or remove an app...

A: That is normal behavior, let it be for a min or two and it will get back to the usual speeds. This is because installing or removing an app involves creating the DEX file in the dalvik cache, extracting the components (lib files, config files, etc.) for the app and placing them in appropriate locations in /data and so on. This will slow down the system responsiveness because all of these are in the EXT partition, and the SD Card interface is a serial interface that will slow down with multiple simultaneous read/ write requests. However, doing what I have said for the previous question will improve performance quite a bit

FAQ is still WIP, I will keep adding to this section as and when...