[Miscellaneous Android Development] Deleted member 5186178:
Set up a device tree.

Of course if you don't have one, because nobody created it before.

Following the clockworkmod guide, you can see how to start this by using mkvendor.sh script.

So place the recovery.img from your stock ROM in that repo folder (CM11-0 for me), and let's take as example my phone Lenovo P780.

With any root explorer take a look at build.prop from "system" and notice these lines:

ro.product.manufacturer=[COLOR="Red"]LENOVO[/COLOR]
ro.product.device=[COLOR="Red"]P780[/COLOR]

I have lenovo (I will use lower-case) and P780.

And the command will be

./build/tools/device/mkvendor.sh lenovo P780 recovery.img

But, at this point I always get an error message:

"[COLOR="Red"]unpackbootimg[/COLOR] not found. Is your android build environment set up and have the host tools been built?"

In that guide they say to do

. build/envsetup.sh
make -j4 otatools

in cm11 folder, and the unpackbootimg will be compiled. What they don't say (or I never found it) is that even after otatools are created, that error still appear. And if we take a look in the script, we see it is searching for unpakbootimg executable:

UNPACKBOOTIMG=[COLOR="Red"]$(which unpackbootimg)[/COLOR]

The which command won't display anything if the module is not in path. So either you add "$HOME/CM11_folder/out/host/linux-x86/bin" in path, or run this in terminal after otatools make is finished:

cp $HOME/CM11_folder/out/host/linux-x86/bin/unpackbootimg $HOME/bin

where CM11_folder is the name of the folder with cm-11.0 building tree. After that the unpackbootimg will be in bin folder, which is in path, and everytime you need to run it, will be found. You can check that in terminal typing

which unpackbootimg

Now back to my example for device tree. Open a terminal window in CM11-0 folder, or open terminal and type

cd CM11-0

then type that command to create the device tree.

./build/tools/device/mkvendor.sh lenovo P780 recovery.img

After script is executed you will see the new device folder in device list, lenovo with subfolder P780.

For a regular phone that will be ok, and you can start working on that device tree,

but for a MTK phone that is not good.

Why? Because MTK use a header appended to kernel and ramdisk, and the script won't be able to properly unpack it.

It will be an error about ramdisk not being in gzip format for a MTK phone.

The result will be that instead of real recovery.fstab and some other data in device tree files, we will get generic default values. As an example, this is the recovery.fstab I've got for my phone after that command:

# mount point	fstype device	[device2]

/boot mtd boot
/cache yaffs2 cache
/data yaffs2 userdata
/misc mtd misc
/recovery mtd recovery
/sdcard vfat /dev/block/mmcblk0p1 /dev/block/mmcblk0
/system yaffs2 system
/sd-ext ext4 /dev/block/mmcblk0p2

That is not the real one (my device is emmc not mtd type) and so, for MTK phones, we need to do some extra things. First get my CarlivImageKitchen and unpack it somewhere in your home folder. The utility contains few unpack and repack scripts for boot/recovery images created using instructions from here.

Then copy the stock recovery image to those utilities folder and open a terminal window in it.

Type

./unpack_MTK_img recovery.img

What you have to do now is to repack the recovery using the regular script instead of MTK script (CarlivImageKitchen strips off the Mediatek header during unpack).

So, just type

./repack_img recovery

and choose the name recovery for the new image.

At the end take the recovery.img an move it to cm11-0 folder.

Back to cm11 folder, open a terminal window and type mkvendor command

./build/tools/device/mkvendor.sh lenovo P780 recovery.img

The result? Well take a look at this recovery.fstab:

boot	/boot emmc defaults defaults
/dev/block/mmcblk0p2 /cache ext4 defaults defaults
/dev/block/mmcblk0p3 /data ext4 defaults defaults
misc	/misc emmc defaults defaults
recovery	/recovery emmc defaults defaults
/dev/block/mmcblk0p4 /sdcard vfat defaults defaults
/dev/block/mmcblk0p6 /system ext4 defaults defaults

This is the real one from stock recovery. It can't be used for CWM but it proves that the ramdisk was unpacked correct.

Anyway this is only the beginning, because we need to check every file from device tree and to add some files too.