[This Guide is also applicable in porting other ROMs like Color OS, Flyme OS, Sense and more...]
ROM porting is not an easy task for a newbie and porting a highly customizable ROM like MIUI v7 is a way tougher. When I was porting MIUI v7 Lollipop for a Qualcomm Snapdragon device I did not find a definitive guide for porting the latest MIUI v7. So, porting MIUI became a very tough task since I was a newbie in porting ROMs. I learnt porting through experience. Hence I am writing this guide to help the new MIUI porters so that they don’t face the problems which I faced.
Not much history now, let’s move on to our actual task i.e. how to port MIUI v7?
DISCLAIMER: This guide is written to help the emerging devs. Soft bricking is common in porting ROMs. But, I am not responsible if you somehow hard-brick your device. Do it at your own risk.
Prerequisites
Things required for porting:
- Device for which the ROM is being ported
- Port ROM i.e. the ROM of other device which you want to port (here we have MIUI 7)
- Base ROM i.e. the Rom which is exclusively made for your device (CyanogenMod is preferable but if it is not available then Stock ROM may be used)
- PC with Windows + Ubuntu (either in dual boot or through Virtualbox)
- Rom Deodexer (for Winidows - JoelDroid Lollipop Batch Deodexer and for Linux - Linux Batch Lollipop Deodex recommended) [For Android 6.0 Marshmallow ROMs use this tool to deodex: SuperR's Kitchen]
- Android Image Kitchen to modify boot.img
- Notepad++ to edit scripts
- Meld to compare files and folders
- Winrar or 7zip
- Apktool (for advanced tasks only)
- And some common sense
Common Information
- This guide will teach you to port ROMs from devices with similar hardware specs and same Qualcomm Snapdragon chipset.
- The Port ROM and the Base ROM should have the same android version.
- ROMs containing DAT files should be properly unpacked. For base ROM you can easily do it by flashing the ROM and taking the TWRP backup of ‘system’ and extracting the resultant file with Winrar/7zip. For Port ROM follow this guide: [DEV] Lollipop/Marshmallow DAT files | Compression and Decompression
- ROMs should be properly deodexed before porting (Linux Batch Lollipop Deodex worked better in deodexing MIUI 7 Lollipop)
- The size of the system folder of your Port ROM should be lesser than that of the system partition of your device, else you'll not be able to flash the ROM. To decrease the size you need to deodex your ROM and you may further need to debloat you Port ROM which is discussed later.
- I am writing this guide on the basis of this configuration:
- Base device: YU Yureka (ARM64)(MSM8939)
- Base ROM: CyanogenMod 12.0
- Android Version: 5.0.2 Lollipop
- Port device: MI4i (ARM64)(MSM8939)
- Port ROM: MIUI v7 Lollipop
Now let’s start porting.
Preparing Porting Environment
- Make sure you have plenty of hard-disk space in your PC.
- Make a folder named MIUI-PORTING-PROJECT (you may take any other name)
- Inside that folder create two folders: (i) BOOT-EDITING (ii) ROM-PORTING
- In ROM-PORTING folder create two folders named BASE and PORT (this is the main working folder)
- Similarly inside the BOOT-EDITING folder create two folders named BOOT-BASE and BOOT-PORT
- Now place the extracted deodexed Port ROM (i.e. MIUI v7) in PORT folder and Base ROM (i.e. CM 12.0) in BASE folder.
- Similarly place the MIUI v7 boot.img in BOOT-PORT folder and CM12 boot.img in BOOT-BASE folder.
These steps are required to properly organize the project and will be helpful in our later discussions.
Cleaning up:
Just delete some unwnted files (.mbn files) and keep only ‘META-INF’ folder, ‘data’ folder (if available), ‘system’ folder, ‘boot.img’ file and ‘file_contexts’ file (if available) in PORT folder.
Now let’s do some work to make the Port ROM boot.
Cleaning up:
Just delete some unwnted files (.mbn files) and keep only ‘META-INF’ folder, ‘data’ folder (if available), ‘system’ folder, ‘boot.img’ file and ‘file_contexts’ file (if available) in PORT folder.
Now let’s do some work to make the Port ROM boot.
META-INF editing
- Open the updater-script file in PORT/META-INF/com/google/android/ with Notepad++.
- Delete the first line containing “get_device_compatible(….” or “assert(getprop….” which restricts the flashing process to other devices.
- Then delete the lines containing scripts for flashing radio image, modem image etc. which are not required for our base device.
Now you are ready to go.
boot.img editing
1. Use Android Image Kitchen to unpack the base and port boot.img in BOOT-BASE and BOOT-PORT folder.
2. Replace the files boot.img-zImage, boot.img-dtb, boot.img-ramdisk.cpio.gz (not so important) in BOOT-PORT/split_img/ with that of BOOT-BASE/split_img.
2. Replace the files boot.img-zImage, boot.img-dtb, boot.img-ramdisk.cpio.gz (not so important) in BOOT-PORT/split_img/ with that of BOOT-BASE/split_img.
Replacing boot.img files |
3. Then in the BOOT-PORT/ramdisk/ folder compare the file fstab.qcom with that of the base i.e. BOOT-BASE/ramdisk/fstab.qcom. (You can use Meld for it.)
Editing fstab.qcom using Meld: Step 1 |
Editing fstab.qcom using Meld: Step 2 |
After this repack your boot.img and place it in your port ROM folder (i.e. PORT) and create a flashable zip. You will be able to boot this time. But, you may face sensors, sound, camera, ext sd-card etc. issues. So let us move on to fix those issues through boot.img first.
4. If the port device doesn’t support external sd-card but your base device does then you make the following changes to your BOOT-PORT/ramdisk/init.qcom.rc file:
Remove ‘#’ from the lines containing scripts for mounting or fusing ‘sdcard1’. You can do this simply by comparing the port init.qcom.rc with that of base through Meld application. (Note: You may also need to add some lines if missing in the port init.qcom.rc)
5. After sd-card, let’s move towards fixing camera, led, sensors etc. issues. For that we need to edit the init.rc and init.target.rc files.
=> Editing init.rc file:
Following lines should be added to init.rc file:
#Add all these lines under 'on post-fs-data' in appropriate places
on post-fs-data
# yulong begin add by zouzhangzhi |
mkdir /data/clb |
chown system system /data/clb |
chmod 0666 /data/clb |
chown system radio /dev/yl_params1 |
chmod 0660 /dev/yl_params1 |
# yulong end |
#Add all these lines under 'on boot' in appropriate places
on boot
# for sensor, modify by hugh 2014-12-29
chmod 0660 /dev/yl_alsprox_sensor
chmod 0660 /dev/yl_acc_sensor
chown system system /dev/yl_alsprox_sensor
chown system system /dev/yl_acc_sensor
#end by hugh
#add by kangxiong 2013.10.9
mkdir /dev/camerainfo
#z camera factory info
chmod 0666 /dev/camera0
chown radio system /dev/camera0
chmod 0660 /dev/camera1
chown radio system /dev/camera1
symlink /dev/camera0 /dev/camerainfo/camera0
symlink /dev/camera1 /dev/camerainfo/camera1
#end
# add for touch firmware calibrate
chown system system /sys/class/touchscreen/touchscreen_dev/calibrate
chown system system /sys/class/touchscreen/touchscreen_dev/firware_update
# yulong end
#yulong add, begin
#for Gesture Wakeup
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/gesture_ctrl
#yulong end
# yulong add for vibrator
chown system system /sys/class/timed_output/vibrator/level
chown system system /sys/class/timed_output/vibrator/blank
# yulong end |
=> Editing init.target.rc file:
Following lines should be added to init.target.rc file:
#Add all these lines under 'on post-fs-data' in appropriate places
on post-fs-data
# yulong begin,add
# CTS touchscreen items, wzh,2013-03-25
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/firmware_update
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/calibrate
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/mode
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/oreitation
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/regs
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/get_rawdata
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/debug
chown system system /sys/devices/virtual/touchscreen/touchscreen_dev/reset
# yulong end
# yulong begin add
# add for hall sensor init , zdd, 20150306
chown system system /sys/class/switch/hall/name
chown system system /sys/class/switch/hall/state
chown system system /sys/class/switch/hall/enable
#yulong end |
#Add all these lines under 'on boot' in appropriate places
on boot
#change sensors permit
chown system system /dev/yl_alsprox_sensor
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/accel_delay
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/accel_enable
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/calibration
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/capabilities
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/debug
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/device_delay
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/event3
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/gyro_delay
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/gyro_enable
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/id
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/max
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/min
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/modalias
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/name
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/phys
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/poll
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/power
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/properties
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/uevent
chown system system sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/uniq
chown system system sys/class/sensors_compass/compass/data
chown system system sys/class/sensors_compass/compass/enable
chown system system sys/class/sensors_compass/compass/handle
chown system system sys/class/sensors_compass/compass/hard_offset
chown system system sys/class/sensors_compass/compass/max_range
chown system system sys/class/sensors_compass/compass/min_delay
chown system system sys/class/sensors_compass/compass/name
chown system system sys/class/sensors_compass/compass/poll_delay
chown system system sys/class/sensors_compass/compass/position
chown system system sys/class/sensors_compass/compass/power
chown system system sys/class/sensors_compass/compass/resolution
chown system system sys/class/sensors_compass/compass/self_test
chown system system sys/class/sensors_compass/compass/self_test_noise
chown system system sys/class/sensors_compass/compass/sensor_power
chown system system sys/class/sensors_compass/compass/type
chown system system sys/class/sensors_compass/compass/uevent
chown system system sys/class/sensors_compass/compass/vendor
chown system system sys/class/sensors_compass/compass/version
chown system system data/system/yas_lib.cfg
chown system system data/system/yas_set.cfg
chmod 0740 /dev/yl_alsprox_sensor
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/accel_delay
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/accel_enable
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/calibration
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/capabilities
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/debug
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/device_delay
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/event3
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/gyro_delay
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/gyro_enable
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/id
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/max
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/min
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/modalias
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/name
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/phys
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/poll
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/power
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/properties
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/uevent
chmod 0740 sys/devices/soc.0/78b6000.i2c/i2c-0/0-0068/input/input3/uniq
chmod 0740 sys/class/sensors_compass/compass/data
chmod 0740 sys/class/sensors_compass/compass/enable
chmod 0740 sys/class/sensors_compass/compass/handle
chmod 0740 sys/class/sensors_compass/compass/hard_offset
chmod 0740 sys/class/sensors_compass/compass/max_range
chmod 0740 sys/class/sensors_compass/compass/min_delay
chmod 0740 sys/class/sensors_compass/compass/name
chmod 0740 sys/class/sensors_compass/compass/poll_delay
chmod 0740 sys/class/sensors_compass/compass/position
chmod 0740 sys/class/sensors_compass/compass/power
chmod 0740 sys/class/sensors_compass/compass/resolution
chmod 0740 sys/class/sensors_compass/compass/self_test
chmod 0740 sys/class/sensors_compass/compass/self_test_noise
chmod 0740 sys/class/sensors_compass/compass/sensor_power
chmod 0740 sys/class/sensors_compass/compass/type
chmod 0740 sys/class/sensors_compass/compass/uevent
chmod 0740 sys/class/sensors_compass/compass/vendor
chmod 0740 sys/class/sensors_compass/compass/version
chmod 0740 data/system/yas_lib.cfg
chmod 0740 data/system/yas_set.cfg
# wbl add camera factory info
chmod 0666 /dev/camera0
#for change compass orientation array
write sys/class/sensors_compass/compass/position 5 |
6. Even after doing the above steps you may find that sensors are not working. So for that you have to do the following step –
Compare the port uneventd.qcom.rc in BOOT-PORT/ramdisk folder with that of base and add the missing lines to the port. This will fix your sensors issue.
7. Similarly compare other BOOT-PORT files like uneventd.rc, file_contexts etc. with that of BOOT-BASE and use your brain to replace required lines.
8. To fix other issues use your common sense.
9. If you are doing boot.img editing at the beginning of your project, then some of you may find that even after doing all these steps, sensors, led, camera etc. are not working. But don’t lose heart, for that you have to start your ROM Porting.
ROM Porting
Before starting ROM porting, your base and port ROM should be properly
deodexed as I discussed before. If you have correctly edited the
boot.img then the following steps will help you to solve your bugs.
1. Debloating Port ROM: Just delete unwanted apps or bloatwares from your port ROM. You will find them in /data/, /system/app/ and /system/priv-app/ folders.
2. According to my previous instructions you should have placed your port ROM to PORT folder and base ROM to BASE folder.
3. Adding missing files and folders: You may add missing files from BASE/system/bin/ to PORT/system/bin/. For this you can just copy all the files from BASE/system/bin/ to your PORT/system/bin/ without replacing any file.
Similarly you can do the same process in system/xbin/, system/fonts/, system/etc/, system/usr/ etc. and their sub-folders.
But always use your brain to decide which files you should add and which you should not.
You may also add some missing folders from your base ROM to your port ROM, e.g. system/tts folder, system/etc/init.d and other important folders.
4. Fixing permission related issues: Now you have to work on system/etc/permissions folder. Just compare handheld_core_hardware.xml and platform.xml of port ROM with that of base and add or replace some lines if required.
You can do the same for some other permission files if required, but as I am always saying use your common sense.
5. Replacing files: Copy and replace files in system/etc/firmware and in system/etc/wifi from base to port.
Copy and replace the files goodix.kl, gpio-keys.kl, Generic.kl in system/usr/keylayout/ from base to port.
We will discuss more about replacing files in bug-fixing section.
6. Open system/framework/framework-res.apk of both base and port with Winrar in two different windows but don’t extract. Then navigate to framework-res.apk/res/xml/ of base and copy storage_list.xml and power_profile (optional) and paste to the Winrar window of port framework-res.apk/res/xml/ and replace the existing files. Then close the Winrar window.
Now let’s move on to our bug-fixing section.
1. Debloating Port ROM: Just delete unwanted apps or bloatwares from your port ROM. You will find them in /data/, /system/app/ and /system/priv-app/ folders.
2. According to my previous instructions you should have placed your port ROM to PORT folder and base ROM to BASE folder.
3. Adding missing files and folders: You may add missing files from BASE/system/bin/ to PORT/system/bin/. For this you can just copy all the files from BASE/system/bin/ to your PORT/system/bin/ without replacing any file.
Similarly you can do the same process in system/xbin/, system/fonts/, system/etc/, system/usr/ etc. and their sub-folders.
But always use your brain to decide which files you should add and which you should not.
You may also add some missing folders from your base ROM to your port ROM, e.g. system/tts folder, system/etc/init.d and other important folders.
4. Fixing permission related issues: Now you have to work on system/etc/permissions folder. Just compare handheld_core_hardware.xml and platform.xml of port ROM with that of base and add or replace some lines if required.
You can do the same for some other permission files if required, but as I am always saying use your common sense.
5. Replacing files: Copy and replace files in system/etc/firmware and in system/etc/wifi from base to port.
Copy and replace the files goodix.kl, gpio-keys.kl, Generic.kl in system/usr/keylayout/ from base to port.
We will discuss more about replacing files in bug-fixing section.
6. Open system/framework/framework-res.apk of both base and port with Winrar in two different windows but don’t extract. Then navigate to framework-res.apk/res/xml/ of base and copy storage_list.xml and power_profile (optional) and paste to the Winrar window of port framework-res.apk/res/xml/ and replace the existing files. Then close the Winrar window.
Now let’s move on to our bug-fixing section.
Bug-Fixing
If you have properly edited the boot.img then only these fixes will help you.
Copy and replace the following files from Base (ROM-PORTING/BASE) to Port (ROM-PORTING/PORT) to solve the given issues:
No sound issue:
system/lib/hw/
Copy and replace the following files from Base (ROM-PORTING/BASE) to Port (ROM-PORTING/PORT) to solve the given issues:
No sound issue:
system/lib/hw/
- audio.primary.msm8916.so
- audio.primary.default.so
system/lib64/hw/
- audio.primary.msm8916.so
- audio.primary.default.so
Home or any other button not working:
system/usr/keylayout/
- goodix.kl
- gpio-keys.kl (important)
- Generik.kl
External sd-card not showing:
Follow the Step 6 in ROM Porting section.
Video hw encoding/decoding not working:
system/etc/firmware/
- venus.*** (all files starting with ‘venus’)
Distorted Outgoing Sound during Phone call:
system/etc/acdbdata/MTP/
- MTP_***.acdb (all files)
Sensors not working:
- system/lib/hw/sensors.msm8916.so (or sensors.lsm6db0.so)
- system/lib64/hw/sensors.msm8916.so (or sensors.lsm6db0.so)
- system/lib/libsensorservice.so
- system/lib64/libsensorservice.so
Led notification not working:
- system/lib/hw/lights.msm8916.so
- system/lib64/hw/lights.msm8916.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 (thanks @Divyansh747):
In some phones you may not find wlan.ko file. In that case you may try replacing these files (thanks @Divyansh747):
- 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’)
[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]
WARNING: Do not replace any file unnecessarily, because it may give rise to new bugs in place of solving it. Always be specific!
WARNING: Do not replace any file unnecessarily, because it may give rise to new bugs in place of solving it. Always be specific!
build.prop editing
You can edit required parts of build.prop to reflect the brand, model
no. etc. according to your preference. You may also add some tweaks and
other things to save battery and to add features.
(But in MIUI 7 according to my experience changing the ro.product.manufacturer gives rise to issue in video recording through third-party apps and changing the ro.product.device trims some features from the ROM.)
Now your Porting Project is ready to be flashed and to be reviewed. Congrats!
(But in MIUI 7 according to my experience changing the ro.product.manufacturer gives rise to issue in video recording through third-party apps and changing the ro.product.device trims some features from the ROM.)
Now your Porting Project is ready to be flashed and to be reviewed. Congrats!
Giving Credits
Last but not least when you successfully port your ROM, always give credits to the Port and Base Rom developers. Also give credits to the people from whom you took help.
Always be generous in giving credits because it will not take anything
from you, on the other hand it will increase your reputation and
strengthen people’s faith in your work.
If you are taking help from this guide in your ROM Porting then don't forget to give some credit to me too.
If you are taking help from this guide in your ROM Porting then don't forget to give some credit to me too.