增加自动化编译打包脚本

This commit is contained in:
2026-09-04 14:59:14 +08:00
parent f4eb881ba7
commit 011bc43621
6 changed files with 275 additions and 205 deletions
+12
View File
@@ -0,0 +1,12 @@
@echo off
chcp 65001 >nul
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0pack_firmware.ps1"
if errorlevel 1 (
echo.
echo pack failed.
pause
exit /b 1
)
echo.
pause
+168
View File
@@ -0,0 +1,168 @@
# pack_firmware.ps1
# Extract JieLi burn files and zip as Project_Version_Date.
# ASCII only: Windows PowerShell 5.1 mis-parses UTF-8 without BOM.
#
# Usage:
# .\build.bat - build + download.bat + pack
# make pack - pack only
# tools\pack_firmware.bat
[CmdletBinding()]
param(
[string]$ProjectName = "JBao_Heat_Pad",
[string]$SdkRoot = ""
)
$ErrorActionPreference = "Stop"
$exitCode = 0
try {
if ([string]::IsNullOrWhiteSpace($SdkRoot)) {
$SdkRoot = Split-Path -Parent $PSScriptRoot
}
$VersionHeader = Join-Path $SdkRoot "apps\usr_jb_proto\Protocol\jb_product.h"
$DownloadDir = Join-Path $SdkRoot "cpu\br28\tools\download\earphone"
$ReleaseRoot = Join-Path $SdkRoot "release"
function Read-FwVersion {
param([string]$HeaderPath)
if (-not (Test-Path -LiteralPath $HeaderPath)) {
throw "version header not found: $HeaderPath"
}
$text = Get-Content -LiteralPath $HeaderPath -Raw -Encoding UTF8
$major = $null
$minor = $null
$patch = $null
if ($text -match '(?m)^\s*#define\s+JB_MCU_SW_VERSION_MAJOR\s+(\d+)') {
$major = $Matches[1]
}
if ($text -match '(?m)^\s*#define\s+JB_MCU_SW_VERSION_MINOR\s+(\d+)') {
$minor = $Matches[1]
}
if ($text -match '(?m)^\s*#define\s+JB_MCU_SW_VERSION_PATCH\s+(\d+)') {
$patch = $Matches[1]
}
if (($null -eq $major) -or ($null -eq $minor) -or ($null -eq $patch)) {
throw "cannot parse JB_MCU_SW_VERSION_* from $HeaderPath"
}
return "V$major.$minor.$patch"
}
$PackItems = @(
@{ Name = "jl_isd_nokey.fw"; Fallback = "jl_isd.fw"; Suffix = "_nokey_burner.fw"; Required = $true; NoteKey = "burner_nokey" },
@{ Name = "update_nokey.ufw"; Fallback = "update.ufw"; Suffix = "_nokey_app_ota.ufw"; Required = $false; NoteKey = "app_nokey" },
@{ Name = "db_update_data_nokey.bin"; Fallback = "db_update_data.bin"; Suffix = "_nokey_gateway_ota.bin"; Required = $false; NoteKey = "gw_nokey" },
@{ Name = "jl_isd_key.fw"; Fallback = ""; Suffix = "_key_burner.fw"; Required = $false; NoteKey = "burner_key" },
@{ Name = "update_key.ufw"; Fallback = ""; Suffix = "_key_app_ota.ufw"; Required = $false; NoteKey = "app_key" },
@{ Name = "db_update_data_key.bin"; Fallback = ""; Suffix = "_key_gateway_ota.bin"; Required = $false; NoteKey = "gw_key" }
)
$NoteZh = @{}
$notesFile = Join-Path $PSScriptRoot "pack_notes_zh.txt"
Get-Content -LiteralPath $notesFile -Encoding UTF8 | ForEach-Object {
if ($_ -match '^([^|]+)\|(.*)$') {
$NoteZh[$Matches[1].Trim()] = $Matches[2].Trim()
}
}
Write-Host "========================================"
Write-Host " pack firmware"
Write-Host "========================================"
$version = Read-FwVersion -HeaderPath $VersionHeader
$dateStr = Get-Date -Format "yyMMddHHmm"
$pkgName = "${ProjectName}_${version}_${dateStr}"
Write-Host "project : $ProjectName"
Write-Host "version : $version (from jb_product.h)"
Write-Host "date : $dateStr"
Write-Host "source : $DownloadDir"
Write-Host ""
if (-not (Test-Path -LiteralPath $DownloadDir)) {
throw "download dir not found, compile the project first: $DownloadDir"
}
$copied = @()
foreach ($item in $PackItems) {
$src = Join-Path $DownloadDir $item.Name
if (-not (Test-Path -LiteralPath $src) -and $item.Fallback) {
$src = Join-Path $DownloadDir $item.Fallback
}
if (Test-Path -LiteralPath $src) {
$item.Src = $src
$item.Dest = $pkgName + $item.Suffix
$copied += $item
continue
}
if ($item.Required) {
throw "missing required file: $($item.Name); please build the firmware first."
}
Write-Host "[skip] $($item.Name) not generated"
}
if ($copied.Count -eq 0) {
throw "no firmware files found in $DownloadDir"
}
$pkgDir = Join-Path $ReleaseRoot $pkgName
if (Test-Path -LiteralPath $pkgDir) {
Remove-Item -LiteralPath $pkgDir -Recurse -Force
}
New-Item -ItemType Directory -Path $pkgDir -Force | Out-Null
foreach ($item in $copied) {
Copy-Item -LiteralPath $item.Src -Destination (Join-Path $pkgDir $item.Dest) -Force
$size = (Get-Item -LiteralPath $item.Src).Length
Write-Host ("[copy] {0,-28} -> {1} ({2} bytes)" -f (Split-Path $item.Src -Leaf), $item.Dest, $size)
}
$fileList = New-Object System.Collections.Generic.List[string]
foreach ($item in $copied) {
$note = $NoteZh[$item.NoteKey]
[void]$fileList.Add((" {0}" -f $item.Dest))
[void]$fileList.Add((" {0}" -f $note))
}
$tplPath = Join-Path $PSScriptRoot "pack_readme_zh.txt"
$readme = Get-Content -LiteralPath $tplPath -Raw -Encoding UTF8
$readme = $readme.Replace("{{PKG_NAME}}", $pkgName)
$readme = $readme.Replace("{{PROJECT}}", $ProjectName)
$readme = $readme.Replace("{{VERSION}}", $version)
$readme = $readme.Replace("{{DATE}}", (Get-Date -Format "yyyy-MM-dd HH:mm:ss"))
$readme = $readme.Replace("{{FILE_LIST}}", ($fileList -join "`r`n"))
$readme = $readme -replace "`n", "`r`n"
$readme = $readme -replace "`r`r`n", "`r`n"
[System.IO.File]::WriteAllText(
(Join-Path $pkgDir "README.txt"),
$readme,
[System.Text.UTF8Encoding]::new($true)
)
$zipPath = Join-Path $ReleaseRoot "$pkgName.zip"
if (Test-Path -LiteralPath $zipPath) {
Remove-Item -LiteralPath $zipPath -Force
}
Compress-Archive -Path (Join-Path $pkgDir "*") -DestinationPath $zipPath -CompressionLevel Optimal
Write-Host ""
Write-Host "folder : $pkgDir"
Write-Host "zip : $zipPath"
Write-Host "done."
Write-Host "========================================"
} catch {
Write-Host ""
Write-Host "pack failed: $($_.Exception.Message)"
$exitCode = 1
}
exit $exitCode
+6
View File
@@ -0,0 +1,6 @@
burner_nokey|不带 Key:产线批量烧录器镜像(调试、未加密芯片)
app_nokey|不带 Key:手机 APP / 小程序 OTAUFW
gw_nokey|不带 Key55AA 服务器 OTA / 网关 OTA(杰理双备份包)
burner_key|带 Key:产线批量烧录器镜像(烧录器需配置同一把 key)
app_key|带 Key:手机 APP / 小程序 OTAUFW
gw_key|带 Key55AA 服务器 OTA / 网关 OTA(杰理双备份包)
+20
View File
@@ -0,0 +1,20 @@
包名 : {{PKG_NAME}}
项目 : {{PROJECT}}
版本 : {{VERSION}}
日期 : {{DATE}}
文件说明:
{{FILE_LIST}}
使用说明:
1. 批量烧录器:打开 *_burner.fw。
2. 杰理 UFW 通道(部分 APP / 小程序):上传 *_app_ota.ufw。
3. 走本协议 55AA 的服务器 OTA(APP / 小程序 / 网关都一样):上传 *_gateway_ota.bin。
Type=0x02BLE),不要传 ufw / fw / 普通 app.bin。
4. 杰理网关若单独吃双备份包:同样用 *_gateway_ota.bin。
不带 Key(*_nokey_*):调试、未加密芯片。
带 Key(*_key_*):加密镜像,烧录器 / 升级工具必须配置同一把 key(RS-5B88)。
本包不包含 .key 文件,请不要把工厂 key 发给终端用户。
本机 USB.\build.bat 默认烧 nokey.\build.bat key 烧带 Key。两套文件都会打包。