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.

127 lines
2.8 KiB

  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0+
  3. # Copyright (C) 2019, Martin Kepplinger <martink@posteo.de>
  4. set -e
  5. cd "$(dirname "$0")"
  6. IFDTOOL=./util/ifdtool/ifdtool
  7. ME_CLEANER=./util/me_cleaner/me_cleaner.py
  8. have_input_image=0
  9. usage()
  10. {
  11. echo "EXPERIMENTAL"
  12. echo ""
  13. echo "This generates files for building Heads from your original 12M backup:"
  14. echo " (cat bottom.bin top.bin > full_backup_image.rom)"
  15. echo " ifd/me will be shrinked by me_cleaner and unlocked"
  16. echo ""
  17. echo " http://osresearch.net"
  18. echo ""
  19. echo "Usage: $0 -f <full_backup_image>.rom -i <ifdtool>(optional) -m <me_cleaner.py(optional)"
  20. }
  21. args=$(getopt -o f:m:i:h -- "$@")
  22. if [ $? -ne 0 ] ; then
  23. usage
  24. exit 1
  25. fi
  26. eval set -- "$args"
  27. while [ $# -gt 0 ]
  28. do
  29. case "$1" in
  30. -f)
  31. INPUT_IMAGE_PATH=$2
  32. have_input_image=1
  33. shift
  34. ;;
  35. -m)
  36. ME_CLEANER=$2
  37. shift
  38. ;;
  39. -i)
  40. IFDTOOL=$2
  41. shift
  42. ;;
  43. -h)
  44. usage
  45. exit 1
  46. ;;
  47. --)
  48. shift
  49. break
  50. ;;
  51. *)
  52. echo "Invalid option: $1"
  53. exit 1
  54. ;;
  55. esac
  56. shift
  57. done
  58. if [ ! "$have_input_image" -gt 0 ] ; then
  59. echo "No image file specified. Please add -f <file>"
  60. echo ""
  61. usage
  62. exit 1
  63. fi
  64. if [ ! -e ${IFDTOOL} ] ; then
  65. if [ ! -d util/ifdtool ] ; then
  66. echo "Please specify -i <ifdtool>"
  67. exit 1
  68. fi
  69. make -C util/ifdtool
  70. if [ ! -e ${IFDTOOL} ] ; then
  71. echo "Failed to build ifdtool"
  72. exit 1
  73. fi
  74. fi
  75. if [ ! -e ${ME_CLEANER} ] ; then
  76. mkdir -p util/me_cleaner
  77. curl -L https://raw.githubusercontent.com/corna/me_cleaner/v1.2/me_cleaner.py -o util/me_cleaner/me_cleaner.py
  78. if [ ! -e ${ME_CLEANER} ] ; then
  79. echo "Failed to download me_cleaner"
  80. exit 1
  81. fi
  82. fi
  83. OUTPUT_PATH=output
  84. INPUT_IMAGE_NAME=$(basename "${INPUT_IMAGE_PATH}")
  85. WORK_IMAGE_NAME=${INPUT_IMAGE_NAME%%.*}_prepared.rom
  86. input_filesize=$(wc -c <"$INPUT_IMAGE_PATH")
  87. reference_filesize=12582912
  88. if [ ! "$input_filesize" -eq "$reference_filesize" ] ; then
  89. echo "Error: input file must be 12MB of size"
  90. exit 1
  91. fi
  92. rm -rf ${OUTPUT_PATH}
  93. mkdir ${OUTPUT_PATH}
  94. cp "${INPUT_IMAGE_PATH}" "${OUTPUT_PATH}/${WORK_IMAGE_NAME}"
  95. ${IFDTOOL} -x "${OUTPUT_PATH}/${WORK_IMAGE_NAME}"
  96. mv flashregion*bin "${OUTPUT_PATH}/"
  97. cp "${OUTPUT_PATH}/flashregion_3_gbe.bin" "${OUTPUT_PATH}/gbe.bin"
  98. rm ${OUTPUT_PATH}/flashregion*bin
  99. python ${ME_CLEANER} -r -t -d -S -O "${OUTPUT_PATH}/unneeded_cleaned_image.bin" -D "${OUTPUT_PATH}/ifd_shrinked.bin" -M "${OUTPUT_PATH}/me.bin" "${OUTPUT_PATH}/${WORK_IMAGE_NAME}"
  100. rm "${OUTPUT_PATH}/unneeded_cleaned_image.bin"
  101. ${IFDTOOL} -u "${OUTPUT_PATH}/ifd_shrinked.bin"
  102. mv "${OUTPUT_PATH}/ifd_shrinked.bin.new" "${OUTPUT_PATH}/descriptor.bin"
  103. rm "${OUTPUT_PATH}/ifd_shrinked.bin"
  104. rm "${OUTPUT_PATH}/${WORK_IMAGE_NAME}"
  105. echo "done. this is what a layout file should look like:"
  106. echo "0x00000000:0x00000fff ifd"
  107. echo "0x00001000:0x00002fff gbe"
  108. echo "0x00003000:0x0001afff me"
  109. echo "0x0001b000:0x00bfffff bios"
  110. mv ${OUTPUT_PATH}/* . && rm -rf ${OUTPUT_PATH}