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 / allen_route_card.sh
| 1 | #!/usr/bin/env bash |
| 2 | # allen_route_card.sh -- build a pi5-allen route card (\EFI\AIENOS\ALLEN.EXM with header "AIENALR1 QUALIF-ALLEN-ROUTE", |
| 3 | # crates/allen-reflex-kernel/src/card.rs parse_route) from route family files (aienos#399). Only the request id, the |
| 4 | # speaker, the consent/pending flags and the turns go into the card; the expected route stays on the host. |
| 5 | # Capabilities never go into the card: the image passes its own (core/allen.c CK_ALLEN_ROUTE_CAPS). |
| 6 | # |
| 7 | # allen_route_card.sh <out file> <file>... |
| 8 | # |
| 9 | # A .psv file is a route family (id|family|speaker|flags|expected_route|expected_then|turns, docs/native/pi5-8/route/); |
| 10 | # a .req file holds requests with no expected answer (id|owner|guest|flags|turns), for example requests written after |
| 11 | # the image was built. Each request gets its own session id (its line number on the card). |
| 12 | # Refuses held-out and sealed files: the Pi card is a rehearsal; held-out families are scored once on the host only. |
| 13 | set -euo pipefail |
| 14 | out="${1:?out file}"; shift |
| 15 | [[ $# -ge 1 ]] || { echo "usage: $0 <out file> <file>..." >&2; exit 2; } |
| 16 | for f in "$@"; do |
| 17 | case "$(readlink -f "$f")" in |
| 18 | */sealed/*|*heldout*) echo "REFUSE: ${f} is a held-out or sealed file" >&2; exit 2 ;; |
| 19 | esac |
| 20 | [[ -r "$f" ]] || { echo "no file ${f}" >&2; exit 2; } |
| 21 | done |
| 22 | tmp="$(mktemp)" |
| 23 | trap 'rm -f "${tmp}"' EXIT |
| 24 | printf 'AIENALR1 QUALIF-ALLEN-ROUTE\n' > "${tmp}" |
| 25 | for f in "$@"; do |
| 26 | if [[ "$f" == *.psv ]]; then nf=6; else nf=3; fi |
| 27 | # keep id, speaker, flags; drop the family and expected columns; turns may hold '|' (all after the last field) |
| 28 | awk -v nf="${nf}" '!/^#/ && NF { |
| 29 | r = $0 |
| 30 | for (n = 0; n < nf; n++) { j = index(r, "|"); if (!j) { print "bad line: " $0 > "/dev/stderr"; exit 1 } |
| 31 | f[n] = substr(r, 1, j - 1); r = substr(r, j + 1) } |
| 32 | sp = (nf == 6) ? f[2] : f[1]; fl = (nf == 6) ? f[3] : f[2] |
| 33 | print f[0] "|" sp "|" fl "|" r }' "$f" >> "${tmp}" |
| 34 | done |
| 35 | # speaker -> speaker:<session>, session = the request's line number on the card |
| 36 | awk 'NR == 1 { print; next } { i = index($0, "|"); id = substr($0, 1, i - 1); r = substr($0, i + 1); |
| 37 | j = index(r, "|"); sp = substr(r, 1, j - 1); print id "|" sp ":" NR - 1 "|" substr(r, j + 1) }' "${tmp}" > "${tmp}.s" |
| 38 | mv "${tmp}.s" "${tmp}" |
| 39 | n=$(( $(wc -l < "${tmp}") - 1 )) |
| 40 | bytes=$(stat -c %s "${tmp}") |
| 41 | [[ ${bytes} -le 131072 ]] || { echo "card file ${bytes} bytes > 131072" >&2; exit 1; } |
| 42 | [[ ${n} -ge 1 && ${n} -le 512 ]] || { echo "card file has ${n} requests (1..512)" >&2; exit 1; } |
| 43 | dups=$(tail -n +2 "${tmp}" | cut -d'|' -f1 | sort | uniq -d | head -3 | tr '\n' ' ') |
| 44 | [[ -z "${dups}" ]] || { echo "duplicate request ids: ${dups}" >&2; exit 1; } |
| 45 | mv "${tmp}" "${out}" |
| 46 | trap - EXIT |
| 47 | echo "route card ${out}: ${n} requests, ${bytes} bytes, sha256 $(sha256sum "${out}" | cut -d' ' -f1)" |