commit
162137812b
@ -0,0 +1,28 @@
|
||||
#! /bin/bash -efu
|
||||
|
||||
## A counterpart of brp-kmod-set-exec-bits that restores original kmod
|
||||
## file permissions
|
||||
|
||||
# If using normal root, avoid changing anything.
|
||||
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] || exit 0
|
||||
|
||||
# Checking for required programs
|
||||
which chmod >/dev/null || exit 0
|
||||
|
||||
[ -r "$RPM_BUILD_ROOT/kmod-permissions.list" ] || exit 0
|
||||
|
||||
while read perm path; do
|
||||
[ -n "$perm" ] || continue
|
||||
|
||||
# Account for possible kernel module compression
|
||||
[ -e "$RPM_BUILD_ROOT/$path" ] || {
|
||||
[ \! -e "$RPM_BUILD_ROOT/$path.gz" ] || path="$path.gz"
|
||||
[ \! -e "$RPM_BUILD_ROOT/$path.bz2" ] || path="$path.bz2"
|
||||
[ \! -e "$RPM_BUILD_ROOT/$path.xz" ] || path="$path.xz"
|
||||
[ \! -e "$RPM_BUILD_ROOT/$path.zst" ] || path="$path.zst"
|
||||
}
|
||||
|
||||
chmod "$perm" "$RPM_BUILD_ROOT/$path"
|
||||
done < "$RPM_BUILD_ROOT/kmod-permissions.list"
|
||||
|
||||
rm -f "$RPM_BUILD_ROOT/kmod-permissions.list"
|
@ -0,0 +1,14 @@
|
||||
#! /bin/bash -efux
|
||||
|
||||
## A hack for making brp-strip taking into account kmod files
|
||||
|
||||
# If using normal root, avoid changing anything.
|
||||
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] || exit 0
|
||||
|
||||
# Checking for required programs
|
||||
which find chmod >/dev/null || exit 0
|
||||
|
||||
find "$RPM_BUILD_ROOT" \
|
||||
-name '*.ko' \
|
||||
-printf '%#m %P\n' \
|
||||
-exec chmod u+x '{}' \; > "$RPM_BUILD_ROOT/kmod-permissions.list"
|
@ -0,0 +1,138 @@
|
||||
#! /bin/bash
|
||||
|
||||
IFS=$'\n'
|
||||
export LC_ALL=C
|
||||
|
||||
# Prevent elfutils from trying to download debuginfos
|
||||
unset DEBUGINFOD_URLS
|
||||
|
||||
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
|
||||
dep_pfx="ksym"
|
||||
# For built-in kmods, "kernel()" syntax is used instead of "ksym()"
|
||||
printf "%s" "$module" | grep -v "^${RPM_BUILD_ROOT}/\?lib/modules/[1-9][^/]*/kernel" > /dev/null \
|
||||
|| dep_pfx="kernel"
|
||||
|
||||
tmpfile=""
|
||||
if [ "x${module%.ko}" = "x${module}" ]; then
|
||||
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
|
||||
proc_bin=
|
||||
case "${module##*.}" in
|
||||
zst)
|
||||
proc_bin=zstd
|
||||
;;
|
||||
xz)
|
||||
proc_bin=xz
|
||||
;;
|
||||
bz2)
|
||||
proc_bin=bzip2
|
||||
;;
|
||||
gz)
|
||||
proc_bin=gzip
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -n "$proc_bin" ] || continue
|
||||
|
||||
"$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
|
||||
module="$tmpfile"
|
||||
fi
|
||||
|
||||
# A modversion can be stored as an ELF symbol in various ways:
|
||||
# - An immediate symbol whose value is available directly; it shows up
|
||||
# in the nm or objdump -t output, for example:
|
||||
# $ nm mlx5_core_5.14.x86_64.ko | grep '__crc_' | head -n 3
|
||||
# 0000000092f175ca A __crc_mlx5_access_reg
|
||||
# 000000005b88c9f1 A __crc_mlx5_add_flow_rules
|
||||
# 00000000e7c0ec8a A __crc_mlx5_alloc_bfreg
|
||||
# $ objdump -t lib/modules/mlx5_core_5.14.x86_64.ko | grep __crc_ | sort -k 5,5 | head -n 3
|
||||
# 0000000092f175ca g *ABS* 0000000000000000 __crc_mlx5_access_reg
|
||||
# 000000005b88c9f1 g *ABS* 0000000000000000 __crc_mlx5_add_flow_rules
|
||||
# 00000000e7c0ec8a g *ABS* 0000000000000000 __crc_mlx5_alloc_bfreg
|
||||
# $ zgrep mlx5_access_reg ./lib/modules/5.14.0-284.15.1.el9_2.x86_64/symvers.gz
|
||||
# 0x92f175ca mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
||||
# This approach was being used on x86 and arm before Linux 5.19,
|
||||
# for example.
|
||||
#
|
||||
# - A globally or locally visible symbol in a read-only (or not;
|
||||
# sometimes .rodata is not a read-only section, after all, as binutils
|
||||
# commit binutils-2_33~1385 has revealed (and binutils-2_35~1768 hasn't
|
||||
# concealed back)) section (historically .rodata, __kcrctab/__kcrctab_gpl
|
||||
# since Linux v5.19-rc1~139^2~2):
|
||||
# $ nm mlx5_core_5.14.s390x.ko | grep '__crc_' | head -n 3
|
||||
# 0000000000002f7c R __crc_mlx5_access_reg
|
||||
# 0000000000003304 R __crc_mlx5_add_flow_rules
|
||||
# 0000000000002d2c R __crc_mlx5_alloc_bfreg
|
||||
# This layout is used on ppc since Linux v4.10-rc7~15^2~1, for example,
|
||||
# and on all architectures since Linux 5.19. To extract the symbol
|
||||
# versions in this case, we get the offset and the section name
|
||||
# from the "objdump -t" output:
|
||||
# $ objdump -t lib/modules/mlx5_core_5.14.s390x.ko | grep '__crc_' | sort -k 5,5 | head -n 2
|
||||
# 0000000000002f7c g .rodata 0000000000000000 __crc_mlx5_access_reg
|
||||
# 0000000000003304 g .rodata 0000000000000000 __crc_mlx5_add_flow_rules
|
||||
# and the section contents from the "readelf -R" call:
|
||||
# $ readelf -R .rodata mlx5_core_5.14.s390x.ko
|
||||
# [... skipped output ...]
|
||||
# 0x00002f70 6c6f635f 6e6f6465 00000000 ed6560a8 loc_node.....e`.
|
||||
# ^^^^^^^^
|
||||
# comparison with the contents
|
||||
# of lib/modules/5.14.0-284.15.1.el9_2.s390x/symvers.gz corroborates
|
||||
# its correctness:
|
||||
# 0xed6560a8 mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
||||
# As mentioned earlier, for the later kernel versions, __kcrctab{,_gpl}
|
||||
# sections are used:
|
||||
# $ objdump -t lib/modules/mlx5_core_6.4.x86_64.ko | grep '__crc_' | sort -k 5,5 | head -n 2
|
||||
# 0000000000000000 l __kcrctab_gpl 0000000000000000 __crc_mlx5_access_reg
|
||||
# 0000000000000090 l __kcrctab 0000000000000000 __crc_mlx5_add_flow_rules
|
||||
# $ readelf -R __kcrctab_gpl mlx5_core_6.4.x86_64.ko
|
||||
# 0x00000000 38b0d3c3 1840ce35 b99babc7 70b4700c 8....@.5....p.p.
|
||||
# ^^^^^^^^
|
||||
# and in lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.x86_64/symvers.xz
|
||||
# we see that it is correct (when accounted for the little endianness):
|
||||
# 0xc3d3b038 mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
||||
# This data, after some post-processing, can be used in the awk script
|
||||
# that extracts parts of the section according to the offsets got
|
||||
# from the "objdump -t" output.
|
||||
objdump -t "$module" \
|
||||
| awk \
|
||||
-v 'dep_pfx='"$dep_pfx" \
|
||||
-v 'module='"$module" \
|
||||
--non-decimal-data \
|
||||
'BEGIN { revbytes = 0 }
|
||||
|
||||
function check_endianness( t) {
|
||||
if (revbytes) return revbytes;
|
||||
|
||||
revbytes = -1;
|
||||
while (("readelf -h \"" module "\"" | getline t) > 0) {
|
||||
if (match(t, /^ Data: *2\047s complement, little endian$/)) {
|
||||
revbytes = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return revbytes;
|
||||
}
|
||||
|
||||
function readsect(name, a, t) {
|
||||
a = "";
|
||||
while (("readelf -R \"" name "\" \"" module "\"" | getline t) > 0) {
|
||||
if (match(t, /^ 0x[0-9a-f]{8}/))
|
||||
a = a substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8);
|
||||
}
|
||||
if (check_endianness() == 1)
|
||||
a = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", a);
|
||||
sectdata[name] = a;
|
||||
}
|
||||
|
||||
match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) {
|
||||
if (a[2] == "*ABS*") {
|
||||
printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1]));
|
||||
} else {
|
||||
if (!(a[2] in sectdata)) { readsect(a[2]) }
|
||||
printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata[a[2]], (strtonum("0x" a[1]) * 2) + 1, 8))
|
||||
}
|
||||
}'
|
||||
|
||||
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
|
||||
done \
|
||||
| sort -k1,1 -u
|
@ -0,0 +1,188 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# This script is called during external module building to create dependencies
|
||||
# both upon the RHEL kernel, and on additional external modules. Symbols that
|
||||
# cannot be reconciled against those provided by the kernel are assumed to be
|
||||
# provided by an external module and "ksym" replaces th regular "kernel" dep.
|
||||
|
||||
IFS=$'\n'
|
||||
export LC_ALL=C
|
||||
|
||||
# Prevent elfutils from trying to download debuginfos
|
||||
unset DEBUGINFOD_URLS
|
||||
|
||||
# Extract all of the symbols provided by this module.
|
||||
all_provides() {
|
||||
for module in "$@"; do
|
||||
tmpfile=""
|
||||
if [ "x${module%.ko}" = "x${module}" ]; then
|
||||
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
|
||||
proc_bin=
|
||||
case "${module##*.}" in
|
||||
zst)
|
||||
proc_bin=zstd
|
||||
;;
|
||||
xz)
|
||||
proc_bin=xz
|
||||
;;
|
||||
bz2)
|
||||
proc_bin=bzip2
|
||||
;;
|
||||
gz)
|
||||
proc_bin=gzip
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -n "$proc_bin" ] || continue
|
||||
|
||||
"$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
|
||||
module="$tmpfile"
|
||||
fi
|
||||
|
||||
objdump -t "$module" \
|
||||
| awk \
|
||||
-v 'dep_pfx='"$dep_pfx" \
|
||||
-v 'module='"$module" \
|
||||
--non-decimal-data \
|
||||
'BEGIN { revbytes = 0 }
|
||||
|
||||
function check_endianness( t) {
|
||||
if (revbytes) return revbytes;
|
||||
|
||||
revbytes = -1;
|
||||
while (("readelf -h \"" module "\"" | getline t) > 0) {
|
||||
if (match(t, /^ Data: *2\047s complement, little endian$/)) {
|
||||
revbytes = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return revbytes;
|
||||
}
|
||||
|
||||
function readsect(name, a, t) {
|
||||
a = "";
|
||||
while (("readelf -R \"" name "\" \"" module "\"" | getline t) > 0) {
|
||||
if (match(t, /^ 0x[0-9a-f]{8}/))
|
||||
a = a substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8);
|
||||
}
|
||||
if (revbytes) { a = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", a); }
|
||||
sectdata[name] = a;
|
||||
}
|
||||
|
||||
match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) {
|
||||
if (a[2] == "*ABS*") {
|
||||
printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1]));
|
||||
} else {
|
||||
if (!(a[2] in sectdata)) { readsect(a[2]) }
|
||||
printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata[a[2]], (strtonum("0x" a[1]) * 2) + 1, 8))
|
||||
}
|
||||
}'
|
||||
|
||||
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
|
||||
done \
|
||||
| sort -k1,1 -u
|
||||
}
|
||||
|
||||
# Extract all of the requirements of this module.
|
||||
all_requires() {
|
||||
for module in "$@"; do
|
||||
set -- $(/sbin/modinfo -F vermagic "$module" | sed -e 's: .*::' -e q)
|
||||
/sbin/modprobe --dump-modversions "$module" \
|
||||
| awk --non-decimal-data '
|
||||
BEGIN { FS = "\t" ; OFS = "\t" }
|
||||
{printf("%s:0x%08x\n", $2, $1)}' \
|
||||
| sed -r -e 's:$:\t'"$1"':'
|
||||
done \
|
||||
| sort -k1,1 -u
|
||||
}
|
||||
|
||||
# Filter out requirements fulfilled by the module itself.
|
||||
mod_requires() {
|
||||
join -t $'\t' -j 1 -v 1 \
|
||||
<(all_requires "$@") \
|
||||
<(all_provides "$@") \
|
||||
| sort -k1,1 -u
|
||||
}
|
||||
|
||||
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
|
||||
cat > /dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
||||
check_kabi() {
|
||||
arch=$(uname -m)
|
||||
kabi_file="/lib/modules/kabi-current/kabi_stablelist_$arch"
|
||||
|
||||
# If not installed, output a warning and return (continue)
|
||||
if [ ! -f "$kabi_file" ]; then
|
||||
echo "" >&2
|
||||
echo "********************************************************************************" >&2
|
||||
echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
|
||||
echo "********************************************************************************" >&2
|
||||
echo "The kernel ABI reference files (provided by "kabi-stablelists") were not found." >&2
|
||||
echo "No compatibility check was performed. Please install the kABI reference files" >&2
|
||||
echo "and rebuild if you would like to verify compatibility with kernel ABI." >&2
|
||||
echo "" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
unset non_kabi
|
||||
for symbol in "$@"; do
|
||||
if ! egrep "^[[:space:]]$symbol\$" $kabi_file >/dev/null; then
|
||||
non_kabi=("${non_kabi[@]}" "$symbol")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#non_kabi[@]} -gt 0 ]; then
|
||||
echo "" >&2
|
||||
echo "********************************************************************************" >&2
|
||||
echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
|
||||
echo "********************************************************************************" >&2
|
||||
echo "The following kernel symbols are not guaranteed to remain compatible with" >&2
|
||||
echo "future kernel updates to this RHEL release:" >&2
|
||||
echo "" >&2
|
||||
for symbol in "${non_kabi[@]}"; do
|
||||
printf "\t$symbol\n" >&2
|
||||
done
|
||||
echo "" >&2
|
||||
echo "Red Hat recommends that you consider using only official kernel ABI symbols" >&2
|
||||
echo "where possible. Requests for additions to the kernel ABI can be filed with" >&2
|
||||
echo "your partner or customer representative (component: driver-update-program)." >&2
|
||||
echo "" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
modules=($(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@")
|
||||
if [ ${#modules[@]} -gt 0 ]; then
|
||||
kernel=$(/sbin/modinfo -F vermagic "${modules[0]}" | sed -e 's: .*::' -e q)
|
||||
|
||||
# get all that kernel provides
|
||||
symvers=$(mktemp -t ${0##*/}.XXXXX)
|
||||
|
||||
cat /usr/src/kernels/$kernel/Module.symvers | awk '
|
||||
BEGIN { FS = "\t" ; OFS = "\t" }
|
||||
{ print $2 ":" $1 }
|
||||
' \
|
||||
| sed -r -e 's:$:\t'"$kernel"':' \
|
||||
| sort -k1,1 -u > $symvers
|
||||
|
||||
# Symbols matching with the kernel get a "kernel" dependency
|
||||
mod_req=$(mktemp -t mod_req.XXXXX)
|
||||
mod_requires "${modules[@]}" > "$mod_req"
|
||||
join -t $'\t' -j 1 $symvers "$mod_req" | sort -u \
|
||||
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "kernel(" $1 ") = " $2 }'
|
||||
|
||||
# Symbols from elsewhere get a "ksym" dependency
|
||||
join -t $'\t' -j 1 -v 2 $symvers "$mod_req" | sort -u \
|
||||
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "ksym(" $1 ") = " $2 }'
|
||||
|
||||
os_id=$(sed -nr '/^ID[[:space:]]*=/{ s/ID[[:space:]]*=[[:space:]]*//; s/^"(.*)"$/\1/; p }' /etc/os-release)
|
||||
if [ "rhel" = "$os_id" ]; then
|
||||
# Check kABI if the kabi-stablelists package is installed
|
||||
# Do this last so we can try to output this error at the end
|
||||
kabi_check_symbols=($(join -t $'\t' -j 1 $symvers "$mod_req" | sort -u \
|
||||
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print $1 }'))
|
||||
check_kabi "${kabi_check_symbols[@]}"
|
||||
fi
|
||||
fi
|
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# firmware.prov - Automatically extract any and all firmware dependencies from
|
||||
# kernel object (.ko) files and add to RPM deps.
|
||||
|
||||
IFS=$'\n'
|
||||
|
||||
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') $*;
|
||||
do
|
||||
for firmware in `/sbin/modinfo -F firmware $module`;
|
||||
do
|
||||
echo "firmware($firmware)"
|
||||
done
|
||||
done
|
@ -0,0 +1,2 @@
|
||||
%__kabi_provides %{_rpmconfigdir}/kabi.sh
|
||||
%__kabi_path ^(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.(gz|xz)$
|
@ -0,0 +1,22 @@
|
||||
#!/bin/bash +x
|
||||
#
|
||||
# kabi.sh - Automatically extract any kernel symbol checksum from the
|
||||
# symvers file and add to RPM deps. This is used to move the
|
||||
# checksum checking from modprobe to rpm install for 3rd party
|
||||
# modules (so they can fail during install and not at load).
|
||||
|
||||
IFS=$'\n'
|
||||
|
||||
for symvers in $(grep -E '(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.(gz|xz)') "$@";
|
||||
do
|
||||
cat_prog="cat"
|
||||
case "$symvers" in
|
||||
*.gz) cat_prog="zcat" ;;
|
||||
*.xz) cat_prog="xzcat" ;;
|
||||
esac
|
||||
|
||||
# We generate dependencies only for symbols exported by vmlinux itself
|
||||
# and not for kmods here as they are spread across subpackages,
|
||||
# so Provides: generation for kmods is handled by find-provides.ksyms.
|
||||
"$cat_prog" "$symvers" | awk '/[^ ]* [^ ]* vmlinux .*/ { print "kernel(" $2 ") = " $1 }'
|
||||
done
|
@ -0,0 +1,54 @@
|
||||
%__kmod_path ^/lib/modules/.*/(modules.builtin|.*\.ko|.*\.ko\.gz|.*\.ko\.bz2|.*\.ko\.xz|.*\.ko\.zst)$
|
||||
|
||||
# Notes on Lua:
|
||||
# The backslash in strings (like "\n" newline) needs to be doubled
|
||||
# because we are inside rpm macro. Single backslashes before most chars
|
||||
# disappear (removed by rpm's parser), so "\n" turns into just "n".
|
||||
# In string.gsub patterns, unlike regexps, backslash has no special meaning.
|
||||
# It can't escape . and such. (Use one-character set [.] to represent
|
||||
# literal period, or lua's percent escape: %.)
|
||||
# Pipe (|) has no special meaning too.
|
||||
|
||||
%__kmod_provides() %{lua:
|
||||
function basename(fn)
|
||||
local b = string.gsub(fn, ".*/", "")
|
||||
-- the above adjusts gsub() result to 1 value
|
||||
-- "return f()" construct would return _all_ values, two in case of gsub()
|
||||
return b
|
||||
end
|
||||
function strip_compress_sfx(fn)
|
||||
local cnt
|
||||
fn, cnt = string.gsub(fn, "%.gz$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.bz2$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.xz$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.zst$", "")
|
||||
return fn
|
||||
end
|
||||
function printdep(mod)
|
||||
print("kmod("..mod..") ")
|
||||
end
|
||||
local fn = rpm.expand("%1")
|
||||
local bn = basename(fn)
|
||||
if bn == "modules.builtin" then
|
||||
for l in io.lines(fn) do
|
||||
local builtin_mod = basename(l)
|
||||
printdep(builtin_mod)
|
||||
local nocompr = strip_compress_sfx(builtin_mod)
|
||||
if nocompr ~= builtin_mod then
|
||||
printdep(nocompr)
|
||||
end
|
||||
end
|
||||
else
|
||||
local mod = string.match(bn, "%g+%.ko")
|
||||
if mod then
|
||||
printdep(mod)
|
||||
local nocompr = strip_compress_sfx(mod)
|
||||
if nocompr ~= mod then
|
||||
printdep(nocompr)
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
@ -0,0 +1,346 @@
|
||||
#!/bin/bash
|
||||
|
||||
# kmodtool - Helper script for building kernel module RPMs
|
||||
# An original version appeared in Fedora. This version is
|
||||
# generally called only by the %kernel_module_package RPM macro
|
||||
# during the process of building Driver Update Packages (which
|
||||
# are also known as "kmods" in the Fedora community).
|
||||
#
|
||||
# Copyright (c) 2003-2010 Ville Skyttä <ville.skytta@iki.fi>,
|
||||
# Thorsten Leemhuis <fedora@leemhuis.info>
|
||||
# Jon Masters <jcm@redhat.com>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# Changelog:
|
||||
#
|
||||
# 2010/07/28 - Add fixes for filelists in line with LF standard
|
||||
# - Remove now defunct "framepointer" kernel variant
|
||||
# - Change version to "rhel6-rh2" as a consequence.
|
||||
#
|
||||
# 2010/01/10 - Simplified for RHEL6. We are working on upstream
|
||||
# moving to a newer format and in any case do not
|
||||
# need to retain support for really old systems.
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
myprog="kmodtool"
|
||||
myver="0.10.10_rhel9"
|
||||
knownvariants=@(debug|kdump|zfcpdump)
|
||||
kmod_name=
|
||||
kver=
|
||||
verrel=
|
||||
variant=
|
||||
|
||||
get_verrel ()
|
||||
{
|
||||
verrel=${1:-$(uname -r)}
|
||||
verrel=${verrel/%[.+]$knownvariants/}
|
||||
}
|
||||
|
||||
print_verrel ()
|
||||
{
|
||||
get_verrel "$@"
|
||||
echo "${verrel}"
|
||||
}
|
||||
|
||||
get_variant ()
|
||||
{
|
||||
get_verrel "$@"
|
||||
variant=${1:-$(uname -r)}
|
||||
variant=${variant/#$verrel?(.+)/}
|
||||
variant=${variant:-'""'}
|
||||
}
|
||||
|
||||
print_variant ()
|
||||
{
|
||||
get_variant $@
|
||||
echo "${variant}"
|
||||
}
|
||||
|
||||
# Detect flavor separator character. We have to do that due to
|
||||
# a systemd-tailored patch for kernel spec[1][2] introduced in Fedora and then
|
||||
# imported in RHEL 8 that broke all OOT kmod infrastructure for the flavored
|
||||
# kernels.
|
||||
#
|
||||
# [1] https://lists.fedoraproject.org/pipermail/kernel/2013-June/004262.html
|
||||
# [2] https://src.fedoraproject.org/rpms/kernel/c/faf25207dc86666a611c45ae3ffaf385c170bd2a
|
||||
#
|
||||
# $1 - kver
|
||||
# $2 - variant
|
||||
get_variant_char ()
|
||||
{
|
||||
variant="$2"
|
||||
[ "$variant" != "default" ] || variant=""
|
||||
|
||||
get_verrel "$1"
|
||||
|
||||
variant_char=""
|
||||
[ -n "$variant" ] || return 0
|
||||
|
||||
# We expect that the flavored kernel is already installed in the buildroot
|
||||
variant_char="+"
|
||||
[ -e "/usr/src/kernels/${verrel}+${variant}" ] && return 0
|
||||
|
||||
variant_char="."
|
||||
}
|
||||
|
||||
print_variant_char ()
|
||||
{
|
||||
get_variant_char "$@"
|
||||
echo "${variant_char}"
|
||||
}
|
||||
|
||||
print_kernel_source ()
|
||||
{
|
||||
get_variant_char "$@"
|
||||
echo "/usr/src/kernels/${verrel}${variant_char}${variant}"
|
||||
}
|
||||
|
||||
get_filelist() {
|
||||
local IFS=$'\n'
|
||||
filelist=($(cat))
|
||||
|
||||
if [ ${#filelist[@]} -gt 0 ];
|
||||
then
|
||||
for ((n = 0; n < ${#filelist[@]}; n++));
|
||||
do
|
||||
line="${filelist[n]}"
|
||||
line=$(echo "$line" \
|
||||
| sed -e "s/%verrel/$verrel/g" \
|
||||
| sed -e "s/%variant/$variant/g" \
|
||||
| sed -e "s/%dashvariant/$dashvariant/g" \
|
||||
| sed -e "s/%dotvariant/$dotvariant/g" \
|
||||
| sed -e "s/\+%1/$dotvariant/g" \
|
||||
| sed -e "s/\.%1/$dotvariant/g" \
|
||||
| sed -e "s/\-%1/$dotvariant/g" \
|
||||
| sed -e "s/%2/$verrel/g")
|
||||
echo "$line"
|
||||
done
|
||||
else
|
||||
echo "%defattr(644,root,root,755)"
|
||||
echo "/lib/modules/${verrel}${dotvariant}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_rpmtemplate ()
|
||||
{
|
||||
local variant="${1}"
|
||||
|
||||
get_variant_char "${verrel}" "${variant}"
|
||||
|
||||
local dashvariant="${variant:+-${variant}}"
|
||||
local dotvariant="${variant:+${variant_char}${variant}}"
|
||||
|
||||
echo "%package -n kmod-${kmod_name}${dashvariant}"
|
||||
|
||||
if [ -z "$kmod_provides_summary" ]; then
|
||||
echo "Summary: ${kmod_name} kernel module(s)"
|
||||
fi
|
||||
|
||||
if [ -z "$kmod_provides_group" ]; then
|
||||
echo "Group: System Environment/Kernel"
|
||||
fi
|
||||
|
||||
if [ ! -z "$kmod_version" ]; then
|
||||
echo "Version: %{kmod_version}"
|
||||
fi
|
||||
|
||||
if [ ! -z "$kmod_release" ]; then
|
||||
echo "Release: %{kmod_release}"
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Provides: kernel-modules >= ${verrel}${dotvariant}
|
||||
Provides: kernel${dashvariant}-modules >= ${verrel}
|
||||
Provides: ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
|
||||
Requires(post): /usr/sbin/depmod
|
||||
Requires(postun): /usr/sbin/depmod
|
||||
Requires(post): /usr/sbin/weak-modules
|
||||
Requires(postun): /usr/sbin/weak-modules
|
||||
EOF
|
||||
|
||||
if [ "yes" != "$nobuildreqs" ]
|
||||
then
|
||||
cat <<EOF
|
||||
BuildRequires: kernel${dashvariant}-devel
|
||||
BuildRequires: kernel-abi-stablelists
|
||||
BuildRequires: redhat-rpm-config kernel-rpm-macros
|
||||
BuildRequires: elfutils-libelf-devel kmod
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ "" != "$override_preamble" ]
|
||||
then
|
||||
cat "$override_preamble"
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
%description -n kmod-${kmod_name}${dashvariant}
|
||||
This package provides the ${kmod_name} kernel modules built for
|
||||
the Linux kernel ${verrel}${dotvariant} for the %{_target_cpu}
|
||||
family of processors.
|
||||
EOF
|
||||
|
||||
##############################################################################
|
||||
## The following are not part of this script directly, they are scripts ##
|
||||
## that will be executed by RPM during various stages of package processing ##
|
||||
##############################################################################
|
||||
|
||||
cat <<EOF
|
||||
%post -n kmod-${kmod_name}${dashvariant}
|
||||
if [ -e "/boot/System.map-${verrel}${dotvariant}" ]; then
|
||||
/usr/sbin/depmod -aeF "/boot/System.map-${verrel}${dotvariant}" "${verrel}${dotvariant}" > /dev/null || :
|
||||
fi
|
||||
|
||||
modules=( \$(find /lib/modules/${verrel}${dotvariant}/extra/${kmod_name} | grep -E '\.ko(\.gz|\.bz2|\.xz|\.zst)?$') )
|
||||
if [ -x "/usr/sbin/weak-modules" ]; then
|
||||
printf '%s\n' "\${modules[@]}" \
|
||||
| /usr/sbin/weak-modules --add-modules
|
||||
fi
|
||||
EOF
|
||||
|
||||
cat <<EOF
|
||||
%preun -n kmod-${kmod_name}${dashvariant}
|
||||
rpm -ql kmod-${kmod_name}${dashvariant}-%{kmod_version}-%{kmod_release}.$(arch) | grep -E '\.ko(\.gz|\.bz2|\.xz|\.zst)?$' > /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
|
||||
EOF
|
||||
|
||||
cat <<EOF
|
||||
%postun -n kmod-${kmod_name}${dashvariant}
|
||||
if [ -e "/boot/System.map-${verrel}${dotvariant}" ]; then
|
||||
/usr/sbin/depmod -aeF "/boot/System.map-${verrel}${dotvariant}" "${verrel}${dotvariant}" > /dev/null || :
|
||||
fi
|
||||
|
||||
modules=( \$(cat /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules) )
|
||||
rm /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
|
||||
if [ -x "/usr/sbin/weak-modules" ]; then
|
||||
printf '%s\n' "\${modules[@]}" \
|
||||
| /usr/sbin/weak-modules --remove-modules
|
||||
fi
|
||||
EOF
|
||||
|
||||
echo "%files -n kmod-${kmod_name}${dashvariant}"
|
||||
|
||||
if [ "" == "$override_filelist" ];
|
||||
then
|
||||
echo "%defattr(644,root,root,755)"
|
||||
echo "/lib/modules/${verrel}${dotvariant}"
|
||||
else
|
||||
cat "$override_filelist" | get_filelist
|
||||
fi
|
||||
}
|
||||
|
||||
print_rpmtemplate ()
|
||||
{
|
||||
kmod_name="${1}"
|
||||
shift
|
||||
kver="${1}"
|
||||
get_verrel "${1}"
|
||||
shift
|
||||
if [ -z "${kmod_name}" ] ; then
|
||||
echo "Please provide the kmodule-name as first parameter." >&2
|
||||
exit 2
|
||||
elif [ -z "${kver}" ] ; then
|
||||
echo "Please provide the kver as second parameter." >&2
|
||||
exit 2
|
||||
elif [ -z "${verrel}" ] ; then
|
||||
echo "Couldn't find out the verrel." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
for variant in "$@" ; do
|
||||
if [ "default" == "$variant" ];
|
||||
then
|
||||
get_rpmtemplate ""
|
||||
else
|
||||
get_rpmtemplate "${variant}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
usage ()
|
||||
{
|
||||
cat <<EOF
|
||||
You called: ${invocation}
|
||||
|
||||
Usage: ${myprog} <command> <option>+
|
||||
Commands:
|
||||
verrel <uname>
|
||||
- Get "base" version-release.
|
||||
variant <uname>
|
||||
- Get variant from uname.
|
||||
variant_char <uname> <variant>
|
||||
- Get kernel variant separator character.
|
||||
kernel_source <uname> <variant>
|
||||
- Get path to kernel source directory.
|
||||
rpmtemplate <mainpgkname> <uname> <variants>
|
||||
- Return a template for use in a source RPM
|
||||
version
|
||||
- Output version number and exit.
|
||||
EOF
|
||||
}
|
||||
|
||||
invocation="$(basename ${0}) $@"
|
||||
while [ "${1}" ] ; do
|
||||
case "${1}" in
|
||||
verrel)
|
||||
shift
|
||||
print_verrel "$@"
|
||||
exit $?
|
||||
;;
|
||||
variant)
|
||||
shift
|
||||
print_variant "$@"
|
||||
exit $?
|
||||
;;
|
||||
variant_char)
|
||||
shift
|
||||
print_variant_char "$@"
|
||||
exit $?
|
||||
;;
|
||||
kernel_source)
|
||||
shift
|
||||
print_kernel_source "$@"
|
||||
exit $?
|
||||
;;
|
||||
rpmtemplate)
|
||||
shift
|
||||
print_rpmtemplate "$@"
|
||||
exit $?
|
||||
;;
|
||||
version)
|
||||
echo "${myprog} ${myver}"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown option '${1}'." >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# mode: sh
|
||||
# sh-indentation: 2
|
||||
# indent-tabs-mode: nil
|
||||
# End:
|
||||
# ex: ts=2 sw=2 et
|
@ -0,0 +1,3 @@
|
||||
# kernel_arches lists what arches the full kernel is built for.
|
||||
|
||||
%kernel_arches x86_64 s390x ppc64le aarch64 %{arm} riscv64
|
@ -0,0 +1,94 @@
|
||||
# Use these macros to differentiate between RH and other KMP implementation(s).
|
||||
redhat_kernel_module_package 1
|
||||
kernel_module_package_release 1
|
||||
|
||||
redhat_kmp_has_post_hooks 1
|
||||
|
||||
%__brp_kmod_set_exec_bit /usr/lib/rpm/redhat/brp-kmod-set-exec-bit
|
||||
%__brp_kmod_restore_perms /usr/lib/rpm/redhat/brp-kmod-restore-perms
|
||||
|
||||
%__kmod_brps_added 0
|
||||
|
||||
#kernel_module_package [ -n name ] [ -v version ] [ -r release ] [ -s script ]
|
||||
# [ -f filelist] [ -x ] [ -p preamble ] flavor flavor ...
|
||||
|
||||
%kernel_module_package_buildreqs %global kmodtool_generate_buildreqs 1 \
|
||||
kernel-devel redhat-rpm-config kernel-rpm-macros elfutils-libelf-devel kmod
|
||||
|
||||
%kernel_module_package(n:v:r:s:f:xp:) %{expand:%( \
|
||||
## An ugly hack: we want kmods to be processed by find-debuginfo,
|
||||
## but it processes only files with executable permission set.
|
||||
## It is important now since, as of now, if debuginfo package
|
||||
## is enabled (and it is enabled), there's an RPM build error
|
||||
## as a result of lack of ether absence or emptiness of
|
||||
## debugsourcefiles.list (which is likely a bug in RPM, but it looks
|
||||
## like that there's no obvious fix and apparently no one have
|
||||
## any issues with this).
|
||||
## In order to minimise intrusiveness, usually (in Red Hat-built kmod
|
||||
## RPMs) *.ko files just have executable permission being set as a part
|
||||
## of %build section. There are two caveats with kmp, however:
|
||||
## * We have no control over %build section itself (and it wasn't
|
||||
## required previously)
|
||||
## * Changing the criteria used in find-debuginfo.sh/brp-strip
|
||||
## for selecting files that have to undergo debug section separation
|
||||
## may introduce regression.
|
||||
## As a result, we insert additional hooks in __spec_install_post
|
||||
## (__brp_kmod_set_exec_bit in the beginning and
|
||||
## __brp_kmod_restore_perms in the end) that (temporarily) set
|
||||
## executable permission for *.ko files so find-debuginfo.sh will pick
|
||||
## them up.
|
||||
## Unfortunately, __spec_install_post's body is copied here since
|
||||
## we want that __debug_package macro expansion has been performed
|
||||
## lazily and it looks like RPM has no ability to provide a body
|
||||
## of a macro verbatim.
|
||||
if [ 0 = "%{__kmod_brps_added}" ]; then \
|
||||
echo "%%global __spec_install_post \\\\" \
|
||||
echo " %%{?__brp_kmod_set_exec_bit} \\\\" \
|
||||
echo " %%%%{?__debug_package:%%%%{__debug_install_post}} \\\\" \
|
||||
echo " %%{__arch_install_post} \\\\" \
|
||||
echo " %%{__os_install_post} \\\\" \
|
||||
echo " %%{?__brp_kmod_pre_sign_process} \\\\" \
|
||||
echo " %%{?__brp_kmod_sign} \\\\" \
|
||||
echo " %%{?__brp_kmod_post_sign_process} \\\\" \
|
||||
echo " %%{?__brp_kmod_compress} \\\\" \
|
||||
echo " %%{?__brp_kmod_post_compress_process} \\\\" \
|
||||
echo " %%{?__brp_kmod_restore_perms} \\\\" \
|
||||
echo "%%{nil}" \
|
||||
fi \
|
||||
%global __kmod_brps_added 1 \
|
||||
%global kmodtool %{-s*}%{!-s:/usr/lib/rpm/redhat/kmodtool} \
|
||||
%global kmod_version %{-v*}%{!-v:%{version}} \
|
||||
%global kmod_release %{-r*}%{!-r:%{release}} \
|
||||
%global latest_kernel %({ rpm -q --qf '%%{VERSION}-%%{RELEASE}.%%{ARCH}\\\\n' `rpm -qa | egrep "^kernel(-rt|-aarch64)?-devel" | /usr/lib/rpm/redhat/rpmsort -r | head -n 1`; echo '%%%%{nil}'; } | head -n 1) \
|
||||
%{!?kernel_version:%{expand:%%global kernel_version %{latest_kernel}}} \
|
||||
%global kverrel %(%{kmodtool} verrel %{?kernel_version} 2>/dev/null) \
|
||||
flavors="default" \
|
||||
if [ -z "%*" ]; then \
|
||||
flavors_to_build=$flavors \
|
||||
elif [ -z "%{-x}" ]; then \
|
||||
flavors_to_build="%*" \
|
||||
else \
|
||||
flavors_to_build=" $flavors "\
|
||||
for i in %* \
|
||||
do \
|
||||
flavors_to_build=${flavors_to_build//$i /}
|
||||
done \
|
||||
fi \
|
||||
echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \
|
||||
echo "%%global kernel_source() \\\$([ default = \"%%%%{1}\" ] && echo \"/usr/src/kernels//%%%%kverrel\" || %{kmodtool} kernel_source \"%%%%{kverrel}\" \"%%%%{1}\" 2>/dev/null || { ls -Ud \"/usr/src/kernels///%%%%{kverrel}\"[.+]\"%%%%{1}\" | sort -V | tail -n 1; } || echo \"/usr/src/kernels////%%%%kverrel.%%%%1\")" \
|
||||
echo "%%global kernel_module_package_moddir() extra" \
|
||||
if [ ! -z "%{-f*}" ] \
|
||||
then \
|
||||
filelist="%{-f*}" \
|
||||
fi \
|
||||
if [ ! -z "%{-p*}" ] \
|
||||
then \
|
||||
preamble="%{-p*}" \
|
||||
fi \
|
||||
nobuildreqs="yes" \
|
||||
if [ "x%{kmodtool_generate_buildreqs}" != "x1" ] \
|
||||
then \
|
||||
nobuildreqs="no" \
|
||||
fi \
|
||||
override_filelist="$filelist" override_preamble="$preamble" nobuildreqs="$nobuildreqs" kmod_version=%kmod_version kmod_release=%kmod_release %{kmodtool} rpmtemplate %{-n*}%{!-n:%name} %{kverrel} $flavors_to_build 2>/dev/null \
|
||||
)}
|
@ -0,0 +1,2 @@
|
||||
%__modalias_provides /usr/lib/rpm/redhat/find-provides.d/modalias.prov
|
||||
%__modalias_path .*\.(ko|ko\.gz|ko\.bz2|ko\.xz|ko\.zst)$
|
@ -0,0 +1,128 @@
|
||||
#! /bin/bash -efu
|
||||
|
||||
# heavily based upon find-suggests.ksyms by Andreas Gruenbacher <agruen@suse.de>.
|
||||
# with modifications by Michael Brown <Michael_E_Brown@dell.com>
|
||||
#
|
||||
# -- added module versioning info to modalias() symbols
|
||||
# -- removed code which inspects spec files.
|
||||
|
||||
IFS=$'\n'
|
||||
|
||||
#
|
||||
# Initially, dont generate modalias() lines for kernel package. This needs
|
||||
# additional discussion. Would like to eventually add them for
|
||||
# completeness, so that we can determine when drivers are folded into
|
||||
# mainline kernel.
|
||||
#
|
||||
is_kernel_package=""
|
||||
case "${1:-}" in
|
||||
kernel-module-*) ;; # Fedora kernel module package names start with
|
||||
# kernel-module.
|
||||
kernel*) is_kernel_package=1 ;;
|
||||
esac
|
||||
|
||||
if ! [ -z "$is_kernel_package" ]; then
|
||||
cat > /dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for presence of the commands used.
|
||||
# "command" is a builtin, faster to use than fork+execing "which" - see
|
||||
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
|
||||
command -v /sbin/modinfo >/dev/null || exit 1
|
||||
command -v sed >/dev/null || exit 1
|
||||
command -v sort >/dev/null || exit 1
|
||||
|
||||
print_modaliases() {
|
||||
local class="$1" variants="$2" pos="$3"
|
||||
if [ -n "$variants" ]; then
|
||||
echo "${class:0:pos}[$variants]${class:pos+1}"
|
||||
else
|
||||
[ -z "$class" ] || echo "$class"
|
||||
fi
|
||||
}
|
||||
|
||||
# Try to make "provides" list a bit smaller:
|
||||
# find "mergeable" strings a-la
|
||||
# modalias(pci:v0000168Cd00000023sv*sd*bc*sc*i*)
|
||||
# modalias(pci:v0000168Cd00000024sv*sd*bc*sc*i*)
|
||||
# modalias(pci:v0000168Cd00000027sv*sd*bc*sc*i*)
|
||||
# modalias(pci:v0000168Cd00000029sv*sd*bc*sc*i*)
|
||||
# replace with
|
||||
# modalias(pci:v0000168Cd0000002[3479]sv*sd*bc*sc*i*)
|
||||
combine_modaliases() {
|
||||
local unused_len next prev variants="" pos="" n end xc
|
||||
|
||||
# Due to set -e, we can exit with exitcode 1 on read EOF
|
||||
# and this makes our caller think we failed. "|| return 0" prevents this:
|
||||
IFS=' ' read unused_len prev || return 0
|
||||
|
||||
# For each line after the first...
|
||||
while IFS=' ' read unused_len next; do
|
||||
if [ -z "$pos" ]; then
|
||||
# 2nd line: after "modalias(" prefix, for each char in prev line...
|
||||
n=9
|
||||
end=${#prev}
|
||||
# TODO speedup? if [ $end != ${#next} ]; then line is not mergeable
|
||||
else
|
||||
# 3rd+ lines: only check the char at the same position
|
||||
n=$pos
|
||||
end=$((pos + 1))
|
||||
fi
|
||||
# Search for aaaNbbb,aaaMbbb line pair, where N and M chars differ.
|
||||
# sort -u guarantees there are no identical line pairs.
|
||||
# We assume that lines will not differ only in " = version" suffix.
|
||||
for ((; n < $end; n++)); do
|
||||
if [ "${prev:0:n}" != "${next:0:n}" ]; then
|
||||
# the prefixes already aren't the same: break
|
||||
n=$end
|
||||
break
|
||||
fi
|
||||
# If suffixes differ, go to next char
|
||||
[ x"${prev:n+1}" != x"${next:n+1}" ] && continue
|
||||
# Found aaaNbbb,aaaMbbb. If N and M aren't special...
|
||||
xc=x"${prev:n:1}"
|
||||
[ x"[" = "$xc" -o x"]" = "$xc" ] && continue
|
||||
[ x"?" = "$xc" -o x"*" = "$xc" ] && continue
|
||||
xc=x"${next:n:1}"
|
||||
[ x"[" = "$xc" -o x"]" = "$xc" ] && continue
|
||||
[ x"?" = "$xc" -o x"*" = "$xc" ] && continue
|
||||
# Add M (and maybe N) to $variants, go to next line
|
||||
variants="${variants:-${prev:n:1}}${next:n:1}"
|
||||
pos=$n
|
||||
break
|
||||
done
|
||||
if [ $n -eq $end ]; then
|
||||
# This line is not mergeable with the previous one(s),
|
||||
# print collected merged line and reset the state
|
||||
print_modaliases "$prev" "$variants" "$pos"
|
||||
variants=""
|
||||
pos=""
|
||||
prev=$next
|
||||
fi
|
||||
done
|
||||
# Print last collected merged line
|
||||
print_modaliases "$prev" "$variants" "$pos"
|
||||
}
|
||||
|
||||
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
|
||||
modver=$(/sbin/modinfo -F version "$module")
|
||||
# delete possible extra lines because some modules have *two* version tags. *cough*b44*cough*
|
||||
modver=${modver%%$'\n'*} # using $'' bashism, avoid running "head -n1" process
|
||||
# replace any strange chars with underscores.
|
||||
# [!...] is glob's "match any char not in set" pattern
|
||||
# (although bash supports [^...] too, it is not standard)
|
||||
modver=${modver//[!0-9a-zA-Z._]/_}
|
||||
# only add version tag if it indeed has a version
|
||||
[ -z "$modver" ] || modver=" = $modver"
|
||||
|
||||
/sbin/modinfo -F alias "$module" \
|
||||
| sed -E "s,[^][0-9a-zA-Z._:*?/-],_,g; s,(.+),modalias(\\1)$modver,"
|
||||
|
||||
# Below: combining code can only possibly combine lines of equal length.
|
||||
# Prepend line lengths before sort, so that same-length lines end up next
|
||||
# to each other. (The lengths are discarded by combine_modaliases).
|
||||
done \
|
||||
| { while read line; do echo "${#line} $line"; done } \
|
||||
| LC_ALL=C sort -u \
|
||||
| combine_modaliases
|
@ -0,0 +1,2 @@
|
||||
%__provided_ksyms_provides /usr/lib/rpm/redhat/find-provides.ksyms
|
||||
%__provided_ksyms_path .*\.(ko|ko\.gz|ko\.bz2|ko\.xz|ko\.zst)$
|
@ -0,0 +1,4 @@
|
||||
%__required_ksyms_requires /usr/lib/rpm/redhat/find-requires.ksyms
|
||||
%__required_ksyms_path .*\.(ko|ko\.gz|ko\.bz2|ko\.xz|ko\.zst)$
|
||||
# Exclude built-in kernel modules
|
||||
%__required_ksyms_exclude_path ^/lib/modules/[1-9][^/]*/kernel/.*
|
@ -0,0 +1,76 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
use Getopt::Long qw(:config gnu_getopt);
|
||||
|
||||
sub rpm_cmp_versions {
|
||||
my ($evr1, $evr2) = @_;
|
||||
|
||||
sub _rpm_cmp {
|
||||
my ($s1, $s2) = @_;
|
||||
|
||||
return defined $s1 <=> defined $s2
|
||||
unless defined $s1 && defined $s2;
|
||||
|
||||
my ($r, $x1, $x2);
|
||||
do {
|
||||
$s1 =~ s/^[^a-zA-Z0-9]+//;
|
||||
$s2 =~ s/^[^a-zA-Z0-9]+//;
|
||||
if ($s1 =~ /^\d/ || $s2 =~ /^\d/) {
|
||||
$s1 =~ s/^0*(\d*)//; $x1 = $1;
|
||||
$s2 =~ s/^0*(\d*)//; $x2 = $1;
|
||||
$r = length $x1 <=> length $x2 || $x1 cmp $x2;
|
||||
} else {
|
||||
$s1 =~ s/^([a-zA-Z]*)//; $x1 = $1;
|
||||
$s2 =~ s/^([a-zA-Z]*)//; $x2 = $1;
|
||||
return 0
|
||||
if $x1 eq '' && $x2 eq '';
|
||||
$r = $x1 cmp $x2;
|
||||
}
|
||||
} until $r;
|
||||
return $r;
|
||||
}
|
||||
|
||||
my ($e1, $v1, $r1) = $evr1 =~ /^(?:(\d*):)?(.*?)(?:-([^-]*))?$/;
|
||||
my ($e2, $v2, $r2) = $evr2 =~ /^(?:(\d*):)?(.*?)(?:-([^-]*))?$/;
|
||||
my $r = _rpm_cmp($e1 || 0, $e2 || 0);
|
||||
$r = _rpm_cmp($v1, $v2)
|
||||
unless $r;
|
||||
$r = _rpm_cmp($r1, $r2)
|
||||
unless $r;
|
||||
return $r;
|
||||
}
|
||||
|
||||
my $reorder = sub { return @_ };
|
||||
my $key = 0;
|
||||
|
||||
GetOptions ("r|reverse" => sub { $reorder = sub { return reverse @_ } },
|
||||
"k|key=i" => \$key)
|
||||
or do {
|
||||
print STDERR "Usage\n";
|
||||
exit 1;
|
||||
};
|
||||
|
||||
if ($key == 0) {
|
||||
# Sort by entire lines
|
||||
map { print } &$reorder(sort { rpm_cmp_versions($a, $b) } <>);
|
||||
} else {
|
||||
# Sort by field $key
|
||||
my @data = map { [(split)[$key-1], $_] } <>;
|
||||
map { print } &$reorder(map { $_->[1] }
|
||||
sort { rpm_cmp_versions($a->[0], $b->[0]) } @data);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Create a table of all symbol sets defined in all /boot/symsets*.tar.gz
|
||||
# files.
|
||||
#
|
||||
# Format:
|
||||
# kernelrelease/modver/symbol <tab> symset <tab> symset_hash
|
||||
#
|
||||
# This table is needed for computing the appropriate Requires: tags for
|
||||
# kernel module packages.
|
||||
|
||||
tmpdir=$(mktemp -t -d ${0##*/}.XXXXXX)
|
||||
trap "cd / ; rm -rf $tmpdir" EXIT
|
||||
cd $tmpdir
|
||||
|
||||
shopt -s nullglob
|
||||
for symsets in /boot/symsets-*.tar.gz; do
|
||||
zcat $symsets \
|
||||
| tar xf -
|
||||
done
|
||||
|
||||
for symsets in /usr/src/kernels/*/symsets-*.tar.gz; do
|
||||
zcat $symsets \
|
||||
| tar xf -
|
||||
done
|
||||
|
||||
for symsets in *; do
|
||||
krel=${symsets#symsets-}
|
||||
for symset in $symsets/*; do
|
||||
class=${symset##*/} ; class=${class%.*}
|
||||
hash=${symset##*.}
|
||||
awk '
|
||||
BEGIN { FS = "\t" ; OFS = "\t" }
|
||||
{ sub(/0x0*/, "", $1)
|
||||
print krel "/" $1 "/" $2, class, hash }
|
||||
' krel="$krel" class="$class" hash="$hash" $symset
|
||||
done
|
||||
done
|
||||
|
||||
# vim:shiftwidth=4 softtabstop=4
|
@ -0,0 +1,223 @@
|
||||
Name: kernel-srpm-macros
|
||||
Version: 1.0
|
||||
# when bumping version and resetting release, don't forget to bump version of kernel-rpm-macros as well
|
||||
Release: 24%{?dist}
|
||||
Summary: RPM macros that list arches the full kernel is built on
|
||||
# This package only exist in Fedora repositories
|
||||
# The license is the standard (MIT) specified in
|
||||
# Fedora Project Contribution Agreement
|
||||
# and as URL we provide dist-git URL
|
||||
License: MIT
|
||||
URL: https://src.fedoraproject.org/rpms/kernel-srpm-macros
|
||||
BuildArch: noarch
|
||||
# We are now the ones shipping kmod.attr
|
||||
Conflicts: redhat-rpm-config < 205
|
||||
# macros.kmp, kmodtool and rpmsort were moved from kernel-rpm-macros
|
||||
# to kernel-srpm-macros in 1.0-9/185-9
|
||||
Conflicts: kernel-rpm-macros < 205
|
||||
|
||||
# Macros
|
||||
Source0: macros.kernel-srpm
|
||||
Source1: macros.kmp
|
||||
|
||||
# Dependency generator scripts
|
||||
Source100: find-provides.ksyms
|
||||
Source101: find-requires.ksyms
|
||||
Source102: firmware.prov
|
||||
Source103: modalias.prov
|
||||
Source104: provided_ksyms.attr
|
||||
Source105: required_ksyms.attr
|
||||
Source106: modalias.attr
|
||||
|
||||
# Dependency generators & their rules
|
||||
Source200: kmod.attr
|
||||
|
||||
# Misc helper scripts
|
||||
Source300: kmodtool
|
||||
Source301: rpmsort
|
||||
Source302: symset-table
|
||||
|
||||
# kabi provides generator
|
||||
Source400: kabi.attr
|
||||
Source401: kabi.sh
|
||||
|
||||
# BRPs
|
||||
Source500: brp-kmod-set-exec-bit
|
||||
Source501: brp-kmod-restore-perms
|
||||
|
||||
%global rrcdir /usr/lib/rpm/redhat
|
||||
|
||||
|
||||
%description
|
||||
This packages contains the rpm macro that list what arches
|
||||
the full kernel is built on.
|
||||
The variable to use is kernel_arches.
|
||||
|
||||
%package -n kernel-rpm-macros
|
||||
Version: 205
|
||||
Summary: Macros and scripts for building kernel module packages
|
||||
# rpmsort is GPL-2.0-or-later
|
||||
License: MIT AND GPL-2.0-or-later
|
||||
Requires: redhat-rpm-config >= 205
|
||||
|
||||
# for brp-kmod-compress
|
||||
Requires: %{_bindir}/xz
|
||||
# for brp-kmod-compress, brp-kmod-set-exec-bit
|
||||
Requires: %{_bindir}/find
|
||||
# for find-provides.ksyms, find-requires.ksyms, kmodtool
|
||||
Requires: %{_bindir}/sed
|
||||
# for find-provides.ksyms, find-requires.ksyms
|
||||
Requires: %{_bindir}/awk
|
||||
Requires: %{_bindir}/grep
|
||||
Requires: %{_bindir}/nm
|
||||
Requires: %{_bindir}/objdump
|
||||
Requires: %{_bindir}/readelf
|
||||
# for find-requires.ksyms
|
||||
Requires: %{_sbindir}/modinfo
|
||||
Requires: %{_sbindir}/modprobe
|
||||
|
||||
%description -n kernel-rpm-macros
|
||||
Macros and scripts for building kernel module packages.
|
||||
|
||||
%prep
|
||||
# Not strictly necessary but allows working on file names instead
|
||||
# of source numbers in install section
|
||||
%setup -c -T
|
||||
cp -p %{sources} .
|
||||
|
||||
|
||||
%build
|
||||
# nothing to do
|
||||
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}/%{_rpmconfigdir}/macros.d
|
||||
install -p -m 0644 -t %{buildroot}/%{_rpmconfigdir}/macros.d macros.kernel-srpm
|
||||
%if 0%{?rhel} >= 8
|
||||
sed -i 's/^%%kernel_arches.*/%%kernel_arches x86_64 s390x ppc64le aarch64/' \
|
||||
%{buildroot}/%{_rpmconfigdir}/macros.d/macros.kernel-srpm
|
||||
%endif
|
||||
|
||||
mkdir -p %{buildroot}%{rrcdir}/find-provides.d
|
||||
mkdir -p %{buildroot}%{_fileattrsdir}
|
||||
install -p -m 755 -t %{buildroot}%{rrcdir} kmodtool rpmsort symset-table
|
||||
install -p -m 755 -t %{buildroot}%{rrcdir} find-provides.ksyms find-requires.ksyms
|
||||
install -p -m 755 -t %{buildroot}%{rrcdir}/find-provides.d firmware.prov modalias.prov
|
||||
install -p -m 755 -t %{buildroot}%{rrcdir} brp-kmod-restore-perms brp-kmod-set-exec-bit
|
||||
install -p -m 644 -t %{buildroot}%{_rpmconfigdir}/macros.d macros.kmp
|
||||
install -p -m 644 -t %{buildroot}%{_fileattrsdir} kmod.attr
|
||||
|
||||
install -p -m 644 -t "%{buildroot}%{_fileattrsdir}" kabi.attr
|
||||
install -p -m 755 -t "%{buildroot}%{_rpmconfigdir}" kabi.sh
|
||||
|
||||
install -p -m 644 -t "%{buildroot}%{_fileattrsdir}" provided_ksyms.attr required_ksyms.attr
|
||||
install -p -m 644 -t "%{buildroot}%{_fileattrsdir}" modalias.attr
|
||||
|
||||
%files
|
||||
%{_rpmconfigdir}/macros.d/macros.kernel-srpm
|
||||
%{_fileattrsdir}/kmod.attr
|
||||
|
||||
%files -n kernel-rpm-macros
|
||||
%{_rpmconfigdir}/macros.d/macros.kmp
|
||||
%{_rpmconfigdir}/kabi.sh
|
||||
%{_fileattrsdir}/kabi.attr
|
||||
%{_fileattrsdir}/modalias.attr
|
||||
%{_fileattrsdir}/provided_ksyms.attr
|
||||
%{_fileattrsdir}/required_ksyms.attr
|
||||
%dir %{rrcdir}/find-provides.d
|
||||
%{rrcdir}/brp-kmod-restore-perms
|
||||
%{rrcdir}/brp-kmod-set-exec-bit
|
||||
%{rrcdir}/symset-table
|
||||
%{rrcdir}/find-provides.ksyms
|
||||
%{rrcdir}/find-requires.ksyms
|
||||
%{rrcdir}/find-provides.d/firmware.prov
|
||||
%{rrcdir}/find-provides.d/modalias.prov
|
||||
%{rrcdir}/kmodtool
|
||||
%{rrcdir}/rpmsort
|
||||
|
||||
%changelog
|
||||
* Tue Nov 26 2024 MSVSphere Packaging Team <packager@msvsphere-os.ru> - 1.0-24
|
||||
- Rebuilt for MSVSphere 10
|
||||
|
||||
* Mon Jun 24 2024 Troy Dawson <tdawson@redhat.com> - 1.0-24
|
||||
- Bump release for June 2024 mass rebuild
|
||||
|
||||
* Wed Mar 06 2024 David Abdurachmanov <davidlt@rivosinc.com> - 1.0-23
|
||||
- Add riscv64
|
||||
|
||||
* Wed Jan 24 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-22
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
|
||||
|
||||
* Sun Jan 21 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-21
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
|
||||
|
||||
* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-20
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
|
||||
|
||||
* Tue May 09 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-19
|
||||
- Capture local __crc_* symbols for "Provides: kernel()".
|
||||
- Add support for XZ compression for the symvers file.
|
||||
- Fix "Provides: kernel()" generation when both __kcrctab and __kcrctab_gpl
|
||||
are present.
|
||||
- Fix regression for "Provides:" generation in cases when modversions are stored
|
||||
in a section that is over 64K in size.
|
||||
- Speedup and cleanup changes in find-provides.ksyms and find-requires.ksyms.
|
||||
- Fix regex usage in kmod.attr. (Denys Vlasenko)
|
||||
- Implement modalias "Provides:" grouping. (Denys Vlasenko)
|
||||
- Speedup and cleanup changes in modalias.prov and kmod.attr. (Denys Vlasenko)
|
||||
|
||||
* Tue Mar 30 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-18
|
||||
- Avoid triggering debuginfod during elfutils tools usage.
|
||||
|
||||
* Tue Jan 31 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-17
|
||||
- Support storing of __crc_* symbols in sections other than .rodata.
|
||||
- Work around a change in type of __crc_* symbols for some kmods printed by nm
|
||||
on ppc64le and s390x.
|
||||
|
||||
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-16
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
|
||||
|
||||
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-15
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
|
||||
|
||||
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-14
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
|
||||
|
||||
* Thu Nov 18 2021 Miro Hrončok <mhroncok@redhat.com> - 1.0-13
|
||||
- Bump kernel-rpm-macros to 205 to provide clear upgrade path
|
||||
|
||||
* Thu Nov 18 2021 Miro Hrončok <mhroncok@redhat.com> - 1.0-12
|
||||
- Correct conflicts to redhat-rpm-macros < 205
|
||||
- Move Perl scripts back to kernel-rpm-macros to avoid Perl in the default buildroot
|
||||
|
||||
* Thu Nov 18 2021 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-11
|
||||
- Add conflicts of redhat-rpm-macros < 204 as macros.kmp, kmodtool,
|
||||
and rpmsort were moved from the latter to the former.
|
||||
- Remove RHEL-specific kABI bits from find-requires.ksyms and macros.kmp.
|
||||
|
||||
* Thu Nov 18 2021 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-10
|
||||
- Add conflicts of kernel-srpm-macros with kernel-rpm-macros < 185-9
|
||||
as macros.kmp, kmodtool, and rpmsort were moved from the latter
|
||||
to the former.
|
||||
|
||||
* Thu Nov 18 2021 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-9
|
||||
- Update scripts with RHEL-specific changes.
|
||||
|
||||
* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-6
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
|
||||
|
||||
* Thu Jun 03 2021 Michal Domonkos <mdomonko@redhat.com> - 1.0-5
|
||||
- Adopt kernel-rpm-macros & kmod.attr subpackage from redhat-rpm-config
|
||||
|
||||
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-4
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
|
||||
|
||||
* Tue Aug 04 2020 Merlin Mathesius <mmathesi@redhat.com> - 1.0-3
|
||||
- Escape percent for %%kernel_arches macro
|
||||
|
||||
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-2
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
|
||||
|
||||
* Tue Jul 21 2020 Troy Dawson <tdawson@redhat.com> - 1.0-1
|
||||
- Initial build
|
||||
|
Loading…
Reference in new issue