[HD2 Android NAND Development] gspiliot:
CWM Recovery & DAF

I will try to help the developer of this rom a bit here and explain a bit.

We all want to use our nand memory to store the ROM of our beloved android OS. With the help of Cotulla and DFT this became a reality with the use of MAGLDR. Now, the nand internal memory has to partitioned (i.e., divided into areas) where different parts of the ROM live, for example:

Boot, for the kernel zImage and initial ramdisk (initrd). This is normally the bootable partition.

System, where the Android libraries/binaries/data live (i.e., the ROM itself)

Userdata, is the, initially empty, space where we store our programs and data

The ROM developer, till the release of MAGLDR 1.13, supplied in essence 3 files which were flashed through MAGLDR:

flash.cfg, which explained to the MAGLDR how to partition the NAND memory (i.e., how big should make the space for boot, system and userdata)

The Boot image to flash in the boot partition

The System image to flash in the system partition

So, to recap, till now a DAF ROM consisted of MAGLDR, a file which described how to divide the partitions and the images for these partitions.

ClockWorkMod Recovery can be thought as a live filesystem in terms of the Operating System. Something like the 'live' distributions of linux or PXE (pre-execution environment) for windows. It is needed for doing work with the main android operating system while this is not running at all. Some things we can do with CWM are:

Backup the entire android operating system while this is inactive

Format partitions and copy files into them.

Patch the android operating system replacing any file we want or running scripts to fix/alter settings/permissions.

partition our SD card

erase or alter files/directories in the userdata partition which cannot be done while android is running

etc.

One of the disadvantages of CMR under our HD2 platform, in contrast with other platforms, is that it cannot do the actual partitioning of the NAND memory. This can only be done by the MAGLDR. So one has to use the correct partitioning (i.e., the correct flash.cfg file together with MAGLDR) before using CWM for flashing/patching.

One can think of the CWM Recovery system as a 'live', extremely small OS. Therefore it needs a zImage (kernel) and a system image (initrd in our case) to begin with (i.e., to boot from). Till the release of MAGLDR 1.13 these two files had to be stored on the SD card. Then we used MAGLDR to boot either from SD (CWM Recovery) or NAND (Android).

With the release of MAGLDR 1.13 it is possible to prepartition the NAND memory to include the CWM Recovery files (zImage, initrd) in a special partition (actually CWM requires at least three partitions: misc, recovery, cache. The cache partition will be used also by the Android OS for storing, what else? the cache). So now a typical ROM should divide (partition) the NAND memory with partitions such as:

misc

recovery

boot

system

userdata

cache

(Some ROMs can elect to merge boot and system partitions into one). The size of each of these partitions are predetermined at MAGLDR flash time. Even if we can use the CWM recovery to change/flash/format/write these partitions we cannot change their sizes.

CWM Recovery, when downloaded independently from its thread, comes with some flash.cfg files which define some specific partition sizes like system=150,250,390 MBytes. Not all of these sizes fit all ROMs because a 150 system partition cannot probably fit a full DHD system image. So in order to use the best out of the restricted NAND memory we have it is better to let the ROM developer to create a MAGLDR flash which includes a properly defined flash.cfg (i.e. the sizes of the partitions) tailored to the size of the respective image (plus a little bit of additional space, as we will see later on, in case later versions need it). For example MarkinuX HD Extra Clean defines a 240M system partition.

Finally, how I can make use of all those MAGLDR & CWM Recovery systems?

First, lets assume that you are flashing a rom for the first time (i.e., you are not upgrading THE SAME ROM). I also assume that MAGLDR is installed on your device. Download the first link (labeled "BUILD INCL. CMR") from this thread (i.e., the MAGLDR or DAF file as it should be named) and flash it by running DAF.EXE (more on how to use MAGLDR to flash can be found by searching). Remember to enable the 24 extra MB of RAM through MAGLDR (this is required for this ROM) otherwise the partitioning will fail. This will:

Divide the regions (partitions) on the NAND memory according to the supplied flash.cfg

Flash the image recovery-raw.img into the 'recovery' partition

flash the boot.img into the 'boot' partition

flash the system.img into the 'system' partition

When the device will reboot (after flashing) you will have 2 options (same at every reboot/power up):

Do nothing and the Android ROM will start executing the android OS

OR - press and hold the power button (the rightmost button) till you get the MAGLDR menu. Then you can select "AD Recovery" which will boot CWM Recovery 'OS' from the recovery partition (remember this partition contains the zImage+initrd for the small CWM Recovery OS)

Using the CWM Recovery OS is pretty easy. Navigate to the menus by using the volume up/down buttons. The Answer (leftmost) button is the ENTER equivalent and the power (rightmost) button is the ESC or EXIT equivalent. Patches or flash files for CWM come as ZIP files. Just put the .zip file on the root of the SD card (DO NOT UNZIP IT!) and select "install zip from sdcard", then select "choose zip from sdcard", then select the file and finally choose "Yes - Install ...".

Now how can you upgrade the ROM with a newer version using CWM Recovery the easy way without loosing any of your installs and with the ability to switch back to the previous version without the use of a PC/mac? Easy:

Download the second ROM (the zip file named "ZIP Version for CMR") from this thread and copy it to the root of your SD card.

Start CWM Recovery as we explained before. Select "backup and restore" and then "Backup". Let it finish. Just a reminder: the backup will be done to a special directory Clockworkmod on the SD card so in order to backup you will need one with enough space.

Still in CWM Recovery choose "install zip from sdcard", then select "choose zip from sdcard", then select the ROM file you copied on step 1 and finally flash it. This will replace just the boot & system partitions and will not touch your files (living in the userdata partition) in any way.

Select 'reboot system now' in CWM.

The above CWM procedure is for upgrading or reinstalling a ROM. For ver 1.7 we have already flashed it using MAGLDR as this is the initial step to get 1.7 + CWM installed. Use the CWM Recovery flash if you want to upgrade to newer versions or if you want, for any reason, to reflash 1.7.

If you want to restore to the backup you have already taken then just boot to CWM again and select "backup and restore" then "restore" and select the right file to restore (the backup files are named with the date the backup was taken).

In order to recap:

If you are flashing for the first time (or if you are coming from an earlier version before 1.7): flash the first file posted in this thread normally using MAGLDR (i.e., running the DAF.exe file).

If you want to upgrade later to 1.8, 1.9 etc. (or even if you want to reflash 1.7) without losing your files/data use the CWM .zip edition of the ROM as described above.

I think this is simple enough.

George.