Skip to content

Commit 2057486

Browse files
1 parent 5a3c51d commit 2057486

260 files changed

Lines changed: 228415 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Binary file not shown.
Binary file not shown.
498 KB
Binary file not shown.
495 KB
Binary file not shown.

firmware-2.7.2.f6d3782/bleota.bin

604 KB
Binary file not shown.
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
@ECHO OFF
2+
SETLOCAL EnableDelayedExpansion
3+
TITLE Meshtastic device-install
4+
5+
SET "SCRIPT_NAME=%~nx0"
6+
SET "DEBUG=0"
7+
SET "PYTHON="
8+
SET "TFT_BUILD=0"
9+
SET "BIGDB8=0"
10+
SET "BIGDB16=0"
11+
SET "ESPTOOL_BAUD=115200"
12+
SET "ESPTOOL_CMD="
13+
SET "LOGCOUNTER=0"
14+
SET "BPS_RESET=0"
15+
16+
@REM FIXME: Determine mcu from PlatformIO variant, this is unmaintainable.
17+
SET "S3=s3 v3 t-deck wireless-paper wireless-tracker station-g2 unphone"
18+
SET "C3=esp32c3"
19+
@REM FIXME: Determine flash size from PlatformIO variant, this is unmaintainable.
20+
SET "BIGDB_8MB=picomputer-s3 unphone seeed-sensecap-indicator crowpanel-esp32s3 heltec_capsule_sensor_v3 heltec-v3 heltec-vision-master-e213 heltec-vision-master-e290 heltec-vision-master-t190 heltec-wireless-paper heltec-wireless-tracker heltec-wsl-v3 icarus seeed-xiao-s3 tbeam-s3-core tracksenger"
21+
SET "BIGDB_16MB=t-deck mesh-tab t-energy-s3 dreamcatcher ESP32-S3-Pico m5stack-cores3 station-g2 t-eth-elite t-watch-s3"
22+
23+
GOTO getopts
24+
:help
25+
ECHO Flash image file to device, but first erasing and writing system information.
26+
ECHO.
27+
ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] [--1200bps-reset]
28+
ECHO.
29+
ECHO Options:
30+
ECHO -f filename The firmware .bin file to flash. Custom to your device type and region. (required)
31+
ECHO The file must be located in this current directory.
32+
ECHO -p PORT Set the environment variable for ESPTOOL_PORT.
33+
ECHO If not set, ESPTOOL iterates all ports (Dangerous).
34+
ECHO -P python Specify alternate python interpreter to use to invoke esptool. (default: python)
35+
ECHO If supplied the script will use python.
36+
ECHO If not supplied the script will try to find esptool in Path.
37+
ECHO --1200bps-reset Attempt to place the device in correct mode. (1200bps Reset)
38+
ECHO Some hardware requires this twice.
39+
ECHO.
40+
ECHO Example: %SCRIPT_NAME% -p COM17 --1200bps-reset
41+
ECHO Example: %SCRIPT_NAME% -f firmware-t-deck-tft-2.6.0.0b106d4.bin -p COM11
42+
ECHO Example: %SCRIPT_NAME% -f firmware-unphone-2.6.0.0b106d4.bin -p COM11
43+
GOTO eof
44+
45+
:version
46+
ECHO %SCRIPT_NAME% [Version 2.6.2]
47+
ECHO Meshtastic
48+
GOTO eof
49+
50+
:getopts
51+
IF "%~1"=="" GOTO endopts
52+
IF /I "%~1"=="-?" GOTO help
53+
IF /I "%~1"=="-h" GOTO help
54+
IF /I "%~1"=="--help" GOTO help
55+
IF /I "%~1"=="-v" GOTO version
56+
IF /I "%~1"=="--version" GOTO version
57+
IF /I "%~1"=="--debug" SET "DEBUG=1" & CALL :LOG_MESSAGE DEBUG "DEBUG mode: enabled."
58+
IF /I "%~1"=="-f" SET "FILENAME=%~2" & SHIFT
59+
IF "%~1"=="-p" SET "ESPTOOL_PORT=%~2" & SHIFT
60+
IF /I "%~1"=="--port" SET "ESPTOOL_PORT=%~2" & SHIFT
61+
IF "%~1"=="-P" SET "PYTHON=%~2" & SHIFT
62+
IF /I "%~1"=="--1200bps-reset" SET "BPS_RESET=1"
63+
SHIFT
64+
GOTO getopts
65+
:endopts
66+
67+
IF %BPS_RESET% EQU 1 GOTO skip-filename
68+
69+
CALL :LOG_MESSAGE DEBUG "Checking FILENAME parameter..."
70+
IF "__!FILENAME!__"=="____" (
71+
CALL :LOG_MESSAGE DEBUG "Missing -f filename input."
72+
GOTO help
73+
) ELSE (
74+
CALL :LOG_MESSAGE DEBUG "Filename: !FILENAME!"
75+
IF NOT "__!FILENAME: =!__"=="__!FILENAME!__" (
76+
CALL :LOG_MESSAGE ERROR "Filename containing spaces are not supported."
77+
GOTO help
78+
)
79+
IF "__!FILENAME:firmware-=!__"=="__!FILENAME!__" (
80+
CALL :LOG_MESSAGE ERROR "Filename must be a firmware-* file."
81+
GOTO help
82+
)
83+
@REM Remove ".\" or "./" file prefix if present.
84+
SET "FILENAME=!FILENAME:.\=!"
85+
SET "FILENAME=!FILENAME:./=!"
86+
)
87+
88+
CALL :LOG_MESSAGE DEBUG "Checking if !FILENAME! exists..."
89+
IF NOT EXIST !FILENAME! (
90+
CALL :LOG_MESSAGE ERROR "File does not exist: !FILENAME!. Terminating."
91+
GOTO eof
92+
)
93+
94+
IF NOT "!FILENAME:update=!"=="!FILENAME!" (
95+
CALL :LOG_MESSAGE DEBUG "We are working with a *update* file. !FILENAME!"
96+
CALL :LOG_MESSAGE INFO "Use script device-update.bat to flash update !FILENAME!."
97+
GOTO eof
98+
) ELSE (
99+
CALL :LOG_MESSAGE DEBUG "We are NOT working with a *update* file. !FILENAME!"
100+
)
101+
102+
:skip-filename
103+
SET "ESPTOOL_BAUD=1200"
104+
105+
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
106+
IF NOT "__%PYTHON%__"=="____" (
107+
SET "ESPTOOL_CMD=!PYTHON! -m esptool"
108+
CALL :LOG_MESSAGE DEBUG "Python interpreter supplied."
109+
) ELSE (
110+
CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool...
111+
WHERE esptool >nul 2>&1
112+
IF %ERRORLEVEL% EQU 0 (
113+
@REM WHERE exits with code 0 if esptool is found.
114+
SET "ESPTOOL_CMD=esptool"
115+
) ELSE (
116+
SET "ESPTOOL_CMD=python -m esptool"
117+
CALL :RESET_ERROR
118+
)
119+
)
120+
121+
CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..."
122+
!ESPTOOL_CMD! >nul 2>&1
123+
IF %ERRORLEVEL% GEQ 2 (
124+
@REM esptool exits with code 1 if help is displayed.
125+
CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!"
126+
EXIT /B 1
127+
GOTO eof
128+
)
129+
IF %DEBUG% EQU 1 (
130+
CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps."
131+
SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!"
132+
)
133+
134+
CALL :LOG_MESSAGE DEBUG "Using esptool command: !ESPTOOL_CMD!"
135+
IF "__!ESPTOOL_PORT!__" == "____" (
136+
CALL :LOG_MESSAGE WARN "Using esptool port: UNSET."
137+
) ELSE (
138+
SET "ESPTOOL_CMD=!ESPTOOL_CMD! --port !ESPTOOL_PORT!"
139+
CALL :LOG_MESSAGE INFO "Using esptool port: !ESPTOOL_PORT!."
140+
)
141+
CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
142+
143+
IF %BPS_RESET% EQU 1 (
144+
@REM Attempt to change mode via 1200bps Reset.
145+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! --after no_reset read_flash_status
146+
GOTO eof
147+
)
148+
149+
@REM Check if FILENAME contains "-tft-" and set target partitionScheme accordingly.
150+
@REM https://github.com/meshtastic/web-flasher/blob/main/types/resources.ts#L3
151+
IF NOT "!FILENAME:-tft-=!"=="!FILENAME!" (
152+
CALL :LOG_MESSAGE DEBUG "We are working with a *-tft-* file. !FILENAME!"
153+
SET "TFT_BUILD=1"
154+
) ELSE (
155+
CALL :LOG_MESSAGE DEBUG "We are NOT working with a *-tft-* file. !FILENAME!"
156+
)
157+
158+
FOR %%a IN (%BIGDB_8MB%) DO (
159+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
160+
@REM We are working with any of %BIGDB_8MB%.
161+
SET "BIGDB8=1"
162+
GOTO end_loop_bigdb_8mb
163+
)
164+
)
165+
:end_loop_bigdb_8mb
166+
167+
FOR %%a IN (%BIGDB_16MB%) DO (
168+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
169+
@REM We are working with any of %BIGDB_16MB%.
170+
SET "BIGDB16=1"
171+
GOTO end_loop_bigdb_16mb
172+
)
173+
)
174+
:end_loop_bigdb_16mb
175+
176+
IF %BIGDB8% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 8mb partition selected."
177+
IF %BIGDB16% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 16mb partition selected."
178+
179+
@REM Extract BASENAME from %FILENAME% for later use.
180+
SET "BASENAME=!FILENAME:firmware-=!"
181+
CALL :LOG_MESSAGE DEBUG "Computed firmware basename: !BASENAME!"
182+
183+
@REM Account for S3 and C3 board's different OTA partition.
184+
FOR %%a IN (%S3%) DO (
185+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
186+
@REM We are working with any of %S3%.
187+
SET "OTA_FILENAME=bleota-s3.bin"
188+
GOTO :end_loop_s3
189+
)
190+
)
191+
192+
FOR %%a IN (%C3%) DO (
193+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
194+
@REM We are working with any of %C3%.
195+
SET "OTA_FILENAME=bleota-c3.bin"
196+
GOTO :end_loop_c3
197+
)
198+
)
199+
200+
@REM Everything else
201+
SET "OTA_FILENAME=bleota.bin"
202+
:end_loop_s3
203+
:end_loop_c3
204+
CALL :LOG_MESSAGE DEBUG "Set OTA_FILENAME to: !OTA_FILENAME!"
205+
206+
@REM Set SPIFFS filename with "littlefs-" prefix.
207+
SET "SPIFFS_FILENAME=littlefs-%BASENAME%"
208+
CALL :LOG_MESSAGE DEBUG "Set SPIFFS_FILENAME to: !SPIFFS_FILENAME!"
209+
210+
@REM Default offsets.
211+
@REM https://github.com/meshtastic/web-flasher/blob/main/stores/firmwareStore.ts#L202
212+
SET "OTA_OFFSET=0x260000"
213+
SET "SPIFFS_OFFSET=0x300000"
214+
215+
@REM Offsets for BigDB 8mb.
216+
IF %BIGDB8% EQU 1 (
217+
SET "OTA_OFFSET=0x340000"
218+
SET "SPIFFS_OFFSET=0x670000"
219+
)
220+
221+
@REM Offsets for BigDB 16mb.
222+
IF %BIGDB16% EQU 1 (
223+
SET "OTA_OFFSET=0x650000"
224+
SET "SPIFFS_OFFSET=0xc90000"
225+
)
226+
227+
CALL :LOG_MESSAGE DEBUG "Set OTA_OFFSET to: !OTA_OFFSET!"
228+
CALL :LOG_MESSAGE DEBUG "Set SPIFFS_OFFSET to: !SPIFFS_OFFSET!"
229+
230+
@REM Ensure target files exist before flashing operations.
231+
IF NOT EXIST !FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
232+
IF NOT EXIST !OTA_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!OTA_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
233+
IF NOT EXIST !SPIFFS_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!SPIFFS_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
234+
235+
@REM Flashing operations.
236+
CALL :LOG_MESSAGE INFO "Trying to flash "!FILENAME!", but first erasing and writing system information..."
237+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! erase_flash || GOTO eof
238+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash 0x00 "!FILENAME!" || GOTO eof
239+
240+
CALL :LOG_MESSAGE INFO "Trying to flash BLEOTA "!OTA_FILENAME!" at OTA_OFFSET !OTA_OFFSET!..."
241+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !OTA_OFFSET! "!OTA_FILENAME!" || GOTO eof
242+
243+
CALL :LOG_MESSAGE INFO "Trying to flash SPIFFS "!SPIFFS_FILENAME!" at SPIFFS_OFFSET !SPIFFS_OFFSET!..."
244+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !SPIFFS_OFFSET! "!SPIFFS_FILENAME!" || GOTO eof
245+
246+
CALL :LOG_MESSAGE INFO "Script complete!."
247+
248+
:eof
249+
ENDLOCAL
250+
EXIT /B %ERRORLEVEL%
251+
252+
253+
:RUN_ESPTOOL
254+
@REM Subroutine used to run ESPTOOL_CMD with arguments.
255+
@REM Also handles %ERRORLEVEL%.
256+
@REM CALL :RUN_ESPTOOL [Baud] [erase_flash|write_flash] [OFFSET] [Filename]
257+
@REM.
258+
@REM Example:: CALL :RUN_ESPTOOL 115200 write_flash 0x10000 "firmwarefile.bin"
259+
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
260+
CALL :RESET_ERROR
261+
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
262+
IF %BPS_RESET% EQU 1 GOTO :eof
263+
IF %ERRORLEVEL% NEQ 0 (
264+
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
265+
EXIT /B %ERRORLEVEL%
266+
)
267+
GOTO :eof
268+
269+
:LOG_MESSAGE
270+
@REM Subroutine used to print log messages in four different levels.
271+
@REM DEBUG messages only get printed if [-d] flag is passed to script.
272+
@REM CALL :LOG_MESSAGE [ERROR|INFO|WARN|DEBUG] "Message"
273+
@REM.
274+
@REM Example:: CALL :LOG_MESSAGE INFO "Message."
275+
SET /A LOGCOUNTER=LOGCOUNTER+1
276+
IF "%1" == "ERROR" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
277+
IF "%1" == "INFO" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
278+
IF "%1" == "WARN" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
279+
IF "%1" == "DEBUG" IF %DEBUG% EQU 1 CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
280+
GOTO :eof
281+
282+
:GET_TIMESTAMP
283+
@REM Subroutine used to set !TIMESTAMP! to HH:MM:ss.
284+
@REM CALL :GET_TIMESTAMP
285+
@REM.
286+
@REM Updates: !TIMESTAMP!
287+
FOR /F "tokens=1,2,3 delims=:,." %%a IN ("%TIME%") DO (
288+
SET "HH=%%a"
289+
SET "MM=%%b"
290+
SET "ss=%%c"
291+
)
292+
SET "TIMESTAMP=!HH!:!MM!:!ss!"
293+
GOTO :eof
294+
295+
:RESET_ERROR
296+
@REM Subroutine to reset %ERRORLEVEL% to 0.
297+
@REM CALL :RESET_ERROR
298+
@REM.
299+
@REM Updates: %ERRORLEVEL%
300+
EXIT /B 0
301+
GOTO :eof

0 commit comments

Comments
 (0)