Skip to content

Commit

Permalink
introduce a new patching system with complex version range support, a…
Browse files Browse the repository at this point in the history
…nd use it to fix idm support in 5.10
  • Loading branch information
azenla committed Nov 11, 2024
1 parent becc372 commit 73f2be0
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 25 deletions.
2 changes: 1 addition & 1 deletion hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ elif [ "${TARGET_ARCH_STANDARD}" = "aarch64" ]
then
cp "${KERNEL_OBJ}/arch/arm64/boot/Image.gz" "${OUTPUT_DIR}/kernel"
else
echo "ERROR: unable to determine what file is the vmlinuz for ${TARGET_ARCH_STANDARD}" > /dev/stderr
echo "ERROR: unable to determine what file is the vmlinuz for ${TARGET_ARCH_STANDARD}" >&2
exit 1
fi

Expand Down
20 changes: 20 additions & 0 deletions hack/cdn-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -e

if [ -z "${1}" ]
then
echo "Usage: cdn-url.sh <KERNEL_VERSION>" >&2
exit 1
fi

KERNEL_VERSION="${1}"
MAJOR_VERSION="$(echo "${KERNEL_VERSION}" | awk -F '.' '{print $1}')"
MINOR_VERSION="$(echo "${KERNEL_VERSION}" | awk -F '.' '{print $2}')"
PATCH_VERSION="$(echo "${KERNEL_VERSION}" | awk -F '.' '{print $3}')"

if [ "${PATCH_VERSION}" = "0" ]
then
KERNEL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}"
fi

echo "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${KERNEL_VERSION}.tar.gz"
File renamed without changes.
31 changes: 8 additions & 23 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ fi

if [ -z "${KERNEL_VERSION}" ]
then
echo "ERROR: KERNEL_VERSION must be specified." > /dev/stderr
echo "ERROR: KERNEL_VERSION must be specified." >&2
exit 1
fi

if [ -z "${KERNEL_SRC_URL}" ]
then
echo "ERROR: KERNEL_SRC_URL must be specified." > /dev/stderr
exit 1
KERNEL_SRC_URL="$(./hack/cdn-url.sh "${KERNEL_VERSION}")"
fi

if [ -z "${KERNEL_FLAVOR}" ]
then
KERNEL_FLAVOR="standard"
KERNEL_FLAVOR="zone"
fi

KERNEL_SRC="${KERNEL_DIR}/src/linux-${KERNEL_VERSION}-${TARGET_ARCH_STANDARD}"
Expand All @@ -59,9 +58,6 @@ then
MAINLINE_VERSION="${KERNEL_VERSION}"
fi

BASE_SERIES_FILE="${KERNEL_DIR}/patches/${MAINLINE_VERSION}/base/series"
SERIES_FILE="${KERNEL_DIR}/patches/${MAINLINE_VERSION}/${KERNEL_FLAVOR}/series"

if [ ! -f "${KERNEL_SRC}/Makefile" ]
then
rm -rf "${KERNEL_SRC}"
Expand All @@ -70,23 +66,12 @@ then
tar xf "${KERNEL_SRC}.txz" --strip-components 1 -C "${KERNEL_SRC}"
rm "${KERNEL_SRC}.txz"

if [ -f "${BASE_SERIES_FILE}" ]
then
cd "${KERNEL_SRC}"
while read patch; do
patch -p1 < "${KERNEL_DIR}/patches/${MAINLINE_VERSION}/base/$patch"
done < "${BASE_SERIES_FILE}"
cd "${KERNEL_DIR}"
fi

if [ -f "${SERIES_FILE}" ]
then
python3 "hack/patchlist.py" "${KERNEL_VERSION}" "${KERNEL_FLAVOR}" | while read patch; do
cd "${KERNEL_SRC}"
while read patch; do
patch -p1 < "${KERNEL_DIR}/patches/${MAINLINE_VERSION}/${KERNEL_FLAVOR}/$patch"
done < "${SERIES_FILE}"
patch -p1 < "${KERNEL_DIR}/${patch}"
cd "${KERNEL_DIR}"
fi
done
cd "${KERNEL_DIR}"
fi

OUTPUT_DIR="${KERNEL_DIR}/target"
Expand All @@ -96,7 +81,7 @@ KERNEL_CONFIG_FILE="${KERNEL_DIR}/configs/${KERNEL_FLAVOR}-${TARGET_ARCH_STANDAR

if [ ! -f "${KERNEL_CONFIG_FILE}" ]
then
echo "ERROR: kernel config file not found for ${TARGET_ARCH_STANDARD}" > /dev/stderr
echo "ERROR: kernel config file not found for ${TARGET_ARCH_STANDARD}" >&2
exit 1
fi

Expand Down
90 changes: 90 additions & 0 deletions hack/patchlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import json
import os
import sys
from packaging.version import parse
from pathlib import Path

if len(sys.argv) != 3:
print("Usage: patchlist <KERNEL_VERSION> <KERNEL_FLAVOR>")
exit(1)

target_version = parse(sys.argv[1])
kernel_flavor = sys.argv[2]
series = "%s.%s" % (target_version.major, target_version.minor)

common_patches = []
with open("patches/common/patches.json") as f:
common_patches = json.load(f)

apply_patches = []

def maybe(m, k):
if k in m:
return m[k]
else:
return None

for patch in common_patches:
file_name = patch["patch"]
order = patch["order"]
lower = maybe(patch, "lower")
only_series = maybe(patch, "series")
upper = maybe(patch, "upper")
if lower is not None:
lower = parse(lower)
if upper is not None:
upper = parse(upper)

apply = False

if lower is None and upper is not None:
if target_version <= upper:
apply = True

if lower is not None and upper is None:
if target_version >= lower:
apply = True

if lower is not None and upper is not None:
if target_version >= lower and target_version <= upper:
apply = True

if only_series is not None and only_series != series:
apply = False

if apply:
apply_patches.append({
"patch": "patches/common/%s" % file_name,
"order": order,
})

base_series_path = Path("patches/%s/base/series" % series)
if base_series_path.is_file():
with base_series_path.open() as base_series_file:
lines = base_series_file.readlines()
for i, line in enumerate(lines):
line = line.strip()
if len(line) == 0:
continue
apply_patches.append({
"patch": "patches/%s/base/%s" % (series, line),
"order": i + 1,
})

flavor_series_path = Path("patches/%s/%s/series" % (series, kernel_flavor))
if flavor_series_path.is_file():
with flavor_series_path.open() as flavor_series_file:
lines = flavor_series_file.readlines()
for i, line in enumerate(lines):
line = line.strip()
if len(line) == 0:
continue
apply_patches.append({
"patch": "patches/%s/%s/%s" % (series, kernel_flavor, line),
"order": i + 1,
})

apply_patches.sort(key=lambda patch: patch["order"])

for patch in apply_patches:
print(patch["patch"])
9 changes: 9 additions & 0 deletions hack/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

REAL_SCRIPT="$(realpath "${0}")"
cd "$(dirname "${REAL_SCRIPT}")/.."
KERNEL_DIR="$(realpath "${PWD}")"

# shellcheck source-path=SCRIPTDIR source=common.sh
. "${KERNEL_DIR}/hack/common.sh"
1 change: 0 additions & 1 deletion patches/5.10/base/series

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 73f2be0

Please sign in to comment.