How to port MIUI 7 ROM to Qualcomm powered Smartphones

How to port MIUI 7 ROM to Qualcomm powered Smartphones 

 [This Guide is also applicable in porting other ROMs like Color OS, Flyme OS, Sense and more...]

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.

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

  1. Make sure you have plenty of hard-disk space in your PC.
  2. Make a folder named MIUI-PORTING-PROJECT (you may take any other name)
  3. Inside that folder create two folders: (i) BOOT-EDITING  (ii) ROM-PORTING
  4. In ROM-PORTING folder create two folders named BASE and PORT (this is the main working folder)
  5. Similarly inside the BOOT-EDITING folder create two folders named BOOT-BASE and BOOT-PORT
  6. 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.
  7. 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.

META-INF editing

  1. Open the updater-script file in PORT/META-INF/com/google/android/ with Notepad++.
  2. Delete the first line containing “get_device_compatible(….” or “assert(getprop….” which restricts the flashing process to other devices.
  3. 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.
boot.img edit 1
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 Step 1
Editing fstab.qcom using Meld: Step 1
Editing fstab.qcom Step 2
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 files.

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.


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:

Home or any other button not working:
  • 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:
  • venus.*** (all files starting with ‘venus’)
Distorted Outgoing Sound during Phone call:
  • MTP_***.acdb (all files)
Sensors not working:
  • system/lib/hw/ (or
  • system/lib64/hw/ (or
  • system/lib/
  • system/lib64/

Led notification not working:
  • system/lib/hw/
  • system/lib64/hw/

Vibration not working:
  • system/lib/
  • system/lib64/

FM not working:
  • system/lib/
  • system/lib64/

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):
  • system/lib/
  • system/lib64/

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:
  • 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!

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!

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.

Tushar Ryan
Obaid Muneer


  1. How miui v8 5.1.1 ROM port attached to my base rom andriod 5.0.2 snapdragon615 yureka I took from it.


Post a Comment

Popular posts from this blog

[GUIDE][PORTING][MEDIATEK][mt6580]Android 6.0.x Marshmallow ROM Porting Guide-figured

Lollipop n Marshmallow System Extractor and Repacker Version 1.60

[CM] [ROM] [6.0.1] CyanogenMod 13 Unofficial - TECNO W4