Skip to content

Commit f2107fc

Browse files
ldir-EDB0blogic
authored andcommitted
ramips: improve Xiaomi Mi Router 3G support
This commit improves support for the Xiaomi Mi Router 3G originally added in commit 6e283cd Improvements: - Remove software watchdog as hardware watchdog now working as per commit 3fbf3ab for all mt7621 devices. - Reset button polarity corrected - length of press determines reboot (short press) vs. reset to defaults (long press) behaviour. - Enable GPIO amber switch port LEDs on board rear - lit indicates 1Gbit link and blink on activity. Green LEDs driven directly by switch indicating any link speed and tx activity. - USB port power on/off GPIO exposed as 'usbpower' - Add access to uboot environment settings for checking/setting uboot boot order preference from user space. Changes: - Front LED indicator is physically made of independent Yellow/Amber, Red & Blue LEDs combined via a plastic 'lightpipe' to a front panel indicator, hence the colour behaviour is similar to an RGB LED. RGB LEDs are not supported at this time because they produce colour results that do not then match colour labels, e.g. enabling 'mir3g:red' and 'mir3g:blue' would result in a purple indicator and we have no such label for purple. The yellow, red & blue LEDs have been split out as individual yellow, red & blue status LEDs, with yellow being the default status LED as before and with red's WAN and blue's USB default associations removed. - Swapped order of vlan interfaces (eth0.1 & eth0.2) to match stock vlan layout. eth0.1 is LAN, eth0.2 is WAN - Add 'lwlll' vlan layout to mt7530 switch driver to prevent packet leakage between kernel switch init and uci swconfig uboot behaviour & system 'recovery' uboot expects to find bootable kernels at nand addresses 0x200000 & 0x600000 known by uboot as "system 1" and "system 2" respectively. uboot chooses which system to hand control to based on 3 environment variables: flag_last_success, flag_try_sys1_failed & flag_try_sys2_failed last_success represents a preference for a particular system and is set to 0 for system 1, set to 1 for system 2. last_success is considered *if* and only if both try_sys'n'_failed flags are 0 (ie. unset) If *either* failed flags are set then uboot will attempt to hand control to the non failed system. If both failed flags are set then uboot will check the uImage CRC of system 1 and hand control to it if ok. If the uImage CRC of system is not ok, uboot will hand control to system 2 irrespective of system 2's uImage CRC. NOTE: uboot only ever sets failed flags, it *never* clears them. uboot sets a system's failed flag if that system's was selected for boot but the uImage CRC is incorrect. Fortunately with serial console access, uboot provides the ability to boot an initramfs image transferred via tftp, similarly an image may be flashed to nand however it will flash to *both* kernels so a backup of stock kernel image is suggested. Note that the suggested install procedure below set's system 1's failed flag (stock) thus uboot ignores the last_success preference and boots LEDE located in system 2. Considerable thought has gone into whether LEDE should replace both kernels, only one (and which one) etc. LEDE kernels do not include a minimal rootfs and thus unlike the stock kernel cannot include a method of controlling uboot environment variables in the event of rootfs mount failure. Similarly uboot fails to provide an external mechanism for indicating boot system failure. Installation - from stock. Installation through telnet/ssh: - copy lede-ramips-mt7621-mir3g-squashfs-kernel1.bin and lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin to usb disk or wget it from LEDE download site to /tmp - switch to /extdisks/sda1/ (if copied to USB drive) or to /tmp if wgetted from LEDE download site - run: mtd write lede-ramips-mt7621-mir3g-squashfs-kernel1.bin kernel1 - run: mtd write lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin rootfs0 - run: nvram set flag_try_sys1_failed=1 - run: nvram commit - run: reboot Recovery - to stock. Assuming you used the above installation instructions you will have a stock kernel image in system 1. If it can be booted then it may be used to perform a stock firmware recovery, thus erasing LEDE completely. From a 'working' LEDE state (even failsafe) Failsafe only: - run: mount_root - run: sh /etc/uci-defaults/30_uboot-envtools Then do the steps for 'All' All: - run: fw_setenv flag_try_sys2_failed 1 - run: reboot The board will reboot into system 1 (stock basic kernel) and wait with system red light slowly blinking for a FAT formatted usb stick with a recovery image to be inserted. Press and hold the reset button for around 1 second. Status LED will turn yellow during recovery and blue when recovery complete. Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
1 parent 6a5b62f commit f2107fc

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

package/boot/uboot-envtools/files/ramips

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ wsr-600|\
2828
zbt-wg2626)
2929
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
3030
;;
31+
mir3g)
32+
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
33+
;;
3134
esac
3235

3336
config_load ubootenv

target/linux/ramips/base-files/etc/board.d/01_leds

+3-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ miniembplug)
253253
set_usb_led "$board:green:mobile"
254254
;;
255255
mir3g)
256-
ucidef_set_led_netdev "eth" "Ethernet" "$board:red:wan" "eth0"
257-
set_usb_led "$board:blue:usb"
256+
ucidef_set_led_switch "wan-amber" "WAN (amber)" "$board:amber:wan" "switch0" "0x02" "0x08"
257+
ucidef_set_led_switch "lan1-amber" "LAN1 (amber)" "$board:amber:lan1" "switch0" "0x08" "0x08"
258+
ucidef_set_led_switch "lan2-amber" "LAN2 (amber)" "$board:amber:lan2" "switch0" "0x04" "0x08"
258259
;;
259260
miwifi-mini)
260261
ucidef_set_led_default "power" "power" "$board:red:status" "1"

target/linux/ramips/base-files/etc/board.d/02_network

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ ramips_setup_interfaces()
124124
;;
125125
mir3g)
126126
ucidef_add_switch "switch0" \
127-
"1:wan" "2:lan:2" "3:lan:1" "6@eth0"
127+
"2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
128128
;;
129129
psg1218b)
130130
ucidef_add_switch "switch0" \
@@ -429,7 +429,7 @@ ramips_setup_macs()
429429
wan_mac=$(macaddr_add "$lan_mac" 1)
430430
;;
431431
mir3g)
432-
lan_mac=$(mtd_get_mac_binary Factory e006)
432+
lan_mac=$(mtd_get_mac_binary Factory 0xe006)
433433
;;
434434
miwifi-mini)
435435
wan_mac=$(cat /sys/class/net/eth0/address)

target/linux/ramips/dts/MIR3G.dts

+53-21
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,36 @@
2121
gpio-leds {
2222
compatible = "gpio-leds";
2323

24-
wan {
25-
label = "mir3g:red:wan";
24+
status_red {
25+
label = "mir3g:red:status";
2626
gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
2727
};
2828

29-
usb {
30-
label = "mir3g:blue:usb";
29+
status_blue {
30+
label = "mir3g:blue:status";
3131
gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
3232
};
3333

34-
status {
34+
status_yellow {
3535
label = "mir3g:yellow:status";
3636
gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
3737
};
38+
39+
wan_amber {
40+
label = "mir3g:amber:wan";
41+
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
42+
};
43+
44+
lan1_amber {
45+
label = "mir3g:amber:lan1";
46+
gpios = <&gpio0 14 GPIO_ACTIVE_LOW>;
47+
};
48+
49+
lan2_amber {
50+
label = "mir3g:amber:lan2";
51+
gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
52+
};
53+
3854
};
3955

4056
gpio-keys-polled {
@@ -45,10 +61,21 @@
4561

4662
reset {
4763
label = "reset";
48-
gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
64+
gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
4965
linux,code = <KEY_RESTART>;
5066
};
5167
};
68+
69+
gpio_export {
70+
compatible = "gpio-export";
71+
#size-cells = <0>;
72+
73+
usbpower {
74+
gpio-export,name = "usbpower";
75+
gpio-export,output = <1>;
76+
gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
77+
};
78+
};
5279
};
5380

5481
&nand {
@@ -63,7 +90,6 @@
6390
partition@80000 {
6491
label = "Config";
6592
reg = <0x80000 0x40000>;
66-
read-only;
6793
};
6894

6995
partition@c0000 {
@@ -81,13 +107,11 @@
81107
partition@140000 {
82108
label = "crash";
83109
reg = <0x140000 0x40000>;
84-
read-only;
85110
};
86111

87112
partition@180000 {
88113
label = "crash_syslog";
89114
reg = <0x180000 0x40000>;
90-
read-only;
91115
};
92116

93117
partition@1c0000 {
@@ -96,15 +120,22 @@
96120
read-only;
97121
};
98122

99-
/*
100-
* kernel0 partition should be erased, so
101-
* u-boot in failsafe routine switches
102-
* to next one looking for kernel image.
103-
* To remind about this fact rename kernel0
104-
* into kernel_erase.
123+
/* uboot expects to find kernels at 0x200000 & 0x600000
124+
* referred to as system 1 & system 2 respectively.
125+
* a kernel is considered suitable for handing control over
126+
* if its linux magic number exists & uImage CRC are correct.
127+
* If either of those conditions fail, a matching sys'n'_fail flag
128+
* is set in uboot env & a restart performed in the hope that the
129+
* alternate kernel is okay.
130+
* if neither kernel checksums ok and both are marked failed, system 2
131+
* is booted anyway.
132+
*
133+
* Note uboot's tftp flash install writes the transferred
134+
* image to both kernel partitions.
105135
*/
136+
106137
partition@200000 {
107-
label = "kernel_erase";
138+
label = "kernel_stock";
108139
reg = <0x200000 0x400000>;
109140
};
110141

@@ -114,12 +145,13 @@
114145
};
115146

116147
/* ubi partition is the result of squashing
117-
* next consequent stock partitions:
118-
* - rootfs0 (rootfs partition for stock kernel0),
119-
* - rootfs1 (rootfs partition for stock failsafe kernel1),
148+
* next consecutive stock partitions:
149+
* - rootfs0 (rootfs partition for stock kernel0),
150+
* - rootfs1 (rootfs partition for stock failsafe kernel1),
120151
* - overlay (used as ubi overlay in stock fw)
121152
* resulting 117,5MiB space for packages.
122153
*/
154+
123155
partition@a00000 {
124156
label = "ubi";
125157
reg = <0xa00000 0x7580000>;
@@ -136,7 +168,7 @@
136168
mediatek,mtd-eeprom = <&factory 0x0000>;
137169
ieee80211-freq-limit = <2400000 2500000>;
138170
};
139-
};
171+
};
140172

141173
pcie1 {
142174
wifi@14c3,7662 {
@@ -156,7 +188,7 @@
156188
&pinctrl {
157189
state_default: pinctrl0 {
158190
gpio {
159-
ralink,group = "jtag", "uart3", "wdt";
191+
ralink,group = "jtag", "uart2", "uart3", "wdt";
160192
ralink,function = "gpio";
161193
};
162194
};

target/linux/ramips/image/mt7621.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ define Device/mir3g
121121
SUPPORTED_DEVICES += R3G
122122
DEVICE_PACKAGES := \
123123
kmod-mt7603 kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport wpad-mini \
124-
kmod-softdog
124+
uboot-envtools
125125
endef
126126
TARGET_DEVICES += mir3g
127127

0 commit comments

Comments
 (0)