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 echo "$timer" >$keypress_sec
38 lock -u $keypress_wait
42 [ "$pi_preinit_no_failsafe" != "y" ] && echo "Press the [$1] key and hit [enter] $2"
43 echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level"
44 # if we're on the console we wait for input
46 while [ -r $keypress_wait ]; do
47 timer="$(cat $keypress_sec)"
49 [ -n "$timer" ] || timer=1
51 [ $timer -ge 1 ] || timer=1
54 read -t "$timer" do_keypress
55 case "$do_keypress" in
57 echo "true" >$keypress_true
60 echo "$do_keypress" >/tmp/debug_level
66 lock -u $keypress_wait
71 lock -w $keypress_wait
74 [ "$(cat $keypress_true)" = "true" ] && keypressed=0
85 [ "$pi_preinit_no_failsafe" == "y" ] && {
86 fs_wait_for_key "" "" $fs_failsafe_wait_timeout
89 grep -q 'failsafe=' /proc/cmdline && FAILSAFE=true && export FAILSAFE
90 if [ "$FAILSAFE" != "true" ]; then
91 pi_failsafe_net_message=true
92 preinit_net_echo "Please press button now to enter failsafe"
93 pi_failsafe_net_message=false
94 fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true
95 [ -f "/tmp/failsafe_button" ] && FAILSAFE=true && echo "- failsafe button "`cat /tmp/failsafe_button`" was pressed -"
96 [ "$FAILSAFE" = "true" ] && export FAILSAFE && touch /tmp/failsafe
100 boot_hook_add preinit_main failsafe_wait