|
| 1 | +@echo off |
| 2 | +setlocal EnableDelayedExpansion |
| 3 | + |
| 4 | +:: ======================================================== |
| 5 | +:: OpenBeken BK7231T Windows build script |
| 6 | +:: Uses Git Bash + bundled ARM GCC toolchain + Windows |
| 7 | +:: packaging tools that are all already in the SDK. |
| 8 | +:: ======================================================== |
| 9 | + |
| 10 | +set APP_NAME=OpenBK7231T_App |
| 11 | +set APP_VERSION=dev_bk7231t |
| 12 | +set SDK_DIR=sdk\OpenBK7231T |
| 13 | +set OBK_VARIANT=2 |
| 14 | + |
| 15 | +:: Allow overriding version from command line |
| 16 | +if not "%~1"=="" set APP_VERSION=%~1 |
| 17 | + |
| 18 | +echo ============================================== |
| 19 | +echo Building OpenBeken for BK7231T on Windows |
| 20 | +echo App Name: %APP_NAME% |
| 21 | +echo App Version: %APP_VERSION% |
| 22 | +echo Variant: %OBK_VARIANT% |
| 23 | +echo SDK Dir: %SDK_DIR% |
| 24 | +echo ============================================== |
| 25 | + |
| 26 | +:: --- Check prerequisites --- |
| 27 | + |
| 28 | +:: 1. Git Bash |
| 29 | +set GIT_BASH= |
| 30 | +for %%P in ( |
| 31 | + "C:\Program Files\Git\bin\bash.exe" |
| 32 | + "C:\Program Files (x86)\Git\bin\bash.exe" |
| 33 | +) do ( |
| 34 | + if exist %%P ( |
| 35 | + set "GIT_BASH=%%~P" |
| 36 | + goto :found_bash |
| 37 | + ) |
| 38 | +) |
| 39 | +echo [ERROR] Git Bash not found! Please install Git for Windows. |
| 40 | +exit /b 1 |
| 41 | + |
| 42 | +:found_bash |
| 43 | +echo [INFO] Using Git Bash: %GIT_BASH% |
| 44 | + |
| 45 | +:: 2. Check that SDK submodule is checked out |
| 46 | +if not exist "%SDK_DIR%\platforms\bk7231t\bk7231t_os\build.sh" ( |
| 47 | + echo [INFO] SDK submodule not found, checking out... |
| 48 | + git submodule update --init --recursive --depth=1 %SDK_DIR% |
| 49 | + if !errorlevel! neq 0 ( |
| 50 | + echo [ERROR] Failed to checkout SDK submodule! |
| 51 | + exit /b 1 |
| 52 | + ) |
| 53 | +) |
| 54 | +echo [INFO] SDK submodule OK. |
| 55 | + |
| 56 | +:: 3. Check that Windows ARM GCC toolchain exists |
| 57 | +if not exist "%SDK_DIR%\platforms\bk7231t\toolchain\windows\gcc-arm-none-eabi-4_9-2015q1\bin\arm-none-eabi-gcc.exe" ( |
| 58 | + echo [ERROR] Windows ARM GCC toolchain not found in SDK! |
| 59 | + echo Expected at: %SDK_DIR%\platforms\bk7231t\toolchain\windows\gcc-arm-none-eabi-4_9-2015q1\bin\ |
| 60 | + exit /b 1 |
| 61 | +) |
| 62 | +echo [INFO] ARM GCC toolchain OK. |
| 63 | + |
| 64 | +:: 4. Ensure our app symlink/junction exists in SDK apps folder |
| 65 | +if not exist "%SDK_DIR%\apps\%APP_NAME%" ( |
| 66 | + echo [INFO] Creating junction for app in SDK apps folder... |
| 67 | + mklink /J "%SDK_DIR%\apps\%APP_NAME%" "%CD%" |
| 68 | + if !errorlevel! neq 0 ( |
| 69 | + echo [ERROR] Failed to create junction. Try running as Administrator. |
| 70 | + exit /b 1 |
| 71 | + ) |
| 72 | +) |
| 73 | +echo [INFO] App link OK. |
| 74 | + |
| 75 | +:: 5. Ensure mbedtls is downloaded (needed by the top-level Makefile) |
| 76 | +if not exist "output\mbedtls-2.28.5" ( |
| 77 | + echo [INFO] Downloading mbedtls... |
| 78 | + "%GIT_BASH%" -c "mkdir -p output && cd output && curl -sL https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.5.tar.gz -o v2.28.5.tar.gz && tar -xf v2.28.5.tar.gz && rm -f v2.28.5.tar.gz && mv mbedtls-2.28.5/library/base64.c mbedtls-2.28.5/library/base64_mbedtls.c" |
| 79 | + if !errorlevel! neq 0 ( |
| 80 | + echo [WARN] mbedtls download may have failed, build might still work. |
| 81 | + ) |
| 82 | +) |
| 83 | + |
| 84 | +:: 6. Ensure output directory exists |
| 85 | +if not exist "output\%APP_VERSION%" mkdir "output\%APP_VERSION%" |
| 86 | + |
| 87 | +:: --- Build via Git Bash --- |
| 88 | +:: The build.sh and application.mk already handle Windows vs Linux toolchain paths. |
| 89 | +:: The trick is: application.mk uses `uname` to decide toolchain dir, and build.sh |
| 90 | +:: uses `uname` to pick the Windows package tools. |
| 91 | +:: Under Git Bash, uname returns MINGW64_NT-... which is NOT "Linux", so it picks |
| 92 | +:: the Windows paths. We just need to provide `make` to Git Bash. |
| 93 | + |
| 94 | +echo [INFO] Starting build via Git Bash... |
| 95 | +echo. |
| 96 | + |
| 97 | +:: Run the inner build script, passing parameters as arguments. |
| 98 | +:: This avoids the fragile inline echo approach that loses $variables. |
| 99 | +"%GIT_BASH%" --login -i "%CD%\build_bk7231t_inner.sh" "%APP_NAME%" "%APP_VERSION%" "%SDK_DIR%" "%OBK_VARIANT%" |
| 100 | +set BUILD_RESULT=%errorlevel% |
| 101 | + |
| 102 | +if %BUILD_RESULT% neq 0 ( |
| 103 | + echo. |
| 104 | + echo [ERROR] BK7231T build failed with exit code %BUILD_RESULT%! |
| 105 | + echo. |
| 106 | + echo [INFO] Checking for partial build artifacts... |
| 107 | + echo [INFO] Looking in: %SDK_DIR%\platforms\bk7231t\bk7231t_os\tools\generate\ |
| 108 | + if exist "%SDK_DIR%\platforms\bk7231t\bk7231t_os\tools\generate" ( |
| 109 | + dir /b "%SDK_DIR%\platforms\bk7231t\bk7231t_os\tools\generate\*.bin" 2>nul |
| 110 | + dir /b "%SDK_DIR%\platforms\bk7231t\bk7231t_os\tools\generate\*.rbl" 2>nul |
| 111 | + ) |
| 112 | + echo. |
| 113 | + echo [INFO] Checking output dir: output\%APP_VERSION%\ |
| 114 | + if exist "output\%APP_VERSION%" ( |
| 115 | + dir /b "output\%APP_VERSION%\*.bin" 2>nul |
| 116 | + dir /b "output\%APP_VERSION%\*.rbl" 2>nul |
| 117 | + dir /b "output\%APP_VERSION%\*.axf" 2>nul |
| 118 | + ) else ( |
| 119 | + echo [INFO] Output dir does not exist yet. |
| 120 | + ) |
| 121 | + exit /b %BUILD_RESULT% |
| 122 | +) |
| 123 | + |
| 124 | +:: --- Copy output --- |
| 125 | +echo. |
| 126 | +echo [INFO] Checking output files... |
| 127 | +set GEN_DIR=%SDK_DIR%\platforms\bk7231t\bk7231t_os\tools\generate |
| 128 | + |
| 129 | +set COPIED_COUNT=0 |
| 130 | +if exist "%GEN_DIR%\%APP_NAME%_%APP_VERSION%.rbl" ( |
| 131 | + copy /y "%GEN_DIR%\%APP_NAME%_%APP_VERSION%.rbl" "output\%APP_VERSION%\" >nul 2>nul |
| 132 | + echo [INFO] Copied: %APP_NAME%_%APP_VERSION%.rbl |
| 133 | + set /a COPIED_COUNT+=1 |
| 134 | +) |
| 135 | +if exist "%GEN_DIR%\%APP_NAME%_UG_%APP_VERSION%.bin" ( |
| 136 | + copy /y "%GEN_DIR%\%APP_NAME%_UG_%APP_VERSION%.bin" "output\%APP_VERSION%\" >nul 2>nul |
| 137 | + echo [INFO] Copied: %APP_NAME%_UG_%APP_VERSION%.bin |
| 138 | + set /a COPIED_COUNT+=1 |
| 139 | +) |
| 140 | +if exist "%GEN_DIR%\%APP_NAME%_UA_%APP_VERSION%.bin" ( |
| 141 | + copy /y "%GEN_DIR%\%APP_NAME%_UA_%APP_VERSION%.bin" "output\%APP_VERSION%\" >nul 2>nul |
| 142 | + echo [INFO] Copied: %APP_NAME%_UA_%APP_VERSION%.bin |
| 143 | + set /a COPIED_COUNT+=1 |
| 144 | +) |
| 145 | +if exist "%GEN_DIR%\%APP_NAME%_QIO_%APP_VERSION%.bin" ( |
| 146 | + copy /y "%GEN_DIR%\%APP_NAME%_QIO_%APP_VERSION%.bin" "output\%APP_VERSION%\" >nul 2>nul |
| 147 | + echo [INFO] Copied: %APP_NAME%_QIO_%APP_VERSION%.bin |
| 148 | + set /a COPIED_COUNT+=1 |
| 149 | +) |
| 150 | + |
| 151 | +echo. |
| 152 | +echo ============================================== |
| 153 | +echo BUILD SUCCESSFUL! (%COPIED_COUNT% files copied) |
| 154 | +echo ============================================== |
| 155 | +echo. |
| 156 | +echo Output directory: |
| 157 | +echo %CD%\output\%APP_VERSION%\ |
| 158 | +echo. |
| 159 | +echo Build files: |
| 160 | +echo ---------------------------------------------- |
| 161 | +for %%F in (output\%APP_VERSION%\*.bin output\%APP_VERSION%\*.rbl) do ( |
| 162 | + echo %%~nxF (%%~zF bytes) |
| 163 | +) |
| 164 | +echo ============================================== |
| 165 | +exit /b 0 |
0 commit comments