main-config: arch common: kernel/u-boot config defaulting+overriding via hook instead of pre-setting

- common.conf delegating to new `mainline_kernel_decide_version` hooks
- special case handling for v6.7-rc7
- some examples
- late-stage "use rolling branch version"
This commit is contained in:
Ricardo Pardini 2023-12-27 14:55:55 +01:00 committed by Igor
parent 7a1c9a46e7
commit dccf44630f
4 changed files with 219 additions and 13 deletions

View File

@ -6,19 +6,180 @@
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
#
# this is sourced before any other arch specific config file, always. see main-config.sh
# Source the mainline kernel hooks, in a separate file for easier maintenance.
# shellcheck source=/dev/null
source "${SRC}/config/sources/mainline-kernel.conf.sh"
declare -g FAST_CREATE_IMAGE='yes'
declare -g MAIN_CMDLINE='rw no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 splash plymouth.ignore-serial-consoles'
# boot loader configuration
[[ -z $BOOTSOURCE ]] && declare -g BOOTSOURCE="$MAINLINE_UBOOT_SOURCE"
[[ -z $BOOTDIR ]] && declare -g BOOTDIR="$MAINLINE_UBOOT_DIR"
[[ -z $BOOTBRANCH ]] && declare -g BOOTBRANCH="${BOOTBRANCH_BOARD:-"tag:v2022.07"}"
# So the idea is to let the board/family/hooks define these variables.
# If the family does NOT define them, assume sane defaults.
function late_family_config__common_defaults_for_mainline_kernel() {
# @TODO: if KERNELSOURCE is 'none', don't do anything; config is explicitly asking to skip kernel compilation.
if [[ "${KERNELSOURCE}" == "none" ]]; then
display_alert "KERNELSOURCE is set to 'none'; will skip kernel compilation" "common_defaults_for_mainline" "warn"
return
fi
# kernel configuration
[[ -z $KERNELDIR ]] && declare -g KERNELDIR="$MAINLINE_KERNEL_DIR"
[[ -z $KERNELSOURCE ]] && declare -g KERNELSOURCE="$MAINLINE_KERNEL_SOURCE"
[[ -z $KERNELBRANCH ]] && declare -g KERNELBRANCH='branch:linux-6.0.y'
declare problems=0
# Setting KERNELBRANCH and not KERNEL_MAJOR_MINOR: legacy code, that didn't receive KERNEL_MAJOR_MINOR yet.
if [[ -n ${KERNELBRANCH} && -z ${KERNEL_MAJOR_MINOR} ]]; then
display_alert "KERNELBRANCH ('${KERNELBRANCH}') is set, but KERNEL_MAJOR_MINOR is unset" "please make sure they match, or remove KERNELBRANCH and trust the system" "warn"
((problems++))
fi
# The good-behaved mainline will hit this, we will auto-determine. @TODO remove from here
if [[ -z ${KERNELBRANCH} && -n ${KERNEL_MAJOR_MINOR} ]]; then
display_alert "KERNEL_MAJOR_MINOR ('${KERNEL_MAJOR_MINOR}') is set and KERNELBRANCH is unset" "hopefully mainline" "info"
fi
# If KERNELSOURCE is set (NOT mainline), then so should KERNELBRANCH, KERNEL_MAJOR_MINOR be set. Check and warn if not.
# Attention: having KERNELSOURCE set here usually means it is a fork, vendor kernel, or other non-strict mainline kernel.
if [[ -n ${KERNELSOURCE} ]]; then
if [[ -z ${KERNEL_MAJOR_MINOR} ]]; then
display_alert "KERNELSOURCE is set, but KERNEL_MAJOR_MINOR is unset" "please make sure they match" "warn"
((problems++))
fi
if [[ -z ${KERNELBRANCH} ]]; then
display_alert "KERNELSOURCE is set, but KERNELBRANCH is unset" "please make sure they match" "warn"
((problems++))
fi
fi
# KERNEL_MAJOR_MINOR is the key to all this stuff. It must be set.
if [[ -z ${KERNEL_MAJOR_MINOR} ]]; then
display_alert "KERNEL_MAJOR_MINOR is unset" "common_defaults_for_mainline" "warn"
((problems++))
fi
# exit with error if some breaking problem detected above.
if ((problems > 0)); then
exit_with_error "Please fix the above kernel configuration problems (check warnings above)."
fi
# Small debuggings to make sure we're not doing something stupid.
if [[ -z ${KERNELSOURCE} ]]; then
display_alert "KERNELSOURCE is unset" "common_defaults_for_mainline" "info"
else
display_alert "KERNELSOURCE is set by board/family/hooks to '${KERNELSOURCE}'" "common_defaults_for_mainline" "ext"
fi
if [[ -z ${KERNELBRANCH} ]]; then
display_alert "KERNELBRANCH is unset" "common_defaults_for_mainline" "info"
else
display_alert "KERNELBRANCH is set by board/family/hooks to '${KERNELBRANCH}'" "common_defaults_for_mainline" "ext"
fi
if [[ -z ${LINUXFAMILY} ]]; then
display_alert "LINUXFAMILY is unset" "common_defaults_for_mainline" "info"
else
display_alert "LINUXFAMILY is set by board/family/hooks to '${LINUXFAMILY}'" "common_defaults_for_mainline" "ext"
fi
if [[ -z ${KERNELPATCHDIR} ]]; then
display_alert "KERNELPATCHDIR is unset" "common_defaults_for_mainline" "info"
else
display_alert "KERNELPATCHDIR is set by board/family/hooks to '${KERNELPATCHDIR}'" "common_defaults_for_mainline" "ext"
fi
if [[ -z ${KERNEL_PATCH_ARCHIVE_BASE} ]]; then
display_alert "KERNEL_PATCH_ARCHIVE_BASE is unset" "common_defaults_for_mainline" "info"
else
display_alert "KERNEL_PATCH_ARCHIVE_BASE is set by board/family/hooks to '${KERNELPATCHDIR}'" "common_defaults_for_mainline" "ext"
fi
if [[ -z ${LINUXCONFIG} ]]; then
display_alert "LINUXCONFIG is unset" "common_defaults_for_mainline" "info"
else
display_alert "LINUXCONFIG is set by board/family/hooks to '${LINUXCONFIG}'" "common_defaults_for_mainline" "ext"
fi
# Generic defaultings, used for all kernels (including vendor/legacy/3rd-party and mainline).
# If KERNEL_PATCH_ARCHIVE_BASE is unset, set it to LINUXFAMILY.
if [[ -z ${KERNEL_PATCH_ARCHIVE_BASE} ]]; then
display_alert "KERNEL_PATCH_ARCHIVE_BASE is unset; using LINUXFAMILY: '${LINUXFAMILY}'" "common_defaults_for_mainline" "info"
KERNEL_PATCH_ARCHIVE_BASE="$LINUXFAMILY"
fi
# If KERNELPATCHDIR is unset, set it to "archive/${KERNELPATCHDIR}-${KERNEL_MAJOR_MINOR}"
if [[ -z ${KERNELPATCHDIR} ]]; then
display_alert "KERNELPATCHDIR is unset; using 'archive/${KERNEL_PATCH_ARCHIVE_BASE}-${KERNEL_MAJOR_MINOR}'" "common_defaults_for_mainline" "info"
KERNELPATCHDIR="archive/${KERNEL_PATCH_ARCHIVE_BASE}-${KERNEL_MAJOR_MINOR}" # previously was KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"
fi
# If LINUFAMILY is unset... bomb
if [[ -z ${LINUXFAMILY} ]]; then
exit_with_error "LINUXFAMILY is unset after family config; KERNELSOURCE=${KERNELSOURCE}"
fi
# if LINUXCONFIG is unset... default to linux-${LINUXFAMILY}-${BRANCH} # Attention: no KERNEL_MAJOR_MINOR here, so manual file rollover is necessary
if [[ -z ${LINUXCONFIG} ]]; then
display_alert "LINUXCONFIG is unset; using 'linux-${LINUXFAMILY}-${BRANCH}'" "common_defaults_for_mainline" "info"
LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"
fi
# Mainline defaults
if [[ -z ${KERNELSOURCE} ]]; then
display_alert "Using mainline kernel defaults" "common_defaults_for_mainline: KERNEL_MAJOR_MINOR: ${KERNEL_MAJOR_MINOR}" "info"
# this "manifests"/resolves the mirrors; any changes after this will need to resolve their own mirrors; later hooks won't be subject to mirroring
KERNELSOURCE="${MAINLINE_KERNEL_SOURCE}"
# If the branch is unset, auto-determine it based on KERNEL_MAJOR_MINOR; allow hooks to customize
if [[ -z ${KERNELBRANCH} ]]; then
declare original_kernelsource="${KERNELSOURCE}" # store for later comparing
call_extension_method "mainline_kernel_decide_version" <<- 'MAINLINE_KERNEL_DECIDE_VERSION'
*determine KERNELBRANCH, based on family / KERNEL_MAJOR_MINOR / etc*
This hook is run when when we know the family uses mainline (does NOT set KERNELSOURCE),
but the family/board/hooks haven't determined a KERNELBRANCH (tag/branch/commit reference) yet.
All hooks are called in the usual order, the last one setting it "wins".
It is expected that hooks here are able to:
- if kernel in RC period, convert say 6.7 to tag:v6.7-rc7
- "lock" certain families (or all families) to a certain tag in a branch; say convert 6.6 to tag:v6.6.6
- change KERNELSOURCE to adapt to too-new -rc releases that haven't shown up in stable kernel git tree yet
MAINLINE_KERNEL_DECIDE_VERSION
display_alert "Mainline hooks determined" "new KERNELBRANCH='${KERNELBRANCH}'" "info"
# if original_kernelsource does not match the current KERNELSOURCE, log it
if [[ "${original_kernelsource}" != "${KERNELSOURCE}" ]]; then
display_alert "Mainline hooks changed source" "new KERNELSOURCE='${KERNELSOURCE}'" "info"
fi
unset original_kernelsource
fi
fi
}
function late_family_config__common_defaults_for_mainline_uboot() {
if [[ -z ${BOOTDIR} ]]; then
display_alert "BOOTDIR is unset" "common_defaults_for_mainline" "warn"
BOOTDIR="$MAINLINE_UBOOT_DIR"
else
display_alert "BOOTDIR is set by board/family/hooks to '${BOOTDIR}'" "common_defaults_for_mainline" "warn"
fi
if [[ -z ${BOOTSOURCE} ]]; then
display_alert "BOOTSOURCE is unset" "common_defaults_for_mainline" "warn"
BOOTSOURCE="$MAINLINE_UBOOT_SOURCE"
else
display_alert "BOOTSOURCE is set by board/family/hooks to '${BOOTSOURCE}'" "common_defaults_for_mainline" "warn"
fi
if [[ -z ${BOOTBRANCH} ]]; then
display_alert "BOOTBRANCH is unset; BOOTBRANCH_BOARD=${BOOTBRANCH_BOARD} or tag:v2022.07" "common_defaults_for_mainline" "warn"
BOOTBRANCH="${BOOTBRANCH_BOARD:-"tag:v2022.07"}"
else
display_alert "BOOTBRANCH is set by board/family/hooks to '${BOOTBRANCH}'" "common_defaults_for_mainline" "warn"
fi
}
true # make sure to exit with 0 status; this protects against shortcircuits etc above.

View File

@ -0,0 +1,42 @@
#
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023 Ricardo Pardini <ricardo@pardini.net>
# This file is a part of the Armbian Build Framework https://github.com/armbian/build/
#
# Shared versioning logic for Armbian mainline kernels.
function mainline_kernel_decide_version__upstream_release_candidate_number() {
[[ -n "${KERNELBRANCH}" ]] && return 0 # if already set, don't touch it; that way other hooks can run in any order
if [[ "${KERNEL_MAJOR_MINOR}" == "6.7" ]]; then # @TODO: roll over to 6.8 and v6.8-rc1 when it is released, which should be around Sunday, 2024-01-21 - see https://deb.tandrin.de/phb-crystal-ball.htm
declare -g KERNELBRANCH="tag:v6.7-rc7"
display_alert "mainline-kernel: upstream release candidate" "Using KERNELBRANCH='${KERNELBRANCH}' for KERNEL_MAJOR_MINOR='${KERNEL_MAJOR_MINOR}'" "info"
fi
}
### Later than normal hooks, for emergencies / locking versions for release / etc. Use mainline_kernel_decide_version__600 or higher.
## Example: "6.6.7 was recently released with changes that break our drivers/patches/souls. Let's Lock 6.6 to 6.6.6 until we've time to fix it."
#function mainline_kernel_decide_version__600_lock_6.6_to_6.6.6() {
# [[ "${KERNEL_MAJOR_MINOR}" != "6.6" ]] && return 0 # only for 6.6
# declare -g KERNELBRANCH="tag:v6.6.6"
# display_alert "mainline-kernel: locked version for 6.6 kernel" "Using fixed version for 6.6 KERNELBRANCH='${KERNELBRANCH}'" "info"
#}
### Later-than-usual hooks, for changing parameters after the hooks above have run. use mainline_kernel_decide_version__750 or higher.
# https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git is missing 6.7-rc7 tag; use Linus GH repo instead.
# Attention: this does not support/respect git mirror... hopefully kernel.org catches up soon and we can remove this.
function mainline_kernel_decide_version__750_use_torvalds_for_6.7-rc7() {
if [[ "${KERNELBRANCH}" == 'tag:v6.7-rc7' ]]; then
display_alert "Using Linus kernel repo for 6.7-rc7" "${KERNELBRANCH}" "warn"
declare -g KERNELSOURCE="https://github.com/torvalds/linux.git"
display_alert "mainline-kernel: missing torvalds tag on 6.7-rc7" "Using KERNELSOURCE='${KERNELSOURCE}' for KERNELBRANCH='${KERNELBRANCH}'" "info"
fi
}
### Last hooks, defaults to branch if not set by previous hooks. Use mainline_kernel_decide_version__900 or higher.
function mainline_kernel_decide_version__900_defaults() {
[[ -n "${KERNELBRANCH}" ]] && return 0 # if already set, don't touch it; that way other hooks can run in any order
declare -g KERNELBRANCH="branch:linux-${KERNEL_MAJOR_MINOR}.y" # default to stable branch
display_alert "mainline-kernel: default to branch / rolling stable version" "Using KERNELBRANCH='${KERNELBRANCH}' for KERNEL_MAJOR_MINOR='${KERNEL_MAJOR_MINOR}'" "info"
}

View File

@ -194,7 +194,6 @@ function do_main_configuration() {
;;
esac
[[ $USE_GITHUB_UBOOT_MIRROR == yes ]] && UBOOT_MIRROR=github # legacy compatibility?
case $UBOOT_MIRROR in
@ -237,7 +236,7 @@ function do_main_configuration() {
# Let's set default data if not defined in board configuration above
[[ -z $OFFSET ]] && OFFSET=4 # offset to 1st partition (we use 4MiB boundaries by default)
[[ -z $ARCH ]] && ARCH=armhf # makes little sense to default to anything... # @TODO: remove
ATF_COMPILE=yes # @TODO: move to armhf/arm64
ATF_COMPILE=yes # @TODO: move to armhf/arm64
[[ -z $WIREGUARD ]] && WIREGUARD="yes"
[[ -z $EXTRAWIFI ]] && EXTRAWIFI="yes"
[[ -z $SKIP_BOOTSPLASH ]] && SKIP_BOOTSPLASH="no"
@ -299,10 +298,8 @@ function do_extra_configuration() {
declare BOOTCONFIG_VAR_NAME="BOOTCONFIG_${BRANCH^^}"
[[ -n ${!BOOTCONFIG_VAR_NAME} ]] && BOOTCONFIG=${!BOOTCONFIG_VAR_NAME}
[[ -z $LINUXCONFIG ]] && LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"
[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY"
[[ -z $BOOTPATCHDIR ]] && BOOTPATCHDIR="u-boot-$LINUXFAMILY" # @TODO move to hook
[[ -z $ATFPATCHDIR ]] && ATFPATCHDIR="atf-$LINUXFAMILY"
[[ -z $KERNELPATCHDIR ]] && KERNELPATCHDIR="$LINUXFAMILY-$BRANCH"
if [[ "$RELEASE" =~ ^(focal|jammy|kinetic|lunar|mantic|noble)$ ]]; then
DISTRIBUTION="Ubuntu"

View File

@ -220,6 +220,12 @@ function config_post_main() {
# So we gotta explictly know the major.minor to be able to do that scheme.
# If we don't know, we could use BRANCH as reference, but that changes over time, and leads to wastage.
if [[ "${skip_kernel:-"no"}" != "yes" ]]; then
# call hooks to do late validation/mutation of sources, branches, patch dirs, etc.
call_extension_method "late_family_config" <<- 'LATE_FAMILY_CONFIG'
*late defaults/overrides, main hook point for KERNELSOURCE/BRANCH and BOOTSOURCE/BRANCH etc*
LATE_FAMILY_CONFIG
if [[ "${KERNELSOURCE}" != 'none' ]]; then
if [[ "x${KERNEL_MAJOR_MINOR}x" == "xx" ]]; then
display_alert "Problem: after configuration, there's not enough kernel info" "Might happen if you used the wrong BRANCH. Make sure 'BRANCH=${BRANCH}' is valid." "err"