84 lines
2.8 KiB
PowerShell
84 lines
2.8 KiB
PowerShell
param(
|
|
[string]$SourceHlsDir,
|
|
[string]$WorkRoot = "C:\hls_tiny_cnn_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_tiny_cnn_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\tiny_cnn_hls\solution1\impl\ip\component.xml"
|
|
if (-not (Test-Path -LiteralPath $ipComponent -PathType Leaf)) {
|
|
throw "Packaged HLS IP not found. Run hls_cnn\run_hls.bat first. Missing: $ipComponent"
|
|
}
|
|
|
|
Write-Host "Running Vivado in ASCII work directory:"
|
|
Write-Host " $workHlsDir"
|
|
& $VivadoBat -mode batch -source (Join-Path $workHlsDir "scripts\create_vivado_project.tcl")
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Vivado failed with exit code $LASTEXITCODE"
|
|
}
|
|
|
|
foreach ($dir in @("vivado", "output")) {
|
|
$from = Join-Path $workHlsDir $dir
|
|
if (Test-Path -LiteralPath $from) {
|
|
$to = Join-Path $sourcePath $dir
|
|
if (Test-Path -LiteralPath $to) {
|
|
Remove-Item -LiteralPath $to -Recurse -Force
|
|
}
|
|
Copy-TreeItem -Source $from -Destination $sourcePath
|
|
}
|
|
}
|
|
|
|
$bit = Join-Path $sourcePath "output\tiny_cnn.bit"
|
|
$hwh = Join-Path $sourcePath "output\tiny_cnn.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 "Vivado build completed:"
|
|
Write-Host " $bit"
|
|
Write-Host " $hwh"
|