[Miscellaneous Android Development] Deleted member 5186178:
And for the next step, open BoardConfig.mk file. For now it 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 := unknown
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 := 0x105c0000
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_FLASH_BLOCK_SIZE := 131072

TARGET_PREBUILT_KERNEL := device/lenovo/P780/kernel

BOARD_HAS_NO_SELECT_BUTTON := true

So, we have to make some changes. First, if the mkvendor script didn't get your platform

TARGET_BOARD_PLATFORM := unknown

add it as you have in fstab.{hardware} and init.{hardware}.rc.

If you don't know your hardware, get it with adb:

adb shell cat /proc/cpuinfo

and you will find the hardware.

For me it is:

Processor	: ARMv7 Processor rev 2 (v7l)
processor	: 0
BogoMIPS	: 2439.94

Features	: swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 2

[COLOR="Blue"]Hardware[/COLOR]	: [COLOR="Red"]MT6589[/COLOR]
Revision	: 0000
Serial	: 0000000000000000

and I changed that line like this

TARGET_BOARD_PLATFORM := [COLOR="Red"]mt6589[/COLOR]

Next there are partitions size defines:

# fix this up by examining /proc/mtd on a running device
BOARD_BOOTIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_FLASH_BLOCK_SIZE := 131072

Do what they say, using "adb shell cat /proc/mtd" or "adb shell cat /proc/emmc" or "adb shell cat /proc/dumchar_info" for a MTK phone, and replace every partition size with the correct value. For me it is:

# Partition sizes
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

The board flash block size is specific to your platform. In MTK phones, that is usually 512, but it will work with default 131072 value too.

Also you can add here

TARGET_USERIMAGES_USE_EXT4 := true

if your phone uses ext4 file system (check in fstab or default.prop in boot.img ramdisk).

Next line that has to be corrected is

TARGET_PREBUILT_KERNEL := device/lenovo/P780/kernel

Remember you have the kernel now in prebuilt subfolder, so it should be:

TARGET_PREBUILT_KERNEL := device/lenovo/P780/prebuilt/kernel

In some cases you may need to use another flag:

TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"

if your phone has a custom PIXEL FORMAT. You need to find out that, or if the flag is not used you may see the recovery doesn't boot.

Now let's add the custom fstab and init.rc

TARGET_RECOVERY_INITRC := device/lenovo/P780/recovery/init.{hardware}.rc
TARGET_RECOVERY_FSTAB := device/lenovo/P780/recovery/recovery.fstab

for me it is

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

If you want to use init.recovery.{hardware}.rc and you have that in /recovery/root folder, skip the first flag and use only

TARGET_RECOVERY_FSTAB := device/lenovo/P780/recovery/recovery.fstab

The path /device/lenovo/P780 is for my example; you should use your device path here.

And last, if you don't want to build regular CWM, you can use recovery variant flag. This way you can add a custom recovery folder in your bootable folder along with default "recovery" and "recovery-cm". You can use here what you want: recovery-twrp, recovery-philz or recovery-carliv. For every one you should check their threads and author's instructions for additional flags or modifications in BoardConfig or device tree.