inject 3.4 KB

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