Skip to content

Commit a9af4fa

Browse files
TiryohShota Aoki
andauthored
Refactor install script and support Raspberry Pi 4 (#62)
* Refactor install script and support Raspberry Pi 4 * Fix indentation Co-authored-by: Shota Aoki <s.aoki@rt-net.jp> Co-authored-by: Shota Aoki <s.aoki@rt-net.jp>
1 parent 29a677a commit a9af4fa

File tree

6 files changed

+65
-29
lines changed

6 files changed

+65
-29
lines changed

src/drivers/Makefile.raspbian

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
MODULE:= rtmouse
2-
TARGET:= $(MODULE).ko
3-
4-
all: $(TARGET)
5-
6-
$(TARGET): $(MODULE).c
7-
make -C /usr/src/linux M=$(PWD) modules
8-
92
obj-m:= $(MODULE).o
3+
clean-files:= *.o *.ko *.mod.[co] *~
4+
5+
LINUX_SRC_DIR:=/usr/src/linux
6+
VERBOSE:=0
107

11-
install:
12-
insmod $(MODULE).ko
8+
rtmouse.ko: rtmouse.c
9+
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules
1310

1411
clean:
15-
rm -f *.o *.order *.mod.c *.symvers *.ko
16-
rm -rf .*.cmd .tmp_versions
12+
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean

src/drivers/Makefile.ubuntu14

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm
2-
TARGET:= rtmouse.ko
1+
MODULE:= rtmouse
2+
obj-m:= $(MODULE).o
3+
clean-files:= *.o *.ko *.mod.[co] *~
34

4-
all: ${TARGET}
5+
LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r)
6+
VERBOSE:=0
57

68
rtmouse.ko: rtmouse.c
7-
make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 modules
9+
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules
810

911
clean:
10-
make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 clean
11-
12-
obj-m:= rtmouse.o
12+
make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean
1313

1414
install: rtmouse.ko
1515
cp ../../50-rtmouse.rules /etc/udev/rules.d/
1616

1717
uninstall:
1818
rm /etc/udev/rules.d/50-rtmouse.rules
1919

20-
clean-files := *.o *.ko *.mod.[co] *~
20+
#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm

utils/build_install.bash

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/env bash
2+
set -eu
23

34
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd)
45

56
if [ -e /usr/src/linux ]; then
7+
# Raspbian/Raspberry Pi OS
68
$SRC_DIR/utils/build_install.raspbian.bash && exit 0
79
elif [ "$(ls /usr/src/linux-* 2> /dev/null)" != '' ]; then
8-
$SRC_DIR/utils/build_install.ubuntu14.bash && exit 0
10+
# Ubuntu
11+
if grep -q "Raspberry Pi 4" /proc/cpuinfo; then
12+
$SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0
13+
else
14+
$SRC_DIR/utils/build_install.ubuntu14.bash && exit 0
15+
fi
916
else
17+
# Error
1018
bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."
1119
fi
12-

utils/build_install.raspbian.bash

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
#!/bin/bash -vxe
1+
#!/bin/bash -eu
22

3-
dir=$(dirname $0)/../
4-
[ ! -e /usr/src/linux ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; }
5-
cd $dir/src/drivers/
3+
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd)
4+
5+
# check kernel headers
6+
[ ! -e /usr/src/linux ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; }
7+
8+
# build and install the driver
9+
cd $SRC_DIR/src/drivers/
610
rm Makefile
711
ln -s Makefile.raspbian Makefile
812
make clean
913
make
1014
sudo insmod rtmouse.ko
15+
16+
# initialize the driver
1117
sleep 1
1218
sudo chmod 666 /dev/rt*
1319
echo 0 > /dev/rtmotoren0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash -eu
2+
3+
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd)
4+
5+
# check kernel headers
6+
[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; }
7+
8+
# build and install the driver
9+
cd $SRC_DIR/src/drivers/
10+
rm Makefile
11+
ln -s Makefile.ubuntu14 Makefile
12+
make clean
13+
# Update for Raspberry Pi 4
14+
sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c
15+
make
16+
sudo insmod rtmouse.ko
17+
18+
# initialize the driver
19+
sleep 1
20+
sudo chmod 666 /dev/rt*
21+
echo 0 > /dev/rtmotoren0

utils/build_install.ubuntu14.bash

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
#!/bin/bash -vxe
1+
#!/bin/bash -eu
22

3-
dir=$(dirname $0)/../
4-
[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; }
5-
cd $dir/src/drivers/
3+
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd)
4+
5+
# check kernel headers
6+
[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; }
7+
8+
# build and install the driver
9+
cd $SRC_DIR/src/drivers/
610
rm Makefile
711
ln -s Makefile.ubuntu14 Makefile
812
make clean
913
make
1014
sudo insmod rtmouse.ko
15+
16+
# initialize the driver
1117
sleep 1
1218
sudo chmod 666 /dev/rt*
1319
echo 0 > /dev/rtmotoren0

0 commit comments

Comments
 (0)