From 7ab4afa15b2c93bf3d35c676705aac43ca71de25 Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Mon, 7 Dec 2020 15:39:35 +0900 Subject: [PATCH 1/2] Refactor install script and support Raspberry Pi 4 --- src/drivers/Makefile.raspbian | 18 +++++++----------- src/drivers/Makefile.ubuntu14 | 16 ++++++++-------- utils/build_install.bash | 10 +++++++++- utils/build_install.raspbian.bash | 14 ++++++++++---- utils/build_install.raspi4ubuntu.bash | 21 +++++++++++++++++++++ utils/build_install.ubuntu14.bash | 14 ++++++++++---- 6 files changed, 65 insertions(+), 28 deletions(-) create mode 100755 utils/build_install.raspi4ubuntu.bash diff --git a/src/drivers/Makefile.raspbian b/src/drivers/Makefile.raspbian index c97eeda..2222e8d 100644 --- a/src/drivers/Makefile.raspbian +++ b/src/drivers/Makefile.raspbian @@ -1,16 +1,12 @@ MODULE:= rtmouse -TARGET:= $(MODULE).ko - -all: $(TARGET) - -$(TARGET): $(MODULE).c - make -C /usr/src/linux M=$(PWD) modules - obj-m:= $(MODULE).o +clean-files:= *.o *.ko *.mod.[co] *~ + +LINUX_SRC_DIR:=/usr/src/linux +VERBOSE:=0 -install: - insmod $(MODULE).ko +rtmouse.ko: rtmouse.c + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - rm -f *.o *.order *.mod.c *.symvers *.ko - rm -rf .*.cmd .tmp_versions + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean \ No newline at end of file diff --git a/src/drivers/Makefile.ubuntu14 b/src/drivers/Makefile.ubuntu14 index 815b1d6..7844404 100644 --- a/src/drivers/Makefile.ubuntu14 +++ b/src/drivers/Makefile.ubuntu14 @@ -1,15 +1,15 @@ -#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm -TARGET:= rtmouse.ko +MODULE:= rtmouse +obj-m:= $(MODULE).o +clean-files:= *.o *.ko *.mod.[co] *~ -all: ${TARGET} +LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) +VERBOSE:=0 rtmouse.ko: rtmouse.c - make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 modules + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 clean - -obj-m:= rtmouse.o + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean install: rtmouse.ko cp ../../50-rtmouse.rules /etc/udev/rules.d/ @@ -17,4 +17,4 @@ install: rtmouse.ko uninstall: rm /etc/udev/rules.d/50-rtmouse.rules -clean-files := *.o *.ko *.mod.[co] *~ +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm \ No newline at end of file diff --git a/utils/build_install.bash b/utils/build_install.bash index 2c2a4d9..590388b 100755 --- a/utils/build_install.bash +++ b/utils/build_install.bash @@ -1,12 +1,20 @@ #!/usr/bin/env bash +set -eu SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) if [ -e /usr/src/linux ]; then + # Raspbian/Raspberry Pi OS $SRC_DIR/utils/build_install.raspbian.bash && exit 0 elif [ "$(ls /usr/src/linux-* 2> /dev/null)" != '' ]; then - $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 + # Ubuntu + if grep -q "Raspberry Pi 4" /proc/cpuinfo; then + $SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0 + else + $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 + fi else + # Error bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found." fi diff --git a/utils/build_install.raspbian.bash b/utils/build_install.raspbian.bash index 504387c..19e4c99 100755 --- a/utils/build_install.raspbian.bash +++ b/utils/build_install.raspbian.bash @@ -1,13 +1,19 @@ -#!/bin/bash -vxe +#!/bin/bash -eu -dir=$(dirname $0)/../ -[ ! -e /usr/src/linux ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; } -cd $dir/src/drivers/ +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux ] && { 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 + +# initialize the driver sleep 1 sudo chmod 666 /dev/rt* echo 0 > /dev/rtmotoren0 diff --git a/utils/build_install.raspi4ubuntu.bash b/utils/build_install.raspi4ubuntu.bash new file mode 100755 index 0000000..0f52a9e --- /dev/null +++ b/utils/build_install.raspi4ubuntu.bash @@ -0,0 +1,21 @@ +#!/bin/bash -eu + +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux-headers-$(uname -r) ] && { 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.ubuntu14 Makefile +make clean +# Update for Raspberry Pi 4 +sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c +make +sudo insmod rtmouse.ko + +# initialize the driver +sleep 1 +sudo chmod 666 /dev/rt* +echo 0 > /dev/rtmotoren0 diff --git a/utils/build_install.ubuntu14.bash b/utils/build_install.ubuntu14.bash index 206e209..9087335 100755 --- a/utils/build_install.ubuntu14.bash +++ b/utils/build_install.ubuntu14.bash @@ -1,13 +1,19 @@ -#!/bin/bash -vxe +#!/bin/bash -eu -dir=$(dirname $0)/../ -[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; } -cd $dir/src/drivers/ +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux-headers-$(uname -r) ] && { 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.ubuntu14 Makefile make clean make sudo insmod rtmouse.ko + +# initialize the driver sleep 1 sudo chmod 666 /dev/rt* echo 0 > /dev/rtmotoren0 From bd967bc66667740573d1ea699f9550a44e6108fc Mon Sep 17 00:00:00 2001 From: Daisuke Sato Date: Tue, 15 Dec 2020 10:58:45 +0900 Subject: [PATCH 2/2] Fix indentation Co-authored-by: Shota Aoki --- utils/build_install.bash | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/utils/build_install.bash b/utils/build_install.bash index 590388b..03225cb 100755 --- a/utils/build_install.bash +++ b/utils/build_install.bash @@ -7,14 +7,13 @@ if [ -e /usr/src/linux ]; then # Raspbian/Raspberry Pi OS $SRC_DIR/utils/build_install.raspbian.bash && exit 0 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 - else - $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 - fi + # Ubuntu + if grep -q "Raspberry Pi 4" /proc/cpuinfo; then + $SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0 + else + $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 + fi else # Error bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found." fi -