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.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 "Usage: $0 -i <4mb_top_image>.rom"
  12. }
  13. args=$(getopt -o i:h -- "$@")
  14. if [ $? -ne 0 ] ; then
  15. usage
  16. exit 1
  17. fi
  18. eval set -- "$args"
  19. while [ $# -gt 0 ]
  20. do
  21. case "$1" in
  22. -i)
  23. INPUT_IMAGE_PATH=$2
  24. have_input_image=1
  25. shift
  26. ;;
  27. -h)
  28. usage
  29. exit 1
  30. ;;
  31. --)
  32. shift
  33. break
  34. ;;
  35. *)
  36. echo "Invalid option: $1"
  37. exit 1
  38. ;;
  39. esac
  40. shift
  41. done
  42. if [ ! "$have_input_image" -gt 0 ] ; then
  43. echo "no input image provided"
  44. usage
  45. exit 1
  46. fi
  47. OUTPUT_PATH=output
  48. INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH})
  49. OUTPUT_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared_12mb.rom
  50. OUTPUT_IMAGE_PATH=${OUTPUT_PATH}/${OUTPUT_IMAGE_NAME}
  51. echo -e "creating ${GREEN}${OUTPUT_IMAGE_PATH}${NC} from ${INPUT_IMAGE_NAME}"
  52. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  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
  60. dd if=/dev/zero of=${OUTPUT_IMAGE_PATH} bs=4M count=2
  61. dd if=${INPUT_IMAGE_PATH} oflag=append conv=notrunc of=${OUTPUT_IMAGE_PATH} bs=4M
  62. echo "0x00000000:0x007fffff ifdmegbe" > ${OUTPUT_PATH}/x230-layout.txt
  63. echo "0x00800000:0x00bfffff bios" >> ${OUTPUT_PATH}/x230-layout.txt
  64. echo "---------------------------------------------------------"
  65. echo -e "${RED}CAUTION: internal flashing is NOT encouraged${NC}"
  66. echo ""
  67. echo "prepared files for internal flashing in output directory."
  68. echo "template flashrom command (please adapt the chip name) :"
  69. echo ""
  70. echo "cd output"
  71. echo -e "${GREEN}flashrom -p internal --layout x230-layout.txt --image bios -w ${OUTPUT_IMAGE_NAME}${NC}"