[Epic 4G Android Development] mkasick:
CM7 dualboot update:

I've been dualbooting CM7 for a while, and Rodderik has gotten it to work on his own as well. While we are slowly getting all the pieces in place to make this relatively easy, it's not yet in a user-friendly package. That said, folks are interested in this and I figure it's worth sharing what I have working now for the brave and capable to take a look at. But do note, this is not final form.

Requirements:

First, you need a micro-SD card reader and access to a Linux machine to partition and format a micro-SD card.

Second, you need a kexec-capable recovery. At present I'm using the stock recovery included in my EI22 keyfix kernel (flashed to bml8), but you'll probably prefer to use DRockstar's test build of CWM5. Note that he hasn't posted that build here yet, but it's mentioned in the topic of the #epic IRC channel and folks have tested it some, and kexec is confirmed to work on it.

Third, you'll need these files:

CM7 1022 update.zip (from the CM7 thread).

CM7 1022 "sdrom" kernel (for use with kexec only, see details below).

boot_zImage.zip

boot_zImage_recovery.zip

Directions:

Partition the micro-SD card using a card reader in a Linux machine. I use fdisk, but parted should work as well. You'll want to create exactly four "primary" (not logical/extended) partitions. The first will be vfat (FAT32) formatted and contain the usual /sdcard, while the 2nd-4th will be ext4 formatted for /system, /data, and /cache. The sizes of the partitions aren't particularly important, but in absence of any better ideas, I stay close to the size of the NAND partitions (/system: 260 MB, /data: 501 MB, /cache: 169 MB). As an example, here's the fdisk output for the partitioning of a 2 GB card (well, first 2 GB of an 8 GB card, I have other stuff after):

Disk /dev/sdb: 8017 MB, 8017412096 bytes
247 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 15314 * 512 = 7840768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe77dc28a

Device Boot Start End Blocks Id System
/dev/sdb1 1 137 1047985 c W95 FAT32 (LBA)
/dev/sdb2 138 173 275652 83 Linux
/dev/sdb3 174 240 513019 83 Linux
/dev/sdb4 241 263 176111 83 Linux

After the card is partitioned, it needs to be formatted, which can be done with the commands below. Make sure to replace /dev/sdb with the appropriate block device lest one blow away part of their RAID-0 setup or something:

mkfs.vfat /dev/sdb1
mkfs.ext4 /dev/sdb2
mkfs.ext4 /dev/sdb3
mkfs.ext4 /dev/sdb4

Once formatted we have to populate the first partition of the micro-SD card with the files necessary to bootstrap CM7. We don't have to worry about the other partitions, those are handled on the phone. The command-line steps for this are:

mount /dev/sdb1 /mnt
cp boot_zImage.zip boot_zImage_recovery.zip /mnt
unzip -d /mnt kernel-cm-7.1.0-Epic-KANG-1022-sdrom.zip
cp update-cm-7.1.0-Epic-KANG-1022-signed.zip /mnt
umount /mnt

That is, copy boot_zImage.zip, boot_zImage_recovery.zip, and update-cm-7.1.0-Epic-KANG-1022-signed.zip all to the root of the micro-SD card, and extract zImage from kernel-cm-7.1.0-Epic-KANG-1022-sdrom.zip and place it there as well.

Shutdown the phone if it isn't already and place the micro-SD card in it. Now, three-finger boot (vol-down, camera, power) into recovery, select "apply update from sdcard" (the specific command varies on the recovery used), then select "boot_zImage_recovery.zip". This will kexec /sdcard/zImage (the CM7 kernel) and boot its recovery. And yes, it's very important that the rest of the installation is preformed under CM7 recovery.

After selecting "boot_zImage_recovery.zip" you'll be abruptly greeted by the SAMSUNG logo and it should soon boot the cyan-colored CM7 CWM (v5.0.2.6). Here, select "install zip from sdcard", "chooze zip from sdcard", "update-cm-7.1.0-Epic-KANG-1022-signed.zip", "Yes - Install ...". This will flash CM7 onto the second partition of the micro-SD card, and should take a minute or so to complete. One finished, select "Go Back" (which will pause for a few seconds, don't worry), and "reboot system now".

This will reboot the phone and automatically boot into bml8 (three-finger) recovery--that is, you don't have to hold the three buttons this time. Select "apply update from sdcard", then "boot_zImage.zip". This should force another reboot, SAMSUNG, and in a few moments show the CM7 boot animation. If so, congrats! If not, you'll probably have to battery pull.

CM7 should work mostly as advertised with two exceptions (that I'm aware of). First, a reboot from CM will always dump you back into bm8 recovery, regardless of the "kind" of reboot, and second, a power off actually does the same thing. That is, the phone powers off as expected, but when powered on again, bml8 recovery is automatically booted.

This behavior turns out to actually be somewhat convenient as you can select which ROM you want to boot from recovery this way. That is, to boot your regular ROM, select "reboot system now" from recovery. And to boot CM7, select "apply update from sdcard", then "boot_zImage.zip".

I should also note that normal reboot behavior is restored during execution of the regular ROM so this isn't a permanent change, but rather the behavior only when operating in CM7. Also, to be honest, I'm not sure what happens when one charges with power off from CM7 (i.e., lpm mode). It should work, but I can't say exactly what will boot after--it should be sane though.

Kernel details:

The "sdrom" kernel is the CM7 1022 kernel with a repackaged initramfs, wrapped with a patched decompressor to make it kexec compatible. Here, the initramfs changes are the most significant part.

The changes to the initramfs contain two patches, a fake param.ko, and a bunch of removed storage models. The first patch replaces rfs/NAND support for ext4/SD in the init scripts. The second patch removes NAND (fsr, stl, j4fs) support entirely. In conjuction with the fake param.ko allows the kernel to function without any potential possibility for disturbing the NAND partitions, so the regular ROM is always kept safe. This also means /mnt/.lfs (stl6) is left untouched, which is responsible for the odd reboot behavior.

Removing NAND support isn't strictly required in SD kernels, it's something I did for testing purposes to avoid any accidents. That said, one beneficial side effect of removing NAND support is that it allows us to flash the CM7 update.zip unmodified. At present, the kernel update step (bmlwrite) fails silently without flashing anything, which is what we want here.

As I mentioned above, all this is stuff I'm using to test CM7 dualbooting, but it's not the final intended form. Of pieces missing, it would be nice to have a script that partitions (if we decide to go with partitions) and formats a micro-SD card in the phone, so there's no external hardware requirements. It would also be ideal to use an unmodified CM7 kernel, which is doable through kexec initramfs overlays once the decompressor patches are included. With kernel NAND (bml or even mtd) support, additional work will be needed to ensure that CM7 update.zips don't perform the kernel flash step, if it's preferable to maintain the ability of flashing unmodified update.zips.