mir3.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. From aa2cc7b9d5124216f0ea377f9ffe28e494da20c6 Mon Sep 17 00:00:00 2001
  2. From: Chen Minqiang <[email protected]>
  3. Date: Sat, 18 Nov 2017 21:35:39 +0800
  4. Subject: [PATCH] ramips: add xiaomi_miwifi-r3 support
  5. Specification:
  6. - CPU: 580 MHz
  7. - Flash size: 128 MiB NAND
  8. - RAM size: 128 MiB DDR2
  9. - Wireless No1: SoC-integrated: MT7620A 2x2 MIMO 802.11b/g/n (2.4 GHz)
  10. - Wireless No2: On-board chip: MT7612E 2x2 MIMO 802.11a/n/ac (5 GHz)
  11. - Switch: MT7620 built-in 10/100 switch w/ vlan support
  12. - USB: 2.0 x1
  13. Flash instructions:
  14. 1. access ssh via https://wiki.openwrt.org/toh/xiaomi/mir3
  15. 2. in ssh:
  16. nvram set flag_last_success=1
  17. nvram set boot_wait=on
  18. nvram set uart_en=1
  19. nvram commit
  20. mtd write lede-ramips-mt7620-miwifi-r3-squashfs-kernel1.bin kernel1
  21. mtd write lede-ramips-mt7620-miwifi-r3-squashfs-rootfs0.bin rootfs0
  22. reboot
  23. If you want to revert back to stock fw while on LEDE:
  24. insert usb stick (FAT/FAT32) with stock fw renamed to miwifi.bin
  25. fw_setenv flag_last_success 0
  26. power off the device
  27. hold the reset button and power on the device, keep holding the reset button until yellow led starts blinking.
  28. Signed-off-by: Chen Minqiang <[email protected]>
  29. ---
  30. package/boot/uboot-envtools/files/ramips | 1 +
  31. .../ramips/dts/mt7620a_xiaomi_miwifi-r3.dts | 187 ++++++++++++++++++
  32. target/linux/ramips/image/mt7620.mk | 17 ++
  33. .../mt7620/base-files/etc/board.d/02_network | 8 +
  34. .../mt7620/base-files/lib/upgrade/platform.sh | 7 +
  35. 5 files changed, 220 insertions(+)
  36. create mode 100644 target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts
  37. diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips
  38. index 05ca7ffd12c8..6afc4470f7a7 100644
  39. --- a/package/boot/uboot-envtools/files/ramips
  40. +++ b/package/boot/uboot-envtools/files/ramips
  41. @@ -79,6 +79,7 @@ xiaomi,mi-router-3g|\
  42. xiaomi,mi-router-3-pro|\
  43. xiaomi,mi-router-4|\
  44. xiaomi,mi-router-ac2100|\
  45. +xiaomi,miwifi-r3|\
  46. xiaomi,redmi-router-ac2100)
  47. ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
  48. ubootenv_add_uci_sys_config "/dev/mtd2" "0x0" "0x4000" "0x20000"
  49. diff --git a/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts b/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts
  50. new file mode 100644
  51. index 000000000000..301b6e3a02e6
  52. --- /dev/null
  53. +++ b/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts
  54. @@ -0,0 +1,187 @@
  55. +/dts-v1/;
  56. +
  57. +#include "mt7620a.dtsi"
  58. +
  59. +#include <dt-bindings/gpio/gpio.h>
  60. +#include <dt-bindings/input/input.h>
  61. +
  62. +/ {
  63. + compatible = "xiaomi,miwifi-r3", "ralink,mt7620a-soc";
  64. + model = "Xiaomi Mi Router R3";
  65. +
  66. + aliases {
  67. + led-status = &led_status_blue;
  68. + };
  69. +
  70. + chosen {
  71. + bootargs = "console=ttyS0,115200";
  72. + };
  73. +
  74. + keys {
  75. + compatible = "gpio-keys";
  76. +
  77. + reset {
  78. + label = "reset";
  79. + gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
  80. + linux,code = <KEY_RESTART>;
  81. + };
  82. + };
  83. +
  84. + leds {
  85. + compatible = "gpio-leds";
  86. +
  87. + led_status_blue: blue {
  88. + label = "blue:status";
  89. + gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
  90. + default-state = "on";
  91. + };
  92. +
  93. + yellow {
  94. + label = "yellow:status";
  95. + gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
  96. + };
  97. +
  98. + red {
  99. + label = "red:status";
  100. + gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
  101. + };
  102. + };
  103. +
  104. + nand {
  105. + status = "okay";
  106. + #address-cells = <1>;
  107. + #size-cells = <1>;
  108. + compatible = "mtk,mt7620-nand";
  109. +
  110. + partitions {
  111. + compatible = "fixed-partitions";
  112. + #address-cells = <1>;
  113. + #size-cells = <1>;
  114. +
  115. + partition@0 {
  116. + label = "Bootloader";
  117. + reg = <0x0 0x40000>;
  118. + read-only;
  119. + };
  120. +
  121. + partition@40000 {
  122. + label = "Config";
  123. + reg = <0x40000 0x40000>;
  124. + };
  125. +
  126. + partition@80000 {
  127. + label = "Bdata";
  128. + reg = <0x80000 0x40000>;
  129. + read-only;
  130. + };
  131. +
  132. + factory: partition@0xc0000 {
  133. + label = "factory";
  134. + reg = <0xc0000 0x40000>;
  135. + read-only;
  136. + };
  137. +
  138. + partition@100000 {
  139. + label = "crash";
  140. + reg = <0x100000 0x40000>;
  141. + read-only;
  142. + };
  143. +
  144. + partition@140000 {
  145. + label = "crash_syslog";
  146. + reg = <0x140000 0x40000>;
  147. + read-only;
  148. + };
  149. +
  150. + partition@180000 {
  151. + label = "reserved0";
  152. + reg = <0x180000 0x80000>;
  153. + read-only;
  154. + };
  155. +
  156. + partition@200000 {
  157. + label = "kernel_stock";
  158. + reg = <0x200000 0x400000>;
  159. + };
  160. +
  161. + partition@600000 {
  162. + label = "kernel";
  163. + reg = <0x600000 0x400000>;
  164. + };
  165. +
  166. + /* ubi partition is the result of squashing
  167. + * next consequent stock partitions:
  168. + * - rootfs0 (rootfs partition for stock kernel0),
  169. + * - rootfs1 (rootfs partition for stock failsafe kernel1),
  170. + * - overlay (used as ubi overlay in stock fw)
  171. + * resulting 117,5MiB space for packages.
  172. + */
  173. + partition@a00000 {
  174. + label = "ubi";
  175. + reg = <0xa00000 0x7600000>;
  176. + };
  177. + };
  178. + };
  179. +};
  180. +
  181. +&gpio1 {
  182. + status = "okay";
  183. +};
  184. +
  185. +&ehci {
  186. + status = "okay";
  187. +};
  188. +
  189. +&ohci {
  190. + status = "okay";
  191. +};
  192. +
  193. +&ethernet {
  194. + pinctrl-names = "default";
  195. + pinctrl-0 = <&ephy_pins>;
  196. + mtd-mac-address = <&factory 0x28>;
  197. + nvmem-cells = <&macaddr_factory_28>;
  198. + nvmem-cell-names = "mac-address";
  199. + mediatek,portmap = "llllw";
  200. +};
  201. +
  202. +&wmac {
  203. + ralink,mtd-eeprom = <&factory 0>;
  204. +};
  205. +
  206. +&pcie {
  207. + status = "okay";
  208. +};
  209. +
  210. +&pcie0 {
  211. + wifi@0,0 {
  212. + compatible = "pci14c3,7662";
  213. + reg = <0x0000 0 0 0 0>;
  214. + mediatek,mtd-eeprom = <&factory 0x8000>;
  215. + ieee80211-freq-limit = <5000000 6000000>;
  216. + };
  217. +};
  218. +
  219. +&pinctrl {
  220. + state_default: pinctrl0 {
  221. + gpio {
  222. + groups = "rgmii1";
  223. + function = "gpio";
  224. + };
  225. +
  226. + pa {
  227. + groups = "pa";
  228. + function = "pa";
  229. + };
  230. + };
  231. +};
  232. +
  233. +&factory {
  234. + compatible = "nvmem-cells";
  235. + #address-cells = <1>;
  236. + #size-cells = <1>;
  237. +
  238. + macaddr_factory_28: macaddr@28 {
  239. + reg = <0x28 0x6>;
  240. + };
  241. +};
  242. diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
  243. index a9dea1db57f9..ebf4cfc4117c 100644
  244. --- a/target/linux/ramips/image/mt7620.mk
  245. +++ b/target/linux/ramips/image/mt7620.mk
  246. @@ -1248,6 +1248,23 @@ define Device/xiaomi_miwifi-mini
  247. endef
  248. TARGET_DEVICES += xiaomi_miwifi-mini
  249. +define Device/xiaomi_miwifi-r3
  250. + SOC := mt7620a
  251. + BLOCKSIZE := 128k
  252. + PAGESIZE := 2048
  253. + KERNEL_SIZE := 4096k
  254. + IMAGE_SIZE := 32768k
  255. + UBINIZE_OPTS := -E 5
  256. + IMAGES += kernel1.bin rootfs0.bin
  257. + IMAGE/kernel1.bin := append-kernel | check-size $$$$(KERNEL_SIZE)
  258. + IMAGE/rootfs0.bin := append-ubi | check-size $$$$(IMAGE_SIZE)
  259. + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  260. + DEVICE_VENDOR := Xiaomi
  261. + DEVICE_MODEL := Mi Router R3
  262. + DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci uboot-envtools
  263. +endef
  264. +TARGET_DEVICES += xiaomi_miwifi-r3
  265. +
  266. define Device/youku_yk-l1
  267. SOC := mt7620a
  268. IMAGE_SIZE := 32448k
  269. diff --git a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  270. index f7bc41669f80..e252b6e04611 100644
  271. --- a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  272. +++ b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  273. @@ -278,6 +278,10 @@ ramips_setup_interfaces()
  274. ucidef_add_switch "switch0" \
  275. "0:lan" "1:lan" "4:wan" "6@eth0"
  276. ;;
  277. + xiaomi,miwifi-r3)
  278. + ucidef_add_switch "switch0" \
  279. + "1:lan" "4:lan" "0:wan" "6@eth0"
  280. + ;;
  281. zbtlink,zbt-we1026-5g-16m)
  282. ucidef_add_switch "switch0" \
  283. "0:lan" "6t@eth0"
  284. @@ -434,6 +438,10 @@ ramips_setup_macs()
  285. tplink,ec220-g5-v2)
  286. wan_mac=$(macaddr_add "$(mtd_get_mac_binary rom 0xf100)" 1)
  287. ;;
  288. + xiaomi,miwifi-r3)
  289. + wan_mac=$(mtd_get_mac_binary factory 0x28)
  290. + lan_mac=$(macaddr_setbit_la "$wan_mac")
  291. + ;;
  292. wavlink,wl-wn531g3|\
  293. wavlink,wl-wn531g3-a2|\
  294. zbtlink,zbt-we1026-5g-16m)
  295. diff --git a/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  296. index 9f71dc918e50..5519312289fa 100755
  297. --- a/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  298. +++ b/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  299. @@ -30,6 +30,11 @@ platform_do_upgrade() {
  300. }
  301. default_do_upgrade "$1"
  302. ;;
  303. + xiaomi,miwifi-r3)
  304. + # this make it compatible with breed
  305. + dd if=/dev/mtd0 bs=64 count=1 2>/dev/null | grep -qi breed && CI_KERNPART_EXT="kernel_stock"
  306. + nand_do_upgrade "$1"
  307. + ;;
  308. *)
  309. default_do_upgrade "$1"
  310. ;;