Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/disk/tests/run_slice_d.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / disk / tests / run_slice_d.sh` 353 lines ยท 13239 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Host verification suite for Slice D (Piece 4: RO NVMe + GPT + ext4 + SHA-256 + RTL8127/TCP + a64efi). 4 # Strictly host-only (NOT_RUN on Spark silicon). Zero real firmware bytes. 5 set -eu 6 7 ROOT=$(CDPATH= cd -- "$(dirname "$0")/../../.." && pwd) 8 OMC="${OMC:-${OMEGA_MACOS_ROOT:-$HOME/workspace/omega-mv-macos}/seed/out/omc-macos}" 9 if [ ! -x "$OMC" ]; then 10 OMC="$ROOT/seed/out/omc" 11 fi 12 13 TMP=$(mktemp -d "${TMPDIR:-/tmp}/slice-d-test.XXXXXX") 14 trap 'rm -rf "$TMP"' EXIT 15 16 OS=$(uname -s) 17 if [ "$OS" = "Darwin" ]; then 18 HOST_HDR="target a64macos" 19 sign_bin() { codesign -s - "$1" >/dev/null 2>&1; } 20 else 21 HOST_HDR="" 22 sign_bin() { :; } 23 fi 24 25 compile_host() { 26 out="$1"; shift 27 if [ -n "$HOST_HDR" ]; then 28 { printf '%s\n' "$HOST_HDR"; cat "$@"; } | "$OMC" > "$out" 29 else 30 cat "$@" | "$OMC" > "$out" 31 fi 32 chmod +x "$out" 33 sign_bin "$out" 34 } 35 36 compile_linux() { 37 out="$1"; shift 38 cat "$@" | "$OMC" > "$out" 39 } 40 41 echo "=== [1/7] NVMe Read-Only Bare-Metal Simulator Test ===" 42 compile_host "$TMP/test_nvme_ro_bare" \ 43 "$ROOT/aienux/disk/nvme_ro_bare.om" \ 44 "$ROOT/aienux/disk/tests/test_nvme_ro_bare.om" 45 "$TMP/test_nvme_ro_bare" 46 compile_linux "$TMP/test_nvme_ro_bare.elf" \ 47 "$ROOT/aienux/disk/nvme_ro_bare.om" \ 48 "$ROOT/aienux/disk/tests/test_nvme_ro_bare.om" 49 echo "PASS: test_nvme_ro_bare (host run + Linux AArch64 ELF compile)" 50 51 echo "=== [2/7] Offline OMFWBND1 Bundle Packer (Synthetic Blobs Only) ===" 52 compile_host "$TMP/pack_bundle" \ 53 "$ROOT/aienux/disk/sha256_bare.om" \ 54 "$ROOT/aienux/disk/pack_bundle.om" 55 compile_linux "$TMP/pack_bundle.elf" \ 56 "$ROOT/aienux/disk/sha256_bare.om" \ 57 "$ROOT/aienux/disk/pack_bundle.om" 58 python3 - "$TMP" <<'PY' 59 import os, sys 60 tmp = sys.argv[1] 61 blobs = [ 62 ("gsp.bin", b"SYNTH_GSP_ELF64" * 300), 63 ("bl.img", b"SYNTH_BL_IMG" * 120), 64 ("fmc.img", b"SYNTH_FMC_IMG" * 120), 65 ("fmc.hash", bytes(range(48))), 66 ("fmc.pubkey", bytes([(i * 7) & 0xff for i in range(384)])), 67 ("fmc.sig", bytes([(i * 13) & 0xff for i in range(384)])), 68 ("bl_desc", bytes([(i * 3) & 0xff for i in range(84)])), 69 ] 70 for name, data in blobs: 71 with open(os.path.join(tmp, name), "wb") as f: 72 f.write(data) 73 PY 74 "$TMP/pack_bundle" "$TMP/spark-bundle.img" `58017302` \ 75 1 "$TMP/gsp.bin" \ 76 2 "$TMP/bl.img" \ 77 3 "$TMP/fmc.img" \ 78 4 "$TMP/fmc.hash" \ 79 5 "$TMP/fmc.pubkey" \ 80 6 "$TMP/fmc.sig" \ 81 7 "$TMP/bl_desc" 82 # Regression: pack_bundle MUST reject u64 overflow (> 2^64-1) and >20-digit args with exit 2 83 set +e 84 "$TMP/pack_bundle" "$TMP/bad1.img" `18446744073709551616` 1 "$TMP/gsp.bin" 85 rc1=$? 86 "$TMP/pack_bundle" "$TMP/bad2.img" `123456789012345678901` 1 "$TMP/gsp.bin" 87 rc2=$? 88 set -e 89 if [ "$rc1" -ne 2 ] || [ "$rc2" -ne 2 ]; then 90 echo "FAIL: pack_bundle bad-arg rejection (rc1=$rc1 rc2=$rc2)" >&2 91 exit 1 92 fi 93 echo "PASS: pack_bundle produced $(wc -c < "$TMP/spark-bundle.img") byte synthetic OMFWBND1 bundle + overflow/length rejection" 94 95 echo "=== [3/7] Synthetic GPT + 64-bit ext4 Image & Read-Only Test ===" 96 python3 - "$TMP/spark-bundle.img" "$TMP/disk.img" <<'PY' 97 import struct, sys, zlib 98 99 bundle = open(sys.argv[1], "rb").read() 100 total_secs = 4096 101 img = bytearray(total_secs * 512) 102 103 # 1. Protective MBR (LBA 0) 104 img[446 + 4] = 0xEE 105 struct.pack_into(" 499 x 4KiB blocks) 115 linux_guid = bytes.fromhex("`af3dc60f838472478e793d69d8477de4`") 116 part2_lba = 64 117 part2_last = total_secs - 34 118 struct.pack_into("<16s16sQQQ", ents, 128, linux_guid, b"\x02"*16, part2_lba, part2_last, 0) 119 ent_crc = zlib.crc32(ents) & 0xffffffff 120 121 def make_gpt_hdr(my_lba, bak_lba, ent_lba): 122 hdr = bytearray(92) 123 struct.pack_into("<8sIIIIQQQQ16sQIII", hdr, 0, 124 b"EFI PART", 0x00010000, 92, 0, 0, 125 my_lba, bak_lba, 34, total_secs - 34, 126 b"\x11"*16, ent_lba, 128, 128, ent_crc) 127 hcrc = zlib.crc32(hdr) & 0xffffffff 128 struct.pack_into("> 32) & 0xffffffff) 166 img[ioff + 40 : ioff + 40 + len(ext_bytes)] = ext_bytes 167 168 def ext_hdr(entries, max_e, depth, magic=0xF30A): 169 return struct.pack("> 32) & 0xffff, pblk & 0xffffffff) 173 174 def ext_idx(ei_blk, leaf_blk): 175 return struct.pack("> 32) & 0xffff, 0) 176 177 def make_dir_block(entries): 178 buf = bytearray(BS) 179 pos = 0 180 for idx, (ino, name, ftype) in enumerate(entries): 181 nb = name.encode("ascii") 182 raw = 8 + len(nb) 183 rlen = (raw + 3) & ~3 184 if idx == len(entries) - 1: 185 rlen = BS - pos 186 struct.pack_into(" blk 10), /aienos (ino 12 -> blk 11), /bad (ino 13 -> blk 12) 192 img[blk_off(10):blk_off(11)] = make_dir_block([(2, ".", 2), (2, "..", 2), (12, "aienos", 2), (13, "bad", 2)]) 193 write_inode(2, 0x41ED, BS, 0x80000, ext_hdr(1, 4, 0) + ext_leaf(0, 1, 10)) 194 195 img[blk_off(11):blk_off(12)] = make_dir_block([(12, ".", 2), (2, "..", 2), (14, "sparse.bin", 1), (15, "spark-bundle.img", 1)]) 196 write_inode(12, 0x41ED, BS, 0x80000, ext_hdr(1, 4, 0) + ext_leaf(0, 1, 11)) 197 198 img[blk_off(12):blk_off(13)] = make_dir_block([ 199 (13, ".", 2), (2, "..", 2), 200 (16, "inline", 1), (17, "encrypt", 1), (18, "noext", 1), (19, "badmagic", 1) 201 ]) 202 write_inode(13, 0x41ED, BS, 0x80000, ext_hdr(1, 4, 0) + ext_leaf(0, 1, 12)) 203 204 # /aienos/sparse.bin (ino 14, 16384 B, DEPTH-1 extent tree! index -> leaf block 13): 205 # lblock 0 -> blk 14 (0xA5) 206 # lblock 1 -> blk 15 (unwritten ee_len = 32768 + 1, disk has 0xEE garbage -> MUST read as 0x00!) 207 # lblock 2 -> sparse hole (no extent -> MUST read as 0x00!) 208 # lblock 3 -> blk 16 (0x5A) 209 img[blk_off(14):blk_off(15)] = bytes([0xA5]) * BS 210 img[blk_off(15):blk_off(16)] = bytes([0xEE]) * BS 211 img[blk_off(16):blk_off(17)] = bytes([0x5A]) * BS 212 leaf13 = ext_hdr(3, 340, 0) + ext_leaf(0, 1, 14) + ext_leaf(1, 32769, 15) + ext_leaf(3, 1, 16) 213 img[blk_off(13):blk_off(13)+len(leaf13)] = leaf13 214 write_inode(14, 0x81A4, 16384, 0x80000, ext_hdr(1, 4, 1) + ext_idx(0, 13)) 215 216 # /aienos/spark-bundle.img (ino 15, blocks 20..) 217 bnd_blks = (len(bundle) + BS - 1) // BS 218 img[blk_off(20):blk_off(20)+len(bundle)] = bundle 219 write_inode(15, 0x81A4, len(bundle), 0x80000, ext_hdr(1, 4, 0) + ext_leaf(0, bnd_blks, 20)) 220 221 # Hostile inodes in /bad/ 222 write_inode(16, 0x81A4, 16, 0x80000 | 0x10000000, ext_hdr(0, 4, 0)) # inline 223 write_inode(17, 0x81A4, 16, 0x80000 | 0x800, ext_hdr(0, 4, 0)) # encrypt 224 write_inode(18, 0x81A4, 16, 0, b"\x00"*60) # no extents 225 write_inode(19, 0x81A4, 4096, 0x80000, ext_hdr(1, 4, 0, magic=0xDEAD) + ext_leaf(0, 1, 14)) 226 227 open(sys.argv[2], "wb").write(img) 228 PY 229 230 # Also build a META_BG (0x10) superblock copy to verify E4_E_FEATURE fail-closed refusal 231 python3 - "$TMP/disk.img" "$TMP/disk_metabg.img" <<'PY' 232 import struct, sys 233 img = bytearray(open(sys.argv[1], "rb").read()) 234 sb = 64 * 512 + 1024 235 inc = struct.unpack_from(" "$TMP/efi_nvme_stub.om" 286 fn a64_dsb_sy to void 287 end 288 fn a64_dc_civac_range pa ulong nbytes ulong to void 289 end 290 fn gpt_read_lba lba ulong to int 291 ret 0 292 end 293 fn ext4_read_lba lba ulong to int 294 ret 0 295 end 296 fn ext4_sink off ulong b uchar to void 297 end 298 fn main to int 299 r = nvme_init `1645215744` `268435456` 1 300 if ne r 0 301 ret r 302 end 303 r2 = gpt_ro_parse 4096 304 if ne r2 0 305 ret r2 306 end 307 ret ext4_ro_mount 64 4000 308 end 309 OM 310 { printf 'target a64efi\n'; \ 311 cat "$ROOT/aienux/disk/nvme_ro_bare.om" \ 312 "$ROOT/aienux/disk/nvme_bare_a64efi.om" \ 313 "$ROOT/aienux/disk/sha256_bare.om" \ 314 "$ROOT/aienux/disk/gpt_ro.om" \ 315 "$ROOT/aienux/disk/ext4_ro.om" \ 316 "$TMP/efi_nvme_stub.om"; } | "$OMC" > "$TMP/nvme_storage.efi" 317 echo "PASS: target a64efi NVMe+GPT+ext4+SHA256 PE32+ compiled ($(wc -c < "$TMP/nvme_storage.efi") bytes)" 318 319 echo "=== [7/7] Bare-Metal target a64efi PE32+ Compile Check (RTL8127 + TCP) ===" 320 cat <<'OM' > "$TMP/efi_net_stub.om" 321 fn a64_dsb_sy to void 322 end 323 fn a64_dc_civac_range pa ulong nbytes ulong to void 324 end 325 fn main to int 326 r = rtl_bare_setup RTL_SPARK_BAR2 `268435456` 327 if ne r 0 328 ret r 329 end 330 e = rtlinit `268435456` 331 if ne e 0 332 ret int e 333 end 334 rtltcp_bind_mac 335 tinit 336 put Tcf 1 `3232235884` 337 put Tcf 2 `3232235777` 338 put Tcf 3 `4294967040` 339 put Tcf 5 12345 340 tlisten 9000 341 z = rtltcp_poll 0 342 ret 0 343 end 344 OM 345 { printf 'target a64efi\n'; \ 346 cat "$ROOT/aienux/net/rtl8127/om/rtl8127/rtl8127.om" \ 347 "$ROOT/aienux/net/rtl8127/om/rtl8127/bare_a64efi.om" \ 348 "$ROOT/aienux/net/tcp/tcp.om" \ 349 "$ROOT/aienux/net/rtl8127/om/rtl8127/tcp_glue.om" \ 350 "$TMP/efi_net_stub.om"; } | "$OMC" > "$TMP/rtl8127_tcp.efi" 351 echo "PASS: target a64efi RTL8127+TCP PE32+ compiled ($(wc -c < "$TMP/rtl8127_tcp.efi") bytes)" 352 353 echo "SLICE D ALL 7 CHECKS PASSED"