Skip to content

Commit

Permalink
ipq806x: Add support for Xiaomi Mi Router HD (R3D)
Browse files Browse the repository at this point in the history
Xiaomi R3D is a 2.4/5 GHz band 11ac router, based on IPQ8064.

Specification:
* SoC:  Qualcomm IPQ8064
* RAM:  512MB DDR3
* STOR: 256MB NAND (Macronix MX30UF2G18AC-TI)
* ETH:  1x WAN 10/100/1000, 3x LAN 10/100/1000
* WiFi: Qualcomm QCA9984 (5GHz, 4T4R, n/ac)
* WiFi: Qualcomm QCA9980 (2.4GHz, 4T4R, b/g/n)
* USB:  1x 3.0
* SATA: 1x SATA 3.1 (only for internal HDD 3.5")
* BTN:  Power, Reset
* LEDS: Status(Green/Blue/Red)
* UART: present as 4-pads on the PCB (3.3V, 115200-8-N-1)

MAC addresses as verified by stock firmware:

| Interface   |       MAC         |  ART    | Format |
|-------------+-------------------+---------+--------|
| WAN (label) | xx:xx:xx:xx:xx:B2 | 0x0     | binary |
| LAN         | xx:xx:xx:xx:xx:B3 | 0x6     | binary |
| WiFi 2g     | xx:xx:xx:xx:xx:B4 | 0x1006  | binary |
| WiFi 5g     | xx:xx:xx:xx:xx:B5 | 0x5006  | binary |

Partition layout and boot:

Stock Xiaomi firmware has the MTD split into (among others)

- kernel0 (@0x0800000)
- kernel1 (@0x0c00000)
- rootfs0 (@0x1000000)
- rootfs1 (@0x3800000)
- overlay (@0x6000000)

Xiaomi uboot expects to find kernels at 0x800000 & 0xc00000
referred to as system 1 & system 2 respectively.
a kernel is considered suitable for handing control over
if its linux magic number exists & uImage CRC are correct.
If either of those conditions fail, a matching sys'n'_fail flag
is set in uboot env & a restart performed in the hope that the
alternate kernel is okay.
If neither kernel checksums ok and both are marked failed, system 2
is booted anyway.

Note uboot's tftp flash install writes the transferred
image to both kernel partitions.

Methods for getting SSH access:
1) https://github.com/acecilia/OpenWRTInvasion
2) https://github.com/openwrt-xiaomi/xmir-patcher

Installation:

The installation file for OpenWRT is a *squashfs-factory.bin file that
contains the kernel and a ubi partition. This is flashed as follows:

nvram flag_boot_success=1
nvram flag_boot_rootfs=1
nvram flag_last_success=1
nvram flag_try_sys1_failed=0
nvram flag_try_sys2_failed=0
nvram commit
dd if=factory.bin bs=1M count=4 | mtd write - kernel0
dd if=factory.bin bs=1M count=4 | mtd write - kernel1
dd if=factory.bin bs=1M skip=4  | mtd write - rootfs0
reboot

Reverting to stock:

Download facinstall.ipk from link
https://github.com/openwrt-xiaomi/facinstall/releases/latest
and install its.
Install miwifi_r3d_firmware_XXXXX.bin image via LuCI interface.

Signed-off-by: Oleg S <[email protected]>
  • Loading branch information
remittor committed May 7, 2024
1 parent 3dde786 commit b11a1d1
Show file tree
Hide file tree
Showing 8 changed files with 622 additions and 3 deletions.
6 changes: 5 additions & 1 deletion package/boot/uboot-envtools/files/ipq806x
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ qcom,ipq8064-ap148|\
qcom,ipq8064-db149)
ubootenv_add_uci_config $(ubootenv_mtdinfo)
;;
xiaomi,mi-router-hd)
ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x10000" "0x20000"
ubootenv_add_uci_sys_config "/dev/mtd12" "0x0" "0x10000" "0x20000"
;;
ubnt,unifi-ac-hd|\
zyxel,nbg6817)
ubootenv_add_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
;;
esac

config_load ubootenv
config_foreach ubootenv_add_app_config ubootenv
config_foreach ubootenv_add_app_config

exit 0
7 changes: 7 additions & 0 deletions target/linux/ipq806x/base-files/etc/board.d/02_network
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ ipq806x_setup_interfaces()
meraki,mr52)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
;;
xiaomi,mi-router-hd)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
ucidef_set_network_device_conduit "lan1" "eth1"
ucidef_set_network_device_conduit "lan2" "eth1"
ucidef_set_network_device_conduit "lan3" "eth1"
ucidef_set_network_device_conduit "wan" "eth0"
;;
*)
echo "Unsupported hardware. Network interfaces not intialized"
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ case "$(board_name)" in
tplink,vr2600v |\
zyxel,nbg6817 |\
asus,onhub |\
tplink,onhub)
tplink,onhub|\
xiaomi,mi-router-hd)
ucidef_set_compat_version "1.1"
;;
linksys,ea7500-v1 |\
Expand Down
8 changes: 8 additions & 0 deletions target/linux/ipq806x/base-files/etc/init.d/bootcount
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ boot() {
linksys,ea8500)
mtd resetbc s_env || true
;;
xiaomi,mi-router-hd)
local boot_wait=$( fw_printenv boot_wait | cut -d = -f 2 )
[ "$boot_wait" != "on" ] && fw_setenv boot_wait on
local bootdelay=$( fw_printenv bootdelay | cut -d = -f 2 )
[ "$bootdelay" != "3" ] && fw_setenv bootdelay 3
local uart_en=$( fw_printenv uart_en | cut -d = -f 2 )
[ "$uart_en" != "1" ] && fw_setenv uart_en 1
;;
esac
}
20 changes: 20 additions & 0 deletions target/linux/ipq806x/base-files/etc/init.d/hwmon_fancontrol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh /etc/rc.common

START=98

boot() {
local path_to_hwmon
# configuring onboard temp/fan controller to run the fan on its own
# for more information, please read https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

case $(board_name) in
xiaomi,mi-router-hd)
path_to_hwmon="$( grep -l emc230 /sys/class/hwmon/hwmon*/name )"
if [ -n "$path_to_hwmon" ]; then
path_to_hwmon=$( dirname "$path_to_hwmon" 2>/dev/null )
# Set FAN speed to 80%
echo "204" > "$path_to_hwmon/pwm1"
fi
;;
esac
}
3 changes: 2 additions & 1 deletion target/linux/ipq806x/base-files/lib/upgrade/platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ platform_do_upgrade() {
netgear,xr500 |\
nokia,ac400i |\
qcom,ipq8064-ap148 |\
qcom,ipq8064-ap161)
qcom,ipq8064-ap161 |\
xiaomi,mi-router-hd)
nand_do_upgrade "$1"
;;
asrock,g10)
Expand Down
Loading

0 comments on commit b11a1d1

Please sign in to comment.