add init script when overclocking that allows the user to opt out on boot

Current kernel builds default to the powersave cpufreq governor, with the
intention that this is changed to 'ondemand' after boot. When the user sets
overclock in raspi-config, an init script is installed which does this switch,
but only does it if it doesn't detect a shift key is held down. This means the
user can still boot the system if they set an overclock setting that is higher
than their device can manage.
This commit is contained in:
Alex Bradbury 2012-09-18 11:57:00 +01:00
parent c5e1966418
commit a8429795bf

View File

@ -220,6 +220,43 @@ set_overclock() {
set_config_var core_freq $3 /boot/config.txt &&
set_config_var sdram_freq $4 /boot/config.txt &&
set_config_var over_voltage $5 /boot/config.txt &&
# now set up an init.d script
cat <<\EOF > /etc/init.d/switch_cpu_governor &&
#!/bin/sh
### BEGIN INIT INFO
# Provides: switch_cpu_governor
# Required-Start: udev mountkernfs $remote_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Switch to ondemand cpu governor (unless shift key is pressed)
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Checking if shift key is held down"
timeout 1 thd --dump /dev/input/event* | grep -q "LEFTSHIFT\|RIGHTSHIFT"
if [ $? -eq 0 ]; then
printf " Yes. Not switching scaling governor"
log_end_msg 0
else
SYS_CPUFREQ_GOVERNOR=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
[ -e $SYS_CPUFREQ_GOVERNOR ] && echo "ondemand" > $SYS_CPUFREQ_GOVERNOR
printf " No. Switching to ondemand scaling governor"
log_end_msg 0
fi
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
EOF
chmod +x /etc/init.d/switch_cpu_governor &&
update-rc.d switch_cpu_governor defaults &&
whiptail --msgbox "Set overclock to preset '$1'" 20 60 2
}