From 34c28953aba4417414476de3b1c91617e9cd91ee Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Wed, 10 Apr 2013 04:35:26 -0700 Subject: [PATCH] backports: add udev rules if required for backported firmware_class Signed-off-by: Luis R. Rodriguez Signed-off-by: Johannes Berg --- backport/Makefile.real | 2 +- backport/scripts/backport_firmware_install.sh | 21 +++++++++++ backport/udev/50-compat_firmware.rules | 4 +++ backport/udev/compat_firmware.sh | 35 +++++++++++++++++++ backport/udev/ubuntu/compat_firmware.sh | 29 +++++++++++++++ gentree.py | 2 +- 6 files changed, 91 insertions(+), 2 deletions(-) create mode 100755 backport/scripts/backport_firmware_install.sh create mode 100644 backport/udev/50-compat_firmware.rules create mode 100755 backport/udev/compat_firmware.sh create mode 100755 backport/udev/ubuntu/compat_firmware.sh diff --git a/backport/Makefile.real b/backport/Makefile.real index 35a1fb34c877..8842778927fa 100644 --- a/backport/Makefile.real +++ b/backport/Makefile.real @@ -90,6 +90,7 @@ install: modules @./scripts/blacklist.sh $(KLIB)/ $(KLIB)/$(KMODDIR) @./scripts/compress_modules.sh $(KLIB)/$(KMODDIR) @./scripts/check_depmod.sh + @./scripts/backport_firmware_install.sh @/sbin/depmod -ae @echo @echo Your backported driver modules should be installed now. @@ -97,4 +98,3 @@ install: modules @echo # FIXME: # install/load/unload/... scripts? -# compat firmware class udev stuff diff --git a/backport/scripts/backport_firmware_install.sh b/backport/scripts/backport_firmware_install.sh new file mode 100755 index 000000000000..e4b9fb03835d --- /dev/null +++ b/backport/scripts/backport_firmware_install.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ -f /usr/bin/lsb_release ]; then + LSB_RED_ID=$(/usr/bin/lsb_release -i -s) +else + LSB_RED_ID="Unknown" +fi + +case $LSB_RED_ID in +"Ubuntu") + mkdir -p /lib/udev/ /lib/udev/rules.d/ + cp udev/ubuntu/compat_firmware.sh /lib/udev/ + cp udev/50-compat_firmware.rules /lib/udev/rules.d/ + ;; +*) + mkdir -p /lib/udev/ /lib/udev/rules.d/ + cp udev/compat_firmware.sh /lib/udev/ + cp udev/50-compat_firmware.rules /lib/udev/rules.d/ + ;; +esac + diff --git a/backport/udev/50-compat_firmware.rules b/backport/udev/50-compat_firmware.rules new file mode 100644 index 000000000000..6473788ec464 --- /dev/null +++ b/backport/udev/50-compat_firmware.rules @@ -0,0 +1,4 @@ +# do not edit this file, it will be overwritten on update + +# compat_firmware-class requests, copies files into the kernel +SUBSYSTEM=="compat_firmware", ACTION=="add", RUN+="compat_firmware.sh" diff --git a/backport/udev/compat_firmware.sh b/backport/udev/compat_firmware.sh new file mode 100755 index 000000000000..ef609e71c6df --- /dev/null +++ b/backport/udev/compat_firmware.sh @@ -0,0 +1,35 @@ +#!/bin/sh -e + +# This is ported from Ubuntu but ubuntu uses these directories which +# other distributions don't care about: +# FIRMWARE_DIRS="/lib/firmware/updates/$(uname -r) /lib/firmware/updates \ +# /lib/firmware/$(uname -r) /lib/firmware" +# If your distribution looks for firmware in other directories +# feel free to extend this and add your own directory here. +# +FIRMWARE_DIRS="/lib/firmware" + +err() { + echo "$@" >&2 + logger -t "${0##*/}[$$]" "$@" 2>/dev/null || true +} + +if [ ! -e /sys$DEVPATH/loading ]; then + err "udev firmware loader misses sysfs directory" + exit 1 +fi + +for DIR in $FIRMWARE_DIRS; do + [ -e "$DIR/$FIRMWARE" ] || continue + echo 1 > /sys$DEVPATH/loading + cat "$DIR/$FIRMWARE" > /sys$DEVPATH/data + echo 0 > /sys$DEVPATH/loading + exit 0 +done + +echo -1 > /sys$DEVPATH/loading +err "Cannot find firmware file '$FIRMWARE'" +mkdir -p /dev/.udev/firmware-missing +file=$(echo "$FIRMWARE" | sed 's:/:\\x2f:g') +ln -s -f "$DEVPATH" /dev/.udev/firmware-missing/$file +exit 1 diff --git a/backport/udev/ubuntu/compat_firmware.sh b/backport/udev/ubuntu/compat_firmware.sh new file mode 100755 index 000000000000..9d4659a34d78 --- /dev/null +++ b/backport/udev/ubuntu/compat_firmware.sh @@ -0,0 +1,29 @@ +#!/bin/sh -e + +FIRMWARE_DIRS="/lib/firmware/updates/$(uname -r) /lib/firmware/updates \ + /lib/firmware/$(uname -r) /lib/firmware" + +err() { + echo "$@" >&2 + logger -t "${0##*/}[$$]" "$@" 2>/dev/null || true +} + +if [ ! -e /sys$DEVPATH/loading ]; then + err "udev firmware loader misses sysfs directory" + exit 1 +fi + +for DIR in $FIRMWARE_DIRS; do + [ -e "$DIR/$FIRMWARE" ] || continue + echo 1 > /sys$DEVPATH/loading + cat "$DIR/$FIRMWARE" > /sys$DEVPATH/data + echo 0 > /sys$DEVPATH/loading + exit 0 +done + +echo -1 > /sys$DEVPATH/loading +err "Cannot find firmware file '$FIRMWARE'" +mkdir -p /dev/.udev/firmware-missing +file=$(echo "$FIRMWARE" | sed 's:/:\\x2f:g') +ln -s -f "$DEVPATH" /dev/.udev/firmware-missing/$file +exit 1 diff --git a/gentree.py b/gentree.py index 199a2c97410f..476a3fc82672 100755 --- a/gentree.py +++ b/gentree.py @@ -324,7 +324,7 @@ def process(kerneldir, outdir, copy_list_file, git_revision=None, backport_files = [(x, x) for x in [ 'Kconfig', 'Makefile', 'Makefile.build', 'Makefile.kernel', '.gitignore', 'Makefile.real', 'compat/', 'include/', 'kconfig/', 'defconfigs/', - 'scripts/', '.blacklist.map', + 'scripts/', '.blacklist.map', 'udev/', ]] if not args.git_revision: logwrite('Copy original source files ...') -- 2.30.2