| # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| description "Preload WiFi driver" |
| author "chromium-os-dev@chromium.org" |
| |
| # Run on boot-services; "stay running" until the udev-trigger completes |
| # (which is guaranteed to happen after boot-services) |
| start on starting boot-services |
| stop on stopped udev-trigger |
| |
| env drvfile=/var/lib/preload-wifi-driver |
| |
| pre-start script |
| # If the driver for built-in WIFI is a module, our post-stop script |
| # will have recorded the driver name on the previous boot cycle. |
| # Load that driver now so flimflam can config the wireless LAN sooner, |
| # ideally by the time login screen is up. |
| # |
| # Note: failure to probe the module here is NOT fatal. |
| if [ -s $drvfile ] ; then |
| drv=$(head -1 $drvfile) |
| if ! modprobe "$drv" >/dev/null 2>&1 ; then |
| # If modprobe didn't like the alias file for some reason, just |
| # move it out of the way. The post-stop script will make a new |
| # one. |
| mv $drvfile $drvfile.bad |
| logger -t "$UPSTART_JOB" \ |
| "modprobe $drv failed. Renamed $drvfile with .bad suffix." |
| fi |
| fi |
| end script |
| |
| post-stop script |
| # Create/Update driver name for the built-in WIFI. |
| # Used to preload WIFI driver in pre-start script. |
| # TODO(ggg): can flimflam share the "user selected" network device? |
| iwdev=$(iw dev | awk '/Interface/ { print $2 ; exit 0 }') |
| |
| if [ -n "$iwdev" ] ; then |
| drv=$(ethtool -i "$iwdev" | awk '/driver:/ { print $2 }') |
| fi |
| |
| if [ -n "$drv" ] ; then |
| drvmod=$(lsmod | awk 'd==$1 { print $1 }' d="$drv") |
| fi |
| |
| if [ -n "$drvmod" ] ; then |
| if [ -s $drvfile ] ; then |
| olddrv=$(head -1 $drvfile) |
| fi |
| |
| # Only update contents if they've changed. |
| if [ "$drv" != "$olddrv" ] ; then |
| echo "$drv" > $drvfile |
| fi |
| else |
| logger -t "$UPSTART_JOB" "$iwdev: $drv is not a module." |
| fi |
| end script |