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.

122 lines
2.9 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. NC='\033[0m'
  7. set -e
  8. have_input_image=0
  9. usage()
  10. {
  11. echo "Skulls for the X230"
  12. echo " Run this script on the X230 directly."
  13. echo ""
  14. echo " This installs Heads, see http://osresearch.net"
  15. echo " Heads is a different project. No image is included."
  16. echo " Read https://github.com/osresearch/heads for how to build it"
  17. echo " Make sure you booted Linux with iomem=relaxed"
  18. echo ""
  19. echo "Usage: $0 -i <heads_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. 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. echo "You picked $INPUT_IMAGE_PATH which is file $REPLY"
  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.rom
  75. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  76. echo -e "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  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 "---------------------------------------------------------"
  92. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  93. echo ""
  94. echo "prepared files in output directory. To flash them:"
  95. echo -e "${GREEN}cd output${NC}"
  96. echo -e "${GREEN}flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"
  97. while true; do
  98. read -r -p "Do you wish to run this now? y/N: " yn
  99. case $yn in
  100. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  101. [Nn]* ) exit;;
  102. * ) exit;;
  103. esac
  104. done