diff --git a/kernel/build-kernel.sh b/kernel/build-kernel.sh index 86000fb0ef..9f46758e3f 100755 --- a/kernel/build-kernel.sh +++ b/kernel/build-kernel.sh @@ -39,10 +39,16 @@ readonly default_kernel_config_dir="${GOPATH}/src/${kernel_config_repo}/kernel/c # Default path to search for kernel config fragments readonly default_config_frags_dir="${GOPATH}/src/${kernel_config_repo}/kernel/configs/fragments" readonly default_config_whitelist="${GOPATH}/src/${kernel_config_repo}/kernel/configs/fragments/whitelist.conf" +# GPU vendor +readonly GV_INTEL="intel" +readonly GV_NVIDIA="nvidia" + #Path to kernel directory kernel_path="" #Experimental kernel support. Pull from virtio-fs GitLab instead of kernel.org experimental_kernel="false" +#GPU kernel support +gpu_vendor="" # patches_path="" # @@ -80,13 +86,14 @@ Commands: Options: - -c : Path to config file to build a the kernel. - -e : Enable experimental kernel. - -h : Display this help. - -k : Path to kernel to build. - -p : Path to a directory with patches to apply to kernel. - -t : Hypervisor_target. - -v : Kernel version to use if kernel path not provided. + -c : Path to config file to build a the kernel. + -e : Enable experimental kernel. + -g : GPU vendor, intel or nvidia. + -h : Display this help. + -k : Path to kernel to build. + -p : Path to a directory with patches to apply to kernel. + -t : Hypervisor_target. + -v : Kernel version to use if kernel path not provided. EOT exit "$exit_code" } @@ -167,6 +174,8 @@ get_major_kernel_version() { get_kernel_frag_path() { local arch_path="$1" local common_path="${arch_path}/../common" + local gpu_path="${arch_path}/../gpu" + local kernel_path="$2" local cmdpath="${kernel_path}/scripts/kconfig/merge_config.sh" local config_path="${arch_path}/.config" @@ -190,6 +199,12 @@ get_kernel_frag_path() { all_configs="${all_configs} ${experimental_configs}" fi + if [[ "${gpu_vendor}" != "" ]];then + info "Add kernel config for GPU due to '-g ${gpu_vendor}'" + local gpu_configs="$(ls ${gpu_path}/${gpu_vendor}.conf)" + all_configs="${all_configs} ${gpu_configs}" + fi + info "Constructing config from fragments: ${config_path}" @@ -365,8 +380,17 @@ install_kata() { config_version=$(get_config_version) [ -n "${config_version}" ] || die "failed to get config version" install_path=$(readlink -m "${DESTDIR}/${PREFIX}/share/${project_name}") - vmlinuz="vmlinuz-${kernel_version}-${config_version}" - vmlinux="vmlinux-${kernel_version}-${config_version}" + + suffix="" + if [[ ${experimental_kernel} == "true" ]]; then + suffix="-virtiofs" + fi + if [[ ${gpu_vendor} != "" ]];then + suffix="-${gpu_vendor}-gpu${suffix}" + fi + + vmlinuz="vmlinuz-${kernel_version}-${config_version}${suffix}" + vmlinux="vmlinux-${kernel_version}-${config_version}${suffix}" if [ -e "arch/${arch_target}/boot/bzImage" ]; then bzImage="arch/${arch_target}/boot/bzImage" @@ -392,21 +416,15 @@ install_kata() { install --mode 0644 -D ./.config "${install_path}/config-${kernel_version}" - if [[ ${experimental_kernel} == "true" ]]; then - sufix="-virtiofs.container" - else - sufix=".container" - fi - - ln -sf "${vmlinuz}" "${install_path}/vmlinuz${sufix}" - ln -sf "${vmlinux}" "${install_path}/vmlinux${sufix}" - ls -la "${install_path}/vmlinux${sufix}" - ls -la "${install_path}/vmlinuz${sufix}" + ln -sf "${vmlinuz}" "${install_path}/vmlinuz${suffix}.container" + ln -sf "${vmlinux}" "${install_path}/vmlinux${suffix}.container" + ls -la "${install_path}/vmlinux${suffix}.container" + ls -la "${install_path}/vmlinuz${suffix}.container" popd >>/dev/null } main() { - while getopts "a:c:hk:p:t:v:e" opt; do + while getopts "a:c:eg:hk:p:t:v:" opt; do case "$opt" in a) arch_target="${OPTARG}" @@ -417,6 +435,10 @@ main() { e) experimental_kernel="true" ;; + g) + gpu_vendor="${OPTARG}" + [[ "${gpu_vendor}" == "${GV_INTEL}" || "${gpu_vendor}" == "${GV_NVIDIA}" ]] || die "GPU vendor only support intel and nvidia" + ;; h) usage 0 ;; diff --git a/kernel/configs/fragments/gpu/intel.conf b/kernel/configs/fragments/gpu/intel.conf new file mode 100644 index 0000000000..d5054767a4 --- /dev/null +++ b/kernel/configs/fragments/gpu/intel.conf @@ -0,0 +1,7 @@ +# The following i915 kernel config options need to be enabled +CONFIG_DRM=y +CONFIG_DRM_I915=y +CONFIG_DRM_I915_USERPTR=y + +# Linux kernel version suffix +CONFIG_LOCALVERSION="-intel-gpu" diff --git a/kernel/configs/fragments/gpu/nvidia.conf b/kernel/configs/fragments/gpu/nvidia.conf new file mode 100644 index 0000000000..883c0f3af9 --- /dev/null +++ b/kernel/configs/fragments/gpu/nvidia.conf @@ -0,0 +1,14 @@ +# Support mmconfig PCI config space access. +# It's used to enable the MMIO access method for PCIe devices. +CONFIG_PCI_MMCONFIG=y + +# Support for loading modules. +# It is used to support loading GPU drivers. +CONFIG_MODULES=y +CONFIG_MODULE_UNLOAD=y + +# CRYPTO_FIPS requires this config when loading modules is enabled. +CONFIG_MODULE_SIG=y + +# Linux kernel version suffix +CONFIG_LOCALVERSION="-nvidia-gpu"