OSDN Git Service

bf5b779aa8a94d64ac622d64dcb8f9a141556675
[immortalwrt/immortalwrt.git] / target / linux / bcm53xx / base-files / etc / diag.sh
1 #!/bin/sh
2
3 . /lib/functions/leds.sh
4
5 get_status_led() {
6         local status_led_file
7
8         # There may be more than one color of power LED, try to avoid amber/red
9         status_led_file=$(find /sys/class/leds/ -name "*:power" -a ! -name "*:amber:*" -a ! -name "*:red:*" | head -n1)
10         if [ -d "$status_led_file" ]; then
11                 status_led=$(basename $status_led_file)
12                 return
13         fi;
14
15         # Now just pick any power LED
16         status_led_file=$(find /sys/class/leds/ -name "*:power" | head -n1)
17         if [ -d "$status_led_file" ]; then
18                 status_led=$(basename $status_led_file)
19                 return
20         fi;
21
22         # And finally, let's also try the device-Tree aliases node
23         status_led="$(get_dt_led status)"
24 }
25
26 set_state() {
27         get_status_led
28
29         [ -z "$status_led" ] && return
30
31         case "$1" in
32         preinit)
33                 status_led_blink_preinit
34                 ;;
35         failsafe)
36                 status_led_blink_failsafe
37                 ;;
38         preinit_regular)
39                 status_led_blink_preinit_regular
40                 ;;
41         done)
42                 status_led_on
43                 ;;
44         esac
45 }