aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / ck_repro_build.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # ck_repro_build.sh -- build the AIENOS C kernel UEFI image twice from the same |
| 18 | # clean commit, in two fresh output folders, and compare the sha256 digests |
| 19 | # (docs/native/PREFLIGHT-AND-RECOVERY.md section 1). Host only: builds files |
| 20 | # under a temp folder, never touches the ESP, NVRAM, firmware, keys or any disk. |
| 21 | # |
| 22 | # Usage: bash scripts/ck_repro_build.sh [full|core] [--keep DIR] |
| 23 | # full (default) make full: the image with the boot stages |
| 24 | # core make: the core-only image (the M1 / M0_ROLLBACK candidate) |
| 25 | # --keep DIR copy build A's BOOTAA64.EFI to DIR (for staging later) |
| 26 | # The hardware staging image (CK_HARDWARE_STAGING=1) needs the owner's files |
| 27 | # and is built by the stage scripts; this script does not build it. |
| 28 | # |
| 29 | # Prints both digests and, last, one line: |
| 30 | # CK_REPRO_BUILD: PASS <kind> commit=<commit> sha256=<digest> |
| 31 | # CK_REPRO_BUILD: FAIL <kind> (digests differ: <a> <b>) |
| 32 | # Exit 0 PASS, 1 FAIL, 2 usage error, dirty tree or build failure. |
| 33 | # The digest changes with every commit (the commit hash is built into the |
| 34 | # image), so it is recorded per commit, never written down in advance. |
| 35 | set -euo pipefail |
| 36 | |
| 37 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 38 | cd "${repo_root}" |
| 39 | |
| 40 | kind=full keep="" |
| 41 | while [[ $# -gt 0 ]]; do |
| 42 | case "$1" in |
| 43 | full|core) kind="$1"; shift ;; |
| 44 | --keep) [[ $# -ge 2 ]] || { echo "--keep needs a folder"; exit 2; }; keep="$2"; shift 2 ;; |
| 45 | *) echo "usage: $0 [full|core] [--keep DIR]"; exit 2 ;; |
| 46 | esac |
| 47 | done |
| 48 | |
| 49 | if [[ -n "$(git status --porcelain --untracked-files=normal)" ]]; then |
| 50 | echo "refused: the working tree is not clean (a digest must map to one commit)" |
| 51 | git status --short | head -20 |
| 52 | exit 2 |
| 53 | fi |
| 54 | commit="$(git rev-parse HEAD)" |
| 55 | cross="" |
| 56 | if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi |
| 57 | target=""; [[ "${kind}" == full ]] && target=full |
| 58 | |
| 59 | work="$(mktemp -d)" |
| 60 | trap 'rm -rf "${work}"' EXIT |
| 61 | declare -A digest=() |
| 62 | for b in a b; do |
| 63 | out="${work}/ck-${b}" |
| 64 | if ! make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" ${target} >"${work}/build-${b}.log" 2>&1; then |
| 65 | tail -20 "${work}/build-${b}.log" |
| 66 | echo "CK_REPRO_BUILD: FAIL ${kind} (build ${b} failed)" |
| 67 | exit 2 |
| 68 | fi |
| 69 | img="${out}/BOOTAA64.EFI" |
| 70 | [[ "${kind}" == full ]] && img="${out}/full/BOOTAA64.EFI" |
| 71 | [[ -f "${img}" ]] || { echo "CK_REPRO_BUILD: FAIL ${kind} (build ${b} produced no ${img#"${work}"/})"; exit 2; } |
| 72 | digest[${b}]="$(sha256sum "${img}" | cut -c1-64)" |
| 73 | echo "build ${b}: ${digest[${b}]} $(stat -c %s "${img}") bytes (OUT=${out})" |
| 74 | [[ "${b}" == a ]] && img_a="${img}" |
| 75 | done |
| 76 | echo "commit: ${commit}" |
| 77 | echo "toolchain: $(${cross}gcc --version | head -1); $(${cross}ld --version | head -1)" |
| 78 | if [[ -n "${keep}" ]]; then |
| 79 | mkdir -p "${keep}" |
| 80 | cp "${img_a}" "${keep}/BOOTAA64.EFI" |
| 81 | echo "kept: ${keep}/BOOTAA64.EFI" |
| 82 | fi |
| 83 | if [[ "${digest[a]}" == "${digest[b]}" ]]; then |
| 84 | echo "CK_REPRO_BUILD: PASS ${kind} commit=${commit} sha256=${digest[a]}" |
| 85 | exit 0 |
| 86 | fi |
| 87 | echo "CK_REPRO_BUILD: FAIL ${kind} (digests differ: ${digest[a]} ${digest[b]})" |
| 88 | exit 1 |