mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
* feat(firmware): inventory and extract UBI image volumes offline * docs: name ubi-volume among compared format metadata kinds The artifact comparison contract lists every format metadata kind that compare_artifacts compares. ubi-volume now carries a declaration, so the contract names it beside the other members. * fix(firmware): keep UBI LEB ranges private to the reader entries() yielded copyArtifactEntry(entry), which spreads the private volume field by reference, so a caller could rewrite volume.ranges and change the bytes the next open() read. Yield only the public entry fields, and test that a returned entry carries no volume mapping. * fix(firmware): keep LEB source ranges in ubi-volume metadata Saved Evidence now records the lnum, PEB, image offset and length of each chosen LEB, so a reassembled volume can be traced to its image bytes. The image summary keeps counts. * fix(firmware): reject smaller UBI eraseblock sizes whose LEB padding is invalid A dynamic LEB with data_size 0 and data_pad equal to a smaller candidate LEB passed the size check, so a valid aligned image was refused as ambiguous. Require data_pad below the candidate LEB, as classifyUbiPeb and the volume table alignment rule already do. * fix(ubi): refuse a UBI# file shorter than its erase-counter header recognizeUbiImage recognized any 4 to 63 byte file starting with UBI# without a CRC or version to check, so open_binary accepted it as an archive and inventory labelled it a container. It now takes the file size and refuses a file that cannot hold the 64-byte header. A short prefix read from a longer file still defers to the reader. * fix(ubi): refuse a volume whose only surviving LEB copy failed its CRC When both competing PEBs for a LEB are wear-leveling copies and both fail their data CRC, the older failed copy still won and open() served bytes that had already failed verification. Mark that LEB unverified and refuse the volume with extract refusal unverified_copy, keeping its inventory. * fix(ubi): refuse an image whose EC headers disagree instead of skipping them Eraseblock discovery and both spacing checks skipped a valid erase-counter header whose image_seq or layout differed from PEB 0, treating it as absent. Alternating sequences or a conflicting second header then measured a multiple of the real eraseblock size and read the image, so a volume became an extractable empty or header-polluted volume. Any valid header now begins an eraseblock, and classifyUbiPeb and checkUbiPebs refuse the disagreement. * fix(ubi): rule out a smaller eraseblock size whose volume table is invalid The ambiguity check declared a smaller eraseblock size equally valid from erased header positions and LEB fit alone. With 128 KiB eraseblocks, data_offset 4096 and a volume of alignment 6144, data_pad is 4096, but a 64 KiB LEB would need data_pad 0, so that size cannot describe the image and a valid image was refused. The check now also requires a volume table copy to stay valid under the smaller geometry, and runs after the table copies are read. * fix(ubi): compare the volume ID in a UBI volume declaration The compared ubi-volume declaration left out the volume ID. A volume renumbered from ID 0 to ID 1 keeps its path and reconstructed bytes, so artifact comparison reported it unchanged even though consumers that address volumes by number now see a different volume. The declaration now includes the ID, and PEB placement stays out of it. * fix(ubi): refuse a volume with no mapped LEB when PEBs are corrupt When a volume's only data PEB had a bad EC or VID header CRC, classification dropped its mapping and reassembly read the absence of surviving headers as an empty volume: a static volume got used_ebs 0, a dynamic one zero LEBs, and both were served as extractable empty files. A corrupt PEB may have held that data, so a volume with no mapped LEB in an image with corrupt PEBs is now inventoried but refused as lost_lebs, with used_ebs null and a named limitation. An image without corrupt PEBs still reads an unmapped volume as empty. * fix(ubi): accept EC headers in static LEB data no smaller eraseblock holds A static volume holding a nested UBI image with the same EC layout puts valid EC headers on a smaller grid inside its payload. With 128 KiB eraseblocks, data_offset 4096 and full 126976-byte static LEBs, the spacing check and the smaller-grid scan refused such a header as a geometry conflict, though ubiSmallerPebSizeHoldsLebs already rules out every smaller size those LEBs would have to fit. Both scans now run their verdict after the PEBs and volume table copies are read, and set aside a header at a position only ruled-out sizes would begin at. A spacing conflict still takes precedence over later failures, and a header where a smaller size stays possible, as under dynamic LEBs, is still refused. * Address review feedback * Address review feedback * Address review feedback * Address review feedback * fix(ubi-image): carry parser limit facts through reader refusals parseFailure now passes the named parser limit and a typed parser fixedAllowance when it wraps a UBI limit refusal, so the 16 MiB eraseblock size ceiling and the 262,144-eraseblock count ceiling reach CLI and MCP with reported_limits and the fixed-ceiling recovery. * fix(ubi-image): ignore nested EC headers no eraseblock could begin at The second-header scan now skips headers inside the data the first PEB's own VID header declares, so a static LEB holding a nested UBI image no longer measures the eraseblock at the nested header. The spacing check now counts only headers at positions an eligible smaller eraseblock (dividing the measured size, larger than data_offset) would begin at, and after the LEBs are read only the sizes they still admit. A dynamic LEB holding a nested image of small eraseblocks parses the same in PEB 2 as in PEB 5. * fix(ubi-image): read only the first VID header within the eraseblock ceiling The eraseblock search read every byte from offset 0 through the first PEB's declared vid_hdr_offset to find its VID header. A CRC-valid EC header could declare an offset of 1 GiB and make the reader allocate a buffer that size before the eraseblock ceiling refused the image. ubiFirstVidHeaderOffset now admits the VID header only when it lies inside the file and the fixed eraseblock ceiling, and the reader reads just those 64 bytes. A header past the ceiling is never read, so the search reaches its bounded eraseblock-size refusal as before. * fix(ubi-image): skip EC headers whose offset cannot be the eraseblock size A dynamic VID header declares data_size 0, so a first PEB holding a nested UBI image only rules out the nested header at data_offset. The next nested header, 6144 bytes into a 128 KiB eraseblock, was taken as the eraseblock size and the valid 524288-byte image was refused as not a multiple of it. The second-header search now skips headers at offsets that do not divide the file size, since no eraseblock size could put them there. The first header at any offset is still kept for the refusal when no size fits. * fix(ubi-image): reject truncated dumps with misleading PEB headers * Address review feedback * Address review feedback * Address review feedback * Keep undersized UBI candidates provisional on valid VID extents A CRC-valid VID header whose data_pad and data_size do not fit a candidate LEB now records the eraseblock size it needs. A dividing candidate smaller than that stays retryable, with its image kept as the fallback, so a later candidate that holds every LEB in full is accepted. * Address review feedback * Address review feedback * Exercise the UBI PEB count ceiling in memory * fix: reject unrelated UBI header conflicts * fix: verify static UBI payloads before retrying geometry * fix: bound UBI static payload CRC work across PEB size candidates * fix: repair UBI integration after merging main * Address review feedback * fix: let cancellation retire paused UBI volume streams * test: synchronize paused UBI volume cancellation * fix: preserve UBI read failures during cancellation * perf(ubi): count PEB states and extractable volumes in one pass Replace the per-state .filter(...).length scans in assembleUbiImage and summarizeUbiImage with single loops, per docs/development/tool-design.md. * Address review feedback * fix(firmware): close UBI geometry ambiguity and corrupt-PEB tail gaps * fix(firmware): verify erased UBI PEB bodies and validate layout VID headers * fix(firmware): defer and cache UBI erased-body scans and deduplicate stream check helper * fix(firmware): eliminate quadratic UBI erased-range scans and cache dynamic copy CRCs * test(firmware): assert UBI erased-range coalescing, walk steps, and elapsed time * perf(ubi): cache EC header scan across block-size retries * fix(ubi): bound EC header scan cache and stream past cap --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Matt Van Horn <mvanhorn@MacBook-Pro-10.local> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>