extract 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env bash
  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. Build_deps(){
  13. if [ ! -d me_cleaner ]; then
  14. printf "downloading me_cleaner\n"
  15. ./download me_cleaner
  16. else
  17. printf "me_cleaner already downloaded. Skipping.\n"
  18. printf "run ./download me_cleaner to manually overwrite\n"
  19. fi
  20. if [ ! -d coreboot/default ]; then
  21. printf "downloading coreboot\n"
  22. ./download coreboot default
  23. else
  24. printf "coreboot already downloaded. Skipping.\n"
  25. printf "run ./download coreboot to manually overwrite\n"
  26. fi
  27. printf "building ifdtool from coreboot\n"
  28. ( cd coreboot/default/util/ifdtool && make )
  29. }
  30. Error_out(){
  31. printf "failed to extract ${1}\nmake sure that your rom dump is valid\n"
  32. exit 1
  33. }
  34. Extract_blobs(){
  35. # TODO: find a better way to know which coreboot config to source
  36. set -- "resources/coreboot/${board}/config/*"
  37. . ${1} 2>/dev/null
  38. . "resources/coreboot/${board}/board.cfg"
  39. if [ "$CONFIG_HAVE_MRC" = "y" ]; then
  40. printf 'haswell board detected, downloading mrc\n'
  41. ./download mrc
  42. fi
  43. _me_destination=${CONFIG_ME_BIN_PATH#../../}
  44. _gbe_destination=${CONFIG_GBE_BIN_PATH#../../}
  45. _ifd_destination=${CONFIG_IFD_BIN_PATH#../../}
  46. printf "extracting clean ime and modified ifd\n"
  47. ./me_cleaner/me_cleaner.py -D ${_ifd_destination} -M ${_me_destination} ${vendor_rom} -t -r -S || Error_out me
  48. printf "extracting gigabit ethernet firmware"
  49. ./coreboot/default/util/ifdtool/ifdtool -x ${vendor_rom}
  50. mv flashregion*gbe.bin ${_gbe_destination} || Error_out gbe
  51. # Cleans up other files extracted with ifdtool
  52. rm flashregion*.bin 2> /dev/null
  53. printf "gbe, ifd, and me extracted to ${_me_destination%/*}\n"
  54. }
  55. if [ ! -f "${vendor_rom}" ] ; then
  56. Print_help
  57. exit 1
  58. fi
  59. if [ ! -d "resources/coreboot/${board}" ]; then
  60. Print_help
  61. printf "build/roms: Target %s does not exist in the %s build system. Skipping build.\n" "${projectname}" "${board}"
  62. exit 1
  63. fi
  64. if [ ! -f "resources/coreboot/${board}/board.cfg" ]; then
  65. Print_help
  66. printf "build/roms: Target %s does not have a board.cfg. Skipping build.\n" "${board}"
  67. exit 1
  68. fi
  69. printf "extracting blobs for ${board} from ${vendor_rom}\n"
  70. Build_deps
  71. Extract_blobs