Skip to content

Commit

Permalink
refactor: DKMS RPM
Browse files Browse the repository at this point in the history
Merge pull request #125 from jerzyjamroz/dkms-rpm
  • Loading branch information
jerzyjamroz authored Jan 31, 2024
2 parents 3b1cbe8 + 80a900d commit 4382d06
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 134 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/linux-build-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Linux latest kernel module test

on:
workflow_dispatch:

jobs:
specific:
name: With ${{ matrix.version }}
runs-on: ${{ matrix.os }}
env:
KSER: ${{ matrix.series }}
KVER: ${{ matrix.version }}
CC: ${{ matrix.cc }}
strategy:
fail-fast: false
matrix:
include:
- name: Ubuntu Latest - Series Latest
os: ubuntu-latest
series: latest
version: latest

steps:
- uses: actions/checkout@v2
- name: Info
run: |
gcc --version
- name: Deps
run: |
sudo apt-get update
# linux-headers-* only to pull in kbuild deps
sudo apt-get -y install linux-headers-`uname -r` kmod libelf-dev
[ "${{ matrix.cc }}" != "gcc-4.8" ] || sudo apt-get -y install gcc-4.8
- name: Setup Linux
run: |
install -d kernel
if [ "$KSER" == "latest" ]; then
KSER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/ | grep -o 'v[0-9]\+\.[0-9a-zA-Z]\+/' | sed 's/\/\s*//' | sort -t. -k2,2V -k3,3V -k4,4V | tail -n 1 | sed 's/v//')
fi
if [ "$KVER" == "latest" ]; then
KVER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/ | grep -o 'linux-[0-9]\+\.[0-9]\+\.[0-9]\+\.tar\.xz' | sort -t- -k2,2n -k3,3n -k4,4n | tail -n 1 | sed 's/linux-\(.*\)\.tar\.xz/\1/')
fi
echo "https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz"
curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz | tar -C kernel --strip-components=1 -xJ
make -C kernel CC=${CC:=gcc} defconfig
make -C kernel CC=${CC:=gcc} modules_prepare
- name: Build
run: |
make -C mrmShared/linux CC=${CC:=gcc} KERNELDIR="$PWD/kernel"
100 changes: 49 additions & 51 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Linux kernel module
on:
push:
paths:
- 'mrmShared/linux/**'
- "mrmShared/linux/**"
pull_request:
paths:
- 'mrmShared/linux/**'
- "mrmShared/linux/**"
workflow_dispatch:

jobs:
Expand All @@ -21,64 +21,62 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
- name: Ubuntu 20.04 - Series 4.x
os: ubuntu-20.04
series: 4.x
version: 4.9.1

- os: ubuntu-20.04
- name: Ubuntu 20.04 - Series 5.x
os: ubuntu-20.04
series: 5.x
version: 5.9.6

- os: ubuntu-latest
series: latest
version: latest

steps:
- uses: actions/checkout@v2
- name: Info
run: |
gcc --version
- name: Deps
run: |
sudo apt-get update
# linux-headers-* only to pull in kbuild deps
sudo apt-get -y install linux-headers-`uname -r` kmod libelf-dev
[ "${{ matrix.cc }}" != "gcc-4.8" ] || sudo apt-get -y install gcc-4.8
- name: Setup Linux
run: |
install -d kernel
if [ "$KSER" == "latest" ]; then
KSER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/ | grep -o 'v[0-9]\+\.[0-9a-zA-Z]\+/' | sed 's/\/\s*//' | sort -t. -k2,2V -k3,3V -k4,4V | tail -n 1 | sed 's/v//')
fi
if [ "$KVER" == "latest" ]; then
KVER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/ | grep -o 'linux-[0-9]\+\.[0-9]\+\.[0-9]\+\.tar\.xz' | sort -t- -k2,2n -k3,3n -k4,4n | tail -n 1 | sed 's/linux-\(.*\)\.tar\.xz/\1/')
fi
echo "https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz"
curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz | tar -C kernel --strip-components=1 -xJ
make -C kernel CC=${CC:=gcc} defconfig
make -C kernel CC=${CC:=gcc} modules_prepare
- name: Build
run: |
make -C mrmShared/linux CC=${CC:=gcc} KERNELDIR="$PWD/kernel"
- uses: actions/checkout@v2
- name: Info
run: |
gcc --version
- name: Deps
run: |
sudo apt-get update
# linux-headers-* only to pull in kbuild deps
sudo apt-get -y install linux-headers-`uname -r` kmod libelf-dev
[ "${{ matrix.cc }}" != "gcc-4.8" ] || sudo apt-get -y install gcc-4.8
- name: Setup Linux
run: |
install -d kernel
if [ "$KSER" == "latest" ]; then
KSER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/ | grep -o 'v[0-9]\+\.[0-9a-zA-Z]\+/' | sed 's/\/\s*//' | sort -t. -k2,2V -k3,3V -k4,4V | tail -n 1 | sed 's/v//')
fi
if [ "$KVER" == "latest" ]; then
KVER=$(curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/ | grep -o 'linux-[0-9]\+\.[0-9]\+\.[0-9]\+\.tar\.xz' | sort -t- -k2,2n -k3,3n -k4,4n | tail -n 1 | sed 's/linux-\(.*\)\.tar\.xz/\1/')
fi
echo "https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz"
curl -s https://cdn.kernel.org/pub/linux/kernel/v$KSER/linux-$KVER.tar.xz | tar -C kernel --strip-components=1 -xJ
make -C kernel CC=${CC:=gcc} defconfig
make -C kernel CC=${CC:=gcc} modules_prepare
- name: Build
run: |
make -C mrmShared/linux CC=${CC:=gcc} KERNELDIR="$PWD/kernel"
host:
name: With VM host
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Info
run: |
uname -a
gcc --version
- name: Deps
run: |
sudo apt-get update
sudo apt-get -y install linux-headers-`uname -r`
- name: Build
run: make -C mrmShared/linux
- name: Install/Load
run: |
sudo make -C mrmShared/linux modules_install
sudo depmod -a
sudo modprobe mrf
sudo dmesg | tail -n 100
- uses: actions/checkout@v2
- name: Info
run: |
uname -a
gcc --version
- name: Deps
run: |
sudo apt-get update
sudo apt-get -y install linux-headers-`uname -r`
- name: Build
run: make -C mrmShared/linux
- name: Install/Load
run: |
sudo make -C mrmShared/linux modules_install
sudo depmod -a
sudo modprobe mrf
sudo dmesg | tail -n 100
8 changes: 8 additions & 0 deletions mrmShared/linux/CONFIG
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Version definition for driver
# 20240124 Release
DRV_VERSION := 3

# Package control vars
PKG_NAME := mrfioc2-dkms
DRV_NAME := mrf
DRV_GROUP := mrf
2 changes: 1 addition & 1 deletion mrmShared/linux/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
KERNELDIR ?= /lib/modules/$(shell uname -r)/build

include VERSION
include CONFIG

all: modules

Expand Down
8 changes: 3 additions & 5 deletions mrmShared/linux/README → mrmShared/linux/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

== cross compiling ==
# Cross compiling

make ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- KERNELDIR=/path/to/headers


== udev ==
# udev

udev rules to automatically set permissions for approprieate /dev/uio*

Expand All @@ -15,8 +14,7 @@ cat << EOF > /etc/udev/rules.d/99-mrfioc2.rules
KERNEL=="uio*", ATTR{name}=="mrf-pci", GROUP="softioc", MODE="0660"
EOF


== dkms ==
# dkms-rpm

To create an installable dksm package for this kernel module do the following:

Expand Down
3 changes: 0 additions & 3 deletions mrmShared/linux/VERSION

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions mrmShared/linux/dkms-rpm/50-mrf.rules.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# UDEV rule giving access to MRF device
KERNEL=="uio*", ATTR{name}=="mrf-pci", GROUP="@@DRV_GROUP@@", MODE="0660", RUN+="/bin/chmod g+rw %S%p/resource0 && /bin/logger UDEV rule giving access to MRF device %S%p"
3 changes: 3 additions & 0 deletions mrmShared/linux/dkms-rpm/CONFIG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

RPM_RELEASE := 1
# NOTE: Not necessary DIST ?= el7
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

SRCDIR = $(CURDIR)/..

DRV_NAME = mrf
include $(SRCDIR)/VERSION
include $(SRCDIR)/CONFIG
include CONFIG

# Determine the architecture of the machine
ARCH := $(shell uname -m)

# The RPM_VERSION string takes the dotted version name (without extra version
# info) and follows the Red Hat versioning rules: only letters, digits, and
Expand All @@ -14,8 +15,7 @@ include CONFIG
# for information on RPM versioning. We'll want to obey these rules if we can.
RPM_VERSION = $(DRV_VERSION)


RPM_FILE = $(DRV_NAME)-$(RPM_VERSION)-1dkms.noarch.rpm
RPM_FILE = $(PKG_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).$(ARCH).rpm

driver-rpm: $(RPM_FILE)
.PHONY: driver-rpm
Expand All @@ -30,9 +30,12 @@ SED_SUBSTS =
SED_SUBSTS += s/@@DRV_VERSION@@/$(DRV_VERSION)/g;
SED_SUBSTS += s/@@DRV_NAME@@/$(DRV_NAME)/g;
SED_SUBSTS += s/@@RPM_VERSION@@/$(RPM_VERSION)/g;
SED_SUBSTS += s/@@MRF_USER@@/$(MRF_USER)/g;
SED_SUBSTS += s/@@DRV_GROUP@@/$(DRV_GROUP)/g;
SED_SUBSTS += s/@@RPM_RELEASE@@/$(RPM_RELEASE)/g;
SED_SUBSTS += s/@@ARCH@@/$(ARCH)/g;
SED_SUBSTS += s/@@PKG_NAME@@/$(PKG_NAME)/g;

%: %.in CONFIG $(SRCDIR)/VERSION
%: %.in CONFIG $(SRCDIR)/CONFIG
sed '$(SED_SUBSTS)' $< >$@

SED_FILES = dkms.conf $(DRV_NAME).spec 50-mrf.rules
Expand All @@ -46,4 +49,4 @@ $(RPM_FILE): $(SED_FILES) $(wildcard $(SRCDIR)/*)
--define '_sourcedir $(SRCDIR)' \
--define '_tmppath %{_topdir}/BUILD' \
$(DRV_NAME).spec
ln -sf rpmbuild/RPMS/noarch/$(RPM_FILE) .
ln -sf rpmbuild/RPMS/$(ARCH)/$(RPM_FILE) .
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
DESCRIPTION="DKMS mrfioc2 kernel module."
PACKAGE_NAME="@@DRV_NAME@@"
PACKAGE_VERSION="@@RPM_VERSION@@"
BUILT_MODULE_NAME[0]="@@DRV_NAME@@"
DEST_MODULE_LOCATION[0]="/extra"
MAKE[0]="make -j1 KERNEL_DIR=$kernel_source_dir VERSION=@@DRV_VERSION@@"
MAKE[0]="make -j1 KERNEL_DIR=$kernel_source_dir VERSION=@@DRV_VERSION@@ DRV_VERSION=@@DRV_VERSION@@"
AUTOINSTALL=YES
REMAKE_INITRD=NO
86 changes: 86 additions & 0 deletions mrmShared/linux/dkms-rpm/mrf.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
%define kmod_name @@DRV_NAME@@
%define udev_rules_update \
/sbin/udevadm control --reload-rules && \
/sbin/udevadm trigger

Summary: DKMS mrfioc2 kernel module

Name: @@PKG_NAME@@
Version: @@RPM_VERSION@@
Release: @@RPM_RELEASE@@

Vendor: EPICS Community
License: EPICS Open License
Group: System Environment/Kernel
URL: https://github.com/epics-modules/mrfioc2
BuildRequires: autoconf libtool gcc gcc-c++
BuildArch: @@ARCH@@
Requires: dkms
Requires: udev
BuildRoot: %{_tmppath}/%{kmod_name}-%{version}-root

# The two target directories
%define dkmsdir /usr/src/%{kmod_name}-%{version}
%define udevdir /etc/udev/rules.d

%description
Installs the kernel driver for interfacing to the MRF timing cards over
PCI express. The driver is installed using dkms.

%clean
rm -rf %{buildroot}

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{dkmsdir} %{buildroot}%{udevdir}
install -m 0644 %{_sourcedir}/uio_mrf.c %{buildroot}%{dkmsdir}
install -m 0644 %{_sourcedir}/jtag_mrf.c %{buildroot}%{dkmsdir}
install -m 0644 %{_sourcedir}/mrf.h %{buildroot}%{dkmsdir}
install -m 0644 %{_curdir}/Makefile.dkms %{buildroot}%{dkmsdir}/Makefile
install -m 0644 %{_sourcedir}/Kbuild %{buildroot}%{dkmsdir}
install -m 0644 %{_curdir}/dkms.conf %{buildroot}%{dkmsdir}
install -m 0644 %{_curdir}/50-mrf.rules %{buildroot}%{udevdir}

%files
%{dkmsdir}/uio_mrf.c
%{dkmsdir}/jtag_mrf.c
%{dkmsdir}/mrf.h
%{dkmsdir}/Makefile
%{dkmsdir}/Kbuild
%{dkmsdir}/dkms.conf
%{udevdir}/50-mrf.rules

%post
# PRP: groupadd -r @@DRV_GROUP@@ 2>&1 || :
dkms add -m %{kmod_name} -v %{version} --rpm_safe_upgrade
dkms build -m %{kmod_name} -v %{version}
dkms install -m %{kmod_name} -v %{version}
modprobe %{kmod_name}
%udev_rules_update

%preun
modprobe -r %{kmod_name}
dkms remove --all -m %{kmod_name} -v %{version} --rpm_safe_upgrade --all ||:
%udev_rules_update
# PRP: group root groupdel @@DRV_GROUP@@ 2>&1 || :

%postun
rmdir /usr/src/%{kmod_name}-%{version}

%changelog

* Wed Jan 24 2024 Jerzy Jamroz <jerzy.jamroz@gmail.com> - 3-1
- Build adjustments exposing the control variables.
- Pkg name changed to mrfioc2-dkms.
- Correction of the driver version handling.
- Group rw access for the pci resource0.
- AER handling functions.
- Device access group added.
- Tested on CentOS7.

* Mon Jan 22 2024 Jerzy Jamroz <jerzy.jamroz@gmail.com> - 2-1
- Version 2 skipped due to usage as version 1.
- Tested on CentOS7.

* Mon Dec 14 2020 Michael Abbott <michael.abbott@diamond.ac.uk> - 1-1
- Initial release.
2 changes: 0 additions & 2 deletions mrmShared/linux/dkms/50-mrf.rules.in

This file was deleted.

3 changes: 0 additions & 3 deletions mrmShared/linux/dkms/CONFIG

This file was deleted.

Loading

0 comments on commit 4382d06

Please sign in to comment.