firmware icon indicating copy to clipboard operation
firmware copied to clipboard

image: release assets are assembled from the previous nightly (race with manifest.yml)

Open DmtryJS opened this issue 1 month ago • 2 comments

Summary

The assets published under the image release tag are assembled from the previous nightly: the kernel and rootfs come from whatever manifest.json advertised at the moment image.yml started, while U-Boot is taken from latest. So the .bin under image mixes today's bootloader with yesterday's firmware — and, on boards where the kernel and the rootfs module must match (e.g. hi3516cv6xx after #138/#276), that combination is actively broken.

Question up front: is this intended ("image is assembled from whatever channels.nightly says when the job starts, one nightly behind")? If not, this is a race between image.yml and manifest.yml that is easy to close.

Evidence (2026-10-24, all times UTC)

Time Event
17:41:01 build.yml run 40117228467 started (dispatch, head 856f22ef)
18:57:18 build.yml run completed
18:57:20 image.yml run 40123066641 started and read manifest.json — channels.nightly was still nightly-20261023-0f146ce
19:02:58 manifest.yml published the new manifest (channels.nightly = nightly-20261024-856f22e)
19:07:30 image assets released from the 23.10 build
19:46:14 next image.yml run 40126796017 → skipped by the if: gate (origin was a pull_request build, the gate allows schedule/workflow_dispatch only)

Inspection of the released openipc-hi3516cv610-ddr3-128m-nor-ultimate.bin (image tag, created 2026-10-24T19:07:30Z, 16 777 216 B, md5 23df0ce91c5499af6b886bb4250a3c0f):

  • /etc/os-release: VERSION=-g0f146ce, BUILD_ID=nightly-20261023-0f146ce;
  • rootfs squashfs creation time 2026-10-23 18:07Z (before the firmware#2664 bump at 19:10:53Z);
  • open_mmz.ko md5 6019dd86bcd93122ebd93ba1b5b1c68f — the pre-OpenIPC/openhisilicon#276 module, with U init_mm / U flush_tlb_kernel_range / U apply_to_page_range;
  • kernel: Linux 5.10.221 #1 SMP Fri Oct 23 18:04:03 UTC 2026;
  • the U-Boot region at offset 0 is byte-identical to boot-hi3516cv610-20s-nor.bin from latest (2026-10-24 11:51Z, md5 74e2b196f76535cc16202b0bd726a447).

Flashing it therefore fails the way it did for us on 2026-10-22: open_mmz.ko cannot resolve init_mm → load_hisilicon aborts → MPP dead, no video, sensor autodetect never runs. The kernel inside is not the problem; the rootfs is one night older.

It also repeats: the asset updated 2026-10-21T19:05:24Z contained VERSION=-gef421c8, i.e. nightly-20261020-ef421c8.

Reproduction on any asset from the image tag:

curl -sSL -o img.bin https://github.com/OpenIPC/firmware/releases/download/image/openipc-hi3516cv610-ddr3-128m-nor-ultimate.bin
dd if=img.bin of=rootfs.sqsh bs=1M skip=37 status=none            # rootfs sits at 0x250000
unsquashfs -q -d x rootfs.sqsh etc/os-release lib/modules >/dev/null
grep BUILD_ID x/etc/os-release                                   # -> BUILD_ID=nightly-20261023-0f146ce
nm -u x/lib/modules/5.10.221/hisilicon/open_mmz.ko | grep -E 'init_mm|flush_tlb_kernel_range'

Root cause

  • image.yml triggers on workflow_run: [build] completed and resolves its build id from the manifest (MANIFEST_URL → .channels.nightly), then fetches each platform through .builds[] | select(.id==$b) | .platforms[...].url. It reads the manifest at job start.
  • manifest.yml triggers on the same event with the same gate, but publishes the manifest later (24.10: ~5.5 min after the image job started).
  • There is no ordering between the two (needs/workflow_call/re-dispatch), and no re-run: later image.yml triggers coming from PR-origin builds are filtered out by the if: gate, so the images are not reassembled after the manifest flips.
  • UBOOT_URL points at latest, so the bootloader in the asset is current even when the payload is not — which makes the staleness invisible from the outside.
  • build.yml already exposes build_id in preflight.outputs (lines ~108-112, 165), but a workflow_run consumer does not receive job outputs, so image.yml cannot pick it up as is.

This looks like an unintended consequence of the manifest-driven design from #2118 — hence the question above.

Suggested fixes

  1. Order the jobs. Trigger image.yml from manifest.yml (workflow_run: workflows: [manifest], or workflow_call, or an explicit gh workflow run image.yml -f build_id=... as the last step of the manifest job). Then channels.nightly is fresh by construction and the image tag always matches what the manifest/site advertise. Cost: images appear a few minutes later.

  2. Resolve the build from the triggering run, not from "whatever the manifest says". Take github.event.workflow_run.head_sha and select the manifest entry whose sha matches, polling with backoff while the manifest catches up; fail loudly if it never appears, instead of silently publishing the previous build:

    HEAD=${{ github.event.workflow_run.head_sha }}
    for i in $(seq 1 30); do
      BUILD_ID=$(jq -r --arg s "$HEAD" '.builds[] | select(.sha==$s) | .id' /tmp/manifest.json)
      [ -n "$BUILD_ID" ] && break
      sleep 60
      curl -fsSL -H 'Cache-Control: no-cache' "$MANIFEST_URL" -o /tmp/manifest.json
    done
    
  3. Guard the assembly (cheap, catches any skew regardless of ordering). After building each .bin, read the build id out of the artifact and abort if it does not match the build being published; log it either way:

    REL=$(dd if="$release" bs=1M skip=37 status=none | unsquashfs -cat /dev/stdin etc/os-release | sed -n 's/^BUILD_ID=//p')
    [ "$REL" = "$BUILD_ID" ] || { echo "::error::$release contains $REL, expected $BUILD_ID"; exit 1; }
    

    This one would have turned the 2026-10-24 case into a red run instead of a published mixed image.

  4. Do not mix latest U-Boot with another build's kernel/rootfs — either take boot-* from the same build when available, or state plainly in the release notes that U-Boot always comes from latest.

  5. Make assets self-identifying. Today the asset name carries no build id, so a stale file cannot be recognised without unpacking it; the site wizard meanwhile serves its own openipc-<soc>-nor-<edition>-<size>mb.bin assembled from channels.nightly (currently correct, and byte-identical to what we assemble locally). Including the build id in the asset name (or setting an asset label) removes that trap.

Workaround we use now

Take the split package from the manifest entry (.../releases/download/<build_id>/openipc.<soc>-nor-<variant>-split.tgz, immutable per-build URL), assemble the 16 MiB image from it plus boot-*.bin from latest, and verify BUILD_ID and open_mmz.ko before flashing.

If the one-nightly lag is intended for some reason, could it be documented in the image release notes? Right now nothing in the release metadata hints that the payload is a day old, while the U-Boot inside is current.


Related: #2118 (image downstream of build via workflow_run, manifest-driven URLs).

DmtryJS avatar Oct 24 '26 21:10 DmtryJS

Not intended. Thanks for the timeline and the reproduction; they made this quick to confirm.

Fix: #2681. image.yml no longer reads the manifest. It resolves the build from the dated release that the triggering run published: build.yml creates nightly-YYYYMMDD-<short> with sha=<HEAD> in its body before the run completes, so workflow_run.head_sha always finds it. The full SHA has to match. If no release matches, the run goes red instead of using an older build.

On your suggestions:

  1. Ordering after manifest.yml. I didn't take this, because it isn't enough on its own. After the push, gh-pages still has to deploy and the CDN still caches the old copy, so reading the Pages URL would still race, just over a shorter window.
  2. Resolve from head_sha. Taken. It reads from the release directly, so there is nothing to poll.
  3. Unsquashfs guard. Not taken. The source is now the immutable per-build release, matched on sha=, so the guard would mainly add a squashfs-tools install to every run.
  4. U-Boot from latest. That is by design: U-Boot isn't built per nightly, because uboot.yml publishes it to latest on its own. The image release body now says so.
  5. Self-identifying assets. Done through the release body rather than the asset names, which the site and wiki link to. The body now carries build_id=, sha= and assembled_at=; until now it was empty.

The assets under image right now are still the 23rd's. After the merge, a manual dispatch will replace them. Your workaround — the split package from the per-build URL, plus a BUILD_ID check — is the right one until then.

openipc-ai avatar Oct 25 '26 07:10 openipc-ai

Fixed by #2681 (merged as 56768a35), and the image tag has been reassembled from it: run 40201147437, dispatched on master.

The release body now names the build, and all 62 assets on the tag are listed as assembled by that run:

build_id=nightly-20261024-856f22e
sha=856f22ef7e046f59a3f409e157eb1e06d42fd03c
assembled_at=2026-10-25T14:13:41Z

I checked openipc-hi3516cv610-ddr3-128m-nor-ultimate.bin from the tag with your reproduction steps:

BUILD_ID=nightly-20261024-856f22e
open_mmz.ko md5 2269a210a7eb73111a69a177a4fb410e
undefined init_mm / flush_tlb_kernel_range / apply_to_page_range: 0
md5 2b7a1d67eecac2da58970344d5fc0d07, byte-identical to the image assembled locally from the 856f22e split package

Compared with what the tag held before:

BUILD_ID=nightly-20261023-0f146ce
open_mmz.ko 6019dd86…
undefined: 3

What changed, from the next nightly on:

  • The image workflow takes the dated release whose sha= matches the commit that triggered it, or goes red.
  • A dispatch accepts only dated build_ids.
  • The release API calls retry.
  • The body lists exactly which files each run rebuilt.

Not done: I have not flashed this image onto a camera. Only the choice of build changed; the payload is the per-build package as published.

openipc-ai avatar Oct 25 '26 14:10 openipc-ai