[Android Software Development] :
Building Guide

To build you need a local repo of cm-12.1 or cm-13 and a proper device tree. To see how a buildable device tree looks check this one from my github.

It builds out of the box with aicp lp-5.1 and aicp mm-6.0 too, but like in cm you need a proper device tree.

Some things to be considered:

For BoardConfig:

- the most common thing in all BoardConfig I saw (you need this to use power button to select if you use physical buttons in some situations)

- BOARD_HAS_NO_SELECT_BUTTON

- for the graphical interface

- TARGET_RECOVERY_PIXEL_FORMAT

- for mass storage if your phone has an external sdcard, to connect it to PC (this one can be specified in fstab too) - and it has to be without any quotes or slashes

- TARGET_USE_CUSTOM_LUN_FILE_PATH := /sys/devices/platform/mt_usb/musb-hdrc.0.auto/gadget/lun%d/file

- for LCD backlight lights - and it has to be without any quotes or slashes

- TARGET_RECOVERY_LCD_BACKLIGHT_PATH := /sys/class/leds/lcd-backlight/brightness

- for vibrator feature - and it has to be without any quotes or slashes

- VIBRATOR_TIMEOUT_FILE := /sys/devices/virtual/timed_output/vibrator/enable

- with link to a valid recovery.fstab version 2 (it may work without it but it is better to be here)

- TARGET_RECOVERY_FSTAB

- for a better readability adapted to your screen (check the minui folder for more fonts)

- BOARD_USE_CUSTOM_RECOVERY_FONT

Carliv Touch Recovery specific flags:

- if you have the recovery on recovery-carliv folder under bootable directory in cm-12.1 source use this next flag.

- RECOVERY_VARIANT := carliv

NOTE: in cm 13, and other android 6 sources too, you can't build with this flag out of the box and so you have some things to do - the easy one is to rename recovery folder in [recovery-stock] and to place my recovery next to that with the name [recovery]. Other option is to open Android.mk from /sytem/core/healthd and find line 58 where you need to replace [LOCAL_C_INCLUDES := bootable/recovery] with [LOCAL_C_INCLUDES := $(call project-path-for,recovery)].

- with your phone resolution like this width x height

- DEVICE_RESOLUTION := 720x1280

- if you want to use it with encrypted phone (it work with a non encrypted phone too but it will be smaller if you don't need decrypting function)

- BOARD_INCLUDE_CRYPTO := true

- if your phone is MTK powered you need this for the MTK menu (it is not mandatory though with the mtk phones shipped with lollipop or marshmallow)

- BOARD_HAS_MTK_CPU := true

- for touch menu, if your phone has an input driver with PROTOCOL_TYPE_B (synaptic is an example, or many samsung devices); if you have access to, check your kernel input driver for something like this [#define PROTOCOL_TYPE_B] - google it if you want to know more about this

- BOARD_USE_PROTOCOL_TYPE_B := true

- to block an input device use

- TOUCH_INPUT_BLACKLIST := "devicename"

- if you use Adopted Storage

- BOARD_USE_ADOPTED_STORAGE := true

For system.prop from device tree:

#
# system.prop for mx
#
ro.ctr.crypto.passwd="64656661756c745f70617373776f7264"
ro.ctr.forbid_format=/frp,/persistent,/lk,/uboot,/logo,/metadata,/nvdata,/nvram,/secro
ro.ctr.forbid_mount=/frp,/persistent,/lk,/uboot,/logo,/metadata,/nvdata,/nvram,/secro
ro.ctr.touch_accuracy=7

- to use decrypt data specify here your password (ro.ctr.crypto.passwd); I forgot to mention that if the phone uses encryption, the recovery will start with few seconds delay, because of the decrypting and mounting data process. If the message will tell you that couldn't be decrypted it is possible that your password was wrong or it uses an unsuported type of password. To be sure just restart the recovery from Power menu and if you still get the same message then you need to check your provided password from system.prop or to find a different solution (other recovery like twrp). If you want to decrypt your phone for good you need to format data and data media from Mount/Storage menu but you will loose your data (settings, preferences).

- ro.ctr.forbid_format and ro.ctr.forbid_mount are for partitions from fstab that you don't want to be shown in Mount/ Storage menu with mount and format option (coma separated, no spaces and with leading slash), like in my example above.

- ro.ctr.touch_accuracy to improve the touch handling (bigger lcd_density = bigger accuracy); the initial value is 7, just like in PhilZ Recovery, and I reccomend you to try different numbers to see what is right for you, but don't go over 19.

All these system.prop lines are not mandatory.

Carliv Touch Recovery uses a fstab version 1 named [ctr.fstab] and you have to create a folder recovery in your device tree, in that recovery folder create a new folder named root, in root folder another folder named etc and in that one place the ctr.fstab. Like this:

recovery/root/etc/ctr.fstab

That will be enough since the compiler will add it in recovery ramdisk and the recovery module will find it in etc folder.

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

# mount point	fstype device	[device2] fs_options [fs_options2] lun

/boot	emmc	/dev/block/platform/mtk-msdc.0/by-name/boot
/cache	ext4	/dev/block/platform/mtk-msdc.0/by-name/cache
/recovery	emmc	/dev/block/platform/mtk-msdc.0/by-name/recovery
/system	ext4	/dev/block/platform/mtk-msdc.0/by-name/system fs_options=rw
/data	ext4	/dev/block/platform/mtk-msdc.0/by-name/userdata fs_options=rw
/internal_sd	datamedia	/dev/null
/sdcard	vfat	/dev/block/mmcblk1p1	/dev/block/mmcblk1 lun=sys/class/android_usb/android0/f_mass_storage/lun/file

Important here is how you define internal storage which is data media

/internal_sd	[COLOR="Red"]datamedia[/COLOR]	[COLOR="Magenta"]/dev/null[/COLOR]

You can see It's used the old way with "datamedia" fstype and /dev/null device.

Important thing: if you have only internal storage define it as

/sdcard datamedia	/dev/null

If you have also an external sdcard, use either way:

/internal_sd	datamedia	/dev/null
/sdcard	vfat	/dev/block/mmcblk1p1	/dev/block/mmcblk1

or

/sdcard	datamedia	/dev/null
/external_sd	vfat	/dev/block/mmcblk1p1	/dev/block/mmcblk1

If you are using the adopted storage feature for external sd card, define this

/data_sd ext4 /dev/block/mmcblk1p2 fs_options=adopted

and remove or comment out the line for external sd card.

You can see the internal storage can be sdcard or internal_sd and external sdcard can be sdcard or external_sd, but internal storage can't be external_sd or external sdcard internal_sd.

If your phone has OTG support you can use that too defining it like this

/usb-otg	vfat	/dev/block/sda1	/dev/block/sda

or this

/usbdisk	vfat	/dev/block/sda1	/dev/block/sda

-check with your phone booted up in Android and a OTG USB mounted to see in [/sys/class/block] or [dev/block] how to set device for this (the dev/block/sdx part).

The recovery has fat32, exfat and ntfs support builtin (also f2fs for file system). You can define your usb-otg and/or external sdcard as "auto" instead of "vfat" and it will work with any of these formats. I tested a portable HDD self powered and it works (120 GB) as usb-otg. Anyway that is available only for zip and image flashing. Maybe I'll make it to work for backup and restore too.