slitaz-arm view rpi/tazberry @ rev 122

Full overcloking support in tazberry
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 21 10:59:25 2014 +0200 (2014-04-21)
parents 30880db2d56f
children 65b9b6991d94
line source
1 #!/bin/sh
2 #
3 # TazBerry - SliTaz Raspberry Pi Config Tool
4 #
5 # Copyright (C) 2014 SliTaz ARM - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 . /lib/libtaz.sh
10 title="{ TazBerry }"
11 config="/boot/config.txt"
12 tmpdir="/tmp/tazberry"
13 tmp="$tmpdir/$$"
14 height="20"
15 width="72"
17 # Use a tmp directory
18 mkdir -p ${tmpdir}
20 # Small built-in help
21 help() {
22 cat << EOT
24 $(boldify "$(gettext 'Usage:')") $(basename $0) [command|rpi_function]
26 $(boldify "$(gettext 'Commands:')")
27 oclock $(gettext 'Configure overclocking')
28 ls-functions $(gettext 'List TazBerry functions')
29 rpi_ $(gettext 'Execute any tazberry_function')
30 testsuite $(gettext 'Run TazBerry testsuite')
32 EOT
33 }
35 #
36 # RPi functions
37 #
39 # This could move to /usr/bin/slitaz-??? or something since it's not
40 # ARM specific
41 rpi_stats() {
42 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
43 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
44 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
45 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
46 cat << EOT
47 $(gettext 'Kernel') : $(uname -snrm)
48 $(gettext 'Uptime') : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
49 $(gettext 'Network IP') : $(echo $ip | awk '{print $1}')
50 $(gettext 'CPU heat') : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
51 $(gettext 'Processes') : $(ps | wc -l)
52 $(gettext 'Memory usage') : ${mem_used_pct}%
53 EOT
54 }
56 rpi_turbo() {
57 if ! fgrep -q 'force_turbo=1' ${config}; then
58 gettext "Enabling Raspberry Pi force turbo..."
59 echo "force_turbo=1" >> ${config}; status
60 else
61 gettext "Disabling Raspberry Pi force turbo..."
62 sed -i '/force_turbo=1/'d ${config}; status
63 fi
64 }
66 # RPi Overclocking
67 rpi_oclock() {
68 cat << EOT
69 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
70 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
71 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
72 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
73 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
74 EOT
75 }
77 # Unset overclocking
78 unset_oclock() {
79 debug "unset_oclock"
80 sed -i \
81 -e '/# Overclocking.*/'d \
82 -e '/arm_freq=/'d \
83 -e '/core_freq=/'d \
84 -e '/sdram_freq=/'d \
85 -e '/over_voltage=/'d ${config}
86 # Remove if 3 empty lines follows
87 sed -i '1N;N;/^\n\n$/d;P;D' ${config}
88 }
90 # Set overclocking: set_oclock [mode]
91 set_oclock() {
92 debug "set_oclock $1"
93 case "$1" in
94 none)
95 arm_freq=700
96 core_freq=250
97 sdram_freq=400
98 over_voltage=0 ;;
99 modest)
100 arm_freq=800
101 core_freq=300
102 sdram_freq=400
103 over_voltage=0 ;;
104 medium)
105 arm_freq=900
106 core_freq=333
107 sdram_freq=450
108 over_voltage=2 ;;
109 hight)
110 arm_freq=950
111 core_freq=450
112 sdram_freq=450
113 over_voltage=6 ;;
114 turbo)
115 arm_freq=1000
116 core_freq=500
117 sdram_freq=500
118 over_voltage=6 ;;
119 esac
120 unset_oclock
121 cat >> ${config} << EOT
122 # Overclocking Settings
123 arm_freq=$arm_freq
124 core_freq=$core_freq
125 sdram_freq=$sdram_freq
126 over_voltage=$over_voltage
128 EOT
129 }
131 #
132 # GUI Functions
133 #
135 # Usage: msg_box "title" "message"
136 msg_box() {
137 dialog --title "{ $1 }" --cr-wrap \
138 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width}
139 }
141 # Usage: text_box "file"
142 text_box() {
143 local file="$1"
144 if [ -f "$file" ]; then
145 dialog --cr-wrap \
146 --title "{ $(gettext 'Viewing file:') $file }" \
147 --extra-button \
148 --extra-label "Edit file" \
149 --ok-label "TazBerry" \
150 --textbox ${file} ${height} ${width}
151 else
152 dialog --title "$title" \
153 --msgbox "\nERROR: $file does not exist" 10 ${width}
154 fi
155 # Handle options
156 case "$?" in
157 3) editor ${file} ;;
158 esac
159 }
161 # Usage: tail_box "file"
162 tail_box() {
163 dialog --title "{ $(gettext 'Watching file:') $2 }" \
164 --tailbox "$1" ${height} ${width}
165 }
167 # Packages info and spk-up button
168 pkgs_box() {
169 out="$tmpdir/spk-info.txt"
170 spk info --output=raw > ${out}
171 dialog --cr-wrap \
172 --title "{ $(gettext 'Packages') }" \
173 --extra-button \
174 --extra-label "$(gettext 'Upgrade')" \
175 --ok-label "TazBerry" \
176 --textbox "$out" ${height} ${width}
177 # Handle options
178 case "$?" in
179 3) spk-up && gettext "Press ENTER to go back to TazBerry"; read ;;
180 esac
181 }
183 # Overclocking info TODO: button to setup
184 oclock_box() {
185 mode=$(fgrep arm_freq ${config} | cut -d '=' -f 2)
186 case "$mode" in
187 700) mode="none" ;;
188 800) mode="modest" ;;
189 900) mode="medium" ;;
190 950) mode="high" ;;
191 1000) mode="turbo" ;;
192 esac
193 dialog \
194 --clear --colors \
195 --extra-button \
196 --title "{ Overclocking }" \
197 --ok-label "TazBerry" \
198 --extra-label "Set Overclock" \
199 --cancel-label "Unset Oclock" \
200 --menu "\nSet Raspberry Pi overcloking, current setting: \Zb\Z2$mode" \
201 ${height} ${width} 14 \
202 "none" "700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt" \
203 "modest" "800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt" \
204 "medium" "900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt" \
205 "high" "950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt" \
206 "turbo" "1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt" 2>${tmp}
207 retval="$?"
208 mode=$(cat $tmp)
209 case "$retval" in
210 0) continue ;;
211 1) unset_oclock ;;
212 3) set_oclock "$mode" ;;
213 255) rm -rf ${tmpdir} && exit 0 ;;
214 esac
215 }
217 gpu_mem_box() {
218 dialog \
219 --clear \
220 --title "$title" \
221 --ok-label "Set mem" \
222 --cancel-label "TazBerry" \
223 --menu "\nSet the memory allocated to the GPU (in MB)" \
224 ${height} ${width} 14 \
225 "16" "For server, NAS, base system without X" \
226 "32" "For very small TFT and TV display" \
227 "64" "Default value, fine for low latency desktop" \
228 "128" "For a faster desktop, using a video player" \
229 "256" "For media center, GL/3D applications" 2>${tmp}
230 mem=$(cat $tmp)
231 sed -i \
232 -e s"/#gpu_mem=.*/gpu_mem=$mem/" \
233 -e s"/gpu_mem=.*/gpu_mem=$mem/" /boot/config.txt
234 }
236 # Main Dialog menu
237 main_box() {
238 dialog \
239 --clear \
240 --title "$title" \
241 --ok-label "Exec" \
242 --cancel-label "Quit" \
243 --menu "" ${height} ${width} 14 \
244 "rpi-stats" "$(gettext 'Show some RPi system stats')" \
245 "gpu-mem" "$(gettext 'Set memory split between ARM and GPU')" \
246 "act-led" "$(gettext 'Test the RPi onboard ACT green led')" \
247 "oclock" "$(gettext 'Overclocking configuration')" \
248 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \
249 "boot-cmdline" "$(gettext 'View boot args /boot/cmdline.txt')" \
250 "boot-config" "$(gettext 'View config file /boot/config.txt')" \
251 "packages" "$(gettext 'SliTaz packages manager') (spk)" \
252 "config" "$(gettext 'System config (lang, keyboard, wifi)')" \
253 "reboot" "$(gettext 'Reboot SliTaz system')" \
254 "halt" "$(gettext 'Halt the Raspberry Pi')" \
255 "quit" "$(gettext 'Exit TazBerry tool')" 2>${tmp}
257 # Handle options
258 case "$?" in
259 1|255) rm -rf ${tmpdir} && exit 0 ;;
260 esac
262 # Handle actions
263 action=$(cat $tmp)
264 case "$action" in
265 rpi-stats)
266 msg_box "RPi Stats" "$(rpi_stats)" ;;
267 gpu-mem)
268 gpu_mem_box ;;
269 act-led)
270 brightness="/sys/class/leds/led0/brightness"
271 (echo "1" > ${brightness}
272 sleep 3; echo "0" > ${brightness}) & ;;
273 oclock)
274 oclock_box ;;
275 rpi-turbo)
276 rpi_turbo && newline
277 gettext "Press ENTER to go back to TazBerry"; read ;;
278 boot-cmdline)
279 text_box /boot/cmdline.txt ;;
280 boot-config)
281 text_box ${config} ;;
282 packages)
283 spk-dialog ;;
284 config)
285 slitaz-config ;;
286 reboot)
287 reboot ;;
288 halt)
289 poweroff ;;
290 quit)
291 rm -rf ${tmpdir} && exit 0 ;;
292 esac
293 }
295 # Progress bar testsuite
296 gauge_box() {
297 { for i in $(seq 1 100); do
298 echo $i
299 sleep 0.01
300 done
301 echo 100; } | dialog --title "{ TazBerry }" \
302 --gauge "Work in progress..." 6 ${width} 0
303 }
305 #
306 # Handle commands
307 #
309 case "$1" in
310 oclock)
311 oclock_box ;;
313 ls-functions)
314 newline
315 boldify "$(gettext 'TazBerry functions list')"
316 separator
317 grep "^rpi_*" $0 | awk '{print " ", $1}'
318 newline ;;
320 testsuite)
321 gauge_box
322 msg_box "Testsuite" "Test message"
323 rpi_stats
324 newline ;;
326 rpi_*)
327 # Execute functions
328 $@ ;;
330 "")
331 # No args: display Ncurses dialog
332 while true; do
333 main_box
334 done ;;
336 *|*help|-h)
337 # Display help
338 help ;;
339 esac
341 # Clean exit
342 rm -rf ${tmpdir}
343 exit 0