inject 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  3. # SPDX-License-Identifier: GPL-3.0-only
  4. Fail(){
  5. if [ ! -z ${@+x} ]; then
  6. printf "\nERROR: ${@}\n"
  7. fi
  8. cat <<- EOF
  9. USAGE: ./blobutil inject -r [/path/to/rom] -b [boardname] -m [macaddress]
  10. Example: ./blobutil inject -r x230_12mb.rom -b x230_12mb
  11. Adding a macadress to the gbe is optional.
  12. If the [-m] parameter is left blank, the gbe will not be touched.
  13. Type './blobutil inject listboards' to get a list of valid boards
  14. EOF
  15. exit 1
  16. }
  17. Modify_gbe(){
  18. printf "changing mac address in gbe to ${new_mac}\n"
  19. _gbe_location=${CONFIG_GBE_BIN_PATH#../../}
  20. if [ ! -f util/nvmutil/nvm ]; then
  21. make -C /util/nvmutil || Fail 'failed to build nvmutil'
  22. fi
  23. _gbe_tmp=$(mktemp -t gbeXXXX.bin)
  24. cp ${_gbe_location} ${_gbe_tmp}
  25. ./util/nvmutil/nvm ${_gbe_tmp} setmac ${new_mac} || Fail 'failed to modify mac address\nmake sure the mac address in the correct format'
  26. ./coreboot/default/util/ifdtool/ifdtool -i GbE:${_gbe_tmp} ${rom} -O ${rom} || exit 1
  27. rm ${_gbe_tmp}
  28. }
  29. listboards() {
  30. for boarddir in resources/coreboot/*; do
  31. if [ ! -d "${boarddir}" ]; then continue; fi
  32. board="${boarddir##resources/coreboot/}"
  33. board="${board%/}"
  34. printf '%s\n' "${board##*/}"
  35. done
  36. }
  37. # This function tries to determine the board from the filename of the rom.
  38. # It will only succeed if the filename is not changed from the build/download
  39. Detect_board(){
  40. filename=$(basename ${rom})
  41. case ${filename} in
  42. grub_*)
  43. board=$(cut -d '_' -f2-3 <<<${filename})
  44. ;;
  45. seabios_withgrub_*)
  46. board=$(cut -d '_' -f3-4 <<<${filename})
  47. ;;
  48. *)
  49. return 1
  50. esac
  51. if [ -d "resources/coreboot/${board}/" ]; then
  52. printf '%s\n' "${board}"
  53. else
  54. return 1
  55. fi
  56. }
  57. Patch(){
  58. set -- "resources/coreboot/${board}/config/*"
  59. . ${1} 2>/dev/null
  60. . "resources/coreboot/${board}/board.cfg"
  61. if [ "$CONFIG_HAVE_MRC" = "y" ]; then
  62. printf 'adding mrc\n'
  63. ./coreboot/default/util/cbfstool/cbfstool ${rom} add -f mrc/haswell/mrc.bin -n mrc.bin -t mrc || exit 1
  64. fi
  65. if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then
  66. _me_location=${CONFIG_ME_BIN_PATH#../../}
  67. printf 'adding intel management engine\n'
  68. ./coreboot/default/util/ifdtool/ifdtool -i me:${_me_location} ${rom} -O ${rom} || exit 1
  69. fi
  70. if [ "${modifygbe}" = "true" ]; then
  71. Modify_gbe
  72. fi
  73. }
  74. if [ "${1}" = "listboards" ]; then
  75. listboards
  76. exit 0
  77. fi
  78. # Implementing parameter parsing now so more options can be added later
  79. while getopts r:b:m: option
  80. do
  81. case "${option}"
  82. in
  83. r)rom=${OPTARG};;
  84. b)board=${OPTARG};;
  85. m)
  86. modifygbe=true
  87. new_mac=${OPTARG}
  88. ;;
  89. esac
  90. done
  91. if [ -z ${rom+x} ]; then
  92. Fail 'no rom specified'
  93. elif [ ! -f "${rom}" ]; then
  94. Fail "${rom} is not a valid path"
  95. elif [ -z ${board+x} ]; then
  96. board=$(Detect_board) || \
  97. Fail 'no board specified'
  98. fi
  99. if [ ! -d "resources/coreboot/${board}/" ]; then
  100. Fail "board ${board} not found"
  101. fi
  102. if [ ! -d coreboot/default ]; then
  103. printf "downloading coreboot\n"
  104. ./download coreboot default
  105. fi
  106. if [ ! -f "coreboot/default/util/ifdtool/ifdtool" ]; then
  107. printf "building ifdtool from coreboot\n"
  108. make -C coreboot/default/util/ifdtool || Fail 'could not build ifdtool'
  109. fi
  110. if [ ! -f "coreboot/default/util/cbfstool/cbfstool" ]; then
  111. printf "building cbfstool from coreboot\n"
  112. make -C cd coreboot/default/util/cbfstool || Fail 'could not build ifdtool'
  113. fi
  114. ./blobutil download ${board} && Patch