Porting ClockworkMod Recovery to a New Device

If you are not familiar with custom recovery images, we suggest you read the Introductory section of XDA-University.

ClockworkMod, commonly abbreviated as CWM, is a popular custom recovery for Android phones and tablets developed by Koushik Dutta (Koush), a well-known name in the Android dev community. This recovery image allows you to perform many advanced tasks like flashing, backups, restoration and other maintenance tasks on your android device which the stock recovery cannot do.
Thus ClockWorkMod (also known as CWM) is a very popular custom recovery.

Setup the build environment. Guide on that can be found here : Building from Source
Please note that we will be compiling the latest version of CWM recovery.

The source for CWM comes bundled with the CyanogenMod source code. So you will have to sync the CyanogenMod source.
In this guide, we use the source of CyanogenMod 10 to build CWM 6.

At this stage make sure that you have synced the source, updated it and setup the build environment. Now lets proceed to the actual compiling part.

Step 1 : Open the terminal and change the directory to the top of your source. Then run the command

“ make -j4 otatools ”

This command will create all the necessary tools and files for the recovery compilation. Here -j# signifies the number of processes to start. It is generally based on the number of processors in your computer. This process generally requires 5-7 minutes on a reasonably fast desktop computer.

Step 2 : Now that the otatools are ready, we need to get a dump of our current boot.img. To do this, use ‘adb shell’ and launch this command

“ dump_image boot /sdcard/boot.img “

This command will dump the boot partition as a image file named boot.img to your sdcard. Now pull this image to your local directory using adb pull or any other method.

Step 3 : Now we need to set up the makefiles for this device. Generally this is a long and tedious process. But since we are only compiling a recovery, it will be a lot easier.

From the root of your source directory, run the command

“ . build/envsetup.sh “ or “ source /build/envsetup.sh “

This command will prepare all the necessary files required for compiling (initialize the build environment).

Once it is done, run the command,

“ build/tools/device/mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot.img “

This will open the boot image and extract all the necessary files in the device/manufacturer/device_name path.

Step 4 : Now that we have extracted the files from the boot.img, we need to edit them to suit our device. Generally this shouldn’t be necessary, but we need  to be sure about that or else we can brick our devices. The only files which are to be edited are ‘BoardConfig.mk’ and ‘recovery.fstab’. The main things that you will need to add is custom partitions (if your device doesn’t support named partitions).

If you change the contents of the BoardConfig.mk file, you will have to run ‘make clobber’ or the changes won’t get picked.
As the name suggests, BoardConfig.mk contains the config about the board used in your device. This is a very important file and a single error or incorrect value can result in a brick. So be cautious while editing this file

Next file is the recovery.fstab. This file lists all the partitions of a device and its paths. If you see any incorrect partition in this file, please change it. You don’t want your boot.img flashed on the bootloader partition, do you ?

I cannot help you with the actual editing as each device has different partitions and different formats.

Step 5 : Once the files are ready, we start the compiling. Run the following command to prepare the system for a compile.

“ . build/envsetup.sh “

Step 6 : Once the system is ready, lets move on to the compile process.

Run the command,

“ lunch full_’device_name’-eng “

For e.g : if you have a device names cooper, the command will be,

“ lunch full_cooper-eng “

This will prepare the files of cooper for compiling.

Step 7 : Now that we have all files setup, run the command

“ make -j4 recoveryimage “

This command builds the recovery in the form of an image file. If you want a fakeflash for testing purpose, then run,

“ make -j4 recoveryzip “

The entire building process takes around 15 minutes.

Once complete, you will get the resulting recovery.img in the ‘out/target/product/device’ path. You can flash the recovery using a flashable zip or from adb using flash_image.