Files

89 lines
4.0 KiB
PowerShell
Raw Permalink Normal View History

# Make a portable copy of TangProgrammer for another PC: the program and only
# the tools it runs (no SDK, no toolchain, no sources).
#
# .\scripts\make_portable.ps1 -> dist\TangProgrammer\ and dist\TangProgrammer.zip
#
# The FPGA and FPGA-flash tabs need TangProgrammer.exe + tools\openFPGALoader.
# The bridge firmware tab also needs BLFlashCommand (for flashing over the USB
# bootloader only the exe and chips\ are used, not the 200+ MB of debug probe
# tools around it), the firmware images and the flash configs.
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot -Parent
$dist = Join-Path $root 'dist'
$out = Join-Path $dist 'TangProgrammer'
$cube = Join-Path $root 'third_party\bouffalo_sdk\tools\bflb_tools\bouffalo_flash_cube'
$bridgeFw = Join-Path $root 'build\build_out\tang25k_debugger_bl616.bin'
if (Test-Path $out) { Remove-Item -Recurse -Force $out }
New-Item -ItemType Directory -Force (Join-Path $out 'tools') | Out-Null
& (Join-Path $PSScriptRoot 'build_gui.ps1') -Out (Join-Path $out 'TangProgrammer.exe')
Copy-Item -Recurse (Join-Path $root 'tools\openFPGALoader') (Join-Path $out 'tools\openFPGALoader')
if (Test-Path (Join-Path $cube 'BLFlashCommand.exe')) {
$dst = Join-Path $out 'tools\bouffalo_flash_cube'
New-Item -ItemType Directory -Force $dst | Out-Null
Copy-Item (Join-Path $cube 'BLFlashCommand.exe') $dst
Copy-Item -Recurse (Join-Path $cube 'chips') $dst
# what earlier flashing left in the SDK copy (ignored by its .gitignore)
Get-ChildItem (Join-Path $dst 'chips\*\img_create') -Directory -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force
Get-ChildItem (Join-Path $dst 'chips\*\eflash_loader\eflash_loader_cfg.ini') -ErrorAction SilentlyContinue | Remove-Item -Force
} else {
Write-Warning 'Bouffalo SDK is not installed (scripts\setup.ps1): the bridge firmware tab will not work in the copy'
}
$fwDir = Join-Path $out 'firmware'
New-Item -ItemType Directory -Force $fwDir | Out-Null
Copy-Item (Join-Path $root 'bin\bl616_bootloader_0x20000_nano20k_signed.bin') $fwDir
Copy-Item (Join-Path $root 'bin\bl616_fpga_partner_25kDock.bin') $fwDir
if (Test-Path $bridgeFw) {
Copy-Item $bridgeFw $fwDir
} else {
Write-Warning 'bridge firmware is not built (scripts\build.ps1): it is missing from the copy'
}
# the same configs as in the project root, pointing at firmware\
Set-Content -Encoding ASCII (Join-Path $out 'flash_prog_cfg.ini') @'
[cfg]
# 0: no erase, 1: programmed section erase, 2: chip erase
erase = 1
skip_mode = 0x0, 0x0
boot2_isp_mode = 0
# Sipeed-encrypted stage-1 loader: the eFuse secure boot only runs images
# encrypted with Sipeed's key at 0x0. It unconditionally jumps to 0x20000.
[bootloader]
filedir = ./firmware/bl616_bootloader_0x20000_nano20k_signed.bin
address = 0x0
[FW]
filedir = ./firmware/tang25k_debugger_bl616.bin
address = 0x20000
'@
Set-Content -Encoding ASCII (Join-Path $out 'restore_prog_cfg.ini') @'
[cfg]
# 0: no erase, 1: programmed section erase, 2: chip erase
erase = 1
skip_mode = 0x0, 0x0
boot2_isp_mode = 0
# Original Sipeed debugger firmware (FT2232 emulation), version 2025030317
[FW]
filedir = ./firmware/bl616_fpga_partner_25kDock.bin
address = 0x0
'@
Copy-Item (Join-Path $root 'gui\portable_readme.txt') (Join-Path $out 'README.txt')
$zip = Join-Path $dist 'TangProgrammer.zip'
if (Test-Path $zip) { Remove-Item -Force $zip }
# not Compress-Archive: in Windows PowerShell 5.1 it writes '\' into the entry
# names, and unzip tools other than Explorer take them for part of the file
# name. ZipFile does the same unless told otherwise (.NET 4.6.1 compat switch).
[AppContext]::SetSwitch('Switch.System.IO.Compression.ZipFile.UseBackslash', $false)
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory($out, $zip, [IO.Compression.CompressionLevel]::Optimal, $true)
$size = (Get-ChildItem -Recurse $out | Measure-Object -Sum Length).Sum
Write-Host ("OK: {0} ({1:N1} MB), {2} ({3:N1} MB)" -f $out, ($size / 1MB), $zip, ((Get-Item $zip).Length / 1MB)) -ForegroundColor Green