Добавить выпуск прошивок из Keil и CCS
This commit is contained in:
221
tools/firmware-publish/PUBLISH_FIRMWARE.bat
Normal file
221
tools/firmware-publish/PUBLISH_FIRMWARE.bat
Normal file
@@ -0,0 +1,221 @@
|
||||
@echo off
|
||||
setlocal EnableExtensions DisableDelayedExpansion
|
||||
|
||||
set "FW_TOOL_DIR=%~dp0"
|
||||
set "FW_MODE=--preflight"
|
||||
set "FW_CONFIG="
|
||||
set "FW_ASSUME_YES=0"
|
||||
set "FW_ALLOW_DIRTY=0"
|
||||
|
||||
:parse_arguments
|
||||
if "%~1"=="" goto arguments_done
|
||||
if /i "%~1"=="--preflight" (
|
||||
set "FW_MODE=--preflight"
|
||||
shift
|
||||
goto parse_arguments
|
||||
)
|
||||
if /i "%~1"=="--publish" (
|
||||
set "FW_MODE=--publish"
|
||||
shift
|
||||
goto parse_arguments
|
||||
)
|
||||
if /i "%~1"=="--yes" (
|
||||
set "FW_ASSUME_YES=1"
|
||||
shift
|
||||
goto parse_arguments
|
||||
)
|
||||
if /i "%~1"=="--allow-dirty" (
|
||||
set "FW_ALLOW_DIRTY=1"
|
||||
shift
|
||||
goto parse_arguments
|
||||
)
|
||||
if /i "%~1"=="--config" (
|
||||
if "%~2"=="" goto missing_config_value
|
||||
set "FW_CONFIG=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_arguments
|
||||
)
|
||||
if /i "%~1"=="--help" goto usage
|
||||
if /i "%~1"=="-h" goto usage
|
||||
echo ERROR: unknown argument: %~1
|
||||
goto usage_error
|
||||
|
||||
:missing_config_value
|
||||
echo ERROR: --config requires a path.
|
||||
goto usage_error
|
||||
|
||||
:arguments_done
|
||||
if not defined FW_CONFIG (
|
||||
if exist "%CD%\firmware-release.cmd" (
|
||||
set "FW_CONFIG=%CD%\firmware-release.cmd"
|
||||
) else (
|
||||
set "FW_CONFIG=%FW_TOOL_DIR%firmware-release.cmd"
|
||||
)
|
||||
)
|
||||
for %%I in ("%FW_CONFIG%") do set "FW_CONFIG=%%~fI"
|
||||
if not exist "%FW_CONFIG%" (
|
||||
echo ERROR: publication config not found:
|
||||
echo %FW_CONFIG%
|
||||
echo Copy one of the examples to the firmware project root as
|
||||
echo firmware-release.cmd, then edit its values.
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
for %%I in ("%FW_CONFIG%") do set "FW_CONFIG_DIR=%%~dpI"
|
||||
call "%FW_CONFIG%"
|
||||
if errorlevel 1 (
|
||||
echo ERROR: publication config returned an error.
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
if not defined FW_PRODUCT goto missing_FW_PRODUCT
|
||||
if not defined FW_VERSION goto missing_FW_VERSION
|
||||
if not defined FW_VERSION_CODE goto missing_FW_VERSION_CODE
|
||||
if not defined FW_TRANSPORTS goto missing_FW_TRANSPORTS
|
||||
if not defined FW_IMAGE goto missing_FW_IMAGE
|
||||
if not defined FW_PROJECT_ROOT set "FW_PROJECT_ROOT=%FW_CONFIG_DIR%"
|
||||
|
||||
pushd "%FW_CONFIG_DIR%" >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: cannot enter config directory: %FW_CONFIG_DIR%
|
||||
exit /b 2
|
||||
)
|
||||
for %%I in ("%FW_PROJECT_ROOT%") do set "FW_PROJECT_ROOT_ABS=%%~fI"
|
||||
for %%I in ("%FW_IMAGE%") do set "FW_IMAGE_ABS=%%~fI"
|
||||
if defined FW_SETGUI_ROOT for %%I in ("%FW_SETGUI_ROOT%") do set "FW_SETGUI_ROOT_ABS=%%~fI"
|
||||
popd
|
||||
|
||||
if not defined FW_SETGUI_ROOT_ABS call :find_setgui
|
||||
if not defined FW_SETGUI_ROOT_ABS (
|
||||
echo ERROR: SETGUI was not found.
|
||||
echo Set FW_SETGUI_ROOT in %FW_CONFIG%
|
||||
exit /b 2
|
||||
)
|
||||
set "FW_SETGUI_PUBLISHER=%FW_SETGUI_ROOT_ABS%\PUBLISH_FIRMWARE.bat"
|
||||
if not exist "%FW_SETGUI_PUBLISHER%" (
|
||||
echo ERROR: SETGUI publisher not found:
|
||||
echo %FW_SETGUI_PUBLISHER%
|
||||
exit /b 2
|
||||
)
|
||||
if not exist "%FW_IMAGE_ABS%" (
|
||||
echo ERROR: firmware image not found:
|
||||
echo %FW_IMAGE_ABS%
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
for %%I in ("%FW_IMAGE_ABS%") do set "FW_IMAGE_EXT=%%~xI"
|
||||
if /i not "%FW_IMAGE_EXT%"==".hex" if /i not "%FW_IMAGE_EXT%"==".bin" (
|
||||
echo ERROR: FW_IMAGE must point to a .hex or .bin file, not %FW_IMAGE_EXT%.
|
||||
echo Keil must create a HEX file; CCS must run C2000 Hex Utility.
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Firmware publication
|
||||
echo Mode: %FW_MODE%
|
||||
echo Project: %FW_PROJECT_ROOT_ABS%
|
||||
echo Image: %FW_IMAGE_ABS%
|
||||
echo Product: %FW_PRODUCT%
|
||||
echo Version: %FW_VERSION% ^(%FW_VERSION_CODE%^)
|
||||
echo Transports: %FW_TRANSPORTS%
|
||||
if defined FW_BASE_ADDRESS echo Base address: %FW_BASE_ADDRESS%
|
||||
echo.
|
||||
|
||||
if /i "%FW_MODE%"=="--publish" call :guard_worktree
|
||||
if errorlevel 1 exit /b %errorlevel%
|
||||
|
||||
if /i "%FW_MODE%"=="--publish" if "%FW_ASSUME_YES%"=="0" (
|
||||
echo This will upload the image and change the public firmware catalog.
|
||||
choice /C YN /N /M "Continue [Y/N]? "
|
||||
if errorlevel 2 (
|
||||
echo Publication cancelled.
|
||||
exit /b 2
|
||||
)
|
||||
)
|
||||
|
||||
for %%T in (%FW_TRANSPORTS:,= %) do (
|
||||
call :publish_transport "%%~T"
|
||||
if errorlevel 1 goto publication_failed
|
||||
)
|
||||
|
||||
if /i "%FW_MODE%"=="--publish" (
|
||||
echo.
|
||||
echo Publication completed and verified for all transports.
|
||||
) else (
|
||||
echo.
|
||||
echo Preflight passed. Run with --publish only when this build is a release.
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:publication_failed
|
||||
echo.
|
||||
echo ERROR: publication step failed; remaining transports were not processed.
|
||||
exit /b 1
|
||||
|
||||
:publish_transport
|
||||
set "FW_TRANSPORT=%~1"
|
||||
if "%FW_TRANSPORT%"=="" exit /b 0
|
||||
echo ----- %FW_TRANSPORT% -----
|
||||
if defined FW_BASE_ADDRESS (
|
||||
call "%FW_SETGUI_PUBLISHER%" %FW_MODE% --file "%FW_IMAGE_ABS%" --product "%FW_PRODUCT%" --version "%FW_VERSION%" --version-code "%FW_VERSION_CODE%" --transport "%FW_TRANSPORT%" --base-address "%FW_BASE_ADDRESS%" --notes "%FW_NOTES%"
|
||||
) else (
|
||||
call "%FW_SETGUI_PUBLISHER%" %FW_MODE% --file "%FW_IMAGE_ABS%" --product "%FW_PRODUCT%" --version "%FW_VERSION%" --version-code "%FW_VERSION_CODE%" --transport "%FW_TRANSPORT%" --notes "%FW_NOTES%"
|
||||
)
|
||||
exit /b %errorlevel%
|
||||
|
||||
:guard_worktree
|
||||
where git >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo WARNING: Git is unavailable; source cleanliness was not checked.
|
||||
exit /b 0
|
||||
)
|
||||
git -C "%FW_PROJECT_ROOT_ABS%" rev-parse --is-inside-work-tree >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo WARNING: project is not a Git worktree; source cleanliness was not checked.
|
||||
exit /b 0
|
||||
)
|
||||
git -C "%FW_PROJECT_ROOT_ABS%" diff --quiet HEAD -- >nul 2>nul
|
||||
if not errorlevel 1 exit /b 0
|
||||
if "%FW_ALLOW_DIRTY%"=="1" (
|
||||
echo WARNING: publishing from a worktree with tracked changes.
|
||||
exit /b 0
|
||||
)
|
||||
echo ERROR: tracked project files differ from HEAD.
|
||||
echo Commit the release sources or repeat with --allow-dirty deliberately.
|
||||
exit /b 3
|
||||
|
||||
:find_setgui
|
||||
for %%I in ("%FW_CONFIG_DIR%..\SETGUI" "%FW_CONFIG_DIR%..\..\SETGUI" "%FW_CONFIG_DIR%..\..\..\SETGUI") do (
|
||||
if exist "%%~fI\PUBLISH_FIRMWARE.bat" if not defined FW_SETGUI_ROOT_ABS set "FW_SETGUI_ROOT_ABS=%%~fI"
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:missing_FW_PRODUCT
|
||||
echo ERROR: FW_PRODUCT is not set in %FW_CONFIG%
|
||||
exit /b 2
|
||||
:missing_FW_VERSION
|
||||
echo ERROR: FW_VERSION is not set in %FW_CONFIG%
|
||||
exit /b 2
|
||||
:missing_FW_VERSION_CODE
|
||||
echo ERROR: FW_VERSION_CODE is not set in %FW_CONFIG%
|
||||
exit /b 2
|
||||
:missing_FW_TRANSPORTS
|
||||
echo ERROR: FW_TRANSPORTS is not set in %FW_CONFIG%
|
||||
exit /b 2
|
||||
:missing_FW_IMAGE
|
||||
echo ERROR: FW_IMAGE is not set in %FW_CONFIG%
|
||||
exit /b 2
|
||||
|
||||
:usage
|
||||
echo Usage:
|
||||
echo PUBLISH_FIRMWARE.bat [--config PATH] --preflight
|
||||
echo PUBLISH_FIRMWARE.bat [--config PATH] --publish [--yes] [--allow-dirty]
|
||||
echo.
|
||||
echo Default mode is --preflight. Default config is firmware-release.cmd
|
||||
echo in the current directory or next to this script.
|
||||
exit /b 0
|
||||
|
||||
:usage_error
|
||||
call :usage
|
||||
exit /b 2
|
||||
Reference in New Issue
Block a user