[Miscellaneous Android Development] yuweng:
[GUIDE]

How to compile PhilZ Touch 6 Recovery

CWM Advanced Edition 6.x

With Part-Source using prebuilt kernel for any android devices

Intro

PhilZ Touch is developed by XDA Recognized Developer Phil3759, it is open source & you can compile it on your own.

Video Preview

You don't need to have a PHD in computer science to build from source.

This guide details the whole process for building PhilZ Touch recovery for MediaTek SoC & it should work on any other android devices that uses ARM architecture.

This guide's aim is to provide enthusiast who would like to try their hands on building PhilZ Touch from source but was turn off by the huge cm repo size. There are hundreds if not thousands of android devices that doesn't have CyanogenMod BUT you can still build PhilZ Touch recovery !

Many have no choice but to download full cm source & many has successfully built PhilZ Touch in spite of it.

As of today the month of Aug 2014, cm-11.0 repo has grow to 473 projects with the total of more than 12GB & this is only the compress hidden folder .repo

When the files are extracted, the whole ~/cm11 folder will be double the size !

Now you don't have to worry about that anymore, the projects for building PhilZ Touch has been identified & you only need 40 of the cm projects instead of the complete 473 & the size of .repo now for building PhilZ Touch is only 1.7GB. Conclusion, you don't need the extra 10.5GB from full source to build PhilZ Touch since your device doesn't have CyanogenMod !

Most important requirement : Willingness to learn, READ, continue reading, continue trying, stop asking questions all the time as most of your questions has already been answered, google it & most importantly, self-taught by looking at various example here. Look for the same SoC closes siblings to your device for recovery.fstab & BoardConfig.mk & compare it with yours.

However, when you have already gone through all that & still couldn't find an answer then ask or you'll never know . . . :laugh:

Always refer to the main thread here plenty of infos . . . :good:

Step 1

How to start

There are already plenty of guides so i won't touch on it, refer to the below on how to get started . . .

How to install Virtualbox on Windows

Download the latest x64 BBQLinux

Getting Started with BBQLinux

WARNING

Always make a backup of your device Factory ROM first with MTK Droid Root & Tools, my old guide here

Lock Bootloaders device then you can forget about building PhilZ Touch from source . . . :laugh:

Step 2

Syncing Part-Source

Updates

-> Refer to this post . . .

Download & unzip the script to your [HOME]. Start Mate Terminal & follow below command.

chmod 777 ~/PhilZ
./PhilZ [COLOR="Red"]<- Execute it by typing [COLOR="Blue"]dot forward-slash PhilZ[/COLOR][/COLOR]

Screenshot

View attachment 2920278

You can stop the script at any time by pressing Ctrl + z

To resume then execute the script again.

Misc Tips

Pls be patient, first sync will take quite awhile depending on your ISP

Screenshot of Part-Source script when finish syncing

View attachment 2920194

You can also drag & drop it from your host OS

View attachment 2918982

Pull your MTK device boot.img directly to BBQLinux then you have to enable the USB port on Virtualbox first.

View attachment 2918997

Check your MT65xx_Android_scatter.txt for boot or recovery partition size

- partition_index: SYS9
partition_name: BOOTIMG
file_name: [COLOR="blue"]boot.img[/COLOR]
is_download: true
type: NORMAL_ROM
linear_start_addr: 0x1DA0000
physical_start_addr: 0x1DA0000
partition_size: 0x[COLOR="blue"]A00000[/COLOR]
region: EMMC_USER
storage: HW_STORAGE_EMMC
boundary_check: true
is_reserved: false
operation_type: UPDATE
reserve: 0x00

- partition_index: SYS10
partition_name: RECOVERY
file_name: [COLOR="blue"]recovery.img[/COLOR]
is_download: true
type: NORMAL_ROM
linear_start_addr: 0x27A0000
physical_start_addr: 0x27A0000
partition_size: [COLOR="Blue"]0x1400000[/COLOR]
region: EMMC_USER
storage: HW_STORAGE_EMMC
boundary_check: true
is_reserved: false
operation_type: UPDATE
reserve: 0x00

You can also use adb shell cat /proc/dumchar_info to check too.

[COLOR="blue"]Part_Name	Size	StartAddr Type	MapTo[/COLOR]
bootimg 0x0000000000[COLOR="blue"]A00000[/COLOR] 0x0000000001DA0000 2 /dev/block/mmcblk0
recovery 0x000000000[COLOR="blue"]1400000[/COLOR] 0x00000000027A0000 2 /dev/block/mmcblk0

Use Calculator or Online Hex to Dec & convert it to decimal.

adb shell "dd if=/dev/[COLOR="Blue"]bootimg[/COLOR] of=/mnt/sdcard/[COLOR="blue"]boot.img[/COLOR] bs=[COLOR="blue"]10485760[/COLOR] count=1"
adb pull /mnt/sdcard/[COLOR="blue"]boot.img[/COLOR]
adb shell rm /mnt/sdcard/[COLOR="blue"]boot.img[/COLOR]
[COLOR="blue"]OR[/COLOR]
adb shell "dd if=/dev/[COLOR="blue"]recovery[/COLOR] of=/mnt/sdcard/[COLOR="blue"]recovery.img[/COLOR] bs=[COLOR="blue"]20971520[/COLOR] count=1"
adb pull /mnt/sdcard/[COLOR="blue"]recovery.img[/COLOR]
adb shell rm /mnt/sdcard/[COLOR="blue"]recovery.img[/COLOR]

Step 3

Setting up the files

Now that you have sync the Part-Source, you will need to use mkvendor.sh to generate the skeleton files for building PhilZ Touch.

Copy your device boot.img or recovery.img to [HOME]

mkvendor.sh will auto-generate eight files for your device needed for building PhilZ Touch

Screenshot of mkvendor.sh

View attachment 2920279

You need to edit the files as listed below only. Below are examples, do not copy & paste, refer to here & here.

Put all PhilZ Touch build flags at the bottom of the BoardConfig.mk under a heading of #PhilZ Touch build flags for easy reference

~/cm11/device/Lenovo/S939/BoardConfig.mk

USE_CAMERA_STUB := true

# inherit from the proprietary version
-include vendor/Lenovo/S939/BoardConfigVendor.mk

TARGET_ARCH := arm
TARGET_NO_BOOTLOADER := true
TARGET_BOARD_PLATFORM := unknown [COLOR="red"]<- Non-critical, you can either leave it as it is or change to any name[/COLOR]
TARGET_CPU_ABI := armeabi-v7a
TARGET_CPU_ABI2 := armeabi
TARGET_ARCH_VARIANT := armv7-a-neon
TARGET_CPU_VARIANT := cortex-a7 [COLOR="red"]<- Critical, either cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a15, krait, scorpion or generic[/COLOR]
TARGET_CPU_SMP := true
ARCH_ARM_HAVE_TLS_REGISTER := true

TARGET_BOOTLOADER_BOARD_NAME := S939

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 := [COLOR="Blue"]0x1400000[/COLOR] [COLOR="red"]<- Change this accordingly to your recovery size so that build will error when its oversize[/COLOR]
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_FLASH_BLOCK_SIZE := 131072

TARGET_PREBUILT_KERNEL := device/Lenovo/S939/kernel

BOARD_HAS_NO_SELECT_BUTTON := true

[COLOR="Blue"]#PhilZ Touch build flags for MTK[/COLOR]
TARGET_COMMON_NAME := Lenovo S939
BOARD_USE_MTK_LAYOUT := true
BOARD_MTK_BOOT_LABEL := "/bootimg"
BOARD_USE_NTFS_3G := false
BRIGHTNESS_SYS_FILE := "/sys/class/leds/lcd-backlight/brightness"
TARGET_USE_CUSTOM_LUN_FILE_PATH := "/sys/devices/virtual/android_usb/android0/f_mass_storage/lun%d/file" [COLOR="Red"]<- Credits to [B][COLOR="Black"]RD[/COLOR][/B] [URL="https://github.com/chrmhoffmann/android_device_wiko_stairway/blob/cm-11.0/BoardConfig.mk#L79"][U]chrmhoffmann[/U][/URL][/COLOR]
TARGET_SCREEN_HEIGHT := 1280
TARGET_SCREEN_WIDTH := 720
BOARD_CUSTOM_BOOTIMG_MK := device/Lenovo/S939/boot.mk [COLOR="Red"]<- Credits to [B][COLOR="Black"]RD[/COLOR][/B] [URL="http://xdaforums.com/showthread.php?t=2676086"][U]chrmhoffmann[/U][/URL]. [B][COLOR="Black"]MTK[/COLOR][/B] uses custom [COLOR="Blue"]mkbootimg[/COLOR][/COLOR]

~/cm11/device/Lenovo/S939/cm.mk

## Specify phone tech before including full_phone
$(call inherit-product, vendor/cm/config/gsm.mk)

# Release name
PRODUCT_RELEASE_NAME := S939

# Inherit some common CM stuff.
[COLOR="Red"]#[/COLOR]$(call inherit-product, vendor/cm/config/common_full_phone.mk) [COLOR="red"]<- Disable it to use this Part-Source or ERROR 1. You don't need this for building [COLOR="blue"]PhilZ Touch[/COLOR][/COLOR]

# Inherit device configuration
$(call inherit-product, device/Lenovo/S939/device_S939.mk)

## Device identifier. This must come after all inclusions
PRODUCT_DEVICE := S939
PRODUCT_NAME := cm_S939
PRODUCT_BRAND := Lenovo
PRODUCT_MODEL := S939
PRODUCT_MANUFACTURER := Lenovo

~/cm11/device/Lenovo/S939/recovery.fstab

# 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

/dev/bootimg /bootimg emmc defaults defaults
/dev/recovery /recovery emmc defaults defaults
/dev/uboot /uboot	emmc defaults defaults
/emmc@android /system ext4 ro,noatime wait
/emmc@cache /cache ext4 noatime,nosuid,nodev,noauto_da_alloc wait
/emmc@usrdata /data ext4 noatime,nosuid,nodev,noauto_da_alloc wait,encryptable=footer

/devices/platform/mtk-msdc.0/mmc_host/mmc0 auto vfat defaults voldmanaged=sdcard0:[COLOR="Blue"]4[/COLOR] [COLOR="red"]<- Change accordingly to your [B][COLOR="Black"]MTK[/COLOR][/B] fat partition no.[/COLOR]
/devices/platform/mtk-msdc.1/mmc_host/mmc1 auto vfat defaults voldmanaged=sdcard1:auto

~/cm11/device/Lenovo/S939/device_S939.mk

$(call inherit-product, $(SRC_TARGET_DIR)/product/languages_full.mk)

# The gps config appropriate for this device
[COLOR="Red"]#[/COLOR]$(call inherit-product, device/common/gps/gps_us_supl.mk) [COLOR="Red"]<- Disable it to use this Part-Source or ERROR 1.[/COLOR]

$(call inherit-product-if-exists, vendor/Lenovo/S939/S939-vendor.mk)

DEVICE_PACKAGE_OVERLAYS += device/Lenovo/S939/overlay

LOCAL_PATH := device/Lenovo/S939
ifeq ($(TARGET_PREBUILT_KERNEL),)
LOCAL_KERNEL := $(LOCAL_PATH)/kernel
else
LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
endif

PRODUCT_COPY_FILES +=
$(LOCAL_KERNEL):kernel

$(call inherit-product, build/target/product/full.mk)

PRODUCT_BUILD_PROP_OVERRIDES += BUILD_UTC_DATE=0
PRODUCT_NAME := full_S939
PRODUCT_DEVICE := S939

[STRIKE][COLOR="Blue"]#PhilZ Touch[/COLOR]
PRODUCT_COPY_FILES +=
$(LOCAL_PATH)/recovery.fstab:recovery/root/fstab.[COLOR="blue"]mt6592[/COLOR] [COLOR="Red"]<- adb shell getprop ro.hardware to identify it.[/STRIKE][/color]

Updates

Above PRODUCT_COPY_FILES doesn't work anymore, just create a new folder recovery/root at your device tree & copy fstab.${ro.hardware} to it & it'll auto copy fstab.${ro.hardware} to root of ramdisk . For this Eg. : ~/cm11/device/Lenovo/S939/recovery/root/fstab.mt6592. Credits : Master Shifu Carliv

Custom mkbootimg

~/cm11/device/Lenovo/S939/boot.mk

Credits to

Chris Hoffmann

AKA RD

chrmhoffmann

, now you can automate the whole build process, no need to unpack/ repack after building !

define make_header
perl -e 'print pack("a4 L a32 a472", "x88x16x88x58", $$ARGV[0], $$ARGV[1], "xFF"x472)' $(1) $(2) > $(3)
endef

$(recovery_ramdisk).mtk.header: $(recovery_ramdisk)
size=$$($(call get-file-size,$(recovery_ramdisk)));
$(call make_header, $$((size)), "RECOVERY", $@)
$(recovery_ramdisk).mtk: $(MKBOOTIMG) $(recovery_ramdisk).mtk.header
$(call pretty,"Adding MTK header to recovery ramdisk.")
cat $(recovery_ramdisk).mtk.header $(recovery_ramdisk) > $@

INTERNAL_MTK_RECOVERYIMAGE_ARGS :=
--kernel $(PRODUCT_OUT)/[COLOR="Blue"]kernel[/COLOR]
--ramdisk $(recovery_ramdisk).mtk

$(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTIMG)
$(recovery_ramdisk).mtk $(PRODUCT_OUT)/[COLOR="Blue"]kernel[/COLOR]
@echo -e ${CL_CYN}"----- Making recovery image ------"${CL_RST}
$(MKBOOTIMG) $(INTERNAL_MTK_RECOVERYIMAGE_ARGS)
$(BOARD_MKBOOTIMG_ARGS) --output $@
$(hide) $(call assert-max-image-size,$@,
$(BOARD_RECOVERYIMAGE_PARTITION_SIZE),raw)
@echo -e ${CL_CYN}"Made recovery image: $@"${CL_RST}

Step 4

Start Building it !

Below are the commands to build, thats it !

cd ~/cm11
export USE_CCACHE=1
prebuilts/misc/linux-x86/ccache/ccache -M 50G
source build/envsetup.sh
lunch cm_[COLOR="Blue"]S939[/COLOR]-eng [COLOR="Red"]<- Change accordingly to your [COLOR="Blue"]device_name[/COLOR][/COLOR]
make -j8 recoveryimage

Video Preview

Misc Tips

First build will take quite awhile, pls be patient however subsequence build will be quick b'cos of ccache.

if you hate cli like i do then you can automate it, no need to type it every time since you are building for the same device that you own.

View attachment 2935830

Use geany & fill in the commands accordingly to your device.

View attachment 2935831

Make it executable by right-click at the file name -> Properties -> Permissions -> Put a Tick at Allow executing file as program. Execute it by typing ./s939 or whatever your file name is.

GNU make

GNU make can handle parallel tasks with a -j# argument.

make -j[COLOR="Blue"]#[/COLOR] recoveryimage

Replace the # with the core count +1, so if you have a dual core it's -j3 and a quad core becomes -j5, etc.

Above is applicable for Native-Boot, on Virtualbox -j8 will work even if you have the old Pentium II except your host OS will lag.

make -j8 recoveryimage 2>&1 | tee ~/Documents/compile.log

You can also use above command so that you can refer to the compile.log for error checking.

Subsequent Build

Refer to post #2 -> Misc Tips -> Make clean before each recompiling or your flag changes will not be picked up !

Step 5

Push it directly to your device

Screenshot of Build Completed

View attachment 2920729

Screenshot of adb push

View attachment 2920732

adb push ~/cm11/out/target/product/[COLOR="red"]S939[/COLOR]/recovery.img /mnt/sdcard
adb shell "dd if=/mnt/sdcard/recovery.img of=/dev/recovery"
adb reboot recovery

Misc Tips

You can also use Flashify or Mobileuncle to install it too.

Congrats, now you have compiled & install PhilZ Touch to your MTK device . . . :good:

Notes about 4.4 Kit Kat ROMs and SELinux

Mostly new android devices doesn't provide kernel source so you need to unpack your stock recovery or stock ROM, manually copy file_contexts, property_contexts & seapp_contexts to replace the one at PhilZ Touch, repack it back to fully support SELinux backup & restore.

No need to replace sepolicy as this binary is built with the latest source. On top of that, sepolicy from stock recovery.img mostly are oudated & the size is huge compare to the one from PhilZ Touch but that is entirely up to you whether to use either one.

XDA members that has success in building PhilZ Touch for any other android devices please share your experience & tips here too so that this will help out others when they face the same problem . . . :good:

Source

Confirmed working PhilZ Touch using this guide

(mkvendor.sh technique)

All MediaTek(MT65xx) devices

LG L90(msm8226) thanks to shoxxy

Hopefully with this guide, many will be able to kick-start development & port a working PhilZ Touch to their android devices. :cool:

Updates 09 April 2016

Its been awhile i've never build PhilZ Touch & as Phil3759 says, her source is solid rock & can be build to support many legacy devices & also new devices too, there has been confirmation that it still works on Android-6.0 Marshmellow too... :good:

Only found out that it doesn't build today & since Phil3759 has retired from this project, as usual, you'll need to revert commits to make it build again.... :cowboy:

cd ~/cm11/system/core
git revert --no-edit [URL="https://github.com/CyanogenMod/android_system_core/commit/6bac0a9fedc711a7dfacd6865ec4923dd332182b"]6bac0a9fedc711a7dfacd6865ec4923dd332182b[/URL]

XDA:DevDB Information

Compile PhilZ Touch from source using BBQLinux Distro, Tool/Utility for all devices (see above for details)

Contributors

yuweng, Phil3759

Source Code: https://github.com/PhilZ-cwm6/philz_touch_cwm6

Version Information

Status: Stable

Current Stable Version: 6.59.0

Stable Release Date: 2014-10-14

Created 2014-08-30

Last Updated 2016-04-08