From b53a56552736b20293f0034ed03a9af3b8f55765 Mon Sep 17 00:00:00 2001 From: Noriaki Ando Date: Fri, 31 Mar 2023 15:13:43 +0900 Subject: [PATCH 1/4] The raspbian build script updated, and some startup scripts added. (#74) --- 50-rtmouse.rules => etc/50-rtmouse.rules | 0 etc/rtmouse.service | 11 ++++ etc/rtmouse.sh | 73 ++++++++++++++++++++++++ src/drivers/Makefile | 2 +- src/drivers/Makefile.raspbian | 17 +++++- utils/build_install.bash | 2 + utils/build_install.raspbian.bash | 7 +-- 7 files changed, 105 insertions(+), 7 deletions(-) rename 50-rtmouse.rules => etc/50-rtmouse.rules (100%) create mode 100644 etc/rtmouse.service create mode 100755 etc/rtmouse.sh diff --git a/50-rtmouse.rules b/etc/50-rtmouse.rules similarity index 100% rename from 50-rtmouse.rules rename to etc/50-rtmouse.rules diff --git a/etc/rtmouse.service b/etc/rtmouse.service new file mode 100644 index 0000000..3afb510 --- /dev/null +++ b/etc/rtmouse.service @@ -0,0 +1,11 @@ +[Unit] +Description=rtmouse driver + +[Service] +Type=oneshot +ExecStart=/etc/init.d/rtmouse.sh start +ExecReload=/etc/init.d/rtmouse.sh restart +ExecStopt=/etc/init.d/rtmouse.sh stop + +[Install] +WantedBy=multi-user.target diff --git a/etc/rtmouse.sh b/etc/rtmouse.sh new file mode 100755 index 0000000..befd125 --- /dev/null +++ b/etc/rtmouse.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# +### BEGIN INIT INFO +# Provides: rtmouse +# Required-Start: $all +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: RT_Mouse_Driver +# Description: RaspPiMouse Driver +### END INIT INFO + +SCRIPTNAME=rtmouse.sh +PROC_FILE=/proc/modules +GREP=/bin/grep +MODPROBE=/sbin/modprobe +MODULE_NAME=rtmouse +DEP_MODULE_NAME=mcp320x + +[ -f $PROC_FILE ] || exit 0 +[ -x $GREP ] || exit 0 +[ -x $MODPROBE ] || exit 0 + +RES=`$GREP $MODULE_NAME $PROC_FILE` + +# installing rtmouse.ko +install_rtmouse() +{ + if [ "$RES" = "" ]; then + $MODPROBE $MODULE_NAME + echo "Module Install $MODULE_NAME" + else + echo "Module '$MODULE_NAME' is already installed" + fi +} + +# uninstalling rtmouse.ko +remove_rtmouse() +{ + if [ "$RES" = "" ]; then + echo "Module '$MODULE_NAME' isn't installed yet." + else + $MODPROBE -r $MODULE_NAME + $MODPROBE -r $DEP_MODULE_NAME + echo "Module '$MODULE_NAME' is rmoved." + fi +} + +case "$1" in + start) + install_rtmouse + sleep 1 + /bin/chmod a+rw /dev/rt* + ;; + stop) + remove_rtmouse + ;; + status) + if [ "$RES" = "" ]; then + echo "Module '$MODULE_NAME' isn't installed yet." + exit 0 + else + echo "Module '$MODULE_NAME' is already installed" + exit 0 + fi + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status}" >&2 + exit 3 +esac + +exit 0 diff --git a/src/drivers/Makefile b/src/drivers/Makefile index 1086ef4..9d4d655 120000 --- a/src/drivers/Makefile +++ b/src/drivers/Makefile @@ -1 +1 @@ -Makefile.ubuntu14 \ No newline at end of file +Makefile.raspbian \ No newline at end of file diff --git a/src/drivers/Makefile.raspbian b/src/drivers/Makefile.raspbian index 2222e8d..986697c 100644 --- a/src/drivers/Makefile.raspbian +++ b/src/drivers/Makefile.raspbian @@ -2,11 +2,24 @@ MODULE:= rtmouse obj-m:= $(MODULE).o clean-files:= *.o *.ko *.mod.[co] *~ -LINUX_SRC_DIR:=/usr/src/linux +LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) VERBOSE:=0 rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean \ No newline at end of file + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean + +install: rtmouse.ko + cp rtmouse.ko /lib/modules/$(shell uname -r)/kernel/drivers/ + cp ../../etc/50-rtmouse.rules /etc/udev/rules.d/ + cp ../../etc/rtmouse.sh /etc/init.d/ + chmod 755 /etc/init.d/rtmouse.sh + cp ../../etc/rtmouse.service /etc/systemd/system/ + systemctl enable rtmouse + +uninstall: + rm /etc/udev/rules.d/50-rtmouse.rules + +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm diff --git a/utils/build_install.bash b/utils/build_install.bash index 03225cb..5c48c22 100755 --- a/utils/build_install.bash +++ b/utils/build_install.bash @@ -10,6 +10,8 @@ elif [ "$(ls /usr/src/linux-* 2> /dev/null)" != '' ]; then # Ubuntu if grep -q "Raspberry Pi 4" /proc/cpuinfo; then $SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0 + elif grep -q "Raspberry Pi" /proc/cpuinfo; then + $SRC_DIR/utils/build_install.raspbian.bash && exit 0 else $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 fi diff --git a/utils/build_install.raspbian.bash b/utils/build_install.raspbian.bash index 19e4c99..c323622 100755 --- a/utils/build_install.raspbian.bash +++ b/utils/build_install.raspbian.bash @@ -1,17 +1,16 @@ #!/bin/bash -eu SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) +KERNEL_SRC=/usr/src/linux-headers-$(uname -r) # check kernel headers -[ ! -e /usr/src/linux ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } +[ ! -e $KERNEL_SRC ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } # build and install the driver cd $SRC_DIR/src/drivers/ -rm Makefile -ln -s Makefile.raspbian Makefile make clean make -sudo insmod rtmouse.ko +sudo make install # initialize the driver sleep 1 From e588f87136bbfd03ea2feaedc88c85dd4d3b5124 Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Fri, 31 Mar 2023 21:18:09 +0900 Subject: [PATCH 2/4] Update uninstallation --- src/drivers/Makefile.header_from_apt | 5 +++++ src/drivers/Makefile.header_from_source | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index 92c5d3e..0dd6513 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -17,9 +17,14 @@ install: rtmouse.ko cp ../../etc/rtmouse.sh /etc/init.d/ chmod 755 /etc/init.d/rtmouse.sh cp ../../etc/rtmouse.service /etc/systemd/system/ + systemctl daemon-reload systemctl enable rtmouse.service uninstall: rm /etc/udev/rules.d/50-rtmouse.rules + -systemctl stop rtmouse.service + systemctl disable rtmouse.service + rm /etc/init.d/rtmouse.sh + rm /etc/systemd/system/rtmouse.sh #Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index 46d59b9..f31506a 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -17,9 +17,14 @@ install: rtmouse.ko cp ../../etc/rtmouse.sh /etc/init.d/ chmod 755 /etc/init.d/rtmouse.sh cp ../../etc/rtmouse.service /etc/systemd/system/ + systemctl daemon-reload systemctl enable rtmouse.service uninstall: rm /etc/udev/rules.d/50-rtmouse.rules + -systemctl stop rtmouse.service + systemctl disable rtmouse.service + rm /etc/init.d/rtmouse.sh + rm /etc/systemd/system/rtmouse.sh #Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm From a4e5a7be8b63af4cd265fbb4fc640fc04e1c91e9 Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Fri, 31 Mar 2023 21:18:32 +0900 Subject: [PATCH 3/4] Update service description --- etc/rtmouse.service | 6 ++++++ etc/rtmouse.sh | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/etc/rtmouse.service b/etc/rtmouse.service index 3afb510..37bbb55 100644 --- a/etc/rtmouse.service +++ b/etc/rtmouse.service @@ -1,11 +1,17 @@ [Unit] Description=rtmouse driver +After=network.target [Service] Type=oneshot +RemainAfterExit=yes +Restart=no ExecStart=/etc/init.d/rtmouse.sh start ExecReload=/etc/init.d/rtmouse.sh restart ExecStopt=/etc/init.d/rtmouse.sh stop +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=rtmouse [Install] WantedBy=multi-user.target diff --git a/etc/rtmouse.sh b/etc/rtmouse.sh index befd125..07af1a7 100755 --- a/etc/rtmouse.sh +++ b/etc/rtmouse.sh @@ -7,8 +7,8 @@ # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: -# Short-Description: RT_Mouse_Driver -# Description: RaspPiMouse Driver +# Short-Description: RasPiMouse_Driver +# Description: Rasoberry Pi Mouse Driver by RT Corporation ### END INIT INFO SCRIPTNAME=rtmouse.sh From 60f85a375594c54c98134f70c049d2646b604f3a Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Fri, 31 Mar 2023 21:21:42 +0900 Subject: [PATCH 4/4] Fix merge commit 8a42389 --- src/drivers/Makefile | 2 +- utils/build_install.raspbian.bash | 19 +------------------ 2 files changed, 2 insertions(+), 19 deletions(-) mode change 100755 => 120000 utils/build_install.raspbian.bash diff --git a/src/drivers/Makefile b/src/drivers/Makefile index 9d4d655..c45a429 120000 --- a/src/drivers/Makefile +++ b/src/drivers/Makefile @@ -1 +1 @@ -Makefile.raspbian \ No newline at end of file +Makefile.header_from_apt \ No newline at end of file diff --git a/utils/build_install.raspbian.bash b/utils/build_install.raspbian.bash deleted file mode 100755 index c323622..0000000 --- a/utils/build_install.raspbian.bash +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -eu - -SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) -KERNEL_SRC=/usr/src/linux-headers-$(uname -r) - -# check kernel headers -[ ! -e $KERNEL_SRC ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } - -# build and install the driver -cd $SRC_DIR/src/drivers/ -make clean -make -sudo make install - -# initialize the driver -sleep 1 -sudo chmod 666 /dev/rt* -echo 0 > /dev/rtmotoren0 diff --git a/utils/build_install.raspbian.bash b/utils/build_install.raspbian.bash new file mode 120000 index 0000000..0cd0e79 --- /dev/null +++ b/utils/build_install.raspbian.bash @@ -0,0 +1 @@ +build_install_header_from_source_raspi2.bash \ No newline at end of file