Xiaomi Mi Router 3G (MIR3G) - Sysupgrade updates wrong kernel partition, device boots from kernel_stock

Hi everyone,

I’m running a Xiaomi Mi Router 3G (R3G) with recent OpenWrt releases and I’m seeing a persistent issue after every sysupgrade.

Problem

After a successful sysupgrade, the router boots with a kernel that does not match the upgraded rootfs. The system comes up, but kernel modules are unavailable because the running kernel and rootfs are from different versions.

root@OpenWrt:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00080000 00020000 "Bootloader"
mtd1: 00040000 00020000 "Config"
mtd2: 00040000 00020000 "Bdata"
mtd3: 00040000 00020000 "factory"
mtd4: 00040000 00020000 "crash"
mtd5: 00040000 00020000 "crash_syslog"
mtd6: 00040000 00020000 "reserved0"
mtd7: 00400000 00020000 "kernel_stock"
mtd8: 00400000 00020000 "kernel"
mtd9: 07580000 00020000 "ubi"

How I fix it

Immediately after sysupgrade, if I copy kernel to kernel_stock, everything works correctly:
dd if=/dev/mtd8 of=/tmp/kernel.mtd8
mtd write /tmp/kernel.mtd8 /dev/mtd7

I would like to have it fixed permanently.
Is there a known Xiaomi dual-boot flag or bootloader variable that selects between these partitions?

Any guidance on identifying the active boot slot or fixing this permanently would be appreciated.

Checked the value of flag_try_sys1_failed ?

Not sure how to do it in a right way but here is the result:

root@OpenWrt:~# strings /dev/mtd1 | head -110
:bootcmd=tftp
bootdelay=5
ethaddr="00:AA:BB:CC:DD:10"
ipaddr=192.168.31.1
serverip=192.168.31.100
ssh_en=1
restore_defaults=0
model=R3G
flag_boot_type=2
mode=Router
flag_ota_reboot=0
flag_last_success=1
uart_en=0
telnet_en=0
SN=15757/30217501
wl0_ssid=Xiaomi_3D3E_5G
wl1_ssid=Xiaomi_3D3E
wl0_radio=1
wl1_radio=1
boot_wait=on
no_wifi_dev_times=0
color=101
CountryCode=CN
nv_wan_type=dhcp
flag_boot_success=1
flag_try_sys2_failed=0
normal_firmware_md5=c6d058bb6363d36e710f6cdcc88e7ed1
Router_unconfigured=0
nv_sys_pwd=xxx
nv_wifi_ssid=Xiaomi_3D3E
nv_wifi_enc=mixed-psk
nv_wifi_pwd=admin1234
nv_wifi_ssid1=Xiaomi_3D3E_5G
nv_wifi_enc1=mixed-psk
nv_wifi_pwd1=admin1234
nv_device_id=xxx
nv_channel_secret=xxx
flag_flash_permission=1
flag_show_upgrade_info=1
stdin=serial
stdout=serial
stderr=serial
flag_boot_rootfs=1
flag_try_sys1_failed=1

You would need someone with a 3G to verify the values of the flag_ params, to check if they're correct.
At least the one I mentioned seems to be.

This parameter appears two times:

flag_try_sys2_failed=0
flag_try_sys1_failed=1

most likely the last one takes precedence