# Shared settings for all scripts. Sourced by the other scripts; override any # of these from the environment. # # The board type is picked with ./select-board.sh and kept in .board; BOARD= # in the environment overrides it for one command. Board specifics (versions, # toolchain, defconfigs, device trees, install method, build hooks) are in # boards/.sh, config fragments and device trees in files//. TOP="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BOARDS_DIR="$TOP/boards" BOARD_SELECTION="$TOP/.board" die() { echo "ERROR: $*" >&2; exit 1; } info() { echo ">>> $*"; } # list_boards -> "idname" per supported board list_boards() { local f for f in "$BOARDS_DIR"/*.sh; do [ -e "$f" ] || continue printf '%s\t%s\n' "$(basename "$f" .sh)" \ "$(sed -n 's/^BOARD_NAME="\(.*\)"$/\1/p' "$f" | head -1)" done } # ---- board selection -------------------------------------------------------- # select-board.sh sets CONFIG_NO_BOARD=1: it must work without a selection. if [ "${CONFIG_NO_BOARD:-0}" != 1 ]; then if [ -n "${BOARD:-}" ]; then BOARD_FROM="BOARD from the environment" else BOARD="$(cat "$BOARD_SELECTION" 2>/dev/null || true)" BOARD_FROM="selected with select-board.sh" fi [ -n "$BOARD" ] || die "no board type selected; run ./select-board.sh first" [ -f "$BOARDS_DIR/$BOARD.sh" ] || die "unknown board type '$BOARD' (known: $(list_boards | cut -f1 | tr '\n' ' '))" . "$BOARDS_DIR/$BOARD.sh" # ---- defaults the board file did not set -------------------------- : "${KERNEL_VERSION:=7.3.4}" : "${UBOOT_VERSION:=v2026.10}" : "${JOBS:=$(nproc)}" export ARCH=arm CROSS_COMPILE # ---- directories -------------------------------------------------- DL="$TOP/dl" # downloaded tarballs (shared) SRC="$TOP/src" # extracted sources (shared, built out of tree) OUT="$TOP/out/$BOARD" # build results of this board type BACKUP_DIR="$TOP/out/backup" # bootloader areas saved by write-uboot.sh (all boards) FILES="$TOP/files" # config fragments shared by all boards BFILES="$FILES/$BOARD" # this board's fragments, device trees, overlays KSRC="$SRC/linux-$KERNEL_VERSION" USRC="$SRC/u-boot-${UBOOT_VERSION#v}" KOUT="$OUT/kernel" # staging: boot/ and lib/modules/ UOUT="$OUT/u-boot" # Every command states which board type it works for. if [ -t 2 ]; then printf '\033[1;36m=== board: %s [%s] (%s)\033[0m\n' "$BOARD_NAME" "$BOARD" "$BOARD_FROM" >&2 else printf '=== board: %s [%s] (%s)\n' "$BOARD_NAME" "$BOARD" "$BOARD_FROM" >&2 fi fi # Fail early if a required program is missing; don't install anything. need_tools() { local t missing=() for t in "$@"; do command -v "$t" >/dev/null 2>&1 || missing+=("$t"); done [ ${#missing[@]} -eq 0 ] || die "missing tools: ${missing[*]} (install them and re-run)" } # check_fragment DOTCONFIG FRAGMENT... # Every option in the config fragments must have survived olddefconfig; a # renamed symbol or a missing dependency silently drops options otherwise. # Fragments are read in order and a later one overrides an earlier one, as # with merge_config.sh. check_fragment() { local dotconfig="$1"; shift local -A want=() from=() local -a order=() local frag line sym val bad=0 have for frag in "$@"; do while IFS= read -r line; do case "$line" in CONFIG_*=*) sym="${line%%=*}"; val="${line#*=}" ;; "# CONFIG_"*" is not set") sym="${line#\# }"; sym="${sym%% *}"; val=n ;; *) continue ;; esac [ -n "${want[$sym]+x}" ] || order+=("$sym") want[$sym]="$val"; from[$sym]="${frag#"$TOP"/}" done < "$frag" done for sym in "${order[@]}"; do have="$(grep -E "^$sym=" "$dotconfig" | cut -d= -f2- || true)" [ -n "$have" ] || have=n if [ "$have" != "${want[$sym]}" ]; then echo " config: $sym wanted ${want[$sym]} (${from[$sym]}), got $have" >&2 bad=1 fi done [ $bad -eq 0 ] || die ".config does not match the fragments (see above)" info "config check passed ($(for frag in "$@"; do printf '%s ' "${frag#"$TOP"/}"; done))" } # fetch DEST URL [fallback URL...] fetch() { local dest="$1"; shift [ -s "$dest" ] && return 0 mkdir -p "$(dirname "$dest")" local url for url in "$@"; do info "downloading $url" if curl -fL --connect-timeout 20 --retry 2 -o "$dest.part" "$url"; then mv "$dest.part" "$dest" return 0 fi done rm -f "$dest.part" die "could not download $(basename "$dest")" }