Files

74 lines
3.8 KiB
PowerShell
Raw Permalink Normal View History

# Collect the files of a release into dist\release\v<version>\:
#
# TangProgrammer-v<version>-win64.zip portable programmer (make_portable.ps1)
# TangProgrammer.exe the program alone
# bl616_bridge_firmware-v<version>.zip bridge firmware (@0x20000), Sipeed loader
# (@0x0), original Sipeed firmware, configs
# for BLFlashCommand
# fpga_test_bitstreams-GW5A-25.zip fpga_test\*\impl\pnr\*.fs, if built
# SHA256SUMS.txt
#
# Five files at most: the Gitea web form takes no more than that ([attachment]
# MAX_FILES on gitea.vector.ru), publish_release.ps1 has no such limit.
#
# .\scripts\build.ps1
# .\scripts\make_release.ps1 version from FW_VERSION_STR in src\sys.h
param([string]$Version)
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot -Parent
if (-not $Version) {
$m = Select-String -Path (Join-Path $root 'src\sys.h') -Pattern '#define\s+FW_VERSION_STR\s+"([^"]+)"'
if (-not $m) { throw 'FW_VERSION_STR not found in src\sys.h' }
$Version = $m.Matches[0].Groups[1].Value
}
$tag = 'v' + $Version.TrimStart('v')
$bridgeFw = Join-Path $root 'build\build_out\tang25k_debugger_bl616.bin'
if (-not (Test-Path $bridgeFw)) { throw 'bridge firmware is not built: run scripts\build.ps1' }
if (-not (Test-Path (Join-Path $root 'third_party\bouffalo_sdk\tools\bflb_tools\bouffalo_flash_cube\BLFlashCommand.exe'))) {
throw 'Bouffalo SDK is not installed (scripts\setup.ps1): the portable copy needs BLFlashCommand'
}
$out = Join-Path $root "dist\release\$tag"
if (Test-Path $out) { Remove-Item -Recurse -Force $out }
New-Item -ItemType Directory -Force $out | Out-Null
& (Join-Path $PSScriptRoot 'make_portable.ps1')
Copy-Item (Join-Path $root 'dist\TangProgrammer.zip') (Join-Path $out "TangProgrammer-$tag-win64.zip")
Copy-Item (Join-Path $root 'dist\TangProgrammer\TangProgrammer.exe') $out
# the bridge images with the flash configs of the project root, pointing next to themselves
$fw = Join-Path $out "bl616_bridge_firmware-$tag"
New-Item -ItemType Directory -Force $fw | Out-Null
Copy-Item $bridgeFw $fw
Copy-Item (Join-Path $root 'bin\bl616_bootloader_0x20000_nano20k_signed.bin') $fw
Copy-Item (Join-Path $root 'bin\bl616_fpga_partner_25kDock.bin') $fw
foreach ($ini in 'flash_prog_cfg.ini', 'restore_prog_cfg.ini') {
$text = [IO.File]::ReadAllText((Join-Path $root $ini))
$text = $text.Replace('./build/build_out/', './').Replace('./bin/', './').Replace('$(CHIPNAME)', 'bl616')
[IO.File]::WriteAllText((Join-Path $fw $ini), $text)
}
Copy-Item (Join-Path $root 'bin\release_readme.txt') (Join-Path $fw 'README.txt')
# not Compress-Archive, see make_portable.ps1
[AppContext]::SetSwitch('Switch.System.IO.Compression.ZipFile.UseBackslash', $false)
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory($fw, "$fw.zip", [IO.Compression.CompressionLevel]::Optimal, $true)
Remove-Item -Recurse -Force $fw
$fs = @(Get-ChildItem (Join-Path $root 'fpga_test\*\impl\pnr\*.fs') -ErrorAction SilentlyContinue)
if ($fs.Count) {
Compress-Archive -Path ($fs | ForEach-Object { $_.FullName }) -DestinationPath (Join-Path $out 'fpga_test_bitstreams-GW5A-25.zip')
} else {
Write-Warning 'no test bitstreams: build them with gw_sh build.tcl in fpga_test\loopback and fpga_test\stream'
}
# sha256sum format, so that "sha256sum -c SHA256SUMS.txt" works
$sums = Get-ChildItem $out -File | Sort-Object Name | ForEach-Object {
(Get-FileHash -Algorithm SHA256 $_.FullName).Hash.ToLower() + ' ' + $_.Name
}
[IO.File]::WriteAllText((Join-Path $out 'SHA256SUMS.txt'), ($sums -join "`n") + "`n")
Get-ChildItem $out -File | Sort-Object Name | Format-Table Name, @{ n = 'KB'; e = { [math]::Ceiling($_.Length / 1KB) }; a = 'right' } -AutoSize
Write-Host "OK: $out" -ForegroundColor Green