Monday, July 1, 2013

Building ClockWorkMod Recovery for the Nook HD+

Now that I've set up a build environment, it's time to build ClockWorkMod Recovery (CWM) for my Nook HD+.

Get the Source Code

The CWM source code is part of the CyanogenMode source distribution.

$ mkdir src
$ cd src
$ repo init -u git://github.com/CyanogenMod/android.git -b cm-10.1

The Nook HD+ is not yet officially supported by CyanogenMod, so the repository containing device-specific files must be added.

$ mkdir .repo/local_manifests
$ wget -O .repo/local_manifests/verygreen_ovation_emmc.xml \
https://raw.github.com/verygreen/android_manifests/cm-10.1/NookHD-jb/local_manifest.xml

Now the source code (approximately 15 GB of it!) can be downloaded, along with any required pre-built binaries.

$ repo sync
$ vendor/cm/get-prebuilts

Build It

$ breakfast cm_ovation-userdebug
$ make -j8 recoveryimage

Now the Tricky Part

The previous step will create a file named out/target/product/ovation/recovery.img, which is nothing of the sort.  (It's actually a ZIP file containing a kernel and a ramdisk image, and the ramdisk isn't even in the required format.)  To make an actual recovery image, use the mkbootimg tool.

$ out/host/linux-x86/bin/mkbootimg --pagesize 4096 --base 0x80000000 \
    --kernel out/target/product/ovation/kernel \
    --ramdisk out/target/product/ovation/ramdisk-recovery.img \
    --output my-recovery.img

This will create a standard, bootable recovery image.  Sadly, a Nook HD+ will not boot a standard image, because of its locked bootloader.

CyanoBoot

CyanoBoot  is "second stage bootloader" that can boot a non-stock ROM or recovery on a Nook HD+.  It occupies the first 1 MiB (1,048,576 bytes) of the recovery partition, followed by the recovery image created in the previous step.  If ClockWorkMod Recovery has been successfully installed on a Nook HD+, CyanoBoot is already installed, and it's possible to simple write the new recovery image at a 1 MiB offset.

Personally, I prefer to create a "complete" image that can be flashed directly to the recovery partition; it strikes me as slightly less error-prone.  The first step is to extract the bootloader from the standard CWM ZIP file.

$ cd
$ wget http://nook.rootshell.ru/hd/cwm-recovery-ovation-2.zip
$ unzip cwm-recovery-ovation-2.zip recovery.img

$ dd if=recovery.img of=cyanoboot.img bs=1048576 count=1

Now the complete image can be created.

$ cat cyanoboot.img src/my-recovery.img > bootable-recovery.img

Installing and Testing

The recovery image is installed by writing it to the device's recovery partition.  After the image has been transferred (via adb or another mechanism), use a root shell on the device to issue the following command:

# dd if=bootable-recovery.img of=/dev/block/platform/omap/omap_hsmmc.1/by-name/recovery

(If installing a "standard" image that does not include CyanoBoot, skip the first 1 MiB of the partition by adding "bs=4096 seek=256" to the dd command.)

The new recovery image can be tested by powering the device off and booting into recovery with the power and home buttons.

Do not reboot directly into recovery via the reboot menu, ROM Manager, etc.  This will configure the device's bootloader to boot from the recovery partition.  If the recovery image is unbootable, the device will boot loop until it can be persuaded to boot from an appropriately formatted microSD card, which can be difficult.

Conclusion

With the build, installation, and testing process established. it's now time to start actually customizing the recovery image.  Thus far, I've simply changed the file system type of the SD card from FAT32 to ext4 by changing the corresponding field in device/bn/ovation/recovery.fstab.

No comments:

Post a Comment