Skip to content

Commit 4d81280

Browse files
Add --1200bps-reset param to device-install/update scripts (#6752)
* add change-mode support * add change-mode support * tab to space * fix if check * change param name to 1200bps-reset * update help section * missed one in help seciton --------- Co-authored-by: Ben Meadors <[email protected]>
1 parent 9ce4455 commit 4d81280

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

bin/device-install.bat

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SET "BIGDB16=0"
1212
SET "ESPTOOL_BAUD=115200"
1313
SET "ESPTOOL_CMD="
1414
SET "LOGCOUNTER=0"
15+
SET "BPS_RESET=0"
1516

1617
@REM FIXME: Determine mcu from PlatformIO variant, this is unmaintainable.
1718
SET "S3=s3 v3 t-deck wireless-paper wireless-tracker station-g2 unphone"
@@ -24,7 +25,7 @@ GOTO getopts
2425
:help
2526
ECHO Flash image file to device, but first erasing and writing system information.
2627
ECHO.
27-
ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] (--web)
28+
ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] (--web) [--1200bps-reset]
2829
ECHO.
2930
ECHO Options:
3031
ECHO -f filename The firmware .bin file to flash. Custom to your device type and region. (required)
@@ -35,13 +36,16 @@ ECHO -P python Specify alternate python interpreter to use to invoke
3536
ECHO If supplied the script will use python.
3637
ECHO If not supplied the script will try to find esptool in Path.
3738
ECHO --web Enable WebUI. (default: false)
39+
ECHO --1200bps-reset Attempt to place the device in correct mode. (1200bps Reset)
40+
ECHO Some hardware requires this twice.
3841
ECHO.
42+
ECHO Example: %SCRIPT_NAME% -p COM17 --1200bps-reset
3943
ECHO Example: %SCRIPT_NAME% -f firmware-t-deck-tft-2.6.0.0b106d4.bin -p COM11
4044
ECHO Example: %SCRIPT_NAME% -f firmware-unphone-2.6.0.0b106d4.bin -p COM11 --web
4145
GOTO eof
4246

4347
:version
44-
ECHO %SCRIPT_NAME% [Version 2.6.1]
48+
ECHO %SCRIPT_NAME% [Version 2.6.2]
4549
ECHO Meshtastic
4650
GOTO eof
4751

@@ -58,10 +62,13 @@ IF "%~1"=="-p" SET "ESPTOOL_PORT=%~2" & SHIFT
5862
IF /I "%~1"=="--port" SET "ESPTOOL_PORT=%~2" & SHIFT
5963
IF "%~1"=="-P" SET "PYTHON=%~2" & SHIFT
6064
IF /I "%~1"=="--web" SET "WEB_APP=1"
65+
IF /I "%~1"=="--1200bps-reset" SET "BPS_RESET=1"
6166
SHIFT
6267
GOTO getopts
6368
:endopts
6469

70+
IF %BPS_RESET% EQU 1 GOTO skip-filename
71+
6572
CALL :LOG_MESSAGE DEBUG "Checking FILENAME parameter..."
6673
IF "__!FILENAME!__"=="____" (
6774
CALL :LOG_MESSAGE DEBUG "Missing -f filename input."
@@ -95,6 +102,9 @@ IF NOT "!FILENAME:update=!"=="!FILENAME!" (
95102
CALL :LOG_MESSAGE DEBUG "We are NOT working with a *update* file. !FILENAME!"
96103
)
97104

105+
:skip-filename
106+
SET "ESPTOOL_BAUD=1200"
107+
98108
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
99109
IF NOT "__%PYTHON%__"=="____" (
100110
SET "ESPTOOL_CMD=!PYTHON! -m esptool"
@@ -133,6 +143,12 @@ IF "__!ESPTOOL_PORT!__" == "____" (
133143
)
134144
CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
135145

146+
IF %BPS_RESET% EQU 1 (
147+
@REM Attempt to change mode via 1200bps Reset.
148+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! --after no_reset read_flash_status
149+
GOTO eof
150+
)
151+
136152
@REM Check if FILENAME contains "-tft-" and set target partitionScheme accordingly.
137153
@REM https://github.com/meshtastic/web-flasher/blob/main/types/resources.ts#L3
138154
IF NOT "!FILENAME:-tft-=!"=="!FILENAME!" (
@@ -254,6 +270,7 @@ EXIT /B %ERRORLEVEL%
254270
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
255271
CALL :RESET_ERROR
256272
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
273+
IF %BPS_RESET% EQU 1 GOTO :eof
257274
IF %ERRORLEVEL% NEQ 0 (
258275
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
259276
EXIT /B %ERRORLEVEL%

bin/device-install.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
PYTHON=${PYTHON:-$(which python3 python | head -n 1)}
44
WEB_APP=false
5+
BPS_RESET=false
56
TFT_BUILD=false
67
MCU=""
78

@@ -72,14 +73,15 @@ set -e
7273
# Usage info
7374
show_help() {
7475
cat <<EOF
75-
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME] [--web]
76+
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME] [--web] [--1200bps-reset]
7677
Flash image file to device, but first erasing and writing system information.
7778
7879
-h Display this help and exit.
7980
-p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerous).
8081
-P PYTHON Specify alternate python interpreter to use to invoke esptool. (Default: "$PYTHON")
8182
-f FILENAME The firmware .bin file to flash. Custom to your device type and region.
8283
--web Enable WebUI. (Default: false)
84+
--1200bps-reset Attempt to place the device in correct mode. Some hardware requires this twice. (1200bps Reset)
8385
8486
EOF
8587
}
@@ -105,6 +107,9 @@ while [ $# -gt 0 ]; do
105107
--web)
106108
WEB_APP=true
107109
;;
110+
--1200bps-reset)
111+
BPS_RESET=true
112+
;;
108113
--) # Stop parsing options
109114
shift
110115
break
@@ -117,6 +122,11 @@ while [ $# -gt 0 ]; do
117122
shift # Move to the next argument
118123
done
119124

125+
if [[ $BPS_RESET == true ]]; then
126+
$ESPTOOL_CMD --baud 1200 --after no_reset read_flash_status
127+
exit 0
128+
fi
129+
120130
[ -z "$FILENAME" -a -n "$1" ] && {
121131
FILENAME=$1
122132
shift

bin/device-update.bat

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ SET "PYTHON="
88
SET "ESPTOOL_BAUD=115200"
99
SET "ESPTOOL_CMD="
1010
SET "LOGCOUNTER=0"
11+
SET "CHANGE_MODE=0"
1112

1213
GOTO getopts
1314
:help
1415
ECHO Flash image file to device, but leave existing system intact.
1516
ECHO.
16-
ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python]
17+
ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] [--change-mode]
1718
ECHO.
1819
ECHO Options:
1920
ECHO -f filename The update .bin file to flash. Custom to your device type and region. (required)
@@ -23,12 +24,15 @@ ECHO If not set, ESPTOOL iterates all ports (Dangerous).
2324
ECHO -P python Specify alternate python interpreter to use to invoke esptool. (default: python)
2425
ECHO If supplied the script will use python.
2526
ECHO If not supplied the script will try to find esptool in Path.
27+
ECHO --change-mode Attempt to place the device in correct mode. (1200bps Reset)
28+
ECHO Some hardware requires this twice.
2629
ECHO.
30+
ECHO Example: %SCRIPT_NAME% -p COM17 --change-mode
2731
ECHO Example: %SCRIPT_NAME% -f firmware-t-deck-tft-2.6.0.0b106d4-update.bin -p COM11
2832
GOTO eof
2933

3034
:version
31-
ECHO %SCRIPT_NAME% [Version 2.6.1]
35+
ECHO %SCRIPT_NAME% [Version 2.6.2]
3236
ECHO Meshtastic
3337
GOTO eof
3438

@@ -44,10 +48,13 @@ IF /I "%~1"=="-f" SET "FILENAME=%~2" & SHIFT
4448
IF "%~1"=="-p" SET "ESPTOOL_PORT=%~2" & SHIFT
4549
IF /I "%~1"=="--port" SET "ESPTOOL_PORT=%~2" & SHIFT
4650
IF "%~1"=="-P" SET "PYTHON=%~2" & SHIFT
51+
IF /I "%~1"=="--change-mode" SET "CHANGE_MODE=1"
4752
SHIFT
4853
GOTO getopts
4954
:endopts
5055

56+
IF %CHANGE_MODE% EQU 1 GOTO skip-filename
57+
5158
CALL :LOG_MESSAGE DEBUG "Checking FILENAME parameter..."
5259
IF "__!FILENAME!__"=="____" (
5360
CALL :LOG_MESSAGE DEBUG "Missing -f filename input."
@@ -77,6 +84,9 @@ IF "!FILENAME:update=!"=="!FILENAME!" (
7784
CALL :LOG_MESSAGE DEBUG "We are working with a *update* file. !FILENAME!"
7885
)
7986

87+
:skip-filename
88+
SET "ESPTOOL_BAUD=1200"
89+
8090
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
8191
IF NOT "__%PYTHON%__"=="____" (
8292
SET "ESPTOOL_CMD=!PYTHON! -m esptool"
@@ -115,6 +125,12 @@ IF "__!ESPTOOL_PORT!__" == "____" (
115125
)
116126
CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
117127

128+
IF %CHANGE_MODE% EQU 1 (
129+
@REM Attempt to change mode via 1200bps Reset.
130+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! --after no_reset read_flash_status
131+
GOTO eof
132+
)
133+
118134
@REM Flashing operations.
119135
CALL :LOG_MESSAGE INFO "Trying to flash update "!FILENAME!" at OFFSET 0x10000..."
120136
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash 0x10000 "!FILENAME!" || GOTO eof
@@ -135,6 +151,7 @@ EXIT /B %ERRORLEVEL%
135151
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
136152
CALL :RESET_ERROR
137153
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
154+
IF %CHANGE_MODE% EQU 1 GOTO :eof
138155
IF %ERRORLEVEL% NEQ 0 (
139156
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
140157
EXIT /B %ERRORLEVEL%

bin/device-update.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22

33
PYTHON=${PYTHON:-$(which python3 python|head -n 1)}
4+
CHANGE_MODE=false
45

56
# Determine the correct esptool command to use
67
if "$PYTHON" -m esptool version >/dev/null 2>&1; then
@@ -17,14 +18,15 @@ fi
1718
# Usage info
1819
show_help() {
1920
cat << EOF
20-
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME|FILENAME]
21-
Flash image file to device, leave existing system intact."
21+
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME|FILENAME] [--change-mode]
22+
Flash image file to device, leave existing system intact.
2223
2324
-h Display this help and exit
2425
-p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerous).
2526
-P PYTHON Specify alternate python interpreter to use to invoke esptool. (Default: "$PYTHON")
2627
-f FILENAME The *update.bin file to flash. Custom to your device type.
27-
28+
--change-mode Attempt to place the device in correct mode. Some hardware requires this twice. (1200bps Reset)
29+
2830
EOF
2931
}
3032

@@ -41,6 +43,9 @@ while getopts ":hp:P:f:" opt; do
4143
;;
4244
f) FILENAME=${OPTARG}
4345
;;
46+
--change-mode)
47+
CHANGE_MODE=true
48+
;;
4449
*)
4550
echo "Invalid flag."
4651
show_help >&2
@@ -50,6 +55,11 @@ while getopts ":hp:P:f:" opt; do
5055
done
5156
shift "$((OPTIND-1))"
5257

58+
if [[ $CHANGE_MODE == true ]]; then
59+
$ESPTOOL_CMD --baud 1200 --after no_reset read_flash_status
60+
exit 0
61+
fi
62+
5363
[ -z "$FILENAME" -a -n "$1" ] && {
5464
FILENAME=$1
5565
shift

0 commit comments

Comments
 (0)