Fix NVM legacy migration code review issues #392
Merged
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.
Summary
Fixes two code review issues in NVM legacy migration logic with minimal changes:
Changes
Fix 1: Migration Preserves Legacy Config
File:
firmware/src/nvm/nvm.c(lines 403-426)Added restore function calls in
nvm_wl_migrate_legacy_config()before callingnvm_save_config():frames_restore_config()ADC_restore_config()motor_restore_config()sensors_restore_config()observers_restore_config()controller_restore_config()CAN_restore_config()traj_planner_restore_config()This ensures that when
nvm_save_config()reads from getters, it gets the legacy config data instead of current runtime state, preserving user settings during migration.Fix 2: Robust Legacy Detection
File:
firmware/src/nvm/nvm.c(lines 373-399)Replaced single
magic_markercheck withnvm_wl_validate_metadata()innvm_wl_detect_legacy_config(). This validates all metadata fields (magic_marker, metadata_version, data_size, and metadata_checksum) instead of just one field, preventing misclassification of corrupted configs.Implementation Details
Both fixes reuse existing, well-tested functions:
nvm_load_config()nvm_wl_validate_metadata()already used in scan and load operationsTotal lines changed: ~10 lines across 2 functions
New code added: 0 (only calls to existing functions)
Risk: Low (affects only legacy migration path)
Testing
Edge Cases Considered