From 4561779b5810bdedd126e3bbc14a5cbb06b417ac Mon Sep 17 00:00:00 2001 From: Entrpi Date: Wed, 28 Oct 2026 04:04:35 +1100 Subject: [PATCH] fix(artifacts): read ESP flash layouts as the bootloader does Read the partition table as bootloader_utility_load_partition_table does: the last factory, otadata and same-subtype OTA declaration wins, and a limitation names repeats. Plan each otadata record within its partition and the dump. An otadata partition smaller than two sectors selects none, the bootloader's INVALID_INDEX; a record the dump lacks leaves the selection unknown while the other record stays reported. The fallbacks follow the bootloader's indexes: ota_0-fallback and factory-fallback name no partition when the table declares none, and the assumptions add GPIO holds and deep-sleep wake. Refuse a dump whose bootloader contradicts its origin before the default table offset is tried, whether flash_offset was omitted or given, and keep the ESP image reader's ESP8266 refusal. A table never lies inside the located bootloader image, so single app images are no longer scanned. An explicit esp-flash-image selection is decided before other container signatures, and the native commands' --target-format no longer takes it. Say when no bootloader confirms the default origin. Exempt the primary bootloader and partition_table entries of ESP-IDF 5.3 from placement limits, report every region inside a longer one, and name partitions by index when labels repeat ignoring case. Keep an undecodable label's bytes in label_hex and compare them. Word undescribed ranges as starting at a byte that is not erased, and treat a short erased region as erased. Add an MCP compare_artifacts test for partition declarations, reader identity and close tests, scan edge cases, the 0x2000 ROM offset and a literal otatool CRC. --- .../references/native-and-artifacts.md | 3 +- docs/esp-flash-image.md | 161 +++++++++++------ .../EspFlashImageArtifactReader.test.ts | 88 +++++++++ src/artifacts/EspFlashImageArtifactReader.ts | 31 ++-- src/artifacts/EspFlashRegionReads.ts | 3 +- src/artifacts/inventory/classify.ts | 52 +++--- src/cli/options.ts | 6 +- src/domain/artifactFormatMetadata.ts | 48 +++-- src/domain/firmware/espFlashBootloader.ts | 65 +++++-- src/domain/firmware/espFlashLayout.test.ts | 123 ++++++++++++- src/domain/firmware/espFlashLayout.ts | 170 ++++++++++++------ src/domain/firmware/espFlashLocation.test.ts | 169 ++++++++++++++--- src/domain/firmware/espFlashLocation.ts | 116 +++++++----- src/domain/firmware/espFlashPlan.test.ts | 122 ++++++++++++- src/domain/firmware/espImageStructures.ts | 11 +- src/domain/firmware/espOtaData.ts | 96 +++++----- src/domain/firmware/espPartitionTable.ts | 114 +++++++++--- .../artifactComparisonEspFlash.test.ts | 124 +++++++++++++ .../boundary/filesystem/binaryTarget.test.ts | 16 ++ 19 files changed, 1188 insertions(+), 330 deletions(-) create mode 100644 tests/acceptance/artifactComparisonEspFlash.test.ts diff --git a/.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md b/.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md index 2b67df630d..d4e62ab5b0 100644 --- a/.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md +++ b/.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md @@ -679,7 +679,8 @@ cannot be opened as raw-binary. See A whole-flash dump opens as `esp-flash-image`. `root_format_metadata` holds `partition_table` (its `method`: `default`, `caller` or a derived `scan`), `bootloader` and `apps` ESP image facts, `otadata` with a derived -`selected` slot and its `assumptions`, and `partitions_outside_dump`; +`selected` slot (null when a record is missing) and its `assumptions`, and +`partitions_outside_dump`; `running_partition` is always `unknown`. Partition rows (`partitions/