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.

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