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.

119 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 updates Skulls to the image you want."
  14. echo " Make sure you booted Linux with iomem=relaxed"
  15. echo ""
  16. echo "Usage: $0 -i <4mb_top_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 x230_coreboot_seabios || 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 "x230_coreboot_seabios*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_12mb.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=4194304
  76. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  77. echo "Error: input file must be 4MB of size"
  78. exit 1
  79. fi
  80. rm -rf ${OUTPUT_PATH}
  81. mkdir ${OUTPUT_PATH}
  82. dd if=/dev/zero of=${OUTPUT_IMAGE_PATH} bs=4M count=2
  83. dd if=${INPUT_IMAGE_PATH} oflag=append conv=notrunc of=${OUTPUT_IMAGE_PATH} bs=4M
  84. LAYOUT_FILENAME="x230-layout.txt"
  85. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  86. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/${LAYOUT_FILENAME}
  87. echo "---------------------------------------------------------"
  88. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  89. echo ""
  90. echo "prepared files in output directory. To flash them:"
  91. echo -e "${GREEN}cd output${NC}"
  92. echo -e "${GREEN}flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"
  93. while true; do
  94. read -p "Do you wish to run this now? y/N: " yn
  95. case $yn in
  96. [Yy]* ) cd output && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w ${OUTPUT_IMAGE_NAME}; break;;
  97. [Nn]* ) exit;;
  98. * ) exit;;
  99. esac
  100. done