Files
light-petal-recognition/hls_cnn/scripts/run_vivado_qcnn_windows.ps1
T

88 lines
3.3 KiB
PowerShell

param(
[string]$SourceHlsDir,
[string]$WorkRoot = "C:\hls_qcnn_work",
[string]$VivadoBat = "F:\ZYNQ_\Vivado\2020.2\bin\vivado.bat"
)
$ErrorActionPreference = "Stop"
function Copy-TreeItem {
param(
[Parameter(Mandatory = $true)][string]$Source,
[Parameter(Mandatory = $true)][string]$Destination
)
if (Test-Path -LiteralPath $Source) {
Copy-Item -LiteralPath $Source -Destination $Destination -Recurse -Force
}
}
$sourcePath = [System.IO.Path]::GetFullPath($SourceHlsDir)
$workRootPath = [System.IO.Path]::GetFullPath($WorkRoot)
$workHlsDir = Join-Path $workRootPath "hls_cnn"
if (-not (Test-Path -LiteralPath $sourcePath -PathType Container)) {
throw "Source HLS directory not found: $sourcePath"
}
if (-not (Test-Path -LiteralPath $VivadoBat -PathType Leaf)) {
throw "Vivado not found: $VivadoBat"
}
if ($workRootPath -notmatch '^[A-Za-z]:\\hls_qcnn_work$') {
throw "Refusing to use unexpected work root: $workRootPath"
}
New-Item -ItemType Directory -Force -Path $workRootPath | Out-Null
if (-not (Test-Path -LiteralPath $workHlsDir -PathType Container)) {
New-Item -ItemType Directory -Force -Path $workHlsDir | Out-Null
}
foreach ($dir in @("build", "include", "scripts", "src", "tb", "ip_repo")) {
$from = Join-Path $sourcePath $dir
if (Test-Path -LiteralPath $from) {
$to = Join-Path $workHlsDir $dir
if (Test-Path -LiteralPath $to) {
Remove-Item -LiteralPath $to -Recurse -Force
}
Copy-TreeItem -Source $from -Destination $workHlsDir
}
}
$ipComponent = Join-Path $workHlsDir "build\hls_qcnn_hls\solution1\impl\ip\component.xml"
if (-not (Test-Path -LiteralPath $ipComponent -PathType Leaf)) {
throw "Packaged HLS-QCNN IP not found. Run hls_cnn\run_hls_qcnn.bat first. Missing: $ipComponent"
}
Write-Host "Running HLS-QCNN Vivado in ASCII work directory:"
Write-Host " $workHlsDir"
& $VivadoBat -mode batch -source (Join-Path $workHlsDir "scripts\create_hls_qcnn_vivado_project.tcl")
if ($LASTEXITCODE -ne 0) {
throw "Vivado failed with exit code $LASTEXITCODE"
}
$sourceVivado = Join-Path $sourcePath "vivado"
$sourceOutput = Join-Path $sourcePath "output"
New-Item -ItemType Directory -Force -Path $sourceVivado | Out-Null
New-Item -ItemType Directory -Force -Path $sourceOutput | Out-Null
Get-ChildItem -LiteralPath (Join-Path $workHlsDir "vivado") -Filter "hls_qcnn_pynq_z2*" | ForEach-Object {
$destination = Join-Path $sourceVivado $_.Name
if (Test-Path -LiteralPath $destination) {
Remove-Item -LiteralPath $destination -Recurse -Force
}
Copy-TreeItem -Source $_.FullName -Destination $sourceVivado
}
Copy-Item -LiteralPath (Join-Path $workHlsDir "output\hls_qcnn.bit") -Destination (Join-Path $sourceOutput "hls_qcnn.bit") -Force
Copy-Item -LiteralPath (Join-Path $workHlsDir "output\hls_qcnn.hwh") -Destination (Join-Path $sourceOutput "hls_qcnn.hwh") -Force
$bit = Join-Path $sourceOutput "hls_qcnn.bit"
$hwh = Join-Path $sourceOutput "hls_qcnn.hwh"
if (-not (Test-Path -LiteralPath $bit -PathType Leaf)) {
throw "Bitstream was not copied back: $bit"
}
if (-not (Test-Path -LiteralPath $hwh -PathType Leaf)) {
throw "HWH was not copied back: $hwh"
}
Write-Host "HLS-QCNN Vivado build completed:"
Write-Host " $bit"
Write-Host " $hwh"