build-uboot.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Download, configure and build mainline U-Boot for the Orange Pi Zero.
  3. # Result: out/u-boot/u-boot-sunxi-with-spl.bin (SPL + U-Boot proper; the H2+
  4. # is 32-bit, so no TF-A/crust is needed). Write it with write-uboot.sh.
  5. #
  6. # Usage: ./build-uboot.sh [all|config|menuconfig|build|clean]
  7. # all (default) configure if needed, then build
  8. # config regenerate .config from orangepi_zero_defconfig
  9. # (+ files/u-boot.config if present; like build-kernel.sh, fails
  10. # if an option of the fragment did not survive)
  11. # menuconfig edit the current .config (kept until "config" is run again)
  12. # build build only (configures first if there is no .config)
  13. # clean remove the U-Boot build directory and out/u-boot/
  14. set -euo pipefail
  15. . "$(dirname "$0")/config.sh"
  16. UBUILD="$OUT/ubuild"
  17. UFRAG="$FILES/u-boot.config"
  18. umake() { make -C "$USRC" O="$UBUILD" -j"$JOBS" "$@"; }
  19. prepare_source() {
  20. need_tools curl tar gzip make "${CROSS_COMPILE}gcc" bison flex bc swig python3 dtc
  21. python3 -c 'import elftools, setuptools' 2>/dev/null ||
  22. die "python3 modules pyelftools and setuptools are required"
  23. [ -d "$USRC" ] && return 0
  24. local tarball="u-boot-${UBOOT_VERSION#v}.tar.gz"
  25. # GitHub mirror first (ftp.denx.de/source.denx.de are often unreachable);
  26. # the denx tarball is .tar.bz2, so it is only a fallback via a temp name.
  27. if ! fetch "$DL/$tarball" "https://github.com/u-boot/u-boot/archive/refs/tags/$UBOOT_VERSION.tar.gz" 2>/dev/null; then
  28. fetch "$DL/u-boot-${UBOOT_VERSION#v}.tar.bz2" \
  29. "https://ftp.denx.de/pub/u-boot/u-boot-${UBOOT_VERSION#v}.tar.bz2"
  30. mkdir -p "$USRC"
  31. tar xjf "$DL/u-boot-${UBOOT_VERSION#v}.tar.bz2" -C "$USRC" --strip-components=1
  32. return 0
  33. fi
  34. mkdir -p "$USRC"
  35. tar xzf "$DL/$tarball" -C "$USRC" --strip-components=1
  36. }
  37. do_config() {
  38. mkdir -p "$UBUILD"
  39. info "configuring: $UBOOT_DEFCONFIG"
  40. umake "$UBOOT_DEFCONFIG"
  41. if [ -f "$UFRAG" ]; then
  42. info "merging files/u-boot.config"
  43. "$USRC/scripts/kconfig/merge_config.sh" -m -O "$UBUILD" \
  44. "$UBUILD/.config" "$UFRAG" >/dev/null
  45. umake olddefconfig
  46. check_fragment "$UFRAG" "$UBUILD/.config"
  47. fi
  48. }
  49. do_build() {
  50. [ -f "$UBUILD/.config" ] || do_config
  51. info "building U-Boot $UBOOT_VERSION"
  52. umake
  53. mkdir -p "$UOUT"
  54. cp "$UBUILD/u-boot-sunxi-with-spl.bin" "$UOUT/"
  55. info "done: $UOUT/u-boot-sunxi-with-spl.bin"
  56. ls -la "$UOUT/u-boot-sunxi-with-spl.bin"
  57. }
  58. cmd="${1:-all}"
  59. case "$cmd" in
  60. all) prepare_source; do_build ;;
  61. config) prepare_source; do_config ;;
  62. menuconfig) prepare_source; [ -f "$UBUILD/.config" ] || do_config; umake menuconfig ;;
  63. build) prepare_source; do_build ;;
  64. clean) rm -rf "$UBUILD" "$UOUT" ;;
  65. *) die "unknown command: $cmd" ;;
  66. esac