Initial gwin-skill: Gowin ACG525 full toolchain skill for agents.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ProjectDir,
|
||||
[string]$GowinRoot = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if (-not $GowinRoot) {
|
||||
$GowinRoot = Join-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) `
|
||||
"tool-chain\Gowin\Gowin_V1.9.11.03_Education_x64"
|
||||
if (-not (Test-Path $GowinRoot)) {
|
||||
$GowinRoot = "C:\Users\Administrator\Documents\fpga\tool-chain\Gowin\Gowin_V1.9.11.03_Education_x64"
|
||||
}
|
||||
}
|
||||
|
||||
$ProjectDir = (Resolve-Path $ProjectDir).Path
|
||||
$gwSh = Join-Path $GowinRoot "IDE\bin\gw_sh.exe"
|
||||
$buildTcl = Join-Path $ProjectDir "build.tcl"
|
||||
|
||||
if (-not (Test-Path $gwSh)) { throw "gw_sh.exe not found: $gwSh" }
|
||||
if (-not (Test-Path $buildTcl)) { throw "build.tcl not found: $buildTcl" }
|
||||
|
||||
$env:PATH = "$(Join-Path $GowinRoot 'IDE\bin');$(Join-Path $GowinRoot 'Programmer\bin');$env:PATH"
|
||||
|
||||
Write-Host "Building: $ProjectDir"
|
||||
Push-Location $ProjectDir
|
||||
try {
|
||||
cmd /c "type build.tcl | gw_sh.exe"
|
||||
if ($LASTEXITCODE -ne 0) { throw "gw_sh failed with exit $LASTEXITCODE" }
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
$fs = Get-ChildItem (Join-Path $ProjectDir "impl\pnr\*.fs") -ErrorAction SilentlyContinue |
|
||||
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||
if (-not $fs) { throw "No bitstream (.fs) under impl\pnr" }
|
||||
|
||||
Write-Host "OK bitstream: $($fs.FullName)"
|
||||
return $fs.FullName
|
||||
@@ -0,0 +1,13 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ProjectDir,
|
||||
[ValidateSet(2, 4, 5, 6)]
|
||||
[int]$Operation = 2,
|
||||
[string]$GowinRoot = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$scripts = $PSScriptRoot
|
||||
|
||||
& (Join-Path $scripts "build.ps1") -ProjectDir $ProjectDir -GowinRoot $GowinRoot
|
||||
& (Join-Path $scripts "download.ps1") -ProjectDir $ProjectDir -Operation $Operation -GowinRoot $GowinRoot
|
||||
@@ -0,0 +1,38 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ProjectDir,
|
||||
[string]$FsFile = "",
|
||||
[ValidateSet(2, 4, 5, 6)]
|
||||
[int]$Operation = 2,
|
||||
[string]$GowinRoot = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if (-not $GowinRoot) {
|
||||
$GowinRoot = "C:\Users\Administrator\Documents\fpga\tool-chain\Gowin\Gowin_V1.9.11.03_Education_x64"
|
||||
}
|
||||
|
||||
$ProjectDir = (Resolve-Path $ProjectDir).Path
|
||||
$cli = Join-Path $GowinRoot "Programmer\bin\programmer_cli.exe"
|
||||
if (-not (Test-Path $cli)) { throw "programmer_cli.exe not found: $cli" }
|
||||
|
||||
$env:PATH = "$(Join-Path $GowinRoot 'Programmer\bin');$env:PATH"
|
||||
|
||||
Write-Host "Scanning cables..."
|
||||
& $cli --scan
|
||||
if ($LASTEXITCODE -ne 0) { throw "scan failed; check USB cable and board power" }
|
||||
|
||||
if (-not $FsFile) {
|
||||
$fs = Get-ChildItem (Join-Path $ProjectDir "impl\pnr\*.fs") |
|
||||
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||
if (-not $fs) { throw "No .fs found; build first" }
|
||||
$FsFile = $fs.FullName
|
||||
} else {
|
||||
$FsFile = (Resolve-Path $FsFile).Path
|
||||
}
|
||||
|
||||
Write-Host "Programming GW5A-25A op=$Operation file=$FsFile"
|
||||
& $cli -d GW5A-25A --fsFile $FsFile -r $Operation
|
||||
if ($LASTEXITCODE -ne 0) { throw "program failed" }
|
||||
Write-Host "Download finished."
|
||||
@@ -0,0 +1,61 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Name,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$TargetDir,
|
||||
[string]$TopModule = "top"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$templateRoot = Join-Path (Split-Path $PSScriptRoot -Parent) "templates"
|
||||
|
||||
if (Test-Path $TargetDir) {
|
||||
throw "Target already exists: $TargetDir"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $TargetDir "src") | Out-Null
|
||||
|
||||
# gprj
|
||||
$gprj = @"
|
||||
<?xml version="1" encoding="UTF-8"?>
|
||||
<!DOCTYPE gowin-fpga-project>
|
||||
<Project>
|
||||
<Template>FPGA</Template>
|
||||
<Version>5</Version>
|
||||
<Device name="GW5A-25A" pn="GW5A-LV25UG324C2/I1">gw5a25a-008</Device>
|
||||
<FileList>
|
||||
<File path="src/$TopModule.v" type="file.verilog" enable="1"/>
|
||||
<File path="src/$TopModule.cst" type="file.cst" enable="1"/>
|
||||
<File path="src/$TopModule.sdc" type="file.sdc" enable="1"/>
|
||||
</FileList>
|
||||
</Project>
|
||||
"@
|
||||
[System.IO.File]::WriteAllText((Join-Path $TargetDir "$Name.gprj"), $gprj, (New-Object System.Text.UTF8Encoding $false))
|
||||
|
||||
# build.tcl (ASCII, no BOM)
|
||||
$tcl = @"
|
||||
open_project $Name.gprj
|
||||
set_option -output_base_name $Name
|
||||
set_option -synthesis_tool gowinsynthesis
|
||||
set_option -top_module $TopModule
|
||||
set_option -use_sspi_as_gpio 1
|
||||
set_option -use_mspi_as_gpio 1
|
||||
set_option -use_ready_as_gpio 1
|
||||
set_option -use_done_as_gpio 1
|
||||
set_option -use_cpu_as_gpio 1
|
||||
run all
|
||||
exit
|
||||
"@
|
||||
[System.IO.File]::WriteAllText((Join-Path $TargetDir "build.tcl"), $tcl, (New-Object System.Text.UTF8Encoding $false))
|
||||
|
||||
Copy-Item (Join-Path $templateRoot "src\top.v") (Join-Path $TargetDir "src\$TopModule.v")
|
||||
Copy-Item (Join-Path $templateRoot "src\top.cst") (Join-Path $TargetDir "src\$TopModule.cst")
|
||||
Copy-Item (Join-Path $templateRoot "src\top.sdc") (Join-Path $TargetDir "src\$TopModule.sdc")
|
||||
|
||||
# fix module name inside copied files
|
||||
$v = Get-Content (Join-Path $TargetDir "src\$TopModule.v") -Raw
|
||||
$v = $v -replace "module top", "module $TopModule"
|
||||
[System.IO.File]::WriteAllText((Join-Path $TargetDir "src\$TopModule.v"), $v, (New-Object System.Text.UTF8Encoding $false))
|
||||
|
||||
Write-Host "Created project: $TargetDir"
|
||||
Write-Host "Next: gwin-skill\scripts\build_and_download.ps1 -ProjectDir $TargetDir"
|
||||
Reference in New Issue
Block a user