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.

83 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_PATH=$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. if [ ! "$have_input_image" -gt 0 ] ; then
  41. echo "no input image provided"
  42. usage
  43. exit 1
  44. fi
  45. OUTPUT_PATH=output
  46. INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH})
  47. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared_12mb.rom
  48. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  49. echo -e "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  50. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  51. reference_filesize=4194304
  52. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  53. echo "Error: input file must be 4MB of size"
  54. exit 1
  55. fi
  56. rm -rf output
  57. mkdir output
  58. dd if=/dev/zero of=${OUTPUT_IMAGE_PATH} bs=4M count=2
  59. dd if=${INPUT_IMAGE_PATH} oflag=append conv=notrunc of=${OUTPUT_IMAGE_PATH} bs=4M
  60. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/x230-layout.txt
  61. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/x230-layout.txt
  62. echo "---------------------------------------------------------"
  63. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  64. echo ""
  65. echo "prepared files for internal flashing in output directory."
  66. echo "template flashrom command (please adapt the chip name) :"
  67. echo ""
  68. echo "cd output"
  69. echo -e "${GREEN}flashrom -p internal --layout x230-layout.txt --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"