blobs 3.9 KB

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