Skip to content

directory: fix entry offset address mode handling and preserve NO_SIZE sentinel#83

Merged
cwerling merged 3 commits intomasterfrom
dev
Apr 14, 2026
Merged

directory: fix entry offset address mode handling and preserve NO_SIZE sentinel#83
cwerling merged 3 commits intomasterfrom
dev

Conversation

@cwerling
Copy link
Copy Markdown
Member

@cwerling cwerling commented Apr 14, 2026

Summary

  • Fix update_entry_fields in directory.py to properly convert ROM buffer offsets back to the value expected by a directory entry, respecting the entry's address mode. Previously the raw buffer offset was written directly, which produced wrong values for x86-physical (mode 0) and relative (mode 2/3) entries.
  • Preserve NO_SIZE_ENTRY_TYPES sentinel sizes (e.g. 0xFFFFFFFF for SOFT_FUSE_CHAIN) during updates. The old code in file.py unconditionally zeroed entry.size for these types at parse time, destroying the sentinel; that logic is removed and update_entry_fields now skips overwriting the size for these types instead.

Address mode handling details

Mode Encoding
0 (x86 physical) Upper bits preserved, lower bits replaced using rom.addr_mask
1 (flash offset) Written as-is
2 / 3 (relative) Stored as offset - directory.buffer_offset

🤖 Generated with Claude Code

cwerling and others added 2 commits April 13, 2026 15:12
…y_fields

Implement the address-mode-aware offset conversion when writing back to
a directory entry. The conversion is the inverse of file_offset() in
entry.py: mode 0 (x86 physical) preserves upper bits and replaces only
the ROM-masked lower bits; mode 1 (flash offset) stores the value
directly; modes 2/3 (relative to directory header/slot) subtract the
directory's buffer offset.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Type 0xb (SOFT_FUSE_CHAIN_01) stores 0xFFFFFFFF as a sentinel in its
size field. from_entry() was zeroing it out via entry.size = 0, but
since entry is a NestedBuffer overlaying the ROM bytes directly, this
permanently destroyed the sentinel at parse time.

The zero-write is unnecessary: file_offset() for type 0xb uses a
special-cased path that ignores entry.size, and File.__init__ takes the
NO_SIZE_ENTRY_TYPES branch (using entry.ENTRY_SIZE) before ever reaching
the bounds check that reads entry.size.

Fix: remove the zero-write so the sentinel is preserved throughout the
object's lifetime, and guard update_entry_fields so a move_buffer call
can never accidentally overwrite it either.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 14,965
Stderr Lines 156
Total Lines 15,121
Error Ratio 1.03%

PSPTool python library metrics

Status Count Percentage
✓ Successful 68 100.0%
✗ Failed 0 0.0%
Total 68 100%

All files parsed successfully!

Comment thread psptool/directory.py Outdated
@cwerling cwerling merged commit d8f676a into master Apr 14, 2026
8 checks passed
@cwerling cwerling deleted the dev branch April 14, 2026 07:47
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