Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit 5a4be8c

Browse files
authored
Merge pull request #8 from jeonghanlee/master
add the dkms support in the mrf kernel module
2 parents fde3892 + c9cf574 commit 5a4be8c

File tree

11 files changed

+207
-40
lines changed

11 files changed

+207
-40
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
21
# Kernel Module Compile Results
32
*.mod*
43
.tmp_versions/
54
modules.order
65
Module.symvers
76
Mkfile.old
8-
dkms.conf
97
*~
108
core.*
119
#*
1210
.#*
1311
\#*
14-
1512
mrfioc2-debug
1613
mrfioc2-dev
14+
dkms/dkms.conf
15+
dkms/dkms_with_msi.conf

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# e3-mrfioc2
22

33

4-
## Kernel modules compiliation and installation
4+
## Kernel module (mrf.ko) can be installed via DKMS
55

66

77
```sh
8-
$ make modules
9-
$ make modules_install
8+
$ make dkms_add
9+
$ make dkms_build
10+
$ make dkms_install
1011
```
1112

12-
In order to remove the mrf.ko from the system.
13+
In order to remove them
1314

1415
```sh
15-
$ make modules_uninstall
16+
$ make dkms_uninstall
17+
$ make dkms_remove
1618
```
1719

1820
## Kernel modules configuration
@@ -30,3 +32,19 @@ In order to clean the configuration,
3032
```sh
3133
$ make setup_clean
3234
```
35+
36+
## Notice
37+
If one has already the running dkms.service in systemd, the next reboot with new kernl image will make the kernel module be ready. However, if one doesn't have one, please run bash dkms/dkms_setup.bash in order to enable dkms.service.
38+
39+
```
40+
$ bash dkms/dkms_setup.bash
41+
$ systemctl status dkms
42+
● dkms.service - Builds and install new kernel modules through DKMS
43+
Loaded: loaded (/etc/systemd/system/dkms.service; enabled; vendor preset: ena
44+
Active: active (exited) since Sun 2018-07-29 01:13:59 CEST; 4s ago
45+
Docs: man:dkms(8)
46+
Process: 3271 ExecStart=/bin/sh -c dkms autoinstall --verbose --kernelver $(un
47+
Main PID: 3271 (code=exited, status=0/SUCCESS)
48+
49+
50+
```

configure/E3/CONFIG_EXPORT

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Variables should be transferred to module_name.makefile
22

33
EPICS_HOST_ARCH:=$(shell $(EPICS_BASE)/startup/EpicsHostArch.pl)
4+
MSI:=$(EPICS_BASE)/bin/$(EPICS_HOST_ARCH)/msi
45

56
EXPORT_VARS+=EPICS_HOST_ARCH
67
EXPORT_VARS+=EPICS_BASE
8+
EXPORT_VARS+=MSI
79
EXPORT_VARS+=E3_REQUIRE_TOOLS
810
EXPORT_VARS+=E3_MODULE_VERSION
911
EXPORT_VARS+=E3_SITEMODS_PATH

configure/E3/RULES_DKMS

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
SUDO2:=sudo -E bash -c
3+
DKMS:=/usr/sbin/dkms
4+
DKMS_ARGS:=-m $(E3_MODULE_NAME) -v $(E3_MODULE_VERSION)
5+
KMOD_NAME := mrf
6+
7+
.PHONY: dkms_add dkms_build dkms_remove dkms_install dkms_uninstall
8+
9+
dkms_add: conf
10+
$(MSI) -M name="$(E3_MODULE_NAME)" -M version="$(E3_MODULE_VERSION)" -M kmod_name="$(KMOD_NAME)" $(TOP)/dkms/dkms_with_msi.conf.in > $(TOP)/dkms/dkms_with_msi.conf
11+
$(QUIET) cat $(TOP)/dkms/dkms_with_msi.conf $(TOP)/dkms/dkms_without_msi.conf > $(TOP)/dkms/dkms.conf
12+
$(QUIET) install -m 644 $(TOP)/dkms/dkms.conf $(E3_KMOD_SRC_PATH)/
13+
$(SUDO2) 'ln -sf $(TOP)/$(E3_KMOD_SRC_PATH) /usr/src/$(E3_MODULE_NAME)-$(E3_MODULE_VERSION)'
14+
$(SUDO) $(DKMS) add $(DKMS_ARGS)
15+
16+
17+
dkms_build:
18+
$(SUDO) $(DKMS) build $(DKMS_ARGS)
19+
20+
21+
dkms_remove:
22+
$(SUDO) $(DKMS) remove $(E3_MODULE_NAME)/$(E3_MODULE_VERSION) --all
23+
24+
25+
dkms_install:
26+
$(SUDO) $(DKMS) install $(DKMS_ARGS)
27+
$(QUIET)$(SUDO) depmod
28+
29+
dkms_uninstall:
30+
$(SUDO) $(DKMS) uninstall $(DKMS_ARGS)
31+
$(QUIET)$(SUDO) depmod
32+
33+
.PHONY: dkms_add dkms_build dkms_install dkms_remove dkms_uninstall
34+
35+
36+
setup:
37+
$(QUIET) $(SUDO2) 'echo KERNEL==\"uio*\", ATTR{name}==\"mrf-pci\", MODE=\"0666\" | tee /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules'
38+
$(QUIET) $(SUDO) /bin/udevadm control --reload-rules
39+
$(QUIET) $(SUDO) /bin/udevadm trigger
40+
$(QUIET) $(SUDO2) 'echo $(KMOD_NAME) | tee /etc/modules-load.d/$(KMOD_NAME).conf'
41+
$(QUIET) $(SUDO) depmod --quick
42+
$(QUIET) $(SUDO) modprobe -rv $(KMOD_NAME)
43+
$(QUIET) $(SUDO) modprobe -v $(KMOD_NAME)
44+
$(QUIET) -ls /dev/uio* 2>/dev/null
45+
46+
47+
setup_clean:
48+
$(QUIET) $(SUDO) modprobe -rv $(KMOD_NAME)
49+
$(SUDO) rm -f /etc/modules-load.d/$(KMOD_NAME).conf
50+
$(SUDO) rm -f /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules
51+
52+
53+
.PHONY: setup setup_clean
54+
55+
56+
VARS_EXCLUDES+=KMOD_NAME
57+
VARS_EXCLUDES+=DKMS_ARGS
58+
VARS_EXCLUDES+=DKMS
59+
VARS_EXCLUDES+=SUDO2

configure/E3/RULES_KMOD

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,7 @@ modules_clean:
1515
modules_uninstall:
1616
sudo rm -f /lib/modules/$(shell uname -r)/extra/$(KMOD_NAME).ko
1717

18-
setup:
19-
$(QUIET) sudo -E bash -c 'echo KERNEL==\"uio*\", ATTR{name}==\"mrf-pci\", MODE=\"0666\" | tee /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules'
20-
$(QUIET) sudo /bin/udevadm control --reload-rules
21-
$(QUIET) sudo /bin/udevadm trigger
22-
$(QUIET) sudo -E bash -c 'echo $(KMOD_NAME) | tee /etc/modules-load.d/$(KMOD_NAME).conf'
23-
$(QUIET) sudo depmod --quick
24-
$(QUIET) sudo modprobe -rv $(KMOD_NAME)
25-
$(QUIET) sudo modprobe -v $(KMOD_NAME)
26-
$(QUIET) ls -ltar /dev/uio*
27-
28-
setup_clean:
29-
$(QUIET) sudo modprobe -rv $(KMOD_NAME)
30-
# sudo rm -f /lib/modules/$(shell uname -r)/extra/$(KMOD_NAME).ko
31-
sudo rm -f /etc/modules-load.d/$(KMOD_NAME).conf
32-
sudo rm -f /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules
33-
34-
35-
.PHONY: modules modules_install modules_uninstall modules_clean setup setup_clean
18+
19+
.PHONY: modules modules_install modules_uninstall modules_clean
3620

3721

configure/RULES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ include $(TOP)/configure/E3/DEFINES_FT
66
include $(TOP)/configure/E3/RULES_E3
77
include $(TOP)/configure/E3/RULES_E3_SITELIBS
88
include $(TOP)/configure/E3/RULES_EPICS
9-
-include $(TOP)/configure/E3/RULES_KMOD
9+
include $(TOP)/configure/E3/RULES_DKMS
10+
#-include $(TOP)/configure/E3/RULES_KMOD
1011

1112
include $(TOP)/configure/E3/RULES_DB
1213
include $(TOP)/configure/E3/RULES_VARS

dkms/dkms.service

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Builds and install new kernel modules through DKMS
3+
Documentation=man:dkms(8)
4+
5+
[Service]
6+
Type=oneshot
7+
RemainAfterExit=true
8+
ExecStart=/bin/sh -c 'dkms autoinstall --verbose --kernelver $(uname -r)'
9+
10+
[Install]
11+
WantedBy=multi-user.target

dkms/dkms_setup.bash

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2018 Jeong Han Lee
4+
#
5+
# The program is free software: you can redistribute
6+
# it and/or modify it under the terms of the GNU General Public License
7+
# as published by the Free Software Foundation, either version 2 of the
8+
# License, or any newer version.
9+
#
10+
# This program is distributed in the hope that it will be useful, but WITHOUT
11+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
# more details.
14+
#
15+
# You should have received a copy of the GNU General Public License along with
16+
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
17+
#
18+
# Author : Jeong Han Lee
19+
# email : jeonghan.lee@gmail.com
20+
# Date : Sunday, July 29 01:06:29 CEST 2018
21+
# version : 0.0.1
22+
23+
24+
declare -gr SC_SCRIPT="$(realpath "$0")"
25+
declare -gr SC_SCRIPTNAME=${0##*/}
26+
declare -gr SC_TOP="${SC_SCRIPT%/*}"
27+
28+
declare -gr SUDO_CMD="sudo";
29+
30+
DKMS_SYSTEMD=dkms.service
31+
SD_UNIT_PATH_DEBIAN=/etc/systemd/system
32+
SD_UNIT_PATH_CENTOS=/usr/lib/systemd/system
33+
34+
35+
function find_dist
36+
{
37+
38+
local dist_id dist_cn dist_rs PRETTY_NAME
39+
40+
if [[ -f /usr/bin/lsb_release ]] ; then
41+
dist_id=$(lsb_release -is)
42+
dist_cn=$(lsb_release -cs)
43+
dist_rs=$(lsb_release -rs)
44+
echo $dist_id ${dist_cn} ${dist_rs}
45+
else
46+
eval $(cat /etc/os-release | grep -E "^(PRETTY_NAME)=")
47+
echo ${PRETTY_NAME}
48+
fi
49+
50+
51+
}
52+
53+
54+
function setup_dkms_systemd
55+
{
56+
printf ">>> Setup the systemd %s in %s\n" "${DKMS_SYSTEMD}" "${SD_UNIT_PATH}"
57+
58+
${SUDO_CMD} install -m 644 ${SC_TOP}/${DKMS_SYSTEMD} ${SD_UNIT_PATH}/
59+
${SUDO_CMD} systemctl daemon-reload;
60+
${SUDO_CMD} systemctl enable ${DKMS_SYSTEMD};
61+
${SUDO_CMD} systemctl start ${DKMS_SYSTEMD};
62+
printf "\n"
63+
64+
}
65+
66+
67+
68+
## Determine CentOS or Debian, because systemd path is different
69+
70+
dist=$(find_dist)
71+
72+
case "$dist" in
73+
*Debian*)
74+
SD_UNIT_PATH=${SD_UNIT_PATH_DEBIAN}
75+
;;
76+
*CentOS*)
77+
SD_UNIT_PATH=${SD_UNIT_PATH_CENTOS}
78+
;;
79+
*)
80+
printf "\n";
81+
printf "Doesn't support the detected $dist\n";
82+
printf "Please contact jeonghan.lee@gmail.com\n";
83+
printf "\n";
84+
exit;
85+
;;
86+
esac
87+
88+
${SUDO_CMD} -v
89+
90+
# Setup Systemd for the DKMS autoinstall
91+
# dkms.sevice will be started before ethercat.service be started.
92+
setup_dkms_systemd
93+

dkms/dkms_with_msi.conf.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PACKAGE_NAME="$(name)"
2+
PACKAGE_VERSION="$(version)"
3+
4+
BUILT_MODULE_NAME[0]="$(kmod_name)"
5+
DEST_MODULE_NAME[0]="$(kmod_name)"

dkms/dkms_without_msi.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
DEST_MODULE_LOCATION[0]="/updates/dkms"
3+
4+
AUTOINSTALL=yes
5+
6+
MAKE[0]="make -C ${kernel_source_dir=${kernel_source}} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
7+
CLEAN="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
8+

0 commit comments

Comments
 (0)