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.

130 lines
2.8 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 the BIOS with the given image."
  17. echo " Make sure you booted Linux with iomem=relaxed"
  18. echo ""
  19. echo "Usage: $0 -i <4mb_top_image>.rom"
  20. }
  21. args=$(getopt -o i:h -- "$@")
  22. if [ $? -ne 0 ] ; then
  23. usage
  24. exit 1
  25. fi
  26. eval set -- "$args"
  27. while [ $# -gt 0 ]
  28. do
  29. case "$1" in
  30. -i)
  31. INPUT_IMAGE_PATH=$2
  32. have_input_image=1
  33. shift
  34. ;;
  35. -h)
  36. usage
  37. exit 1
  38. ;;
  39. --)
  40. shift
  41. break
  42. ;;
  43. *)
  44. echo "Invalid option: $1"
  45. exit 1
  46. ;;
  47. esac
  48. shift
  49. done
  50. check_x230_root
  51. if [ ! "$have_input_image" -gt 0 ] ; then
  52. image_available=$(ls -1 | grep x230_coreboot_seabios || 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 "x230_coreboot_seabios*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_12mb.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=4194304
  80. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  81. echo "Error: input file must be 4MB of size"
  82. exit 1
  83. fi
  84. rm -rf ${OUTPUT_PATH}
  85. mkdir ${OUTPUT_PATH}
  86. dd if=/dev/zero of="${OUTPUT_IMAGE_PATH}" bs=4M count=2 status=none
  87. dd if="${INPUT_IMAGE_PATH}" oflag=append conv=notrunc of="${OUTPUT_IMAGE_PATH}" bs=4M status=none
  88. LAYOUT_FILENAME="x230-layout.txt"
  89. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  90. echo "0x00800000: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 && 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. * ) reboot;;
  108. esac
  109. done