post-image.sh 1.7 KB

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