download 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. # Allow adding only blobs that can be legally redistributed (ifd+gbe)
  8. if [ "${2}" = "redistributable" ]; then
  9. redistributable=true
  10. else
  11. redistributable=false
  12. fi
  13. Download_needed(){
  14. for need in ${needs}; do
  15. case ${need} in
  16. *ME*)
  17. Extract_me || _failed+=" me"
  18. ;;
  19. *MRC*)
  20. ./download mrc || _failed+=" mrc"
  21. ;;
  22. esac
  23. done
  24. if [ ! -z ${_failed+x} ]; then
  25. printf "\nERROR: failed to obtain${_failed}\nrun: './blobutil extract ${board} /path/to/romdump.rom' to extract the remaining blobs\n"
  26. exit 1
  27. fi
  28. }
  29. Extract_me(){
  30. _me_destination=${CONFIG_ME_BIN_PATH#../../}
  31. if [ -f "${_me_destination}" ]; then
  32. printf 'me already downloaded\n'
  33. return 0
  34. fi
  35. if [ -z "${me_dl+x}" ]; then
  36. printf 'no me download available for this board\n'
  37. return 1
  38. fi
  39. if [ ! -d "${_me_destination%/*}" ]; then
  40. mkdir -p ${_me_destination%/*}
  41. fi
  42. printf "Extracting neutered me for ${board}\n"
  43. # Delete old me downloads in case user is building for multiple boards
  44. if [ -f "blobs/me.exe" ]; then
  45. rm blobs/me.exe
  46. fi
  47. if [ -d "blobs/app" ]; then
  48. rm -r blobs/app
  49. fi
  50. curl ${me_dl} > blobs/me.exe || curl ${me_dl_bkup} > blobs/me.exe
  51. if [ ! "$(sha1sum blobs/me.exe)" = "${me_hash} blobs/me.exe" ]; then
  52. printf 'checksum of downloaded me did not mactch\ncorrupted me downloaded or wrong me for board\n'
  53. rm blobs/me.exe
  54. return 1
  55. fi
  56. ( cd blobs && innoextract me.exe )
  57. printf 'extracting and stripping intel management engine\n'
  58. ./me_cleaner/me_cleaner.py -r -t -O ${_me_destination} blobs/app/*ME*.bin \
  59. || ./resources/blobs/me7_update_parser.py -O ${_me_destination} blobs/app/ME7*.bin
  60. printf "Truncated and cleaned me output to ${_me_destination}\n"
  61. }
  62. Build_deps(){
  63. if [ ! -d me_cleaner ]; then
  64. printf "downloading me_cleaner\n"
  65. ./download me_cleaner
  66. fi
  67. if [ ! -d coreboot/default ]; then
  68. printf "downloading coreboot\n"
  69. ./download coreboot default
  70. fi
  71. if [ ! -f "coreboot/default/util/ifdtool/ifdtool" ]; then
  72. printf "building ifdtool from coreboot\n"
  73. ( cd coreboot/default/util/ifdtool && make )
  74. fi
  75. }
  76. set -- "resources/coreboot/${board}/config/*"
  77. . ${1} 2>/dev/null
  78. . "resources/coreboot/${board}/board.cfg"
  79. if [ "${CONFIG_HAVE_MRC}" = "y" ]; then
  80. if [ "${redistributable}" = "false" ]; then
  81. printf 'haswell board detected, downloading mrc\n'
  82. needs+=" MRC"
  83. fi
  84. fi
  85. if [ "${CONFIG_HAVE_IFD_BIN}" = "y" ]; then
  86. printf 'board needs intel firmware descriptor\n'
  87. needs+=" IFD"
  88. fi
  89. if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then
  90. if [ "${redistributable}" = "false" ]; then
  91. printf 'board needs intel management engine\n'
  92. needs+=" ME"
  93. fi
  94. fi
  95. if [ "${CONFIG_HAVE_GBE_BIN}" = "y" ]; then
  96. printf 'board needs gigabit ethernet firmware\n'
  97. needs+=" GBE"
  98. fi
  99. # Quickly exit without wasting more time if there are no blobs needed (GM45)
  100. if [ -z ${needs+x} ]; then
  101. printf 'No binary blobs needed for this board\n'
  102. exit 0
  103. fi
  104. Build_deps
  105. while read -r line ; do
  106. case ${line} in
  107. ME_hash*)
  108. set ${line}
  109. me_hash=${2}
  110. ;;
  111. ME_dl*)
  112. set ${line}
  113. me_dl=${2}
  114. ;;
  115. ME_bkup_dl*)
  116. set ${line}
  117. me_dl_bkup=${2}
  118. ;;
  119. esac
  120. done <<< $(eval "awk ' /\{.*${board_short}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }' resources/blobs/sources")
  121. Download_needed