u-boot 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/env sh
  2. # helper script: builds U-Boot source code
  3. #
  4. # Copyright (C) 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2021, 2022 Ferass El Hafidi <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. . "${board_dir}/board.cfg" # source
  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. for config in "${board_dir}/config"/*; do
  81. if [ ! -f "${config}" ]; then
  82. printf "%s: Target %s has no configs to build for. Skipping build.\n" \
  83. "build/payload/u-boot" "${board}"
  84. RET=1
  85. continue
  86. fi
  87. config_name="${config#$board_dir/config/}"
  88. if [ "$config_name" = "default" ]; then
  89. dest_dir="payload/u-boot/${board}"
  90. else
  91. dest_dir="payload/u-boot/${board}/${config_name}"
  92. fi
  93. mkdir -p "${dest_dir}"
  94. printf "%s: Building for target %s (config %s).\n" \
  95. "build/payload/u-boot" "${board}" "${config_name}"
  96. make -C "${ubdir}" distclean
  97. cp "${config}" "${ubdir}/.config"
  98. make -C "${ubdir}" olddefconfig
  99. make -C "${ubdir}" -j"$(nproc)" all
  100. for f in "${ubdir}"/u-boot "${ubdir}"/u-boot.bin "${ubdir}"/u-boot.dtb \
  101. "${ubdir}"/u-boot.img "${ubdir}"/u-boot.itb "${ubdir}"/u-boot.elf; do
  102. if [ -f "$f" ]; then
  103. mv "$f" "${dest_dir}/"
  104. fi
  105. done
  106. make -C "${ubdir}" distclean
  107. printf "%s: Built for target %s (config %s).\n" \
  108. "build/payload/u-boot" "${board}" "${config_name}"
  109. done
  110. done
  111. printf "Done! U-Boot files are in payload/u-boot/\n\n"
  112. exit $RET
  113. # ------------------- DONE ----------------------