You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.9 KiB

  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0+
  3. # Copyright (C) 2018, Martin Kepplinger <martink@posteo.de>
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. YELLOW='\033[0;33m'
  7. NC='\033[0m'
  8. set -e
  9. have_input_image=0
  10. usage()
  11. {
  12. echo "Skulls for the X230"
  13. echo " Run this script on the X230 directly."
  14. echo ""
  15. echo " This flashes Heads to your BIOS, see http://osresearch.net"
  16. echo " Heads is a different project. No image is included."
  17. echo " Read https://github.com/osresearch/heads for how to build it"
  18. echo " Make sure you booted Linux with iomem=relaxed"
  19. echo ""
  20. echo "Usage: $0 -i <heads_image>.rom"
  21. }
  22. args=$(getopt -o i:h -- "$@")
  23. if [ $? -ne 0 ] ; then
  24. usage
  25. exit 1
  26. fi
  27. eval set -- "$args"
  28. while [ $# -gt 0 ]
  29. do
  30. case "$1" in
  31. -i)
  32. INPUT_IMAGE_PATH=$2
  33. have_input_image=1
  34. shift
  35. ;;
  36. -h)
  37. usage
  38. exit 1
  39. ;;
  40. --)
  41. shift
  42. break
  43. ;;
  44. *)
  45. echo "Invalid option: $1"
  46. exit 1
  47. ;;
  48. esac
  49. shift
  50. done
  51. if [ ! "$have_input_image" -gt 0 ] ; then
  52. image_available=$(ls -1 | grep rom || true)
  53. if [ -z "${image_available}" ] ; then
  54. echo "No image file found. Please add -i <file>"
  55. echo ""
  56. usage
  57. exit 1
  58. fi
  59. prompt="file not specified. Please select a file to flash:"
  60. options=( $(find -maxdepth 1 -name "*rom" -print0 | xargs -0) )
  61. PS3="$prompt "
  62. select INPUT_IMAGE_PATH in "${options[@]}" "Quit" ; do
  63. if (( REPLY == 1 + ${#options[@]} )) ; then
  64. exit
  65. elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  66. break
  67. else
  68. echo "Invalid option. Try another one."
  69. fi
  70. done
  71. fi
  72. OUTPUT_PATH=output
  73. INPUT_IMAGE_NAME=$(basename "${INPUT_IMAGE_PATH}")
  74. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared.rom
  75. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  76. echo -e "input: ${INPUT_IMAGE_NAME}"
  77. echo -e "output: ${OUTPUT_IMAGE_PATH}"
  78. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  79. reference_filesize=12582912
  80. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  81. echo "Error: input file must be 12MB of size"
  82. exit 1
  83. fi
  84. rm -rf ${OUTPUT_PATH}
  85. mkdir ${OUTPUT_PATH}
  86. cp "${INPUT_IMAGE_PATH}" "${OUTPUT_IMAGE_PATH}"
  87. LAYOUT_FILENAME="x230-layout-heads.txt"
  88. echo "0x00000000:0x00000fff ifd" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  89. echo "0x00001000:0x00002fff gbe" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  90. echo "0x00003000:0x004fffff me" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  91. echo "0x00500000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  92. echo -e "${YELLOW}WARNING${NC}: Make sure not to power off your computer or interrupt this process in any way!"
  93. echo -e " Interrupting this process may result in irreparable damage to your computer!"
  94. while true; do
  95. read -r -p "Flash the BIOS now? y/N: " yn
  96. case $yn in
  97. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  98. [Nn]* ) exit;;
  99. * ) exit;;
  100. esac
  101. done
  102. while true; do
  103. read -r -p "Reboot now? (please do!) y/N: " yn
  104. case $yn in
  105. [Yy]* ) reboot ;;
  106. [Nn]* ) exit;;
  107. * ) exit;;
  108. esac
  109. done