Skip to content

ptool, CI: deterministic GPT artifacts and pinned checksum check#111

Open
igoropaniuk wants to merge 2 commits intoqualcomm-linux:mainfrom
igoropaniuk:feat/deterministic_ptool_artifacts
Open

ptool, CI: deterministic GPT artifacts and pinned checksum check#111
igoropaniuk wants to merge 2 commits intoqualcomm-linux:mainfrom
igoropaniuk:feat/deterministic_ptool_artifacts

Conversation

@igoropaniuk
Copy link
Copy Markdown
Contributor

@igoropaniuk igoropaniuk commented Apr 27, 2026

Honour PTOOL_SEED from the environment to seed the RNG used for DiskGUID and UniquePartitionGUID, making "make all" reproducible when set and unchanged (random) when unset. The GitHub Actions build sets a fixed seed and now also runs make check-checksums against a pinned tests/integration/checksums.sha256 manifest covering every generated artifact, so unintended changes from a refactor or regression fail CI.

A make generate-checksums target is provided to regenerate the manifest when partition configs or generators change deliberately, with the diff becoming part of PR review.

@lumag
Copy link
Copy Markdown
Contributor

lumag commented Apr 27, 2026

I'd prefer to let users specify the random seed (e.g. via the environment variable) and then use the fixed seed for all our CI builds (which would allow e.g. comparing by the results by the checksum).

@igoropaniuk igoropaniuk force-pushed the feat/deterministic_ptool_artifacts branch from 56aeddd to f8d0399 Compare April 28, 2026 06:49
@igoropaniuk igoropaniuk changed the title ptool: seed RNG from input XML for reproducible GPT output ptool, CI: opt-in deterministic GPT artifacts via PTOOL_SEED Apr 28, 2026
@igoropaniuk
Copy link
Copy Markdown
Contributor Author

@lumag done

lumag
lumag previously approved these changes Apr 28, 2026
@lumag
Copy link
Copy Markdown
Contributor

lumag commented Apr 28, 2026

Thanks!. Maybe it would be nice (as a followup) to add regression testing in the form of the checksumming (some) of the generated files.

@igoropaniuk
Copy link
Copy Markdown
Contributor Author

Thanks!. Maybe it would be nice (as a followup) to add regression testing in the form of the checksumming (some) of the generated files.

I'm already in the middle of it, can push additional commits to this PR

@igoropaniuk igoropaniuk changed the title ptool, CI: opt-in deterministic GPT artifacts via PTOOL_SEED ptool, CI: deterministic GPT artifacts and pinned checksum check Apr 28, 2026
@igoropaniuk
Copy link
Copy Markdown
Contributor Author

@lumag done!

Comment thread tests/integration/check-checksums Outdated
Comment thread Makefile
Comment thread .github/workflows/build.yml
@igoropaniuk igoropaniuk force-pushed the feat/deterministic_ptool_artifacts branch from 48cf3c8 to 1a1b6e8 Compare April 29, 2026 06:39
@igoropaniuk igoropaniuk requested a review from lumag April 29, 2026 06:40
The DiskGUID and per-partition UniquePartitionGUID values are produced
by random.randint(0, 2**128) with an unseeded RNG. As a result, two
consecutive runs of "make all" on the same commit yielded gpt_main*.bin,
gpt_backup*.bin and gpt_both*.bin files that differed in ~250+ bytes
(the random GUIDs themselves plus the header and partition-array CRC32
fields that cover them). This made it impossible to compare artifacts
across CI runs or between developer trees on the same input by checksum.

Honour PTOOL_SEED from the environment: when set and non-empty, seed
random with its value before parsing the input, making the run fully
reproducible. When unset, behaviour is unchanged and GUIDs stay random,
matching pre-existing expectations for normal local use.

Set PTOOL_SEED to a fixed value in the GitHub Actions build workflow so
"make all integration" is reproducible in CI, enabling artifact
comparison by checksum across branches and re-runs.

The existing --sequentialguid flag and explicit per-partition uguid="..."
overrides keep working unchanged; PTOOL_SEED only affects the random
fallback path. GPT spec semantics are preserved: DiskGUID and
UniquePartitionGUIDs are still full 128-bit values, each partition
still gets a distinct GUID (including across LUNs on multi-LUN
platforms like apq8096-db820c with 6 LUNs).

Verified on apq8016-sbc/emmc/gpt_main0.bin:

- Without PTOOL_SEED: two runs produce different DiskGUIDs (random).
- PTOOL_SEED=42 twice: identical artifacts.
- PTOOL_SEED=42 vs PTOOL_SEED=99: different DiskGUIDs.
- PTOOL_SEED=qcom-ptool-ci + full "make all" twice: zero differing
  files under platforms/.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Add tests/integration/checksums.sha256, a sha256sum -c manifest covering
every generated *.bin and *.xml under platforms/, produced with
PTOOL_SEED=qcom-ptool-ci (the seed CI uses). Wire two Makefile targets
around it:

- check-checksums: runs sha256sum -c against the manifest. Fails the
  build if any artifact has changed unexpectedly.
- generate-checksums: regenerates the manifest from the current tree.
  Intended for use when partition configs or generator scripts are
  changed deliberately and the diff to checksums.sha256 then becomes
  part of the PR review (one line per affected artifact).

The wrapper script lives at tests/integration/check-checksums and
matches the style of the existing check-missing-files helper.

The GitHub Actions build step now runs:

$ make all integration check-checksums

and a follow-up step regenerates the manifest and fails the build if
the result does not match the checked-in file:

$ make generate-checksums
$ git diff --exit-code tests/integration/checksums.sha256

This catches contributors who add or modify a platform without also
running make generate-checksums and committing the updated manifest;
check-checksums alone would miss new files.

Platform maintainer workflow:

$ PTOOL_SEED=qcom-ptool-ci make clean generate-checksums
$ git add tests/integration/checksums.sha256
$ git commit ...

Verified locally:

- Pristine seeded build passes (exit 0, no FAILED lines).
- Tampering with a single artifact fails check-checksums (exit 1).
- Building with a different seed fails check-checksums (288 GPT
  binaries diverge as expected).
- Adding a stray file under platforms/ causes generate-checksums to
  produce a manifest that differs from the checked-in file, and
  git diff --exit-code reports it as expected.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
@igoropaniuk igoropaniuk force-pushed the feat/deterministic_ptool_artifacts branch from 1a1b6e8 to 8d17375 Compare April 29, 2026 07:36
@igoropaniuk
Copy link
Copy Markdown
Contributor Author

@lumag all comments are addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants