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/aienux/blob/main/scripts/qemu_native_sdhci_test.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / qemu_native_sdhci_test.sh` 125 lines ยท 4866 bytes Raw Blame History 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 # qemu_native_sdhci_test.sh -- boot a bare-metal AArch64 payload that drives 18 # QEMU's emulated PCI SD Host Controller and SD card with the C driver in 19 # native/disk (disk_sdhci.c, the Pi 5 microSD driver). 20 # 21 # Two boots: 22 # spec2-sdsc host controller spec 2.00, 64 MiB card (standard capacity, 23 # byte addressing, power-of-two clock divider) 24 # spec3-sdhc host controller spec 3.00, 4 GiB card (high capacity, block 25 # addressing, 10-bit divided clock) 26 # Each boot writes, reads back, flushes, checks range refusal, re-initialises 27 # the controller and card and checks the data is still there. Afterwards this 28 # script reads block 5 out of the card image file and checks the marker the 29 # payload wrote, so the data is known to have reached the medium. 30 # 31 # Verdict line: AIENOS_DISK_SDHCI_QEMU: PASS | FAIL | NOT_RUN 32 # QEMU is an emulator. PASS here qualifies nothing about physical hardware. 33 # 34 # Respects the shared quiet flag: refuses to run (NOT_RUN, exit 0) while 35 # ~/workspace/.spark-quiet exists, which it only reads, or while another gate 36 # holds the QEMU gate lock (scripts/lib_gate_hold.sh, aienos#278). 37 set -euo pipefail 38 39 repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 40 qemu_timeout="${AIENOS_QEMU_TIMEOUT:-60}" 41 out_rel="out" 42 out="${repo}/native/disk/qemu/${out_rel}" 43 . "${repo}/scripts/lib_gate_hold.sh" 44 45 if ! gh_quiet_check; then 46 echo "NOT_RUN ${gh_why}" 47 echo "AIENOS_DISK_SDHCI_QEMU: NOT_RUN" 48 exit 0 49 fi 50 for tool in qemu-system-aarch64 timeout make truncate dd; do 51 if ! command -v "${tool}" >/dev/null 2>&1; then 52 echo "required tool ${tool} not found" 53 echo "AIENOS_DISK_SDHCI_QEMU: NOT_RUN" 54 exit 0 55 fi 56 done 57 58 # One QEMU gate at a time; the gate lock record is removed only if it is still 59 # this run's own (never another run's hold). 60 if ! gh_lock_take qemu_native_sdhci_test "${AIENOS_GATE_MINUTES:-60}"; then 61 echo "NOT_RUN ${gh_why}" 62 echo "AIENOS_DISK_SDHCI_QEMU: NOT_RUN" 63 exit 0 64 fi 65 cleanup() { gh_lock_release; } 66 trap cleanup EXIT 67 68 cross="" 69 if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi 70 if ! make -s -C "${repo}/native/disk/qemu" OUT="${out_rel}" \ 71 CC="${cross}gcc" LD="${cross}ld" NM="${cross}nm" >"${repo}/native/disk/qemu/build.log" 2>&1; then 72 tail -20 "${repo}/native/disk/qemu/build.log" 73 echo "payload build failed" 74 echo "AIENOS_DISK_SDHCI_QEMU: FAIL" 75 exit 1 76 fi 77 rm -f "${repo}/native/disk/qemu/build.log" 78 79 mark="AIENOS-SDHCI-QEMU block 5 written by disk_sdhci.c" 80 verdict=0 81 run_one() { # name spec-version image-size 82 local name="$1" spec="$2" size="$3" 83 local img="${out}/sd-${name}.img" log="${out}/qemu-${name}.log" qrc 84 rm -f "${img}" "${log}" 85 truncate -s "${size}" "${img}" 86 echo "== ${name}: sd-spec-version=${spec}, card ${size}" 87 set +e 88 timeout --kill-after=5 "${qemu_timeout}" qemu-system-aarch64 \ 89 -M virt,highmem=off -cpu cortex-a57 -m 256M -smp 1 \ 90 -nographic -monitor none -serial stdio -no-reboot \ 91 -kernel "${out}/sdhci_payload.elf" \ 92 -drive "file=${img},if=none,id=aienos_sd,format=raw" \ 93 -device "sdhci-pci,sd-spec-version=${spec}" \ 94 -device sd-card,drive=aienos_sd \ 95 "${log}" 2>&1 96 qrc=$? 97 set -e 98 tr -d '\r' <"${log}" | grep -v '^$' | tail -12 99 if [ "${qrc}" -eq 124 ] || [ "${qrc}" -eq 137 ]; then 100 echo "QEMU did not power off within ${qemu_timeout} s" 101 fi 102 if ! tr -d '\r' <"${log}" | grep -qx 'SDHCI_QEMU_PAYLOAD: PASS' || [ "${qrc}" -ne 0 ]; then 103 echo "${name}: FAIL" 104 verdict=1 105 return 106 fi 107 if [ "$(dd if="${img}" bs=512 skip=5 count=1 status=none | head -c "${#mark}")" != "${mark}" ]; then 108 echo "${name}: marker not found in block 5 of the card image (FAIL)" 109 verdict=1 110 return 111 fi 112 echo "${name}: PASS (marker read back from the card image file)" 113 } 114 115 run_one spec2-sdsc 2 64M 116 run_one spec3-sdhc 3 4G 117 rm -f "${out}"/sd-*.img 118 119 if [ "${verdict}" -eq 0 ]; then 120 echo "(QEMU emulated SD host controller and card only; not a physical-hardware qualification)" 121 echo "AIENOS_DISK_SDHCI_QEMU: PASS" 122 exit 0 123 fi 124 echo "AIENOS_DISK_SDHCI_QEMU: FAIL" 125 exit 1