debian: dkms mkdeb で生成した Debian パッケージからドライバをインストールする際の問題を修正

同時に Debian パッケージにファームウェアを含めるようにした
ref: https://github.com/dell/dkms/issues/53#issuecomment-1591788158
This commit is contained in:
tsukumi
2023-06-30 04:38:52 +00:00
parent 07334069ef
commit c6afab65ef
20 changed files with 249 additions and 58 deletions

2
.gitignore vendored
View File

@@ -15,7 +15,7 @@ modules.order
/driver/revision.h
/fwtool/fwtool
*.bin
fwtool/*.bin
*.sys
*.zip

View File

@@ -85,6 +85,9 @@ BonDriver と同じフォルダに DriverHost_PX4.exe / DriverHost_PX4.ini / it9
### 1. ファームウェアの抽出とインストール
> **px4_drv を Debian パッケージや DKMS を使ってインストールする場合、ファームウェアは自動的にインストールされます。**
> Debian パッケージや DKMS を使ってインストールする場合は、この手順は不要です。
unzip, gcc, make がインストールされている必要があります。
$ cd fwtool
@@ -97,39 +100,40 @@ unzip, gcc, make がインストールされている必要があります。
または、抽出済みのファームウェアを利用することもできます。
$ sudo mkdir -p /lib/firmware && sudo cp winusb/pkg/DriverHost_PX4/it930x-firmware.bin /lib/firmware/
$ sudo mkdir -p /lib/firmware && sudo cp etc/it930x-firmware.bin /lib/firmware/
### 2. ドライバのインストール
一部の Linux ディストリビューションでは、udev のインストールが別途必要になる場合があります。
#### Debian パッケージを使用してインストール
#### DKMS を使用しない場合
`./build_deb.sh` を実行すると、./build_deb.sh の一つ上層のディレクトリに `px4-drv-dkms_0.2.1_(amd64|arm64).deb` という名前の Debian パッケージが生成されます。
gcc, make, カーネルソース/ヘッダがインストールされている必要があります。
$ ./build_deb.sh
$ sudo apt install -y ../px4-drv-dkms_0.2.1_amd64.deb
$ cd driver
$ make
$ sudo make install
$ cd ../
上記コマンドで、px4_drv の Debian パッケージをインストールできます。
#### DKMS を使用する場合
#### DKMS を使用してインストールする
gcc, make, カーネルソース/ヘッダ, dkms がインストールされている必要があります。
$ sudo cp -a ./ /usr/src/px4_drv-0.2.1
$ sudo dkms add px4_drv/0.2.1
$ sudo dkms install px4_drv/0.2.1
#### ビルド済みバイナリを Debian パッケージからインストールする
`build_deb.sh` を実行すると、
- px4-drv-***.deb
- px4-drv-dkms-***.deb
の2つのファイルが生成されます。
```
sudo apt install ./px4-drv*.deb -y
```
とする事でインストールができます。
#### DKMS を使用せずにインストールする
gcc, make, カーネルソース/ヘッダがインストールされている必要があります。
> DKMS を使用せずにインストールした場合、カーネルのアップデート時にドライバが自動的に再ビルドされないため、アップデート後に再度インストールを行う必要があります。
> 基本 DKMS を使用してインストールすることをおすすめします。
$ cd driver
$ make
$ sudo make install
$ cd ../
### 3. 確認
@@ -220,19 +224,27 @@ sudo apt install ./px4-drv*.deb -y
### 1. ドライバのアンインストール
#### DKMS を使用せずにインストールした場合
#### Debian パッケージを使用してインストールした場合
$ cd driver
$ sudo make uninstall
$ cd ../
$ sudo apt purge px4-drv-dkms
#### DKMS を使用してインストールした場合
$ sudo dkms remove px4_drv/0.2.1 --all
$ sudo rm -rf /usr/src/px4_drv-0.2.1
#### DKMS を使用せずにインストールした場合
$ sudo modprobe -r px4_drv
$ cd driver
$ sudo make uninstall
$ cd ../
### 2. ファームウェアのアンインストール
> **px4_drv を Debian パッケージや DKMS を使ってインストールした場合、ファームウェアは自動的にアンインストールされます。**
> Debian パッケージや DKMS を使ってインストールした場合は、この手順は不要です。
$ sudo rm /lib/firmware/it930x-firmware.bin
## 受信方法

View File

@@ -1,26 +1,9 @@
#!/bin/bash
set -CEuo pipefail
SCRIPT_DIR=$(cd $(dirname $0) && pwd)
VER_MAJ=0
VER_MIN=2
VER_BUILD=1
cd $SCRIPT_DIR
# Prep
sudo apt install dkms dpkg
sudo apt-get install -y dkms dpkg
# Source pkg
# Build dkms deb
dkms mkdeb
# Binary pkg
mkdir -p ./installer/lib/firmware
cp ./winusb/pkg/DriverHost_PX4/it930x-firmware.bin ./installer/lib/firmware
cp -r ./debian ./installer/DEBIAN
dpkg-deb --build installer
# Clean up, and then place them all
rm -rf installer
mv ./installer.deb ../px4-drv_${VER_MAJ}.${VER_MIN}.${VER_BUILD}_all.deb -v

7
debian/control vendored
View File

@@ -1,7 +0,0 @@
Maintainer: nns779 <25547272+nns779@users.noreply.github.com>
Build-Depends: debhelper (>= 9), dpkg
Package: px4-drv
Architecture: all
Depends: px4-drv-dkms
Description: Binary blob(s) for the it930x driver
Version: 0.2.1

View File

@@ -5,6 +5,6 @@ MAKE="cd ./driver; make KVER=${kernelver} px4_drv.ko"
BUILT_MODULE_LOCATION="driver"
BUILT_MODULE_NAME="px4_drv"
DEST_MODULE_LOCATION="/updates/dkms"
POST_INSTALL="dkms/post_install"
POST_REMOVE="dkms/post_remove"
POST_INSTALL="dkms/post_install.sh"
POST_REMOVE="dkms/post_remove.sh"
AUTOINSTALL="yes"

View File

@@ -1,3 +0,0 @@
#!/bin/sh
rm -fv /etc/udev/rules.d/90-px4.rules
install -D -v -m 644 ./etc/99-px4video.rules /etc/udev/rules.d/99-px4video.rules

11
dkms/post_install.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
# Unload previous driver
KVER=`uname -r`
if [ `grep -e '^px4_drv' /proc/modules | wc -l` -ne 0 ]; then
modprobe -r px4_drv
fi
rm -fv /etc/udev/rules.d/90-px4.rules
install -D -v -m 644 ./etc/99-px4video.rules /etc/udev/rules.d/99-px4video.rules
install -D -v -m 644 ./etc/it930x-firmware.bin /lib/firmware/it930x-firmware.bin

View File

@@ -1,4 +0,0 @@
#!/bin/sh
if [ `find /lib/modules/ -name px4_drv.ko | wc -l` -eq 0 ]; then
rm -fv /etc/udev/rules.d/90-px4.rules /etc/udev/rules.d/99-px4video.rules
fi

12
dkms/post_remove.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
# Unload previous driver
KVER=`uname -r`
if [ `grep -e '^px4_drv' /proc/modules | wc -l` -ne 0 ]; then
modprobe -r px4_drv
fi
if [ `find /lib/modules/ -name px4_drv.ko | wc -l` -eq 0 ]; then
rm -fv /etc/udev/rules.d/90-px4.rules /etc/udev/rules.d/99-px4video.rules
rm -fv /lib/firmware/it930x-firmware.bin
fi

BIN
etc/it930x-firmware.bin Normal file

Binary file not shown.

View File

@@ -0,0 +1,29 @@
#/usr/bin/make
SRC = $(DESTDIR)/usr/src
SHARE = $(DESTDIR)/usr/share/$(NAME)-dkms
all:
clean:
install:
#source tree
ifeq ("$(wildcard $(NAME)-$(VERSION))", "$(NAME)-$(VERSION)")
install -d "$(SRC)"
cp -a $(NAME)-$(VERSION) $(SRC)
#ref: https://github.com/dell/dkms/issues/53#issuecomment-1591788158
#chmod 644 -R "$(SRC)/$(NAME)-$(VERSION)"
endif
#tarball, possibly with binaries
ifeq ("$(wildcard $(NAME)-$(VERSION).dkms.tar.gz)", "$(NAME)-$(VERSION).dkms.tar.gz")
install -d "$(SHARE)"
install -m 644 $(NAME)-$(VERSION).dkms.tar.gz "$(SHARE)"
endif
#postinst, only if we are supporting legacy mode
ifeq ("$(wildcard common.postinst)", "common.postinst")
install -d "$(SHARE)"
install -m 755 $(PREFIX)/usr/lib/dkms/common.postinst $(SHARE)/postinst
endif

View File

@@ -0,0 +1,5 @@
MODULE_NAME DKMS module for Debian
This package was automatically generated by the DKMS system,
for distribution on Debian based operating systems.

View File

@@ -0,0 +1,6 @@
DEBIAN_PACKAGE-dkms (MODULE_VERSION) stable; urgency=low
* Automatically packaged by DKMS.
-- Dynamic Kernel Modules Support Team <pkg-dkms-maint@lists.alioth.debian.org> DATE_STAMP

View File

@@ -0,0 +1 @@
7

View File

@@ -0,0 +1,12 @@
Source: DEBIAN_PACKAGE-dkms
Section: misc
Priority: optional
Maintainer: Dynamic Kernel Modules Support Team <pkg-dkms-maint@lists.alioth.debian.org>
Build-Depends: debhelper (>= 7), dkms
Standards-Version: 3.8.1
Package: DEBIAN_PACKAGE-dkms
Architecture: DEBIAN_BUILD_ARCH
Provides: DEBIAN_PACKAGE-modules (= MODULE_VERSION)
Depends: dkms (>= 1.95), ${misc:Depends}
Description: DEBIAN_PACKAGE driver in DKMS format.

View File

@@ -0,0 +1,2 @@
This copyright has not been completed by the author of this package.

View File

@@ -0,0 +1 @@
usr/src

View File

@@ -0,0 +1,49 @@
#!/bin/sh
# Copyright (C) 2002-2005 Flavio Stanchina
# Copyright (C) 2005-2006 Aric Cyr
# Copyright (C) 2007 Mario Limonciello
# Copyright (C) 2009 Alberto Milone
set -e
NAME=MODULE_NAME
PACKAGE_NAME=$NAME-dkms
DEB_NAME=$(echo $PACKAGE_NAME | sed 's,_,-,')
CVERSION=`dpkg-query -W -f='${Version}' $DEB_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`
ARCH=`dpkg-architecture -qDEB_BUILD_GNU_CPU`
dkms_configure () {
for POSTINST in /usr/lib/dkms/common.postinst "/usr/share/$PACKAGE_NAME/postinst"; do
if [ -f "$POSTINST" ]; then
"$POSTINST" "$NAME" "$CVERSION" "/usr/share/$PACKAGE_NAME" "$ARCH" "$2"
return $?
fi
echo "WARNING: $POSTINST does not exist." >&2
done
echo "ERROR: DKMS version is too old and $PACKAGE_NAME was not" >&2
echo "built with legacy DKMS support." >&2
echo "You must either rebuild $PACKAGE_NAME with legacy postinst" >&2
echo "support or upgrade DKMS to a more current version." >&2
return 1
}
case "$1" in
configure)
dkms_configure
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

28
px4_drv-dkms-mkdeb/debian/prerm Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/sh
NAME=MODULE_NAME
VERSION=MODULE_VERSION
set -e
case "$1" in
remove|upgrade|deconfigure)
if [ "`dkms status -m $NAME`" ]; then
dkms remove -m $NAME -v $VERSION --all
fi
;;
failed-upgrade)
;;
*)
echo "prerm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

54
px4_drv-dkms-mkdeb/debian/rules Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
DEB_NAME=DEBIAN_PACKAGE
NAME=MODULE_NAME
VERSION=MODULE_VERSION
configure: configure-stamp
configure-stamp:
dh_testdir
touch configure-stamp
build: build-stamp
build-stamp: configure-stamp
dh_testdir
$(MAKE)
touch $@
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
-$(MAKE) clean
dh_clean
install: build
dh_testdir
dh_testroot
dh_prep
dh_installdirs
$(MAKE) DESTDIR=$(CURDIR)/debian/$(DEB_NAME)-dkms NAME=$(NAME) VERSION=$(VERSION) install
binary-arch: build install
binary-indep: build install
dh_testdir
dh_testroot
dh_link
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure