[Android Software/Hacking General [Developers Only]] K001droid:
ALL IN ONE PORTING GUIDE

by [MENTION=7174278]kuberrocks96[/MENTION]

/*
* Your warranty is now void.
*
* I am not responsible for bricked devices, dead SD cards,
* thermonuclear war, or you getting fired because the alarm app failed. Please
* do some research if you have any concerns about features included in this ROM
* before flashing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you.
*/

INDEX:

GUIDE FOR MTK

MTK BUG FIXING

RECOVERY PORTING

QUALCOMM BUG FIXING

Update

:-

*Updated Bug Fix Guide for MTK
*Added SNAPDRAGON Bug fix guide.
*Guide to port TWRP also updated.
*Improved the thread.
*Added more fixes.
*Qualcomm porting guide added.

This is for all those users who want to port roms and use them in their devices.

But , before porting any rom,here are some of the main things you should keep in mind.

1)Base Rom :-

What is a Base Rom?

Base Rom is reffered to the Stock rom or the Default Rom of your device or sometimes the rom from which you will take base files(libs,apns,modem etc).

2)Port Rom

What is a Port Rom?

Port Rom is the rom which you will port for your device.
like if you are working a rom of another device having similar specifications and porting it for your device then it is called PORT ROM.

3)Kernel

What is a Kernel?

The kernel is a computer program that is the core of a computer's operating system, with complete control over everything in the system.
the central or most important part of something
In easy words kernel acts as the middle man between the Software and the Hardware

When porting a rom , you should check the Kernel version of the Port Rom and the Base Rom

They both should be similar,

like you can port from :

3.18.xx to 3.18.xx only

3.10.xx to 3.10.xx only

BUGS IN THE BASE ROM OR IN THE PORT ROM.

Yes , our Base Rom and the Port roms may contain bugs,

Those bugs will exist in our final Ported Rom also so , fixing those is not possible - Its always recommended to use a Stable or near to Stable Roms but hi, Custom Roms are made for pleasure only and these roms can't take place of stock roms.

Many users don't like Stock Rom (i.e Default Rom) so , they look for a Custom Rom.

Now let's talk about the main topic for which YOU ARE HERE!

PORTING A ROM!

In this Guide, i will tell one of the most easy way to BOOT UP THE ROM.

So, lets begin,

This guide will focus on MT6735/MT6753 porting.

Device i used is Coolpad Note 3 Lite

CPU:MT6735

But, it will work mostly on all MT675X SoCs , this can also be useful for MT67XX series but , My main focus is on MT675X

Without any delay let's talk about how you should port a ROM and what should be your focus at

YOU SHOULD FOCUS ON BOOTING THE ROM INSTEAD OF BUG FIXING AND DOING OTHER THINGS.

WHEN YOU PORT A ROM CHANGE FILES WISELY

DONT JUST COPY PASTE

PORTING A ROM CAN GET TOUGH ACCORDING TO THE ROM, LIKE PORTING AN AOSP BUILD CAN BE EASY BUT PORTING A MIUI BUILD IS CONSIDERED ONE OF THE MOST TOUGHED AND IRRITATING THING.

RESPECT THE EFFORTS BY THE PREVIOUS DEV.

CREDITS, WHEN YOU PORT A ROM THAT ROM WAS MADE BY SOMEONE , PORTED BY SOMEONE or BUG FIXED BY SOMEONE - SO BY ANY MEANS IF YOU KNOW THE SOURCE AND THE DEV OR TEAM WHOSE BUILD YOU ARE PORTING PLEASE GIVE CREDIT.

THANKS.

NOW , FINALLY. LET'S TALK ABOUT THE PORTING GUIDE WHICH YOU ALL ARE WAITING FOR.

What you guys need:-

1)Base Rom
2)Port Rom
3)Any good Notepad
4)Any Boot.img repack or unpack tool
5)Brain

Now , if you have all the above mentioned things , Lets proceed.

BOOT.IMG :-

BOOT.IMG contains all the magic , it has the KERNEL inside which is one of the main thing.

Porting from Same CPU & GPU:-

NOTE:- When you are porting from a Similar device having same chipset like porting from:-

MT6753 TO MT6753

MT6735 TO MT6735

Use this method (95% times working ):-

System/lib & lib64 :-

libaudiocomponentengine.so
libaudiocustparam.so
libnvram.so
libnvramagentclient.so
libnvram_platform.so
libnvram_sec.so
libcustom_nvram.so

System/etc :-

/Firmware folder
/apnconfig
/spnconfig
/agps_profile_conf2
/media_codecs.xml

BLACK SCREEN AFTER LOGO???

REPLACE THIS LIB:- libcam.paramsmgr

To Fix Camera ( sometimes bootloop so try one by one ) :-

from System/lib & lib64 replace all libs starting like this:-

libcamera.mt6735 (mt6735 is according to my CPU )

libcameracustom.lib etc
libcamalgo.lib

Unpack Boot.img of both Base & Port Rom

replace kernel
and init.mt6735.rc ( not recommended always)
and Fstab.mt6735

System/Lib(/64)/HW*

Done , Now zip em and flash.

90% Rom will boot with BUGS! ( NO ROM IS THERE WITHOUT BUGS, LOL)

==>READ BUG FIX METHOD ALSO{Later in this Guide}<==

For Cross Porting Like:-

MT6752 etc to MT6753/MT6735

DO REMEMBER TO CHANGE :-

System/xbin/mnld
System/mddb
System/etc/firmware
System/etc/Apnconf
System/etc/spnconf

In lib(/64)/HW :- add files accordingly to your CPU or rename them.

BLACK SCREEN AFTER LOGO :-

libcam.paramsmgr

BOOT.IMG PORTING:-

UNPACK both Base Rom and Port Rom Boot.img

In PORT ROM BOOT.IMG:-

replace the boot.img-kernel

and in ramdisk folder add these files from Base Boot.img to Port Boot.img

fstab.mt6735
init.mt6735.rc
init.mt6735.usb.rc

Note:- Name may differ a little according to your CPU

REPACK THE BOOT IMAGE

NOTE:- If u get WIFI AND BLUETOOTH NOT SWITCHING ON OR BATTERY PERCENTAGE THEN REPLACE

init.project.rc

Done , You have succesfully ported Boot.img

Now , Lets focus on BUG FIXING

Bug Fixing isnt easy as it seems.

Replacing any wrong file or not supported file can easily give you bootloops.

It depends from ROM to ROM.

BUG FIXING[MTK]

Let's Begin.

If any lib missing in Base leave that - DONT WORRY

NOTE:- CHANGE LIB FILES FROM BOTH lib & lib64 folders

If you face "This rom is for Coolpad Note 3 Lite and your device is "K4Note"

To remove this delete the assertlines in Updater-script

ALWAYS CHANGE DPI IN BUILD.PROP ACCORDING TO YOUR STOCK ROM

Bootloop when porting

*libandroid_runtime.so
*libandroid_servers.so
*libmedia_jni.so

*Repack boot.image (properly)

RadioFM

\system\bin\fmradio
\system\etc\firmware\mt6620_patch_e3_hdr.bin
\system\etc\firmware\mt6620_patch_e6_hdr.bin
\system\etc\firmware\WMT.CFG
\system\lib(/64)\libfmcust.so
/system/lib(/64)/libfmjni.so

Sensors

/system/bin/akmd*
/system/lib/libsensors.so
/system/lib/libms3c_yamaha.so ( acc. To device)
/system/etc/firmware (folder)
/system/bin/servicemanager
/system/bin/sensorservice
System/bin/msensord

system/etc/permissions/:-
android.hardware.sensor.xxxxx.xml

FIX Offline charging:-

In Boot.img -> sbin/healthd

System/Lib(/64):-
Showlogo

System/bin:-
Kpoc_charger

Bluetooth\Wifi not turning On\Off(old)

\system\lib\module\mtk_stp_wmt

Wifi

/system/etc/wifi (folder)

/system/bin/netcfg
/system/bin/dhcpcd
/system/bin/ifconfig
/system/bin/hostap
/system/bin/hostapd
/system/bin/hostapd_bin
/system/bin/pcscd
/system/bin/wlan*
/system/bin/wpa*

/system/lib(/64)/libhardwarelegacy.so

Hotspot:-

/system/bin/netd

*follow Wifi fix also*

Camera

firstly try one by one:
\system\lib(/64)\libcameracustom.so
\system\lib(/64)\libcameraservice.so
System/lib(/64)/camalgo
/system/etc/media_profiles.xml
/system/lib(/64)/libcamera.so
/system/lib(/64)/liboemcamera.so
\system\lib(/64)\hw\camera.default.so
\system\lib(/64)\libcamera_client.so
\system\lib(/64)\libcamer aprofile.so
\system\lib(/64)\libmhal.so
\system\lib(/64)\libmhalcontent.s o
\system\lib(/64)\libmhaldrv.so
\system\lib(/64)\libmhalmdp.so
\system\lib(/64)\libmhalpipe.so
\system\lib(/64)\libmhalscenario.so
\system\lib(/64)\libmhalutility.so
\system\etc\permission\android.hardware.camera.front.xml

Other cam files if any

*try one by one*

CamCoder/HwDecoder

\system\lib\libOmx*.so
system/etc/media_codecs

[SIZE="3"][B]Green/pink Camera / video lagging[/B][/SIZE]
system/lib(/64)/libdpframework.so

SD card/Memory

mt67**.fstab in boot.img

/system/bin/vold
/System/bin/pq

System/bin/sdcard

WhatsApp Media Fix:-

from System/bin/ replace these files:-
Media
mediaserver
netd
service
servicemanager
surfaceflinger

GPS

\system\xbin\libmnlp
/system/etc/gps.conf

Touch Screen(Haptic)

/system/usr
/system/usr\keylayout\Generic.kl ->fix HomeKey

NFC ( experimental)

System/etc/: Nfc files
System/etc/permissions/ nfc files
System/lib/libnfc****** ( all starting from nfc )

Sim1/2 (RIL)

((Trustbin.bin flash it accordingly to LP or MM etc of stock rom))

\system\etc\firmware\modem.img
\system\etc\permission (RIL)

Try these aswell if ( you may suffer Bootloop )

/System/bin/mtkrild
/System/bin/mtkrildm1

/system/bin/stmd

EXPERIMENTAL FIX for ril:-

System/ Lib(/64)/ :-
Nvram
Nvram_sec
Nvram_platform
Nvrammagentclient

System/bin:-
Gsm***

System/etc/trustzone

Lib(/64):-
Libril
Libc2k***
Librilmtk

Audio/Sound:-

\system\lib\libaudio* .so
system/lib(/64)/libaudiocustomparam
system/lib(/64)/libaudiopolicymanager
system/lib(/64)/libaudiopolicyservice
system/etc/audio_effects
system/etc/audio_policy
System/lib(/64)/soundfx

Sometimes if Sound isn't working fully :::::

System/lib(/64)/hw/audioxxxxxxxxx (audio files)

Bluetooth:-

system/etc/bluetooth
System/etc/permissions/android.hardware.bluetooth.xml

/system/bin/uim*
/system/bin/bluetooth*
/system/lib(/64)/libbluetooth_mtk.so
/system/lib(/64)/libbluetoothem_mtk.so

Ads

/system/etc/hosts ->replace with new files or use tweak.

=====>>ADVANCE BUG FIXING:-

Volte Fixing

( Will only work if your Base Rom , Port Rom and Kernel supports VOLTE )

Boot.img:-
Zimage ( kernel - volte supported )
init.volte.rc

==THIS SHOULD NORMALLY FIX but if it doesn't try :- ==

System Folder:-
bin/volte_stack
bin/volte_imcb
bin/volte_ua

lib(/64)/volte_imsm

build.prop(Not always required):-

ro.mtk_volte_support=1
persist.mtk.volte.enable=1

FingerPrint:-

[Try one by one][If any file missing leave it]

Usual way to fix :-

System/etc/permissions/android.hardware.fingerprint.xml
System/lib(/64)/libgatekeeper.so
System/lib(/64)/hw/gatekeeper.mt6735.so
System/(/64)/libmcgatekeeper.so

System/lib(/64)/hw/fingerprint.default.so ( can break FP in some devices)

Advanced ( if usual doesn't work ):-

System/bin/:-
fingerprintd
Gx_fpd
tee_deamon

Lib64/lib:- ( if any missing leave that)
Fpclient
Fpalgorithm
Fphal
FPservice

IF ROM DOESNT BOOT TAKE LOG ( From ADB)

adb shell logcat > log.txt

and check what is causing issue

REFERENCE LINKS :-

Carliv Image Kitchen :-

https://xdaforums.com/android/development/tool-cika-carliv-image-kitchen-android-t3013658

Cross Port and Porting Guides:-

https://xdaforums.com/k3-note/development/guide-porting-64bit-mtk-roms-cross-t3310605

Unpack and Repack without PC guide:-

https://youtu.be/qTe9XofT5VE

Meta-INF Info:-

http://www.mtkroms.com/2015/06/make-stock-rom-mtk-easy.html?m=1

Meta-Inf generator:- ( Not tested try but its worth a look)

https://xdaforums.com/showthread.php?t=1221003

Sample Recovery flashable zip:-

https://xdaforums.com/android/development/sample-custom-recovery-zip-t3552916

Assert Failed ?check this:-

http://forums.androidcentral.com/optimus-v-rooting-roms-hacks/182438-solved-assert-failed.html

BUG FIXING FOR SNAPDRAGON

Compare the PORT FILES FROM BASE FILES:

uneventd.qcom.rc ( will fix sensor )
uneventd.rc

Copy and replace the following files from Base (ROM-PORTING/BASE) to Port (ROM-PORTING/PORT) to solve the given issues:

No sound bug:

system/lib/hw/
audio.primary.msm****.so
audio.primary.default.so
system/lib64/hw/
audio.primary.msm****.so
audio.primary.default.so

Sound working in speaker but not working through headphones or vice-versa:

system/etc/

mixer_paths.xml (you can also try patching it with the base)

[B]Distorted Outgoing Sound during Phone call or [/B]Partial Sound:
system/etc/acdbdata/MTP/
MTP_***.acdb (all files)

Home or any other button not working:

system/usr/keylayout/
goodix.kl
gpio-keys.kl (important)
Generik.kl

Video hw encoding/decoding not working:

system/etc/firmware/
venus.*** (all files starting with ‘venus’)

Sensors not working:

system/lib/hw/sensors.msm****.so (or sensors.lsm6db0.so)
system/lib64/hw/sensors.msm****.so (or sensors.lsm6db0.so)
system/lib/libsensorservice.so
system/lib64/libsensorservice.so

Led notification not working:

system/lib/hw/lights.msm****.so
system/lib64/hw/lights.msm****.so

Vibration not working:

system/lib/libhardware_legacy.so
system/lib64/libhardware_legacy.so

FM not working:

system/lib/qcomfm_jni.so
system/lib64/qcomfm_jni.so

Wifi not working:

system/lib/modules/wlan.ko

[Note: In MIUI, wlan.ko is renamed as pronto_wlan.ko and is also kept in system/lib/modules/pronto/ folder, so you have to replace in both the places.]

In some phones you may not find wlan.ko file. In that case you may try replacing these files

system/lib/libwcnss_qmi.so
system/lib64/libwcnss_qmi.so

For slow WiFi network and other WiFi related issues replace these files:

system/etc/wifi/ -- all files
system/etc/firmware/wlan/ -- all files

Camera and flash not working:

system/vendor/lib/ :-

libactuator_***.so (all files starting with ‘libactuator’)
libchromatix_***.so (all files starting with ‘libchromatix’)
libmmcamera_***.so (all files starting with ‘libmmcamera’)

system/lib/:-

libmm-qcamera.so
libmmcamera_interface.co
system/lib/hw/
camera.msm****.so

[Note: If such files are also available in your BASE/system/vendor/lib64/ then you have to copy those files also to their respective place in PORT]

GUIDE TO PORT RECOVERY

PORT TWRP RECOVERY

Things You are Required ::-

1.Android Image Kitchen
2.Notepad++
3.Base Recovery
4.TWRP to Port
5.Brain

First of All , You Guys need to unpack Recovery.img i.e both Stock Recovery or TWRP Recovery.

After this :-

You need to Copy these files from your Stock Recovery to the TWRP Recovery ( which you want to port ) :-

Lets Divide Step by Step ::--

*REPLACE FROM STOCK TO PORT*

STEP1:

Inside Ramdisk Folder ::::::

1.meta_init.modem.rc
2.meta_init.project.rc
3.meta_init.rc

STEP2:

Now replace your Kernel usually named as zimage-kernel

STEP3

Inside Ramdisk Folder(boot.img):::::::

1.fstab
2.ueventd.rc
3.ueventd.goldfish.rc.

STEP4

INSIDE RAMDISK/ETC

recovery.fstab

STEP5

Open Default.prop

and Compare it with stock Default.prop or your Build.prop ( add values from build.prop )

=============>>>>>>>

DONE!!!!! EVERYTHING IS IN PLACE

NOW REPACK IT AND FLASH.

YOU HAVE PORTED A RECOVERY.... :)

WARNING: Do not replace any file unnecessarily, because it may give rise to new bugs in place of solving it. Always be specific!

Now Mostly its the end of the Guide / Tutorial / G.K on porting or whatever you call it.

Once again , i (Kuber Sharma) hope you guys succesfully learn porting and making roms soon.

You guys have my Best Wishes.

Thank You.

I couldn't have done this without the help of :-

Amit Kumar (A.M.T)

Sam Grande (A.M.T)

Special Thanks to [MENTION=5450421]sandeep.sethi[/MENTION]

Special Thanks to [MENTION=5885640]Yousef Algadri[/MENTION]

Special thanks to [MENTION=7471004]mohancm[/MENTION]

You can find me here:-

[MENTION=7174278]kubersharma[/MENTION]

Want to buy me a coffee or wanna donate me for my cause!!

https://paypal.me/kubersharma

DO HIT THANKS BUTTON IF YOU LIKE MY GUIDE

THANK YOU