Note
Para a versão em português deste guia, consulte o arquivo README_PT.md.
This guide explains how to compile, pack, and boot the custom kernel with KernelSU-Next and Binary Parity support via RAM (without permanently flashing the phone's partitions), and outlines the next steps for project development.
Warning
Build #8 boots past early-init but hangs indefinitely on the RedMagic logo screen.
The root cause has been identified as an SCMI timeout on arm-scmi.1.auto that prevents the ADSP/CDSP remoteproc, keymint, and vold from starting — which blocks /data decryption (FBE).
Community help is needed! If you have experience with Qualcomm SCMI, GKI KCFI, or Android FBE boot flow, please check the diagnostic documents below.
| Document | Language | Description |
|---|---|---|
| BOOT_HANG_DIAGNOSTIC_PT.md | 🇧🇷 Português | Diagnóstico completo do hang de boot com dados de ramoops, comparação stock vs custom, e guia de investigação |
| BOOT_HANG_DIAGNOSTIC_EN.md | 🇺🇸 English | Full boot hang diagnostic with ramoops data, stock vs custom comparison, and investigation guide |
| NOTIFICACAO_COMPLIANCE_GPL_ZTE.md | 🇧🇷 Português | Notificação formal de descumprimento da licença GPL v2 e lista de fontes em falta para enviar à ZTE |
| GPL_COMPLIANCE_NOTICE_ZTE.md | 🇺🇸 English | Formal GPL v2 compliance notice and missing components report to send to ZTE support |
To ensure compilation and packaging work correctly, you must supply the following components (which are configured in .gitignore to keep the repository clean):
-
Clang Toolchain (r536225):
- Download the AOSP Clang toolchain (revision
r536225). - Extract it to the root of this repository in a folder named
clang-r536225/(such that the main binary is located atclang-r536225/bin/clang). - Alternatively, you can set the
CLANG_DIRenvironment variable pointing to your Clang directory before compiling.
- Download the AOSP Clang toolchain (revision
-
Device Tree Blob (
dtb.img):- Extract the official
dtb.imgfile from the stock ZTE boot image (boot.img) corresponding to your target userdebug ROM. - Place the
dtb.imgfile directly in the root of this repository. It is required to concatenate the Device Trees to the kernel image during packaging.
- Extract the official
-
Host Dependencies:
- Ensure your Linux machine has the essential build packages installed (
build-essential,libssl-dev,bison,flex,libelf-dev,python3, etc.).
- Ensure your Linux machine has the essential build packages installed (
To enable Fastboot flashing and commands on the RedMagic 11 Pro (NX809J) and other ZTE/Nubia devices, follow these steps:
- Windows: Download the official Android SDK Platform-Tools and add them to your system's PATH.
- Linux (Ubuntu/Debian): Install via apt:
sudo apt update sudo apt install android-tools-adb android-tools-fastboot
- macOS: Install via Homebrew:
brew install android-platform-tools
To enable Fastboot, you must first swap your device's stock Bootloader image (abl) with the custom version. Since Fastboot is locked/disabled by default on stock ROMs, you do not have Fastboot access yet. You must write the file in EDL Mode:
- Boot your device into EDL Mode (Emergency Download Mode) and open the ZTE Family Toolbox (ZTE Toolbox).
- Use the toolbox to backup/dump your official
abl_aandabl_bpartitions (keep these backups safe!). - Write the custom unlocked ABL image provided in this repository (🔴
abl_unlock.elf) to both slots (abl_aandabl_b) by selecting Option 12 (Write Partition) in the ZTE Family Toolbox. -
[!IMPORTANT] ZTE Toolbox Option 19: Immediately after writing the unlocked ABL via the ZTE Family Toolbox, you MUST run Option 19 in the ZTE Family Toolbox to clear the device boot/temp flags. If you skip this, the device will trigger a boot lockout and boot into Dumper Mode (Crash Dump screen) on the next boot.
-
[!WARNING] DO NOT use Option 18 (Fingerprint Fix) in the ZTE Family Toolbox! Even though it is labeled to fix the fingerprint reader, executing Option 18 will corrupt the boot configuration, triggering a boot lockout and causing the device to boot loop back into Dumper Mode. Only use Option 19 to clear flags and avoid Option 18 entirely.
Once 🔴 abl_unlock.elf is successfully written and the boot state is cleared, reboot the device. It will now allow you to enter and run commands in Fastboot Mode:
- Reboot the device into Fastboot Mode.
- You MUST flash the stock
vbmetaandvbmeta_systemimages with verification disabled to prevent boot loops or AVB verification issues:fastboot --disable-verity flash vbmeta_a vbmeta.img fastboot --disable-verity flash vbmeta_b vbmeta.img fastboot --disable-verity --disable-verification flash vbmeta_system_a vbmeta_system.img fastboot --disable-verity --disable-verification flash vbmeta_system_b vbmeta_system.img
[!CAUTION] DO NOT use the
--disable-verificationflag when flashingvbmeta_aorvbmeta_b(only use--disable-verity). If you use--disable-verificationonvbmeta, your device will get stuck in the bootloader and will not boot up, requiring a full recovery in EDL Mode to fix! - Finally, unlock the bootloader (if desired) by running:
Confirm the unlock on the device screen using the volume keys and power button.
fastboot flashing unlock
We use the unified script super_build.sh which sets up the environment, applies the platform defconfig (nx809j_defconfig), injects security flags (CFI Permissive, KernelSU-Next), and compiles the binaries with the appropriate Clang toolchain.
Run in your terminal:
./super_build.sh- The kernel will be compiled and the resulting image will be located at:
kernel_platform/common/arch/arm64/boot/Image.
Qualcomm's dynamic drivers require the physical concatenation of Device Trees (dtb.img) into the kernel header. The script repack_perfect_sign.sh handles packaging without an internal ramdisk (exact size of 64MB) and performs the mandatory cryptographic signing via AVB to avoid bootloader lockouts.
Run:
./repack_perfect_sign.sh- This will generate the signed boot image in the root of the project:
dev_reverse_perfect.img.
Important
Compiler and AnyKernel Compatibility:
To run this current kernel, the device must already have a working kernel compiled with Clang 20 installed.
Therefore, before attempting to perform a temporary boot in RAM (fastboot boot), you need to flash the boot image on the smartphone using AnyKernel so that the necessary patches like SUSFS and Linux Droidspaces are properly enabled.
Otherwise, the temporary boot will not be stable or compatible for development, since the original stock kernel uses an older Clang version.
Warning
NEVER run fastboot flash boot or flash this image permanently to your device during the testing phase. The boot must always be loaded temporarily in RAM. If the system hangs or presents issues, simply holding the Power button for 10 seconds will restore the original official boot.
-
Reboot your smartphone into bootloader mode:
adb reboot bootloader
-
Boot the image directly into RAM using fastboot:
sudo fastboot boot dev_reverse_perfect.img
(Enter your sudo password if the terminal prompts for root privileges to establish USB communication with fastboot).
-
The phone will boot into Android. Once booted, you can validate the active kernel by running:
adb shell uname -a
You should see the signature indicating your custom build with active KernelSU-Next support.
In the drivers/soc/qcom/zte/Makefile, the drivers are configured as follows:
obj-y += zte_misc/
obj-y += zte_power_supply/
obj-y += zte_imem_info/
obj-y += zte_stats_info/
obj-y += zte_sensor_sensitivity/
obj-y += zte_ir/
obj-y += zte_reboot_ext/
obj-y += zte_ramdisk_reboot/
obj-y += zte_led/
obj-y += zte_fingerprint/
obj-y += zte_charger_policy/
obj-m += zte_tpd/-
obj-y(Built-in / Statically Linked): The driver code is compiled directly into the main kernel executable binary (vmlinux/Image).- How it loads: It is loaded into RAM as part of the kernel boot process at the very early init stages.
- Advantages: It does not require any external
.kofile to be loaded from the storage. It starts instantly and bypasses userspace loading signatures or late binding restrictions.
-
obj-m(Modular / Loadable Kernel Module): The driver code is compiled as an independent dynamic binary with a.ko(Kernel Object) extension (e.g.,zte_tpd.ko).- How it loads: The main kernel starts without this code. The operating system (Android) loads it at runtime using commands like
insmodormodprobe(typically from/vendor_dlkm/lib/modules/or via a KernelSU boot script duringpost-fs-data). - Advantages: Highly flexible; allows dynamic replacement, resolving of duplicate symbol collisions during build time, and hot-plug loading.
- How it loads: The main kernel starts without this code. The operating system (Android) loads it at runtime using commands like
Because this project is built for testing via fastboot boot (running a custom kernel temporarily in RAM while mounting the phone's physical partitions), the driver stack is split into two categories:
- Touchscreen (
zte_tpd.ko): Rebuilt dynamically as a modular driver (obj-m), optimized with our custom dynamic platform allocations and unbound workqueue fixes to prevent suspend watchdog bites.- How it loads and runs: Since the phone's physical
/vendor_dlkmpartition is mounted as Read-Only, the customzte_tpd.kodriver is loaded using KernelSU-Next. The compiled file is copied to/data/adb/modules/zte_tpd_only/vendor_dlkm/lib/modules/zte_tpd.ko. To ensure the overlay (bind-mount) applies correctly on Android 16, we create a script hook at/data/adb/modules/zte_tpd_only/post-fs-data.shwith the command (mount -o bind /data/adb/modules/zte_tpd_only/vendor_dlkm/lib/modules/zte_tpd.ko /vendor_dlkm/lib/modules/zte_tpd.ko). During boot, KernelSU executes this script to swap the active module seamlessly and safely.
- How it loads and runs: Since the phone's physical
- Core ZTE System Drivers: All 11 drivers under
obj-y(zte_misc,zte_led,zte_fingerprint,zte_charger_policy, etc.) are built-in directly to the compiledImage. - KernelSU-Next: Integrated and compiled statically inside the core kernel.
- Compatibility Stubs (
zte_parity.c): Establishes ABI parity, satisfying internal symbol links required by the closed-source parts.
When booting from RAM, Android mounts the phone's official physical /vendor and /vendor_dlkm partitions.
Therefore, the device loads the original Qualcomm closed-source modules from these partitions:
- Camera & Display:
camera.ko,msm_drm.ko,msm_video.ko. - Audio & Power: Audio codec drivers (
wcd939x_dlkm.ko), haptics, and charge controller. - Connectivity: Mobile data modem drivers (
dataipa.ko) and Wi-Fi host driver (qca_cld3_peach_v2.ko).
Note: Because our custom kernel maintains perfect ABI parity with the stock ROM (e.g. keeping CONFIG_SCHED_CLASS_EXT and CONFIG_DEBUG_INFO_BTF options active), the prebuilt vendor modules load and run flawlessly without causing crash dumps.
Now that we have achieved stable binary parity compatibility (where the custom kernel loads and runs the system normally), we can begin the specific development tasks described in NEXT_STEPS.md:
Since booting via RAM uses the physical partitions and mounts /vendor_dlkm from the original system, the active modules at the moment are ZTE's original ones. To execute our rebuilt modules (reconstructed from Ghidra source code):
- Built-in Method: Modify the
Kbuildof the drivers we rebuilt (such aszte_charger_policyandzte_led), changing the compilation to built-in (obj-yinstead ofobj-m). This way, they will be compiled directly inside theImagefile and loaded before the system initializes the official ones.
- Extract and decompile the original Device Tree (
dtb.imgordtbo.img) into text format (.dts). - Locate the OPP (Operating Performance Points) table for the Adreno 830 GPU.
- Add the overclock frequency steps (with correct voltage bindings) to achieve a stable 1200MHz+.
- Recompile the tree and test via
fastboot boot.
- Adapt and compile the touch modules (
touch-drivers) to validate physical screen interaction using our tree. - Validate mobile network connectivity (
dataipa).
- Monitor panic logs (
dmesgandconsole-ramoops-0) to map any remaining CFI (Control Flow Integrity) failures in the loaded modules.
If you have questions, need support, or want to collaborate on this reverse engineering project, you can reach out via:
- 📧 Email: idealcreativesuporte@idealcreative.com.br
- 💬 Telegram Group: Join Group (Or direct contact: @idealcreative)
- 🌐 XDA Thread: RedMagic 11 Pro Unlock & Guide
This repository is intended to be built on the maintainer machine/container. A successful local build can publish the exact output to GitHub Releases with:
�ash export GITHUB_TOKEN=<token with repo scope> python3 scripts/publish_local_release.py /path/to/build/artifacts --build-log /path/to/build.log
The local release package includes the generated boot images, kernel Image, �mlinux, modules, kernel.config, build log, DTBs archive, and an opensource-.tar.gz archive created from the exact Git commit used for that build.