Skip to content

Commit

Permalink
kernel: configs: add kernel fragment support
Browse files Browse the repository at this point in the history
Add the framework to build kernel config files from trees
of kernel fragments.

If no fragment directory is found for the requested kernel
version and architecture then revert to looking for a whole
prebuilt kernel config file instead.

Fixes: kata-containers#234

Signed-off-by: Graham Whaley <graham.whaley@intel.com>
  • Loading branch information
Graham Whaley committed Jan 23, 2019
1 parent f802dd8 commit ddcaf02
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions kernel/build-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ readonly patches_repo_dir="${GOPATH}/src/${patches_repo}"
readonly default_patches_dir="${patches_repo_dir}/kernel/patches/"
# Default path to search config for kata
readonly default_kernel_config_dir="${GOPATH}/src/${kernel_config_repo}/kernel/configs"
# Default path to search for kernel config fragments
readonly default_config_frags_dir="${GOPATH}/src/${kernel_config_repo}/kernel/configs/fragments"
#Path to kernel directory
kernel_path=""
#
Expand Down Expand Up @@ -128,19 +130,77 @@ get_kernel() {
mv "linux-${version}" "${kernel_path}"
}

# Make a kernel config file from generic and arch specific
# fragments
# - arg1 - path to arch specific fragments
# - arg2 - path to kernel sources
#
get_kernel_frag_path() {
local arch_path="$1"
local common_path="${arch_path}/../common"
local kernel_path="$2"
local cmdpath="${kernel_path}/scripts/kconfig/merge_config.sh"
local config_path="${arch_path}/.config"

local arch_configs="$(ls ${arch_path}/*.conf)"
local common_configs="$(ls ${common_path}/*.conf)"
local all_configs="${common_configs} ${arch_configs}"

local results=$(export KCONFIG_CONFIG=${config_path}; export ARCH=${arch_target}; cd ${kernel_path}; ${cmdpath} -r -n ${all_configs})

# Did we request any entries that did not make it?
local missing=$(grep -v -q "not in final" <<< ${results}; echo $?)
if [ ${missing} -ne 0 ]; then
info "Some CONFIG elements failed to make the final .config:"
info "${results}"
die "Failed to construct requested .config file"
fi

# Did we define something as two different values?
local redefined=$(grep -v -q "redefined" <<< ${results}; echo $?)
if [ ${redefined} -ne 0 ]; then
info "Some CONFIG elements are redefined in fragments:"
info "${results}"
die "Failed to construct requested .config file"
fi

# Did we define something twice? Nominally this may not be an error, and it
# might be convinient to allow it, but for now, let's pick up on them.
local redundant=$(grep -v -q "redundant" <<< ${results}; echo $?)
if [ ${redundant} -ne 0 ]; then
info "Some CONFIG elements failed to make the final .config"
info "${results}"
die "Failed to construct requested .config file"
fi

echo "${config_path}"
}

# Locate and return the path to the relevant kernel config file
# - arg1: kernel version
# - arg2: hypervisor target
# - arg3: arch target
# - arg4: kernel source path
get_default_kernel_config() {
local version="${1}"

local hypervisor="$2"
local kernel_arch="$3"
local kernel_path="$4"

[ -n "${version}" ] || die "kernel version not provided"
[ -n "${hypervisor}" ] || die "hypervisor not provided"
[ -n "${kernel_arch}" ] || die "kernel arch not provided"

major_version=$(echo "${version}" | cut -d. -f1)
minor_version=$(echo "${version}" | cut -d. -f2)
config="${default_kernel_config_dir}/${kernel_arch}_kata_${hypervisor}_${major_version}.${minor_version}.x"

archfragdir="${default_config_frags_dir}/${major_version}.${minor_version}.x/${kernel_arch}"
if [ -d "${archfragdir}" ]; then
config="$(get_kernel_frag_path ${archfragdir} ${kernel_path})"
else
config="${default_kernel_config_dir}/${kernel_arch}_kata_${hypervisor}_${major_version}.${minor_version}.x"
fi
[ -f "${config}" ] || die "failed to find default config ${config}"
echo "${config}"
}
Expand Down Expand Up @@ -196,8 +256,9 @@ setup_kernel() {
[ -n "${hypervisor_target}" ] || hypervisor_target="kvm"
[ -n "${arch_target}" ] || arch_target="$(uname -m)"
arch_target=$(arch_to_kernel "${arch_target}")
[ -n "${kernel_config_path}" ] || kernel_config_path=$(get_default_kernel_config "${kernel_version}" "${hypervisor_target}" "${arch_target}")
[ -n "${kernel_config_path}" ] || kernel_config_path=$(get_default_kernel_config "${kernel_version}" "${hypervisor_target}" "${arch_target}" "${kernel_path}")

info "Copying config file from: ${kernel_config_path}"
cp "${kernel_config_path}" ./.config
make oldconfig
}
Expand Down

0 comments on commit ddcaf02

Please sign in to comment.