Repository navigation
Fail flash backup on data or checksum write errors - #85
Open
markmounteer wants to merge 2 commits into
Open
markmounteer wants to merge 2 commits into
markmounteer wants to merge 2 commits into
Conversation
flash_backup ignored fwrite, fclose and fprintf results, hashed pages whether or not they were saved, printed success and returned 0. A backup now succeeds only when the data file is fully written and closed and the sha256 sidecar is fully written and closed. On any failure reading stops, the data file and any sidecar are removed so no partial artifact looks complete, and -1 reaches the CLI exit status. Adds an offline regression with memory-backed page reads and ld --wrap stdio failure injection.
markmounteer
marked this pull request as ready for review
October 28, 2026 02:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fail flash backup on data or checksum write errors
Stacked on draft PR84 (
2c6a2f46ec4ffd2be0dc63a28f8cc34fe730179f), whose Efinix reload-payload repair is preserved unchanged. This PR adds one commit on top; review the top commit for this change.Defect
flash_backupin eeprom.c ignored the results of the data-filefwriteandfcloseand of the checksum-filefprintfandfclose, then printed success and returned 0. The SHA256 was updated from the incoming page buffers whether or not the bytes were saved, so the.sha256sidecar could describe a complete image that was never successfully written. A failed or partial backup could therefore look like a trustworthy recovery artifact.Fix (only
flash_backupin eeprom.c)fwritemust returnPAGE_SIZE. On a short or zero write, reading stops immediately (no further page reads), the partial data file is removed, no checksum is created, no success is announced, and -1 is returned.SHA256_Updateruns only after that page was fully written, so the sidecar can only describe saved bytes.fclose(delayed flush error) removes the data file and returns -1 with no checksum and no success message.fprintfandfclosefailures (and the existingfopenfailure) remove the sidecar and the data file and return -1.Partial-file policy, documented in a comment above the function: a backup is successful only when both files are fully written and closed; on any failure both artifacts are removed best-effort so no partial artifact can be mistaken for a completed backup. The -1 result reaches the process exit status because mesaflash.c assigns the
anyio_dev_backup_flashresult toretand returns it frommain(that propagation already existed and is unchanged).No EEPROM programming, erase or header logic, short-final-page programming semantics, reload behavior, global build options, or the shared Makefile were changed.
Tests (new files only)
tests/test_flash_backup.clinks the real eeprom.c with a deterministic memory-backedread_pagestub and GNU ld--wrapinjection forfopen/fwrite/fclose/fprintf. No physical transport is linked or called. Run it with the dedicated makefile (the shared Makefile is untouched):Seven bounded cases: exact-length success with verified bytes and sidecar digest, short first-page write, zero first-page write, later-page (10th) write failure, delayed data-close failure, checksum-write failure, and checksum-close failure. Failure cases assert return -1 (the caller-visible failure), stopped reads where applicable, and that neither artifact remains.
Validation (Azure ARM64, vm-cnc-build3-cc, GCC 13.3.0, Ubuntu 24.04)
2c6a2f46plus the identical new fixture: 7 cases, 21 failed assertions. The success case passes; all six failure cases return 0, keep reading, leave both files, and publish the same sidecar digest as the success case.makebuild passes with-Wall -Wextra -Werror; backup regression 7 cases, 0 failed assertions; existing reload regression (make check) 50 cases, 0 failed assertions.6ebc9111ca4fffa0900cbfa1ed23099675252d73988fdb1444501e0153e2f127. It needs a new source/binary pin before any installation use.No board, Pi, flashing, reload, deployment, or merge was performed. This proves backup failure handling in software only; it proves no current backup or physical recovery.