extract 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env sh
  2. # script to automate extracting blobs from an existing vendor bios
  3. # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  4. # SPDX-License-Identifier: GPL-3.0-only
  5. board="${1}"
  6. vendor_rom="${2}"
  7. Print_help(){
  8. printf "Usage: ./blobutil extract {boardname} {path/to/vendor_rom}\n"
  9. printf "Example: ./blobutil extract x230 12mb_flash.bin\n"
  10. printf "\nYou need to specify exactly 2 arguments\n"
  11. }
  12. Fail(){
  13. printf "\nERROR: $@\n"
  14. exit 1
  15. }
  16. Build_deps(){
  17. if [ ! -d me_cleaner ]; then
  18. printf "downloading me_cleaner\n"
  19. ./download me_cleaner || Fail 'could not download me_cleaner'
  20. else
  21. printf "me_cleaner already downloaded. Skipping.\n"
  22. printf "run ./download me_cleaner to manually overwrite\n"
  23. fi
  24. if [ ! -d coreboot/default ]; then
  25. printf "downloading coreboot\n"
  26. ./download coreboot default || Fail 'could not download coreboot'
  27. else
  28. printf "coreboot already downloaded. Skipping.\n"
  29. printf "run ./download coreboot to manually overwrite\n"
  30. fi
  31. if ! [ -f coreboot/default/util/ifdtool/ifdtool ]; then
  32. printf "building ifdtool from coreboot\n"
  33. make -C coreboot/default/util/ifdtool || Fail 'could not build ifdtool'
  34. fi
  35. }
  36. Extract_blobs(){
  37. # TODO: find a better way to know which coreboot config to source
  38. set -- "resources/coreboot/${board}/config/*"
  39. . ${1} 2>/dev/null
  40. . "resources/coreboot/${board}/board.cfg"
  41. if [ "$CONFIG_HAVE_MRC" = "y" ]; then
  42. printf 'haswell board detected, downloading mrc\n'
  43. ./download mrc || Fail 'could not download mrc, check network connection'
  44. fi
  45. _me_destination=${CONFIG_ME_BIN_PATH#../../}
  46. _gbe_destination=${CONFIG_GBE_BIN_PATH#../../}
  47. _ifd_destination=${CONFIG_IFD_BIN_PATH#../../}
  48. printf "extracting clean ime and modified ifd\n"
  49. ./me_cleaner/me_cleaner.py -D ${_ifd_destination} -M ${_me_destination} ${vendor_rom} -t -r -S \
  50. || ./resources/blobs/me7_update_parser.py -O ${_me_destination} ${vendor_rom} \
  51. || Fail 'me_cleaner failed to extract blobs from rom'
  52. printf "extracting gigabit ethernet firmware"
  53. ./coreboot/default/util/ifdtool/ifdtool -x ${vendor_rom}
  54. mv flashregion*gbe.bin ${_gbe_destination} || Fail 'could not extract gbe'
  55. # Cleans up other files extracted with ifdtool
  56. rm flashregion*.bin 2> /dev/null
  57. if [ -f ${_ifd_destination} ]; then
  58. printf "gbe, ifd, and me extracted to ${_me_destination%/*}\n"
  59. else
  60. printf "WARNING: Intel firmware descriptor could not be extracted with modified me\n"
  61. fi
  62. }
  63. if [ ! -f "${vendor_rom}" ] ; then
  64. Print_help
  65. exit 1
  66. fi
  67. if [ ! -d "resources/coreboot/${board}" ]; then
  68. Print_help
  69. printf "build/roms: Target %s does not exist in the %s build system. Skipping build.\n" "${projectname}" "${board}"
  70. exit 1
  71. fi
  72. if [ ! -f "resources/coreboot/${board}/board.cfg" ]; then
  73. Print_help
  74. printf "build/roms: Target %s does not have a board.cfg. Skipping build.\n" "${board}"
  75. exit 1
  76. fi
  77. printf "extracting blobs for ${board} from ${vendor_rom}\n"
  78. Build_deps
  79. Extract_blobs