Skip to content

fix(patch-hash): hash body by load address (p_paddr) + 0xFF gap fill - #3

Merged
sanchuanhehe merged 1 commit into
mainfrom
chore/release-v0.2.1
Jun 16, 2026
Merged

sanchuanhehe merged 1 commit into
mainfrom
chore/release-v0.2.1

Conversation

@sanchuanhehe

Copy link
Copy Markdown
Contributor

Why

On-target HIL of the hisi-riscv-hal driver suite failed: every test "crashed" (core ran wild to __heap_start__). Root cause traced to flashboot rejecting the freshly-flashed image — UART showed VE (verify error). tests-hil (no initialized .data) booted fine; any .data-carrying binary did not.

patch-hash flattened the boot-header body by p_vaddr and zero-filled inter-segment gaps. But flashboot verifies the body by SHA-256'ing code_area_len bytes read contiguously from flash — each section at its flash LMA (p_paddr), alignment gaps left erased (0xFF). So a segment that runs from RAM but is initialized from flash (.data: p_vaddr in SRAM, p_paddr at its flash LMA) was placed at the wrong offset and its real flash position left as fill → body hash ≠ flashboot's → VE. Latent for gap-free, all-flash binaries (vaddr == paddr).

Fix

Lay the body out by p_paddr and fill gaps with 0xFF, exactly mirroring the programmed flash image.

Verification

  • New ELF-path regression test (.data segment with p_vaddr != p_paddr + an alignment gap); existing tests only covered the gap-free bin path.
  • Real WS63 silicon: the hisi-riscv-hal on-target HIL driver suite passes 19/19 once images are patched with the fixed tool (was: every test crashed pre-fix).

🤖 Generated with Claude Code

flashboot verifies a boot-header image by SHA-256'ing code_area_len bytes
read contiguously from flash — each section at its flash LMA, alignment gaps
left erased (0xFF). patch-hash flattened the body by p_vaddr and zero-filled
gaps, so any segment that runs from RAM but is initialized from flash (e.g. a
`.data` with p_vaddr in SRAM, p_paddr at its flash LMA) was misplaced and its
real flash position left as fill — the body hash then disagreed with flashboot
and the boot ROM rejected the image ("VE", verify error). Latent for gap-free
all-flash binaries (vaddr==paddr). Now lays the body out by p_paddr and fills
gaps with 0xFF (the algorithm's empty_value), exactly mirroring the programmed
flash image. Verified on real WS63 silicon: hisi-riscv-hal HIL 19/19 pass.

Adds an ELF-path regression test (a .data segment with p_vaddr!=p_paddr plus an
alignment gap) — the existing tests only covered the gap-free bin path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sanchuanhehe
sanchuanhehe merged commit 3b4c732 into main Jun 16, 2026
1 check failed
@sanchuanhehe
sanchuanhehe deleted the chore/release-v0.2.1 branch June 16, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant