Skip to content

Commit b53a565

Browse files
authored
The raspbian build script updated, and some startup scripts added. (#74)
1 parent 8c36a6c commit b53a565

File tree

7 files changed

+105
-7
lines changed

7 files changed

+105
-7
lines changed
File renamed without changes.

etc/rtmouse.service

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=rtmouse driver
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/etc/init.d/rtmouse.sh start
7+
ExecReload=/etc/init.d/rtmouse.sh restart
8+
ExecStopt=/etc/init.d/rtmouse.sh stop
9+
10+
[Install]
11+
WantedBy=multi-user.target

etc/rtmouse.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
#
3+
#
4+
### BEGIN INIT INFO
5+
# Provides: rtmouse
6+
# Required-Start: $all
7+
# Required-Stop:
8+
# Default-Start: 2 3 4 5
9+
# Default-Stop:
10+
# Short-Description: RT_Mouse_Driver
11+
# Description: RaspPiMouse Driver
12+
### END INIT INFO
13+
14+
SCRIPTNAME=rtmouse.sh
15+
PROC_FILE=/proc/modules
16+
GREP=/bin/grep
17+
MODPROBE=/sbin/modprobe
18+
MODULE_NAME=rtmouse
19+
DEP_MODULE_NAME=mcp320x
20+
21+
[ -f $PROC_FILE ] || exit 0
22+
[ -x $GREP ] || exit 0
23+
[ -x $MODPROBE ] || exit 0
24+
25+
RES=`$GREP $MODULE_NAME $PROC_FILE`
26+
27+
# installing rtmouse.ko
28+
install_rtmouse()
29+
{
30+
if [ "$RES" = "" ]; then
31+
$MODPROBE $MODULE_NAME
32+
echo "Module Install $MODULE_NAME"
33+
else
34+
echo "Module '$MODULE_NAME' is already installed"
35+
fi
36+
}
37+
38+
# uninstalling rtmouse.ko
39+
remove_rtmouse()
40+
{
41+
if [ "$RES" = "" ]; then
42+
echo "Module '$MODULE_NAME' isn't installed yet."
43+
else
44+
$MODPROBE -r $MODULE_NAME
45+
$MODPROBE -r $DEP_MODULE_NAME
46+
echo "Module '$MODULE_NAME' is rmoved."
47+
fi
48+
}
49+
50+
case "$1" in
51+
start)
52+
install_rtmouse
53+
sleep 1
54+
/bin/chmod a+rw /dev/rt*
55+
;;
56+
stop)
57+
remove_rtmouse
58+
;;
59+
status)
60+
if [ "$RES" = "" ]; then
61+
echo "Module '$MODULE_NAME' isn't installed yet."
62+
exit 0
63+
else
64+
echo "Module '$MODULE_NAME' is already installed"
65+
exit 0
66+
fi
67+
;;
68+
*)
69+
echo "Usage: $SCRIPTNAME {start|stop|status}" >&2
70+
exit 3
71+
esac
72+
73+
exit 0

src/drivers/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Makefile.ubuntu14
1+
Makefile.raspbian

src/drivers/Makefile.raspbian

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@ MODULE:= rtmouse
22
obj-m:= $(MODULE).o
33
clean-files:= *.o *.ko *.mod.[co] *~
44

5-
LINUX_SRC_DIR:=/usr/src/linux
5+
LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r)
66
VERBOSE:=0
77

88
rtmouse.ko: rtmouse.c
99
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules
1010

1111
clean:
12-
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean
12+
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean
13+
14+
install: rtmouse.ko
15+
cp rtmouse.ko /lib/modules/$(shell uname -r)/kernel/drivers/
16+
cp ../../etc/50-rtmouse.rules /etc/udev/rules.d/
17+
cp ../../etc/rtmouse.sh /etc/init.d/
18+
chmod 755 /etc/init.d/rtmouse.sh
19+
cp ../../etc/rtmouse.service /etc/systemd/system/
20+
systemctl enable rtmouse
21+
22+
uninstall:
23+
rm /etc/udev/rules.d/50-rtmouse.rules
24+
25+
#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm

utils/build_install.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ elif [ "$(ls /usr/src/linux-* 2> /dev/null)" != '' ]; then
1010
# Ubuntu
1111
if grep -q "Raspberry Pi 4" /proc/cpuinfo; then
1212
$SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0
13+
elif grep -q "Raspberry Pi" /proc/cpuinfo; then
14+
$SRC_DIR/utils/build_install.raspbian.bash && exit 0
1315
else
1416
$SRC_DIR/utils/build_install.ubuntu14.bash && exit 0
1517
fi

utils/build_install.raspbian.bash

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/bin/bash -eu
22

33
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd)
4+
KERNEL_SRC=/usr/src/linux-headers-$(uname -r)
45

56
# check kernel headers
6-
[ ! -e /usr/src/linux ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; }
7+
[ ! -e $KERNEL_SRC ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; }
78

89
# build and install the driver
910
cd $SRC_DIR/src/drivers/
10-
rm Makefile
11-
ln -s Makefile.raspbian Makefile
1211
make clean
1312
make
14-
sudo insmod rtmouse.ko
13+
sudo make install
1514

1615
# initialize the driver
1716
sleep 1

0 commit comments

Comments
 (0)