From 5eeb998509198ff4cde75905584e80a1bd61df1d Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 26 Oct 2025 10:03:10 +0100 Subject: [PATCH] armbian-kernel: standardize on opts_y/opts_n/opts_m + opts_val arrays - call_extensions_kernel_config() now declares the vars and calls armbian_kernel_config_apply_opts_from_arrays() at the end - so each individual hook doesn't need to - adapt family code using the old way too --- .../families/include/meson64_common.inc | 6 +-- config/sources/families/meson-s4t7.conf | 14 ++---- lib/functions/compilation/armbian-kernel.sh | 47 ++++--------------- lib/functions/compilation/kernel-config.sh | 10 ++++ 4 files changed, 25 insertions(+), 52 deletions(-) diff --git a/config/sources/families/include/meson64_common.inc b/config/sources/families/include/meson64_common.inc index 4e8310564f..588453ec65 100644 --- a/config/sources/families/include/meson64_common.inc +++ b/config/sources/families/include/meson64_common.inc @@ -49,11 +49,7 @@ esac # Use custom vendor driver for wireless rtl88x2cs # See https://github.com/armbian/build/pull/6227 function custom_kernel_config__enable_rtl88x2cs_driver() { - kernel_config_modifying_hashes+=("CONFIG_RTL8822CS=m") - if [[ -f .config ]]; then - display_alert "Enabling rtl88x2cs driver in kernel config" "armbian-kernel" "wrn" - kernel_config_set_m CONFIG_RTL8822CS - fi + opts_m+=("CONFIG_RTL8822CS") } # this helper function includes postprocess for s400 and its variants. diff --git a/config/sources/families/meson-s4t7.conf b/config/sources/families/meson-s4t7.conf index 7e8b88b3eb..4ebe6ae31b 100644 --- a/config/sources/families/meson-s4t7.conf +++ b/config/sources/families/meson-s4t7.conf @@ -121,6 +121,11 @@ function build_custom_uboot__meson_s4t7_build_custom_uboot() { } function custom_kernel_config__add_khadas_common_drivers() { + display_alert "Enabling kernel config" "DEBUG_KERNEL=y, EXPERT=y, EMBEDDED=y to fix khadas_common_drivers compilation" "info" + opts_y+=("DEBUG_KERNEL") # Unfortunately, debug kernel has to be enabled to make khadas_common_drivers compile + opts_y+=("EMBEDDED") + opts_y+=("EXPERT") + # viraniac: The kernel config hooks are always called twice, once without being in kernel directory and once with current directory being the kernel work directory. if [[ ! -f .config ]]; then display_alert "$BOARD" "Fetching khadas common drivers git info" "info" @@ -136,15 +141,6 @@ function custom_kernel_config__add_khadas_common_drivers() { # Hack to ensure that we will recreate kernel if common_drivers source changes kernel_config_modifying_hashes+=("khadas_common_drivers=${GIT_INFO_COMMON_DRIVERS[SHA1]}") - - # viraniac: kernel_config_modifying_hashes is only needed during first call of this function to calculate kernel artifact version string. It serves no purpose whatsoever during second call. - kernel_config_modifying_hashes+=("CONFIG_DEBUG_KERNEL=y" "CONFIG_EXPERT=y" "CONFIG_EMBEDDED=y") - else - # Unfortunately, debug kernel has to be enabled to make khadas_common_drivers compile - display_alert "Enabling kernel config" "DEBUG_KERNEL=y, EXPERT=y, EMBEDDED=y to fix khadas_common_drivers compilation" "info" - kernel_config_set_y DEBUG_KERNEL - kernel_config_set_y EXPERT - kernel_config_set_y EMBEDDED fi } diff --git a/lib/functions/compilation/armbian-kernel.sh b/lib/functions/compilation/armbian-kernel.sh index 1354178df5..55d659c843 100644 --- a/lib/functions/compilation/armbian-kernel.sh +++ b/lib/functions/compilation/armbian-kernel.sh @@ -13,10 +13,15 @@ # armbian_kernel_config hooks are called twice: once for obtaining the version via hashing, # and once for actually modifying the kernel .config. They *must* be consistent, and can't depend on # the contents of the .config (which is not available during version calculation). -# the convenience `armbian_kernel_config_apply_opts_from_arrays` function lets you simply define -# the opts_n/opts_y arrays and/or the opts_val dictionary with the wanted values and it will -# hash and apply at the correct moments. Otherwise: check for .config presence. -# In both cases: be consistent -- if you're not, you're effectively making Armbian worse. +# +# To facilitate this, use the arrays opts_n/opts_y/opts_m and/or the opts_val dictionary. +# those will be hashed and applied at the correct moments automatically. +# +# Be consistent -- both the versioning/hashing mechanism and the fast-rebuild principles depend on it. +# +# A word on modules or built-in: try use modules if possible. Certain things should be built-in, +# specially if they're needed before the initramfs is available. +# # The exact same also applies to custom_kernel_config hooks. # Please note: Manually changing options doesn't check the validity of the .config file. This is done at next make time. Check for warnings in build log. @@ -33,8 +38,6 @@ # kernel_config_modifying_hashes - Array accumulating configuration changes. # function armbian_kernel_config__extrawifi_enable_wifi_opts_80211() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() if linux-version compare "${KERNEL_MAJOR_MINOR}" ge 6.13; then # Required by many wifi drivers; otherwise "error: 'struct net_device' has no member named 'ieee80211_ptr'" # In 6.13 something changed ref CONFIG_MAC80211 and CONFIG_CFG80211; enable both to preserve wireless drivers @@ -43,7 +46,6 @@ function armbian_kernel_config__extrawifi_enable_wifi_opts_80211() { opts_y+=("CONFIG_MAC80211_MESH") opts_y+=("CONFIG_CFG80211_WEXT") fi - armbian_kernel_config_apply_opts_from_arrays } # Enables the NETKIT kernel configuration option for kernels version 6.7 and above. @@ -55,12 +57,9 @@ function armbian_kernel_config__extrawifi_enable_wifi_opts_80211() { # If both conditions are met, it alerts the user about enabling NETKIT and sets the NETKIT option to 'y' in the kernel configuration. # function armbian_kernel_config__netkit() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() if linux-version compare "${KERNEL_MAJOR_MINOR}" ge 6.7; then opts_y+=("NETKIT") fi - armbian_kernel_config_apply_opts_from_arrays } # Disables various kernel configuration options that conflict with Armbian's kernel build requirements. @@ -80,8 +79,6 @@ function armbian_kernel_config__netkit() { # performed if the .config file exists. # function armbian_kernel_config__disable_various_options() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() display_alert "Enable CONFIG_EXPERT=y" "armbian-kernel" "debug" opts_y+=("EXPERT") # Too many config options are hidden behind EXPERT=y, lets have it always on @@ -95,18 +92,13 @@ function armbian_kernel_config__disable_various_options() { # DONE: Disable: version shenanigans opts_n+=("CONFIG_LOCALVERSION_AUTO") # This causes a mismatch between what Armbian wants and what make produces. opts_val["CONFIG_LOCALVERSION"]='""' # Must be empty; make is later invoked with LOCALVERSION and it adds up - - armbian_kernel_config_apply_opts_from_arrays } function armbian_kernel_config__force_pa_va_48_bits_on_arm64() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() if [[ "${ARCH}" == "arm64" ]]; then opts_y+=("CONFIG_ARM64_VA_BITS_48") opts_val["CONFIG_ARM64_PA_BITS"]="48" fi - armbian_kernel_config_apply_opts_from_arrays } # Configures kernel options to enable or disable eBPF and BTF debug information. @@ -132,9 +124,6 @@ function armbian_kernel_config__force_pa_va_48_bits_on_arm64() { # 0 on successful configuration application. # function armbian_kernel_config__600_enable_ebpf_and_btf_info() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() - if [[ "${KERNEL_BTF}" == "no" ]]; then # If user is explicit by passing "KERNEL_BTF=no", then actually disable all debug info. display_alert "Disabling eBPF and BTF info for kernel" "as requested by KERNEL_BTF=no" "info" opts_y+=("CONFIG_DEBUG_INFO_NONE") # Enable the "none" option @@ -160,9 +149,6 @@ function armbian_kernel_config__600_enable_ebpf_and_btf_info() { "CONFIG_DEBUG_INFO" "CONFIG_DEBUG_INFO_DWARF5" "CONFIG_DEBUG_INFO_BTF" "CONFIG_DEBUG_INFO_BTF_MODULES" # BTF & CO-RE == off ) fi - armbian_kernel_config_apply_opts_from_arrays - - return 0 } # Enables ZRAM support by configuring the kernel for compressed memory swap. @@ -181,8 +167,6 @@ function armbian_kernel_config__600_enable_ebpf_and_btf_info() { # kernel_config_modifying_hashes - Array used to store configuration changes. # function armbian_kernel_config__enable_zram_support() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() opts_y+=("ZSWAP") # Enables compressed swap space in memory opts_y+=("ZSWAP_ZPOOL_DEFAULT_ZBUD") # Sets default compression pool for ZSWAP to ZBUD opts_m+=("ZSMALLOC") # Enables compressed memory allocator for better memory usage @@ -195,7 +179,6 @@ function armbian_kernel_config__enable_zram_support() { opts_y+=("ZRAM_BACKEND_DEFLATE") opts_y+=("ZRAM_BACKEND_842") opts_y+=("ZRAM_BACKEND_LZO") - armbian_kernel_config_apply_opts_from_arrays } # Enables almost all IPTABLES/NFTABLES options as modules [whilst @@ -205,8 +188,6 @@ function armbian_kernel_config__enable_zram_support() { # split in part from armbian_kernel_config__enable_docker_support. # function armbian_kernel_config__select_nftables() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() opts_m+=("BRIDGE_NETFILTER") # Enables netfilter support for the bridge opts_m+=("IP6_NF_FILTER") # Enables IPv6 netfilter filtering support opts_m+=("IP6_NF_IPTABLES") # IP6 tables support (required for filtering) @@ -403,7 +384,6 @@ function armbian_kernel_config__select_nftables() { opts_m+=("IP_SET_HASH_IPPORTNET") opts_m+=("IP_SET_BITMAP_IP") opts_m+=("IP_SET_BITMAP_PORT") - armbian_kernel_config_apply_opts_from_arrays } # Enables Docker support by configuring a comprehensive set of kernel options required for Docker functionality. @@ -418,8 +398,6 @@ function armbian_kernel_config__select_nftables() { # components. These settings ensure that the kernel is properly configured to support containerized environments. # function armbian_kernel_config__enable_docker_support() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() opts_y+=("BTRFS_FS") # Enables the BTRFS file system support opts_y+=("BTRFS_FS_POSIX_ACL") # Enables POSIX ACL support for BTRFS opts_y+=("BLK_CGROUP") # Enables block layer control groups (cgroups) @@ -491,7 +469,6 @@ function armbian_kernel_config__enable_docker_support() { opts_y+=("XFRM") # Enables transform (XFRM) framework support opts_m+=("XFRM_ALGO") # Enables cryptographic algorithm support for XFRM opts_m+=("XFRM_USER") # Enables user space XFRM framework support - armbian_kernel_config_apply_opts_from_arrays } # Enables live system access to the kernel configuration via /proc/config.gz. @@ -505,18 +482,12 @@ function armbian_kernel_config__enable_docker_support() { # kernel_config_modifying_hashes - Array holding pending kernel configuration changes. # function armbian_kernel_config__enable_config_access_in_live_system() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() opts_y+=("CONFIG_IKCONFIG") # This information can be extracted from the kernel image file with the script scripts/extract-ikconfig and used as input to rebuild the current kernel or to build another kernel opts_y+=("CONFIG_IKCONFIG_PROC") # This option enables access to the kernel configuration file through /proc/config.gz - armbian_kernel_config_apply_opts_from_arrays } function armbian_kernel_config__restore_enable_gpio_sysfs() { - declare -A opts_val=() - declare -a opts_y=() opts_n=() opts_m=() opts_y+=("CONFIG_GPIO_SYSFS") # This was a victim of not having EXPERT=y due to some _DEBUG conflicts in old times. Re-enable it forcefully. - armbian_kernel_config_apply_opts_from_arrays } # +++++++++++ HELPERS CORNER +++++++++++ diff --git a/lib/functions/compilation/kernel-config.sh b/lib/functions/compilation/kernel-config.sh index 7aabd9d559..15a65a7812 100644 --- a/lib/functions/compilation/kernel-config.sh +++ b/lib/functions/compilation/kernel-config.sh @@ -86,6 +86,13 @@ function kernel_config_initialize() { # These kernel config hooks are always called twice, once without being in kernel directory and once with current directory being the kernel work directory. # You must check with "if [[ -f .config ]]; then" in which of the two phases you are. Otherwise, functions like "kernel_config_set_y" won't work. function call_extensions_kernel_config() { + # Prepare arrays and dict for modifications. + # Those will be used by the hooks called below. + # shellcheck disable=SC2034 + declare -A opts_val=() + # shellcheck disable=SC2034 + declare -a opts_y=() opts_n=() opts_m=() + # Run the core-armbian config modifications here, built-in extensions: call_extension_method "armbian_kernel_config" <<- 'ARMBIAN_KERNEL_CONFIG' *Armbian-core default hook point for pre-olddefconfig Kernel config modifications* @@ -108,6 +115,9 @@ function call_extensions_kernel_config() { Either way, the hook _must_ add representative changes to the `kernel_config_modifying_hashes` array, for kernel config hashing. Please note: Manually changing options doesn't check the validity of the .config file. Check for warnings in your build log. CUSTOM_KERNEL_CONFIG + + # Apply the modifications set in the arrays/dict + armbian_kernel_config_apply_opts_from_arrays } function kernel_config_finalize() {