check_arm32_env.sh (4276B)
1 #!/usr/bin/env bash 2 # test/lib/check_arm32_env.sh — kit arm32 "doctor". 3 # 4 # Prerequisite check for the arm32 behavioral-oracle lane (test/smoke/arm32.sh). 5 # Like rv32, the arm32 target is freestanding `arm-none-eabi`: it runs as a 6 # bare-metal Cortex-M3 (Thumb-2) image under qemu-system-arm -machine 7 # mps2-an385, with a startup stub at flash 0x0 (M-profile vector table: initial 8 # MSP + reset handler) that copies .data flash->SRAM, zeroes .bss, calls the 9 # program, and reports its result through ARM semihosting SYS_EXIT_EXTENDED 10 # (BKPT #0xAB) — qemu's own process exit then == the program's exit code. 11 # 12 # arm32 v1 is soft-float only (Cortex-M3 has no FPU): -mfloat-abi=soft routes 13 # float + double through the AEABI helpers. So, unlike rv32, there is no 14 # FPU-enable step in the stub and only a single ABI lane. 15 # 16 # Each checked tool is reported as a one-liner (OK / MISSING) with what was 17 # looked for and how to install it. Source it and call check_arm32_env to 18 # populate the ARM32_* globals; run it directly for a standalone report. 19 # 20 # After check_arm32_env returns, these globals are set: 21 # ARM32_HAVE_CLANG_TARGET 0/1 — clang accepts --target=arm-none-eabi (M3) 22 # ARM32_HAVE_LLD 0/1 — ld.lld on PATH (bare-metal link fallback) 23 # ARM32_HAVE_QEMU_SYSTEM 0/1 — qemu-system-arm on PATH 24 # ARM32_QEMU_SYSTEM_BIN path or empty 25 # ARM32_READY 0/1 — clang target + qemu-system both usable 26 27 _arm32_os_tag() { 28 case "$(uname -s 2>/dev/null)" in 29 Darwin) echo darwin ;; 30 Linux) 31 if [ -r /etc/os-release ]; then 32 . /etc/os-release 33 case "${ID:-}:${ID_LIKE:-}" in 34 *alpine*) echo alpine ;; 35 *debian*|*ubuntu*) echo debian ;; 36 *fedora*|*rhel*) echo fedora ;; 37 *) echo linux ;; 38 esac 39 else echo linux; fi ;; 40 *) echo other ;; 41 esac 42 } 43 44 _arm32_hint_clang() { 45 case "$(_arm32_os_tag)" in 46 darwin) echo "brew install llvm (clang ships the arm-none-eabi target)" ;; 47 debian) echo "apt install clang lld" ;; 48 fedora) echo "dnf install clang lld" ;; 49 alpine) echo "apk add clang lld" ;; 50 *) echo "install an LLVM/clang with the arm (Cortex-M) target" ;; 51 esac 52 } 53 54 _arm32_hint_qemu_system() { 55 case "$(_arm32_os_tag)" in 56 darwin) echo "brew install qemu" ;; 57 debian) echo "apt install qemu-system-arm" ;; 58 fedora) echo "dnf install qemu-system-arm" ;; 59 alpine) echo "apk add qemu-system-arm" ;; 60 *) echo "install qemu (qemu-system-arm)" ;; 61 esac 62 } 63 64 check_arm32_env() { 65 ARM32_HAVE_CLANG_TARGET=0 66 ARM32_HAVE_LLD=0 67 ARM32_HAVE_QEMU_SYSTEM=0 68 ARM32_QEMU_SYSTEM_BIN="" 69 70 # clang with the arm-none-eabi (Cortex-M3) target: probe by compiling an 71 # empty TU. The smoke lane uses --target=arm-none-eabi; the canonical Thumb-2 72 # M-profile spelling thumbv7m-none-eabi is equivalent for this probe. 73 if command -v clang >/dev/null 2>&1; then 74 if echo 'int _e(void){return 0;}' | \ 75 clang --target=arm-none-eabi -mcpu=cortex-m3 -mthumb -mfloat-abi=soft \ 76 -ffreestanding -nostdlib -c -x c - -o /dev/null >/dev/null 2>&1; then 77 ARM32_HAVE_CLANG_TARGET=1 78 echo " OK clang --target=arm-none-eabi -mcpu=cortex-m3" 79 else 80 echo " MISSING clang arm-none-eabi target — install: $(_arm32_hint_clang)" 81 fi 82 else 83 echo " MISSING clang — install: $(_arm32_hint_clang)" 84 fi 85 86 if command -v ld.lld >/dev/null 2>&1; then 87 ARM32_HAVE_LLD=1 88 echo " OK ld.lld" 89 else 90 echo " MISSING ld.lld — install: $(_arm32_hint_clang)" 91 fi 92 93 if command -v qemu-system-arm >/dev/null 2>&1; then 94 ARM32_HAVE_QEMU_SYSTEM=1 95 ARM32_QEMU_SYSTEM_BIN="$(command -v qemu-system-arm)" 96 echo " OK qemu-system-arm ($ARM32_QEMU_SYSTEM_BIN)" 97 else 98 echo " MISSING qemu-system-arm — install: $(_arm32_hint_qemu_system)" 99 fi 100 101 ARM32_READY=0 102 if [ "$ARM32_HAVE_CLANG_TARGET" -eq 1 ] && [ "$ARM32_HAVE_QEMU_SYSTEM" -eq 1 ]; then 103 ARM32_READY=1 104 echo " READY arm32 behavioral oracle available" 105 else 106 echo " BLOCKED arm32 behavioral oracle needs clang arm-none-eabi target + qemu-system-arm" 107 fi 108 } 109 110 # Run standalone: report and exit non-zero if blocked. 111 if [ "${BASH_SOURCE[0]}" = "${0}" ]; then 112 check_arm32_env 113 [ "${ARM32_READY:-0}" -eq 1 ] 114 fi