Custom ROM Porting Guide
A comprehensive guide on how to port a custom ROM from one Qualcomm device to another, including editing the boot image, fixing common bugs, and setting device information.
Note:
This article explains how to adapt software from one Qualcomm-based device to another. Porting is different from compiling; it involves making two already-compiled ROMs compatible with each other.
Overview
Porting a custom ROM involves taking a ROM built for one device (the "port" or "target" ROM) and adapting it to run on your device (the "base" ROM). Compared to compiling from source, porting is often less stable initially, and you can expect to encounter bugs that need to be fixed.
The process can be broken down into three main stages: A) Getting it to Boot B) Fixing Bugs C) Finalizing Device Information
Requirements
- Your Device and a compatible custom/stock ROM for it (the Base ROM).
- A Target Device and its custom/stock ROM (the Port ROM). The devices should have the same or a very similar SoC (e.g., both Snapdragon 730).
- NotePad++ or a similar advanced text editor.
- 7-Zip or WinRAR.
- Android Image Kitchen (AIK) to unpack and repack boot images.
- A Windows or Linux computer.
- Tools to unpack/repack system images (e.g.,
system.new.dat.brtosystem.img).
Note:
The Android versions of the Base and Port ROMs must be the same, otherwise, you will face kernel incompatibilities and the ROM will not boot.
Understanding the ROM ZIP Structure
firmware-update: Contains device-specific hardware images. You must delete this folder from the Port ROM. Flashing firmware from another device will hard brick your phone.META-INF: Contains theupdater-script, which tells the TWRP recovery what to do. We will edit this file.system.new.dat.br,system.patch.dat,system.transfer.list: This is the modern way system partitions are packaged. You will need tools to convert this to asystem.imgfile before you can modify it.vendor: Contains hardware integration files for things like sensors, GPS, etc. If the Android versions are the same, you can often use your device's vendor image and delete the one from the port ROM.boot.img: The core image that integrates the software with your hardware to start the system. We will heavily modify this.
A) Getting the ROM to Boot: Editing boot.img and updater-script
1. Prepare Your Workspace
Create two folders on your desktop: "Base" and "Port". Extract the contents of the Android Image Kitchen zip into both folders.
2. Unpack the Boot Images
- Place your device's
boot.img(from your Base ROM) into the "Base" folder. - Place the target device's
boot.img(from the Port ROM) into the "Port" folder. - In both folders, drag the
boot.imgfile ontounpackimg.bat. This will create asplit_imgfolder and aramdiskfolder.
3. Modify the Port boot.img
- From the "Base/split_img" folder, copy the
boot.img-zImageandboot.img-dtbfiles. - Paste and replace these files inside the "Port/split_img" folder.
- Open the
fstab.qcomfile from both the "Base/ramdisk" and "Port/ramdisk" folders with Notepad++. - In the Port's
fstab.qcom, delete all lines between/dev/block/bootdevice(inclusive) and/device(s)(exclusive). Replace them with the corresponding lines from your Base'sfstab.qcom. If this fails, try replacing the entirefstab.qcomfile.
4. Repack the Boot Image
- In the "Port" folder, run the
repackimg.batscript. It will create a file namedimage-new.img. - Rename
image-new.imgtoboot.img. - Replace the original
boot.imgin your Port ROM's zip file with this newly created one.
5. Edit the updater-script
- Inside the Port ROM zip, navigate to
META-INF/com/google/android/and openupdater-script. - Look for lines that perform device checks, like
getprop("ro.product.device") == "davinci". Delete these lines to prevent TWRP from aborting the installation on your device.
Now, try flashing the ROM. If it doesn't boot, compare files like init.rc, uneventd.rc, and file_contexts between the Base and Port ramdisks and merge any missing lines from Base to Port.
B) Fixing Common Bugs
Once the ROM boots, you will likely face bugs. The general strategy is to replace system files in the Port ROM with files from your Base ROM. You will need to unpack the system image to do this.
- Sensors: Replace sensor-related libraries in
system/lib/hw/,system/lib64/hw/, andlib/andlib64/(e.g.,sensors.msmxxxx.so,libsensorservice.so). - Audio: Replace audio libraries in
system/lib/hw/andsystem/lib64/hw/(e.g.,audio.primary.msmxxxx.so). - Headphones/Earpiece: Replace
system/etc/mixer_paths.xml. - Buttons: Replace key layout files in
system/usr/keylayout/(e.g.,gpio-keys.kl). - Video Playback: Replace all files starting with
venus.insystem/etc/firmware/. - Vibration: Replace
libhardware_legacy.soinsystem/lib/andsystem/lib64/. - Wi-Fi: Replace
wlan.koinsystem/lib/modules/andlibwcnss_qmi.soinsystem/lib/andsystem/lib64/.
Note:
Make changes one at a time and test if the ROM still boots. If it doesn't, revert the last change.
C) Finalizing Device Information
The final step is to edit the build.prop file located in the system directory of your ROM.
- Open
system/build.propwith a text editor. - Find properties like
ro.product.brand=andro.product.model=and change their values to match your device. - You can also change the default language and region here (e.g., change
ro.product.locale.language=entotr).
After making these changes, repack your system image, put it back into the zip, and you're done!