download 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/env sh
  2. # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  3. # SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. # SPDX-License-Identifier: GPL-3.0-only
  5. board="${1}"
  6. # A shorthand for each board so as not to duplicate blobs for boards of different sizes
  7. board_short=${board%%_*mb}
  8. Fail(){
  9. printf "\nERROR: $@\n"
  10. exit 1
  11. }
  12. Download_needed(){
  13. for need in ${needs}; do
  14. case ${need} in
  15. *ME*)
  16. Extract_me || _failed="${_failed} me"
  17. ;;
  18. *MRC*)
  19. ./download mrc || _failed="${_failed} mrc"
  20. ;;
  21. esac
  22. done
  23. if [ ! -z ${_failed+x} ]; then
  24. Fail "failed to obtain ${_failed}\nYou may try manually extracting blobs with './blobutil extract'"
  25. fi
  26. }
  27. Extract_me(){
  28. _me_destination=${CONFIG_ME_BIN_PATH#../../}
  29. if [ -f "${_me_destination}" ]; then
  30. printf 'me already downloaded\n'
  31. return 0
  32. fi
  33. if [ -z "${me_dl+x}" ]; then
  34. printf 'no me download available for this board\n'
  35. return 1
  36. fi
  37. if [ ! -d "${_me_destination%/*}" ]; then
  38. mkdir -p ${_me_destination%/*}
  39. fi
  40. printf "Extracting neutered me for ${board}\n"
  41. # Delete old me downloads in case user is building for multiple boards
  42. if [ -f "blobs/me.exe" ]; then
  43. rm blobs/me.exe
  44. fi
  45. if [ -d "blobs/app" ]; then
  46. rm -r blobs/app
  47. fi
  48. curl ${me_dl} > blobs/me.exe || curl ${me_dl_bkup} > blobs/me.exe
  49. if [ "$(sha1sum blobs/me.exe | awk '{print $1}')" != "${me_hash}" ]; then
  50. printf 'checksum of downloaded me did not mactch\ncorrupted me downloaded or wrong me for board\n'
  51. rm blobs/me.exe
  52. return 1
  53. fi
  54. printf 'extracting and stripping intel management engine\n'
  55. innoextract blobs/me.exe -d blobs || Fail 'could not extract me executable with innoextract'
  56. ./me_cleaner/me_cleaner.py -r -t -O ${_me_destination} blobs/app/*ME*.bin \
  57. || ./resources/blobs/me7_update_parser.py -O ${_me_destination} blobs/app/ME7*.bin \
  58. || return 1
  59. printf "Truncated and cleaned me output to ${_me_destination}\n"
  60. }
  61. Build_deps(){
  62. if [ ! -d me_cleaner ]; then
  63. printf "downloading me_cleaner\n"
  64. ./download me_cleaner || Fail 'could not download me_cleaner'
  65. fi
  66. if [ ! -d coreboot/default ]; then
  67. printf "downloading coreboot\n"
  68. ./download coreboot default || Fail 'could not download coreboot'
  69. fi
  70. if [ ! -f "coreboot/default/util/ifdtool/ifdtool" ]; then
  71. printf "building ifdtool from coreboot\n"
  72. make -C coreboot/default/util/ifdtool || Fail 'could not build ifdtool'
  73. fi
  74. }
  75. set -- "resources/coreboot/${board}/config/*"
  76. . ${1} 2>/dev/null
  77. . "resources/coreboot/${board}/board.cfg"
  78. if [ "${CONFIG_HAVE_MRC}" = "y" ]; then
  79. printf 'haswell board detected, downloading mrc\n'
  80. needs="${needs} MRC"
  81. fi
  82. if [ "${CONFIG_HAVE_IFD_BIN}" = "y" ]; then
  83. printf 'board needs intel firmware descriptor\n'
  84. needs="${needs} IFD"
  85. fi
  86. if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then
  87. printf 'board needs intel management engine\n'
  88. needs="${needs} ME"
  89. fi
  90. if [ "${CONFIG_HAVE_GBE_BIN}" = "y" ]; then
  91. printf 'board needs gigabit ethernet firmware\n'
  92. needs="${needs} GBE"
  93. fi
  94. # Quickly exit without wasting more time if there are no blobs needed (GM45)
  95. if [ -z ${needs+x} ]; then
  96. printf 'No binary blobs needed for this board\n'
  97. exit 0
  98. fi
  99. Build_deps
  100. while read -r line ; do
  101. case ${line} in
  102. ME_hash*)
  103. set ${line}
  104. me_hash=${2}
  105. ;;
  106. ME_dl*)
  107. set ${line}
  108. me_dl=${2}
  109. ;;
  110. ME_bkup_dl*)
  111. set ${line}
  112. me_dl_bkup=${2}
  113. ;;
  114. esac
  115. done << EOF
  116. $(eval "awk ' /\{.*${board_short}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }' resources/blobs/sources")
  117. EOF
  118. Download_needed