Skip to content

Commit 79eb7e3

Browse files
committed
Build U-boot for all boards in parallel if there are enough CPU cores
Signed-off-by: Alexey Charkov <alchark@flipper.net>
1 parent 1436906 commit 79eb7e3

1 file changed

Lines changed: 43 additions & 11 deletions

File tree

build-uboot.sh

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,48 @@ else
7777
BOARDS="$BOARD"
7878
fi
7979

80-
for i in $BOARDS; do
81-
pushd "$UBOOT_DIR"
82-
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE" clean
83-
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE" "$i"-rk3576_defconfig rockchip-ramboot.config
84-
./scripts/kconfig/merge_config.sh -m .config "$CONFIGS"
85-
make -j$(nproc) CROSS_COMPILE="$CROSS_COMPILE" BL31="$BL31" ROCKCHIP_TPL="$ROCKCHIP_TPL" TEE="$TEE"
86-
popd
80+
NPROC=$(nproc)
81+
NBOARDS=$(set -- $BOARDS; echo $#)
82+
83+
# Run as many boards in parallel as we have cores, but never more than
84+
# the number of boards. Give each build an even slice of the cores
85+
# (rounded up so we don't leave cores idle). Memory/IO assumed not to bind.
86+
MAX_PAR=$(( NBOARDS < NPROC ? NBOARDS : NPROC ))
87+
[ "$MAX_PAR" -lt 1 ] && MAX_PAR=1
88+
JOBS=$(( (NPROC + MAX_PAR - 1) / MAX_PAR ))
89+
90+
# Track temp build dirs so we can clean them all up on exit.
91+
TMPDIRS=""
92+
cleanup() { [ -n "$TMPDIRS" ] && rm -rf $TMPDIRS; }
93+
trap cleanup EXIT
94+
95+
build_board() {
96+
local i="$1"
97+
local out="$2" # out-of-tree temp build dir
8798

88-
rm -rf "$UBOOT_OUT"/"$i"
89-
mkdir -p "$UBOOT_OUT"/"$i"
90-
cp "$UBOOT_DIR"/u-boot-rockchip*.bin "$UBOOT_OUT"/"$i"/
91-
cp "$RKBIN_DIR"/rk3576_*loader_*.bin "$UBOOT_OUT"/"$i"
99+
make -C "$UBOOT_DIR" O="$out" -j"$JOBS" -l"$NPROC" \
100+
CROSS_COMPILE="$CROSS_COMPILE" \
101+
"$i"-rk3576_defconfig rockchip-ramboot.config || return 1
102+
"$UBOOT_DIR"/scripts/kconfig/merge_config.sh -m -O "$out" "$out/.config" "$CONFIGS" || return 1
103+
make -C "$UBOOT_DIR" O="$out" -j"$JOBS" -l"$NPROC" \
104+
CROSS_COMPILE="$CROSS_COMPILE" \
105+
BL31="$BL31" ROCKCHIP_TPL="$ROCKCHIP_TPL" TEE="$TEE" || return 1
106+
107+
rm -rf "$UBOOT_OUT/$i"
108+
mkdir -p "$UBOOT_OUT/$i"
109+
cp "$out"/u-boot-rockchip*.bin "$UBOOT_OUT/$i"/
110+
cp "$RKBIN_DIR"/rk3576_*loader_*.bin "$UBOOT_OUT/$i"/
111+
}
112+
113+
rc=0
114+
for i in $BOARDS; do
115+
# Throttle: wait until fewer than MAX_PAR jobs are running.
116+
while [ "$(jobs -rp | wc -l)" -ge "$MAX_PAR" ]; do wait -n; done
117+
out=$(mktemp -d) || { rc=1; break; }
118+
TMPDIRS="$TMPDIRS $out"
119+
build_board "$i" "$out" &
92120
done
121+
122+
# Collect results from all remaining jobs.
123+
for pid in $(jobs -rp); do wait "$pid" || rc=1; done
124+
exit "$rc"

0 commit comments

Comments
 (0)