]> git.pld-linux.org Git - projects/rc-scripts.git/blob - firmware-loader.sh
log to kmsg, as syslog is not available early to notice the errors
[projects/rc-scripts.git] / firmware-loader.sh
1 #!/bin/sh
2 set -e
3
4 FIRMWARE_DIRS="/lib/firmware/updates/$(uname -r) /lib/firmware/updates \
5                /lib/firmware/$(uname -r) /lib/firmware"
6
7 # add initrd code to print to kmsg
8 # @param string message
9 # @param int loglevel. defaults to "6" (info)
10 # Log levels can be:
11 # Name      String  Meaning
12 # KERN_EMERG    "0" Emergency messages, system is about to crash or is unstable
13 # KERN_ALERT    "1" Something bad happened and action must be taken immediately
14 # KERN_CRIT "2" A critical condition occurred like a serious hardware/software failure
15 # KERN_ERR  "3" An error condition, often used by drivers to indicate difficulties with the hardware
16 # KERN_WARNING  "4" A warning, meaning nothing serious by itself but might indicate problems
17 # KERN_NOTICE   "5" Nothing serious, but notably nevertheless. Often used to report security events.
18 # KERN_INFO "6" Informational message e.g. startup information at driver initialization
19 # KERN_DEBUG    "7" Debug messages
20 # KERN_CONT "c" "continued" line of log printout (only done after a line that had no enclosing \n)
21 kmsg() {
22     local msg="$1" level=${2:-3}
23     echo "<$level>$msg" > /dev/kmsg
24 }
25
26 err() {
27         echo >&2 "$*"
28         kmsg "${0##*/}[$$] $*"
29 }
30
31 if [ ! -e /sys$DEVPATH/loading ]; then
32         err "firmware loader misses sysfs directory"
33         exit 1
34 fi
35
36 for DIR in $FIRMWARE_DIRS; do
37         [ -e "$DIR/$FIRMWARE" ] || continue
38         echo 1 > /sys$DEVPATH/loading
39         cat "$DIR/$FIRMWARE" > /sys$DEVPATH/data
40         echo 0 > /sys$DEVPATH/loading
41         exit 0
42 done
43
44 echo -1 > /sys$DEVPATH/loading
45 err "Cannot find firmware file '$FIRMWARE'"
46 exit 1
This page took 0.089318 seconds and 3 git commands to generate.