Устранить пересечение образа логгера с параметрами EEPROM и проверять размер BIN
This commit is contained in:
36
check_firmware.ps1
Normal file
36
check_firmware.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Path,
|
||||
[string]$PublishPath
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
# Load_params/Save_params use word address 0x3FFF-(ANSWER_LEN+1).
|
||||
# Seeprom_write converts that address to wire bytes (WORD_LEN=2).
|
||||
$header = Get-Content -Raw -LiteralPath "$PSScriptRoot/Source/Internal/Include/message.h"
|
||||
if ($header -notmatch '(?m)^#define\s+ANSWER_LEN\s+(0x[0-9a-fA-F]+|[0-9]+)') {
|
||||
throw 'Cannot determine the EEPROM parameter reservation from ANSWER_LEN'
|
||||
}
|
||||
$registerCount = if ($Matches[1].StartsWith('0x')) {
|
||||
[Convert]::ToInt32($Matches[1].Substring(2), 16)
|
||||
} else { [int]$Matches[1] }
|
||||
$limit = (0x3FFF - ($registerCount + 1)) * 2
|
||||
$bytes = [IO.File]::ReadAllBytes((Resolve-Path -LiteralPath $Path).Path)
|
||||
if ($bytes.Length -gt $limit) {
|
||||
throw "Firmware size $($bytes.Length) exceeds EEPROM firmware area $limit bytes; overlaps saved parameters by $($bytes.Length - $limit) bytes."
|
||||
}
|
||||
if ($bytes.Length -lt 30 -or [BitConverter]::ToUInt16($bytes, 0) -ne 0x08AA) {
|
||||
throw 'Expected a C2000 SCI8 boot image'
|
||||
}
|
||||
$offset = 22
|
||||
$blocks = 0
|
||||
while ($true) {
|
||||
if ($offset + 2 -gt $bytes.Length) { throw 'Missing boot table terminator' }
|
||||
$words = [BitConverter]::ToUInt16($bytes, $offset)
|
||||
$offset += 2
|
||||
if (!$words) { break }
|
||||
$offset += 4 + 2 * $words
|
||||
if ($offset -gt $bytes.Length) { throw 'Truncated boot table block' }
|
||||
$blocks++
|
||||
}
|
||||
if (!$blocks -or $offset -ne $bytes.Length) { throw 'Invalid boot table length' }
|
||||
if ($PublishPath) { Move-Item -LiteralPath $Path -Destination $PublishPath -Force }
|
||||
Write-Output "Verified SCI8 image: $($bytes.Length) bytes, $blocks blocks, $($limit - $bytes.Length) bytes before saved parameters."
|
||||
Reference in New Issue
Block a user