mirror of https://github.com/dynup/kpatch
commit
16e447ad09
|
@ -569,7 +569,7 @@ Yes! There's a few requirements, and the feature is still in its infancy.
|
||||||
|
|
||||||
1. You need to use the `--oot-module` flag to specify the version of the
|
1. You need to use the `--oot-module` flag to specify the version of the
|
||||||
module that's currently running on the machine.
|
module that's currently running on the machine.
|
||||||
2. `--sourcedir` has to be passed with a directory containing the same
|
2. `--oot-module-src` has to be passed with a directory containing the same
|
||||||
version of code as the running module, all set up and ready to build with a
|
version of code as the running module, all set up and ready to build with a
|
||||||
`make` command. For example, some modules need `autogen.sh` and
|
`make` command. For example, some modules need `autogen.sh` and
|
||||||
`./configure` to have been run with the appropriate flags to match the
|
`./configure` to have been run with the appropriate flags to match the
|
||||||
|
@ -585,7 +585,7 @@ built separately.
|
||||||
|
|
||||||
***Sample invocation***
|
***Sample invocation***
|
||||||
|
|
||||||
`kpatch-build --sourcedir ~/test/ --target default --oot-module /lib/modules/$(uname -r)/extra/test.ko test.patch`
|
`kpatch-build --oot-module-src ~/test/ --target default --oot-module /lib/modules/$(uname -r)/extra/test.ko test.patch`
|
||||||
|
|
||||||
|
|
||||||
Get involved
|
Get involved
|
||||||
|
|
|
@ -41,7 +41,7 @@ SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
|
||||||
ARCH="$(uname -m)"
|
ARCH="$(uname -m)"
|
||||||
CPUS="$(getconf _NPROCESSORS_ONLN)"
|
CPUS="$(getconf _NPROCESSORS_ONLN)"
|
||||||
CACHEDIR="${CACHEDIR:-$HOME/.kpatch}"
|
CACHEDIR="${CACHEDIR:-$HOME/.kpatch}"
|
||||||
SRCDIR="$CACHEDIR/src"
|
KERNEL_SRCDIR="$CACHEDIR/src"
|
||||||
RPMTOPDIR="$CACHEDIR/buildroot"
|
RPMTOPDIR="$CACHEDIR/buildroot"
|
||||||
VERSIONFILE="$CACHEDIR/version"
|
VERSIONFILE="$CACHEDIR/version"
|
||||||
TEMPDIR="$CACHEDIR/tmp"
|
TEMPDIR="$CACHEDIR/tmp"
|
||||||
|
@ -138,27 +138,27 @@ remove_patches() {
|
||||||
for (( ; APPLIED_PATCHES>0; APPLIED_PATCHES-- )); do
|
for (( ; APPLIED_PATCHES>0; APPLIED_PATCHES-- )); do
|
||||||
idx=$(( APPLIED_PATCHES - 1))
|
idx=$(( APPLIED_PATCHES - 1))
|
||||||
patch="${PATCH_LIST[$idx]}"
|
patch="${PATCH_LIST[$idx]}"
|
||||||
patch -p1 -R -d "$SRCDIR" < "$patch" &> /dev/null
|
patch -p1 -R -d "$BUILDDIR" < "$patch" &> /dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
# If $SRCDIR was a git repo, make sure git actually sees that
|
# If $BUILDDIR was a git repo, make sure git actually sees that
|
||||||
# we've reverted our patch(es).
|
# we've reverted our patch(es).
|
||||||
[[ -d "$SRCDIR/.git" ]] && (cd "$SRCDIR" && git update-index -q --refresh)
|
[[ -d "$BUILDDIR/.git" ]] && (cd "$BUILDDIR" && git update-index -q --refresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f "$SRCDIR/.scmversion"
|
rm -f "$BUILDDIR/.scmversion"
|
||||||
|
|
||||||
remove_patches
|
remove_patches
|
||||||
|
|
||||||
# restore original vmlinux if it was overwritten by sourcedir build
|
# restore original vmlinux if it was overwritten by sourcedir build
|
||||||
[[ -e "$TEMPDIR/vmlinux" ]] && mv -f "$TEMPDIR/vmlinux" "$SRCDIR/"
|
[[ -e "$TEMPDIR/vmlinux" ]] && mv -f "$TEMPDIR/vmlinux" "$KERNEL_SRCDIR/"
|
||||||
|
|
||||||
# restore original link-vmlinux.sh if we updated it for the build
|
# restore original link-vmlinux.sh if we updated it for the build
|
||||||
[[ -e "$TEMPDIR/link-vmlinux.sh" ]] && mv -f "$TEMPDIR/link-vmlinux.sh" "$SRCDIR/scripts"
|
[[ -e "$TEMPDIR/link-vmlinux.sh" ]] && mv -f "$TEMPDIR/link-vmlinux.sh" "$KERNEL_SRCDIR/scripts"
|
||||||
|
|
||||||
# restore original Makefile.modfinal if we updated it for the build
|
# restore original Makefile.modfinal if we updated it for the build
|
||||||
[[ -e "$TEMPDIR/Makefile.modfinal" ]] && mv -f "$TEMPDIR/Makefile.modfinal" "$SRCDIR/scripts"
|
[[ -e "$TEMPDIR/Makefile.modfinal" ]] && mv -f "$TEMPDIR/Makefile.modfinal" "$KERNEL_SRCDIR/scripts"
|
||||||
|
|
||||||
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
||||||
rm -rf "$RPMTOPDIR"
|
rm -rf "$RPMTOPDIR"
|
||||||
|
@ -538,15 +538,16 @@ usage() {
|
||||||
echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2
|
echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2
|
||||||
echo " in <CACHEDIR>/tmp" >&2
|
echo " in <CACHEDIR>/tmp" >&2
|
||||||
echo " (can be specified multiple times)" >&2
|
echo " (can be specified multiple times)" >&2
|
||||||
echo " -e, --oot-module Enable patching out-of-tree module," >&2
|
echo " --oot-module Enable patching out-of-tree module," >&2
|
||||||
echo " specify current version of module" >&2
|
echo " specify current version of module" >&2
|
||||||
|
echo " --oot-module-src Specify out-of-tree module source directory" >&2
|
||||||
echo " -R, --non-replace Disable replace patch (replace is on by default)" >&2
|
echo " -R, --non-replace Disable replace patch (replace is on by default)" >&2
|
||||||
echo " --skip-cleanup Skip post-build cleanup" >&2
|
echo " --skip-cleanup Skip post-build cleanup" >&2
|
||||||
echo " --skip-compiler-check Skip compiler version matching check" >&2
|
echo " --skip-compiler-check Skip compiler version matching check" >&2
|
||||||
echo " (not recommended)" >&2
|
echo " (not recommended)" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
options="$(getopt -o ha:r:s:c:v:j:t:n:o:de:R -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,skip-gcc-check,skip-compiler-check,skip-cleanup,non-replace" -- "$@")" || die "getopt failed"
|
options="$(getopt -o ha:r:s:c:v:j:t:n:o:dR -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,oot-module-src:,debug,skip-gcc-check,skip-compiler-check,skip-cleanup,non-replace" -- "$@")" || die "getopt failed"
|
||||||
|
|
||||||
eval set -- "$options"
|
eval set -- "$options"
|
||||||
|
|
||||||
|
@ -604,11 +605,16 @@ while [[ $# -gt 0 ]]; do
|
||||||
echo "DEBUG mode enabled"
|
echo "DEBUG mode enabled"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-e|--oot-module)
|
--oot-module)
|
||||||
[[ ! -f "$2" ]] && die "out-of-tree module '$2' not found"
|
[[ ! -f "$2" ]] && die "out-of-tree module '$2' not found"
|
||||||
OOT_MODULE="$(readlink -f "$2")"
|
OOT_MODULE="$(readlink -f "$2")"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--oot-module-src)
|
||||||
|
[[ ! -d "$2" ]] && die "out-of-tree module source dir '$2' not found"
|
||||||
|
OOT_MODULE_SRCDIR="$(readlink -f "$2")"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-R|--non-replace)
|
-R|--non-replace)
|
||||||
KLP_REPLACE=0
|
KLP_REPLACE=0
|
||||||
;;
|
;;
|
||||||
|
@ -657,8 +663,8 @@ if [[ -n "$SRCRPM" ]]; then
|
||||||
ARCHVERSION="${ARCHVERSION#alt-}"
|
ARCHVERSION="${ARCHVERSION#alt-}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$OOT_MODULE" ]] && [[ -z "$USERSRCDIR" ]]; then
|
if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
|
||||||
warn "--oot-module requires --sourcedir"
|
warn "--oot-module requires --oot-module-src"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -672,21 +678,30 @@ if [[ -n "$USERSRCDIR" ]]; then
|
||||||
warn "--archversion is incompatible with --sourcedir"
|
warn "--archversion is incompatible with --sourcedir"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
SRCDIR="$USERSRCDIR"
|
KERNEL_SRCDIR="$USERSRCDIR"
|
||||||
|
|
||||||
if [[ -z "$OOT_MODULE" ]]; then
|
[[ -z "$VMLINUX" ]] && VMLINUX="$KERNEL_SRCDIR"/vmlinux
|
||||||
[[ -z "$VMLINUX" ]] && VMLINUX="$SRCDIR"/vmlinux
|
|
||||||
[[ ! -e "$VMLINUX" ]] && die "can't find vmlinux"
|
[[ ! -e "$VMLINUX" ]] && die "can't find vmlinux"
|
||||||
|
|
||||||
# Extract the target kernel version from vmlinux in this case.
|
# Extract the target kernel version from vmlinux in this case.
|
||||||
ARCHVERSION="$(strings "$VMLINUX" | grep -m 1 -e "^Linux version" | awk '{ print($3); }')"
|
ARCHVERSION="$(strings "$VMLINUX" | grep -m 1 -e "^Linux version" | awk '{ print($3); }')"
|
||||||
else
|
|
||||||
ARCHVERSION="$(modinfo -F vermagic "$OOT_MODULE" | awk '{print $1}')"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$OOT_MODULE" ]]; then
|
||||||
|
ARCHVERSION="$(modinfo -F vermagic "$OOT_MODULE" | awk '{print $1}')"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -z "$ARCHVERSION" ]] && ARCHVERSION="$(uname -r)"
|
[[ -z "$ARCHVERSION" ]] && ARCHVERSION="$(uname -r)"
|
||||||
|
|
||||||
|
if [[ -n "$OOT_MODULE" ]]; then
|
||||||
|
if [[ -z "$USERSRCDIR" ]]; then
|
||||||
|
KERNEL_SRCDIR="/lib/modules/$ARCHVERSION/build/"
|
||||||
|
fi
|
||||||
|
BUILDDIR="$OOT_MODULE_SRCDIR"
|
||||||
|
else
|
||||||
|
BUILDDIR="$KERNEL_SRCDIR"
|
||||||
|
fi
|
||||||
|
|
||||||
[[ "$SKIPCLEANUP" -eq 0 ]] && trap cleanup EXIT INT TERM HUP
|
[[ "$SKIPCLEANUP" -eq 0 ]] && trap cleanup EXIT INT TERM HUP
|
||||||
|
|
||||||
KVER="${ARCHVERSION%%-*}"
|
KVER="${ARCHVERSION%%-*}"
|
||||||
|
@ -728,18 +743,16 @@ if [[ -n "$USERSRCDIR" ]]; then
|
||||||
echo "Using source directory at $USERSRCDIR"
|
echo "Using source directory at $USERSRCDIR"
|
||||||
|
|
||||||
# save original vmlinux before it gets overwritten by sourcedir build
|
# save original vmlinux before it gets overwritten by sourcedir build
|
||||||
if [[ -z "$OOT_MODULE" ]] && [[ "$VMLINUX" -ef "$SRCDIR"/vmlinux ]]; then
|
if [[ "$VMLINUX" -ef "$KERNEL_SRCDIR"/vmlinux ]]; then
|
||||||
cp -f "$VMLINUX" "$TEMPDIR/vmlinux" || die
|
cp -f "$VMLINUX" "$TEMPDIR/vmlinux" || die
|
||||||
VMLINUX="$TEMPDIR/vmlinux"
|
VMLINUX="$TEMPDIR/vmlinux"
|
||||||
fi
|
fi
|
||||||
|
elif [[ -n "$OOT_MODULE" ]]; then
|
||||||
# For external modules, use the running kernel's config
|
if [[ -z "${CONFIGFILE}" ]]; then
|
||||||
if [[ -n "$OOT_MODULE" ]] && [[ -z "$CONFIGFILE" ]]; then
|
|
||||||
CONFIGFILE="/boot/config-${ARCHVERSION}"
|
CONFIGFILE="/boot/config-${ARCHVERSION}"
|
||||||
fi
|
fi
|
||||||
|
elif [[ -e "$KERNEL_SRCDIR"/.config ]] && [[ -e "$VERSIONFILE" ]] && [[ "$(cat "$VERSIONFILE")" = "$ARCHVERSION" ]]; then
|
||||||
elif [[ -e "$SRCDIR"/.config ]] && [[ -e "$VERSIONFILE" ]] && [[ "$(cat "$VERSIONFILE")" = "$ARCHVERSION" ]]; then
|
echo "Using cache at $KERNEL_SRCDIR"
|
||||||
echo "Using cache at $SRCDIR"
|
|
||||||
|
|
||||||
else
|
else
|
||||||
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]]; then
|
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]]; then
|
||||||
|
@ -765,19 +778,19 @@ else
|
||||||
rpmbuild -D "_topdir $RPMTOPDIR" -bp --nodeps "--target=$(uname -m)" "$RPMTOPDIR"/SPECS/kernel$ALT.spec 2>&1 | logger ||
|
rpmbuild -D "_topdir $RPMTOPDIR" -bp --nodeps "--target=$(uname -m)" "$RPMTOPDIR"/SPECS/kernel$ALT.spec 2>&1 | logger ||
|
||||||
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
|
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
|
||||||
|
|
||||||
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$SRCDIR" 2>&1 | logger || die
|
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$KERNEL_SRCDIR" 2>&1 | logger || die
|
||||||
rm -rf "$RPMTOPDIR"
|
rm -rf "$RPMTOPDIR"
|
||||||
rm -rf "$SRCDIR/.git"
|
rm -rf "$KERNEL_SRCDIR/.git"
|
||||||
|
|
||||||
if [[ "$ARCHVERSION" == *-* ]]; then
|
if [[ "$ARCHVERSION" == *-* ]]; then
|
||||||
sed -i "s/^EXTRAVERSION.*/EXTRAVERSION = -${ARCHVERSION##*-}/" "$SRCDIR/Makefile" || die
|
sed -i "s/^EXTRAVERSION.*/EXTRAVERSION = -${ARCHVERSION##*-}/" "$KERNEL_SRCDIR/Makefile" || die
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$ARCHVERSION" > "$VERSIONFILE" || die
|
echo "$ARCHVERSION" > "$VERSIONFILE" || die
|
||||||
|
|
||||||
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$SRCDIR/configs/kernel$ALT-$KVER-$ARCH.config"
|
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR/configs/kernel$ALT-$KVER-$ARCH.config"
|
||||||
|
|
||||||
(cd "$SRCDIR" && make mrproper 2>&1 | logger) || die
|
(cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die
|
||||||
|
|
||||||
elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then
|
elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then
|
||||||
|
|
||||||
|
@ -806,14 +819,14 @@ else
|
||||||
echo "Downloading and unpacking the kernel source for $ARCHVERSION"
|
echo "Downloading and unpacking the kernel source for $ARCHVERSION"
|
||||||
# Download source deb pkg
|
# Download source deb pkg
|
||||||
(dget -u "$url/${pkgname}/${dscname}" 2>&1) | logger || die "dget: Could not fetch/unpack $url/${pkgname}/${dscname}"
|
(dget -u "$url/${pkgname}/${dscname}" 2>&1) | logger || die "dget: Could not fetch/unpack $url/${pkgname}/${dscname}"
|
||||||
mv "${pkgname}-$KVER" "$SRCDIR" || die
|
mv "${pkgname}-$KVER" "$KERNEL_SRCDIR" || die
|
||||||
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="/boot/config-${ARCHVERSION}"
|
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="/boot/config-${ARCHVERSION}"
|
||||||
if [[ "$ARCHVERSION" == *-* ]]; then
|
if [[ "$ARCHVERSION" == *-* ]]; then
|
||||||
echo "-${ARCHVERSION#*-}" > "$SRCDIR/localversion" || die
|
echo "-${ARCHVERSION#*-}" > "$KERNEL_SRCDIR/localversion" || die
|
||||||
fi
|
fi
|
||||||
# for some reason the Ubuntu kernel versions don't follow the
|
# for some reason the Ubuntu kernel versions don't follow the
|
||||||
# upstream SUBLEVEL; they are always at SUBLEVEL 0
|
# upstream SUBLEVEL; they are always at SUBLEVEL 0
|
||||||
sed -i "s/^SUBLEVEL.*/${sublevel}/" "$SRCDIR/Makefile" || die
|
sed -i "s/^SUBLEVEL.*/${sublevel}/" "$KERNEL_SRCDIR/Makefile" || die
|
||||||
echo "$ARCHVERSION" > "$VERSIONFILE" || die
|
echo "$ARCHVERSION" > "$VERSIONFILE" || die
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -821,10 +834,10 @@ else
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$SRCDIR"/.config
|
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR"/.config
|
||||||
[[ ! -e "$CONFIGFILE" ]] && die "can't find config file"
|
[[ ! -e "$CONFIGFILE" ]] && die "can't find config file"
|
||||||
if [[ ! "$CONFIGFILE" -ef "$SRCDIR"/.config ]] ; then
|
if [[ -z "$OOT_MODULE" && ! "$CONFIGFILE" -ef "$KERNEL_SRCDIR"/.config ]] ; then
|
||||||
cp -f "$CONFIGFILE" "$SRCDIR/.config" || die
|
cp -f "$CONFIGFILE" "$KERNEL_SRCDIR/.config" || die
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# kernel option checking
|
# kernel option checking
|
||||||
|
@ -832,7 +845,6 @@ grep -q "CONFIG_DEBUG_INFO=y" "$CONFIGFILE" || die "kernel doesn't have 'CONFIG_
|
||||||
|
|
||||||
# Build variables - Set some defaults, then adjust features
|
# Build variables - Set some defaults, then adjust features
|
||||||
# according to .config and kernel version
|
# according to .config and kernel version
|
||||||
KBUILD_EXTRA_SYMBOLS=""
|
|
||||||
KPATCH_LDFLAGS=""
|
KPATCH_LDFLAGS=""
|
||||||
USE_KLP=0
|
USE_KLP=0
|
||||||
USE_KLP_ARCH=0
|
USE_KLP_ARCH=0
|
||||||
|
@ -887,12 +899,12 @@ grep -q "CONFIG_GCC_PLUGIN_RANDSTRUCT=y" "$CONFIGFILE" && die "kernel option 'CO
|
||||||
# link-vmlinux.sh and Makefile.modfinal since kpatch doesn't care about
|
# link-vmlinux.sh and Makefile.modfinal since kpatch doesn't care about
|
||||||
# that anyway.
|
# that anyway.
|
||||||
if grep -q "CONFIG_DEBUG_INFO_BTF=y" "$CONFIGFILE" ; then
|
if grep -q "CONFIG_DEBUG_INFO_BTF=y" "$CONFIGFILE" ; then
|
||||||
cp -f "$SRCDIR/scripts/link-vmlinux.sh" "$TEMPDIR/link-vmlinux.sh" || die
|
cp -f "$KERNEL_SRCDIR/scripts/link-vmlinux.sh" "$TEMPDIR/link-vmlinux.sh" || die
|
||||||
sed -i 's/CONFIG_DEBUG_INFO_BTF/DISABLED_FOR_KPATCH_BUILD/g' "$SRCDIR"/scripts/link-vmlinux.sh || die
|
sed -i 's/CONFIG_DEBUG_INFO_BTF/DISABLED_FOR_KPATCH_BUILD/g' "$KERNEL_SRCDIR"/scripts/link-vmlinux.sh || die
|
||||||
|
|
||||||
if [[ -e "$SRCDIR/scripts/Makefile.modfinal" ]]; then
|
if [[ -e "$KERNEL_SRCDIR/scripts/Makefile.modfinal" ]]; then
|
||||||
cp -f "$SRCDIR/scripts/Makefile.modfinal" "$TEMPDIR/Makefile.modfinal" || die
|
cp -f "$KERNEL_SRCDIR/scripts/Makefile.modfinal" "$TEMPDIR/Makefile.modfinal" || die
|
||||||
sed -i 's/CONFIG_DEBUG_INFO_BTF_MODULES/DISABLED_FOR_KPATCH_BUILD/g' "$SRCDIR"/scripts/Makefile.modfinal || die
|
sed -i 's/CONFIG_DEBUG_INFO_BTF_MODULES/DISABLED_FOR_KPATCH_BUILD/g' "$KERNEL_SRCDIR"/scripts/Makefile.modfinal || die
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -914,7 +926,7 @@ if [[ "$SKIPCOMPILERCHECK" -eq 0 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Testing patch file(s)"
|
echo "Testing patch file(s)"
|
||||||
cd "$SRCDIR" || die
|
cd "$BUILDDIR" || die
|
||||||
verify_patch_files
|
verify_patch_files
|
||||||
apply_patches
|
apply_patches
|
||||||
remove_patches
|
remove_patches
|
||||||
|
@ -962,13 +974,13 @@ fi
|
||||||
make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
|
make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
|
||||||
|
|
||||||
# Save original module symvers
|
# Save original module symvers
|
||||||
cp -f "$SRCDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
|
cp -f "$BUILDDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
|
||||||
|
|
||||||
echo "Building patched source"
|
echo "Building patched source"
|
||||||
apply_patches
|
apply_patches
|
||||||
mkdir -p "$TEMPDIR/orig" "$TEMPDIR/patched"
|
mkdir -p "$TEMPDIR/orig" "$TEMPDIR/patched"
|
||||||
export KPATCH_GCC_TEMPDIR="$TEMPDIR"
|
export KPATCH_GCC_TEMPDIR="$TEMPDIR"
|
||||||
export KPATCH_GCC_SRCDIR="$SRCDIR"
|
export KPATCH_GCC_SRCDIR="$BUILDDIR"
|
||||||
save_env
|
save_env
|
||||||
# $TARGETS used as list, no quotes.
|
# $TARGETS used as list, no quotes.
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
|
@ -985,7 +997,7 @@ if [[ ! -e "$TEMPDIR/changed_objs" ]]; then
|
||||||
die "no changed objects found"
|
die "no changed objects found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$OOT_MODULE" ]] || grep -q vmlinux "$SRCDIR/Module.symvers" || die "truncated $SRCDIR/Module.symvers file"
|
grep -q vmlinux "$KERNEL_SRCDIR/Module.symvers" || die "truncated $KERNEL_SRCDIR/Module.symvers file"
|
||||||
|
|
||||||
if [[ "$CONFIG_MODVERSIONS" -eq 1 ]]; then
|
if [[ "$CONFIG_MODVERSIONS" -eq 1 ]]; then
|
||||||
while read -ra sym_line; do
|
while read -ra sym_line; do
|
||||||
|
@ -995,9 +1007,9 @@ if [[ "$CONFIG_MODVERSIONS" -eq 1 ]]; then
|
||||||
|
|
||||||
sym=${sym_line[1]}
|
sym=${sym_line[1]}
|
||||||
|
|
||||||
read -ra patched_sym_line <<< "$(grep "\s$sym\s" "$SRCDIR/Module.symvers")"
|
read -ra patched_sym_line <<< "$(grep "\s$sym\s" "$BUILDDIR/Module.symvers")"
|
||||||
if [[ ${#patched_sym_line[@]} -lt 4 ]]; then
|
if [[ ${#patched_sym_line[@]} -lt 4 ]]; then
|
||||||
die "Malformed symbol entry for ${sym} in ${SRCDIR}/Module.symvers file"
|
die "Malformed symbol entry for ${sym} in ${BUILDDIR}/Module.symvers file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Assume that both original and patched symvers have the same format.
|
# Assume that both original and patched symvers have the same format.
|
||||||
|
@ -1015,7 +1027,7 @@ fi
|
||||||
for i in $(cat "$TEMPDIR/changed_objs")
|
for i in $(cat "$TEMPDIR/changed_objs")
|
||||||
do
|
do
|
||||||
mkdir -p "$TEMPDIR/patched/$(dirname "$i")" || die
|
mkdir -p "$TEMPDIR/patched/$(dirname "$i")" || die
|
||||||
cp -f "$SRCDIR/$i" "$TEMPDIR/patched/$i" || die
|
cp -f "$BUILDDIR/$i" "$TEMPDIR/patched/$i" || die
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Extracting new and modified ELF sections"
|
echo "Extracting new and modified ELF sections"
|
||||||
|
@ -1050,9 +1062,8 @@ ERROR=0
|
||||||
|
|
||||||
# Prepare OOT module symvers file
|
# Prepare OOT module symvers file
|
||||||
if [[ -n "$OOT_MODULE" ]]; then
|
if [[ -n "$OOT_MODULE" ]]; then
|
||||||
BUILDDIR="/lib/modules/$ARCHVERSION/build/"
|
cp -f "$OOT_MODULE_SRCDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
|
||||||
cp -f "$SRCDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
|
awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${KERNEL_SRCDIR}/Module.symvers" >> "$TEMPDIR/Module.symvers"
|
||||||
awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${BUILDDIR}/Module.symvers" >> "$TEMPDIR/Module.symvers"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for i in $FILES; do
|
for i in $FILES; do
|
||||||
|
@ -1065,7 +1076,7 @@ for i in $FILES; do
|
||||||
[[ "$i" = usr/initramfs_data.o ]] && continue
|
[[ "$i" = usr/initramfs_data.o ]] && continue
|
||||||
|
|
||||||
mkdir -p "output/$(dirname "$i")"
|
mkdir -p "output/$(dirname "$i")"
|
||||||
cd "$SRCDIR" || die
|
cd "$BUILDDIR" || die
|
||||||
find_kobj "$i"
|
find_kobj "$i"
|
||||||
cd "$TEMPDIR" || die
|
cd "$TEMPDIR" || die
|
||||||
if [[ -e "orig/$i" ]]; then
|
if [[ -e "orig/$i" ]]; then
|
||||||
|
@ -1073,7 +1084,7 @@ for i in $FILES; do
|
||||||
KOBJFILE_NAME=vmlinux
|
KOBJFILE_NAME=vmlinux
|
||||||
KOBJFILE_PATH="$VMLINUX"
|
KOBJFILE_PATH="$VMLINUX"
|
||||||
SYMTAB="${TEMPDIR}/${KOBJFILE_NAME}.symtab"
|
SYMTAB="${TEMPDIR}/${KOBJFILE_NAME}.symtab"
|
||||||
SYMVERS_FILE="$SRCDIR/Module.symvers"
|
SYMVERS_FILE="$BUILDDIR/Module.symvers"
|
||||||
elif [[ "$(basename "$KOBJFILE")" = "$(basename "$OOT_MODULE")" ]]; then
|
elif [[ "$(basename "$KOBJFILE")" = "$(basename "$OOT_MODULE")" ]]; then
|
||||||
KOBJFILE_NAME="$(basename --suffix=.ko "$OOT_MODULE")"
|
KOBJFILE_NAME="$(basename --suffix=.ko "$OOT_MODULE")"
|
||||||
KOBJFILE_PATH="$OOT_MODULE"
|
KOBJFILE_PATH="$OOT_MODULE"
|
||||||
|
@ -1084,7 +1095,7 @@ for i in $FILES; do
|
||||||
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
|
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
|
||||||
KOBJFILE_PATH="${TEMPDIR}/module/$KOBJFILE"
|
KOBJFILE_PATH="${TEMPDIR}/module/$KOBJFILE"
|
||||||
SYMTAB="${KOBJFILE_PATH}.symtab"
|
SYMTAB="${KOBJFILE_PATH}.symtab"
|
||||||
SYMVERS_FILE="$SRCDIR/Module.symvers"
|
SYMVERS_FILE="$BUILDDIR/Module.symvers"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readelf -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
|
readelf -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
|
||||||
|
@ -1138,7 +1149,7 @@ if [[ -z "$USERSRCDIR" ]] && [[ "$DISTRO" = ubuntu ]]; then
|
||||||
# UBUNTU: add UTS_UBUNTU_RELEASE_ABI to utsrelease.h after regenerating it
|
# UBUNTU: add UTS_UBUNTU_RELEASE_ABI to utsrelease.h after regenerating it
|
||||||
UBUNTU_ABI="${ARCHVERSION#*-}"
|
UBUNTU_ABI="${ARCHVERSION#*-}"
|
||||||
UBUNTU_ABI="${UBUNTU_ABI%-*}"
|
UBUNTU_ABI="${UBUNTU_ABI%-*}"
|
||||||
echo "#define UTS_UBUNTU_RELEASE_ABI $UBUNTU_ABI" >> "$SRCDIR"/include/generated/utsrelease.h
|
echo "#define UTS_UBUNTU_RELEASE_ABI $UBUNTU_ABI" >> "$KERNEL_SRCDIR"/include/generated/utsrelease.h
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$TEMPDIR/output" || die
|
cd "$TEMPDIR/output" || die
|
||||||
|
@ -1161,18 +1172,13 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$TEMPDIR/patch" || die
|
cd "$TEMPDIR/patch" || die
|
||||||
if [[ -z "$OOT_MODULE" ]]; then
|
|
||||||
KPATCH_BUILD="$SRCDIR"
|
|
||||||
else
|
|
||||||
KPATCH_BUILD="/lib/modules/$ARCHVERSION/build"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We no longer need kpatch-cc
|
# We no longer need kpatch-cc
|
||||||
for ((idx=0; idx<${#MAKEVARS[@]}; idx++)); do
|
for ((idx=0; idx<${#MAKEVARS[@]}; idx++)); do
|
||||||
MAKEVARS[$idx]=${MAKEVARS[$idx]/${KPATCH_CC_PREFIX}/}
|
MAKEVARS[$idx]=${MAKEVARS[$idx]/${KPATCH_CC_PREFIX}/}
|
||||||
done
|
done
|
||||||
|
|
||||||
export KPATCH_BUILD="$KPATCH_BUILD" KPATCH_NAME="$MODNAME" \
|
export KPATCH_BUILD="$BUILDDIR" KPATCH_NAME="$MODNAME" \
|
||||||
KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
|
KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
|
||||||
KPATCH_LDFLAGS="$KPATCH_LDFLAGS"
|
KPATCH_LDFLAGS="$KPATCH_LDFLAGS"
|
||||||
save_env
|
save_env
|
||||||
|
|
|
@ -47,10 +47,13 @@ effect.
|
||||||
Keep scratch files in /tmp
|
Keep scratch files in /tmp
|
||||||
(can be specified multiple times)
|
(can be specified multiple times)
|
||||||
|
|
||||||
-e|--oot-module
|
--oot-module
|
||||||
Enable patching out-of-tree module,
|
Enable patching out-of-tree module,
|
||||||
specify current version of module
|
specify current version of module
|
||||||
|
|
||||||
|
--oot-module-src
|
||||||
|
Specify out-of-tree module source directory
|
||||||
|
|
||||||
-R|--non-replace
|
-R|--non-replace
|
||||||
Disable replace flag of KLP
|
Disable replace flag of KLP
|
||||||
(replace is on by default)
|
(replace is on by default)
|
||||||
|
|
Loading…
Reference in New Issue