This commit adds OpenWrt U-Boot (UBI) layout support for MERCUSYS MR90X
v1.
Stock U-Boot UBI size:   50 MiB
OpenWrt U-boot UBI size: 126 MiB
Install
-------
1. Perform steps 1-14 of the OpenWrt installation guide (use OpenWrt
   initramfs-recovery.itb instead of initramfs-kernel.bin at the step 10,
   12 and 14).
Link: https://openwrt.org/toh/mercusys/mr90x_v1#installation
2. Make backups:
```
cat /dev/mtd0 > /tmp/boot.bin
cat /dev/mtd5 > /tmp/tp_data.bin
```
   Copy /tp_data dir content, /tmp/boot.bin and /tmp/tp_data.bin and to
   your PC using scp. You can also backup the remaining partititons. Copy
   backups to a safe place, they are required for the next steps and stock
   firmware recovery.
3. Reboot to OpenWrt initramfs:
```
reboot
```
4. Copy OpenWrt ubi-bl31-uboot.fip, ubi-preloader.bin,
   ubi-squashfs-sysupgrade.itb and MT7986_EEPROM.bin, default-mac (from
   /tp_data backup) to the /tmp folder of the router using scp.
5. Prepare UBI:
```
ubidetach -p /dev/mtd3; ubiformat /dev/mtd3 -y; ubiattach -p /dev/mtd3
ubimkvol /dev/ubi0 -N fip -t static -s 1MiB
ubiupdatevol /dev/ubi0_0 /tmp/ubi-bl31-uboot.fip
ubimkvol /dev/ubi0 -N ubootenv -s 0x1f000
ubimkvol /dev/ubi0 -N ubootenv2 -s 0x1f000
```
6.  Install kmod-mtd-rw and unlock partitions:
```
opkg update && opkg install kmod-mtd-rw
insmod mtd-rw i_want_a_brick=1
mtd unlock boot
mtd unlock bl2
mtd unlock factory
```
7. Prepare "factory" partition:
```
dd if=/dev/zero bs=$((0x8000)) count=1 | tr '\000' '\377' > /tmp/factory.bin
dd if=/tmp/MT7986_EEPROM.bin of=/tmp/factory.bin conv=notrunc
dd if=/tmp/default-mac >> /tmp/factory.bin
```
8. Write "factory" partition:
```
mtd erase factory
mtd write /tmp/factory.bin factory
```
9. Write preloader partition:
```
mtd erase bl2
mtd write /tmp/ubi-preloader.bin bl2
```
10. Write OpenWrt sysupgrade image:
```
sysupgrade -n /tmp/ubi-squashfs-sysupgrade.itb
```
Recovery
--------
1. Place OpenWrt initramfs-recovery.itb image (with original name) on the
   tftp server (IP: 192.168.1.254).
2. Press "reset" button and power on the router. After ~10 sec release the
   button.
3. Use OpenWrt initramfs system for recovery.
BL2 and FIP recovery
--------------------
Use mtk_uartboot and UART connetion if BL2 or FIP in UBI is destroyed:
Link: https://github.com/981213/mtk_uartboot
Link: https://openwrt.org/toh/mercusys/mr90x_v1#serial
Return to stock:
----------------
1. Copy "boot" partition backup (boot.bin) to the /tmp dir of the router
   using scp.
2. Install kmod-mtd-rw:
```
opkg update && opkg install kmod-mtd-rw
```
3. Restore stock U-Boot:
```
   insmod mtd-rw i_want_a_brick=1
   mtd unlock boot
   mtd erase boot
   mtd write /tmp/boot.bin boot
```
4. Erase UBI and reboot:
```
mtd erase ubi
reboot
```
5. Open U-Boot web recovery, upload stock firmware image and start
   upgrade.
Link: http://192.168.1.1
6. Complete steps 1-9 of the OpenWrt installation guide to get root
   rights.
Link: https://openwrt.org/toh/mercusys/mr90x_v1#installation
7. Upload "tp_data" partition backup (tp_data.bin) to the /tmp folder of
   the router using scp.
8. Restore stock calibrations:
```
mtd write /tmp/tp_data.bin tp_data
reboot
```
9. Perform "factory restore" via stock firmware web interface.
Signed-off-by: Mikhail Zhilkin <csharper2005@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16744
(cherry picked from commit ee8df790ca)
Signed-off-by: Mikhail Zhilkin <csharper2005@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/17129
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
		
	
		
			
				
	
	
		
			148 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
#
 | 
						|
# Copyright (C) 2021 OpenWrt.org
 | 
						|
#
 | 
						|
 | 
						|
[ -e /etc/config/ubootenv ] && exit 0
 | 
						|
 | 
						|
touch /etc/config/ubootenv
 | 
						|
 | 
						|
. /lib/uboot-envtools.sh
 | 
						|
. /lib/functions.sh
 | 
						|
 | 
						|
board=$(board_name)
 | 
						|
 | 
						|
ubootenv_add_mmc_default() {
 | 
						|
	local envdev="$(find_mmc_part "ubootenv" "${1:-mmcblk0}")"
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x40000" "0x40000" "1"
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x40000" "0x40000" "0x40000" "1"
 | 
						|
}
 | 
						|
 | 
						|
ubootenv_add_nor_default() {
 | 
						|
	local envdev="/dev/mtd$(find_mtd_index "u-boot-env")"
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1"
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x20000" "0x20000" "0x20000" "1"
 | 
						|
}
 | 
						|
 | 
						|
ubootenv_add_ubi_default() {
 | 
						|
	. /lib/upgrade/nand.sh
 | 
						|
	local envubi=$(nand_find_ubi ubi)
 | 
						|
	local envdev=/dev/$(nand_find_volume $envubi ubootenv)
 | 
						|
	local envdev2=/dev/$(nand_find_volume $envubi ubootenv2)
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1"
 | 
						|
	ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1"
 | 
						|
}
 | 
						|
 | 
						|
case "$board" in
 | 
						|
abt,asr3000|\
 | 
						|
h3c,magic-nx30-pro|\
 | 
						|
jcg,q30-pro|\
 | 
						|
mercusys,mr90x-v1-ubi|\
 | 
						|
netcore,n60|\
 | 
						|
nokia,ea0326gmp|\
 | 
						|
qihoo,360t7|\
 | 
						|
routerich,ax3000-ubootmod|\
 | 
						|
tplink,tl-xdr4288|\
 | 
						|
tplink,tl-xdr6086|\
 | 
						|
tplink,tl-xdr6088|\
 | 
						|
tplink,tl-xtr8488|\
 | 
						|
xiaomi,mi-router-ax3000t-ubootmod|\
 | 
						|
xiaomi,mi-router-wr30u-ubootmod|\
 | 
						|
xiaomi,redmi-router-ax6000-ubootmod|\
 | 
						|
zyxel,ex5601-t0-ubootmod)
 | 
						|
	ubootenv_add_ubi_default
 | 
						|
	;;
 | 
						|
acer,predator-w6|\
 | 
						|
acer,predator-w6d|\
 | 
						|
acer,vero-w6m|\
 | 
						|
glinet,gl-mt2500|\
 | 
						|
glinet,gl-mt6000|\
 | 
						|
glinet,gl-x3000|\
 | 
						|
glinet,gl-xe3000)
 | 
						|
	local envdev=$(find_mmc_part "u-boot-env")
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x80000"
 | 
						|
	;;
 | 
						|
asus,rt-ax59u)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd0" "0x100000" "0x20000" "0x20000"
 | 
						|
	;;
 | 
						|
bananapi,bpi-r3|\
 | 
						|
bananapi,bpi-r3-mini|\
 | 
						|
bananapi,bpi-r4|\
 | 
						|
bananapi,bpi-r4-poe|\
 | 
						|
cmcc,rax3000m|\
 | 
						|
jdcloud,re-cp-03)
 | 
						|
	. /lib/upgrade/fit.sh
 | 
						|
	export_fitblk_bootdev
 | 
						|
	case "$CI_METHOD" in
 | 
						|
	ubi)
 | 
						|
		ubootenv_add_ubi_default
 | 
						|
		;;
 | 
						|
	emmc)
 | 
						|
		bootdev=${EMMC_KERN_DEV%%p[0-9]*}
 | 
						|
		ubootenv_add_mmc_default "${bootdev#/dev/}"
 | 
						|
		;;
 | 
						|
	default)
 | 
						|
		ubootenv_add_nor_default
 | 
						|
		;;
 | 
						|
	esac
 | 
						|
	;;
 | 
						|
comfast,cf-e393ax)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x80000"
 | 
						|
	;;
 | 
						|
cetron,ct3003|\
 | 
						|
edgecore,eap111|\
 | 
						|
netgear,wax220|\
 | 
						|
zbtlink,zbt-z8102ax|\
 | 
						|
zbtlink,zbt-z8103ax)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
 | 
						|
	;;
 | 
						|
dlink,aquila-pro-ai-m30-a1)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
 | 
						|
	;;
 | 
						|
gatonetworks,gdsp)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
 | 
						|
	;;
 | 
						|
glinet,gl-mt3000)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x20000"
 | 
						|
	;;
 | 
						|
mercusys,mr90x-v1|\
 | 
						|
routerich,ax3000|\
 | 
						|
tplink,re6000xd)
 | 
						|
	local envdev=/dev/mtd$(find_mtd_index "u-boot-env")
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1"
 | 
						|
	;;
 | 
						|
openembed,som7981)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x80000"
 | 
						|
	ubootenv_add_uci_sys_config "/dev/mtd3" "0x0" "0x100000" "0x100000"
 | 
						|
	;;
 | 
						|
openwrt,one)
 | 
						|
	ubootenv_add_ubi_default
 | 
						|
	;;
 | 
						|
smartrg,sdg-8733|\
 | 
						|
smartrg,sdg-8733a|\
 | 
						|
smartrg,sdg-8734)
 | 
						|
	local envdev=$(find_mmc_part "u-boot-env" "mmcblk0")
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x8000" "0x8000"
 | 
						|
	;;
 | 
						|
ubnt,unifi-6-plus)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x10000"
 | 
						|
	;;
 | 
						|
xiaomi,mi-router-ax3000t|\
 | 
						|
xiaomi,mi-router-wr30u-stock|\
 | 
						|
xiaomi,redmi-router-ax6000-stock)
 | 
						|
	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x20000"
 | 
						|
	ubootenv_add_uci_sys_config "/dev/mtd2" "0x0" "0x10000" "0x20000"
 | 
						|
	;;
 | 
						|
zyxel,ex5601-t0)
 | 
						|
	local envdev=/dev/mtd$(find_mtd_index "u-boot-env")
 | 
						|
	ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x40000" "2"
 | 
						|
	;;
 | 
						|
zyxel,ex5700-telenor)
 | 
						|
	ubootenv_add_uci_config "/dev/ubootenv" "0x0" "0x4000" "0x4000" "1"
 | 
						|
	;;
 | 
						|
esac
 | 
						|
 | 
						|
config_load ubootenv
 | 
						|
config_foreach ubootenv_add_app_config
 | 
						|
 | 
						|
exit 0
 |