[Nexus 4 Android Development] ramjet73:
Flashing Tips

It seems that a lot of people are having problems flashing this ROM so I'm going to go through a few explanations and tips. I don't want to insult all the gurus so If you think you are one you can stop reading now. ;)

The first thing is to understand is how the partitions are setup on the Nexus devices (see attachment 1). When flashing a ROM you are going to affect the boot partition, cache partition, system partition and to some extent the data partition. The first three are not really interesting since the boot partition is completely replaced by the boot.img (kernel+ramdisk) in the ROM zip file, the cache partition is usually formatted, and the system partition is formatted and rebuilt from the files in the ROM zip by the updater-script.

So that leaves the data partition where things start to get pretty complicated. The data partition contains the dalvik cache area (still used by ART), user apps and their associated data, user data and system settings. All this stuff is merged together into one physical partition, including the simulated SD card which is in the /data/media directory. But the system settings are what makes doing a clean flash so important, since they don't necessarily match in format and location between ROM's and sometimes even between releases for the same ROM.

A clean flash with TWRP is the default "factory reset" wipe, which includes the cache partition along with the dalvik cache and other parts of the data partition excluding the /data/media directory. Therefore you do not lose your simulated SD card but the rest of the data partition is formatted and after the flash you have to restore or re-install your user apps and their data, and redo the system settings that are stored in the data partition. How this formatting of the data partition works is further explained by this TWRP article but unless you explicitly choose the data partition in the advanced formatting options you will not lose your simulated SD card.

Hopefully that explains why it is important to do a "clean" flash at least once when changing ROM's since the system settings stored in the data partition need to be done from scratch and the dalvik cache portion of the data partition needs to be cleared. You never need to format the boot or system partition when flashing a ROM since those are always completely replaced by the updater-script, which often also formats the cache partition as well even though the "factory reset" has already done that.

When changing kernels or updating versions of the same ROM a "dirty" flash (wipe cache+dalvik only) is usually OK since the system partition is rebuilt from scratch, wiping out any updates the previous kernel or ROM might have done, and the systems settings location and format usually match between versions of the same ROM. However, if new problems are experienced after a dirty flash a clean flash should be performed.

Finally, it is very important to check the MD5 checksum of ROM and kernel zip files when they are on the phone and not when they are downloaded to a PC since a bad USB port or cable (and other things) can corrupt the transfer of the file to the phone. A utility like ES File Explorer has MD5 checking built-in (see attachment 2) and there are standalone Android apps that will generate the MD5 checksum that then needs to be checked against the one displayed on the original download site. Any file hosting site that doesn't generate and display an MD5 hash for each file really isn't suitable for distribution of official releases.

Hope these explanations and tips help a little with the flashing of this ROM since a lot of the recurring problems seem to be caused by inappropriate flashes (clean versus dirty) or bad file downloads and/or transfers from PC to phone.

ramjet73