u-boot 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env bash
  2. # helper script: builds U-Boot source code
  3. #
  4. # Copyright (C) 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2021 Vitali64 <vitali64pmemail@protonmail.com>
  6. # Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.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. RET=0
  24. # Build U-Boot
  25. # ---------------------------------------------------------------------
  26. printf "Building U-Boot payloads\n"
  27. # Build for all boards if no argument is given
  28. if [ "$#" -eq 0 ]; then
  29. for board_dir in resources/u-boot/*; do
  30. if [ -d "${board_dir}/config/" ]; then
  31. set -- "$@" "${board_dir#resources/u-boot/}"
  32. fi
  33. done
  34. fi
  35. [ ! -d "payload/" ] && mkdir -p payload/
  36. [ ! -d "payload/u-boot" ] && mkdir -p payload/u-boot/
  37. # Appends additional version info to U-Boot
  38. our_version="$(cat version)"
  39. projectname="$(cat projectname)"
  40. export LOCALVERSION="-${projectname}-${our_version}"
  41. for board in "$@"; do
  42. board_dir="resources/u-boot/${board}"
  43. rm -rf "payload/u-boot/${board}"
  44. mkdir -p "payload/u-boot/${board}"
  45. ubtree="undefined"
  46. arch="undefined"
  47. if [ ! -f "${board_dir}/board.cfg" ]; then
  48. printf "%s: Target %s does not have a board.cfg. Skipping build.\n" \
  49. "build/payload/u-boot" "${board}"
  50. RET=1
  51. continue
  52. fi
  53. # Override the above defaults using board.cfg
  54. source "${board_dir}/board.cfg"
  55. if [ "${ubtree}" = "undefined" ]; then
  56. printf "%s: Target %s does not define a U-Boot tree. Skipping build.\n" \
  57. "build/payload/u-boot" "${board}"
  58. RET=1
  59. continue
  60. fi
  61. if [ "${arch}" = "undefined" ]; then
  62. printf "%s: Target %s does not define a CPU type. Skipping build.\n" \
  63. "build/payload/u-boot" "${board}"
  64. RET=1
  65. continue
  66. fi
  67. ubdir="u-boot/${board}"
  68. if [ "${board}" != "${ubtree}" ]; then
  69. ubdir="u-boot/${ubtree}"
  70. fi
  71. if [ ! -d "${ubdir}" ]; then
  72. ./download u-boot "$board"
  73. fi
  74. if [ ! -d "${ubdir}" ]; then
  75. printf "%s: Failed to download U-Boot for target %s. Skipping build.\n" \
  76. "build/payload/u-boot" "${board}"
  77. RET=1
  78. continue
  79. fi
  80. if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
  81. export CROSS_COMPILE=x86_64-linux-
  82. elif [ "${arch}" = "ARMv7" ]; then
  83. export CROSS_COMPILE=arm-linux-gnueabi-
  84. elif [ "${arch}" = "AArch64" ]; then
  85. export CROSS_COMPILE=aarch64-linux-gnu-
  86. fi
  87. for config in "${board_dir}/config"/*; do
  88. if [ ! -f "${config}" ]; then
  89. printf "%s: Target %s has no configs to build for. Skipping build.\n" \
  90. "build/payload/u-boot" "${board}"
  91. RET=1
  92. continue
  93. fi
  94. config_name="${config#$board_dir/config/}"
  95. if [ "$config_name" = "default" ]; then
  96. dest_dir="payload/u-boot/${board}"
  97. else
  98. dest_dir="payload/u-boot/${board}/${config_name}"
  99. fi
  100. mkdir -p "${dest_dir}"
  101. printf "%s: Building for target %s (config %s).\n" \
  102. "build/payload/u-boot" "${board}" "${config_name}"
  103. make -C "${ubdir}" distclean
  104. cp "${config}" "${ubdir}/.config"
  105. make -C "${ubdir}" olddefconfig
  106. make -C "${ubdir}" -j"$(nproc)" all
  107. for f in "${ubdir}"/u-boot{,.bin,.dtb,.img,.itb,.elf}; do
  108. if [ -f "$f" ]; then
  109. mv "$f" "${dest_dir}/"
  110. fi
  111. done
  112. make -C "${ubdir}" distclean
  113. printf "%s: Built for target %s (config %s).\n" \
  114. "build/payload/u-boot" "${board}" "${config_name}"
  115. done
  116. done
  117. printf "Done! U-Boot files are in payload/u-boot/\n\n"
  118. exit $RET
  119. # ------------------- DONE ----------------------