Skip to content

Instantly share code, notes, and snippets.

@imSp4rky
Created September 21, 2026 15:43
Show Gist options
  • Select an option

  • Save imSp4rky/75ca403530780feeb3182d5d269ee421 to your computer and use it in GitHub Desktop.

Select an option

Save imSp4rky/75ca403530780feeb3182d5d269ee421 to your computer and use it in GitHub Desktop.
Rooting the Xiaomi TV Box S 3rd Gen (MiTV-AFMU0 / "twilight")

Rooting the Xiaomi TV Box S 3rd Gen (MiTV-AFMU0 / "twilight")

Tested 2026-09-14 on build UKG3.250107.001 / V816.0.25.7.22.UZFAABX (Android TV 14, June 2025 patch). Result: Magisk 30.7 root, with Widevine L1 and PlayReady still working.

0. Know what you have

Item Value on this box How to check
Model MiTV-AFMU0 adb shell getprop ro.product.model
Codename twilight adb shell getprop ro.product.name
SoC Amlogic S7D adb shell getprop ro.board.platform -> s7d
Kernel 5.15 GKI, 32-bit userspace adb shell uname -a
Layout A/B, dynamic partitions, has init_boot adb shell ls /dev/block/by-name/

Watch out for the TV Stick 4K ("adastra"). It reports the same ro.product.device=twilight but is a different device, and its images will not boot on the box. Check ro.product.model and ro.product.name instead.

This is a GKI device with init_boot_a/b, so Magisk patches init_boot, not boot. That is the main thing every 2nd Gen guide gets wrong for this box.

1. Facts that shape the risk

Slot B is empty on a fresh unit. init_boot_b, boot_b and vendor_boot_b are all zeros, so there is no A/B fallback if slot A stops booting.

There is no recovery key combo on the remote. Several users have tried. If the box boot-loops you cannot get back to fastboot from software.

The one way back into fastboot from a boot loop is a hardware test-point short. Open the case, have fastboot waiting on the PC, connect power and USB, and the instant the LED first lights, short TP140 to TP180 for two to three seconds. This comes from 4PDA topic 1104313, post 10312, where the poster recovered a box this way.

Fastboot cannot dump partitions on this bootloader. fastboot fetch only works for vendor_boot, and the unprivileged ADB shell cannot read /dev/block. The stock image has to come from firmware, not from the device.

Every brick reported so far came from flashing an init_boot built from a different firmware version. Section 4 shows how to check the fingerprint before you flash.

Unlocking and rooting did not affect Widevine L1 or PlayReady on this box. The DRM keys live in fused TEE storage that the bootloader state does not touch.

2. Tools

  • Android platform-tools (adb, fastboot). The Windows fastboot.exe worked fine. Scripting was done from WSL over network adb.
  • payload-dumper-go to pull images out of the OTA payload.bin.
  • Magisk APK (v30.7 used), from https://github.com/topjohnwu/Magisk/releases.
  • Python 3 with the lz4 module (pip install lz4) for the fingerprint check. Optional, but worth it.

3. Unlock the bootloader

Plain fastboot. No Mi account, no Mi Unlock Tool, no waiting period.

  1. Settings -> Device Preferences -> About -> click Build 7 times -> Developer options.
  2. Turn on OEM unlocking and USB debugging. Turn on network ADB too if you want to work wirelessly later.
  3. Connect USB to the PC and:
adb reboot bootloader
fastboot devices
fastboot getvar unlocked          # expect: no
fastboot flashing unlock
fastboot flashing unlock_critical
fastboot reboot

The box wipes and you set it up again. Afterwards adb shell getprop ro.boot.verifiedbootstate reports orange and fastboot getvar unlocked reports yes. (4PDA post 2114, and confirmed here.)

4. Get the stock init_boot for your exact build

4a. Find your build

adb shell getprop ro.build.fingerprint
adb shell getprop ro.bootimage.build.date.utc

Example: Xiaomi/twilight/twilight:14/UKG3.250107.001/V816.0.25.7.22.UZFAABX:user/release-keys, timestamp 1753131656.

4b. Download the full OTA

Google hosts Xiaomi's Google TV OTAs and they download without a login. Known URLs:

Build URL Size
UKG3.250107.001 / V816.0.25.7.22 (Jul 2025) https://android.googleapis.com/packages/ota-api/package/fbc6a620d9d88823fa3b4b4257e7c765eb471cb1.zip 1,143,553,247 B
UKG3.250826.001 / V816.0.7.0 (Jan 2026) https://android.googleapis.com/packages/ota-api/package/8eebe81e9e0de636b2521f4e18ab7971c995f2b0.zip 1,235,546,567 B

For other builds, the first post of the 4PDA thread has a firmware archive. xiaomifirmwareupdater does not list TV products.

Confirm the zip matches your build before extracting anything:

unzip -p <ota>.zip META-INF/com/android/metadata | grep -E "post-build=|post-timestamp="

Both values must equal your device's fingerprint and ro.bootimage.build.date.utc.

4c. Extract

unzip <ota>.zip payload.bin
payload-dumper-go -p init_boot,boot,vendor_boot,dtbo,vbmeta -o extracted payload.bin

You only need init_boot.img (8 MB). Keep the others as a recovery kit. None of them need flashing for root.

4d. Verify the image before you go further

Check the magic bytes and, if you can, the fingerprint inside the ramdisk. The ramdisk is LZ4-legacy compressed. A short Python check:

import struct, re, lz4.block
d = open("extracted/init_boot.img", "rb").read()
assert d[:8] == b"ANDROID!"
ks, rs = struct.unpack("<II", d[8:16]); pg = 4096
off = pg + ((ks + pg - 1) // pg) * pg; rd = d[off:off + rs]
out = b""; p = 4
while p + 4 <= len(rd):
    n = struct.unpack("<I", rd[p:p+4])[0]; p += 4
    if n == 0x184c2102: continue
    out += lz4.block.decompress(rd[p:p+n], uncompressed_size=8 << 20); p += n
print(re.search(rb"ro\.bootimage\.build\.fingerprint=([^\n]*)", out).group(1).decode())

The printed fingerprint must equal adb shell getprop ro.bootimage.build.fingerprint. Record sha256sum extracted/init_boot.img. This file is your rollback image.

5. Patch with Magisk

Two options. Option B was used here because the Android TV file picker is a pain with a remote.

Option A: Magisk app UI

adb install Magisk.apk
adb push extracted/init_boot.img /sdcard/Download/

Open Magisk -> Install -> "Select and Patch a File" -> pick init_boot.img. Pull /sdcard/Download/magisk_patched-*.img.

Option B: run Magisk's patch script over ADB (no UI)

The Magisk APK ships the same script the app runs. Extract it and lay the files out flat. The box is armeabi-v7a, so use the 32-bit libs:

mkdir stage && cd stage
unzip -j ../Magisk.apk assets/boot_patch.sh assets/util_functions.sh assets/stub.apk
unzip -p ../Magisk.apk lib/armeabi-v7a/libmagiskboot.so  > magiskboot
unzip -p ../Magisk.apk lib/armeabi-v7a/libmagiskinit.so  > magiskinit
unzip -p ../Magisk.apk lib/armeabi-v7a/libinit-ld.so     > init-ld
unzip -p ../Magisk.apk lib/armeabi-v7a/libmagisk.so      > magisk
unzip -p ../Magisk.apk lib/armeabi-v7a/libbusybox.so     > busybox
cd ..
adb install Magisk.apk
adb push extracted/init_boot.img /data/local/tmp/
adb shell mkdir -p /data/local/tmp/mg
adb push stage/. /data/local/tmp/mg/
adb shell "cd /data/local/tmp/mg && chmod 755 * && sh ./boot_patch.sh /data/local/tmp/init_boot.img"
adb pull /data/local/tmp/mg/new-boot.img extracted/init_boot_magisk.img

The output should include Stock boot image detected, Pre-init storage partition: metadata and Repack to boot image: [new-boot.img]. The defaults KEEPVERITY=false and KEEPFORCEENCRYPT=false are fine on an unlocked device.

Verify the patched image

adb shell sha256sum /data/local/tmp/mg/new-boot.img
sha256sum extracted/init_boot_magisk.img         # must match

Run the Python check from 4d on the patched image as well. The fingerprint must still be yours, and the cpio should now contain overlay.d/sbin/magisk.xz, .backup/init.xz and friends.

6. Flash

One partition, active slot only. No vbmeta, dtbo, vendor_boot or super changes. The unlock already turned AVB off, so the --disable-verity steps from 2nd Gen guides do not apply.

adb reboot bootloader
fastboot getvar current-slot                 # expect: a
fastboot flash init_boot_a init_boot_magisk.img
fastboot reboot

You should see Sending 'init_boot_a' (8192 KB) OKAY and Writing 'init_boot_a' OKAY. Boot takes about 20 seconds.

If current-slot says b, flash init_boot_b instead. Read the value rather than assuming it.

7. First boot and confirm root

The Magisk app shows up as a stub and offers additional setup. Let it run. It may reboot the box once.

adb shell /debug_ramdisk/su -c id      # uid=0(root) ... context=u:r:magisk:s0
adb shell /debug_ramdisk/magisk -v     # 30.7:MAGISK:R

su is not on the ADB shell's PATH on this box, so use the full path /debug_ramdisk/su. In the Magisk app under Superuser, set Shell to Grant so ADB requests stop prompting.

8. Rollback

Same command with the stock image:

fastboot flash init_boot_a init_boot.img

If the box boot-loops and you cannot reach fastboot, use the TP140 to TP180 test-point method from section 1, run fastboot flashing unlock if needed, and flash the stock image.

9. OTA handling after root

An A/B OTA installs to the inactive slot and flips to it, which drops root and fills slot B. You have two choices.

To keep updates and keep root: download the OTA but do not reboot. Open Magisk -> Install -> "Install to Inactive Slot (After OTA)", then reboot. Root carries over and slot B becomes a real fallback. (4PDA post 2647.)

To block updates entirely, which is what was done here: system updates on Google TV go through GMS rather than the Xiaomi app, so disable only the GMS update components plus the Xiaomi updater. The change survives reboots and needs no Magisk module.

adb shell /debug_ramdisk/su -c '
pm disable com.google.android.gms/.update.SystemUpdateService
pm disable com.google.android.gms/.update.SystemUpdateGcmTaskService
pm disable com.google.android.gms/.update.SystemUpdatePersistentListenerService
pm disable com.google.android.gms/.update.SystemUpdatePanoActivity
pm disable com.google.android.gms/.update.OtaPanoSetupActivity
pm disable com.google.android.gms/.update.CompleteDialog
pm disable-user --user 0 com.xiaomi.mitv.updateservice
pm clear --user 0 com.xiaomi.mitv.updateservice'

Revert with pm enable on each. One caveat: a future Play system update that touches those components could cause a boot loop. Magisk safe mode kicks in after three failed boots, or you can pm enable them from ADB.

Sources

@DoubleGhosty

Copy link
Copy Markdown

Thanks a lot for this guide! It helped me root my Xiaomi TV Box S 3rd Gen successfully.

I was on the newer firmware:

V816.0.11.0.UZFAABX

Fingerprint:

Xiaomi/twilight/twilight:14/UKG3.250826.001/V816.0.11.0.UZFAABX:user/release-keys

My active slot was B.

The pre-patched init_boot from the bundle was for V816.0.7.0.UZFAABX, so the installer rejected it with FIRMWARE MISMATCH.

I found the correct OTA through OTAChecker (OTA #2546). Interestingly, the OTA itself is V816.0.7.0, but its post-condition fingerprint is V816.0.11.0.UZFAABX, matching my box.

I downloaded that OTA, extracted the init_boot.img, and then followed your exact method to patch it with Magisk 30.7 using magiskboot and boot_patch.sh.

I then used the installer with my patched image, and it successfully flashed init_boot_b.

After reboot:

uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0

So your method works on `V816.0.11.0.UZFAABX as well. The important part was finding the OTA whose post-condition fingerprint matched the firmware actually installed, rather than simply looking for an OTA with the same version number.

Thanks again for the original work! Hopefully this helps anyone running the newer firmware.

@mrgcli

mrgcli commented Oct 25, 2026

Copy link
Copy Markdown

Hello,

My device is stuck in a bootloop—it keeps restarting at the logo—after I flashed a Magisk-patched init_boot image. It seems I missed a step, causing the device to fail to boot. Could you please help me restore my Mi TV Box? The device details are: Xiaomi/twilight/twilight:14/UKG3.250826.001/V816.0.11.0.UZFAABX:user/release-keys.

I attempted to enter fastboot mode by shorting pins TPM140 and TPM180 (since the TP140 to TP180 points mentioned elsewhere aren't present on my board). I managed to trigger fastboot mode, but the device is being detected as "NDL" on my PC. Please help me restore my device. Thank you.

@imSp4rky

Copy link
Copy Markdown
Author

@mrgcli "NDL" means the short put the box into Amlogic's BootROM USB mode (ADNL), not fastboot. You usually land there when the short happens too early, before the ROM has loaded u-boot from the eMMC. You can still recover from it, so don't give up on the box.

Option 1: retry the short a bit later (easiest)

Keep fastboot devices running in a loop on the PC. Plug in power and USB, wait until the LED lights up, and then short the two points for 2 to 3 seconds. By then u-boot is already running, so when it can't read the boot partitions it falls back to fastboot. Once you're in:

fastboot getvar current-slot
fastboot flash init_boot_<slot> init_boot.img   # the STOCK image from the same OTA you patched
fastboot reboot

If it still won't boot, try fastboot --set-active=a (or the other slot). After an OTA, the other slot still has your previous firmware on it.

Option 2: recover from the ADNL mode you're already in

Get Amlogic's adnl tool (Khadas has a Windows build: https://dl.khadas.com/products/vim4/tool/aml_dnl-win32.zip). Then pull the bootloader out of your OTA along with init_boot:

payload-dumper-go -p bootloader,init_boot -o extracted payload.bin

I checked this on my own box: the bootloader.img inside the OTA is byte for byte the same as what's on the eMMC, so it's the right signed image. Then:

adnl devices                       # should list Aml_DNL
adnl getvar identify               # expect DNL mode [BL1]
adnl bl1_boot -f bootloader.img
adnl bl2_boot -f bootloader.img

That boots u-boot from RAM. Check fastboot devices from there and flash the stock init_boot the same way as in Option 1. Don't write the bootloader partition. It isn't damaged; only init_boot is.

I haven't tested Option 2 on this exact box. The steps come from an ADNL recovery on the S905W2/S4 (https://github.com/MarcinWad/Amlogic_s905W2_S4), which uses the same protocol, so expect to adjust a bit.

Also, which image did you flash, and to which slot? A pre-patched image built for V816.0.7.0 won't boot on V816.0.11.0. You need the init_boot from the OTA whose post-build fingerprint matches your box, like DoubleGhosty described above.

@0x189D7997

0x189D7997 commented Nov 5, 2026 •

Copy link
Copy Markdown

Latest OTA link can be obtained with google-ota-prober
No need to hope someone posted it on forums.

For twilight the command would be:

python probe.py --fingerprint "Xiaomi/twilight/twilight:14/UKG3.250826.001/V816.0.7.0.UZFAABX:user/release-keys"

With UKG3.250826.001/V816.0.11.0.UZFAABX as a result as of now:

Update title: system update
OTA URL obtained: https://android.googleapis.com/packages/ota-api/package/3d463b9f43d2ae30edef351bfbbcb585da24e91f.zip

If previous version is not known just use your current system fingerprint and decrement version by one like V816.0.10.0 or similar, I have found the OTA API quite forgiving, most likely it will give you the latest update, just don't specify a fingerprint that matches it exactly.

https://android.github.io/analyseOTA/
can be used to quickly see what you actually got.

@imSp4rky please add this method to the gist if you see this.

@kendikaku

kendikaku commented Nov 6, 2026 •

Copy link
Copy Markdown

Nice!
Now all that’s missing is a LineageOS version for our device (it’s out for version 2).

Note: Over on the 4PDA forum, I go by the username japa18244. I contribute various files there, such as an init_boot image patched with the latest Magisk (v31.1), links for downloading OTA updates, and more.

OS1.0.11.0.UZFAABX - OTA

Init_boot original and Init_boot patch magisk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment