utils: ビルドしたモジュールを /lib/modules に配置して再起動後も残るようにする - #3
Open
NOPLAB wants to merge 1 commit into
Open
Conversation
The build scripts end with `sudo insmod rtmouse.ko`, which loads the module straight out of the build directory and never installs it. After a reboot the module is gone, so anything that loads the driver at boot has to compile it again -- on a Raspberry Pi 4 that is several minutes of CPU on every single boot. Install the module into `/lib/modules/$(uname -r)/extra/` and run `depmod` so `modprobe rtmouse` works, then load it with `modprobe` instead of `insmod`. Using `modprobe` also makes the scripts idempotent: `insmod` fails with "File exists" when the module is already loaded, and with `set -e` that aborts the script. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3ZzEzNKDxANptPX4QNnHn
There was a problem hiding this comment.
Pull request overview
This PR updates the utils/build_install_header_from_* helper scripts to install the built rtmouse.ko into the running kernel’s module tree so it can be loaded via modprobe (and persists across reboots), rather than loading directly from the build directory with insmod.
Changes:
- Replace
sudo insmod rtmouse.kowith installation into/lib/modules/$(uname -r)/extra/rtmouse.ko. - Run
depmod -aso the module dependency database includes the newly installed module. - Load the module using
sudo modprobe rtmouse(more re-runnable thaninsmod).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| utils/build_install_header_from_source_raspi4.bash | Install rtmouse.ko into /lib/modules and load via depmod + modprobe. |
| utils/build_install_header_from_source_raspi2.bash | Install rtmouse.ko into /lib/modules and load via depmod + modprobe. |
| utils/build_install_header_from_apt_raspi4.bash | Install rtmouse.ko into /lib/modules and load via depmod + modprobe. |
| utils/build_install_header_from_apt_raspi2.bash | Install rtmouse.ko into /lib/modules and load via depmod + modprobe. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+17
to
+18
| sudo depmod -a | ||
| sudo modprobe rtmouse |
Comment on lines
17
to
18
|
|
||
| # initialize the driver |
Comment on lines
+15
to
+16
| sudo depmod -a | ||
| sudo modprobe rtmouse |
Comment on lines
15
to
+16
| make | ||
| sudo insmod rtmouse.ko | ||
| sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
utils/build_install_*.bashの 4 本は、いずれも同じ形で終わっています。insmodはビルドディレクトリからモジュールを直接ロードするだけで、インストールはしません。そのため
/lib/modules/$(uname -r)にrtmouse.koは置かれず、modprobe rtmouseは機能しません。結果として、起動時にドライバをロードする仕組みは毎回モジュールをコンパイルし直す
ことになります。Raspberry Pi 4 では 1 回の起動あたり数分の CPU 時間です。
Ubuntu 22.04 / カーネル
5.15.0-1098-raspiの実機で、raspicat_setup_scriptsのraspicat.serviceが起動のたびにbuild_install_header_from_apt_raspi4.bashへ入り直しているのを確認しました。
もう 1 つ、小さい問題があります。モジュールが既にロード済みのとき
insmodはFile existsで失敗します。これらのスクリプトはすべてset -eの下で動くため、再実行すると途中で異常終了します。
変更内容
make -sudo insmod rtmouse.ko +sudo install -D -m 644 rtmouse.ko /lib/modules/$(uname -r)/extra/rtmouse.ko +sudo depmod -a +sudo modprobe rtmouse4 つのバリアント(
apt/source×raspi2/raspi4)すべてに同じ変更を入れ、挙動をそろえています。
extra/はツリー外モジュールの慣例的な置き場で、make modules_installが使う場所と同じです。depmod -aによりmodprobeから解決できるようになります。
modprobeでロードすることで、再実行しても問題なく通るようになります。
動作確認
上記の実機でビルドとインストールを行いました。
この状態で
modprobe rtmouseはコンパイルなしにドライバをロードし、/dev/rtmotor0や/dev/rtlightsensor0などもこれまでどおり生成されます。この PR に含めていないもの
src/drivers/Makefileのinstall:ターゲットは50-rtmouse.rulesを/etc/udev/rules.d/にコピーしますが、これを呼ぶ箇所がどこにもありません。そのため、これらのスクリプトはロードのたびに
sudo chmod 666 /dev/rt*を必要としています。ここまで入れると変更の趣旨が変わるため別件としましたが、
この PR に含めたほうがよければ対応します。
🤖 Generated with Claude Code
https://claude.ai/code/session_01V3ZzEzNKDxANptPX4QNnHn