2 # Copyright (C) 2006-2010 OpenWrt.org
3 # Copyright (C) 2010 Vertical Communications
9 local keypress_true
="$(mktemp)"
10 local keypress_wait
="$(mktemp)"
11 local keypress_sec
="$(mktemp)"
12 if [ -z "$keypress_wait" ]; then
13 keypress_wait
=/tmp
/.keypress_wait
16 if [ -z "$keypress_true" ]; then
17 keypress_true
=/tmp
/.keypress_true
20 if [ -z "$keypress_sec" ]; then
21 keypress_sec
=/tmp
/.keypress_sec
25 trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" INT
26 trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" USR1
28 [ -n "$timeout" ] || timeout
=1
29 [ $timeout -ge 1 ] || timeout
=1
33 while [ $timer -gt 0 ]; do
34 pi_failsafe_net_message
=true \
35 preinit_net_echo
"Please press button now to enter failsafe"
36 echo "$timer" >$keypress_sec
40 lock
-u $keypress_wait
44 [ "$pi_preinit_no_failsafe" != "y" ] && echo "Press the [$1] key and hit [enter] $2"
45 echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level"
46 # if we're on the console we wait for input
48 while [ -r $keypress_wait ]; do
49 timer
="$(cat $keypress_sec)"
51 [ -n "$timer" ] || timer
=1
53 [ $timer -ge 1 ] || timer
=1
56 read -t "$timer" do_keypress
57 case "$do_keypress" in
59 echo "true" >$keypress_true
62 echo "$do_keypress" >/tmp
/debug_level
68 lock
-u $keypress_wait
73 lock
-w $keypress_wait
76 [ "$(cat $keypress_true)" = "true" ] && keypressed
=0
87 [ "$pi_preinit_no_failsafe" = "y" ] && {
88 fs_wait_for_key
"" "" $fs_failsafe_wait_timeout
91 grep -q 'failsafe=' /proc
/cmdline
&& FAILSAFE
=true
&& export FAILSAFE
92 if [ "$FAILSAFE" != "true" ]; then
93 fs_wait_for_key f
'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE
=true
94 [ -f "/tmp/failsafe_button" ] && FAILSAFE
=true
&& echo "- failsafe button "`cat /tmp/failsafe_button`" was pressed -"
95 [ "$FAILSAFE" = "true" ] && export FAILSAFE
&& touch /tmp
/failsafe
99 boot_hook_add preinit_main failsafe_wait