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

Commit

Permalink
Merge pull request #8 from jeonghanlee/master
Browse files Browse the repository at this point in the history
add the dkms support in the mrf kernel module
  • Loading branch information
jeonghanlee authored Jul 31, 2018
2 parents fde3892 + c9cf574 commit 5a4be8c
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 40 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

# Kernel Module Compile Results
*.mod*
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
*~
core.*
#*
.#*
\#*

mrfioc2-debug
mrfioc2-dev
dkms/dkms.conf
dkms/dkms_with_msi.conf
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# e3-mrfioc2


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


```sh
$ make modules
$ make modules_install
$ make dkms_add
$ make dkms_build
$ make dkms_install
```

In order to remove the mrf.ko from the system.
In order to remove them

```sh
$ make modules_uninstall
$ make dkms_uninstall
$ make dkms_remove
```

## Kernel modules configuration
Expand All @@ -30,3 +32,19 @@ In order to clean the configuration,
```sh
$ make setup_clean
```

## Notice
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.

```
$ bash dkms/dkms_setup.bash
$ systemctl status dkms
● dkms.service - Builds and install new kernel modules through DKMS
Loaded: loaded (/etc/systemd/system/dkms.service; enabled; vendor preset: ena
Active: active (exited) since Sun 2018-07-29 01:13:59 CEST; 4s ago
Docs: man:dkms(8)
Process: 3271 ExecStart=/bin/sh -c dkms autoinstall --verbose --kernelver $(un
Main PID: 3271 (code=exited, status=0/SUCCESS)
```
2 changes: 2 additions & 0 deletions configure/E3/CONFIG_EXPORT
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Variables should be transferred to module_name.makefile

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

EXPORT_VARS+=EPICS_HOST_ARCH
EXPORT_VARS+=EPICS_BASE
EXPORT_VARS+=MSI
EXPORT_VARS+=E3_REQUIRE_TOOLS
EXPORT_VARS+=E3_MODULE_VERSION
EXPORT_VARS+=E3_SITEMODS_PATH
Expand Down
59 changes: 59 additions & 0 deletions configure/E3/RULES_DKMS
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

SUDO2:=sudo -E bash -c
DKMS:=/usr/sbin/dkms
DKMS_ARGS:=-m $(E3_MODULE_NAME) -v $(E3_MODULE_VERSION)
KMOD_NAME := mrf

.PHONY: dkms_add dkms_build dkms_remove dkms_install dkms_uninstall

dkms_add: conf
$(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
$(QUIET) cat $(TOP)/dkms/dkms_with_msi.conf $(TOP)/dkms/dkms_without_msi.conf > $(TOP)/dkms/dkms.conf
$(QUIET) install -m 644 $(TOP)/dkms/dkms.conf $(E3_KMOD_SRC_PATH)/
$(SUDO2) 'ln -sf $(TOP)/$(E3_KMOD_SRC_PATH) /usr/src/$(E3_MODULE_NAME)-$(E3_MODULE_VERSION)'
$(SUDO) $(DKMS) add $(DKMS_ARGS)


dkms_build:
$(SUDO) $(DKMS) build $(DKMS_ARGS)


dkms_remove:
$(SUDO) $(DKMS) remove $(E3_MODULE_NAME)/$(E3_MODULE_VERSION) --all


dkms_install:
$(SUDO) $(DKMS) install $(DKMS_ARGS)
$(QUIET)$(SUDO) depmod

dkms_uninstall:
$(SUDO) $(DKMS) uninstall $(DKMS_ARGS)
$(QUIET)$(SUDO) depmod

.PHONY: dkms_add dkms_build dkms_install dkms_remove dkms_uninstall


setup:
$(QUIET) $(SUDO2) 'echo KERNEL==\"uio*\", ATTR{name}==\"mrf-pci\", MODE=\"0666\" | tee /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules'
$(QUIET) $(SUDO) /bin/udevadm control --reload-rules
$(QUIET) $(SUDO) /bin/udevadm trigger
$(QUIET) $(SUDO2) 'echo $(KMOD_NAME) | tee /etc/modules-load.d/$(KMOD_NAME).conf'
$(QUIET) $(SUDO) depmod --quick
$(QUIET) $(SUDO) modprobe -rv $(KMOD_NAME)
$(QUIET) $(SUDO) modprobe -v $(KMOD_NAME)
$(QUIET) -ls /dev/uio* 2>/dev/null


setup_clean:
$(QUIET) $(SUDO) modprobe -rv $(KMOD_NAME)
$(SUDO) rm -f /etc/modules-load.d/$(KMOD_NAME).conf
$(SUDO) rm -f /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules


.PHONY: setup setup_clean


VARS_EXCLUDES+=KMOD_NAME
VARS_EXCLUDES+=DKMS_ARGS
VARS_EXCLUDES+=DKMS
VARS_EXCLUDES+=SUDO2
20 changes: 2 additions & 18 deletions configure/E3/RULES_KMOD
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,7 @@ modules_clean:
modules_uninstall:
sudo rm -f /lib/modules/$(shell uname -r)/extra/$(KMOD_NAME).ko

setup:
$(QUIET) sudo -E bash -c 'echo KERNEL==\"uio*\", ATTR{name}==\"mrf-pci\", MODE=\"0666\" | tee /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules'
$(QUIET) sudo /bin/udevadm control --reload-rules
$(QUIET) sudo /bin/udevadm trigger
$(QUIET) sudo -E bash -c 'echo $(KMOD_NAME) | tee /etc/modules-load.d/$(KMOD_NAME).conf'
$(QUIET) sudo depmod --quick
$(QUIET) sudo modprobe -rv $(KMOD_NAME)
$(QUIET) sudo modprobe -v $(KMOD_NAME)
$(QUIET) ls -ltar /dev/uio*

setup_clean:
$(QUIET) sudo modprobe -rv $(KMOD_NAME)
# sudo rm -f /lib/modules/$(shell uname -r)/extra/$(KMOD_NAME).ko
sudo rm -f /etc/modules-load.d/$(KMOD_NAME).conf
sudo rm -f /etc/udev/rules.d/99-$(KMOD_NAME)ioc2.rules


.PHONY: modules modules_install modules_uninstall modules_clean setup setup_clean

.PHONY: modules modules_install modules_uninstall modules_clean


3 changes: 2 additions & 1 deletion configure/RULES
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ include $(TOP)/configure/E3/DEFINES_FT
include $(TOP)/configure/E3/RULES_E3
include $(TOP)/configure/E3/RULES_E3_SITELIBS
include $(TOP)/configure/E3/RULES_EPICS
-include $(TOP)/configure/E3/RULES_KMOD
include $(TOP)/configure/E3/RULES_DKMS
#-include $(TOP)/configure/E3/RULES_KMOD

include $(TOP)/configure/E3/RULES_DB
include $(TOP)/configure/E3/RULES_VARS
Expand Down
11 changes: 11 additions & 0 deletions dkms/dkms.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Builds and install new kernel modules through DKMS
Documentation=man:dkms(8)

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/sh -c 'dkms autoinstall --verbose --kernelver $(uname -r)'

[Install]
WantedBy=multi-user.target
93 changes: 93 additions & 0 deletions dkms/dkms_setup.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
#
# Copyright (c) 2018 Jeong Han Lee
#
# The 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 any newer 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, see https://www.gnu.org/licenses/gpl-2.0.txt
#
# Author : Jeong Han Lee
# email : [email protected]
# Date : Sunday, July 29 01:06:29 CEST 2018
# version : 0.0.1


declare -gr SC_SCRIPT="$(realpath "$0")"
declare -gr SC_SCRIPTNAME=${0##*/}
declare -gr SC_TOP="${SC_SCRIPT%/*}"

declare -gr SUDO_CMD="sudo";

DKMS_SYSTEMD=dkms.service
SD_UNIT_PATH_DEBIAN=/etc/systemd/system
SD_UNIT_PATH_CENTOS=/usr/lib/systemd/system


function find_dist
{

local dist_id dist_cn dist_rs PRETTY_NAME

if [[ -f /usr/bin/lsb_release ]] ; then
dist_id=$(lsb_release -is)
dist_cn=$(lsb_release -cs)
dist_rs=$(lsb_release -rs)
echo $dist_id ${dist_cn} ${dist_rs}
else
eval $(cat /etc/os-release | grep -E "^(PRETTY_NAME)=")
echo ${PRETTY_NAME}
fi


}


function setup_dkms_systemd
{
printf ">>> Setup the systemd %s in %s\n" "${DKMS_SYSTEMD}" "${SD_UNIT_PATH}"

${SUDO_CMD} install -m 644 ${SC_TOP}/${DKMS_SYSTEMD} ${SD_UNIT_PATH}/
${SUDO_CMD} systemctl daemon-reload;
${SUDO_CMD} systemctl enable ${DKMS_SYSTEMD};
${SUDO_CMD} systemctl start ${DKMS_SYSTEMD};
printf "\n"

}



## Determine CentOS or Debian, because systemd path is different

dist=$(find_dist)

case "$dist" in
*Debian*)
SD_UNIT_PATH=${SD_UNIT_PATH_DEBIAN}
;;
*CentOS*)
SD_UNIT_PATH=${SD_UNIT_PATH_CENTOS}
;;
*)
printf "\n";
printf "Doesn't support the detected $dist\n";
printf "Please contact [email protected]\n";
printf "\n";
exit;
;;
esac

${SUDO_CMD} -v

# Setup Systemd for the DKMS autoinstall
# dkms.sevice will be started before ethercat.service be started.
setup_dkms_systemd

5 changes: 5 additions & 0 deletions dkms/dkms_with_msi.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PACKAGE_NAME="$(name)"
PACKAGE_VERSION="$(version)"

BUILT_MODULE_NAME[0]="$(kmod_name)"
DEST_MODULE_NAME[0]="$(kmod_name)"
8 changes: 8 additions & 0 deletions dkms/dkms_without_msi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

DEST_MODULE_LOCATION[0]="/updates/dkms"

AUTOINSTALL=yes

MAKE[0]="make -C ${kernel_source_dir=${kernel_source}} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
CLEAN="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"

13 changes: 0 additions & 13 deletions mrfioc2.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,6 @@ TEMPLATES += $(wildcard $(EVRMRMAPPDB)/*.template)
#TEMPLATES += $(wildcard $(EVRMRMAPPDB)/*.substitutions)


### We have to think how to find $(EPICS_BASE) and
### $(EPICS_HOST_ARCH) during driver.makefile
### Friday, November 3 16:44:55 CET 2017, jhlee
### This step can be done when we "installing..." ?


# MSI:= $(EPICS_BASE)/bin/$(EPICS_HOST_ARCH)/msi


EPICS_BASE_HOST_BIN = $(EPICS_BASE)/bin/$(EPICS_HOST_ARCH)
MSI = $(EPICS_BASE_HOST_BIN)/msi


USR_DBFLAGS += -I . -I ..
USR_DBFLAGS += -I $(EPICS_BASE)/db
USR_DBFLAGS += -I $(MRMSHAREDDB)
Expand Down

0 comments on commit 5a4be8c

Please sign in to comment.