| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | print_usagescip-shell shell llvm-toolchain-22 1:22.1.7-1 print_usage().() { |
| 4 | echoscip-shell system . . echo. "Usage: $(basenamescip-shell system . . basename. $0) --arch [arm|arm64] [options]" |
| 5 | echoscip-shell system . . echo. -e "Starts QEMU system mode emulation for the architecture.\n" |
| 6 | echoscip-shell system . . echo. -e " --help\t\t\tDisplay this information." |
| 7 | echoscip-shell system . . echo. -e " --arch {arm|arm64}\t\tSelects architecture QEMU system emulation." |
| 8 | echoscip-shell system . . echo. -e " --sve\t\t\t\tEnables AArch64 SVE mode." |
| 9 | echoscip-shell system . . echo. -e " --mte\t\t\t\tEnables AArch64 MTE mode." |
| 10 | echoscip-shell system . . echo. -e " --sme\t\t\t\tEnables AArch64 SME mode." |
| 11 | echoscip-shell system . . echo. -e " --rootfs {path}\t\tPath of root file system image." |
| 12 | echoscip-shell system . . echo. -e " --qemu {path}\t\t\tPath of pre-installed qemu-system-* executable." |
| 13 | echoscip-shell system . . echo. -e " --kernel {path}\t\tPath of Linux kernel prebuilt image.\n" |
| 14 | echoscip-shell system . . echo. -e "By default this utility will use:" |
| 15 | echoscip-shell system . . echo. -e " QEMU image built from source in qemu.git directory" |
| 16 | echoscip-shell system . . echo. -e " Linux kernel image from linux.build/(arm or arm64) directory." |
| 17 | echoscip-shell system . . echo. -e "Custom Linux kernel image or QEMU binary can be provided using commandline." |
| 18 | exit "$1" |
| 19 | } |
| 20 | |
| 21 | invalid_argscip-shell shell llvm-toolchain-22 1:22.1.7-1 invalid_arg().() { |
| 22 | echoscip-shell system . . echo. "ERROR: Unrecognized argument: $1" >&2 |
| 23 | print_usagescip-shell shell llvm-toolchain-22 1:22.1.7-1 print_usage(). 1 |
| 24 | } |
| 25 | |
| 26 | run_qemuscip-shell shell llvm-toolchain-22 1:22.1.7-1 run_qemu().() { |
| 27 | QEMU_CORES=2 |
| 28 | QEMU_MEMORY=1024 |
| 29 | |
| 30 | $QEMU_BIN \ |
| 31 | -cpu $QEMU_CPU \ |
| 32 | -m $QEMU_MEMORY \ |
| 33 | -smp $QEMU_CORES \ |
| 34 | -kernel $KERNEL_IMG \ |
| 35 | -machine $QEMU_MACHINE \ |
| 36 | -drive file=$ROOTFS_IMG,if=none,format=raw,id=hd0 \ |
| 37 | -device virtio-blk-device,drive=hd0 \ |
| 38 | -append "root=/dev/vda rw ip=dhcp mem=1024M raid=noautodetect \ |
| 39 | crashkernel=128M rootwait console=ttyAMA0 devtmpfs.mount=0" \ |
| 40 | -netdev type=tap,id=net0 \ |
| 41 | -device virtio-net-device,netdev=net0 \ |
| 42 | -nographic |
| 43 | } |
| 44 | |
| 45 | # Parse options |
| 46 | while [[ $# -gt 0 ]]; do |
| 47 | case "${END_OF_OPT}${1}" in |
| 48 | --arch) ARCH=$2; shift;; |
| 49 | --rootfs) ROOTFS_IMG=$2; shift;; |
| 50 | --kernel) KERNEL_IMG=$2; shift;; |
| 51 | --qemu) QEMU_BIN=$2; shift;; |
| 52 | --sve) SVE=1;; |
| 53 | --mte) MTE=1;; |
| 54 | --sme) SME=1;; |
| 55 | --help) print_usagescip-shell shell llvm-toolchain-22 1:22.1.7-1 print_usage(). 0 ;; |
| 56 | *) invalid_argscip-shell shell llvm-toolchain-22 1:22.1.7-1 invalid_arg(). "$1" ;; |
| 57 | esac |
| 58 | shift |
| 59 | done |
| 60 | |
| 61 | if [scip-shell system . . `[`. "$ARCH" == "arm64" ] && [scip-shell system . . `[`. "$ARCH" == "arm" ]; then |
| 62 | echoscip-shell system . . echo. "Invalid architecture: $ARCH" |
| 63 | print_usagescip-shell shell llvm-toolchain-22 1:22.1.7-1 print_usage(). 1 |
| 64 | fi |
| 65 | |
| 66 | if [[ ! -f "$ROOTFS_IMG" ]]; then |
| 67 | echoscip-shell system . . echo. "No root file system image image available for emulation." |
| 68 | exit |
| 69 | fi |
| 70 | |
| 71 | if [[ ! -f "$KERNEL_IMG" ]]; then |
| 72 | KERNEL_IMG_PATH=$(pwdscip-shell system . . pwd.)/linux.build/"$ARCH"/arch/"$ARCH"/boot/ |
| 73 | |
| 74 | if [[ ! -d "$KERNEL_IMG_PATH" ]]; then |
| 75 | echoscip-shell system . . echo. "No Linux kernel image available for emulation." |
| 76 | exit |
| 77 | fi |
| 78 | |
| 79 | if [[ "$ARCH" == "arm" ]]; then |
| 80 | KERNEL_IMG=$KERNEL_IMG_PATH/zImage |
| 81 | elif [[ "$ARCH" == "arm64" ]]; then |
| 82 | KERNEL_IMG=$KERNEL_IMG_PATH/Image |
| 83 | fi |
| 84 | fi |
| 85 | |
| 86 | if [[ ! -f "$QEMU_BIN" ]]; then |
| 87 | if [[ "$ARCH" == "arm" ]]; then |
| 88 | QEMU_BIN=$(pwdscip-shell system . . pwd.)/qemu.git/arm-softmmu/qemu-system-arm |
| 89 | elif [[ "$ARCH" == "arm64" ]]; then |
| 90 | QEMU_BIN=$(pwdscip-shell system . . pwd.)/qemu.git/aarch64-softmmu/qemu-system-aarch64 |
| 91 | fi |
| 92 | |
| 93 | if [[ ! -f "$QEMU_BIN" ]]; then |
| 94 | echoscip-shell system . . echo. "QEMU $ARCH system emulation executable not found." |
| 95 | exit |
| 96 | fi |
| 97 | fi |
| 98 | |
| 99 | if [[ "$ARCH" == "arm" ]]; then |
| 100 | QEMU_MACHINE="virt,highmem=off" |
| 101 | QEMU_CPU="cortex-a15" |
| 102 | |
| 103 | if [[ $SVE ]]; then |
| 104 | echoscip-shell system . . echo. "warning: --sve is supported by AArch64 targets only" |
| 105 | fi |
| 106 | if [[ $MTE ]]; then |
| 107 | echoscip-shell system . . echo. "warning: --mte is supported by AArch64 targets only" |
| 108 | fi |
| 109 | if [[ $SME ]]; then |
| 110 | echoscip-shell system . . echo. "warning: --sme is supported by AArch64 targets only" |
| 111 | fi |
| 112 | elif [[ "$ARCH" == "arm64" ]]; then |
| 113 | QEMU_MACHINE=virt |
| 114 | QEMU_SVE_MAX_VQ=4 |
| 115 | QEMU_CPU="cortex-a53" |
| 116 | |
| 117 | if [[ $SVE ]] || [[ $MTE ]] || [[ $SME ]]; then |
| 118 | QEMU_CPU="max" |
| 119 | fi |
| 120 | |
| 121 | if [[ $SVE ]] || [[ $SME ]]; then |
| 122 | QEMU_CPU="$QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ" |
| 123 | fi |
| 124 | if [[ $MTE ]]; then |
| 125 | QEMU_MACHINE="$QEMU_MACHINE,mte=on" |
| 126 | fi |
| 127 | fi |
| 128 | |
| 129 | run_qemuscip-shell shell llvm-toolchain-22 1:22.1.7-1 run_qemu(). |