coreboot 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env bash
  2. # helper script: builds the dependencies that coreboot needs before building a ROM image
  3. #
  4. # Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  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 root
  21. # of git or release archive
  22. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. HOMEDIR=$(pwd)
  25. # Build utilities needed in coreboot directory
  26. # --------------------------------------------------------------------
  27. printf "Building the utilities in coreboot\n"
  28. # build coreboot utilities (in each revision) and
  29. # create symlinks to the crossgcc archive
  30. for payload in $HOMEDIR/coreboot/*; do
  31. for board in "${payload}/"*; do
  32. # cbfstool, cbmem, nvramtool
  33. for util in {cbfs,nvram}tool cbmem; do
  34. if [ "${util}" = "cbfstool" ]; then
  35. sed -i '/.*fmd_scanner.o.*-Wno-unused-function$/ s/$/ -Wno-sign-compare/' "${board}"/util/cbfstool/Makefile.inc
  36. fi
  37. make -BC "${board}/util/${util}"
  38. done
  39. # create symlink to crossgcc
  40. (
  41. ln -fs $HOMEDIR/crossgcc/util/crossgcc/ ${board}/util/crossgcc
  42. )
  43. done
  44. done
  45. for payloads in $HOMEDIR/resources/libreboot/config/*; do
  46. if [ ! -d "${payloads}/" ]; then
  47. continue
  48. fi
  49. payload="${payloads##*/}"
  50. for boardconfig in $HOMEDIR/resources/libreboot/config/${payload}/*; do
  51. if [ ! -d "${boardconfig}/" ]; then
  52. continue
  53. fi
  54. boardname="${boardconfig##*/}"
  55. cbrevision=$(cat "${boardconfig}/cbrevision")
  56. vbootrevision=$(cat "${boardconfig}/vbootrevision")
  57. reused_coreboot_patches="$HOMEDIR/resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}/reused.list"
  58. reused_vboot_patches="$HOMEDIR/resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}/reused.list"
  59. for reused_patches in "${reused_coreboot_patches}" "${reused_vboot_patches}"; do
  60. if [ -f "${reused_patches}" ]; then
  61. for patch in $(cat "${reused_patches}"); do
  62. if [ ! -f "./${patch}" ]; then
  63. printf "%s listed in %s does not exist\n" "${patch}" "${reused_patches}"
  64. exit 1
  65. fi
  66. done
  67. fi
  68. done
  69. done
  70. done
  71. # sanity check (check for invalid paths in the reused.list patch lists before proceeding)
  72. # in ascending filename order, apply patches from a directory
  73. apply_patches_from_directory() {
  74. patch_directory="${1}" # directory containing the patch files
  75. if [ -d "${patch_directory}" ]; then
  76. for patch in ${patch_directory}/*.patch; do
  77. if [ "${patch##*/}" = "*.patch" ]; then # oh so ugly
  78. continue # ugly ugly ugly ugly ugly
  79. fi # most hideous thing you've ever seen
  80. git am "${patch}" || continue
  81. done
  82. fi
  83. }
  84. # files listed in the file (if found) are absolute paths, relative to the root of the libreboot src directory
  85. # the file lists patches patches that should be applied
  86. apply_patches_from_file() {
  87. patch_list="${1}" # file listing the paths to all the patches
  88. libreboot_src_root="${2}" # path to the root of the libreboot_src directory
  89. if [ -f "${patch_list}" ]; then
  90. for patchname in $(cat "${patch_list}"); do
  91. git am "${libreboot_src_root}/${patchname}" || continue
  92. done
  93. fi
  94. }
  95. create_branch() {
  96. branchname="${1}"
  97. git branch ${branchname}
  98. git checkout ${branchname}
  99. git checkout master
  100. }
  101. # use git-init on everything
  102. # this is so that we can then apply patche
  103. # for these revisions of vboot and coreboot
  104. for i in $HOMEDIR/coreboot/*; do
  105. if [ ! -d "${i}/" ]; then
  106. continue
  107. fi
  108. for revision in ${i}/*; do
  109. if [ ! -d "${revision}/" ]; then
  110. continue
  111. fi
  112. (
  113. cd "${revision}/"
  114. rm -rf .git
  115. git init
  116. git add -A .
  117. git commit -m "coreboot revision ${revision##*/}"
  118. cd "3rdparty/vboot/"
  119. rm -rf .git
  120. git init
  121. git add -A .
  122. git commit -m "coreboot revision ${revision##*/}"
  123. )
  124. done
  125. done
  126. for payloads in $HOMEDIR/resources/libreboot/config/*; do
  127. if [ ! -d "${payloads}/" ]; then
  128. continue
  129. fi
  130. payload="${payloads##*/}"
  131. for boardconfig in $HOMEDIR/resources/libreboot/config/${payload}/*; do
  132. if [ ! -d "${boardconfig}/" ]; then
  133. continue
  134. fi
  135. boardname="${boardconfig##*/}"
  136. cbrevision=$(cat "${boardconfig}/cbrevision")
  137. vbootrevision=$(cat "${boardconfig}/vbootrevision")
  138. branchname="${payload}_${boardname}"
  139. # the same vboot revision is always used for coreboot revision,
  140. # so we don't need to wworry about checking for that here
  141. # patch that version
  142. (
  143. cd "$HOMEDIR/coreboot/${cbrevision}/${cbrevision}/"
  144. create_branch ${branchname}
  145. git checkout ${branchname}
  146. # apply patches (coreboot, common to all systems using this revision)
  147. apply_patches_from_directory "$HOMEDIR/resources/libreboot/patch/common/coreboot/${cbrevision}"
  148. # apply patches re-used from other boards, before applying main patches (common patches for similar boards)
  149. apply_patches_from_file "$HOMEDIR/resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}/reused.list" ../../..
  150. # apply patches (coreboot, machine-specific for this revision)
  151. apply_patches_from_directory "$HOMEDIR/resources/libreboot/patch/coreboot/${cbrevision}/${payload}/${boardname}"
  152. git checkout master
  153. cd "3rdparty/vboot/"
  154. # reset to known revision (vboot)
  155. create_branch ${branchname}
  156. git checkout ${branchname}
  157. # apply patches (vboot, common to all systems using this revision)
  158. apply_patches_from_directory "$HOMEDIR/resources/libreboot/patch/common/vboot/${vbootrevision}"
  159. # apply patches re-used from other boards, before applying main patches (common patches for similar boards)
  160. apply_patches_from_file "$HOMEDIR/resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}/reused.list" ../../../../..
  161. # apply patches (vboot, machine-specific for this revision)
  162. apply_patches_from_directory "$HOMEDIR/resources/libreboot/patch/vboot/${vbootrevision}/${payload}/${boardname}"
  163. git checkout master
  164. )
  165. done
  166. done