add local-sign variant to baosign.ps1

This commit is contained in:
bunnie 2026-04-13 00:04:14 +08:00
parent 0c23c5e5bc
commit aaad119bcc

View file

@ -16,7 +16,10 @@ param(
[string]$CredentialFile = "beta.json", [string]$CredentialFile = "beta.json",
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string]$Target = "bunnie@10.0.245.50:code/csp-tool/" [string]$Target = "bunnie@10.0.245.50:code/csp-tool/",
[Parameter(Mandatory = $false)]
[switch]$Local
) )
# Configuration # Configuration
@ -26,47 +29,47 @@ $SIGNING_DIR = ".\signing\fido-signer"
# Define configurations and their associated images with function codes # Define configurations and their associated images with function codes
# Modify these mappings according to your actual image names and function codes # Modify these mappings according to your actual image names and function codes
$configurations = @{ $configurations = @{
"bootloader" = @( "bootloader" = @(
@{ Image = "bao1x-boot0.img"; FunctionCode = "boot0" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }, @{ Image = "bao1x-boot0.img"; FunctionCode = "boot0" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" },
@{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }, @{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" },
@{ Image = "bao1x-alt-boot1.img"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } @{ Image = "bao1x-alt-boot1.img"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }
) )
"baremetal" = @( "baremetal" = @(
@{ Image = "baremetal.img"; FunctionCode = "baremetal" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } @{ Image = "baremetal.img"; FunctionCode = "baremetal" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }
) )
"dabao" = @( "dabao" = @(
@{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "apps.img"; FunctionCode = "app" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "apps.img"; FunctionCode = "app" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"baosec" = @( "baosec" = @(
@{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"baosec-lite" = @( "baosec-lite" = @(
@{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
@{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }, @{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" },
@{ Image = "bao1x-alt-boot1.img"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } @{ Image = "bao1x-alt-boot1.img"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }
) )
"kernel" = @( "kernel" = @(
@{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"loader" = @( "loader" = @(
@{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"swap" = @( "swap" = @(
@{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"apps" = @( "apps" = @(
@{ Image = "apps.img"; FunctionCode = "app" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "apps.img"; FunctionCode = "app" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" }
) )
"boot1" = @( "boot1" = @(
@{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } @{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }
) )
"alt-boot1" = @( "alt-boot1" = @(
@{ Image = "bao1x-alt-boot1.img"; FunctionCode = "baremetal" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } @{ Image = "bao1x-alt-boot1.img"; FunctionCode = "baremetal" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }
) )
} }
@ -193,6 +196,7 @@ foreach ($imageSpec in $selectedConfig) {
Write-Status "Signing image..." Write-Status "Signing image..."
Write-Status "Command: $($cargoCmd -join ' ')" Write-Status "Command: $($cargoCmd -join ' ')"
Write-Status "Target SSH: $(if ($Local) { '(skipped, --Local mode)' } else { $TARGET })"
# Execute the signing command # Execute the signing command
& cargo run -- --credential-file "..\credentials\$CredentialFile" --file "..\..\$imagePath" --function-code $functionCode 2>&1 | Tee-Object -Variable result & cargo run -- --credential-file "..\credentials\$CredentialFile" --file "..\..\$imagePath" --function-code $functionCode 2>&1 | Tee-Object -Variable result
@ -218,20 +222,26 @@ foreach ($imageSpec in $selectedConfig) {
} }
# Copy files to SSH target # Copy files to SSH target
Write-Status "Copying files to remote host..." if ($Local) {
Write-Warning "Skipping remote copy (--Local flag set)"
$imgCopySuccess = Copy-ToSSH -LocalPath $imagePath -RemoteTarget $TARGET
$uf2CopySuccess = Copy-ToSSH -LocalPath $uf2Path -RemoteTarget $TARGET
if ($imgCopySuccess -and $uf2CopySuccess) {
Write-Success "Completed processing: $imageName" Write-Success "Completed processing: $imageName"
$successfulImages++ $successfulImages++
} }
else { else {
Write-Warning "Partial completion for: $imageName (signing OK, copy failed)" Write-Status "Copying files to remote host..."
$failedImages++
}
$imgCopySuccess = Copy-ToSSH -LocalPath $imagePath -RemoteTarget $TARGET
$uf2CopySuccess = Copy-ToSSH -LocalPath $uf2Path -RemoteTarget $TARGET
if ($imgCopySuccess -and $uf2CopySuccess) {
Write-Success "Completed processing: $imageName"
$successfulImages++
}
else {
Write-Warning "Partial completion for: $imageName (signing OK, copy failed)"
$failedImages++
}
}
} }
else { else {
Write-Error "Failed to sign image: $imageName" Write-Error "Failed to sign image: $imageName"