#!/bin/bash # Download, configure and build mainline U-Boot for the selected board type # (./select-board.sh). Result: out//u-boot/u-boot-sunxi-with-spl.bin # (SPL + U-Boot proper; the H2+ and R40 are 32-bit, so no TF-A/crust is # needed). Write it with write-uboot.sh. # # Usage: ./build-uboot.sh [all|config|menuconfig|build|clean] # all (default) configure if needed, then build # config regenerate .config from the board's defconfig (boards/.sh) # (+ files//u-boot.config if present; like build-kernel.sh, fails # if an option of the fragment did not survive) # menuconfig edit the current .config (kept until "config" is run again) # build build only (configures first if there is no .config) # clean remove the U-Boot build directory and out//u-boot/ set -euo pipefail . "$(dirname "$0")/config.sh" UBUILD="$OUT/ubuild" UFRAG="$BFILES/u-boot.config" umake() { make -C "$USRC" O="$UBUILD" -j"$JOBS" "$@"; } prepare_source() { need_tools curl tar gzip make "${CROSS_COMPILE}gcc" bison flex bc swig python3 dtc python3 -c 'import elftools, setuptools' 2>/dev/null || die "python3 modules pyelftools and setuptools are required" [ -d "$USRC" ] && return 0 local tarball="u-boot-${UBOOT_VERSION#v}.tar.gz" # GitHub mirror first (ftp.denx.de/source.denx.de are often unreachable); # the denx tarball is .tar.bz2, so it is only a fallback via a temp name. if ! fetch "$DL/$tarball" "https://github.com/u-boot/u-boot/archive/refs/tags/$UBOOT_VERSION.tar.gz" 2>/dev/null; then fetch "$DL/u-boot-${UBOOT_VERSION#v}.tar.bz2" \ "https://ftp.denx.de/pub/u-boot/u-boot-${UBOOT_VERSION#v}.tar.bz2" mkdir -p "$USRC" tar xjf "$DL/u-boot-${UBOOT_VERSION#v}.tar.bz2" -C "$USRC" --strip-components=1 return 0 fi mkdir -p "$USRC" tar xzf "$DL/$tarball" -C "$USRC" --strip-components=1 } do_config() { mkdir -p "$UBUILD" info "configuring: $UBOOT_DEFCONFIG" umake "$UBOOT_DEFCONFIG" if [ -f "$UFRAG" ]; then info "merging ${UFRAG#"$TOP"/}" "$USRC/scripts/kconfig/merge_config.sh" -m -O "$UBUILD" \ "$UBUILD/.config" "$UFRAG" >/dev/null umake olddefconfig check_fragment "$UBUILD/.config" "$UFRAG" fi } do_build() { [ -f "$UBUILD/.config" ] || do_config info "building U-Boot $UBOOT_VERSION" umake mkdir -p "$UOUT" cp "$UBUILD/u-boot-sunxi-with-spl.bin" "$UOUT/" info "done ($BOARD_NAME): $UOUT/u-boot-sunxi-with-spl.bin" ls -la "$UOUT/u-boot-sunxi-with-spl.bin" } cmd="${1:-all}" case "$cmd" in all) prepare_source; do_build ;; config) prepare_source; do_config ;; menuconfig) prepare_source; [ -f "$UBUILD/.config" ] || do_config; umake menuconfig ;; build) prepare_source; do_build ;; clean) rm -rf "$UBUILD" "$UOUT" ;; *) die "unknown command: $cmd" ;; esac