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.

98 lines
2.2 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. echo "no input image provided"
  49. usage
  50. exit 1
  51. fi
  52. OUTPUT_PATH=output
  53. INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH})
  54. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared_12mb.rom
  55. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  56. echo -e "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  57. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  58. reference_filesize=4194304
  59. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  60. echo "Error: input file must be 4MB of size"
  61. exit 1
  62. fi
  63. rm -rf output
  64. mkdir output
  65. dd if=/dev/zero of=${OUTPUT_IMAGE_PATH} bs=4M count=2
  66. dd if=${INPUT_IMAGE_PATH} oflag=append conv=notrunc of=${OUTPUT_IMAGE_PATH} bs=4M
  67. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/x230-layout.txt
  68. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/x230-layout.txt
  69. echo "---------------------------------------------------------"
  70. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  71. echo ""
  72. echo "prepared files for internal flashing in output directory."
  73. echo "template flashrom command (please adapt the chip name) :"
  74. echo ""
  75. echo -e "${GREEN}cd output${NC}"
  76. echo -e "${GREEN}flashrom -p internal --layout x230-layout.txt --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"
  77. while true; do
  78. read -p "Do you wish to run this now? y/N: " yn
  79. case $yn in
  80. [Yy]* ) cd output && flashrom -p internal --layout x230-layout.txt --image bios -w ${OUTPUT_IMAGE_NAME}; break;;
  81. [Nn]* ) exit;;
  82. * ) exit;;
  83. esac
  84. done