Last active
October 22, 2025 17:23
-
-
Save mnalis/9c54023ec5067d6a72d43f2771d0b747 to your computer and use it in GitHub Desktop.
RaspberryPI IrToy - restore /dev/ttyACM0 interface in newer kernels automatically on kernel upgrade
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
| #!/bin/sh | |
| # by Matija Nalis <mnalis-rpi@voyager.hr> GPLv3+ started 20211112 | |
| # automatically kludge cdc_acm.ko for IrToy /dev/ttyACM0 usage "old-way" | |
| # updated by Matija Nalis <mnalis-rpi@voyager.hr> 20251022 for RpiOS-Trixie (6.12.47+rpt-rpi-v8) | |
| # | |
| # put this file with +rx permissions in /etc/kernel/postinst.d/cdc-acm-irtoy-kludge | |
| # | |
| #echo script: $0 | |
| #echo params: "$@" | |
| #echo "\$DPKG_MAINTSCRIPT_PACKAGE::\$DPKG_MAINTSCRIPT_NAME=$DPKG_MAINTSCRIPT_PACKAGE::$DPKG_MAINTSCRIPT_NAME" | |
| #echo env: ; env | |
| case "$DPKG_MAINTSCRIPT_PACKAGE::$DPKG_MAINTSCRIPT_NAME" in | |
| raspberrypi-kernel*::postrm|linux-image-*+rpt*::postrm) | |
| exit 0;; | |
| esac | |
| NEW_VER=$1 | |
| echo "Detecting new kernel version base: $NEW_VER" | |
| FLAVOUR=`uname -r | sed -e 's/^.*-v/-v/'` | |
| echo "Extracted current kernel flavour: $FLAVOUR" | |
| echo "Verifying correct flavor:" | |
| if echo $NEW_VER | fgrep -q -- $FLAVOUR | |
| then | |
| echo "FLAVOUR $FLAVOUR OK, continuing..." | |
| NEWDIR="/lib/modules/${NEW_VER}" | |
| echo "Checking kernel modules dir: $NEWDIR" | |
| if ! test -d ${NEWDIR} | |
| then | |
| echo "Failed to detect new kernel directory, ABORTING!" | |
| exit 3 | |
| fi | |
| echo "Found, trying to kludge cdc_acm.ko..." | |
| # from https://gist.github.com/mnalis/2fed42a1abf8e98f45f6edf162bf609f | |
| # This changes blacklisting of USB ID `04d8:fd08` in cdc-acm, so IrToy gets recognized | |
| # as it was in previous kernel versions, and `/dev/ttyACM0` gets created for it instead of `/dev/lirc0` | |
| # For those who don't use lirc but IrToy directly and so need compatibility with that... | |
| # | |
| # should work at least in Raspbian.org Buster raspberrypi-kernel 1:1.20211029-1~buster armhf | |
| # and in RaspberryPi OS Trixie linux-image-6.12.47+rpt-rpi-v8 arm64 | |
| MODULE=`echo ${NEWDIR}/kernel/drivers/usb/class/cdc-acm.ko*` | |
| EXT=${MODULE##*.} | |
| case $EXT in | |
| DISABLED) | |
| echo "cdc-acm module already kludged. Skipping." | |
| exit 0 | |
| ;; | |
| ko) COMP="cat"; DECOMP="cat"; EEXT="";; | |
| xz) COMP="xz"; DECOMP="xz -dc"; EEXT=".$EXT";; | |
| gz) COMP="gzip"; DECOMP="gzip -dc"; EEXT=".$EXT";; | |
| bz2) COMP="bzip2"; DECOMP="bzip2 -dc"; EEXT=".$EXT";; | |
| *) | |
| echo "Failed to find cdc-acm kernel module (got extension $EXT from $MODULE). ABORTING!" | |
| exit 0 | |
| ;; | |
| esac | |
| #echo "COMP=$COMP DECOMP=$DECOMP EXT=$EXT EEXT=$EEXT from MODULE=$MODULE" | |
| echo " cdc-acm.ko${EEXT} found, proceeding to kludge it..." | |
| cd ${NEWDIR}/kernel/drivers && \ | |
| mv -n media/rc/ir_toy.ko${EEXT} media/rc/ir_toy.ko${EEXT}.DISABLED && \ | |
| mv -n usb/class/cdc-acm.ko${EEXT} usb/class/cdc-acm.ko${EEXT}.DISABLED && \ | |
| $DECOMP < usb/class/cdc-acm.ko${EEXT}.DISABLED | env -i sed -e 's/\xd8\x04\x08\xfd/\xff\x04\x08\xfd/' | $COMP > usb/class/cdc-acm.ko${EEXT} && \ | |
| depmod -a && \ | |
| echo " Kludge finished. Please reboot when ready to activate changes in ${NEWDIR}..." || (echo FAILED; exit 5) | |
| else | |
| echo "FLAVOUR of $NEW_VER does not match $FLAVOUR, skipping..." | |
| exit 0 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment