Skip to content

Commit 0ad7f75

Browse files
test1
1 parent 1d174d6 commit 0ad7f75

3 files changed

Lines changed: 386 additions & 0 deletions

File tree

build_bk7231t.bat

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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

build_bk7231t_inner.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Inner build script called by build_bk7231t.bat
3+
# Arguments: APP_NAME APP_VERSION SDK_DIR OBK_VARIANT
4+
set -e
5+
6+
APP_NAME="$1"
7+
APP_VERSION="$2"
8+
SDK_DIR="$3"
9+
export OBK_VARIANT="$4"
10+
11+
echo "[INFO] Inner build script started"
12+
echo "[INFO] APP_NAME=$APP_NAME"
13+
echo "[INFO] APP_VERSION=$APP_VERSION"
14+
echo "[INFO] SDK_DIR=$SDK_DIR"
15+
echo "[INFO] OBK_VARIANT=$OBK_VARIANT"
16+
17+
# First, check if make is available
18+
if type make > /dev/null 2>&1; then
19+
echo "[INFO] GNU make is available."
20+
else
21+
echo "[INFO] GNU make not found in Git Bash. Attempting to get it..."
22+
MAKE_FOUND=0
23+
for MAKE_PATH in /c/ProgramData/chocolatey/bin/make.exe /c/msys64/usr/bin/make.exe /w/TOOLS/msys64/usr/bin/make.exe; do
24+
if [ -f "$MAKE_PATH" ]; then
25+
export PATH="$(dirname "$MAKE_PATH"):$PATH"
26+
MAKE_FOUND=1
27+
echo "[INFO] Found make at $MAKE_PATH"
28+
break
29+
fi
30+
done
31+
if [ $MAKE_FOUND -eq 0 ]; then
32+
echo "[ERROR] GNU make not found!"
33+
echo "Please install make via one of:"
34+
echo " choco install make"
35+
echo " pacman -S make (in MSYS2)"
36+
echo " Or download from https://gnuwin32.sourceforge.net/packages/make.htm"
37+
exit 1
38+
fi
39+
fi
40+
41+
echo "[INFO] make found: $(which make)"
42+
echo "[INFO] make version: $(make --version | head -1)"
43+
44+
SCRIPT_DIR="$(pwd)"
45+
46+
# Set a localized TEMP dir to avoid PyInstaller extraction permission errors
47+
# beken_packager.exe is a PyInstaller bundle that needs to extract VCRUNTIME140.dll
48+
LOCAL_TMP="$(cygpath -m "$SCRIPT_DIR/output/tmp")"
49+
echo "[INFO] Setting local TEMP dir: $LOCAL_TMP"
50+
mkdir -p "$SCRIPT_DIR/output/tmp"
51+
export TEMP="$LOCAL_TMP"
52+
export TMP="$LOCAL_TMP"
53+
export TMPDIR="$LOCAL_TMP"
54+
echo "[INFO] TEMP=$TEMP"
55+
echo "[INFO] TMP=$TMP"
56+
echo "[INFO] TMPDIR=$TMPDIR"
57+
58+
# Navigate to the build system directory
59+
cd "$SDK_DIR/platforms/bk7231t/bk7231t_os"
60+
61+
echo "[INFO] Running BK7231T build from $(pwd)..."
62+
bash build.sh "$APP_NAME" "$APP_VERSION" bk7231t "OBK_VARIANT=$OBK_VARIANT"
63+
64+
echo "[INFO] Build complete!"

build_esp32.bat

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
4+
:: Default settings
5+
set APP_VERSION=dev_esp32
6+
set OBK_VARIANT=2
7+
set ESP_FSIZE=4MB
8+
set TARGET=esp32
9+
10+
:: Check for target argument
11+
if not "%~1"=="" set TARGET=%~1
12+
13+
if "%TARGET%"=="esp32" (
14+
set BUILD_DIR=platforms\ESP-IDF\build-32
15+
set BOOTLOADER_ADDR=0x1000
16+
) else if "%TARGET%"=="esp32c3" (
17+
set BUILD_DIR=platforms\ESP-IDF\build-c3
18+
set BOOTLOADER_ADDR=0x0
19+
) else if "%TARGET%"=="esp32c2" (
20+
set BUILD_DIR=platforms\ESP-IDF\build-c2
21+
set BOOTLOADER_ADDR=0x0
22+
) else if "%TARGET%"=="esp32c5" (
23+
set BUILD_DIR=platforms\ESP-IDF\build-c5
24+
set BOOTLOADER_ADDR=0x2000
25+
) else if "%TARGET%"=="esp32c6" (
26+
set BUILD_DIR=platforms\ESP-IDF\build-c6
27+
set BOOTLOADER_ADDR=0x0
28+
) else if "%TARGET%"=="esp32c61" (
29+
set BUILD_DIR=platforms\ESP-IDF\build-c61
30+
set BOOTLOADER_ADDR=0x0
31+
) else if "%TARGET%"=="esp32s2" (
32+
set BUILD_DIR=platforms\ESP-IDF\build-s2
33+
set BOOTLOADER_ADDR=0x1000
34+
) else if "%TARGET%"=="esp32s3" (
35+
set BUILD_DIR=platforms\ESP-IDF\build-s3
36+
set BOOTLOADER_ADDR=0x0
37+
) else (
38+
echo [ERROR] Unknown target: %TARGET%
39+
exit /b 1
40+
)
41+
42+
echo ==============================================
43+
echo Building OpenBeken ESP32 on Windows natively
44+
echo Target: %TARGET%
45+
echo Size: %ESP_FSIZE%
46+
echo Variant (2=tuyaMCU/4MB): %OBK_VARIANT%
47+
echo Bootloader Addr: %BOOTLOADER_ADDR%
48+
echo Build Directory: %BUILD_DIR%
49+
echo ==============================================
50+
51+
:: Check if ESP-IDF environment is active
52+
where idf.py >nul 2>nul
53+
if %errorlevel% equ 0 goto :idf_ready
54+
55+
echo [INFO] ESP-IDF 'idf.py' not found in PATH.
56+
echo [INFO] Attempting to load from sdk\esp-idf...
57+
58+
if not exist "sdk\esp-idf\export.bat" goto :no_idf
59+
60+
:: Try export.bat first
61+
call "sdk\esp-idf\export.bat"
62+
where idf.py >nul 2>nul
63+
if %errorlevel% equ 0 goto :idf_ready
64+
65+
:: export.bat didn't give us idf.py - try install.bat then re-export
66+
echo [INFO] export.bat did not set up environment. Running install.bat...
67+
if not exist "sdk\esp-idf\install.bat" goto :no_idf
68+
69+
call "sdk\esp-idf\install.bat"
70+
71+
echo [INFO] Retrying export.bat...
72+
call "sdk\esp-idf\export.bat"
73+
where idf.py >nul 2>nul
74+
if %errorlevel% equ 0 goto :idf_ready
75+
76+
echo [ERROR] ESP-IDF environment still not available after install+export!
77+
exit /b 1
78+
79+
:no_idf
80+
echo [ERROR] ESP-IDF not found!
81+
echo Please ensure sdk\esp-idf is checked out (git submodule update --init --recursive sdk/esp-idf)
82+
exit /b 1
83+
84+
:idf_ready
85+
echo [INFO] ESP-IDF environment is ready.
86+
87+
:: Prepare partition tables based on OBK_VARIANT
88+
if exist platforms\ESP-IDF\sdkconfig del platforms\ESP-IDF\sdkconfig
89+
if exist platforms\ESP-IDF\partitions.csv del platforms\ESP-IDF\partitions.csv
90+
91+
:: Defaulting to 4MB for variant 2
92+
copy /y platforms\ESP-IDF\partitions-4mb.csv platforms\ESP-IDF\partitions.csv >nul
93+
94+
:: Set environment variables for IDF cmake
95+
set IDF_TARGET=%TARGET%
96+
97+
:: Configure CMake via ESP-IDF toolchain
98+
echo [INFO] Running CMake configuration for %TARGET%...
99+
cmake platforms\ESP-IDF -B %BUILD_DIR% -G "Ninja"
100+
if !errorlevel! neq 0 (
101+
echo [ERROR] CMake configuration failed!
102+
exit /b 1
103+
)
104+
105+
:: Build using CMake
106+
echo [INFO] Building with CMake/Ninja...
107+
cmake --build %BUILD_DIR% -j
108+
if !errorlevel! neq 0 (
109+
echo [ERROR] Build failed!
110+
exit /b 1
111+
)
112+
113+
:: Ensure output directory exists
114+
echo [INFO] Creating output directory...
115+
if not exist "output\%APP_VERSION%" mkdir output\%APP_VERSION%
116+
117+
:: Determine output names
118+
if "%TARGET%"=="esp32" (
119+
set OUT_NAME=OpenESP32
120+
) else if "%TARGET%"=="esp32c3" (
121+
set OUT_NAME=OpenESP32C3
122+
) else if "%TARGET%"=="esp32c2" (
123+
set OUT_NAME=OpenESP32C2
124+
) else if "%TARGET%"=="esp32c5" (
125+
set OUT_NAME=OpenESP32C5
126+
) else if "%TARGET%"=="esp32c6" (
127+
set OUT_NAME=OpenESP32C6
128+
) else if "%TARGET%"=="esp32c61" (
129+
set OUT_NAME=OpenESP32C61
130+
) else if "%TARGET%"=="esp32s2" (
131+
set OUT_NAME=OpenESP32S2
132+
) else if "%TARGET%"=="esp32s3" (
133+
set OUT_NAME=OpenESP32S3
134+
) else (
135+
set OUT_NAME=Open%TARGET%
136+
)
137+
138+
:: Package binaries using esptool
139+
echo [INFO] Merging binaries with esptool...
140+
set FACTORY_BIN=output\%APP_VERSION%\!OUT_NAME!_%APP_VERSION%.factory.bin
141+
set IMG_BIN=output\%APP_VERSION%\!OUT_NAME!_%APP_VERSION%.img
142+
143+
python -m esptool -c %TARGET% merge_bin -o !FACTORY_BIN! --flash_mode dio --flash_size %ESP_FSIZE% %BOOTLOADER_ADDR% %BUILD_DIR%\bootloader\bootloader.bin 0x8000 %BUILD_DIR%\partition_table\partition-table.bin 0x10000 %BUILD_DIR%\OpenBeken.bin
144+
if !errorlevel! neq 0 (
145+
echo [ERROR] esptool merge failed!
146+
exit /b 1
147+
)
148+
149+
copy /y %BUILD_DIR%\OpenBeken.bin !IMG_BIN! >nul
150+
151+
echo ==============================================
152+
echo BUILD SUCCESSFUL!
153+
echo Output files located in output\%APP_VERSION%
154+
echo Factory Bin: !FACTORY_BIN!
155+
echo OTA Bin: !IMG_BIN!
156+
echo ==============================================
157+
exit /b 0

0 commit comments

Comments
 (0)