- Makefile 源文件列表对齐 CodeBlocks,命令行 make 能编过;编完自动打到 ../release/ - 新增 tools/pack_firmware:按版本打出烧录器 / APP UFW / 网关双备份包,带 Key 和不带 Key 各一套 - build.bat key 烧带 Key,默认或不带参数烧 nokey;另一套只生成不写 Flash - 删掉未使用的 version.txt;release/ 不进仓库
170 lines
5.7 KiB
PowerShell
170 lines
5.7 KiB
PowerShell
# 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:
|
|
# make - build + download.bat + pack
|
|
# make pack - pack only
|
|
# pack_firmware.bat
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$ProjectName = "JL7016_MOD_FW",
|
|
[string]$SdkRoot = ""
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$exitCode = 0
|
|
|
|
try {
|
|
|
|
$RepoRoot = Split-Path -Parent $PSScriptRoot
|
|
if ([string]::IsNullOrWhiteSpace($SdkRoot)) {
|
|
$SdkRoot = Join-Path $RepoRoot "JBao_JL7016_MOD_FW"
|
|
}
|
|
|
|
$VersionHeader = Join-Path $SdkRoot "apps\usr_mcu_bridge\business\mcu_version.h"
|
|
$DownloadDir = Join-Path $SdkRoot "cpu\br28\tools\download\earphone"
|
|
$ReleaseRoot = Join-Path $RepoRoot "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+MCU_BLE_FW_VER_MAJOR\s+\((\d+)u?\)') {
|
|
$major = $Matches[1]
|
|
}
|
|
if ($text -match '(?m)^\s*#define\s+MCU_BLE_FW_VER_MINOR\s+\((\d+)u?\)') {
|
|
$minor = $Matches[1]
|
|
}
|
|
if ($text -match '(?m)^\s*#define\s+MCU_BLE_FW_VER_PATCH\s+\((\d+)u?\)') {
|
|
$patch = $Matches[1]
|
|
}
|
|
|
|
if (($null -eq $major) -or ($null -eq $minor) -or ($null -eq $patch)) {
|
|
throw "cannot parse MCU_BLE_FW_VER_* 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 mcu_version.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
|