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.

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