Skip to content

Commit 26b7a64

Browse files
1 parent 0d555da commit 26b7a64

276 files changed

Lines changed: 231821 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.8.a0c0388/bleota.bin

604 KB
Binary file not shown.
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
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 t-eth-elite tlora-pager mesh-tab dreamcatcher ESP32-S3-Pico seeed-sensecap-indicator heltec_capsule_sensor_v3 vision-master icarus tracksenger elecrow-adv"
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 tlora-pager t-watch-s3 elecrow-adv"
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+
104+
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
105+
IF NOT "__%PYTHON%__"=="____" (
106+
SET "ESPTOOL_CMD=!PYTHON! -m esptool"
107+
CALL :LOG_MESSAGE DEBUG "Python interpreter supplied."
108+
) ELSE (
109+
CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool...
110+
WHERE esptool >nul 2>&1
111+
IF %ERRORLEVEL% EQU 0 (
112+
@REM WHERE exits with code 0 if esptool is found.
113+
SET "ESPTOOL_CMD=esptool"
114+
) ELSE (
115+
SET "ESPTOOL_CMD=python -m esptool"
116+
CALL :RESET_ERROR
117+
)
118+
)
119+
120+
CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..."
121+
!ESPTOOL_CMD! >nul 2>&1
122+
IF %ERRORLEVEL% GEQ 2 (
123+
@REM esptool exits with code 1 if help is displayed.
124+
CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!"
125+
EXIT /B 1
126+
GOTO eof
127+
)
128+
IF %DEBUG% EQU 1 (
129+
CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps."
130+
SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!"
131+
)
132+
133+
CALL :LOG_MESSAGE DEBUG "Using esptool command: !ESPTOOL_CMD!"
134+
IF "__!ESPTOOL_PORT!__" == "____" (
135+
CALL :LOG_MESSAGE WARN "Using esptool port: UNSET."
136+
) ELSE (
137+
SET "ESPTOOL_CMD=!ESPTOOL_CMD! --port !ESPTOOL_PORT!"
138+
CALL :LOG_MESSAGE INFO "Using esptool port: !ESPTOOL_PORT!."
139+
)
140+
CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
141+
142+
IF %BPS_RESET% EQU 1 (
143+
@REM Attempt to change mode via 1200bps Reset.
144+
CALL :RUN_ESPTOOL 1200 --after no_reset read_flash_status
145+
GOTO eof
146+
)
147+
148+
@REM Check if FILENAME contains "-tft-" and set target partitionScheme accordingly.
149+
@REM https://github.com/meshtastic/web-flasher/blob/main/types/resources.ts#L3
150+
IF NOT "!FILENAME:-tft-=!"=="!FILENAME!" (
151+
CALL :LOG_MESSAGE DEBUG "We are working with a *-tft-* file. !FILENAME!"
152+
SET "TFT_BUILD=1"
153+
) ELSE (
154+
CALL :LOG_MESSAGE DEBUG "We are NOT working with a *-tft-* file. !FILENAME!"
155+
)
156+
157+
FOR %%a IN (%BIGDB_8MB%) DO (
158+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
159+
@REM We are working with any of %BIGDB_8MB%.
160+
SET "BIGDB8=1"
161+
GOTO end_loop_bigdb_8mb
162+
)
163+
)
164+
:end_loop_bigdb_8mb
165+
166+
FOR %%a IN (%BIGDB_16MB%) DO (
167+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
168+
@REM We are working with any of %BIGDB_16MB%.
169+
SET "BIGDB16=1"
170+
GOTO end_loop_bigdb_16mb
171+
)
172+
)
173+
:end_loop_bigdb_16mb
174+
175+
IF %BIGDB8% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 8mb partition selected."
176+
IF %BIGDB16% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 16mb partition selected."
177+
178+
@REM Extract BASENAME from %FILENAME% for later use.
179+
SET "BASENAME=!FILENAME:firmware-=!"
180+
CALL :LOG_MESSAGE DEBUG "Computed firmware basename: !BASENAME!"
181+
182+
@REM Account for S3 and C3 board's different OTA partition.
183+
FOR %%a IN (%S3%) DO (
184+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
185+
@REM We are working with any of %S3%.
186+
SET "OTA_FILENAME=bleota-s3.bin"
187+
GOTO :end_loop_s3
188+
)
189+
)
190+
191+
FOR %%a IN (%C3%) DO (
192+
IF NOT "!FILENAME:%%a=!"=="!FILENAME!" (
193+
@REM We are working with any of %C3%.
194+
SET "OTA_FILENAME=bleota-c3.bin"
195+
GOTO :end_loop_c3
196+
)
197+
)
198+
199+
@REM Everything else
200+
SET "OTA_FILENAME=bleota.bin"
201+
:end_loop_s3
202+
:end_loop_c3
203+
CALL :LOG_MESSAGE DEBUG "Set OTA_FILENAME to: !OTA_FILENAME!"
204+
205+
@REM Set SPIFFS filename with "littlefs-" prefix.
206+
SET "SPIFFS_FILENAME=littlefs-%BASENAME%"
207+
CALL :LOG_MESSAGE DEBUG "Set SPIFFS_FILENAME to: !SPIFFS_FILENAME!"
208+
209+
@REM Default offsets.
210+
@REM https://github.com/meshtastic/web-flasher/blob/main/stores/firmwareStore.ts#L202
211+
SET "OTA_OFFSET=0x260000"
212+
SET "SPIFFS_OFFSET=0x300000"
213+
214+
@REM Offsets for BigDB 8mb.
215+
IF %BIGDB8% EQU 1 (
216+
SET "OTA_OFFSET=0x340000"
217+
SET "SPIFFS_OFFSET=0x670000"
218+
)
219+
220+
@REM Offsets for BigDB 16mb.
221+
IF %BIGDB16% EQU 1 (
222+
SET "OTA_OFFSET=0x650000"
223+
SET "SPIFFS_OFFSET=0xc90000"
224+
)
225+
226+
CALL :LOG_MESSAGE DEBUG "Set OTA_OFFSET to: !OTA_OFFSET!"
227+
CALL :LOG_MESSAGE DEBUG "Set SPIFFS_OFFSET to: !SPIFFS_OFFSET!"
228+
229+
@REM Ensure target files exist before flashing operations.
230+
IF NOT EXIST !FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
231+
IF NOT EXIST !OTA_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!OTA_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
232+
IF NOT EXIST !SPIFFS_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!SPIFFS_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof
233+
234+
@REM Flashing operations.
235+
CALL :LOG_MESSAGE INFO "Trying to flash "!FILENAME!", but first erasing and writing system information..."
236+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! erase-flash || GOTO eof
237+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write-flash 0x00 "!FILENAME!" || GOTO eof
238+
239+
CALL :LOG_MESSAGE INFO "Trying to flash BLEOTA "!OTA_FILENAME!" at OTA_OFFSET !OTA_OFFSET!..."
240+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write-flash !OTA_OFFSET! "!OTA_FILENAME!" || GOTO eof
241+
242+
CALL :LOG_MESSAGE INFO "Trying to flash SPIFFS "!SPIFFS_FILENAME!" at SPIFFS_OFFSET !SPIFFS_OFFSET!..."
243+
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write-flash !SPIFFS_OFFSET! "!SPIFFS_FILENAME!" || GOTO eof
244+
245+
CALL :LOG_MESSAGE INFO "Script complete!."
246+
247+
:eof
248+
ENDLOCAL
249+
EXIT /B %ERRORLEVEL%
250+
251+
252+
:RUN_ESPTOOL
253+
@REM Subroutine used to run ESPTOOL_CMD with arguments.
254+
@REM Also handles %ERRORLEVEL%.
255+
@REM CALL :RUN_ESPTOOL [Baud] [erase_flash|write-flash] [OFFSET] [Filename]
256+
@REM.
257+
@REM Example:: CALL :RUN_ESPTOOL 115200 write-flash 0x10000 "firmwarefile.bin"
258+
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
259+
CALL :RESET_ERROR
260+
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
261+
IF %BPS_RESET% EQU 1 GOTO :eof
262+
IF %ERRORLEVEL% NEQ 0 (
263+
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
264+
EXIT /B %ERRORLEVEL%
265+
)
266+
GOTO :eof
267+
268+
:LOG_MESSAGE
269+
@REM Subroutine used to print log messages in four different levels.
270+
@REM DEBUG messages only get printed if [-d] flag is passed to script.
271+
@REM CALL :LOG_MESSAGE [ERROR|INFO|WARN|DEBUG] "Message"
272+
@REM.
273+
@REM Example:: CALL :LOG_MESSAGE INFO "Message."
274+
SET /A LOGCOUNTER=LOGCOUNTER+1
275+
IF "%1" == "ERROR" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
276+
IF "%1" == "INFO" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
277+
IF "%1" == "WARN" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
278+
IF "%1" == "DEBUG" IF %DEBUG% EQU 1 CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2
279+
GOTO :eof
280+
281+
:GET_TIMESTAMP
282+
@REM Subroutine used to set !TIMESTAMP! to HH:MM:ss.
283+
@REM CALL :GET_TIMESTAMP
284+
@REM.
285+
@REM Updates: !TIMESTAMP!
286+
FOR /F "tokens=1,2,3 delims=:,." %%a IN ("%TIME%") DO (
287+
SET "HH=%%a"
288+
SET "MM=%%b"
289+
SET "ss=%%c"
290+
)
291+
SET "TIMESTAMP=!HH!:!MM!:!ss!"
292+
GOTO :eof
293+
294+
:RESET_ERROR
295+
@REM Subroutine to reset %ERRORLEVEL% to 0.
296+
@REM CALL :RESET_ERROR
297+
@REM.
298+
@REM Updates: %ERRORLEVEL%
299+
EXIT /B 0
300+
GOTO :eof

0 commit comments

Comments
 (0)