post-image.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # shellcheck disable=SC2086 # glob over each readme file
  13. QEMU_CMD_LINE="$(sed -r ':a; /\\$/N; s/\\\n//; s/\t/ /; ta; /# '"${DEFCONFIG_NAME}"'$/!d; s/#.*//' ${README_FILES})"
  14. if [ -z "${QEMU_CMD_LINE}" ]; then
  15. # No Qemu cmd line found, can't test.
  16. exit 0
  17. fi
  18. # Remove output/images path since the script will be in
  19. # the same directory as the kernel and the rootfs images.
  20. QEMU_CMD_LINE="${QEMU_CMD_LINE//output\/images\//}"
  21. # Remove -serial stdio if present, keep it as default args
  22. DEFAULT_ARGS="$(sed -r -e '/-serial stdio/!d; s/.*(-serial stdio).*/\1/' <<<"${QEMU_CMD_LINE}")"
  23. QEMU_CMD_LINE="${QEMU_CMD_LINE//-serial stdio/}"
  24. # Remove any string before qemu-system-*
  25. QEMU_CMD_LINE="$(sed -r -e 's/^.*(qemu-system-)/\1/' <<<"${QEMU_CMD_LINE}")"
  26. # Disable graphical output and redirect serial I/Os to console
  27. case ${DEFCONFIG_NAME} in
  28. (qemu_sh4eb_r2d_defconfig|qemu_sh4_r2d_defconfig)
  29. # Special case for SH4
  30. SERIAL_ARGS="-serial stdio -display none"
  31. ;;
  32. (*)
  33. SERIAL_ARGS="-nographic"
  34. ;;
  35. esac
  36. sed -e "s|@SERIAL_ARGS@|${SERIAL_ARGS}|g" \
  37. -e "s|@DEFAULT_ARGS@|${DEFAULT_ARGS}|g" \
  38. -e "s|@QEMU_CMD_LINE@|${QEMU_CMD_LINE}|g" \
  39. -e "s|@HOST_DIR@|${HOST_DIR}|g" \
  40. <"${QEMU_BOARD_DIR}/start-qemu.sh.in" \
  41. >"${START_QEMU_SCRIPT}"
  42. chmod +x "${START_QEMU_SCRIPT}"