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.

143 lines
3.4 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. BIOS_VENDOR=$(dmidecode -t bios | grep Vendor | cut -d':' -f2)
  48. if [[ $BIOS_VENDOR != *"coreboot"* ]] ; then
  49. BIOS_VERSION=$(dmidecode -s bios-version | grep -o '[1-2].[0-7][0-9]')
  50. bios_major=$(echo "$BIOS_VERSION" | cut -d. -f1)
  51. bios_minor=$(echo "$BIOS_VERSION" | cut -d. -f2)
  52. if [ "${bios_minor}" -ge "60" ] ; then
  53. echo "Ready to use external_install_bottom.sh and external_install_top.sh"
  54. echo "Please run both scripts from a different computer with a"
  55. echo "hardware SPI flasher."
  56. else
  57. echo -e "The installed original BIOS is very old."
  58. echo -e "${RED}Please upgrade${NC} from lenovo.com before installing coreboot."
  59. fi
  60. exit 0
  61. fi
  62. if [ ! "$have_input_image" -gt 0 ] ; then
  63. image_available=$(ls -1 | grep x230_coreboot_seabios || true)
  64. if [ -z "${image_available}" ] ; then
  65. echo "No image file found. Please add -i <file>"
  66. echo ""
  67. usage
  68. exit 1
  69. fi
  70. prompt="file not specified. Please select a file to flash. Please read the README for details about the differences:"
  71. options=( $(find -maxdepth 1 -name "x230_coreboot_seabios*rom" -print0 | xargs -0) )
  72. PS3="$prompt "
  73. select INPUT_IMAGE_PATH in "${options[@]}" "Quit" ; do
  74. if (( REPLY == 1 + ${#options[@]} )) ; then
  75. exit
  76. elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  77. break
  78. else
  79. echo "Invalid option. Try another one."
  80. fi
  81. done
  82. fi
  83. OUTPUT_PATH=output
  84. INPUT_IMAGE_NAME=$(basename "${INPUT_IMAGE_PATH}")
  85. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared_12mb.rom
  86. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  87. echo -e "input: ${INPUT_IMAGE_NAME}"
  88. echo -e "output: ${OUTPUT_IMAGE_PATH}"
  89. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  90. reference_filesize=4194304
  91. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  92. echo "Error: input file must be 4MB of size"
  93. exit 1
  94. fi
  95. rm -rf ${OUTPUT_PATH}
  96. mkdir ${OUTPUT_PATH}
  97. dd if=/dev/zero of="${OUTPUT_IMAGE_PATH}" bs=4M count=2 status=none
  98. dd if="${INPUT_IMAGE_PATH}" oflag=append conv=notrunc of="${OUTPUT_IMAGE_PATH}" bs=4M status=none
  99. LAYOUT_FILENAME="x230-layout.txt"
  100. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  101. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  102. echo -e "${YELLOW}WARNING${NC}: Make sure not to power off your computer or interrupt this process in any way!"
  103. echo -e " Interrupting this process may result in irreparable damage to your computer!"
  104. check_battery
  105. while true; do
  106. read -r -p "Flash the BIOS now? y/N: " yn
  107. case $yn in
  108. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  109. [Nn]* ) exit;;
  110. * ) exit;;
  111. esac
  112. done
  113. while true; do
  114. read -r -p "Reboot now? (please do!) Y/n: " yn
  115. case $yn in
  116. [Yy]* ) reboot ;;
  117. [Nn]* ) exit;;
  118. * ) reboot;;
  119. esac
  120. done