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.

85 lines
1.7 KiB

  1. #!/bin/bash
  2. RED='\033[0;31m'
  3. GREEN='\033[0;32m'
  4. NC='\033[0m'
  5. set -e
  6. have_input_image=0
  7. usage()
  8. {
  9. echo "Usage: $0 -i <4mb_top_image>.rom"
  10. }
  11. args=$(getopt -o i:h -- "$@")
  12. if [ $? -ne 0 ] ; then
  13. usage
  14. exit 1
  15. fi
  16. eval set -- "$args"
  17. while [ $# -gt 0 ]
  18. do
  19. case "$1" in
  20. -i)
  21. INPUT_IMAGE=$2
  22. have_input_image=1
  23. shift
  24. ;;
  25. -h)
  26. usage
  27. exit 1
  28. ;;
  29. --)
  30. shift
  31. break
  32. ;;
  33. *)
  34. echo "Invalid option: $1"
  35. exit 1
  36. ;;
  37. esac
  38. shift
  39. done
  40. OUTPUT_IMAGE=${INPUT_IMAGE%%.*}_prepared_12mb.rom
  41. if [ "$have_input_image" -gt 0 ] ; then
  42. echo "creating"
  43. echo "output/${OUTPUT_IMAGE}"
  44. echo "from"
  45. echo "${INPUT_IMAGE}"
  46. echo "---------------------------------------------------------"
  47. else
  48. echo "no input image provided"
  49. usage
  50. exit 1
  51. fi
  52. input_filesize=$(wc -c <"$INPUT_IMAGE")
  53. reference_filesize=4194304
  54. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  55. echo "Error: input file must be 4MB of size"
  56. exit 1
  57. fi
  58. rm -rf output
  59. mkdir output && cd output
  60. dd if=/dev/zero of=${OUTPUT_IMAGE} bs=4M count=2
  61. cp ../${INPUT_IMAGE} .
  62. dd if=${INPUT_IMAGE} oflag=append conv=notrunc of=${OUTPUT_IMAGE} bs=4M
  63. echo "0x00000000:0x007fffff ifdmegbe" > x230-layout.txt
  64. echo "0x00800000:0x00bfffff bios" >> x230-layout.txt
  65. rm ${INPUT_IMAGE}
  66. echo "---------------------------------------------------------"
  67. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  68. echo ""
  69. echo "prepared files for internal flashing in output directory."
  70. echo "template flashrom command (please adapt the chip name) :"
  71. echo ""
  72. echo "cd output"
  73. echo -e "${GREEN}flashrom -p internal:laptop=force_I_want_a_brick,spispeed=128 --layout x230-layout.txt --image bios -c "MX25L3206E" -w ${OUTPUT_IMAGE}${NC}"