Blob Blame History Raw
%global pkg megaraid_sas

%global driver_version 4.18.0-305.el8

%global kernel_version 4.18.0-305.7.1.el8_4

%global _use_internal_dependency_generator 0
%global __find_requires /usr/lib/rpm/redhat/find-requires
%global __find_provides /usr/lib/rpm/redhat/find-provides

%global debug_package %{nil}

%global __spec_install_post \
  %{?__debug_package:%{__debug_install_post}} \
  %{__arch_install_post} \
  %{__os_install_post} \
  %{__mod_compress_install_post}

%global __mod_compress_install_post find %{buildroot}/lib/modules -type f -name \*.ko -exec xz \{\} \\;


Name:             kmod-%{pkg}
Version:          4.18.0.305
Release:          1%{?dist}
Summary:          Broadcom MegaRAID SAS (%{pkg}) driver

License:          GPLv2
URL:              https://www.kernel.org/

Source0:          %{pkg}-%{driver_version}.tar.xz
Patch1:           0001-add-deprecated-ids.patch

ExclusiveArch:    x86_64 aarch64

BuildRequires:    elfutils-libelf-devel
BuildRequires:    gcc
BuildRequires:    kernel-rpm-macros
BuildRequires:    kmod
BuildRequires:    make
BuildRequires:    redhat-rpm-config
BuildRequires:    xz

BuildRequires:    kernel-abi-stablelists = %{kernel_version}
BuildRequires:    kernel-devel = %{kernel_version}
BuildRequires:    kernel-devel-uname-r = %{kernel_version}.%{_arch}

Requires:         kernel >= %{kernel_version}
Requires:         kernel-uname-r >= %{kernel_version}.%{_arch}
Requires:         kernel-modules >= %{kernel_version}
Requires:         kernel-modules-uname-r >= %{kernel_version}.%{_arch}

Provides:         installonlypkg(kernel-module)
Provides:         kernel-modules >= %{kernel_version}.%{_arch}

Requires(post):   %{_sbindir}/depmod
Requires(postun): %{_sbindir}/depmod

Requires(post):   %{_sbindir}/weak-modules
Requires(postun): %{_sbindir}/weak-modules


%description
This package provides the Broadcom MegaRAID SAS (%{pkg}) driver. Compared to
the in-kernel driver this driver re-enables support for deprecated adapters:

- 0x1000:0x0060: LSI MegaRAID SAS1078R
- 0x1000:0x0078: LSI MegaRAID SAS1078 Gen2
- 0x1000:0x007C: LSI MegaRAID SAS1078DE
- 0x1000:0x0411: LSI MegaRAID SAS1064R
- 0x1000:0x0413: LSI MegaRAID SAS1068 Verde ZCR
- 0x1028:0x0015: Dell PERC5

The removal of the following adapters has been reverted in 4.18.0-290 [1761485]:
- 0x1000:0x0071: LSI MegaRAID SAS0071 Skinny
- 0x1000:0x0073: LSI MegaRAID SAS0073 Skinny
- 0x1000:0x0079: LSI MegaRAID SAS0079 Gen2


%prep
%autosetup -p1 -n %{pkg}-%{driver_version}


%build
pushd src
%{__make} -C /usr/src/kernels/%{kernel_version}.%{_arch} %{?_smp_mflags} M=$PWD modules
popd


%install
%{__install} -D -t %{buildroot}/lib/modules/%{kernel_version}.%{_arch}/extra/drivers/scsi/megaraid src/%{pkg}.ko

# Make .ko objects temporarily executable for automatic stripping
find %{buildroot}/lib/modules -type f -name \*.ko -exec chmod u+x \{\} \+

# Generate depmod.conf
%{__install} -d %{buildroot}/%{_sysconfdir}/depmod.d/
for kmod in $(find %{buildroot}/lib/modules/%{kernel_version}.%{_arch}/extra -type f -name \*.ko -printf "%%P\n" | sort)
do
    echo "override $(basename $kmod .ko) * weak-updates/$(dirname $kmod)" >> %{buildroot}/%{_sysconfdir}/depmod.d/%{pkg}.conf
done


%clean
%{__rm} -rf %{buildroot}


%post
mkdir -p %{_localstatedir}/lib/rpm-state/sig-kmods
printf '%s\n' "/lib/modules/%{kernel_version}.%{_arch}/extra/drivers/scsi/megaraid/%{pkg}.ko.xz" >> %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-add


%preun
mkdir -p %{_localstatedir}/lib/rpm-state/sig-kmods
rpm -ql kmod-%{pkg}-%{?epoch:%{epoch}:}%{version}-%{release}.%{_arch} | grep '/lib/modules/%{kernel_version}.%{_arch}/.*\.ko\.xz$' >> %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-remove


%postun
if [ -f %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-remove ]
then
    modules=( $(cat %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-remove) )
    rm -f %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-remove
    rmdir --ignore-fail-on-non-empty %{_localstatedir}/lib/rpm-state/sig-kmods
    printf '%s\n' "${modules[@]}" | %{_sbindir}/weak-modules --remove-modules
fi


%pretrans -p <lua>
posix.unlink("%{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-add")
posix.unlink("%{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-remove")


%posttrans
if [ -f %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-add ]
then
    modules=( $(cat %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-add) )
    rm -f %{_localstatedir}/lib/rpm-state/sig-kmods/weak-modules-add
    rmdir --ignore-fail-on-non-empty %{_localstatedir}/lib/rpm-state/sig-kmods
    printf '%s\n' "${modules[@]}" | %{_sbindir}/weak-modules --add-modules
fi


%files
%defattr(644,root,root,755)
/lib/modules/%{kernel_version}.%{_arch}
%license COPYING
%config(noreplace) %{_sysconfdir}/depmod.d/%{pkg}.conf


%changelog
* Thu Oct 28 2021 Peter Georg <peter.georg@physik.uni-regensburg.de> - 4.18.0.305-1
- Convert to kABI tracking kmod package (kernel >= 4.18.0-305.7.1.el8)
- Build 4.18.0-305.el8 for 4.18.0-305.7.1.el8_4
- Use release number independent of kernel
- Add driver release number to version

* Wed Sep 15 2021 Peter Georg <peter.georg@physik.uni-regensburg.de> - 4.18.0-305.19.1
- Rebuild for 4.18.0-305.19.1.el8_4

* Thu Sep  9 2021 Peter Georg <peter.georg@physik.uni-regensburg.de> - 4.18.0-305.17.1
- Set specific kernel version to use
- Rename kernel_version_min to driver_version
- Add Provides kernel-modules
- Add .%{_arch} to kernel-modules provides version
- Rebuild for 4.18.0-305.17.1.el8_4

* Wed Aug 11 2021 Peter Georg <peter.georg@physik.uni-regensburg.de> - 4.18.0-305.12.1
- Rebuild for 4.18.0-305.12.1.el8_4

* Wed Aug 11 2021 Peter Georg <peter.georg@physik.uni-regensburg.de> - 4.18.0-305
- Initial version