release 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: MIT
  3. # SPDX-FileCopyrightText: 2020-2023 Leah Rowe <leah@libreboot.org>
  4. [ "x${DEBUG+set}" = 'xset' ] && set -v
  5. set -u -e
  6. . "include/err.sh"
  7. . "include/option.sh"
  8. eval "$(setvars "" vdir relname src_dirname srcdir _xm target romdir \
  9. microcode_required mode)"
  10. main()
  11. {
  12. vdir="release"
  13. while getopts d:m: option; do
  14. [ -z "${OPTARG}" ] && err "Empty argument not allowed"
  15. case "${option}" in
  16. d) vdir="${OPTARG}" ;;
  17. m) mode="${OPTARG}" ;;
  18. *) err "Invalid option" ;;
  19. esac
  20. done
  21. vdir="${vdir}/${version}"
  22. relname="${projectname}-${version}"
  23. src_dirname="${relname}_src"
  24. srcdir="${vdir}/${src_dirname}"
  25. [ -e "${vdir}" ] && err "already exists: \"${vdir}\""
  26. mkvdir
  27. build_release
  28. printf "DONE! Check release files under %s\n" "${vdir}"
  29. }
  30. mkvdir()
  31. {
  32. mkdir -p "${vdir}" || err "mkvdir: !mkdir -p \"${vdir}\""
  33. git clone . "${srcdir}" || err "mkdir: !gitclone \"${srcdir}\""
  34. insert_version_files "${srcdir}" || err "mkvdir ${srcdir}: versionfile"
  35. }
  36. build_release()
  37. {
  38. _xm="build_release ${vdir}"
  39. (
  40. cd "${srcdir}" || err "${_xm}: !cd \"${srcdir}\""
  41. fetch_trees
  42. x_ mv src/docs docs
  43. )
  44. (
  45. cd "${srcdir%/*}" || err "${_xm}: mktarball \"${srcdir}\""
  46. mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || err "${_xm}: mksrc"
  47. )
  48. [ "${mode}" = "src" ] && return 0 # for src mode, xgcc tarballs are
  49. # not included in the src archive
  50. # now build roms, then copy crossgcc to src and re-compress
  51. # while compressing rom images too.
  52. (
  53. cd "${srcdir}" || err "${_xm}: 2 !cd \"${srcdir}\""
  54. mkrom_images
  55. )
  56. for _cbd in "${srcdir}/src/coreboot/"*; do
  57. [ -d "${_cbd}/util/crossgcc/tarballs" ] || continue
  58. _xgccdir="${vdir}/crossgcc/${_cbd##*/}"
  59. mkdir -p "${_xgccdir}" || \
  60. err "build_release: !mkdir -p ${_xgccdir}"
  61. cp -R "${_cbd}/util/crossgcc/tarballs/"* "${_xgccdir}" || \
  62. err "build_gcc: !copy xgcc ${_cbd}"
  63. done
  64. rm -Rf "${srcdir}" || err "build_release: !rm -Rf ${srcdir}"
  65. (
  66. cd "${srcdir%/*}" || err "${_xm} 2: mktarball \"${srcdir}\""
  67. tar -xf "${srcdir##*/}.tar.xz" || err "!extract ${srcdir##*/}.tar.xz"
  68. rm -f "${srcdir##*/}.tar.xz" || err "!rm -f ${srcdir##*/}.tar.xz"
  69. )
  70. for _xgcc in "${vdir}/crossgcc/"*; do
  71. [ -d "${_xgcc}" ] || continue
  72. mkdir -p "${srcdir}/src/coreboot/${_xgcc##*/}/util/crossgcc/tarballs" || \
  73. err "!mkdir src/coreboot/${_xgcc##*/}/util/crossgcc/tarballs"
  74. mv "${_xgcc}/"* \
  75. "${srcdir}/src/coreboot/${_xgcc##*/}/util/crossgcc/tarballs/" \
  76. || err "!move xgcc tarballs to ${srcdir}/xgcc/${_xgcc##*/}"
  77. done
  78. rm -Rf "${vdir}/crossgcc" || err "!rm -Rf \"${vdir}/crossgcc\""
  79. (
  80. cd "${srcdir%/*}" || err "${_xm}: mktarball \"${srcdir}\""
  81. mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || err "${_xm}: mksrc"
  82. )
  83. # now test the vendor insert script, using the release archive:
  84. (
  85. cd "${srcdir}" || err "!cd ${srcdir}"
  86. mkfakeroms
  87. for vrom in ../roms/*.tar.xz; do
  88. [ -f "${vrom}" ] || continue
  89. case "${vrom}" in
  90. *serprog*) continue ;;
  91. esac
  92. ./vendor inject "${vrom}" || \
  93. err "TESTFAIL: inject: ${vrom##*/}"
  94. continue
  95. done
  96. )
  97. rm -Rf "${srcdir}" || err "!rm -Rf ${srcdir}"
  98. }
  99. fetch_trees()
  100. {
  101. for x in config/git/*; do
  102. [ ! -f "${x}" ] || ./update trees -f "${x#config/git/}" || \
  103. err "${_xm}: fetch ${x#config/git/}"
  104. done
  105. for x in config/*/build.list; do
  106. [ -f "${x}" ] || continue
  107. xp="${x#*/}"; xp="${xp%/*}"
  108. [ -L "${xp}" ] || rm -Rf "src/${xp}/${xp}" || \
  109. err "!rm -Rf \"src/${xp}/${xp}\""
  110. done
  111. find . -name ".git" -exec rm -Rf {} + || err "${_xm}: rm .git"
  112. find . -name ".gitmodules" -exec rm -Rf {} + || err "${_xm}: rm .gitmod"
  113. x_ rm -Rf tmp .git
  114. }
  115. mkrom_images()
  116. {
  117. mkfakeroms
  118. ./build roms all || err "${_xm}: roms-all"
  119. ./build serprog rp2040 || err "${_xm}: rp2040"
  120. ./build serprog stm32 || err "${_xm}: stm32"
  121. for rombuild in bin/*; do
  122. [ -d "${rombuild}" ] || continue
  123. handle_rom_archive "${rombuild}"
  124. done
  125. mv "release/${version}/roms/" ../roms || err "${_xm}: copy roms/"
  126. }
  127. mkfakeroms()
  128. {
  129. # fake me.bin to make x201 roms build
  130. mkdir -p "vendorfiles/x201/" || \
  131. err "mkvdir: !mkdir -p \"vendorfiles/x201/\""
  132. dd if=/dev/zero of="vendorfiles/x201/me.bin" \
  133. bs=68k count=1 || err "mkvdir: can't make fake x201 me.bin"
  134. }
  135. handle_rom_archive()
  136. {
  137. builddir="${1}"
  138. romdir="tmp/romdir"
  139. rm -Rf "${romdir}" || err "!rm romdir, handle_rom_archive"
  140. target="${builddir##*/}"
  141. if [ ! -f "config/coreboot/${target}/target.cfg" ]; then
  142. # No config, just make a tarball
  143. tarball="release/${version}/roms/${relname}_${target}.tar.xz"
  144. insert_copying_files "${builddir}" || \
  145. err "!insert copy, handle, ${builddir}"
  146. mktarball "${builddir}" "${tarball}"
  147. return 0
  148. fi
  149. romdir="${romdir}/bin/${target}"
  150. mkdir -p "${romdir}" || err "!mkdir -p romdir, handle_rom_archive"
  151. cp "${builddir}/"* "${romdir}" || err "!cp romdir, handle_rom_archive"
  152. nukerom
  153. printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
  154. "${version}" "${projectname}" "${version}" "${target##*/}"
  155. insert_version_files "${romdir}" || \
  156. err "mkrom_tarball ${romdir}: versionfile"
  157. insert_copying_files "${romdir}" || err "!insert copy, handle 2, ${romdir}"
  158. mkrom_tarball
  159. }
  160. nukerom()
  161. {
  162. microcode_required="y"
  163. . "config/coreboot/${target}/target.cfg"
  164. if [ "${microcode_required}" != "y" ] && \
  165. [ "${microcode_required}" != "n" ]; then microcode_required="y"; fi
  166. if [ "${microcode_required}" = "n" ]; then
  167. for romfile in "${romdir}"/*.rom; do
  168. [ -f "${romfile}" ] || continue
  169. strip_ucode "${romfile}"
  170. done
  171. for romfile in "${romdir}"/*.tmprom; do
  172. [ -f "${romfile}" ] || continue
  173. mv "${romfile}" "${romfile%.tmprom}.rom" || \
  174. err "!mv romfile, nukerom"
  175. done
  176. fi
  177. # Hash the images before removing vendor files
  178. # which "./vendor inject" uses for verification
  179. rm -f "${romdir}/vendorhashes" || err "!rm ${romdir}/vendorhashes"
  180. touch "${romdir}/vendorhashes" || err "!touch ${romdir}/vendorhashes"
  181. (
  182. cd "${romdir}" || err "!cd romdir ${romdir}, nukerom"
  183. sha512sum *.rom >> vendorhashes || err "!create vendorhashes, nukerom"
  184. )
  185. for romfile in "${romdir}"/*.rom; do
  186. [ -f "${romfile}" ] || continue
  187. ./vendor inject -r "${romfile}" -b ${target} -n nuke || \
  188. err "!vendor inject (nuke) ${romfile}, nukerom"
  189. done
  190. }
  191. strip_ucode()
  192. {
  193. romfile=${1}
  194. _newrom_b="${romfile%.rom}_nomicrocode.tmprom"
  195. cp "${romfile}" "${_newrom_b}" || err "!cp romfile ${romfile}, strip_u"
  196. microcode_present="y"
  197. "${cbfstool}" "${_newrom_b}" remove -n \
  198. cpu_microcode_blob.bin 2>/dev/null || microcode_present="n"
  199. [ "${microcode_present}" = "n" ] || return 0
  200. printf "REMARK: '%s' already lacks microcode\n" "${romfile}" 1>&2
  201. printf "Renaming default ROM file instead.\n" 1>&2
  202. mv "${romfile}" "${_newrom_b}" || err "!mv romfile ${romfile}, strip_u"
  203. }
  204. insert_copying_files()
  205. {
  206. rm -Rf "${1}/licenses" || return 1
  207. mkdir -p "${1}/licenses" || return 1
  208. l="${1}/licenses"
  209. # copy licenses to rom image archive, for completion
  210. cp "src/grub/COPYING" "${l}/COPYING.grub" || return 1
  211. cp "src/coreboot/default/COPYING" "${l}/COPYING.coreboot" || return 1
  212. cp -R "src/coreboot/default/LICENSES" "${l}/LICENSES.coreboot" || return 1
  213. cp "src/seabios/default/COPYING" "${l}/COPYING.coreboot" || return 1
  214. cp "src/seabios/default/COPYING.LESSER" "${l}/COPYING.LESSER.seabios" || return 1
  215. cp -R "src/u-boot/default/Licenses" "${l}/COPYING.u-boot" || return 1
  216. printf "Multiple licenses. Check corresponding %s source archive\n" \
  217. "${projectname}" > "${1}/COPYING" || return 1
  218. }
  219. mkrom_tarball()
  220. {
  221. archivename="${relname}_${target##*/}"
  222. f="release/${version}/roms/${archivename}"
  223. mkdir -p "${f%/*}" || err "mkrom_tarball: !mkdir -p ${f%/*}"
  224. (
  225. cd "${romdir%/bin/${target}}" || err "!cd ${romdir%/bin/${target}}"
  226. mktarball "bin/${target}" "${archivename}.tar.xz"
  227. )
  228. mv "${romdir%/bin/${target}}/${archivename}.tar.xz"* "${f%/*}" || \
  229. err "!mktarball, rom, ${f%/*}/${romdir%/bin/${target}}/${archivename}.tar.xz"
  230. printf "Created ROM archive: ${f%/*}/${archivename}.tar.xz"
  231. }
  232. insert_version_files()
  233. {
  234. printf "%s\n" "${version}" > "${1}/version" || return 1
  235. printf "%s\n" "${versiondate}" > "${1}/versiondate" || return 1
  236. printf "%s\n" "${projectname}" > "${1}/projectname" || return 1
  237. }
  238. mktarball()
  239. {
  240. # preserve timestamps for reproducible tarballs
  241. tar_implementation=$(tar --version | head -n1) || :
  242. [ "${2%/*}" = "${2}" ] || mkdir -p "${2%/*}" || err "mk, !mkdir -p \"${2%/*}\""
  243. if [ "${tar_implementation% *}" = "tar (GNU tar)" ]; then
  244. tar --sort=name --owner=root:0 --group=root:0 \
  245. --mtime="UTC 2023-11-06" -c "${1}" | xz -T0 -9e > "${2}" || \
  246. err "mktarball 1, ${1}"
  247. else
  248. # TODO: reproducible tarballs on non-GNU systems
  249. tar -c "${1}" | xz -T0 -9e > "${2}" || err "mktarball 2, ${1}"
  250. fi
  251. (
  252. [ "${2%/*}" != "${2}" ] && x_ cd "${2%/*}"
  253. sha512sum "${2##*/}" > "${2##*/}.sha512" || \
  254. err "!sha512sum \"${2##*/}\" > \"${2##*/}.sha512\""
  255. )
  256. }
  257. main $@