mirror of
https://github.com/aleksamagicka/aquacomputer_d5next-hwmon.git
synced 2025-07-23 04:03:00 +02:00
Add DKMS support (#105)
* Update Makefile Add additional targets for building dkms module and integrating existing targets. Signed-off-by: Daniel Clark <megadjc@gmail.com> * Add DKMS Support Adds DKMS support and adds two useful utilities to automate installation and removal of the dkms module. Signed-off-by: Daniel Clark <megadjc@gmail.com> * Add DKMS Documentation. Adds installation instructions for the DKMS Module. All previous targets such as "make checkpath" and "make dev" are supported. Signed-off-by: Daniel Clark <megadjc@gmail.com> * Update Makefile Update formatting Signed-off-by: Daniel Clark <megadjc@gmail.com> --------- Signed-off-by: Daniel Clark <megadjc@gmail.com>
This commit is contained in:
118
Makefile
118
Makefile
@@ -1,23 +1,123 @@
|
||||
.PHONY: all modules install modules_install clean
|
||||
|
||||
# external KDIR specification is supported
|
||||
KDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
PWD ?= $(shell pwd)
|
||||
# For building for the current running version of Linux
|
||||
ifndef TARGET
|
||||
TARGET = $(shell uname -r)
|
||||
endif
|
||||
# Or specific version
|
||||
#TARGET = 2.6.33.5
|
||||
|
||||
#pull from original makefile to support checkpatch option
|
||||
SOURCES := aquacomputer_d5next.c docs/aquacomputer_d5next.rst
|
||||
|
||||
.PHONY: all modules modules clean checkpatch dev
|
||||
KERNEL_MODULES = /lib/modules/$(TARGET)
|
||||
|
||||
ifneq ("","$(wildcard /usr/src/linux-headers-$(TARGET)/*)")
|
||||
# Ubuntu
|
||||
KERNEL_BUILD = /usr/src/linux-headers-$(TARGET)
|
||||
else
|
||||
ifneq ("","$(wildcard /usr/src/kernels/$(TARGET)/*)")
|
||||
# Fedora
|
||||
KERNEL_BUILD = /usr/src/kernels/$(TARGET)
|
||||
else
|
||||
KERNEL_BUILD = $(KERNEL_MODULES)/build
|
||||
endif
|
||||
endif
|
||||
|
||||
# SYSTEM_MAP = $(KERNEL_BUILD)/System.map
|
||||
ifneq ("","$(wildcard /boot/System.map-$(TARGET))")
|
||||
SYSTEM_MAP = /boot/System.map-$(TARGET)
|
||||
else
|
||||
# Arch
|
||||
SYSTEM_MAP = /proc/kallsyms
|
||||
endif
|
||||
|
||||
DRIVER := aquacomputer_d5next
|
||||
ifneq ("","$(wildcard .git/*)")
|
||||
#default is branch name plus dkms modifier
|
||||
DRV_VERSION="$(git rev-parse --abbrev-ref HEAD)-dkms.$(date -u -d "$(git show -s --format=%ci HEAD)" +%Y%m%d)"
|
||||
#use below for tagged versioning. Should we add tagged version tracking?
|
||||
#DRIVER_VERSION := $(shell git describe --long).$(shell date -u -d "$$(git show -s --format=%ci HEAD)" +%Y%m%d)
|
||||
else
|
||||
ifneq ("", "$(wildcard VERSION)")
|
||||
DRIVER_VERSION := $(shell cat VERSION)
|
||||
else
|
||||
DRIVER_VERSION := unknown
|
||||
endif
|
||||
endif
|
||||
|
||||
# DKMS
|
||||
DKMS_ROOT_PATH=/usr/src/$(DRIVER)-$(DRIVER_VERSION)
|
||||
MODPROBE_OUTPUT=$(shell lsmod | grep aquacomputer_d5next)
|
||||
|
||||
# Directory below /lib/modules/$(TARGET)/kernel into which to install
|
||||
# the module:
|
||||
MOD_SUBDIR = drivers/hwmon
|
||||
MODDESTDIR=$(KERNEL_MODULES)/kernel/$(MOD_SUBDIR)
|
||||
|
||||
obj-m = $(patsubst %,%.o,$(DRIVER))
|
||||
obj-ko := $(patsubst %,%.ko,$(DRIVER))
|
||||
|
||||
MAKEFLAGS += --no-print-directory
|
||||
|
||||
ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.gz)")
|
||||
COMPRESS_GZIP := y
|
||||
endif
|
||||
ifneq ("","$(wildcard $(MODDESTDIR)/*.ko.xz)")
|
||||
COMPRESS_XZ := y
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: all install modules modules_install clean dkms dkms_clean checkpatch dev
|
||||
|
||||
all: modules
|
||||
|
||||
|
||||
# Targets for running make directly in the external module directory:
|
||||
|
||||
AQUACOMPUTER_D5NEXT_CFLAGS=-AQUACOMPUTER_D5NEXT_DRIVER_VERSION='\"$(DRIVER_VERSION)\"'
|
||||
|
||||
modules:
|
||||
@$(MAKE) EXTRA_CFLAGS="$(AQUACOMPUTER_D5NEXT_CFLAGS)" -C $(KERNEL_BUILD) M=$(CURDIR) $@
|
||||
|
||||
clean:
|
||||
@$(MAKE) -C $(KERNEL_BUILD) M=$(CURDIR) $@
|
||||
|
||||
install: modules_install
|
||||
|
||||
modules modules_install clean:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) $@
|
||||
modules_install:
|
||||
mkdir -p $(MODDESTDIR)
|
||||
cp $(DRIVER).ko $(MODDESTDIR)/
|
||||
ifeq ($(COMPRESS_GZIP), y)
|
||||
@gzip -f $(MODDESTDIR)/$(DRIVER).ko
|
||||
endif
|
||||
ifeq ($(COMPRESS_XZ), y)
|
||||
@xz -f $(MODDESTDIR)/$(DRIVER).ko
|
||||
endif
|
||||
depmod -a -F $(SYSTEM_MAP) $(TARGET)
|
||||
|
||||
dkms:
|
||||
@mkdir -p $(DKMS_ROOT_PATH)
|
||||
@cp ./dkms.conf $(DKMS_ROOT_PATH)
|
||||
@cp ./Makefile $(DKMS_ROOT_PATH)
|
||||
@cp ./aquacomputer_d5next.c $(DKMS_ROOT_PATH)
|
||||
@sed -i -e '/^PACKAGE_VERSION=/ s/=.*/=\"$(DRIVER_VERSION)\"/' $(DKMS_ROOT_PATH)/dkms.conf
|
||||
@echo "$(DRIVER_VERSION)" >$(DKMS_ROOT_PATH)/VERSION
|
||||
@dkms add -m $(DRIVER) -v $(DRIVER_VERSION)
|
||||
@dkms build -m $(DRIVER) -v $(DRIVER_VERSION) -k $(TARGET)
|
||||
@dkms install --force -m $(DRIVER) -v $(DRIVER_VERSION) -k $(TARGET)
|
||||
@modprobe $(DRIVER)
|
||||
|
||||
dkms_clean:
|
||||
@if [ ! -z "$(MODPROBE_OUTPUT)" ]; then \
|
||||
rmmod $(DRIVER);\
|
||||
fi
|
||||
@dkms remove -m $(DRIVER) -v $(DRIVER_VERSION) --all
|
||||
@rm -rf $(DKMS_ROOT_PATH)
|
||||
|
||||
#pulled from original makefile to support checkpatch option
|
||||
checkpatch:
|
||||
$(KDIR)/scripts/checkpatch.pl --strict --no-tree --ignore LINUX_VERSION_CODE $(SOURCES)
|
||||
$(KERNEL_BUILD)/scripts/checkpatch.pl --strict --no-tree --ignore LINUX_VERSION_CODE $(SOURCES)
|
||||
|
||||
#pulled from original makefile to support dev option
|
||||
dev:
|
||||
$(MAKE) clean
|
||||
$(MAKE)
|
||||
|
17
README.md
17
README.md
@@ -149,14 +149,27 @@ First, clone the repository by running:
|
||||
git clone https://github.com/aleksamagicka/aquacomputer_d5next-hwmon.git
|
||||
```
|
||||
|
||||
Then, compile it and insert it into the running kernel, replacing the existing instance (if needed):
|
||||
Then, You can run the followish script to create and install the dkms module:
|
||||
|
||||
```commandline
|
||||
make dev
|
||||
sudo ./dkms-install.sh
|
||||
```
|
||||
|
||||
If all went well, you can skip ahead to see how to use it.
|
||||
|
||||
If you wish to uninstall the dkms module you can run the following script
|
||||
|
||||
```commandline
|
||||
sudo ./dkms-remove.sh
|
||||
```
|
||||
|
||||
To compile the module and temporarily insert the module into the running kernel you can run the following:
|
||||
(Note that this will not be permanent and the kernel module will revert to the default module upon reboot.)
|
||||
|
||||
```commandline
|
||||
make dev
|
||||
```
|
||||
|
||||
If you are sure that you're on a recent kernel and are still getting errors, please open an issue so we can track it down.
|
||||
|
||||
### Kernel 5.17 and earlier
|
||||
|
25
dkms-install.sh
Normal file
25
dkms-install.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "You must run this with superuser priviliges. Try \"sudo ./dkms-install.sh\"" 2>&1
|
||||
exit 1
|
||||
else
|
||||
echo "About to run dkms install steps..."
|
||||
fi
|
||||
|
||||
DRV_NAME="$(basename "$(pwd)" | sed 's/-hwmon$//')"
|
||||
echo $DRV_NAME
|
||||
|
||||
#default is branch name plus dkms modifier
|
||||
DRV_VERSION="$(git rev-parse --abbrev-ref HEAD)-dkms.$(date -u -d "$(git show -s --format=%ci HEAD)" +%Y%m%d)"
|
||||
#use below for tagged versioning. Should we add tagged version tracking?
|
||||
#DRV_VERSION=$(git describe --long).$(date -u -d "$(git show -s --format=%ci HEAD)" +%Y%m%d)
|
||||
echo $DRV_VERSION
|
||||
DKMS_DIR=/usr/src/${DRV_NAME}-${DRV_VERSION}
|
||||
echo $DKMS_DIR
|
||||
|
||||
make -f Makefile DRIVER=$DRV_NAME DRIVER_VERSION=$DRV_VERSION DKMS_ROOT_PATH=$DKMS_DIR dkms
|
||||
|
||||
echo "Finished running dkms install steps."
|
||||
|
||||
exit $RESULT
|
22
dkms-remove.sh
Normal file
22
dkms-remove.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "You must run this with superuser priviliges. Try \"sudo ./dkms-remove.sh\"" 2>&1
|
||||
exit 1
|
||||
else
|
||||
echo "About to run dkms removal steps..."
|
||||
fi
|
||||
|
||||
DRV_NAME="$(basename "$(pwd)" | sed 's/-hwmon$//')"
|
||||
DRV_VERSION=$(dkms status ${DRV_NAME} -k $(uname -r) | cut -d, -f1 | cut -d/ -f2)
|
||||
|
||||
make -f Makefile DRIVER=$DRV_NAME DRIVER_VERSION=$DRV_VERSION dkms_clean
|
||||
|
||||
RESULT=$?
|
||||
if [[ "$RESULT" != "0" ]]; then
|
||||
echo "Error occurred while running dkms remove." 2>&1
|
||||
else
|
||||
echo "Finished running dkms removal steps."
|
||||
fi
|
||||
|
||||
exit $RESULT
|
Reference in New Issue
Block a user