roms 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env bash
  2. #
  3. # helper script: build coreboot images with various payloads
  4. #
  5. # Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe <info@minifree.org>
  6. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  7. # Copyright (C) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # This script assumes that the working directory is the root
  23. # of git or release archive
  24. [ "x${DEBUG+set}" = 'xset' ] && set -v
  25. set -u -e
  26. projectname="$(cat projectname)"
  27. listboards() {
  28. for boarddir in resources/coreboot/*; do
  29. if [ ! -d "${boarddir}" ]; then continue; fi
  30. board="${boarddir##resources/coreboot/}"
  31. board="${board%/}"
  32. printf '%s\n' "${board##*/}"
  33. done
  34. }
  35. help() {
  36. cat <<- EOF
  37. USAGE: ./build boot roms boardname
  38. To build *all* boards, do this: ./build boot roms all
  39. To list *all* boards, do this: ./build boot roms list
  40. Optional Flags:
  41. -d: displaymode
  42. -p: payload
  43. -k: keyboard layout
  44. Example: ./build boot roms x60
  45. Example: ./build boot roms x200_8mb x60
  46. Example: ./build boot roms x230_12mb -p grub -d corebootfb -k usqwerty
  47. possible values for 'boardname':
  48. $(listboards)
  49. Refer to the ${projectname} documentation for more information.
  50. EOF
  51. }
  52. die() {
  53. printf 'Error: %s\n' "${@}" 1>&2
  54. exit 1
  55. }
  56. # Build ROM images for supported boards
  57. buildrom() {
  58. board="$1"
  59. # Start by building blobs and placing them in the coreboot tree only for boards that need them
  60. ./blobutil download ${board} || exit 1
  61. if [ -d "resources/coreboot/${board}/" ]; then
  62. ./build boot roms_helper "${board}${opts}"
  63. else
  64. die "\nbuild/roms: target not defined in the build system: %s\n" "${board}"
  65. fi
  66. }
  67. buildrom_release() {
  68. board="$1"
  69. if [ -d "resources/coreboot/${board}/" ]; then
  70. ./build release deblob ${board}
  71. if [ "$?" = 2 ]; then
  72. ./build boot roms_helper "${board}"
  73. else
  74. ./build boot roms_helper deblobbed "${board}"
  75. fi
  76. else
  77. die "\nbuild/roms: target not defined in the build system: %s\n" "${board}"
  78. fi
  79. }
  80. if [ $# -gt 0 ]; then
  81. firstoption="${1}"
  82. if [ "${firstoption}" = "help" ]; then
  83. help
  84. exit 0
  85. fi
  86. if [ "${firstoption}" = "list" ]; then
  87. listboards
  88. exit 0
  89. fi
  90. while [[ $# > 0 ]]; do
  91. case ${1} in
  92. -d)
  93. opts+=" -d ${2}"
  94. shift ;;
  95. -p)
  96. opts+=" -p ${2}"
  97. shift ;;
  98. -k)
  99. opts+=" -k ${2}"
  100. shift ;;
  101. *)
  102. boards+="${1} " ;;
  103. esac
  104. shift
  105. done
  106. if [ -z ${opts+x} ]; then
  107. opts=""
  108. fi
  109. printf "Building %s ROM images\n" "${projectname}"
  110. if [ "${firstoption}" = "release" ]; then
  111. for boardname in $(listboards); do
  112. buildrom_release "${boardname}" || die "build/roms: something went wrong"
  113. done
  114. elif [ "${firstoption}" = "all" ]; then
  115. for boardname in $(listboards); do
  116. buildrom "${boardname}" || die "build/roms: something went wrong"
  117. done
  118. else
  119. for board in ${boards}; do
  120. buildrom "${board}" || die "build/roms: something went wrong"
  121. done
  122. fi
  123. else
  124. help
  125. exit 1
  126. fi
  127. printf "\n\nDone! Your ROMs are in bin/\n\n"