[Miscellaneous Android Development] Deleted member 5186178:
This part is universal, not only for MTK phones.

At this point the device folder looks like this.

First we need to create a new file, vendorsetup.sh with this content:

add_lunch_combo cm_P780-eng

or copy one from an existent device tree, changing the device name with yours.

Actually entire file looks like this:

#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This file is executed by build/envsetup.sh, and can use anything
# defined in envsetup.sh.
#
# In particular, you can add lunch options with the add_lunch_combo
# function: add_lunch_combo generic-eng

add_lunch_combo cm_P780-eng

This will add your device in lunch options, and will be initialized by build/envsetup.sh command. It should work even without it, but is better to create this script: the official clockworkmod guide says - " It is used to add non-standard lunch combos to the lunch menu.".

Next you have to change AndroidBoard.mk to Android.mk and instead of

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET)

# include the non-open-source counterpart to this file
-include vendor/lenovo/P780/AndroidBoardVendor.mk

it should contain this

#
# Copyright (C) 2013 The Android Open-Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# WARNING: Everything listed here will be built on ALL platforms,
# including x86, the emulator, and the SDK. Modules must be uniquely
# named (liblights.tuna), and must build everywhere, or limit themselves
# to only building on ARM if they include assembly. Individual makefiles
# are responsible for having their own logic, for fine-grained control.

LOCAL_PATH := $(call my-dir)

ifeq ($(TARGET_DEVICE),P780)
include $(call all-makefiles-under,$(LOCAL_PATH))
endif

AndroidProducts.mk file is ok as it is and we will let BoardConfig.mk for the end.

Let's create first a folder "prebuilt" and move the kernel in it. Then a new folder "recovery" and move recovery.fstab in it.

Then cm.mk file can remain as it is for building recovery, so let's open device_YOURPHONE.mk (in my case device_P780.mk) - all editing must be made with a good editor (IDE) - I'm using Geany. You can see the kernel is called from device folder, but you moved it in prebuilt folder so change this

LOCAL_PATH := device/lenovo/P780

to this

LOCAL_PATH := device/lenovo/P780/prebuilt

Also here you can add rules for files that have to be copied in built recovery ramdisk, or aditional lines to default prop file.

Like this:

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 \
ro.allow.mock.location=1 \
persist.mtk.aee.aed=on \
ro.debuggable=1 \
persist.service.acm.enable=0 \
persist.sys.usb.config=mass_storage \
ro.bootloader.mode=download \
ro.mount.fs=EXT4 \
ro.persist.partition.support=no

or if you don't want those unuseful goldfish things in ramdisk, add this too:

PRODUCT_COPY_FILES_OVERRIDES += \
root/fstab.goldfish \
root/init.goldfish.rc \
recovery/root/fstab.goldfish

You have to know that in cm11 any file that starts with init will be deleted from root of ramdisk as we can see in /build/core/Makefile:

@echo -e ${CL_CYN}"Modifying ramdisk contents..."${CL_RST}
$(hide) [COLOR="Red"]rm -f $(TARGET_RECOVERY_ROOT_OUT)/init*.rc[/COLOR]

So if you want to add some init files in recovery ramdisk root (init.usb.rc or init.ssd.rc, etc.) there is another way. For cm11, you have to create a subfolder "recovery" in device tree - which you did already, and in that folder to create subfolders that match recovery ramdisk folders (ex. etc, res, sbin...), and for files that have to be in root create a root subfolder. The building process will take those, if they are in res or root subfolder and place them in corresponding folders in recovery ramdisk. for the other subfolders (etc, sbin) you have to create an Android.mk file in recovery folder defining every file as local module and to use device_xxxx.mk to add them as product packages. This method with locale module is also recommended for boot image ramdisk. For building recovery we don't need that, but I mention it for further developments.

Now it's time to add some files in recovery folder. A custom init.rc and fstab, named after your hardware: if it is qualcomm will be init.qualcomm.rc and fstab.qualcomm, if it is a MTK phone will be init.mt6589.rc and fstab.mt6589 or whatever is your MTK hardware, and so on. This fstab will be placed in /recovery/root folder and init file will remain in recovery folder. Another way is to name init.{hardware}.rc as init.recovery.{hardware}.rc and to place it in /recovery/root folder too, and to not use a custom init.rc for recovery, because that one will be called in default init.rc, but I prefer only one init.rc file in ramdisk.