u-boot 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env bash
  2. # helper script: download u-boot
  3. #
  4. # Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2021 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.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. [ "x${DEBUG+set}" = 'xset' ] && set -v
  21. set -u -e
  22. # set this when you want to modify each u-boot tree
  23. # for example, you want to test custom patches
  24. # NODELETE= ./download coreboot
  25. deleteblobs="true"
  26. [ "x${NODELETE+set}" = 'xset' ] && deleteblobs="false"
  27. # Error handling is extreme in this script.
  28. # This script handles the internet, and Git. Both are inherently unreliable.
  29. [[ -f build_error ]] && rm -f build_error
  30. downloadfor() {
  31. uboot_revision="v2021.07"
  32. uboot_dir="u-boot/u-boot"
  33. if [ -d "${uboot_dir}" ]; then
  34. printf \
  35. "REMARK: '%s' directory already exists. Skipping setup.\n" \
  36. "${uboot_dir}"
  37. return 0
  38. fi
  39. if [ ! -d "${uboot_dir}" ]; then
  40. mkdir -p "${uboot_dir}"
  41. fi
  42. if [ ! -d "${uboot_dir}" ]; then
  43. printf \
  44. "ERROR: '%s' directory not created. Check file system permissions\n" \
  45. "${uboot_dir}"
  46. return 1
  47. fi
  48. if [ ! -d "${uboot_dir}/.git" ] && [ -d "${uboot_dir}" ]; then
  49. rm -Rf "${uboot_dir}"
  50. fi
  51. if [ ! -d "${uboot_dir}" ]; then
  52. printf "Download u-boot from upstream:\n"
  53. git clone https://source.denx.de/u-boot/u-boot \
  54. "${uboot_dir}" || \
  55. rm -Rf "${uboot_dir}"
  56. if [ ! -d "${uboot_dir}" ]; then
  57. printf \
  58. "ERROR: %s: Problem with git-clone. Network issue?\n" \
  59. "download/u-boot"
  60. return 1
  61. fi
  62. else
  63. git -C "${uboot_dir}" pull || touch build_error
  64. if [ -f build_error ]; then
  65. printf \
  66. "ERROR: %s: Problem with git-pull. Network issue?\n" \
  67. "download/u-boot"
  68. return 1
  69. fi
  70. fi
  71. git -C "${uboot_dir}" reset --hard ${uboot_revision} || \
  72. touch build_error
  73. if [ -f build_error ]; then
  74. printf \
  75. "ERROR: %s: Unable to reset to commit ID/tag '%s' for board '%s' on tree '%s'\n" \
  76. "download/u-boot" "${uboot_revision}" "${1}" "${uboot_dir}"
  77. return 1
  78. fi
  79. }
  80. strip_comments()
  81. {
  82. file="$1"
  83. # Remove comments
  84. sed 's/#.*//' "${file}" | \
  85. # Remove lines composed of whitespaces only
  86. sed '/^\W\+$/d' | \
  87. # Remove empty lines
  88. sed '/^$/d'
  89. }
  90. printf "Downloading u-boot and (if exist in build system) applying patches\n"
  91. downloadfor
  92. rm -f "build_error"
  93. printf "\n\n"
  94. if [ "${deleteblobs}" = "true" ]; then
  95. bloblist="resources/u-boot/default/blobs.list"
  96. for blob_path in $(strip_comments "${bloblist}"); do
  97. if echo "${blob_path}" | grep '/$' 2>&1 >/dev/null ; then
  98. printf "Deleting blob directory: '%s/%s'\n" \
  99. "${uboot_dir}" "${blob_path}"
  100. rm -rf "${uboot_dir}/${blob_path}"
  101. else
  102. printf "Deleting blob file: '%s/%s'\n" \
  103. "${uboot_dir}" "${blob_path}"
  104. rm -f "${uboot_dir}/${blob_path}"
  105. fi
  106. done
  107. fi
  108. exit 0