diff --git a/kernel/build-kernel.sh b/kernel/build-kernel.sh index ab986a05db..e42c8ad84f 100755 --- a/kernel/build-kernel.sh +++ b/kernel/build-kernel.sh @@ -123,11 +123,19 @@ get_kernel() { sha256sum -c "${kernel_tarball}.sha256" - tar xf ${kernel_tarball} + tar xf "${kernel_tarball}" mv "linux-${version}" "${kernel_path}" } +get_major_kernel_version() { + local version="${1}" + [ -n "${version}" ] || die "kernel version not provided" + major_version=$(echo "${version}" | cut -d. -f1) + minor_version=$(echo "${version}" | cut -d. -f2) + echo "${major_version}.${minor_version}" +} + get_default_kernel_config() { local version="${1}" @@ -138,9 +146,9 @@ get_default_kernel_config() { [ -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" + local kernel_ver + kernel_ver=$(get_major_kernel_version "${version}") + config="${default_kernel_config_dir}/${kernel_arch}_kata_${hypervisor}_${major_kernel}.x" [ -f "${config}" ] || die "failed to find default config ${config}" echo "${config}" } @@ -185,21 +193,32 @@ setup_kernel() { [ -d "${patches_path}" ] || die " patches path '${patches_path}' does not exist" - kernel_patches=$(find "${patches_path}" -name '*.patch' -type f) + local major_kernel + major_kernel=$(get_major_kernel_version "${kernel_version}") + local patches_dir_for_version="${patches_path}/${major_kernel}.x" + local kernel_patches="" + if [ -d "${patches_dir_for_version}" ]; then + kernel_patches=$(find "${patches_dir_for_version}" -name '*.patch' -type f) + else + info "kernel patches directory does not exit" - pushd "${kernel_path}" >>/dev/null - for p in ${kernel_patches}; do - info "Applying patch $p" - patch -p1 <"$p" - done + fi - [ -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}") + ( + cd "${kernel_path}" || exit 1 + for p in ${kernel_patches}; do + info "Applying patch $p" + patch -p1 <"$p" + done - cp "${kernel_config_path}" ./.config - make oldconfig + [ -n "${hypervisor_target}" ] || hypervisor_target="kvm" + [ -n "${kernel_config_path}" ] || kernel_config_path=$(get_default_kernel_config "${kernel_version}" "${hypervisor_target}" "${arch_target}") + + cp "${kernel_config_path}" ./.config + make oldconfig + ) } build_kernel() { diff --git a/kernel/kata_config_version b/kernel/kata_config_version index a787364590..8f92bfdd49 100644 --- a/kernel/kata_config_version +++ b/kernel/kata_config_version @@ -1 +1 @@ -34 +35 diff --git a/kernel/patches/0001-Enable-memory-hotplug-using-probe-for-arm64.patch b/kernel/patches/4.19.x/0001-Enable-memory-hotplug-using-probe-for-arm64.patch similarity index 100% rename from kernel/patches/0001-Enable-memory-hotplug-using-probe-for-arm64.patch rename to kernel/patches/4.19.x/0001-Enable-memory-hotplug-using-probe-for-arm64.patch diff --git a/kernel/patches/0001-NO-UPSTREAM-9P-always-use-cached-inode-to-fill-in-v9.patch b/kernel/patches/4.19.x/0001-NO-UPSTREAM-9P-always-use-cached-inode-to-fill-in-v9.patch similarity index 100% rename from kernel/patches/0001-NO-UPSTREAM-9P-always-use-cached-inode-to-fill-in-v9.patch rename to kernel/patches/4.19.x/0001-NO-UPSTREAM-9P-always-use-cached-inode-to-fill-in-v9.patch diff --git a/kernel/patches/0002-Compile-in-evged-always.patch b/kernel/patches/4.19.x/0002-Compile-in-evged-always.patch similarity index 100% rename from kernel/patches/0002-Compile-in-evged-always.patch rename to kernel/patches/4.19.x/0002-Compile-in-evged-always.patch diff --git a/kernel/patches/0003-arm64-backport-Arm64-KVM-Dynamic-IPA-and-52bit-IPA-s.patch b/kernel/patches/4.19.x/0003-arm64-backport-Arm64-KVM-Dynamic-IPA-and-52bit-IPA-s.patch similarity index 100% rename from kernel/patches/0003-arm64-backport-Arm64-KVM-Dynamic-IPA-and-52bit-IPA-s.patch rename to kernel/patches/4.19.x/0003-arm64-backport-Arm64-KVM-Dynamic-IPA-and-52bit-IPA-s.patch diff --git a/obs-packaging/linux-container/update.sh b/obs-packaging/linux-container/update.sh index 63c2947ccb..815c0baec4 100755 --- a/obs-packaging/linux-container/update.sh +++ b/obs-packaging/linux-container/update.sh @@ -27,7 +27,9 @@ KATA_CONFIG_VERSION=$(cat "${SCRIPT_DIR}/../../kernel/kata_config_version") KR_SERIES="$(echo $VERSION | cut -d "." -f 1).x" KR_LTS=$(echo $VERSION | cut -d "." -f 1,2) -KR_PATCHES=$(eval find "${SCRIPT_DIR}/../../kernel/patches" -type f -name "*.patch") +ln -sfT "${SCRIPT_DIR}/../../kernel/patches-${KR_LTS}" "${SCRIPT_DIR}/patches" + +KR_PATCHES=$(eval find "${SCRIPT_DIR}/patches" -type f -name "*.patch") KR_REL=https://www.kernel.org/releases.json KR_SHA=https://cdn.kernel.org/pub/linux/kernel/v"${KR_SERIES}"/sha256sums.asc @@ -66,6 +68,5 @@ get_git_info #TODO delete me: used by changelog_update hash_tag="nocommit" changelog_update "${VERSION}-${KATA_CONFIG_VERSION}" -ln -sfT "${SCRIPT_DIR}/../../kernel/patches" "${SCRIPT_DIR}/patches" generate_files "$SCRIPT_DIR" "${replace_list[@]}" build_pkg "${PROJECT_REPO}" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1d942f4358..a871d92fcf 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -218,8 +218,9 @@ parts: make mrproper + # Apply patches - for patch in ${SNAPCRAFT_STAGE}/kernel/patches/*.patch; do + for patch in ${SNAPCRAFT_STAGE}/kernel/patches/${x_version}/*.patch; do echo "Applying $(basename "$patch") ..." patch \ --batch \