Compare commits

...

13 Commits

Author SHA1 Message Date
5b9f1f2f39 Re-add specific device config 2025-10-23 16:46:16 -04:00
c5bfc7907b Remove specific device config 2025-10-23 16:43:34 -04:00
533b0b5ffc Re-add specific device config 2025-10-23 16:34:37 -04:00
eba54804d3 Blank the seed file 2025-10-23 16:31:34 -04:00
09b62923a8 Re-add specific device config 2025-10-23 16:19:58 -04:00
960755e6a2 Use faster feeds mirror 2025-10-22 21:16:41 -04:00
0fa9b0d85a Streamling config options 2025-10-22 21:02:36 -04:00
4de18e6696 Add optional build clean arg to --source 2025-10-22 20:55:20 -04:00
3772d373bb Tune resource limits 2025-10-22 20:27:21 -04:00
b75597946d Improve worktree detection 2025-10-22 19:35:38 -04:00
018a91e216 Introduce reusable worktrees 2025-10-22 19:31:58 -04:00
0c61a27b06 Reorganize from_source() 2025-10-22 19:25:59 -04:00
675ed5eb39 Abandon upstream seed, untenable 2025-10-22 19:11:51 -04:00
2 changed files with 68 additions and 73 deletions

View File

@@ -5,7 +5,7 @@
# See README and ./profiles for device configuration # See README and ./profiles for device configuration
# Set default release # Set default release
: "${RELEASE:="24.10.3"}" : "${RELEASE:="24.10.4"}"
# @internal # @internal
print_help() { print_help() {
@@ -22,18 +22,16 @@ print_help() {
--release,-r,--version,-v RELEASE ("snapshot", "22.03.5") --release,-r,--version,-v RELEASE ("snapshot", "22.03.5")
--buildroot,-b PATH --buildroot,-b PATH
Default: location of openwrtbuilder script Default: location of openwrtbuilder script
--source --source[=CLEAN]
Build image from source, not from Image Builder Build image from source, not from Image Builder
Allows make config options to be passed in profile Optional CLEAN runs the given clean mode before building
Uses git worktree for multi-profile deduplication (clean|targetclean|dirclean|distclean)
--ssh-upgrade HOST --ssh-upgrade HOST
Examples: root@192.168.1.1, root@router.lan Examples: root@192.168.1.1, root@router.lan
--ssh-backup SSH_PATH --ssh-backup SSH_PATH
Enabled by default for --ssh-upgrade Enabled by default for --ssh-upgrade
--flash,-f DEVICE --flash,-f DEVICE
Example: /dev/sdX Example: /dev/sdX
--reset
Cleanup all source and output files
--depends --depends
Force dependency installation Force dependency installation
--yes,-y --yes,-y
@@ -127,8 +125,8 @@ parse_input() {
debug "${FUNCNAME[0]}" "$*" debug "${FUNCNAME[0]}" "$*"
declare -ga PROFILES declare -ga PROFILES
declare -gi RESET=0 FROM_SOURCE=0 YES=0 DEBUG=0 FORCE_DEPENDS=0 declare -gi RESET=0 FROM_SOURCE=0 YES=0 DEBUG=0 FORCE_DEPENDS=0
declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV SOURCE_CLEAN
local long_opts='release:,version:,profile:,buildroot:,source,' local long_opts='release:,version:,profile:,buildroot:,source::,'
long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,depends,yes,debug,help' long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,depends,yes,debug,help'
if _input=$(getopt -o +r:v:p:b:sf:ydh -l $long_opts -- "$@"); then if _input=$(getopt -o +r:v:p:b:sf:ydh -l $long_opts -- "$@"); then
@@ -138,7 +136,12 @@ parse_input() {
--release|-r|--version|-v) shift; USER_RELEASE="$1" ;; --release|-r|--version|-v) shift; USER_RELEASE="$1" ;;
--profile|-p) shift; PROFILES+=("$1") ;; --profile|-p) shift; PROFILES+=("$1") ;;
--buildroot|-b) shift; BUILD_ROOT="$1" ;; --buildroot|-b) shift; BUILD_ROOT="$1" ;;
--source|-s) FROM_SOURCE=1 ;; --source|-s) FROM_SOURCE=1
case "$1" in
-*|"") ;; # if empty
*) SOURCE_CLEAN="$1"; shift ;;
esac
;;
--ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;; --ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;;
--ssh-backup) shift; SSH_BACKUP_PATH="$1" ;; --ssh-backup) shift; SSH_BACKUP_PATH="$1" ;;
--flash|-f) shift; FLASH_DEV="$1" ;; --flash|-f) shift; FLASH_DEV="$1" ;;
@@ -514,11 +517,29 @@ from_source() {
local seed_file="$BUILD_DIR/.config" local seed_file="$BUILD_DIR/.config"
local worktree_meta="$SRC_DIR/.git/worktrees/source-$ref" local worktree_meta="$SRC_DIR/.git/worktrees/source-$ref"
local pkg config commit seed_file description local pkg config commit seed_file description
local -a make_opts config_opts local -a make_opts
local -a config_opts=(
"CONFIG_TARGET_${TARGET%%/*}=y"
"CONFIG_TARGET_${TARGET//\//_}=y"
"CONFIG_TARGET_PROFILE=DEVICE_$DEVICE"
"CONFIG_TARGET_${TARGET//\//_}_DEVICE_$DEVICE=y"
"CONFIG_TARGET_ROOTFS_${FILESYSTEM^^}=y"
"CONFIG_TARGET_MULTI_PROFILE=n"
"CONFIG_BUILDBOT=n"
"CONFIG_ALL_KMODS=n"
"CONFIG_ALL_NONSHARED=n"
"CONFIG_DEVEL=n"
"CONFIG_COLLECT_KERNEL_DEBUG=n"
"CONFIG_SDK=n"
"CONFIG_SDK_LLVM_BPF=n"
"CONFIG_IB=n"
"CONFIG_MAKE_TOOLCHAIN=n"
"CONFIG_TARGET_PER_DEVICE_ROOTFS=n"
)
echo "Building from source is under development" echo "Building from source is under development"
# Remove all build directories and worktrees # Remove all build directories and worktrees if --reset
if ((RESET)); then if ((RESET)); then
if [[ -d "$BUILD_DIR" || -d "$worktree_meta" ]]; then if [[ -d "$BUILD_DIR" || -d "$worktree_meta" ]]; then
execute git -C "$SRC_DIR" worktree remove --force --force "$BUILD_DIR" execute git -C "$SRC_DIR" worktree remove --force --force "$BUILD_DIR"
@@ -536,29 +557,35 @@ from_source() {
execute git clone "$src_url" "$SRC_DIR" execute git clone "$src_url" "$SRC_DIR"
fi fi
# Recreate worktree from the remote ref # Reuse worktree if present; otherwise create it (support branches and tags)
execute git -C "$SRC_DIR" worktree remove --force "$BUILD_DIR" || true if git -C "$BUILD_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
execute rm -rf "$BUILD_DIR" execute git -C "$BUILD_DIR" fetch origin --tags --prune
execute git -C "$BUILD_DIR" reset --hard "origin/$ref" || \
execute git -C "$BUILD_DIR" reset --hard "$ref" || \
execute git -C "$BUILD_DIR" checkout --detach "$ref"
else
execute git -C "$SRC_DIR" worktree prune --verbose execute git -C "$SRC_DIR" worktree prune --verbose
# Prefer local tag/branch if present, otherwise use remote-tracking branch
if ! execute git -C "$SRC_DIR" worktree add --detach "$BUILD_DIR" "$ref"; then
execute git -C "$SRC_DIR" worktree add --detach "$BUILD_DIR" "origin/$ref" execute git -C "$SRC_DIR" worktree add --detach "$BUILD_DIR" "origin/$ref"
fi
fi
# Add cherrypick commits if specified in profile # Add cherrypick commits if specified in profile (skip if already included)
for entry in ${P_ARR[cherrypicks]}; do for entry in ${P_ARR[cherrypicks]}; do
remote="${entry%%:*}" remote="${entry%%:*}"
commit="${entry##*:}" commit="${entry##*:}"
# Add remote if not present
if ! git -C "$BUILD_DIR" remote | grep -q "^$remote$"; then if ! git -C "$BUILD_DIR" remote | grep -q "^$remote$"; then
execute git -C "$BUILD_DIR" remote add "$remote" "https://github.com/$remote/openwrt.git" execute git -C "$BUILD_DIR" remote add "$remote" "https://github.com/$remote/openwrt.git"
fi fi
# Fetch remote
execute git -C "$BUILD_DIR" fetch "$remote" execute git -C "$BUILD_DIR" fetch "$remote"
# Cherry-pick commit execute git -C "$BUILD_DIR" merge-base --is-ancestor "$commit" HEAD ||
execute git -C "$BUILD_DIR" cherry-pick "$commit" execute git -C "$BUILD_DIR" cherry-pick "$commit"
done done
# Print commit info # Print commit info
commit=$(git -C "$BUILD_DIR" rev-parse HEAD) commit=$(git -C "$BUILD_DIR" rev-parse HEAD)
description=$(git -C "$BUILD_DIR" describe) description=$(git -C "$BUILD_DIR" describe --always --dirty)
echo "Current commit hash: $commit" echo "Current commit hash: $commit"
echo "Git worktree description: $description" echo "Git worktree description: $description"
@@ -570,26 +597,24 @@ from_source() {
# Begin OpenWRT build process # Begin OpenWRT build process
((DEBUG)) && make_opts+=("V=sc") ((DEBUG)) && make_opts+=("V=sc")
# Cleanup build environment # Cleanup build environment: heavy clean only when --reset was used earlier
execute make "${make_opts[@]}" "-j1" distclean
# make clean # compiled output # make clean # compiled output
# make targetclean # compiled output, toolchain # make targetclean # compiled output, toolchain
# make dirclean # compiled output, toolchain, build tools # make dirclean # compiled output, toolchain, build tools
# make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache # make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache
if [[ -n $SOURCE_CLEAN ]]; then
execute make "${make_opts[@]}" "-j1" "$SOURCE_CLEAN"
else
debug "Skipping cleanup step"
fi
# Use a custom (faster) mirror # Use a custom (faster) mirror
# execute sed -i -E 's;git.openwrt.org/(feed|project);github.com/openwrt;' feeds.conf.default execute sed -i -E 's;git.openwrt.org/(feed|project);github.com/openwrt;' feeds.conf.default
# Update package feed # Update package feed
./scripts/feeds update -a -f && ./scripts/feeds update -a -f &&
./scripts/feeds install -a -f ./scripts/feeds install -a -f
# Grab the release seed config
if ! execute "$DL_TOOL" "-o" "$seed_file" "$seed_url"; then
echo "Could not obtain $seed_file from $seed_url"
return 1
fi
# Add custom packages # Add custom packages
for pkg in $PACKAGES; do for pkg in $PACKAGES; do
if [[ $pkg == -* ]]; then if [[ $pkg == -* ]]; then
@@ -599,47 +624,13 @@ from_source() {
fi fi
done done
# Disable unecessary buildbot config options
config_opts+=(
"CONFIG_BUILDBOT=n"
"CONFIG_ALL_KMODS=n"
"CONFIG_ALL_NONSHARED=n"
"CONFIG_DEVEL=n"
"CONFIG_COLLECT_KERNEL_DEBUG=n"
"CONFIG_SDK=n"
"CONFIG_SDK_LLVM_BPF=n"
"CONFIG_IB=n"
"CONFIG_MAKE_TOOLCHAIN=n"
)
# Only compile selected fs
execute sed -i '/CONFIG_TARGET_ROOTFS_/d' "$seed_file"
config_opts+=("CONFIG_TARGET_PER_DEVICE_ROOTFS=n")
case "$FILESYSTEM" in
squashfs) config_opts+=(
"CONFIG_TARGET_ROOTFS_EXT4FS=n"
"CONFIG_TARGET_ROOTFS_SQUASHFS=y"
) ;;
ext4) config_opts+=(
"CONFIG_TARGET_ROOTFS_SQUASHFS=n"
"CONFIG_TARGET_ROOTFS_EXT4FS=y"
) ;;
esac
# Only compile selected target image
execute sed -i '/CONFIG_TARGET_DEVICE_/d' "$seed_file"
config_opts+=(
"CONFIG_TARGET_MULTI_PROFILE=n"
"CONFIG_TARGET_PROFILE=DEVICE_$DEVICE"
"CONFIG_TARGET_${TARGET//\//_}_DEVICE_$DEVICE=y"
)
# Add profile config options # Add profile config options
for config in ${P_ARR[config]}; do for config in ${P_ARR[config]}; do
config_opts+=("$config") config_opts+=("$config")
done done
# Write options to config seed file # Reset and write options to config seed file
[[ -f $seed_file ]] && execute rm -f "$seed_file"
for config in "${config_opts[@]}"; do for config in "${config_opts[@]}"; do
debug "Writing $config to $seed_file" debug "Writing $config to $seed_file"
echo "$config" >> "$seed_file" echo "$config" >> "$seed_file"
@@ -648,18 +639,22 @@ from_source() {
# Expand seed into full config # Expand seed into full config
execute make "${make_opts[@]}" "-j1" defconfig execute make "${make_opts[@]}" "-j1" defconfig
# make_opts+=("-j$(($(nproc)-2))") # Run serial make download for better reliability
((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$(($(nproc)-2))") execute make "${make_opts[@]}" "-j1" download
# (Optional) Disable multicore make world
# ((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$(($(nproc)-2))")
make_opts+=("-j$(($(nproc)-2))")
# Make image # Make image
if ! execute ionice -c 3 chrt --idle 0 nice -n19 make "${make_opts[@]}" BIN_DIR="$BIN_DIR" download world; then if ! execute ionice -c2 -n7 nice -n19 make "${make_opts[@]}" BIN_DIR="$BIN_DIR" world; then
echo "Error: make failed" echo "Error: make failed"
return 1 return 1
fi fi
execute popd || return 1 execute popd || return 1
# Symlink output images to root of BIN_DIR (match Image Builder) # Symlink output images to root of BIN_DIR (match Image Builder behavior)
shopt -s nullglob shopt -s nullglob
for image in "$BIN_DIR/targets/${TARGET}/"*.{img,img.gz,ubi}; do for image in "$BIN_DIR/targets/${TARGET}/"*.{img,img.gz,ubi}; do
execute ln -fs "$image" "$BIN_DIR/${image##*/}" execute ln -fs "$image" "$BIN_DIR/${image##*/}"

View File

@@ -19,7 +19,7 @@ declare -Ag r4s=(
[target]="rockchip/armv8" [target]="rockchip/armv8"
[filesystem]="ext4" [filesystem]="ext4"
[packages]="${default_packages[*]} \ [packages]="${default_packages[*]} \
luci-app-ddns luci-app-sqm irqbalance \ luci-app-ddns luci-app-sqm \
adblock luci-app-adblock \ adblock luci-app-adblock \
collectd-mod-df usbutils kmod-usb-storage kmod-usb-storage-uas \ collectd-mod-df usbutils kmod-usb-storage kmod-usb-storage-uas \
kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \ kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \