Skip to content

Instantly share code, notes, and snippets.

@mnalis
Created November 12, 2021 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnalis/9c54023ec5067d6a72d43f2771d0b747 to your computer and use it in GitHub Desktop.
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
#!/bin/sh
# by Matija Nalis <mnalis-rpi@voyager.hr> GPLv3+ 20211112
# automatically kludge cdc_acm.ko for IrToy /dev/ttyACM0 usage "old-way"
#
#echo script: $0
#echo params: "$@"
#echo env:
#env
case "$DPKG_MAINTSCRIPT_PACKAGE::$DPKG_MAINTSCRIPT_NAME" in
raspberrypi-kernel*::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, proceeding 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...
#
# works at least in Raspbian.org Buster raspberrypi-kernel 1:1.20211029-1~buster armhf
cd ${NEWDIR}/kernel/drivers && \
mv -n media/rc/ir_toy.ko media/rc/ir_toy.ko.DISABLED && \
mv -n usb/class/cdc-acm.ko usb/class/cdc-acm.ko.DISABLED && \
env -i sed -e 's/\xd8\x04\x08\xfd/\xff\x04\x08\xfd/' < usb/class/cdc-acm.ko.DISABLED > usb/class/cdc-acm.ko && \
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