feat: update CAN integration and T2G seat firmware
This commit is contained in:
Binary file not shown.
Binary file not shown.
+101
-93
@@ -1,132 +1,140 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[ValidateSet('all', 'combined', 'heater', 'fan', 'move')]
|
||||
[ValidateSet('combined')]
|
||||
[string]$Profile = 'combined',
|
||||
[string]$Configuration = 'rev_d',
|
||||
[string]$SdkRoot = 'C:\Users\D30042075206\Desktop\T2G_Sample_Driver_Library_7.9.0',
|
||||
[string]$RepositoryRoot = '',
|
||||
[string]$IarBuild = 'D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\iarbuild.exe'
|
||||
[string]$IarBuild = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$resolvedSdk = (Resolve-Path -LiteralPath $SdkRoot).Path
|
||||
$repositoryCandidate = if ($RepositoryRoot) {
|
||||
$RepositoryRoot
|
||||
} else {
|
||||
Join-Path $PSScriptRoot '..'
|
||||
}
|
||||
$resolvedRepository = (Resolve-Path -LiteralPath $repositoryCandidate).Path
|
||||
$resolvedIarBuild = (Resolve-Path -LiteralPath $IarBuild).Path
|
||||
$projects = [ordered]@{
|
||||
combined = 'Seat_Controller_demo'
|
||||
heater = 'Seat_Backrest_Heater_demo'
|
||||
fan = 'Seat_Fan_demo'
|
||||
move = 'Seat_Move_demo'
|
||||
$firmwareRoot = Join-Path $resolvedRepository 'firmware\t2g'
|
||||
$repositoryFirmware = Join-Path $firmwareRoot 'Seat_Controller_demo'
|
||||
$repositoryProject = Join-Path $repositoryFirmware 'IAR\Seat_Controller_demo.ewp'
|
||||
$vendorCommon = Join-Path $firmwareRoot 'common'
|
||||
$vendorDevice = Join-Path $firmwareRoot 'tviibh8m'
|
||||
|
||||
function Resolve-IarBuild {
|
||||
param([string]$ConfiguredPath)
|
||||
|
||||
$candidates = @()
|
||||
if ($ConfiguredPath) {
|
||||
$candidates += $ConfiguredPath
|
||||
}
|
||||
if ($env:COGNITIVE_AGENT_IAR_BUILD) {
|
||||
$candidates += $env:COGNITIVE_AGENT_IAR_BUILD
|
||||
}
|
||||
$command = Get-Command iarbuild.exe -ErrorAction SilentlyContinue
|
||||
if ($command) {
|
||||
$candidates += $command.Source
|
||||
}
|
||||
$candidates += @(
|
||||
'D:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\iarbuild.exe',
|
||||
'C:\Program Files\IAR Systems\Embedded Workbench 9.2\common\bin\iarbuild.exe'
|
||||
)
|
||||
foreach ($candidate in $candidates) {
|
||||
if ($candidate -and (Test-Path -LiteralPath $candidate -PathType Leaf)) {
|
||||
return (Resolve-Path -LiteralPath $candidate).Path
|
||||
}
|
||||
}
|
||||
throw 'IAR iarbuild.exe was not found; pass -IarBuild or set COGNITIVE_AGENT_IAR_BUILD.'
|
||||
}
|
||||
$selected = if ($Profile -eq 'all') { @($projects.Keys) } else { @($Profile) }
|
||||
|
||||
foreach ($required in @($repositoryProject, $vendorCommon, $vendorDevice)) {
|
||||
if (-not (Test-Path -LiteralPath $required)) {
|
||||
throw "Self-contained firmware dependency is missing: $required"
|
||||
}
|
||||
}
|
||||
$resolvedIarBuild = Resolve-IarBuild -ConfiguredPath $IarBuild
|
||||
|
||||
function Invoke-IarBuild {
|
||||
param(
|
||||
[string]$ProjectName,
|
||||
[string]$ProjectPath
|
||||
)
|
||||
param([string]$ProjectPath)
|
||||
|
||||
Write-Host "Building $ProjectName ($Configuration)..."
|
||||
Write-Host "Building Seat_Controller_demo ($Configuration)..."
|
||||
& $resolvedIarBuild $ProjectPath -build $Configuration -log all
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "IAR build failed for $ProjectName with exit code $LASTEXITCODE"
|
||||
throw "IAR build failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
function Write-ImageSummary {
|
||||
param(
|
||||
[string]$ProjectName,
|
||||
[string]$ImagePath
|
||||
)
|
||||
param([string]$ImagePath)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $ImagePath -PathType Leaf)) {
|
||||
throw "Build completed but HEX image was not found: $ImagePath"
|
||||
}
|
||||
$hash = Get-FileHash -LiteralPath $ImagePath -Algorithm SHA256
|
||||
Write-Host "$ProjectName HEX: $ImagePath"
|
||||
Write-Host "$ProjectName SHA256: $($hash.Hash.ToLowerInvariant())"
|
||||
Write-Host "Seat_Controller_demo HEX: $ImagePath"
|
||||
Write-Host "Seat_Controller_demo SHA256: $($hash.Hash.ToLowerInvariant())"
|
||||
}
|
||||
|
||||
foreach ($name in $selected) {
|
||||
$projectName = $projects[$name]
|
||||
if ($name -ne 'combined') {
|
||||
$project = Join-Path $resolvedSdk "$projectName\IAR\$projectName.ewp"
|
||||
if (-not (Test-Path -LiteralPath $project -PathType Leaf)) {
|
||||
throw "IAR project not found: $project"
|
||||
# Preserve the IAR project's original ../../common and ../../tviibh8m layout
|
||||
# while keeping both vendor trees inside this repository. Building in a
|
||||
# temporary staging root avoids committing IAR Obj/BrowseInfo/List products.
|
||||
$temporaryParent = Join-Path $resolvedRepository '.codex_tmp'
|
||||
New-Item -ItemType Directory -Path $temporaryParent -Force | Out-Null
|
||||
$stagingRoot = Join-Path $temporaryParent (
|
||||
'seat-firmware-build-' + [guid]::NewGuid().ToString('N')
|
||||
)
|
||||
$stagingRootFull = [System.IO.Path]::GetFullPath($stagingRoot)
|
||||
$temporaryParentFull = [System.IO.Path]::GetFullPath($temporaryParent)
|
||||
if (-not $stagingRootFull.StartsWith(
|
||||
$temporaryParentFull + [System.IO.Path]::DirectorySeparatorChar,
|
||||
[System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "Firmware staging directory escaped repository temporary root: $stagingRootFull"
|
||||
}
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $stagingRootFull | Out-Null
|
||||
$stagingProjectRoot = Join-Path $stagingRootFull 'Seat_Controller_demo'
|
||||
Copy-Item -LiteralPath $repositoryFirmware -Destination $stagingProjectRoot -Recurse
|
||||
New-Item -ItemType Junction -Path (Join-Path $stagingRootFull 'common') -Target $vendorCommon | Out-Null
|
||||
New-Item -ItemType Junction -Path (Join-Path $stagingRootFull 'tviibh8m') -Target $vendorDevice | Out-Null
|
||||
|
||||
$stagedProject = Join-Path $stagingProjectRoot 'IAR\Seat_Controller_demo.ewp'
|
||||
Invoke-IarBuild -ProjectPath $stagedProject
|
||||
|
||||
$stagedExe = Join-Path $stagingProjectRoot "IAR\$Configuration\Exe"
|
||||
$repositoryExe = Join-Path $repositoryFirmware "IAR\$Configuration\Exe"
|
||||
New-Item -ItemType Directory -Path $repositoryExe -Force | Out-Null
|
||||
foreach ($artifact in @('Seat_Controller_demo.hex', 'Seat_Controller_demo.out')) {
|
||||
$sourceArtifact = Join-Path $stagedExe $artifact
|
||||
if (-not (Test-Path -LiteralPath $sourceArtifact -PathType Leaf)) {
|
||||
throw "IAR build did not produce $sourceArtifact"
|
||||
}
|
||||
Invoke-IarBuild -ProjectName $projectName -ProjectPath $project
|
||||
$image = Join-Path $resolvedSdk "$projectName\IAR\$Configuration\Exe\$projectName.hex"
|
||||
Write-ImageSummary -ProjectName $projectName -ImagePath $image
|
||||
continue
|
||||
Copy-Item -LiteralPath $sourceArtifact -Destination (
|
||||
Join-Path $repositoryExe $artifact
|
||||
) -Force
|
||||
}
|
||||
|
||||
$repositoryFirmware = Join-Path $resolvedRepository 'firmware\t2g\Seat_Controller_demo'
|
||||
$repositoryProject = Join-Path $repositoryFirmware 'IAR\Seat_Controller_demo.ewp'
|
||||
if (-not (Test-Path -LiteralPath $repositoryProject -PathType Leaf)) {
|
||||
throw "Repository IAR project not found: $repositoryProject"
|
||||
}
|
||||
|
||||
# The IAR project intentionally keeps the vendor-library relative layout.
|
||||
# Stage the repository-owned project beside junctions to the external SDK so
|
||||
# common/ and tviibh8m/ remain vendor dependencies rather than copied source.
|
||||
$temporaryParent = Join-Path $resolvedRepository '.codex_tmp'
|
||||
New-Item -ItemType Directory -Path $temporaryParent -Force | Out-Null
|
||||
$stagingRoot = Join-Path $temporaryParent ("seat-firmware-build-" + [guid]::NewGuid().ToString('N'))
|
||||
$stagingRootFull = [System.IO.Path]::GetFullPath($stagingRoot)
|
||||
$temporaryParentFull = [System.IO.Path]::GetFullPath($temporaryParent)
|
||||
if (-not $stagingRootFull.StartsWith(
|
||||
$temporaryParentFull + [System.IO.Path]::DirectorySeparatorChar,
|
||||
[System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "Firmware staging directory escaped repository temporary root: $stagingRootFull"
|
||||
}
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $stagingRootFull | Out-Null
|
||||
$stagingProjectRoot = Join-Path $stagingRootFull 'Seat_Controller_demo'
|
||||
Copy-Item -LiteralPath $repositoryFirmware -Destination $stagingProjectRoot -Recurse
|
||||
New-Item -ItemType Junction -Path (Join-Path $stagingRootFull 'common') -Target (Join-Path $resolvedSdk 'common') | Out-Null
|
||||
New-Item -ItemType Junction -Path (Join-Path $stagingRootFull 'tviibh8m') -Target (Join-Path $resolvedSdk 'tviibh8m') | Out-Null
|
||||
|
||||
$stagedProject = Join-Path $stagingProjectRoot 'IAR\Seat_Controller_demo.ewp'
|
||||
Invoke-IarBuild -ProjectName $projectName -ProjectPath $stagedProject
|
||||
|
||||
$stagedExe = Join-Path $stagingProjectRoot "IAR\$Configuration\Exe"
|
||||
$repositoryExe = Join-Path $repositoryFirmware "IAR\$Configuration\Exe"
|
||||
New-Item -ItemType Directory -Path $repositoryExe -Force | Out-Null
|
||||
foreach ($artifact in @('Seat_Controller_demo.hex', 'Seat_Controller_demo.out')) {
|
||||
$sourceArtifact = Join-Path $stagedExe $artifact
|
||||
if (-not (Test-Path -LiteralPath $sourceArtifact -PathType Leaf)) {
|
||||
throw "IAR build did not produce $sourceArtifact"
|
||||
}
|
||||
Copy-Item -LiteralPath $sourceArtifact -Destination (Join-Path $repositoryExe $artifact) -Force
|
||||
}
|
||||
Write-ImageSummary -ProjectName $projectName -ImagePath (Join-Path $repositoryExe 'Seat_Controller_demo.hex')
|
||||
}
|
||||
finally {
|
||||
if (Test-Path -LiteralPath $stagingRootFull) {
|
||||
foreach ($dependencyLink in @('common', 'tviibh8m')) {
|
||||
$linkPath = Join-Path $stagingRootFull $dependencyLink
|
||||
if (Test-Path -LiteralPath $linkPath) {
|
||||
$link = Get-Item -LiteralPath $linkPath -Force
|
||||
if (($link.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -eq 0) {
|
||||
throw "Refusing to remove non-junction dependency path: $linkPath"
|
||||
}
|
||||
[System.IO.Directory]::Delete($linkPath, $false)
|
||||
Write-ImageSummary -ImagePath (
|
||||
Join-Path $repositoryExe 'Seat_Controller_demo.hex'
|
||||
)
|
||||
}
|
||||
finally {
|
||||
if (Test-Path -LiteralPath $stagingRootFull) {
|
||||
foreach ($dependencyLink in @('common', 'tviibh8m')) {
|
||||
$linkPath = Join-Path $stagingRootFull $dependencyLink
|
||||
if (Test-Path -LiteralPath $linkPath) {
|
||||
$link = Get-Item -LiteralPath $linkPath -Force
|
||||
if (($link.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -eq 0) {
|
||||
throw "Refusing to remove non-junction dependency path: $linkPath"
|
||||
}
|
||||
[System.IO.Directory]::Delete($linkPath, $false)
|
||||
}
|
||||
$remainingLinks = @(
|
||||
Get-ChildItem -LiteralPath $stagingRootFull -Recurse -Force -Attributes ReparsePoint -ErrorAction SilentlyContinue
|
||||
)
|
||||
if ($remainingLinks.Count -ne 0) {
|
||||
throw "Refusing recursive cleanup because a reparse point remains in $stagingRootFull"
|
||||
}
|
||||
[System.IO.Directory]::Delete($stagingRootFull, $true)
|
||||
}
|
||||
$remainingLinks = @(
|
||||
Get-ChildItem -LiteralPath $stagingRootFull -Recurse -Force -Attributes ReparsePoint -ErrorAction SilentlyContinue
|
||||
)
|
||||
if ($remainingLinks.Count -ne 0) {
|
||||
throw "Refusing recursive cleanup because a reparse point remains in $stagingRootFull"
|
||||
}
|
||||
[System.IO.Directory]::Delete($stagingRootFull, $true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user