build-uboot.sh 2.8 KB

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