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.

124 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. have_input_image=0
  10. usage()
  11. {
  12. echo "Skulls for the X230"
  13. echo " Run this script on the X230 directly."
  14. echo ""
  15. echo " This flashes the BIOS with the given image."
  16. echo " Make sure you booted Linux with iomem=relaxed"
  17. echo ""
  18. echo "Usage: $0 -i <4mb_top_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. if [ ! "$have_input_image" -gt 0 ] ; then
  50. image_available=$(ls -1 | grep x230_coreboot_seabios || 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 "x230_coreboot_seabios*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_12mb.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=4194304
  78. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  79. echo "Error: input file must be 4MB of size"
  80. exit 1
  81. fi
  82. rm -rf ${OUTPUT_PATH}
  83. mkdir ${OUTPUT_PATH}
  84. dd if=/dev/zero of="${OUTPUT_IMAGE_PATH}" bs=4M count=2 status=none
  85. dd if="${INPUT_IMAGE_PATH}" oflag=append conv=notrunc of="${OUTPUT_IMAGE_PATH}" bs=4M status=none
  86. LAYOUT_FILENAME="x230-layout.txt"
  87. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  88. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  89. echo -e "${YELLOW}WARNING${NC}: Make sure not to power off your computer or interrupt this process in any way!"
  90. echo -e " Interrupting this process may result in irreparable damage to your computer!"
  91. while true; do
  92. read -r -p "Flash the BIOS now? y/N: " yn
  93. case $yn in
  94. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  95. [Nn]* ) exit;;
  96. * ) exit;;
  97. esac
  98. done
  99. while true; do
  100. read -r -p "Reboot now? (please do!) y/N: " yn
  101. case $yn in
  102. [Yy]* ) reboot ;;
  103. [Nn]* ) exit;;
  104. * ) exit;;
  105. esac
  106. done