1#!/bin/bash 2 3QEMU_BOARD_DIR="$(dirname $0)" 4DEFCONFIG_NAME="$(basename $2)" 5README_FILES="${QEMU_BOARD_DIR}/*/readme.txt" 6START_QEMU_SCRIPT="${BINARIES_DIR}/start-qemu.sh" 7 8if [[ "${DEFCONFIG_NAME}" =~ ^"qemu_*" ]]; then 9 # Not a Qemu defconfig, can't test. 10 exit 0 11fi 12 13# Search for "# qemu_*_defconfig" tag in all readme.txt files. 14# Qemu command line on multilines using back slash are accepted. 15QEMU_CMD_LINE=$(sed -r ':a; /\\$/N; s/\\\n//; s/\t/ /; ta; /# '${DEFCONFIG_NAME}'$/!d; s/#.*//' ${README_FILES}) 16 17if [ -z "${QEMU_CMD_LINE}" ]; then 18 # No Qemu cmd line found, can't test. 19 exit 0 20fi 21 22# Remove output/images path since the script will be in 23# the same directory as the kernel and the rootfs images. 24QEMU_CMD_LINE="${QEMU_CMD_LINE//output\/images\//}" 25 26# Remove -serial stdio if present, keep it as default args 27DEFAULT_ARGS="$(sed -r -e '/-serial stdio/!d; s/.*(-serial stdio).*/\1/' <<<"${QEMU_CMD_LINE}")" 28QEMU_CMD_LINE="${QEMU_CMD_LINE//-serial stdio/}" 29 30# Remove any string before qemu-system-* 31QEMU_CMD_LINE="$(sed -r -e 's/^.*(qemu-system-)/\1/' <<<"${QEMU_CMD_LINE}")" 32 33# Disable graphical output and redirect serial I/Os to console 34case ${DEFCONFIG_NAME} in 35 (qemu_sh4eb_r2d_defconfig|qemu_sh4_r2d_defconfig) 36 # Special case for SH4 37 SERIAL_ARGS="-serial stdio -display none" 38 ;; 39 (*) 40 SERIAL_ARGS="-nographic" 41 ;; 42esac 43 44cat <<-_EOF_ > "${START_QEMU_SCRIPT}" 45 #!/bin/sh 46 ( 47 BINARIES_DIR="\${0%/*}/" 48 cd \${BINARIES_DIR} 49 50 if [ "\${1}" = "serial-only" ]; then 51 EXTRA_ARGS='${SERIAL_ARGS}' 52 else 53 EXTRA_ARGS='${DEFAULT_ARGS}' 54 fi 55 56 export PATH="${HOST_DIR}/bin:\${PATH}" 57 exec ${QEMU_CMD_LINE} \${EXTRA_ARGS} 58 ) 59_EOF_ 60 61chmod +x "${START_QEMU_SCRIPT}" 62