Skip to content

Commit 2c1a7c0

Browse files
committed
Fix building of photon live patch from kernel source RPM
Signed-off-by: Guruswamy Basavaiah <guruswamy.basavaiah@broadcom.com>
1 parent a04e6e9 commit 2c1a7c0

1 file changed

Lines changed: 24 additions & 40 deletions

File tree

kpatch-build/kpatch-build

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -855,16 +855,28 @@ if [[ ${#PATCH_LIST[@]} -eq 0 ]]; then
855855
fi
856856

857857
trace_on
858+
# Don't check external file.
859+
# shellcheck disable=SC1090
860+
if [[ -z "$USERSRCDIR" ]] && [[ -f "$RELEASE_FILE" ]]; then
861+
source "$RELEASE_FILE"
862+
DISTRO="$ID"
863+
fi
864+
858865

859866
if [[ -n "$SRCRPM" ]]; then
860867
if [[ -n "$ARCHVERSION" ]]; then
861868
warn "--archversion is incompatible with --sourcerpm"
862869
exit 1
863870
fi
864871
rpmname="$(basename "$SRCRPM")"
865-
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
872+
if [[ "$DISTRO" = photon ]]; then
873+
ARCHVERSION="${rpmname%.src.rpm}"
874+
else
875+
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
876+
fi
866877
ARCHVERSION="${ARCHVERSION#kernel-}"
867878
ARCHVERSION="${ARCHVERSION#alt-}"
879+
ARCHVERSION="${ARCHVERSION#linux-}"
868880
fi
869881

870882
if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
@@ -914,13 +926,6 @@ fi
914926

915927
[[ "$SKIPCLEANUP" -eq 0 ]] && trap cleanup EXIT INT TERM HUP
916928

917-
# Don't check external file.
918-
# shellcheck disable=SC1090
919-
if [[ -z "$USERSRCDIR" ]] && [[ -f "$RELEASE_FILE" ]]; then
920-
source "$RELEASE_FILE"
921-
DISTRO="$ID"
922-
fi
923-
924929
KVER="${ARCHVERSION%%-*}"
925930
if [[ "$ARCHVERSION" =~ - ]]; then
926931
# handle flavor extension on Photon ex) -rt, -esx
@@ -932,12 +937,12 @@ if [[ "$ARCHVERSION" =~ - ]]; then
932937
KREL="${KREL%-*}"
933938
KREL="${KREL#*-}"
934939

935-
PH_TAG="${ARCHVERSION##*.}"
936-
PH_FLAVOR="${PH_TAG##*-}"
937-
PH_TAG="${PH_TAG%%-*}"
938-
939-
# if no flavor, these will be the same
940-
[[ "$PH_FLAVOR" = "$PH_TAG" ]] && PH_FLAVOR=""
940+
PH_TAG=$(echo "$ARCHVERSION" | grep -oE 'ph[0-9]+')
941+
if [[ "$ARCHVERSION" =~ (^|[-\.])(rt|esx|aws)($|[-\.]) ]]; then
942+
PH_FLAVOR="${BASH_REMATCH[2]}"
943+
else
944+
PH_FLAVOR=""
945+
fi
941946
else
942947
KREL="${ARCHVERSION##*-}"
943948
fi
@@ -1015,11 +1020,9 @@ else
10151020
if [ -z "$SRCRPM" ]; then
10161021
SRCRPM="$TEMPDIR/kernel$ALT-$KVER-$KREL.src.rpm"
10171022
fi
1018-
10191023
fi
10201024

10211025
echo "Unpacking kernel source"
1022-
10231026
if [[ "$DISTRO" = photon ]]; then
10241027
[[ -n "$PH_FLAVOR" ]] && SPECNAME="linux-$PH_FLAVOR.spec" || SPECNAME="linux.spec"
10251028
else
@@ -1030,7 +1033,7 @@ else
10301033

10311034
# Define dist tag to handle rpmbuild of the linux src rpm in Photon
10321035
if [[ "$DISTRO" = photon ]] && [ "$(rpm -E %dist)" = "%dist" ]; then
1033-
sed -i "1s/^/%define dist .$PH_TAG/" "$RPMTOPDIR"/SPECS/"$SPECNAME"
1036+
sed -i "1s|^|%define dist .$PH_TAG\n\n|" "$RPMTOPDIR"/SPECS/"$SPECNAME"
10341037
fi
10351038

10361039
rpmbuild -D "_topdir $RPMTOPDIR" -bp --nodeps "--target=$(uname -m)" "$RPMTOPDIR"/SPECS/"$SPECNAME" 2>&1 | logger || die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
@@ -1042,19 +1045,6 @@ else
10421045
elif [[ "$DISTRO" = opencloudos ]]; then
10431046
mv "$RPMTOPDIR"/BUILD/kernel-*/kernel-* "$KERNEL_SRCDIR" 2>&1 | logger || die
10441047
elif [[ "$DISTRO" = photon ]]; then
1045-
# Photon has some files that are copied over during the build section of the spec file (instead of prep)
1046-
# These change occasionally, so check they exist before copying
1047-
ls "$RPMTOPDIR"/BUILD/fips*canister* &> /dev/null && ( cp -rT "$RPMTOPDIR"/BUILD/fips*canister* "$RPMTOPDIR"/BUILD/linux-"$KVER"/crypto | logger || die )
1048-
[[ -f "$RPMTOPDIR"/SOURCES/fips_canister-kallsyms ]] && ( cp "$RPMTOPDIR"/SOURCES/fips_canister-kallsyms rpmbuild/BUILD/linux-"$KVER"/crypto | logger || die )
1049-
1050-
if [[ -z "$CONFIGFILE" ]]; then
1051-
# Photon has multiple config files per src rpm sometimes, and naming is not consistent.
1052-
# So do our best to find the right one by parsing the spec file
1053-
SRC_CFG=$(rpmspec -P -D "_topdir $RPMTOPDIR" "$RPMTOPDIR"/SPECS/"$SPECNAME" | awk '/^cp .*\/SOURCES\/config.* \.config$/{print $2}')
1054-
[[ -z "$SRC_CFG" ]] && die "Failed to locate kernel config file"
1055-
SRC_CFG="${SRC_CFG##*/}"
1056-
cp "$RPMTOPDIR"/SOURCES/"$SRC_CFG" "$RPMTOPDIR"/BUILD/linux-"$KVER" | logger || die
1057-
fi
10581048
mv "$RPMTOPDIR"/BUILD/linux-"$KVER" "$KERNEL_SRCDIR" 2>&1 | logger || die
10591049
else
10601050
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$KERNEL_SRCDIR" 2>&1 | logger || die
@@ -1072,20 +1062,14 @@ else
10721062
if [[ "$DISTRO" = openEuler ]] || [[ "$DISTRO" = opencloudos ]]; then
10731063
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="/boot/config-${ARCHVERSION}"
10741064
elif [[ "$DISTRO" = photon ]]; then
1075-
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR/$SRC_CFG"
1076-
1077-
# modify config file here to get the right vermagic, as Photon does not always listen to localversion file
1078-
if [[ -z "$PH_FLAVOR" ]]; then
1079-
sed -i s/^CONFIG_LOCALVERSION=\".*\"/CONFIG_LOCALVERSION=\"-"$KREL"."$PH_TAG"\"/g "$CONFIGFILE" || die
1080-
else
1081-
sed -i s/^CONFIG_LOCALVERSION=\".*\"/CONFIG_LOCALVERSION=\"-"$KREL"."$PH_TAG"-"$PH_FLAVOR"\"/g "$CONFIGFILE" || die
1082-
fi
1083-
1065+
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR"/.config
10841066
else
10851067
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR/configs/kernel$ALT-$KVER-$ARCH.config"
10861068
fi
1069+
if [[ ! "$DISTRO" = photon ]]; then
1070+
(cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die
1071+
fi
10871072

1088-
(cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die
10891073

10901074
elif is_supported_deb_distro "$DISTRO"; then
10911075

0 commit comments

Comments
 (0)