mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-04 03:18:10 +10:00
fix(bin): repair the Windows device-install and device-update scripts (#11388)
* fix(bin): correct filename check and esptool v5 subcommands in .bat installers device-install.bat rejected every valid firmware-*.factory.bin name. The substring-strip comparison was negated, so it errored when the suffix was present instead of when it was absent. Both scripts hardcoded esptool subcommand spellings. device-install.bat used the v4 underscore forms only. device-update.bat used the v5 write-flash with the v4 read_flash_status, so it worked fully on neither version. Probe the help output once and select the spelling, mirroring bin/device-install.sh. The probe uses %ESPTOOL_CMD% rather than !ESPTOOL_CMD! because cmd does not split a delayed-expanded command token carrying a path into program and arguments. Fixes #8156 * fix(bin): make the -P interpreter option work in the .bat installers Both scripts invoked ESPTOOL_CMD through delayed expansion. cmd does not split a delayed-expanded command token that carries a path into program and arguments, so "-P C:\path\python.exe" exited 9009 and the scripts reported "esptool not found". Use %ESPTOOL_CMD% at the two command positions per file. device-update.bat additionally wrapped the interpreter in doubled quotes, which made python treat python.exe as a source file. Quote the path once, as device-install.bat does, so interpreter paths containing spaces also work. * fix(bin): anchor the .factory.bin suffix check and harden esptool detection The filename check matched .factory.bin anywhere in the name, so firmware-x.factory.bin.bak passed and the script then derived firmware-x.bak.mt.json for metadata. Compare the last 12 characters instead, matching the anchored glob in bin/device-install.sh. A quoted interpreter path that does not exist returns 3 rather than 9009, so the missing-esptool check skipped it and the script died at the probe with no message. Treat 3 as missing as well. device-update.bat read %ERRORLEVEL% after a CALL that overwrote it, so the missing-esptool check never fired. Capture the exit code before logging it.
This commit is contained in:
+30
-11
@@ -70,7 +70,7 @@ IF "__!FILENAME!__"=="____" (
|
||||
CALL :LOG_MESSAGE ERROR "Filename containing spaces are not supported."
|
||||
GOTO help
|
||||
)
|
||||
IF NOT "__!FILENAME:.factory.bin=!__"=="__!FILENAME!__" (
|
||||
IF /I NOT "!FILENAME:~-12!"==".factory.bin" (
|
||||
CALL :LOG_MESSAGE ERROR "Filename must be a firmware-*.factory.bin file."
|
||||
GOTO help
|
||||
)
|
||||
@@ -111,7 +111,7 @@ IF EXIST !METAFILE! (
|
||||
|
||||
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
|
||||
IF NOT "__%PYTHON%__"=="____" (
|
||||
SET "ESPTOOL_CMD=!PYTHON! -m esptool"
|
||||
SET "ESPTOOL_CMD="!PYTHON!" -m esptool"
|
||||
CALL :LOG_MESSAGE DEBUG "Python interpreter supplied."
|
||||
) ELSE (
|
||||
CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool..."
|
||||
@@ -126,12 +126,31 @@ IF NOT "__%PYTHON%__"=="____" (
|
||||
)
|
||||
|
||||
CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..."
|
||||
!ESPTOOL_CMD! >nul 2>&1
|
||||
IF %ERRORLEVEL% EQU 9009 (
|
||||
@REM 9009 = command not found on Windows
|
||||
@REM %VAR% not !VAR!: cmd will not split a delayed-expanded command token that
|
||||
@REM carries a path, so the "python -m esptool" form never starts.
|
||||
%ESPTOOL_CMD% >nul 2>&1
|
||||
SET "ESPTOOL_EXIT=!ERRORLEVEL!"
|
||||
@REM 9009 = command not found, 3 = bad path from -P. Both mean unusable.
|
||||
IF !ESPTOOL_EXIT! EQU 3 SET "ESPTOOL_EXIT=9009"
|
||||
IF !ESPTOOL_EXIT! EQU 9009 (
|
||||
CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!"
|
||||
EXIT /B 1
|
||||
)
|
||||
|
||||
@REM esptool v5 renamed subcommands to dashes; older versions only take underscores.
|
||||
@REM Probe here: the --debug and --port rewrites below leave ESPTOOL_CMD unusable.
|
||||
SET "ESPTOOL_WRITE_FLASH=write_flash"
|
||||
SET "ESPTOOL_ERASE_FLASH=erase_flash"
|
||||
SET "ESPTOOL_READ_FLASH_STATUS=read_flash_status"
|
||||
%ESPTOOL_CMD% 2>&1 | findstr /C:"write-flash" >nul
|
||||
IF !ERRORLEVEL! EQU 0 (
|
||||
SET "ESPTOOL_WRITE_FLASH=write-flash"
|
||||
SET "ESPTOOL_ERASE_FLASH=erase-flash"
|
||||
SET "ESPTOOL_READ_FLASH_STATUS=read-flash-status"
|
||||
)
|
||||
CALL :RESET_ERROR
|
||||
CALL :LOG_MESSAGE DEBUG "Using esptool write command: !ESPTOOL_WRITE_FLASH!"
|
||||
|
||||
IF %DEBUG% EQU 1 (
|
||||
CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps."
|
||||
SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!"
|
||||
@@ -148,7 +167,7 @@ CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
|
||||
|
||||
IF %BPS_RESET% EQU 1 (
|
||||
@REM Attempt to change mode via 1200bps Reset.
|
||||
CALL :RUN_ESPTOOL 1200 --after no_reset read_flash_status
|
||||
CALL :RUN_ESPTOOL 1200 --after no_reset !ESPTOOL_READ_FLASH_STATUS!
|
||||
GOTO eof
|
||||
)
|
||||
|
||||
@@ -174,14 +193,14 @@ IF NOT EXIST !SPIFFS_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!S
|
||||
|
||||
@REM Flashing operations.
|
||||
CALL :LOG_MESSAGE INFO "Trying to flash "!FILENAME!", but first erasing and writing system information..."
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! erase_flash || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash 0x00 "!FILENAME!" || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! !ESPTOOL_ERASE_FLASH! || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! !ESPTOOL_WRITE_FLASH! 0x00 "!FILENAME!" || GOTO eof
|
||||
|
||||
CALL :LOG_MESSAGE INFO "Trying to flash BLEOTA "!OTA_FILENAME!" at OTA_OFFSET !OTA_OFFSET!..."
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !OTA_OFFSET! "!OTA_FILENAME!" || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! !ESPTOOL_WRITE_FLASH! !OTA_OFFSET! "!OTA_FILENAME!" || GOTO eof
|
||||
|
||||
CALL :LOG_MESSAGE INFO "Trying to flash SPIFFS "!SPIFFS_FILENAME!" at SPIFFS_OFFSET !SPIFFS_OFFSET!..."
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !SPIFFS_OFFSET! "!SPIFFS_FILENAME!" || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! !ESPTOOL_WRITE_FLASH! !SPIFFS_OFFSET! "!SPIFFS_FILENAME!" || GOTO eof
|
||||
|
||||
CALL :LOG_MESSAGE INFO "Script complete!."
|
||||
|
||||
@@ -198,7 +217,7 @@ EXIT /B %ERRORLEVEL%
|
||||
@REM Example:: CALL :RUN_ESPTOOL 115200 write_flash 0x10000 "firmwarefile.bin"
|
||||
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
|
||||
CALL :RESET_ERROR
|
||||
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
|
||||
%ESPTOOL_CMD% --baud %~1 %~2 %~3 %~4
|
||||
IF %BPS_RESET% EQU 1 GOTO :eof
|
||||
IF %ERRORLEVEL% NEQ 0 (
|
||||
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
|
||||
|
||||
+27
-8
@@ -90,7 +90,7 @@ IF NOT "__!FILENAME:.factory.bin=!__"=="__!FILENAME!__" (
|
||||
|
||||
CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..."
|
||||
IF NOT "__%PYTHON%__"=="____" (
|
||||
SET "ESPTOOL_CMD=""!PYTHON!"" -m esptool"
|
||||
SET "ESPTOOL_CMD="!PYTHON!" -m esptool"
|
||||
CALL :LOG_MESSAGE DEBUG "Python interpreter supplied."
|
||||
) ELSE (
|
||||
CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool..."
|
||||
@@ -105,13 +105,32 @@ IF NOT "__%PYTHON%__"=="____" (
|
||||
)
|
||||
|
||||
CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..."
|
||||
!ESPTOOL_CMD! >nul 2>&1
|
||||
CALL :LOG_MESSAGE DEBUG "esptool exit code: %ERRORLEVEL%"
|
||||
IF %ERRORLEVEL% EQU 9009 (
|
||||
@REM 9009 = command not found on Windows
|
||||
@REM %VAR% not !VAR!: cmd will not split a delayed-expanded command token that
|
||||
@REM carries a path, so the "python -m esptool" form never starts.
|
||||
%ESPTOOL_CMD% >nul 2>&1
|
||||
SET "ESPTOOL_EXIT=!ERRORLEVEL!"
|
||||
CALL :LOG_MESSAGE DEBUG "esptool exit code: !ESPTOOL_EXIT!"
|
||||
@REM 9009 = command not found, 3 = bad path from -P. Both mean unusable.
|
||||
IF !ESPTOOL_EXIT! EQU 3 SET "ESPTOOL_EXIT=9009"
|
||||
IF !ESPTOOL_EXIT! EQU 9009 (
|
||||
CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!"
|
||||
EXIT /B 1
|
||||
)
|
||||
|
||||
@REM esptool v5 renamed subcommands to dashes; older versions only take underscores.
|
||||
@REM Probe here: the --debug and --port rewrites below leave ESPTOOL_CMD unusable.
|
||||
SET "ESPTOOL_WRITE_FLASH=write_flash"
|
||||
SET "ESPTOOL_ERASE_FLASH=erase_flash"
|
||||
SET "ESPTOOL_READ_FLASH_STATUS=read_flash_status"
|
||||
%ESPTOOL_CMD% 2>&1 | findstr /C:"write-flash" >nul
|
||||
IF !ERRORLEVEL! EQU 0 (
|
||||
SET "ESPTOOL_WRITE_FLASH=write-flash"
|
||||
SET "ESPTOOL_ERASE_FLASH=erase-flash"
|
||||
SET "ESPTOOL_READ_FLASH_STATUS=read-flash-status"
|
||||
)
|
||||
CALL :RESET_ERROR
|
||||
CALL :LOG_MESSAGE DEBUG "Using esptool write command: !ESPTOOL_WRITE_FLASH!"
|
||||
|
||||
IF %DEBUG% EQU 1 (
|
||||
CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps."
|
||||
SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!"
|
||||
@@ -128,13 +147,13 @@ CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!."
|
||||
|
||||
IF %CHANGE_MODE% EQU 1 (
|
||||
@REM Attempt to change mode via 1200bps Reset.
|
||||
CALL :RUN_ESPTOOL !RESET_BAUD! --after no_reset read_flash_status
|
||||
CALL :RUN_ESPTOOL !RESET_BAUD! --after no_reset !ESPTOOL_READ_FLASH_STATUS!
|
||||
GOTO eof
|
||||
)
|
||||
|
||||
@REM Flashing operations.
|
||||
CALL :LOG_MESSAGE INFO "Trying to flash update "!FILENAME!" at OFFSET !UPDATE_OFFSET!..."
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write-flash !UPDATE_OFFSET! "!FILENAME!" || GOTO eof
|
||||
CALL :RUN_ESPTOOL !ESPTOOL_BAUD! !ESPTOOL_WRITE_FLASH! !UPDATE_OFFSET! "!FILENAME!" || GOTO eof
|
||||
|
||||
CALL :LOG_MESSAGE INFO "Script complete!."
|
||||
|
||||
@@ -151,7 +170,7 @@ EXIT /B %ERRORLEVEL%
|
||||
@REM Example:: CALL :RUN_ESPTOOL 115200 write-flash 0x10000 "firmwarefile.bin"
|
||||
IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
|
||||
CALL :RESET_ERROR
|
||||
!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4
|
||||
%ESPTOOL_CMD% --baud %~1 %~2 %~3 %~4
|
||||
IF %CHANGE_MODE% EQU 1 GOTO :eof
|
||||
IF %ERRORLEVEL% NEQ 0 (
|
||||
CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4"
|
||||
|
||||
Reference in New Issue
Block a user