u-boot-download.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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() # (uboot_revision uboot_dir)
  31. {
  32. uboot_revision="$1"
  33. uboot_dir="$2"
  34. if [ -d "${uboot_dir}" ]; then
  35. printf \
  36. "REMARK: '%s' directory already exists. Skipping setup.\n" \
  37. "${uboot_dir}"
  38. return 0
  39. fi
  40. if [ ! -d "${uboot_dir}" ]; then
  41. mkdir -p "${uboot_dir}"
  42. fi
  43. if [ ! -d "${uboot_dir}" ]; then
  44. printf \
  45. "ERROR: '%s' directory not created. Check file system permissions\n" \
  46. "${uboot_dir}"
  47. return 1
  48. fi
  49. if [ ! -d "${uboot_dir}/.git" ] && [ -d "${uboot_dir}" ]; then
  50. rm -Rf "${uboot_dir}"
  51. fi
  52. if [ ! -d "${uboot_dir}" ]; then
  53. printf "Download u-boot from upstream:\n"
  54. git clone https://source.denx.de/u-boot/u-boot \
  55. "${uboot_dir}" || \
  56. rm -Rf "${uboot_dir}"
  57. if [ ! -d "${uboot_dir}" ]; then
  58. printf \
  59. "ERROR: %s: Problem with git-clone. Network issue?\n" \
  60. "download/u-boot"
  61. return 1
  62. fi
  63. else
  64. git -C "${uboot_dir}" pull || touch build_error
  65. if [ -f build_error ]; then
  66. printf \
  67. "ERROR: %s: Problem with git-pull. Network issue?\n" \
  68. "download/u-boot"
  69. return 1
  70. fi
  71. fi
  72. git -C "${uboot_dir}" reset --hard ${uboot_revision} || \
  73. touch build_error
  74. if [ -f build_error ]; then
  75. printf \
  76. "ERROR: %s: Unable to reset to commit ID/tag '%s' for board '%s' on tree '%s'\n" \
  77. "download/u-boot" "${uboot_revision}" "${1}" "${uboot_dir}"
  78. return 1
  79. fi
  80. }
  81. strip_comments()
  82. {
  83. file="$1"
  84. # Remove comments
  85. sed 's/#.*//' "${file}" | \
  86. # Remove lines composed of whitespaces only
  87. sed '/^\W\+$/d' | \
  88. # Remove empty lines
  89. sed '/^$/d'
  90. }
  91. printf "Downloading u-boot and (if exist in build system) applying patches\n"
  92. downloadfor $1 "$2"
  93. rm -f "build_error"
  94. printf "\n\n"
  95. if [ "${deleteblobs}" = "true" ]; then
  96. bloblist="$3"
  97. if [[ -f "${bloblist}" ]]; then
  98. for blob_path in $(strip_comments "${bloblist}"); do
  99. if echo "${blob_path}" | grep '/$' 2>&1 >/dev/null ; then
  100. printf "Deleting blob directory: '%s/%s'\n" \
  101. "${uboot_dir}" "${blob_path}"
  102. rm -rf "${uboot_dir}/${blob_path}"
  103. else
  104. printf "Deleting blob file: '%s/%s'\n" \
  105. "${uboot_dir}" "${blob_path}"
  106. rm -f "${uboot_dir}/${blob_path}"
  107. fi
  108. done
  109. else
  110. printf \
  111. "ERROR: %s: bloblist: %s not found.\n" \
  112. "$(basename $0)" "${bloblist}"
  113. exit 1
  114. fi
  115. fi
  116. exit 0