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.8 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 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 the BIOS with the given image."
  13. echo " Make sure you booted Linux with iomem=relaxed"
  14. echo ""
  15. echo "Usage: $0 -i <4mb_top_image>.rom"
  16. }
  17. args=$(getopt -o i:h -- "$@")
  18. if [ $? -ne 0 ] ; then
  19. usage
  20. exit 1
  21. fi
  22. eval set -- "$args"
  23. while [ $# -gt 0 ]
  24. do
  25. case "$1" in
  26. -i)
  27. INPUT_IMAGE_PATH=$2
  28. have_input_image=1
  29. shift
  30. ;;
  31. -h)
  32. usage
  33. exit 1
  34. ;;
  35. --)
  36. shift
  37. break
  38. ;;
  39. *)
  40. echo "Invalid option: $1"
  41. exit 1
  42. ;;
  43. esac
  44. shift
  45. done
  46. force_x230_and_root
  47. if [ ! "$have_input_image" -gt 0 ] ; then
  48. image_available=$(ls -1 | grep x230_coreboot_seabios || true)
  49. if [ -z "${image_available}" ] ; then
  50. echo "No image file found. Please add -i <file>"
  51. echo ""
  52. usage
  53. exit 1
  54. fi
  55. prompt="file not specified. Please select a file to flash. Please read the README for details about the differences:"
  56. options=( $(find -maxdepth 1 -name "x230_coreboot_seabios*rom" -print0 | xargs -0) )
  57. PS3="$prompt "
  58. select INPUT_IMAGE_PATH in "${options[@]}" "Quit" ; do
  59. if (( REPLY == 1 + ${#options[@]} )) ; then
  60. exit
  61. elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  62. break
  63. else
  64. echo "Invalid option. Try another one."
  65. fi
  66. done
  67. fi
  68. OUTPUT_PATH=output
  69. INPUT_IMAGE_NAME=$(basename "${INPUT_IMAGE_PATH}")
  70. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared_12mb.rom
  71. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  72. echo -e "input: ${INPUT_IMAGE_NAME}"
  73. echo -e "output: ${OUTPUT_IMAGE_PATH}"
  74. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  75. reference_filesize=4194304
  76. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  77. echo "Error: input file must be 4MB of size"
  78. exit 1
  79. fi
  80. rm -rf ${OUTPUT_PATH}
  81. mkdir ${OUTPUT_PATH}
  82. dd if=/dev/zero of="${OUTPUT_IMAGE_PATH}" bs=4M count=2 status=none
  83. dd if="${INPUT_IMAGE_PATH}" oflag=append conv=notrunc of="${OUTPUT_IMAGE_PATH}" bs=4M status=none
  84. LAYOUT_FILENAME="x230-layout.txt"
  85. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  86. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  87. echo -e "${YELLOW}WARNING${NC}: Make sure not to power off your computer or interrupt this process in any way!"
  88. echo -e " Interrupting this process may result in irreparable damage to your computer!"
  89. check_battery
  90. while true; do
  91. read -r -p "Flash the BIOS now? y/N: " yn
  92. case $yn in
  93. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  94. [Nn]* ) exit;;
  95. * ) exit;;
  96. esac
  97. done
  98. while true; do
  99. read -r -p "Reboot now? (please do!) Y/n: " yn
  100. case $yn in
  101. [Yy]* ) reboot ;;
  102. [Nn]* ) exit;;
  103. * ) reboot;;
  104. esac
  105. done