[Miscellaneous Android Development] Deleted member 5186178:
Build a CWM-based Recovery

So if you want to build a stock Clockworkmod Recovery, you will use the default recovery from Cyanogenmod 11 building tree.

But if you want to build a CWM variant or custom you have to use a flag on BoardConfig, corresponding to that custom recovery folder: recovery-cm, recovery-twrp, recovery-philz, recovery-miui, etc. Place that flag on BoardConfig:

RECOVERY_VARIANT := twrp

or

RECOVERY_VARIANT := philz

and same goes for the other variants too.

If your phone is one with MTK platform,

you may need one more flag:

BOARD_CUSTOM_BOOTIMG_MK := device/lenovo/P780/mkmtkbootimg.mk

to append MTK header to compiled image. Remmember that the prebuilt kernel has MTK header stripped off and if you use the recovery image built without MTK header, it won't work. For correct this we will use a custom file developed by chrmhoffmann and inspired by bgcngm's mtk-tools scripts, which I named mkmtkbootimg.mk. There are some other custom boot makers for MTK phones (one is developed by Omnirom team for Oppo R819), but this one is the best for me. Copy it in your device folder if your phone is a MTK - or create a new mk file and paste the content in it, then add that BOARD_CUSTOM_BOOTIMG_MK flag. Even if you don't have a MTK phone you may need to use a custom boot maker script, as I saw in LG phones.

For MTK phones again, if you don't want to use a custom boot image maker, you can build normal, but after build is finished, take the recovery.img and using my CarlivImageKitchen, open a terminal in that folder and type:

./unpack_img recovery.img

and then

./repack_MTK_img recovery

to make it compatible with MTK phones (my utility will append the MTK header to kernel and ramdisk).

Anyway using a custom boot image maker file is a better solution.

Other thing you can add is this flag:

TARGET_RECOVERY_LCD_BACKLIGHT_PATH := \"/sys/devices/platform/leds-mt65xx/leds/lcd-backlight/brightness\"

Search in your phone with a root explorer the path for lcd-backlight (usually in /sys/devices/platform/leds something.... This is for recoveries that needs it (twrp, philz).

Also you can use a custom font for recovery. Take a look in /bootable/recovery or recovery-variant/minui folder and choose one. There are few fonts file with 00x00 in name: those are with and height for a character, so you know how to choose one for your screen resolution. As an example, for a screen res of 540x960 the best view is with "roboto_15x24.h" font.

Define it like this:

BOARD_USE_CUSTOM_RECOVERY_FONT := \"roboto_15x24.h\"

Finally now my BoardConfig looks like this:

USE_CAMERA_STUB := true

# inherit from the proprietary version
-include vendor/lenovo/P780/BoardConfigVendor.mk

TARGET_ARCH := arm
TARGET_NO_BOOTLOADER := true
TARGET_BOARD_PLATFORM := mt6589
TARGET_CPU_ABI := armeabi-v7a
TARGET_CPU_ABI2 := armeabi
TARGET_ARCH_VARIANT := armv7-a-neon
TARGET_CPU_VARIANT := cortex-a7
TARGET_CPU_SMP := true
ARCH_ARM_HAVE_TLS_REGISTER := true

TARGET_BOOTLOADER_BOARD_NAME := P780

BOARD_KERNEL_CMDLINE :=
BOARD_KERNEL_BASE := 0x10000000
BOARD_KERNEL_PAGESIZE := 2048

# fix this up by examining /proc/mtd on a running device
BOARD_BOOTIMAGE_PARTITION_SIZE := 6291456
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 6291456
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 939524096
BOARD_USERDATAIMAGE_PARTITION_SIZE := 1283457024
BOARD_FLASH_BLOCK_SIZE := 512
TARGET_USERIMAGES_USE_EXT4 := true

TARGET_PREBUILT_KERNEL := device/lenovo/P780/prebuilt/kernel
TARGET_RECOVERY_INITRC := device/lenovo/P780/recovery/init.mt6589.rc
TARGET_RECOVERY_FSTAB := device/lenovo/P780/recovery/recovery.fstab

BOARD_HAS_NO_SELECT_BUTTON := true

BOARD_CUSTOM_BOOTIMG_MK := device/lenovo/P780/mkmtkbootimg.mk

BOARD_USE_CUSTOM_RECOVERY_FONT := \"font_17x33.h\"
DEVICE_RESOLUTION := 720x1280
TARGET_RECOVERY_LCD_BACKLIGHT_PATH := \"/sys/devices/platform/leds-mt65xx/leds/lcd-backlight/brightness\"

This is it, the device tree is done, good to build a recovery now, and you can add on it what you need to make it build a full ROM. We made now only the base of the device tree.