43 lines
1.9 KiB
PowerShell
43 lines
1.9 KiB
PowerShell
# Shared helpers for build/flash scripts.
|
|||
|
|
|
||
|
|
# A mapped drive that points back to a share on this very PC (D: -> \\THISPC\Projects)
|
||
|
|
# makes every compiler launch go through SMB and antivirus scanning: builds
|
||
|
|
# get ~50x slower. Translate such paths to the local folder behind the share.
|
||
|
|
function Resolve-LocalPath([string]$Path) {
|
||
|
|
$full = (Resolve-Path $Path).ProviderPath
|
||
|
|
$drive = Get-PSDrive -Name $full.Substring(0, 1) -ErrorAction SilentlyContinue
|
||
|
|
if ($drive -and $drive.DisplayRoot -match '^\\\\([^\\]+)\\([^\\]+)') {
|
||
|
|
if ($Matches[1] -ieq $env:COMPUTERNAME) {
|
||
|
|
$share = Get-CimInstance Win32_Share -Filter "Name='$($Matches[2])'" -ErrorAction SilentlyContinue
|
||
|
|
if ($share) {
|
||
|
|
return Join-Path $share.Path $full.Substring(3)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $full
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-ProjectRoot {
|
||
|
|
return Resolve-LocalPath (Join-Path $PSScriptRoot '..')
|
||
|
|
}
|
||
|
|
|
||
|
|
function Set-BuildEnv([string]$Root) {
|
||
|
|
$sdk = Join-Path $Root 'third_party\bouffalo_sdk'
|
||
|
|
$tc = Join-Path $Root 'third_party\toolchain_gcc_t-head_windows\bin'
|
||
|
|
if (-not (Test-Path $sdk) -or -not (Test-Path $tc)) {
|
||
|
|
throw "SDK/toolchain not found in $Root\third_party - run scripts\setup.ps1 first"
|
||
|
|
}
|
||
|
|
$env:BL_SDK_BASE = $sdk
|
||
|
|
$env:PATH = "$tc;$sdk\tools\make;$sdk\tools\ninja;$sdk\tools\cmake\bin;$env:SystemRoot\System32;$env:SystemRoot"
|
||
|
|
}
|
||
|
|
|
||
|
|
# COM port name(s) of present devices whose instance id matches the pattern
|
||
|
|
function Find-ComPort([string]$IdPattern) {
|
||
|
|
Get-CimInstance Win32_PnPEntity -Filter "PNPClass='Ports'" -ErrorAction SilentlyContinue |
|
||
|
|
Where-Object { $_.PNPDeviceID -match $IdPattern -and $_.Name -match '\((COM\d+)\)' } |
|
||
|
|
ForEach-Object { [regex]::Match($_.Name, '\((COM\d+)\)').Groups[1].Value }
|
||
|
|
}
|
||
|
|
|
||
|
|
$BootromPortId = 'VID_349B&PID_6160' # BL616 ROM USB bootloader "Bouffalo CDC DEMO"
|
||
|
|
$FirmwarePortId = 'VID_1209&PID_C0CA&MI_01' # this firmware's CDC UART
|