download 3.3 KB

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