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.

131 lines
2.9 KiB

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