Skip to content

Commit

Permalink
Update Gateway Global Tool to 20230821
Browse files Browse the repository at this point in the history
  • Loading branch information
niceboy committed Aug 21, 2023
1 parent 3e1740d commit fcfc2e4
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 73 deletions.
19 changes: 12 additions & 7 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@

### Linux/MacOS
1. Download [gw_global_tool.expect](https://github.com/niceboygithub/AqaraM1SM2fw/blob/main/tools/gw_global_tool.expect)
1. make sure following programs are installed (If MacOS, use brew to install):
2. make sure following programs are installed (If MacOS, use brew to install):
```
* expect
* sx/lsx (from package lrzsz)
* stty
1. make sure that flasher (flasher*.bin) are in the same folder
1. make sure you're in "dialout" group
1. run:
```
```
3. make sure that flasher (flasher*.bin) are in the same folder
4. make sure you're in "dialout" group
5. run:
```
chmod +x gw_global_tool.expect
./gw_global_tool.expect
```
1. follow on-screen instructions
```
6. follow on-screen instructions

#### TroubleShooting
1. If you see the error log "Uncompressing Linux...LZMA: Decoding error", try to normal boot and try again.


<a href="https://www.buymeacoffee.com/niceboygithub" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
93 changes: 62 additions & 31 deletions tools/gw_global_tool.expect
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This script was reference to https://raw.githubusercontent.com/serrj-sv/lumi.gateway.mgl03/main/uart_recovery/mgl03_uart_recovery.ttl
#

set version "20230815"
set version "20230821"

puts "Xiaomi/Aqara Gateway Global tool script version: $version"
puts "Requires:"
Expand All @@ -28,7 +28,7 @@ puts "\n\nConnect Gateway to UART, disconnect it from power\n"

puts "Please select choose your gateway:"
puts "\[0\] Xiaomi Multimode Gateway 1"
puts "\[1\] Aqara Gateway M2 Global/China"
puts "\[1\] Aqara Gateway M2 old Global/China, M1S, H1, P3"
puts "\[2\] Aqara Gateway M2 Korea"
puts "\[3\] Other Gateway with SoC RTL8197F"
set idx 0
Expand Down Expand Up @@ -114,11 +114,11 @@ set console $spawn_id
puts "\nPower ON Gateway NOW!"

expect {
"uart ok" {
send -- "u"
}
"Enter ROM console" {
puts "Connected to correct flahser!"
"uart ok" {
send -- "u"
}
"Enter ROM console" {
puts "Connected to correct flahser!"
}
"load img ok" {
puts "Connected to wrong flahser!"
Expand Down Expand Up @@ -163,6 +163,7 @@ send "\r"
expect "<RealTek>"

# boot
puts "If it got 'Uncompressing Linux...LZMA: Decoding error', please try restart the gateway and try again."
send "bootsh\r"
expect "BusyBox v"
expect "#"
Expand All @@ -176,13 +177,13 @@ if { $gwtype == 0} {
expect "#"
send "/var/tmp/rcS\r"
} elseif { $gwtype == 1 } {
send "mount -t proc proc /proc; mount -t ramfs ramfs /var; mount -t sysfs sysfs /sys; mkdir /var/tmp\r"
send "mount -t ramfs ramfs /var; mkdir /var/tmp\r"
expect "#"
send "kick_wdog_timer.sh &\r"
send "cp /etc/init.d/rcS /var/tmp/rcS\r"
expect "#"
send "kick_wdog &\r"
send "sed -i 's/fw_manager.sh -r/echo skip/g' /var/tmp/rcS\r"
expect "#"
send 'ubifs_mount'
send "/var/tmp/rcS\r"
} elseif { $gwtype == 2 } {
send "mount -t proc proc /proc; mount -t ramfs ramfs /var; mount -t sysfs sysfs /sys; mkdir /var/tmp\r"
expect "#"
Expand All @@ -203,54 +204,84 @@ if { $gwtype == 0} {
expect "#"
send "passwd -d admin\r"
expect "#"
set modelname 0
if { $gwtype == 0} {
puts "\n\nGateway token in ASCII (use xxd -p to convert to 32 characters hexadecimal string):"
send "cat /data/miio/device.token\r"
expect "#"
puts "\nGateway Info:"
send "cat /data/miio/device.conf\r"
} elseif { $gwtype == 1 } {
send "[ -d /data/storage ] || mkdir -p /data/storage\r"
expect "#"
send "property_service -i /etc/build.prop -p /data/storage/prop.dat -b\r"
expect "#"
send "setprop persist.app.tty_enable truer\r"
expect "#"
puts "\nGateway Info:"
send "getprop | grep miio\r"
expect "#"
send "getprop persist.sys.model"
expect {
"lumi.gateway.acn01" {
set modelname 1
}
"lumi.aircondition.acn05" {
set modelname 2
}
"lumi.gateway.iragl5" {
set modelname 3
}
"lumi.gateway.agl001" {
set modelname 3
}
"lumi.gateway.sacn01" {
set modelname 4
}
}
} elseif { $gwtype == 2 } {
send "cat /lumi/app/gw/conf/device.conf\r"
}
expect "#"

send "reboot\r"
close $console

if { $gwtype == 1} {
puts "\nGateway clear password complete, and the gateway info is showed, then it will be rebooted!\n If the gateway is CN or new Global version, you can flash modified firmware after reboot to enable telnet."

send_user "\nWould you like to flash M2 modified firmware? (y/N): "
expect_user -re "(.*)\n"
set test $expect_out(1,string)
if {$test == "y"} {
puts "1. Connect Gateway to ethernet\n2. Make sure that gateway connect to internet (access to github)"
send 'ifconfig eth0 up'
expect '#'
send 'ifconfig lo up'
expect '#'
send 'udhcpc -i eth0'
expect '#'
send 'cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl'
expect '#'
send '/tmp/curl -s -k -L -o /tmp/m2_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/M2/m2_update.sh'
expect '#'
send 'chmod a+x /tmp/m2_update.sh && /tmp/m2_update.sh'
expect '#'
puts "1. Connect Gateway to ethernet \n2. Make sure that gateway connect to internet (access to github) \n3.While flashing firmware, PLEASE donot disconnect the power"
send "fw_manager.sh -r\r"
expect "#"
expect "mDNSResponder"
send "cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl\r"
expect "#"
if { $modelname == 1} {
send "/tmp/curl -s -k -L -o /tmp/m1s_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/M1S/m1s_update.sh\r"
expect "#"
send "chmod a+x /tmp/m1s_update.sh && /tmp/m1s_update.sh\r"
} elseif { $gwtype == 2} {
send "/tmp/curl -s -k -L -o /tmp/p3_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/P3/p3_update.sh\r"
expect "#"
send "chmod a+x /tmp/p3_update.sh && /tmp/p3_update.sh\r"
} elseif { $gwtype == 3} {
send "/tmp/curl -s -k -L -o /tmp/m2_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/M2/m2_update.sh\r"
expect "#"
send "chmod a+x /tmp/m2_update.sh && /tmp/m2_update.sh\r"
} elseif { $gwtype == 4} {
send "/tmp/curl -s -k -L -o /tmp/h1_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/H1/h1_update.sh\r"
expect "#"
send "chmod a+x /tmp/h1_update.sh && /tmp/h1_update.sh\r"
} else {
puts "Error: Unkown supported gateway"
send "\r"
}
expect "#"
}
} else {
puts "\nGateway clear password complete, and the gateway info is showed, then it will be rebooted!"
}

send "reboot\r"
close $console

send_user "\nIf this project helped you, you can treat me with a cup of coffee :)\nOpen url $coffee_url1 (y/N): "
expect_user -re "(.*)\n"
set test $expect_out(1,string)
Expand Down
57 changes: 22 additions & 35 deletions tools/gw_global_tool.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
; This script was reference to https://raw.githubusercontent.com/serrj-sv/lumi.gateway.mgl03/main/uart_recovery/mgl03_uart_recovery.ttl
;

version='20230815'
version='20230821'
setsync 0
show -1
enablekeyb 0
setspeed 38400

strdim msg 4
msg[0] = 'Xiaomi Multimode Gateway 1'
msg[1] = 'Aqara Gateway M2 old Global/China, M1S, H1, P3'
msg[2] = 'Aqara Gateway M2 Korea'
msg[3] = 'Other Gateway with SoC RTL8197F'
listbox 'Please select choose your gateway' 'Confirmation' msg
gwtype=result
yesnobox 'Would you like to try automatic bootloader interrupt?\n (choose "No" if it fails for you)' 'Bootloader' 1
if result then
messagebox '1. Connect Gateway to UART\n2. Disconnect Gateway from power\n3. Press OK' 'Start' 1
Expand Down Expand Up @@ -53,13 +60,6 @@ dispstr #$1B"[2J" #$1B"[H"
sendln ''
wait '<RealTek>'
sendln 'xmrx 80000000'
strdim msg 4
msg[0] = 'Xiaomi Multimode Gateway 1'
msg[1] = 'Aqara Gateway M2 Global/China'
msg[2] = 'Aqara Gateway M2 Korea'
msg[3] = 'Other Gateway with SoC RTL8197F'
listbox 'Please select choose your gateway' 'Confirmation' msg
gwtype=result
getdir curdir
if gwtype=0 then
sprintf '%s\flasher_mgl03.bin' curdir inputstr
Expand All @@ -82,13 +82,12 @@ wait '<RealTek>'
dispstr #$1B"[2J" #$1B"[H"
sendln ''
wait '<RealTek>'
dispstr 'If it got "Uncompressing Linux...LZMA: Decoding error", please try restart the gateway and try again.\n'
sendln 'bootsh'
wait ''
wait 'BusyBox v'
wait '#'
if gwtype=0 then
;sendln 'kick_wdog_timer &'
;wait '#'
sendln 'mount -t ramfs ramfs /var; mkdir /var/tmp'
wait '#'
sendln 'cp /etc/init.d/rcS /var/tmp/rcS'
Expand All @@ -97,13 +96,13 @@ if gwtype=0 then
wait '#'
sendln '/var/tmp/rcS'
elseif gwtype=1 then
sendln 'mount -t proc proc /proc; mount -t ramfs ramfs /var; mount -t sysfs sysfs /sys; mkdir /var/tmp'
sendln 'mount -t ramfs ramfs /var; mkdir /var/tmp'
wait '#'
sendln 'kick_wdog_timer.sh &'
sendln 'cp /etc/init.d/rcS /var/tmp/rcS'
wait '#'
sendln 'kick_wdog &'
sendln "sed -i 's/fw_manager.sh -r/echo skip/g' /var/tmp/rcS"
wait '#'
sendln 'ubifs_mount'
sendln '/var/tmp/rcS'
elseif gwtype=2 then
sendln 'mount -t proc proc /proc; mount -t ramfs ramfs /var; mount -t sysfs sysfs /sys; mkdir /var/tmp'
wait '#'
Expand Down Expand Up @@ -131,10 +130,6 @@ if gwtype=0 then
waitln 'model='
model=inputstr
elseif gwtype=1 then
sendln '[ -d /data/storage ] || mkdir -p /data/storage'
wait '#'
sendln 'property_service -i /etc/build.prop -p /data/storage/prop.dat -b'
wait '#'
sendln 'setprop persist.app.tty_enable true'
wait '#'
sendln 'getprop | grep miio'
Expand All @@ -147,7 +142,7 @@ elseif gwtype=2 then
endif
wait '#'
if gwtype=1 then
message="Gateway clear password complete, and the gateway info is showed, then it will be rebooted!\n If the gateway is CN or new Global version, you can flash modified firmware after reboot to enable telnet."
message="Gateway clear password complete, and the gateway info is showed, then it will be rebooted! \n If the gateway is CN or new Global version, you can flash modified firmware after reboot to enable telnet."

yesnobox 'Would you like to flash M2 modified firmware?' 'flasher' 1
if result then
Expand All @@ -163,21 +158,10 @@ if gwtype=1 then
strcompare model 'lumi.gateway.sacn01'
if result=0 modelname=4 ; h1

messagebox '1. Connect Gateway to ethernet\n2. Make sure that gateway connect to internet (access to github)\n3. Press OK' 'Start' 1
sendln 'ifconfig lo up'
messagebox '1. Connect Gateway to ethernet \n2. Make sure that gateway connect to internet (access to github) \n3.While flashing firmware, PLEASE donot disconnect the power. \n4. Press OK' 'Start' 1
sendln 'fw_manager.sh -r'
wait '#'
strcompare model 'lumi.gateway.iragl5'
if modelname=3 then
sendln 'ifconfig eth0 up'
wait '#'
sendln 'udhcpc -i eth0'
wait '#'
else
sendln 'ifconfig wlan0 up'
wait '#'
sendln '/usr/factory_test/bin/wifi_test_station.sh $(getprop persist.app.wifi_ssid) $(getprop persist.app.wifi_passphrase)'
wait '#'
endif
wait 'mDNSResponder'
sendln 'cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl'
wait '#'
if modelname=1 then
Expand All @@ -197,15 +181,18 @@ if gwtype=1 then
wait '#'
sendln 'chmod a+x /tmp/h1_update.sh && /tmp/h1_update.sh'
else
messagebox 'Unknwn supported gateway' 'Error'
messagebox 'Unkown supported gateway' 'Error'
endif
wait '#'
endif
else
message="Gateway clear password complete, and the gateway info is showed, then it will be rebooted!"
endif

messagebox message 'Done'
messagebox message 'Done' 1
showtt -1
showtt 1
mpause 100
sendln 'reboot'
setspeed 38400
enablekeyb 1
Expand Down

0 comments on commit fcfc2e4

Please sign in to comment.