diff --git a/lib/functions/compilation/kernel-config.sh b/lib/functions/compilation/kernel-config.sh index 646166aaf6..6e37e444fa 100644 --- a/lib/functions/compilation/kernel-config.sh +++ b/lib/functions/compilation/kernel-config.sh @@ -29,10 +29,16 @@ function kernel_config() { [[ ! -d "${kernel_work_dir}" ]] && exit_with_error "kernel_work_dir does not exist: ${kernel_work_dir}" declare previous_config_filename=".config.armbian.previous" declare kernel_config_source_filename="" # which actual .config was used? + declare config_after_kernel_config_extension_filename=".config_after_kernel_config_extension" LOG_SECTION="kernel_config_initialize" do_with_logging do_with_hooks kernel_config_initialize if [[ "${KERNEL_CONFIGURE}" == "yes" ]]; then + + # Check sanity of kernel config and repair the config if necessary + LOG_SECTION="kernel_config_check_and_repair" do_with_logging do_with_hooks kernel_config_check_and_repair + + # Start interactive config menu unless running rewrite-kernel-config if [[ "${ARMBIAN_COMMAND}" != "rewrite-kernel-config" ]]; then # This piece is interactive, no logging display_alert "Starting (interactive) kernel ${KERNEL_MENUCONFIG:-menuconfig}" "${LINUXCONFIG}" "debug" @@ -78,6 +84,9 @@ function kernel_config_initialize() { # Call the extensions. This is _also_ done during the kernel artifact's prepare_version, for consistent caching. call_extensions_kernel_config + # Save the config state after the extensions forced some kernel options, for later checks + run_host_command_logged cp -pv ".config" "${config_after_kernel_config_extension_filename}" + display_alert "Kernel configuration" "${LINUXCONFIG}" "info" } @@ -89,6 +98,7 @@ function call_extensions_kernel_config() { Instead, use `custom_kernel_config` which runs later and can undo anything done by this step. Important: this hook might be run multiple times, and one of them might not have a .config in place. 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. ARMBIAN_KERNEL_CONFIG # Custom hooks receive a clean / updated config; depending on their modifications, they may need to run olddefconfig again. @@ -99,6 +109,7 @@ function call_extensions_kernel_config() { Armbian default Kconfig modifications have already been applied and can be overriden. Important: this hook might be run multiple times, and one of them might not have a .config in place. 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 } @@ -138,3 +149,25 @@ function kernel_config_export() { run_host_command_logged cp -pv defconfig "${kernel_config_source_filename}.defconfig" fi } + +# Manually forcing kernel options with 'call_extensions_kernel_config()' can introduce missing dependencies or misconfigurations +# This function checks the config, re-establishes its sanity if necessary and outputs any changes to the user +function kernel_config_check_and_repair() { + # Re-run kernel make to automatically solve any dependencies and/or misconfigurations + run_kernel_make_dialog oldconfig + + # Compare the previously saved config file with the current one + if cmp --silent "${kernel_work_dir}/.config" "${kernel_work_dir}/${config_after_kernel_config_extension_filename}"; then + # Do nothing if both files are the same + display_alert "No misconfigurations or missing kernel option dependencies detected" "info" + else + # Warn user and output diffs if make had to change anything because of missing dependencies or misconfigurations + display_alert "Forced kernel options introduced misconfigurations or missing dependencies!" "Please re-run rewrite-kernel-config" "warn" + display_alert "If this warning persists" "please remove dependent options using kernel-config or adapt your custom_kernel_config hooks" "warn" + display_alert "In some cases, the issue might also be" "misconfigured options in armbian_kernel_config hooks" "debug" + + run_host_command_logged scripts/diffconfig "${config_after_kernel_config_extension_filename}" ".config" + + display_alert "See options above which have been changed automatically" "to solve dependencies and/or misconfigurations" "warn" + fi +}