| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- Set-StrictMode -Version Latest
- $ErrorActionPreference = "Stop"
- $root = Split-Path -Parent $MyInvocation.MyCommand.Path
- $required = @(
- "fw.bit",
- "package-info.json",
- "evidence\td-primary-receipt.json",
- "evidence\td-confirmation-receipt.json",
- "evidence\validation-summary.json",
- "evidence\package-selftest-result.json",
- "config\host-contract.json",
- "schemas\host-contract.schema.json",
- "SEND_HEX.ps1",
- "INITIALIZE_DISABLE.ps1",
- "PROGRAM_SRAM.ps1",
- "run.ps1",
- "bootstrap.ps1",
- "README.zh-CN.md"
- )
- foreach ($relative in $required) {
- if (-not (Test-Path -LiteralPath (Join-Path $root $relative) -PathType Leaf)) {
- throw "required file missing: $relative"
- }
- }
- function Get-BoundSha256([string]$Path) {
- return (Get-FileHash -Algorithm SHA256 -LiteralPath $Path).Hash.ToLowerInvariant()
- }
- $info = Get-Content -LiteralPath (Join-Path $root "package-info.json") -Raw -Encoding UTF8 | ConvertFrom-Json
- if ([string]$info.schema -ne "prod2u-p4-normal-v3-folder-package-info-v3") {
- throw "package-info schema mismatch"
- }
- if ([string]$info.profile -ne "prod2u-p4-normal-actuator-binary921-v3") {
- throw "package profile mismatch"
- }
- $commit = [string]$info.commit
- if ($commit -notmatch '^[0-9a-f]{40}$') { throw "package commit is invalid" }
- $firmware = Join-Path $root "fw.bit"
- $bitstreamSha256 = Get-BoundSha256 $firmware
- if ([string]$info.bitstream_sha256 -ne $bitstreamSha256) {
- throw "bitstream hash mismatch"
- }
- $expectedName = "prod2u-p4-normal-$commit-$($bitstreamSha256.Substring(0, 16))"
- $currentName = Split-Path -Leaf $root
- if ($currentName -ne $expectedName -and -not $currentName.StartsWith(".prod2u-p4-normal-stage-")) {
- throw "package folder name mismatch"
- }
- if ((Split-Path -Leaf (Split-Path -Parent $root)) -ne $commit) {
- throw "package commit parent folder mismatch"
- }
- $primaryReceipt = Join-Path $root "evidence\td-primary-receipt.json"
- $confirmationReceipt = Join-Path $root "evidence\td-confirmation-receipt.json"
- $validationSummary = Join-Path $root "evidence\validation-summary.json"
- $selftestResult = Join-Path $root "evidence\package-selftest-result.json"
- if ([string]$info.td_receipt_sha256 -ne (Get-BoundSha256 $primaryReceipt)) {
- throw "primary TD receipt hash mismatch"
- }
- if ([string]$info.confirmation_td_receipt_sha256 -ne (Get-BoundSha256 $confirmationReceipt)) {
- throw "confirmation TD receipt hash mismatch"
- }
- if ([string]$info.validation_summary_sha256 -ne (Get-BoundSha256 $validationSummary)) {
- throw "validation summary hash mismatch"
- }
- if ([string]$info.package_selftest_result_sha256 -ne (Get-BoundSha256 $selftestResult)) {
- throw "package selftest result hash mismatch"
- }
- $primary = Get-Content -LiteralPath $primaryReceipt -Raw -Encoding UTF8 | ConvertFrom-Json
- $confirmation = Get-Content -LiteralPath $confirmationReceipt -Raw -Encoding UTF8 | ConvertFrom-Json
- if ([string]$primary.commit -ne $commit) { throw "primary TD receipt commit mismatch" }
- if ([string]$primary.bitstream_sha256 -ne $bitstreamSha256) {
- throw "primary TD receipt bitstream mismatch"
- }
- if ([string]$confirmation.commit -ne $commit) {
- throw "confirmation TD receipt commit mismatch"
- }
- if ([string]$info.synthesis_input_hash -ne [string]$primary.synthesis_input_hash) {
- throw "primary synthesis input hash mismatch"
- }
- if ([string]$info.confirmation_synthesis_input_hash -ne [string]$confirmation.synthesis_input_hash) {
- throw "confirmation synthesis input hash mismatch"
- }
- if ([string]$info.confirmation_bitstream_sha256 -ne [string]$confirmation.bitstream_sha256) {
- throw "confirmation bitstream hash binding mismatch"
- }
- $validation = Get-Content -LiteralPath $validationSummary -Raw -Encoding UTF8 | ConvertFrom-Json
- if ([string]$validation.schema -ne "prod2u-p4-normal-v3-validation-summary-v1") {
- throw "validation summary schema mismatch"
- }
- if ([string]$validation.commit -ne $commit -or [string]$validation.bitstream_sha256 -ne $bitstreamSha256) {
- throw "validation summary binding mismatch"
- }
- foreach ($property in @($validation.layers.PSObject.Properties)) {
- if ([string]$property.Value.status -notin @("pass", "fail", "not_run")) {
- throw "validation layer status is invalid: $($property.Name)"
- }
- }
- $expectedFiles = @{}
- foreach ($property in @($info.file_sha256.PSObject.Properties)) {
- $expectedFiles[[string]$property.Name] = [string]$property.Value
- }
- $observedFiles = @{}
- Get-ChildItem -LiteralPath $root -Recurse -File | ForEach-Object {
- $relative = $_.FullName.Substring($root.Length).TrimStart('\').Replace('\', '/')
- if ($relative -notin @("package-info.json", "evidence/package-selftest-result.json")) {
- $observedFiles[$relative] = Get-BoundSha256 $_.FullName
- }
- }
- if ($expectedFiles.Count -ne $observedFiles.Count) { throw "package file hash map is not closed" }
- foreach ($relative in $observedFiles.Keys) {
- if (-not $expectedFiles.ContainsKey($relative)) { throw "package file is not bound: $relative" }
- if ($expectedFiles[$relative] -ne $observedFiles[$relative]) {
- throw "package file hash mismatch: $relative"
- }
- }
- [ordered]@{
- schema = "prod2u-p4-normal-v3-folder-selftest-v3"
- status = "pass"
- commit = $commit
- bitstream_sha256 = $bitstreamSha256
- validation_status = if (@($validation.layers.PSObject.Properties | Where-Object { $_.Value.status -eq "fail" }).Count -eq 0) { "pass" } else { "fail" }
- } | ConvertTo-Json -Compress
|