Skip to content

Commit 452cdf5

Browse files
committed
fix: handle variable stage2.bin file sizes across firmware versions
- Add STAGE2_SIZES mapping for firmware versions with larger stage2.bin files - Update validate_file_size function to accept firmware version parameter - Firmware 904, 950, 951 have 6034-byte stage2.bin files (vs 2705 for others) - All stage1.bin files remain 500 bytes consistently This resolves the file size validation failures for firmware versions 904, 950, and 951.
1 parent bb37507 commit 452cdf5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/firmware-downloader.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ declare -A FIRMWARE_MAP=(
3232
# Expected file sizes (in bytes) for validation
3333
declare -A EXPECTED_SIZES=(
3434
["stage1.bin"]=500
35-
["stage2.bin"]=2705
35+
["stage2.bin"]=2705 # Default size, will be adjusted per firmware version
36+
)
37+
38+
# Firmware-specific stage2.bin sizes (some versions have larger stage2 files)
39+
declare -A STAGE2_SIZES=(
40+
["904"]=6034
41+
["950"]=6034
42+
["951"]=6034
43+
# All other versions use the default 2705 bytes
3644
)
3745

3846
# Colors for output
@@ -74,6 +82,7 @@ generate_url() {
7482
validate_file_size() {
7583
local file_path="$1"
7684
local binary_name="$2"
85+
local firmware_version="${3:-}"
7786

7887
if [[ ! -f "$file_path" ]]; then
7988
log_error "File does not exist: $file_path"
@@ -82,7 +91,12 @@ validate_file_size() {
8291

8392
local actual_size
8493
actual_size=$(stat -c%s "$file_path" 2>/dev/null || stat -f%z "$file_path" 2>/dev/null)
94+
95+
# Get expected size based on firmware version and binary type
8596
local expected_size="${EXPECTED_SIZES[$binary_name]}"
97+
if [[ "$binary_name" == "stage2.bin" && -n "$firmware_version" && -n "${STAGE2_SIZES[$firmware_version]:-}" ]]; then
98+
expected_size="${STAGE2_SIZES[$firmware_version]}"
99+
fi
86100

87101
# Allow some tolerance for file size variations (±10%)
88102
local min_size=$((expected_size * 90 / 100))
@@ -157,7 +171,7 @@ download_binary() {
157171
fi
158172

159173
# Validate downloaded file
160-
if validate_file_size "$output_path" "$binary_name"; then
174+
if validate_file_size "$output_path" "$binary_name" "$firmware_version"; then
161175
local checksum
162176
checksum=$(calculate_checksum "$output_path")
163177
log_success "Downloaded and validated: $binary_name (SHA256: $checksum)"
@@ -229,7 +243,7 @@ verify_firmware_version() {
229243
return 1
230244
fi
231245

232-
if validate_file_size "$stage1_path" "stage1.bin" && validate_file_size "$stage2_path" "stage2.bin"; then
246+
if validate_file_size "$stage1_path" "stage1.bin" "$firmware_version" && validate_file_size "$stage2_path" "stage2.bin" "$firmware_version"; then
233247
log_success "Firmware $firmware_name ($firmware_version) verification passed"
234248
return 0
235249
else

0 commit comments

Comments
 (0)