]>
Commit | Line | Data |
---|---|---|
caec3c40 | 1 | #!/bin/sh |
47a185c4 ER |
2 | # Firmware loader. |
3 | # See also: | |
4 | # https://www.kernel.org/doc/Documentation/firmware_class/README | |
5 | # https://www.kernel.org/doc/Documentation/firmware_class/hotplug-script | |
caec3c40 | 6 | set -e |
f71c07f8 | 7 | |
5a873f5d ER |
8 | # handle only firmware add requests |
9 | if [ "$SUBSYSTEM" != "firmware" ]; then | |
10 | exit 0 | |
11 | fi | |
12 | if [ "$ACTION" != "add" ]; then | |
13 | exit 0 | |
14 | fi | |
15 | ||
f71c07f8 | 16 | FIRMWARE_DIRS="/lib/firmware/updates/$(uname -r) /lib/firmware/updates \ |
17 | /lib/firmware/$(uname -r) /lib/firmware" | |
18 | ||
caec3c40 ER |
19 | # @param string message |
20 | # @param int loglevel. defaults to "6" (info) | |
21 | # Log levels can be: | |
22 | # Name String Meaning | |
23 | # KERN_EMERG "0" Emergency messages, system is about to crash or is unstable | |
24 | # KERN_ALERT "1" Something bad happened and action must be taken immediately | |
25 | # KERN_CRIT "2" A critical condition occurred like a serious hardware/software failure | |
26 | # KERN_ERR "3" An error condition, often used by drivers to indicate difficulties with the hardware | |
27 | # KERN_WARNING "4" A warning, meaning nothing serious by itself but might indicate problems | |
28 | # KERN_NOTICE "5" Nothing serious, but notably nevertheless. Often used to report security events. | |
29 | # KERN_INFO "6" Informational message e.g. startup information at driver initialization | |
30 | # KERN_DEBUG "7" Debug messages | |
31 | # KERN_CONT "c" "continued" line of log printout (only done after a line that had no enclosing \n) | |
32 | kmsg() { | |
33 | local msg="$1" level=${2:-3} | |
34 | echo "<$level>$msg" > /dev/kmsg | |
35 | } | |
36 | ||
f71c07f8 | 37 | err() { |
caec3c40 ER |
38 | echo >&2 "$*" |
39 | kmsg "${0##*/}[$$] $*" | |
f71c07f8 | 40 | } |
41 | ||
42 | if [ ! -e /sys$DEVPATH/loading ]; then | |
43 | err "firmware loader misses sysfs directory" | |
44 | exit 1 | |
45 | fi | |
46 | ||
47 | for DIR in $FIRMWARE_DIRS; do | |
48 | [ -e "$DIR/$FIRMWARE" ] || continue | |
49 | echo 1 > /sys$DEVPATH/loading | |
50 | cat "$DIR/$FIRMWARE" > /sys$DEVPATH/data | |
51 | echo 0 > /sys$DEVPATH/loading | |
52 | exit 0 | |
53 | done | |
54 | ||
55 | echo -1 > /sys$DEVPATH/loading | |
e92fa90d | 56 | err "Cannot find firmware file '$FIRMWARE'" |
f71c07f8 | 57 | exit 1 |