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.

121 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. 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 " It installs Heads, see http://osresearch.net"
  14. echo " Make sure you booted Linux with iomem=relaxed"
  15. echo ""
  16. echo "Usage: $0 -i <heads_image>.rom"
  17. }
  18. args=$(getopt -o i:h -- "$@")
  19. if [ $? -ne 0 ] ; then
  20. usage
  21. exit 1
  22. fi
  23. eval set -- "$args"
  24. while [ $# -gt 0 ]
  25. do
  26. case "$1" in
  27. -i)
  28. INPUT_IMAGE_PATH=$2
  29. have_input_image=1
  30. shift
  31. ;;
  32. -h)
  33. usage
  34. exit 1
  35. ;;
  36. --)
  37. shift
  38. break
  39. ;;
  40. *)
  41. echo "Invalid option: $1"
  42. exit 1
  43. ;;
  44. esac
  45. shift
  46. done
  47. if [ ! "$have_input_image" -gt 0 ] ; then
  48. image_available=$(ls -1 | grep rom || 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:"
  56. options=( $(find -maxdepth 1 -name "*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. echo "You picked $INPUT_IMAGE_PATH which is file $REPLY"
  63. break
  64. else
  65. echo "Invalid option. Try another one."
  66. fi
  67. done
  68. fi
  69. OUTPUT_PATH=output
  70. INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH})
  71. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared.rom
  72. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  73. echo -e "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  74. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  75. reference_filesize=12582912
  76. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  77. echo "Error: input file must be 12MB of size"
  78. exit 1
  79. fi
  80. rm -rf ${OUTPUT_PATH}
  81. mkdir ${OUTPUT_PATH}
  82. cp ${INPUT_IMAGE_PATH} ${OUTPUT_IMAGE_PATH}
  83. LAYOUT_FILENAME="x230-layout-heads.txt"
  84. echo "0x00000000:0x00000fff ifd" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  85. echo "0x00001000:0x00002fff gbe" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  86. echo "0x00003000:0x004fffff me" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  87. echo "0x00500000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  88. echo "---------------------------------------------------------"
  89. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  90. echo ""
  91. echo "prepared files for internal flashing in output directory."
  92. echo "template flashrom command (please adapt the chip name) :"
  93. echo ""
  94. echo -e "${GREEN}cd output${NC}"
  95. echo -e "${GREEN}flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"
  96. while true; do
  97. read -p "Do you wish to run this now? y/N: " yn
  98. case $yn in
  99. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}; break;;
  100. [Nn]* ) exit;;
  101. * ) exit;;
  102. esac
  103. done