# Rebuild (optional) and refresh firmware/cyd_28r from PlatformIO build output. # Usage: # .\firmware\export_from_build.ps1 # .\firmware\export_from_build.ps1 -SkipBuild param([switch]$SkipBuild) $ErrorActionPreference = "Stop" $root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) Set-Location $root if (-not $SkipBuild) { pio run -e cyd_28r if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } } $src = Join-Path $root ".pio\build\cyd_28r" $dst = Join-Path $root "firmware\cyd_28r" New-Item -ItemType Directory -Force -Path $dst | Out-Null Copy-Item (Join-Path $src "bootloader.bin") $dst -Force Copy-Item (Join-Path $src "partitions.bin") $dst -Force Copy-Item (Join-Path $src "firmware.bin") $dst -Force $bootApp = Join-Path $env:USERPROFILE ".platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin" if (-not (Test-Path $bootApp)) { Write-Error "boot_app0.bin not found under PlatformIO packages" } Copy-Item $bootApp (Join-Path $dst "boot_app0.bin") -Force $git = "nogit" try { $git = (git -C $root rev-parse --short HEAD 2>$null).Trim() if (-not $git) { $git = "nogit" } } catch { $git = "nogit" } $date = Get-Date -Format "yyyy-MM-dd" $hashes = Get-FileHash (Join-Path $dst "*.bin") -Algorithm SHA256 $lines = @( "name: CYD SGP30 air quality dashboard (cyd_28r)", "git: $git", "date: $date", "board: ESP32-2432S028R (ILI9341)", "sgp30: SDA=GPIO22 SCL=GPIO27", "flash_size: 4MB", "offsets:", " 0x1000 bootloader.bin", " 0x8000 partitions.bin", " 0xe000 boot_app0.bin", " 0x10000 firmware.bin", "sha256:" ) foreach ($h in $hashes) { $lines += (" {0,-15} {1}" -f (Split-Path $h.Path -Leaf), $h.Hash) } $lines | Set-Content -Encoding utf8 (Join-Path $dst "VERSION.txt") Write-Host "Exported -> $dst (git $git)"