withdepthcharge 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/bash
  2. # helper script: build ROM images with depthcharge and put them in ./bin/
  3. #
  4. # Copyright (C) 2014, 2015, 2016 Leah Woods <info@minifree.org>
  5. # Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # This script assumes that the working directory is the
  21. # root of libreboot_src or libreboot git.
  22. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. if [ -z ${NPROC+x} ]; then
  25. cores="$(nproc)"
  26. else
  27. case ${NPROC} in
  28. ''|*[!0-9]*)
  29. printf "value '%s' for NPROC is invalid. non-numeric. Exiting.\n" "${NPROC}"
  30. exit 1
  31. ;;
  32. esac
  33. cores="${NPROC}"
  34. fi
  35. printf "Building ROM images with the depthcharge payload\n"
  36. if [ ! -d "bin/" ]
  37. then
  38. mkdir "bin/"
  39. fi
  40. if [ -f "version" ]; then
  41. # _src release archive is being used
  42. version="$(cat "version")"
  43. else
  44. # git repo is being used
  45. version="$(git describe --tags HEAD)" # note: in libreboot, coreboot/.git doesn't exist, this uses libreboot .git
  46. fi
  47. # Build libpayload
  48. # ------------------------------------------------------------------------------
  49. buildlibpayload() {
  50. family="${1}"
  51. board="${2}"
  52. cbrevision="${3}"
  53. vbootrevision="${4}"
  54. (
  55. cd "coreboot/${cbrevision}/${cbrevision}/"
  56. git checkout depthcharge_${board}
  57. (
  58. cd "3rdparty/vboot/"
  59. git checkout depthcharge_${board}
  60. )
  61. cd "payloads/libpayload/"
  62. make distclean
  63. rm -Rf "install/"
  64. make KBUILD_DEFCONFIG="configs/config.$family" defconfig
  65. make -j${cores}
  66. make DESTDIR="install" install
  67. cd "../../"
  68. git checkout master
  69. cd "3rdparty/vboot/"
  70. git checkout master
  71. )
  72. }
  73. # Build depthcharge
  74. # ------------------------------------------------------------------------------
  75. builddepthcharge() {
  76. board="${1}"
  77. cbrevision="${2}"
  78. vbootrevision="${3}"
  79. (
  80. (
  81. cd "coreboot/${cbrevision}/${cbrevision}/"
  82. git checkout depthcharge_${board}
  83. cd "3rdparty/vboot/"
  84. git checkout depthcharge_${board}
  85. )
  86. cd "depthcharge/"
  87. make distclean
  88. rm -f "../coreboot/${cbrevision:?}/${cbrevision:?}/depthcharge.elf"
  89. make BOARD="${board}" defconfig
  90. make BOARD="${board}" LIBPAYLOAD_DIR="$(pwd)/../coreboot/${cbrevision}/${cbrevision}/payloads/libpayload/install/libpayload" VB_SOURCE="$(pwd)/../coreboot/${cbrevision}/${cbrevision}/3rdparty/vboot" -j${cores} depthcharge_unified
  91. cp "build/depthcharge.elf" "../coreboot/${cbrevision}/${cbrevision}/"
  92. cd "../coreboot/${cbrevision}/${cbrevision}/"
  93. git checkout master
  94. cd "3rdparty/vboot/"
  95. git checkout master
  96. )
  97. }
  98. # Build coreboot
  99. # ------------------------------------------------------------------------------
  100. buildcoreboot() {
  101. board="${1}"
  102. cbrevision="${2}"
  103. vbootrevision="${3}"
  104. (
  105. cd "coreboot/${cbrevision}/${cbrevision}"
  106. git checkout depthcharge_${board}
  107. (
  108. cd "3rdparty/vboot/"
  109. git checkout depthcharge_${board}
  110. )
  111. make distclean
  112. rm -f ".coreboot-version"
  113. rm -f *.img
  114. printf 'libreboot-%s' "${version}" > "ro-frid"
  115. printf 'libreboot-%s\n' "${version}" > ".coreboot-version" # needed for reproducible builds in coreboot
  116. make KBUILD_DEFCONFIG="$(pwd)/../../../resources/libreboot/config/depthcharge/${board}/config" defconfig
  117. make -j${cores}
  118. cbfs_size=$( grep CONFIG_CBFS_SIZE ".config" | sed "s/.*[[:space:]]*=[[:space:]]*//g" )
  119. cbfs_size=$( printf "%d\n" "${cbfs_size}" )
  120. cbfs_size=$(( $cbfs_size / 1024 ))
  121. dd if="build/coreboot.rom" of="coreboot.img" bs=1024 count="${cbfs_size}"
  122. objcopy -I binary -O binary --pad-to=0x100 --gap-fill=0x00 "ro-frid" "ro-frid.img"
  123. # prepare directory for new images
  124. rm -Rf "${board:?}/"
  125. mkdir "${board}/"
  126. # move the images into the newly created directory
  127. mv "coreboot.img" "${board}/"
  128. mv "ro-frid.img" "${board}/"
  129. # copy the scripts too
  130. cp "../../../resources/libreboot/install/depthcharge/cros-flash-replace" "${board}/"
  131. cp "../../../resources/libreboot/install/depthcharge/${board}/layout.txt" "${board}/"
  132. # delete the old images from ../bin
  133. rm -Rf "../../../bin/depthcharge/${board}/"
  134. # now put the new images in ./bin/depthcharge/
  135. [ ! -d "../../../bin/depthcharge/" ] && mkdir -p "../../../bin/depthcharge/"
  136. mv "${board}/" "../../../bin/depthcharge/"
  137. # clean this up
  138. rm -f "depthcharge.elf"
  139. rm -f *.img
  140. git checkout master
  141. cd "3rdparty/vboot/"
  142. git checkout master
  143. )
  144. }
  145. # Build ROM images for supported boards
  146. buildrom() {
  147. board="${1}"
  148. cbrevision="$(cat resources/libreboot/config/depthcharge/${board}/cbrevision)"
  149. vbootrevision="$(cat resources/libreboot/config/depthcharge/${board}/vbootrevision)"
  150. if [ -f "resources/libreboot/config/depthcharge/${board}/config" ]; then
  151. family=$( echo ${board} |sed "s/_.*//g" )
  152. buildlibpayload "${family}" "${board}" "${cbrevision}" "${vbootrevision}"
  153. builddepthcharge "${board}" "${cbrevision}" "${vbootrevision}"
  154. buildcoreboot "${board}" "${cbrevision}" "${vbootrevision}"
  155. fi
  156. }
  157. if [ $# -gt 0 ]; then
  158. for board in "${@}"; do
  159. buildrom "${board}"
  160. done
  161. else
  162. for board in resources/libreboot/config/depthcharge/*; do
  163. buildrom "${board##*/}"
  164. done
  165. fi