coreboot 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #!/usr/bin/env sh
  2. # helper script: download coreboot
  3. #
  4. # Copyright (C) 2014-2016,2020,2021,2023 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
  6. # Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. [ "x${DEBUG+set}" = 'xset' ] && set -v
  22. set -u -e
  23. _board=""
  24. cbtree=""
  25. cbrevision=""
  26. # NODELETE= ./download coreboot
  27. # usage: NODELETE= ./download coreboot
  28. # if you do this, .git* won't be removed, nor will blobs
  29. # this is useful for working on patches to a coreboot tree,
  30. # in git, then then add in the build system
  31. nodelete="false"
  32. if [ "x${NODELETE+set}" = 'xset' ]; then
  33. nodelete="true"
  34. fi
  35. cbcfgsdir="resources/coreboot"
  36. main()
  37. {
  38. rm -f ${cbcfgsdir}/*/seen
  39. printf "Downloading coreboot and (if available) applying patches\n"
  40. boards=""
  41. if [ $# -gt 0 ]; then
  42. boards=$@
  43. else
  44. for board in "${cbcfgsdir}/"*; do
  45. [ ! -d "${board}" ] && continue
  46. boards="${boards} ${board##*/}"
  47. done
  48. fi
  49. for board in ${boards}; do
  50. rm -f "${cbcfgsdir}"/*/seen
  51. download_coreboot_for_board "${board}"
  52. done
  53. censor_blobs
  54. rm -f ${cbcfgsdir}/*/seen
  55. }
  56. download_coreboot_for_board()
  57. {
  58. _board="${1}"
  59. cbtree="undefined"
  60. cbrevision="undefined"
  61. fetch_coreboot_config "${_board}" || exit 1
  62. rm -f "${cbcfgsdir}"/*/seen
  63. if [ -d "coreboot/${cbtree}" ]; then
  64. printf "REMARK: download/coreboot %s: exists. Skipping.\n" \
  65. ${cbtree}
  66. [ "${cbtree}" != "${1}" ] && \
  67. printf "(for board: '%s}')\n" ${1}
  68. return 0
  69. fi
  70. gitclone_coreboot_from_upstream || exit 1
  71. prepare_new_coreboot_tree "${1}" "${cbtree}" "${cbrevision}" \
  72. || exit 1
  73. }
  74. fetch_coreboot_config()
  75. {
  76. _board=${1}
  77. while true; do
  78. cbrevision="undefined"
  79. cbtree="undefined"
  80. check_config_for_board "${_board}" || return 1
  81. # This is to override $cbrevision and $cbtree
  82. . "${cbcfgsdir}/${_board}/board.cfg" || exit 1
  83. if [ "${_board}" != "${cbtree}" ]; then
  84. _board="${cbtree}"
  85. continue
  86. elif [ "${cbtree}" = "undefined" ]; then
  87. printf "ERROR: download/coreboot:"
  88. printf " tree name undefined for '%s\n'" \
  89. ${_board}
  90. return 1
  91. elif [ "${cbrevision}" = "undefined" ]; then
  92. printf "ERROR: download/coreboot:"
  93. printf " commit ID undefined for '%s'\n" \
  94. ${_board}
  95. return 1
  96. else
  97. break
  98. fi
  99. done
  100. }
  101. check_config_for_board()
  102. {
  103. _board=${1}
  104. if [ ! -f "${cbcfgsdir}/${_board}/board.cfg" ]; then
  105. printf "ERROR: download/coreboot: board.cfg does not"
  106. printf " exist for '%s'\n" ${_board}
  107. return 1
  108. elif [ -f "${cbcfgsdir}/${_board}/seen" ]; then
  109. printf "ERROR: download/coreboot: logical loop:"
  110. printf " '%s' board.cfg refers to another tree," ${_board}
  111. printf " which ultimately refers back to '%s'." ${_board}
  112. return 1
  113. fi
  114. touch "${cbcfgsdir}/${_board}/seen"
  115. }
  116. gitclone_coreboot_from_upstream()
  117. {
  118. [ ! -d coreboot ] && \
  119. mkdir -p coreboot
  120. [ ! -d coreboot ] && \
  121. return 1
  122. [ -d coreboot/coreboot ] && \
  123. return 0
  124. ./gitclone coreboot || \
  125. return 1
  126. }
  127. prepare_new_coreboot_tree()
  128. {
  129. target=${1}
  130. cbtree=${2}
  131. cbrevision=${3}
  132. printf "Preparing coreboot tree: %s\n" ${cbtree}
  133. [ "${cbtree}" != "${target}" ] && \
  134. printf "(for board: %s)\n" "${target}"
  135. cp -R coreboot/coreboot "coreboot/${cbtree}" || exit 1
  136. (
  137. cd "coreboot/${cbtree}" \
  138. || err "cannot cd to coreboot/${cbtree}"
  139. git reset --hard ${cbrevision} \
  140. || err "cannot reset coreboot revision for tree, ${cbtree}"
  141. git submodule update --init \
  142. || err "cannot update coreboot submodules for tree, ${cbtree}"
  143. for patch in ../../"${cbcfgsdir}"/"${cbtree}"/patches/*.patch; do
  144. [ ! -f "${patch}" ] && \
  145. continue
  146. if ! git am "${patch}"; then
  147. git am --abort
  148. err "cannot patch ${cbtree}"
  149. fi
  150. done
  151. # extra.sh can be used for anything
  152. # but should *only* be a last resort
  153. if [ -f "../../${cbcfgsdir}/${cbtree}/extra.sh" ]; then
  154. "../../${cbcfgsdir}/${cbtree}/extra.sh" || \
  155. err "${cbtree} extra.sh"
  156. fi
  157. )
  158. }
  159. censor_blobs()
  160. {
  161. if [ "${nodelete}" = "true" ]; then
  162. return
  163. fi
  164. printf "Doing this to coreboot: https://en.wikipedia.org/wiki/Book_burning\n"
  165. printf "Whatever you do, don't read: https://libreboot.org/news/policy.html\n"
  166. rm -Rf coreboot/coreboot/
  167. rm -Rf coreboot/.git* coreboot/*/.git* \
  168. coreboot/*/3rdparty/*/.git*
  169. rm -Rf coreboot/*/util/nvidia/cbootimage/.git*
  170. # Also delete that nasty evil documentation that
  171. # tells users how to install coreboot, because those
  172. # evil coreboot people recommend blobs sometimes. /s
  173. rm -Rf coreboot/*/Documentation
  174. # it's basically book-burning. GNU FSDG policy == censorship.
  175. # https://en.wikipedia.org/wiki/Book_burning
  176. # there is a much better way:
  177. # https://libreboot.org/news/policy.html
  178. # but this version of libreboot is designed for the FSF
  179. # to use in their GNU Boot project.
  180. # and i guarantee you, they will remove the above comments
  181. # if they fork this code.
  182. # *they* will call it FREEDOM.
  183. # but it's not. they're removing your freedom to choose.
  184. # and censoring everything they don't like.
  185. # they will decide what is good for you.
  186. # they will decide against you.
  187. # and if you fell for their propaganda, you'll feel
  188. # pure. despite the fact that your machine is still
  189. # full of blobs, even if the boot flash is blob-free.
  190. # see:
  191. # https://libreboot.org/faq.html#what-other-firmware-exists-outside-of-libreboot
  192. # this, despite the fact that libreboot is a free software
  193. # project. they call it non-free. the truth is written here:
  194. # https://libreboot.org/freedom-status.html
  195. for cbdir in coreboot/*; do
  196. if [ ! -d "${cbdir}" ]; then continue; fi
  197. cbtree="${cbdir##coreboot/}"
  198. cbtree="${cbtree%/}"
  199. if [ ! -d "coreboot/${cbtree}" ]; then continue; fi
  200. bloblist="resources/coreboot/${cbtree}/blobs.list"
  201. if [ -f "${bloblist}" ]; then
  202. for blobfile in $(cat "${bloblist}"); do
  203. printf "Deleting blob: 'coreboot/%s/%s'\n" \
  204. "${cbtree}" "${blobfile}"
  205. rm -f "coreboot/${cbtree}/${blobfile}"
  206. done
  207. else
  208. printf "WARNING blobs.list unavailable for %s" \
  209. ${cbtree} 1>&2
  210. fi
  211. rmlist="resources/coreboot/${cbtree}/rm.list"
  212. if [ -f "${rmlist}" ]; then
  213. for rmentry in $(cat "${rmlist}"); do
  214. printf "Deleting directory to save space: "
  215. printf "'coreboot/%s/%s'\n" \
  216. "${cbtree}" "${rmentry}"
  217. rm -Rf "coreboot/${cbtree}/${rmentry}"
  218. done
  219. fi
  220. done
  221. }
  222. err()
  223. {
  224. printf "ERROR: %s: %s\n" $0 $1 1>&2
  225. exit 1
  226. }
  227. main $@