From bec3b638bd312ed2b3e9daa982a3c89ad6276052 Mon Sep 17 00:00:00 2001 From: ebasov Date: Thu, 21 Nov 2024 15:00:46 +0300 Subject: [PATCH] Build for MSVSphere 9 --- .focal-spi-kmod.metadata | 1 + .gitignore | 1 + SOURCES/Makefile | 11 ++++ SOURCES/focal_spi_cs_high.patch | 11 ++++ SPECS/focal-spi-kmod.spec | 89 +++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 .focal-spi-kmod.metadata create mode 100644 .gitignore create mode 100644 SOURCES/Makefile create mode 100644 SOURCES/focal_spi_cs_high.patch create mode 100644 SPECS/focal-spi-kmod.spec diff --git a/.focal-spi-kmod.metadata b/.focal-spi-kmod.metadata new file mode 100644 index 0000000..238debd --- /dev/null +++ b/.focal-spi-kmod.metadata @@ -0,0 +1 @@ +1e30ee778ed5f3733733530917eac3bfd2803fa8 SOURCES/focal_spi_cs_high.zip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9825192 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/focal_spi_cs_high.zip diff --git a/SOURCES/Makefile b/SOURCES/Makefile new file mode 100644 index 0000000..ca93104 --- /dev/null +++ b/SOURCES/Makefile @@ -0,0 +1,11 @@ +# To build as a module, use: +# make -C /usr/src/kernels/x.y.z M=$(pwd) +# To cleanup, use: +# make -C /usr/src/kernels/x.y.z M=$(pwd) clean +# +# Build is expected to work with the following kernels: +# make -C /usr/src/kernels/5.14.0-427.35.1.el9_4.x86_64 M=$(pwd) +# make -C /usr/src/kernels/6.1.104-1.el9.inferit.x86_64 M=$(pwd) +# make -C /usr/src/kernels/6.6.45-1.el9.inferit.x86_64 M=$(pwd) + +obj-m += focal_spi.o diff --git a/SOURCES/focal_spi_cs_high.patch b/SOURCES/focal_spi_cs_high.patch new file mode 100644 index 0000000..efccdd9 --- /dev/null +++ b/SOURCES/focal_spi_cs_high.patch @@ -0,0 +1,11 @@ +--- focal_spi.c.orig 2024-06-28 14:09:39.000000000 +0300 ++++ focal_spi.c 2024-11-07 18:59:57.322296546 +0300 +@@ -489,7 +489,7 @@ + /* Set up SPI*/ + spi->max_speed_hz=4*1000*1000; + spi->bits_per_word = 8; +- spi->mode = SPI_MODE_0|SPI_CS_HIGH; ++ spi->mode = SPI_MODE_0; + error = spi_setup(spi); + if (error) + return error; diff --git a/SPECS/focal-spi-kmod.spec b/SPECS/focal-spi-kmod.spec new file mode 100644 index 0000000..e248dbb --- /dev/null +++ b/SPECS/focal-spi-kmod.spec @@ -0,0 +1,89 @@ +%global buildforkernels current +%global debug_package %{nil} +%global __os_install_post %{nil} + +Name: focal-spi-kmod +Summary: Kernel module (kmod) for FocalTech SPI FPR +Version: 0.1 +Release: 4%{?dist} +License: GPLv2 +URL: https://github.com/ftfpteams/ubuntu_spi +Source0: focal_spi_cs_high.zip +Source1: Makefile +Patch0: focal_spi_cs_high.patch +# get the needed BuildRequires (in parts depending on what we build for) +BuildRequires: %{_bindir}/kmodtool +%{!?kernels:BuildRequires: buildsys-build-msvsphere-kerneldevpkgs-%{?buildforkernels:%{buildforkernels}}%{!?buildforkernels:current}-%{_target_cpu} } +%{?fedora:BuildRequires: unifdef} + +BuildRequires: gcc +BuildRequires: make +BuildRequires: elfutils-libelf-devel + +# kmodtool does its magic here +%{expand:%(kmodtool --target %{_target_cpu} --repo msvsphere --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null) } + +%description +Driver module for FocalTech FPR on SPI bus + +%prep +# error out if there was something wrong with kmodtool +%{?kmodtool_check} +# print kmodtool output for debugging purposes: +kmodtool --target %{_target_cpu} --repo msvsphere --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null + +%setup -q -c +mkdir focal-spi +ls -l +cp focal_spi.c focal-spi + +pushd focal-spi +cp %{SOURCE1} . +%patch0 -p0 -b .fix-segfault +popd +#Copied from kernel sources +pwd +ls + +for kernel_version in %{?kernel_versions} ; do + cp -a focal-spi _kmod_build_${kernel_version%%___*} +done + + +%build +for kernel_version in %{?kernel_versions} ; do +%make_build -C ${kernel_version##*___} \ + M=${PWD}/_kmod_build_${kernel_version%%___*} \ + modules +done + + +%install +for kernel_version in %{?kernel_versions}; do + mkdir -p ${RPM_BUILD_ROOT}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/ + install -D -m 755 -t ${RPM_BUILD_ROOT}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/ $(find _kmod_build_${kernel_version%%___*}/ -name '*.ko') +done + +# Fix for the SB-signing issue caused by a bug in /usr/lib/rpm/brp-strip +# https://bugzilla.redhat.com/show_bug.cgi?id=1967291 +find %{buildroot} -name \*.ko -type f | xargs --no-run-if-empty %{__strip} --strip-debug + +# Sign the modules(s) +%if %{?_with_modsign:1}%{!?_with_modsign:0} +for kernel_version in %{?kernel_versions}; do + # If the module signing keys are not defined, define them here. + %{!?privkey: %define privkey %{_sysconfdir}/pki/kmod/msvsphere_kmod.priv} + %{!?pubkey: %define pubkey %{_sysconfdir}/pki/kmod/msvsphere_kmod.pem} + for module in $(find %{buildroot} -type f -name \*.ko); + do %{_usrsrc}/kernels/${kernel_version%%___*}/scripts/sign-file \ + sha256 %{privkey} %{pubkey} $module; + done +done +%endif + +%{?akmod_install} + + +%changelog +* Thu Nov 21 2024 Eduard Basov - 0.1-4 +- Build for MSVSphere 9