[Miscellaneous Android Development] nasreirma:
Hello everybody

this is my guide to port a device tree ans vendor blobs to your device so that you can compile custom ROMs from source without porting

This is not a complete guide that will work on all devices and fix all bugs keep it in mind

So lets start

First i want to thank all of my friends that helps me starting from Syed Ahmed Ali Shah , [MENTION=4557311]izaq[/MENTION] Kull , @Coulibaly Nonta , Ahmed Rahmy , [MENTION=1253539]Roman Y[/MENTION]uskovsky , [MENTION=5593584]hyperion70[/MENTION] , [MENTION=376228]lenovo[/MENTION]ved , John Gothi , [MENTION=283382]ROCK[/MENTION] rok , Dennis M Wachira , Zakaria Re RE , and many more

Without these wonderful guys up here i would never reach that so Thank you Guys

And please know that this guide costs me a lot of time and efforts to write it and i tried to explain every single step to make it clear

SO PLEASE DO NOT STEAL THIS GUIDE OR SHARE IT IN YOUR BLOG OR WEBSITE WITHOUT MY PERMISSION

1- Porting will be more easier if you can find a device with the same CPU same architecture that already have a device tree

2- If you find a device that verify the reqirements try to port a rom compiled with this device tree and fix bugs as much as possible

3- if porting was successful and the rom boots you need to remember every change you made because we will need it to adapt this device tree to our device

4- Some softwares needs to be installed on your computer for me the most important ones are

- Superrs kitchen if you have Ubuntu installed it is useful to unpack repack ROMs

- Assayed kitchen for Windows if you dont have ubuntu

- Notepad ++ for editing Files

- Winmerge for comparing files and folders

- File Seek for searching inside of files

here are the Device tree and Vendor Blobs links used in this porting

Device Tree : https://github.com/nasreirma/X571-test.git

Vendor Blobs : https://github.com/nasreirma/android_vendor_Infinix_X571.git

If you did all the steps and save all the files replaced and all the files edited now were good to go to modifying device tree to adapt it to our device

As example I will try to port Infinix NOTE 4 Pro device tree to Infinix S2 Based on Nougat 3.18.35+ 64-bit

Both of the devices are MT6753 so it will be more easier

I tried to port a ROM compiled for the Infinix NOTE 4 Pro to the S2 and it was successful but I face some Bugs and i will try to explain how to solve them Later

So i made some changes in 3 ompenents of the ROM wich is

- System Files

- Boot.img

- Build.prop

For System files i copy the changed files to vendor directly and overwrite them

For Boot.img i did replace he prebuilt kernel and changed some files in the ramdisk so i just look for the kernel in the device tree and I replace it and for the ramdisk files I make the same changes in the "rootdir" directory wich it contains ramdisk files

And for build.prop we need to make changes all over the device tree and vendor blobs so i need just to take a few lines from my build.prop and then i will explain file by file

the lines to take from your build.prop are

ro.product.model=Infinix S2

ro.product.brand=Infinix

ro.product.device=Infinix-X522

ro.product.name=H539

ro.product.manufacturer=Infinix

ro.board.platform=mt6753

ro.build.description=full_rlk6753_65_n-user 7.0 NRD90M 1502824225 release-keys

ro.build.fingerprint=Infinix/H539/Infinix-X522:7.0/NRD90M/X522-H539A-N-170816V187:user/release-keys

ro.mediatek.platform=MT6735

mediatek.wlan.chip=CONSYS_MT6735

mediatek.wlan.module.postfix=_consys_mt6735

ro.rlk_project=x522

After we get these lines we write our device tree path wich is "device/manufacturer/project_name" wich is in my case "device/Infinix/X522"

now we open the device tree and i will tell you wich file you need to modifying

I will not touch these folders "cmhw,EngineerMode,include,Mediatek,power,ril,seccomp,wifi_hal,wpa_supplicant_8_lib,YGPS"

we open bluetooth/bdroid_buildcfg.h

we change that line

#define BTM_DEF_LOCAL_NAME "Infinix NOTE 4 Pro"

to

#define BTM_DEF_LOCAL_NAME "Infinix S2" (check ro.product.model)

Lets move to "overlay" folder

the only fie that i will change is "overlay/frameworks/base/core/res/res/xml/power_profile.xml"

i will change this line " <item name="battery.capacity">5000</item>"

this line is designed for battery capacity do change with your device capacity

then we will move on patches folder

i will change these 2 files "apply-patches.sh,check-patches.sh"

i will change only the device path form "device/Infinix/X571" to "device/Infinix/X522" in these 2 files

then "prebuild folder

i will change only the kernel to my stock kernel

then "rootdir" folder

you need to apply the changes you did earlier on ramdisk into this folder if you add or delete a file you need to mention it in the device make file to avoid errors during compiling (i will explain when we move to the file)

were done with the folders lets move to the files inside

starting with "Android.mk"

we change that line "ifeq ($(TARGET_DEVICE),X571)" with our device project name wich it is in my case "ifeq ($(TARGET_DEVICE),X522)"

For "AndroidBoard.mk"

if you have got kernel source and you want to use it comment this line "ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET)"

if not just leave it and dont change anything in this file

For "BoardConfig.mk"

first we need to change the device path and vendor path whenever we found it in this file

in my case its present in hese 4 lines

DEVICE_PATH := device/Infinix/X571

VENDOR_PATH := vendor/Infinix/X571

BOARD_RIL_CLASS := ../../../device/Infinix/X571/ril/

BOARD_SECCOMP_POLICY += device/Infinix/X571/seccomp

so we change to

DEVICE_PATH := device/Infinix/X522

VENDOR_PATH := vendor/Infinix/X522

BOARD_RIL_CLASS := ../../../device/Infinix/X522/ril/

BOARD_SECCOMP_POLICY += device/Infinix/X522/seccomp

lets move to "# Architecture" Part

if you have a 32-bit device and you want to port a my 64-bit device tree you need to uncomment this line "#FORCE_32_BIT := false"

uncomment means to delete "#" and thats it

for 32-bit you need to make more changesso its better to take from a 32-bit device and i will explain how to adapt to 32-bit from 64-bit so dont worry

for "# Platform"

we change that line to our device platform "TARGET_BOARD_PLATFORM := mt6753" better port from a device with the sae platform but its possible to port between mt653/mt6735/mt6737m

since is the same platform for me i will leave it

same for "# Bootloader"

TARGET_BOOTLOADER_BOARD_NAME := mt6753

for "# Kernel"

if you have a prebuilt kernel and want to use prebuilt kernel dont touch anything

if you want to use kernel sources you need to delete this line "TARGET_PREBUILT_KERNEL := $(DEVICE_PATH)/prebuild/kernel"

and add this lines

if you have 32-bit add this after "ifeq ($(FORCE_32_BIT),true)" and before "else"

BOARD_KERNEL_IMAGE_NAME := zImage-dtb

TARGET_KERNEL_CONFIG := rlk6753_n_defconfig (change to your device defconfig)

TARGET_KERNEL_SOURCE := kernel/Infinix/X522

if you have 64-bit add this after "else" and before "endif"

BOARD_KERNEL_IMAGE_NAME := Image.gz-dtb

TARGET_KERNEL_CONFIG := rlk6753_n_defconfig (change to your device defconfig)

TARGET_KERNEL_SOURCE := kernel/Infinix/X522

for "# Assert"

change this line "TARGET_OTA_ASSERT_DEVICE := X571,Infinix NOTE 4 Pro,H5311,Infinix-X571" you can refer to the lines that we took from build.prop

and thats it for BoardConfig.mk

lets move to "full_X571.mk"

first we rename it to "full_X522.mk" (refer to the device project name)

and then we open it to modify it

as "BoardConfig.mk" we will change device paths

LOCAL_PATH := device/Infinix/X571 to LOCAL_PATH := device/Infinix/X522

$(call inherit-product-if-exists, vendor/Infinix/X571/X571-vendor.mk) to $(call inherit-product-if-exists, vendor/Infinix/X522/X522-vendor.mk)

DEVICE_PACKAGE_OVERLAYS += device/Infinix/X571/overlay to DEVICE_PACKAGE_OVERLAYS += device/Infinix/X522/overlay

PRODUCT_PACKAGE_OVERLAYS += device/Infinix/X571/overlay to PRODUCT_PACKAGE_OVERLAYS += device/Infinix/X522/overlay

for 32-bit change

$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk) to $(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)

for "# Dalvik/HWUI"

$(call inherit-product-if-exists, frameworks/native/build/phone-xxhdpi-3072-dalvik-heap.mk)

$(call inherit-product-if-exists, frameworks/native/build/phone-xxhdpi-3072-hwui-memory.mk)

we will change only xxhdpi and 3072

since my S2 is xhdpi i will change it to that

and since it is 2GB RAM i will change 3072 to 2048 if you have 3GB or more RAM just leave it 3072

same for "# set locales & aapt config."

PRODUCT_AAPT_CONFIG := normal xhdpi xxhdpi

PRODUCT_AAPT_PREF_CONFIG := xxhdpi

for these 2 lines change to your default country language and region for me its Morocco "MA" and french "fr"

PRODUCT_DEFAULT_LANGUAGE := fr

PRODUCT_DEFAULT_REGION := MA

for "# Ramdisk"it depends on your changes to the "rootdir" directory if you add a file mention here if you delete delete this line

do as example i added a file named "example" so i will add this line

" $(LOCAL_PATH)/rootdir/example:root/example "

for " power.mt6753" or any file with mt6753 change with your platform

like if i have mt6737m platform i will change that line to " power.mt6737m"

this line is for device density

"	ro.sf.lcd_density=480 " i will change to 320 since my S2 density is 320

for those lines here

PRODUCT_BUILD_PROP_OVERRIDES += PRODUCT_NAME=H5311

PRODUCT_BUILD_PROP_OVERRIDES += PRODUCT_MODEL="Infinix NOTE 4 Pro"

PRODUCT_BUILD_PROP_OVERRIDES += PRODUCT_BRAND=Infinix

PRODUCT_BUILD_PROP_OVERRIDES += PRODUCT_DEVICE=Infinix-X571

PRODUCT_BUILD_PROP_OVERRIDES += BUILD_FINGERPRINT=Infinix/H5311/Infinix-X571:7.0/NRD90M/X571-H5311A-N-170701V151:user/release-keys

PRODUCT_BUILD_PROP_OVERRIDES += PRIVATE_BUILD_DESC="full_rlk6753_65_n-user 7.0 NRD90M 1498916323 release-keys"

refer to the lines that you took earlier from build.prop

and were done from full_X522.mk

lets move to "lineage.mk"

for "# Release name"

PRODUCT_RELEASE_NAME := Infinix NOTE 4 Pro

I will change to

PRODUCT_RELEASE_NAME := Infinix S2

for "# Inherit device configuration"

$(call inherit-product, device/Infinix/X571/full_X571.mk)

I will change to

$(call inherit-product, device/Infinix/X522/full_X522.mk)

for those 3 lines

TARGET_SCREEN_HEIGHT := 1920

TARGET_SCREEN_WIDTH := 1080

DEVICE_RESOLUTION := 1080x1920

change to your device weight and width for me its 1280x720

so it will be

TARGET_SCREEN_HEIGHT := 1280

TARGET_SCREEN_WIDTH := 720

DEVICE_RESOLUTION := 720x1280

for "# Device identifier. This must come after all inclusions"

PRODUCT_DEVICE := X571

PRODUCT_NAME := lineage_X571

PRODUCT_BRAND := Infinix

PRODUCT_MODEL := Infinix NOTE 4 Pro

PRODUCT_MANUFACTURER := Infinix

change to your device infos (refer to build.prop)

so it will be

PRODUCT_DEVICE := X522

PRODUCT_NAME := lineage_X522

PRODUCT_BRAND := Infinix

PRODUCT_MODEL := Infinix S2

PRODUCT_MANUFACTURER := Infinix

for "PRODUCT_GMS_CLIENTID_BASE := android-Infinix" change to your device manufacturer like if you have tecno must change to "PRODUCT_GMS_CLIENTID_BASE := android-tecno"

and for "# Available languages"

PRODUCT_LOCALES := fr_MA ar_MA ru_RU en_US en_AU en_IN fr_FR it_IT es_ES et_EE de_DE nl_NL cs_CZ pl_PL ja_JP zh_TW zh_CN zh_HK ko_KR nb_NO es_US da_DK el_GR tr_TR pt_PT pt_BR sv_SE bg_BG ca_ES en_GB fi_FI hi_IN hr_HR hu_HU in_ID iw_IL lt_LT lv_LV ro_RO sk_SK sl_SI sr_RS vi_VN tl_PH ar_EG fa_IR th_TH sw_TZ ms_MY af_ZA zu_ZA am_ET en_XA ar_XB fr_CA km_KH lo_LA ne_NP si_LK mn_MN hy_AM az_AZ ka_GE my_MM mr_IN ml_IN is_IS mk_MK ky_KG eu_ES gl_ES bn_BD ta_IN kn_IN te_IN uz_UZ ur_PK kk_KZ sq_AL gu_IN pa_IN be_BY bs_BA

add or delete whatever language you want

thats all for lineage.mk

for system.prop refer to your build.prop and change from your stock

for MANUAL.md and README.md just bunch of files to specify for wich device is device tree and the compiling instructions

and finally "vendorsetup.sh"

just change this line " add_lunch_combo lineage_X571-$var" to your device project name

so for me it ill be

" add_lunch_combo lineage_X522-$var"

and thats it for the device tree

lets move to the vendor blobs now

first replace all the files you already used for porting the rom and overwrite any

then lets move to the files

for "Android.mk"

change only that line

ifneq ($(filter X571, $(TARGET_DEVICE)),)

to your device project name

ifneq ($(filter X522, $(TARGET_DEVICE)),)

For "X571-vendor.mk" rename it to "X522-vendor.mk" (always device project name"

and change paths from "vendor/Infinix/X571" to "vendor/Infinix/X522"

and if you add a folder add the line as well in this file

and Hola finally we finished porting the device tree and vendor blobs

we can start now building our first ROM for our device

Now after i did all of that i found 3 Major Bugs on my ROM for the S2

wich are

- Camera

- Fingerprint

- Video Recording (after fixing Camera)

so for Camera i replaced all files responsible for camera exept "libcam.client.so" wich it causes bootloop

do what did i do is taking a logcat and analyse it (before booloop)

so i found i symbol missing (its present only in libcam.client.so"

so if you suufer from the same issue and found a missing symbol

you need to copy that symbol

in my case it was "_ZN7android16CameraParameters20KEY_APP_PACKAGE_NAMEE" it may change according to the device

and i add this line that contains the symbol to "mtk_symbols/mtk_cam.cpp"

void _ZN7android16CameraParameters20KEY_APP_PACKAGE_NAMEE () {

}

between the "extern "C" {" and the final "}"

so camera got fixed

for fingerprint i didnt fix it yet but the problem in "sepolicy" folder need to add some lines in order to make it work

and for video recording i didnt manage to fix it but i will try to

So thats all hope that this guide helps you porting a device tree for your devices