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.

120 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 ""
  14. echo " This updates Skulls to the given image."
  15. echo " Make sure you booted Linux with iomem=relaxed"
  16. echo ""
  17. echo "Usage: $0 -i <4mb_top_image>.rom"
  18. }
  19. args=$(getopt -o i:h -- "$@")
  20. if [ $? -ne 0 ] ; then
  21. usage
  22. exit 1
  23. fi
  24. eval set -- "$args"
  25. while [ $# -gt 0 ]
  26. do
  27. case "$1" in
  28. -i)
  29. INPUT_IMAGE_PATH=$2
  30. have_input_image=1
  31. shift
  32. ;;
  33. -h)
  34. usage
  35. exit 1
  36. ;;
  37. --)
  38. shift
  39. break
  40. ;;
  41. *)
  42. echo "Invalid option: $1"
  43. exit 1
  44. ;;
  45. esac
  46. shift
  47. done
  48. if [ ! "$have_input_image" -gt 0 ] ; then
  49. image_available=$(ls -1 | grep x230_coreboot_seabios || true)
  50. if [ -z "${image_available}" ] ; then
  51. echo "No image file found. Please add -i <file>"
  52. echo ""
  53. usage
  54. exit 1
  55. fi
  56. prompt="file not specified. Please select a file to flash:"
  57. options=( $(find -maxdepth 1 -name "x230_coreboot_seabios*rom" -print0 | xargs -0) )
  58. PS3="$prompt "
  59. select INPUT_IMAGE_PATH in "${options[@]}" "Quit" ; do
  60. if (( REPLY == 1 + ${#options[@]} )) ; then
  61. exit
  62. elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  63. echo "You picked $INPUT_IMAGE_PATH which is file $REPLY"
  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 "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  75. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  76. reference_filesize=4194304
  77. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  78. echo "Error: input file must be 4MB of size"
  79. exit 1
  80. fi
  81. rm -rf ${OUTPUT_PATH}
  82. mkdir ${OUTPUT_PATH}
  83. dd if=/dev/zero of="${OUTPUT_IMAGE_PATH}" bs=4M count=2
  84. dd if="${INPUT_IMAGE_PATH}" oflag=append conv=notrunc of="${OUTPUT_IMAGE_PATH}" bs=4M
  85. LAYOUT_FILENAME="x230-layout.txt"
  86. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  87. echo "0x00800000: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 in output directory. To flash them:"
  92. echo -e "${GREEN}cd output${NC}"
  93. echo -e "${GREEN}flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"
  94. while true; do
  95. read -r -p "Do you wish to run this now? y/N: " yn
  96. case $yn in
  97. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;;
  98. [Nn]* ) exit;;
  99. * ) exit;;
  100. esac
  101. done