kernel: Refactor configure script

This patch removes support for "platforms" and "sub-platforms" which we
won't need any more.

Instead, configuration files are now called by their architecture name
and flavour. The "generic" flavour is the default flavour and any other
flavours for the same architecture will be based on it.

There are no changes to the configuration files in this patch.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer 2022-12-13 16:44:12 +00:00
parent 1350134bfa
commit f05d9a8595
4 changed files with 248 additions and 240 deletions

View File

@ -5,7 +5,7 @@
name = kernel
version = 6.0.6
release = 0.2
release = 0.3
thisapp = linux-%{version}
maintainer = Arne Fitzenreiter <arne.fitzenreiter@ipfire.org>
@ -97,7 +97,7 @@ build
configure_kernel() {
local flavour=${1}
local suffix
if [ "${flavour}" != "default" ]; then
if [ "${flavour}" != "generic" ]; then
suffix="-${flavour}"
fi
@ -107,7 +107,7 @@ build
# Generate configuration files for all kernels we are going to
# build.
configure_kernel "default"
configure_kernel "generic"
end
build
@ -116,7 +116,7 @@ build
local suffix
local localversion="%{localversion}"
local fullversion="%{fullver}"
if [ "${flavour}" != "default" ]; then
if [ "${flavour}" != "generic" ]; then
suffix="-${flavour}"
localversion="${localversion}.${flavour}"
fullversion="${fullversion}.${flavour}"
@ -220,7 +220,7 @@ build
}
# Build the kernel
build_kernel "default"
build_kernel "generic"
# cpupower
chmod +x tools/power/cpupower/utils/version-gen.sh

View File

@ -4,19 +4,15 @@
# Copyright (C) - IPFire Development Team <info@ipfire.org> #
###############################################################################
BASEDIR=$(dirname ${0})
SCRIPTS_DIR=${BASEDIR}
BASEDIR="$(dirname "${0}")"
SCRIPTS_DIR="${BASEDIR}"
# x86_64
CONFIGS="x86_64:default"
CONFIGS=(
# x86_64
"x86_64:generic"
# aarch64
CONFIGS="${CONFIGS} aarch64:default"
PLATFORMS="x86 arm"
declare -A SUBPLATFORMS
SUBPLATFORMS=(
[arm]="arm64"
# aarch64
"aarch64:generic"
)
search_kernel_dir() {
@ -29,36 +25,50 @@ search_kernel_dir() {
done
}
function get_platform() {
local arch="${1}"
case "${arch}" in
aarch64)
echo "arm"
;;
x86_64)
echo "x86"
;;
*)
return 1
;;
esac
arches() {
local config
for config in ${CONFIGS[@]}; do
echo "${config%:*}"
done
}
function get_subplatform() {
flavours_for_arch() {
local arch="${1}"
case "${arch}" in
aarch64)
echo "arm64"
;;
*)
return 1
;;
esac
local config
for config in ${CONFIGS[@]}; do
if [ "${arch}:" = "${config%:*}:" ]; then
echo "${config#*:}"
fi
done
}
function get_kernel_arch() {
configs() {
local arch="${1}"
local flavour="${2}"
shift 2
# Add any extra files first
local configs=( "$@" )
# Add the generic configuration
configs+=( "config-generic" )
# If flavour is not generic, we add *-generic
if [ "${flavour}" != "generic" ]; then
configs+=( "config-${arch}-generic" )
fi
# Add the architecture/flavour configuration
configs+=( "config-${arch}-${flavour}" )
# Return the result
echo "${configs[@]}"
return 0
}
get_kernel_arch() {
local arch="${1}"
case "${arch}" in
@ -68,89 +78,74 @@ function get_kernel_arch() {
x86_64)
echo "x86"
;;
*)
echo "${arch}"
;;
esac
}
function merge_config() {
local arch=${1}
local flavour=${2}
local output=${3}
kernel_config() {
local arch="${1}"
local action="${2}"
local config_in="${3}"
local config_out="${4}"
echo "Running 'make ${action}' for ${arch}..."
local kernel_arch="$(get_kernel_arch "${arch}")"
pushd "${KERNEL_DIR}" >/dev/null
cat "${config_in}" > ".config"
# Run the configuration program
make ARCH="${kernel_arch}" "${action}"
# Write back the configuration file
cat ".config" > "${config_out}"
popd >/dev/null
}
merge_config() {
local arch="${1}"
local flavour="${2}"
local output="${3}"
shift 3
local arg
for arg in arch flavour output; do
if [ -z "${!arg}" ]; then
echo >&2 "merge usage: <arch> <flavour> <output filename>"
exit 2
return 2
fi
done
local config_mode="olddefconfig"
local extra_configs
while [ $# -gt 0 ]; do
case "${1}" in
--mode=*)
config_mode=${1#--mode=}
shift
;;
-*)
echo >&2 "Unknown option: ${1}"
;;
*)
extra_configs="${extra_configs} ${1}"
;;
esac
shift
done
local configs="${extra_configs} config-generic"
case "${arch}:${flavour}" in
# x86
x86_64:default)
configs="${configs} config-x86-generic"
;;
# ARM64
aarch64:default)
configs="${configs} config-arm64-generic"
;;
*)
echo >&2 "ERROR: Invalid parameters given: $@"
return 1
;;
esac
local configs="$(configs "${arch}" "${flavour}" "$@")"
# Merge the configuration files from its elementary configuration
# files.
local tmp_out=$(mktemp)
local tmp_in=$(mktemp)
local tmp_out="$(mktemp)"
local tmp_in="$(mktemp)"
local config
for config in ${configs}; do
cat ${tmp_out} > ${tmp_in}
perl ${SCRIPTS_DIR}/merge.pl \
${tmp_in} ${config} > ${tmp_out}
cat "${tmp_out}" > "${tmp_in}"
if ! perl "${SCRIPTS_DIR}/merge.pl" \
"${tmp_in}" "${config}" > "${tmp_out}"; then
echo >&2 "Could not merge configuration for ${arch} ${flavour}"
rm -f "${tmp_in}" "${tmp_out}"
return 1
fi
done
if [ "${config_mode}" != "none" ]; then
echo "Running 'make olddefconfig' for ${arch} (${flavour})..."
local kernel_arch="$(get_kernel_arch "${arch}")"
(
cd ${KERNEL_DIR}
cat ${tmp_out} > .config
make ARCH="${kernel_arch}" ${config_mode}
cat .config > ${tmp_out}
)
fi
cat ${tmp_out} > ${output}
rm -f ${tmp_in} ${tmp_out}
cat "${tmp_out}" > "${output}"
rm -f "${tmp_in}" "${tmp_out}"
}
# This function runs an interactive "make oldconfig".
function make_config() {
# This function runs an interactive "make oldconfig"
make_config() {
local action="${1}"
local arch="${2}"
@ -160,174 +155,187 @@ function make_config() {
fi
# Detect kernel arch
local kernel_arch="$(get_kernel_arch "${arch}")"
local flavour="default"
local flavour="generic"
local config_in=$(mktemp)
local config_out=$(mktemp)
local diff_out=$(mktemp)
# Create a temporary directory
local tmpdir="$(mktemp -d)"
merge_config ${arch} ${flavour} ${config_in} --mode=none
# Merge configuration
if ! merge_config "${arch}" "${flavour}" "${tmpdir}/.config.old"; then
echo "Could not merge configuration for ${arch} (${flavour})" >&2
return 1
fi
(
pushd ${KERNEL_DIR}
cat ${config_in} > .config
# Open the kernel configuration editor (in the given mode)
if ! kernel_config "${arch}" "${action}" "${tmpdir}/.config.old" "${tmpdir}/.config"; then
echo >&2 "Kernel configuration editing has been unsuccessful"
rm -rf "${tmpdir}"
return 1
fi
echo "You may now edit the configuration..."
make ARCH=${kernel_arch} "${action}"
# Diff the old and changed configuration
if ! python3 "${SCRIPTS_DIR}/configdiff.py" \
"${tmpdir}/.config.old" "${tmpdir}/.config" > "${tmpdir}/diff"; then
rm -rf "${tmpdir}"
return 1
fi
cat .config > ${config_out}
popd
)
# Check if the diff contains any data
if [ ! -s "${tmpdir}/diff" ]; then
echo "No changes found"
return 0
fi
python3 ${SCRIPTS_DIR}/configdiff.py ${config_in} ${config_out} > ${diff_out}
# Apply the diff to all configurations
if ! diff_configs "${tmpdir}/diff"; then
rm -rf "${tmpdir}"
return 1
fi
# Update the rest of the configurations.
diff_configs ${diff_out} --mode=oldconfig
# Cleanup
rm -rf "${tmpdir}"
rm -f ${config_in} ${config_out} ${diff_out}
return 0
}
# config-generic
# Intersection of all files.
# config-x86-x86_64
# Diff against merge of (config-generic and config-x86-generic).
diff_configs() {
local tmpdir="$(mktemp -d)"
function diff_configs() {
local extra_configs="$@"
local configs=()
local filename
local platform
local subplatform
local config
for config in ${CONFIGS[@]}; do
arch="${config%:*}"
flavour="${config#*:}"
declare -A platform_configs
declare -A subplatform_configs
# Generate the filename
local filename="${tmpdir}/full-${arch}-${flavour}"
tmpdir=$(mktemp -d)
for config in ${CONFIGS}; do
arch=${config%:*}
flavour=${config#*:}
filename=${tmpdir}/config-${arch}-${flavour}
merge_config ${arch} ${flavour} ${filename} ${extra_configs}
platform="$(get_platform "${arch}")"
subplatform="$(get_subplatform "${arch}")"
if [ -n "${subplatform}" ]; then
subplatform_configs[${subplatform}]="${subplatform_configs[${subplatform}]} ${filename}"
else
platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
# Merge configuration
if ! merge_config "${arch}" "${flavour}" "${filename}" "$@"; then
rm -rf "${tmpdir}"
return 1
fi
done
local common_configs
for platform in ${PLATFORMS}; do
for subplatform in ${SUBPLATFORMS[${platform}]}; do
filename="${tmpdir}/config-${subplatform}-common"
python3 ${SCRIPTS_DIR}/configcommon.py ${subplatform_configs[${subplatform}]} \
> ${filename}
# Run "oldconfig" to ensure there are no gaps in other architectures
kernel_config "${arch}" "oldconfig" "${filename}" "${filename}"
platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
done
filename="${tmpdir}/config-${platform}-common"
python3 ${SCRIPTS_DIR}/configcommon.py ${platform_configs[${platform}]} \
> ${filename}
common_configs="${common_configs} ${filename}"
done
python3 ${SCRIPTS_DIR}/configcommon.py ${common_configs} > ${tmpdir}/config-generic
for platform in ${PLATFORMS}; do
for subplatform in ${SUBPLATFORMS[${platform}]}; do
python3 ${SCRIPTS_DIR}/configdiff.py \
${tmpdir}/config-${platform}-common \
${tmpdir}/config-${subplatform}-common \
> ${tmpdir}/config-${subplatform}-generic
done
python3 ${SCRIPTS_DIR}/configdiff.py \
${tmpdir}/config-generic \
${tmpdir}/config-${platform}-common \
> ${tmpdir}/config-${platform}-generic
done
for config in ${CONFIGS}; do
arch=${config%:*}
flavour=${config#*:}
filename=${tmpdir}/config-${arch}-${flavour}
case "${config}" in
aarch64:default|x86_64:default)
# Virtual configuration
rm -f ${filename}
continue
;;
*)
platform="$(get_subplatform "${arch}" || get_platform "${arch}")"
python3 ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-${platform}-common \
${filename} > ${filename}.tmp
# Collect all *-generic configurations
case "${flavour}" in
generic)
configs+=( "${filename}" )
;;
esac
mv ${filename}{.tmp,}
done
rm -f ${tmpdir}/config-*-common
for config in ${tmpdir}/*; do
if ! cmp $(basename ${config}) ${config} &>/dev/null; then
echo "$(basename ${config}) has changed."
# Generate config-generic
if ! python3 "${SCRIPTS_DIR}/configcommon.py" "${configs[@]}" \
> "${tmpdir}/config-generic"; then
echo >&2 "Could not generate config-generic"
rm -rf "${tmpdir}"
return 1
fi
local arch
for arch in $(arches); do
# Fetch all flavours
local flavours="$(flavours_for_arch "${arch}")"
local flavour
for flavour in ${flavours}; do
local base_config="${tmpdir}/config-${arch}-generic"
# config-${arch}-generic is handled in a special way and diffed
# directly against config-generic
case "${flavour}" in
generic)
base_config="${tmpdir}/config-generic"
;;
esac
# Diff configurations
if ! python3 "${SCRIPTS_DIR}/configdiff.py" \
"${base_config}" \
"${tmpdir}/full-${arch}-${flavour}" \
> "${tmpdir}/config-${arch}-${flavour}"; then
echo >&2 "Could not generate config-${arch}-${flavour}"
rm -rf "${tmpdir}"
return 1
fi
done
done
# List any changes and copy back the result
for config in config-*; do
if ! cmp "${tmpdir}/${config}" "${config}" &>/dev/null; then
echo "${config} has changed"
fi
cat ${config} > $(basename ${config})
# Copy back configuration
cat "${tmpdir}/${config}" > "${config}"
done
rm -rf ${tmpdir}
# Cleanup
rm -rf "${tmpdir}"
return 0
}
KERNEL_DIR="$(search_kernel_dir)"
# Parse commandline.
while [ $# -gt 0 ]; do
arg=${1}; shift
case "${arg}" in
help|"")
echo "${0} - available commands:"
echo " * merge <arch> <flavour> <output filename>"
echo " * menuconfig"
echo " * oldconfig"
echo " * olddefconfig"
exit 0
main() {
local action
# Parse commandline
local arg
while [ $# -gt 0 ]; do
arg="${1}"
shift
case "${arg}" in
--kernel-dir=*)
KERNEL_DIR="${arg#--kernel-dir=}"
;;
listnewconfig|menuconfig|merge|oldconfig|olddefconfig)
action="${arg}"
break
;;
help|"")
echo "${0} - available commands:"
echo " * merge <arch> <flavour> <output filename>"
echo " * menuconfig"
echo " * oldconfig"
echo " * olddefconfig"
return 0
;;
esac
done
# Check if KERNEL_DIR has been set and exists
if [ -z "${KERNEL_DIR}" -o ! -d "${KERNEL_DIR}" ]; then
echo >&2 "KERNEL_DIR was not set or does not exist!"
return 2
fi
case "${action}" in
merge)
merge_config "$@"
return $?
;;
listnewconfig|menuconfig|merge|oldconfig|olddefconfig)
action=${arg}
break
listnewconfig|menuconfig|oldconfig|olddefconfig)
make_config "${action}" "$@"
return $?
;;
# Handle no or invalid actions
*)
echo >&2 "No action given... Try ${0} help."
return 2
;;
esac
done
}
if [ -z "${KERNEL_DIR}" ]; then
echo >&2 "KERNEL_DIR was not set!"
exit 2
fi
if [ -z "${action}" ]; then
echo >&2 "No action given... Try ${0} help."
exit 2
fi
case "${action}" in
merge)
merge_config $@
exit $?
;;
listnewconfig|menuconfig|oldconfig|olddefconfig)
make_config "${action}" "$@"
exit $?
;;
esac
exit 1
main "$@" || exit $?