|
27 | 27 | ) |
28 | 28 |
|
29 | 29 |
|
| 30 | +def get_firmware_metadata(fw_path: str) -> dict: |
| 31 | + """Firmware-level metadata for display in the UI (not per-segment) - |
| 32 | + version string, segment count, checksum validity, total image size, and |
| 33 | + the AudioLibraryHeader's raw fw_version field.""" |
| 34 | + fw = ISD9160Firmware.from_filepath(fw_path) |
| 35 | + return { |
| 36 | + "version": fw.version, |
| 37 | + "segmentCount": fw.segment_count, |
| 38 | + "checksumValid": fw.is_checksum_valid(), |
| 39 | + "sizeBytes": len(fw.data), |
| 40 | + "fwVersionRaw": fw.audiolib_header.fw_version, |
| 41 | + } |
| 42 | + |
| 43 | + |
30 | 44 | def extract_segments(fw_path: str, output_dir: str) -> list[dict]: |
31 | 45 | """Extract every segment in the firmware at fw_path to WAV+raw files |
32 | 46 | under output_dir (via ISD9160Firmware.extract_all). Returns per-segment |
@@ -80,10 +94,10 @@ def patch_firmware(fw_path: str, segment_paths: dict[int, str], version_str: str |
80 | 94 | NOTE: writes output_path itself rather than returning ISD9160Firmware.data |
81 | 95 | directly, and deliberately does not return the ISD9160Firmware object |
82 | 96 | patch_with_new_segments() produces - its `.version`/`.seg_entries` stay |
83 | | - stale after patching (see external/DuRFUnitI2C/tests/test_vpe.py's |
84 | | - documented gotcha), only `.data` is trustworthy. Read output_path back |
85 | | - via a fresh ISD9160Firmware.from_filepath() call if you need to inspect |
86 | | - the result afterwards. |
| 97 | + stale after patching (see this project's tests/test_vpe.py's documented |
| 98 | + gotcha), only `.data` is trustworthy. Read output_path back via a fresh |
| 99 | + ISD9160Firmware.from_filepath() call if you need to inspect the result |
| 100 | + afterwards (get_firmware_metadata() above does exactly that). |
87 | 101 | """ |
88 | 102 | fw = ISD9160Firmware.from_filepath(fw_path) |
89 | 103 | new_segments = fw.get_all_segments() |
|
0 commit comments