slitaz-arm annotate rpi/tazberry @ rev 147

TazBerry: add support for updating SliTaz raspberry Pi custom Kernel
author Christophe Lincoln <pankso@slitaz.org>
date Wed Apr 30 16:27:48 2014 +0200 (2014-04-30)
parents 9d4ba98c2bc7
children 7cb91f467e98
rev   line source
pankso@44 1 #!/bin/sh
pankso@44 2 #
pankso@44 3 # TazBerry - SliTaz Raspberry Pi Config Tool
pankso@44 4 #
pankso@44 5 # Copyright (C) 2014 SliTaz ARM - BSD License
pankso@44 6 # Author: Christophe Lincoln <pankso@slitaz.org>
pankso@44 7 #
pankso@44 8 . /lib/libtaz.sh
pankso@137 9 check_root
pankso@44 10
pankso@44 11 title="{ TazBerry }"
pankso@44 12 config="/boot/config.txt"
pankso@44 13 tmpdir="/tmp/tazberry"
pankso@44 14 tmp="$tmpdir/$$"
pankso@44 15 height="20"
pankso@44 16 width="72"
pankso@44 17
pankso@147 18 # Mirror URL
pankso@147 19 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
pankso@147 20
pankso@44 21 # Use a tmp directory
pankso@44 22 mkdir -p ${tmpdir}
pankso@44 23
pankso@44 24 # Small built-in help
pankso@44 25 help() {
pankso@44 26 cat << EOT
pankso@44 27
pankso@44 28 $(boldify "$(gettext 'Usage:')") $(basename $0) [command|rpi_function]
pankso@44 29
pankso@44 30 $(boldify "$(gettext 'Commands:')")
pankso@122 31 oclock $(gettext 'Configure overclocking')
pankso@134 32 cam-setup $(gettext 'Configure your Pi to use the Camera')
pankso@44 33 ls-functions $(gettext 'List TazBerry functions')
pankso@105 34 rpi_ $(gettext 'Execute any tazberry_function')
pankso@44 35 testsuite $(gettext 'Run TazBerry testsuite')
pankso@44 36
pankso@44 37 EOT
pankso@44 38 }
pankso@44 39
pankso@44 40 #
pankso@44 41 # RPi functions
pankso@44 42 #
pankso@44 43
paul@65 44 # This could move to /usr/bin/slitaz-??? or something since it's not
pankso@58 45 # ARM specific
pankso@44 46 rpi_stats() {
pankso@58 47 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
pankso@58 48 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
pankso@58 49 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
pankso@58 50 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
pankso@44 51 cat << EOT
pankso@67 52 $(gettext 'Kernel') : $(uname -snrm)
pankso@67 53 $(gettext 'Uptime') : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
pankso@67 54 $(gettext 'Network IP') : $(echo $ip | awk '{print $1}')
pankso@67 55 $(gettext 'CPU heat') : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
pankso@67 56 $(gettext 'Processes') : $(ps | wc -l)
pankso@67 57 $(gettext 'Memory usage') : ${mem_used_pct}%
pankso@44 58 EOT
pankso@44 59 }
pankso@44 60
pankso@44 61 rpi_turbo() {
pankso@44 62 if ! fgrep -q 'force_turbo=1' ${config}; then
pankso@44 63 gettext "Enabling Raspberry Pi force turbo..."
pankso@44 64 echo "force_turbo=1" >> ${config}; status
pankso@44 65 else
pankso@44 66 gettext "Disabling Raspberry Pi force turbo..."
pankso@44 67 sed -i '/force_turbo=1/'d ${config}; status
pankso@44 68 fi
pankso@44 69 }
pankso@44 70
pankso@44 71 # RPi Overclocking
pankso@44 72 rpi_oclock() {
pankso@44 73 cat << EOT
pankso@44 74 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
pankso@44 75 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
pankso@44 76 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
pankso@44 77 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
pankso@44 78 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
pankso@44 79 EOT
pankso@44 80 }
pankso@44 81
pankso@147 82 # Update custom Raspberry Pi Kernel
pankso@147 83 rpi_linux_up() {
pankso@147 84 cache="/var/cache/tazpkg"
pankso@147 85 gettext "Updating Raspberry Pi Linux kernel..."; echo
pankso@147 86 mkdir -p ${cache}
pankso@147 87
pankso@147 88 # Last version
pankso@147 89 rm -f ${cache}/linux-version.txt
pankso@147 90 if busybox wget -q -s ${rpi_mirror}/packages/last-linux.txt; then
pankso@147 91 echo -n "Fetching latest Kernel string..."
pankso@147 92 wget -q ${rpi_mirror}/packages/last-linux.txt \
pankso@147 93 -O ${cache}/linux-version.txt || exit 1
pankso@147 94 status
pankso@147 95 else
pankso@147 96 gettext "Mirror is unreachable"; echo && exit 1
pankso@147 97 fi
pankso@147 98 kvers=$(cat $cache/linux-version.txt)
pankso@147 99 rm -rf ${cache}/linux-${kvers}*
pankso@147 100 gettext "Kernel version: $kvers"; echo
pankso@147 101
pankso@147 102 # Download
pankso@147 103 gettext "Fetching latest Linux package..."
pankso@147 104 wget -q ${rpi_mirror}/packages/linux-${kvers}.tazpkg \
pankso@147 105 -O ${cache}/linux-${kvers}.tazpkg; status
pankso@147 106
pankso@147 107 # Install
pankso@147 108 if [ -f "$cache/linux-$kvers.tazpkg" ]; then
pankso@147 109 cd ${cache} && spk-add linux-${kvers}.tazpkg
pankso@147 110 else
pankso@147 111 gettext "Kernel update failed..."; echo
pankso@147 112 fi
pankso@147 113 rm -f ${cache}/linux-version.txt
pankso@147 114 }
pankso@147 115
pankso@122 116 # Unset overclocking
pankso@122 117 unset_oclock() {
pankso@122 118 debug "unset_oclock"
pankso@122 119 sed -i \
pankso@122 120 -e '/# Overclocking.*/'d \
pankso@122 121 -e '/arm_freq=/'d \
pankso@122 122 -e '/core_freq=/'d \
pankso@122 123 -e '/sdram_freq=/'d \
pankso@122 124 -e '/over_voltage=/'d ${config}
pankso@122 125 # Remove if 3 empty lines follows
pankso@122 126 sed -i '1N;N;/^\n\n$/d;P;D' ${config}
pankso@122 127 }
pankso@122 128
pankso@122 129 # Set overclocking: set_oclock [mode]
pankso@122 130 set_oclock() {
pankso@122 131 debug "set_oclock $1"
pankso@122 132 case "$1" in
pankso@122 133 none)
pankso@122 134 arm_freq=700
pankso@122 135 core_freq=250
pankso@122 136 sdram_freq=400
pankso@122 137 over_voltage=0 ;;
pankso@122 138 modest)
pankso@122 139 arm_freq=800
pankso@122 140 core_freq=300
pankso@122 141 sdram_freq=400
pankso@122 142 over_voltage=0 ;;
pankso@122 143 medium)
pankso@122 144 arm_freq=900
pankso@122 145 core_freq=333
pankso@122 146 sdram_freq=450
pankso@122 147 over_voltage=2 ;;
paul@127 148 high)
pankso@122 149 arm_freq=950
pankso@122 150 core_freq=450
pankso@122 151 sdram_freq=450
pankso@122 152 over_voltage=6 ;;
pankso@122 153 turbo)
pankso@122 154 arm_freq=1000
pankso@122 155 core_freq=500
pankso@122 156 sdram_freq=500
pankso@122 157 over_voltage=6 ;;
pankso@122 158 esac
pankso@122 159 unset_oclock
pankso@122 160 cat >> ${config} << EOT
pankso@122 161 # Overclocking Settings
pankso@122 162 arm_freq=$arm_freq
pankso@122 163 core_freq=$core_freq
pankso@122 164 sdram_freq=$sdram_freq
pankso@122 165 over_voltage=$over_voltage
pankso@122 166
pankso@122 167 EOT
pankso@122 168 }
pankso@122 169
pankso@147 170 tazberry_back() {
pankso@147 171 gettext "Press ENTER to go back to TazBerry"; read ;;
pankso@147 172 }
pankso@147 173
pankso@44 174 #
pankso@44 175 # GUI Functions
pankso@44 176 #
pankso@44 177
pankso@44 178 # Usage: msg_box "title" "message"
pankso@44 179 msg_box() {
pankso@44 180 dialog --title "{ $1 }" --cr-wrap \
pankso@44 181 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width}
pankso@44 182 }
pankso@44 183
pankso@44 184 # Usage: text_box "file"
pankso@44 185 text_box() {
pankso@44 186 local file="$1"
pankso@44 187 if [ -f "$file" ]; then
pankso@44 188 dialog --cr-wrap \
pankso@115 189 --title "{ $(gettext 'Viewing file:') $file }" \
pankso@44 190 --extra-button \
pankso@44 191 --extra-label "Edit file" \
pankso@44 192 --ok-label "TazBerry" \
pankso@44 193 --textbox ${file} ${height} ${width}
pankso@44 194 else
pankso@44 195 dialog --title "$title" \
pankso@44 196 --msgbox "\nERROR: $file does not exist" 10 ${width}
pankso@44 197 fi
pankso@44 198 # Handle options
pankso@44 199 case "$?" in
pankso@73 200 3) editor ${file} ;;
pankso@44 201 esac
pankso@44 202 }
pankso@44 203
pankso@44 204 # Usage: tail_box "file"
pankso@44 205 tail_box() {
pankso@115 206 dialog --title "{ $(gettext 'Watching file:') $2 }" \
pankso@44 207 --tailbox "$1" ${height} ${width}
pankso@44 208 }
pankso@44 209
pankso@44 210 # Packages info and spk-up button
pankso@44 211 pkgs_box() {
pankso@44 212 out="$tmpdir/spk-info.txt"
pankso@44 213 spk info --output=raw > ${out}
pankso@44 214 dialog --cr-wrap \
pankso@44 215 --title "{ $(gettext 'Packages') }" \
pankso@44 216 --extra-button \
pankso@44 217 --extra-label "$(gettext 'Upgrade')" \
pankso@44 218 --ok-label "TazBerry" \
pankso@44 219 --textbox "$out" ${height} ${width}
pankso@44 220 # Handle options
pankso@44 221 case "$?" in
pankso@147 222 3) spk-up && tazberry_back ;;
pankso@44 223 esac
pankso@44 224 }
pankso@44 225
pankso@122 226 # Overclocking info TODO: button to setup
pankso@44 227 oclock_box() {
pankso@122 228 mode=$(fgrep arm_freq ${config} | cut -d '=' -f 2)
pankso@122 229 case "$mode" in
pankso@122 230 700) mode="none" ;;
pankso@122 231 800) mode="modest" ;;
pankso@122 232 900) mode="medium" ;;
pankso@122 233 950) mode="high" ;;
pankso@122 234 1000) mode="turbo" ;;
pankso@122 235 esac
pankso@122 236 dialog \
pankso@122 237 --clear --colors \
pankso@122 238 --extra-button \
pankso@122 239 --title "{ Overclocking }" \
pankso@44 240 --ok-label "TazBerry" \
pankso@122 241 --extra-label "Set Overclock" \
pankso@122 242 --cancel-label "Unset Oclock" \
paul@127 243 --menu "\nSet Raspberry Pi overclocking, current setting: \Zb\Z2$mode" \
pankso@122 244 ${height} ${width} 14 \
pankso@122 245 "none" "700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt" \
pankso@122 246 "modest" "800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt" \
pankso@122 247 "medium" "900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt" \
pankso@122 248 "high" "950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt" \
pankso@122 249 "turbo" "1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt" 2>${tmp}
pankso@122 250 retval="$?"
pankso@122 251 mode=$(cat $tmp)
pankso@122 252 case "$retval" in
pankso@122 253 0) continue ;;
pankso@122 254 1) unset_oclock ;;
pankso@122 255 3) set_oclock "$mode" ;;
pankso@122 256 255) rm -rf ${tmpdir} && exit 0 ;;
pankso@122 257 esac
pankso@44 258 }
pankso@44 259
pankso@105 260 gpu_mem_box() {
pankso@105 261 dialog \
pankso@105 262 --clear \
pankso@105 263 --title "$title" \
pankso@105 264 --ok-label "Set mem" \
pankso@105 265 --cancel-label "TazBerry" \
paul@108 266 --menu "\nSet the memory allocated to the GPU (in MB)" \
pankso@105 267 ${height} ${width} 14 \
pankso@105 268 "16" "For server, NAS, base system without X" \
pankso@105 269 "32" "For very small TFT and TV display" \
pankso@105 270 "64" "Default value, fine for low latency desktop" \
pankso@105 271 "128" "For a faster desktop, using a video player" \
pankso@105 272 "256" "For media center, GL/3D applications" 2>${tmp}
pankso@105 273 mem=$(cat $tmp)
pankso@105 274 sed -i \
pankso@105 275 -e s"/#gpu_mem=.*/gpu_mem=$mem/" \
pankso@105 276 -e s"/gpu_mem=.*/gpu_mem=$mem/" /boot/config.txt
pankso@105 277 }
pankso@105 278
pankso@134 279 picam_setup() {
pankso@134 280 db="/var/lib/tazpkg/installed"
pankso@134 281 gpu_mem=128
pankso@134 282 pct="0"
pankso@134 283 {
pankso@134 284 # Needed packages
pankso@134 285 for pkg in raspberrypi-vc raspberrypi-boot-x
pankso@134 286 do
pankso@134 287 echo "XXX" && echo $((${pct} + 20))
pankso@134 288 echo -e "\nInstalling: $pkg"
pankso@134 289 echo "XXX"
pankso@142 290 [ -d "$db/$pkg" ] || spk-add ${pkg} >/dev/null 2>/dev/null
pankso@134 291 sleep 1
pankso@134 292 done
pankso@134 293
pankso@134 294 echo "XXX" && echo 60
pankso@134 295 echo -e "\nSetting up: ${config}"
pankso@134 296 echo "XXX" && sleep 1
pankso@134 297 # 0 to disable camera, 1 to enable it
pankso@134 298 if ! grep -q "start_x=1" ${config}; then
pankso@134 299 cat >> ${config} << EOT
pankso@134 300
pankso@134 301 # Camera settings
pankso@134 302 start_x=1
pankso@134 303
pankso@134 304 EOT
pankso@134 305 fi
pankso@134 306 # In case it was commented ot disabled
pankso@134 307 sed -i s'/#start_x=.*/start_x=1/' ${config}
pankso@134 308 sed -i s'/start_x=.*/start_x=1/' ${config}
pankso@134 309
pankso@134 310 # PiCam need 128 MB of GPU memory
pankso@134 311 echo "XXX" && echo 80
pankso@134 312 echo -e "\nSetting GPU memory to: ${gpu_mem}"
pankso@134 313 echo "XXX" && sleep 1
pankso@134 314
pankso@134 315 sed -i "s/#gpu_mem=.*/gpu_mem=${gpu_mem}/" ${config}
pankso@134 316 sed -i "s/gpu_mem=.*/gpu_mem=${gpu_mem}/" ${config}
pankso@134 317
pankso@134 318 echo "XXX" && echo 100
pankso@134 319 echo -e "\nPiCam config done..."
pankso@134 320 echo "XXX" && sleep 1
pankso@134 321
pankso@134 322 } | dialog --title "{ PiCam Setup }" \
pankso@134 323 --gauge "" 8 ${width} 0
pankso@134 324
pankso@134 325 # Reboot ?
pankso@134 326 dialog --title "$title" \
pankso@134 327 --yesno "\n\
pankso@134 328 SliTaz is configured for the PiCam but you need a reboot to use it.\
pankso@134 329 \n\n
pankso@134 330 Do You wish to reboot now ?" \
pankso@134 331 ${height} ${width}
pankso@141 332 [ "$?" == 0 ] && reboot
pankso@134 333 }
pankso@134 334
pankso@137 335 # Breakout bords!
pankso@137 336 boards_box() {
pankso@137 337 dialog \
pankso@137 338 --clear \
pankso@137 339 --title "$title" \
pankso@137 340 --ok-label "Exec" \
pankso@137 341 --cancel-label "Quit" \
pankso@137 342 --menu "\nSetup or use a breakout board" ${height} ${width} 14 \
pankso@137 343 "cam-setup" "$(gettext 'Configure your Pi to use a Camera')" \
pankso@137 344 "piglow" "$(gettext 'Setup your Pi to use PiGlow')" 2>${tmp}
pankso@137 345
pankso@137 346 # Handle options
pankso@137 347 case "$?" in
pankso@137 348 1|255) rm -rf ${tmpdir} && exit 0 ;;
pankso@137 349 esac
pankso@137 350
pankso@137 351 # Handle actions
pankso@137 352 action=$(cat $tmp)
pankso@137 353 case "$action" in
pankso@137 354 cam-setup)
pankso@137 355 picam_setup ;;
pankso@137 356 piglow)
pankso@137 357 for pkg in python-rpi-pyglow wiringpi-piglow; do
pankso@137 358 spk-add ${pkg}
pankso@137 359 done
pankso@137 360 newline
pankso@137 361 echo -n "Do you wish to try the leds [y/N] ? " ; read anser
pankso@137 362 [ "$anser" == "y" ] && echo "Enter a value between: 5-255" \
pankso@137 363 && pyglow test
pankso@137 364 esac
pankso@137 365 }
pankso@137 366
pankso@44 367 # Main Dialog menu
pankso@44 368 main_box() {
pankso@44 369 dialog \
pankso@44 370 --clear \
pankso@44 371 --title "$title" \
pankso@44 372 --ok-label "Exec" \
pankso@44 373 --cancel-label "Quit" \
pankso@44 374 --menu "" ${height} ${width} 14 \
pankso@44 375 "rpi-stats" "$(gettext 'Show some RPi system stats')" \
pankso@105 376 "gpu-mem" "$(gettext 'Set memory split between ARM and GPU')" \
pankso@137 377 "boards" "$(gettext 'Boards settings and tools (Camera, PyGlow)')" \
pankso@105 378 "act-led" "$(gettext 'Test the RPi onboard ACT green led')" \
pankso@122 379 "oclock" "$(gettext 'Overclocking configuration')" \
pankso@105 380 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \
pankso@88 381 "boot-cmdline" "$(gettext 'View boot args /boot/cmdline.txt')" \
pankso@88 382 "boot-config" "$(gettext 'View config file /boot/config.txt')" \
pankso@147 383 "linux-up" "$(gettext 'Update SliTaz Raspberry Pi Linux Kernel')" \
pankso@115 384 "packages" "$(gettext 'SliTaz packages manager') (spk)" \
pankso@115 385 "config" "$(gettext 'System config (lang, keyboard, wifi)')" \
pankso@122 386 "reboot" "$(gettext 'Reboot SliTaz system')" \
pankso@44 387 "halt" "$(gettext 'Halt the Raspberry Pi')" \
pankso@88 388 "quit" "$(gettext 'Exit TazBerry tool')" 2>${tmp}
pankso@44 389
pankso@44 390 # Handle options
pankso@105 391 case "$?" in
pankso@46 392 1|255) rm -rf ${tmpdir} && exit 0 ;;
pankso@44 393 esac
pankso@44 394
pankso@44 395 # Handle actions
pankso@44 396 action=$(cat $tmp)
pankso@44 397 case "$action" in
pankso@44 398 rpi-stats)
pankso@44 399 msg_box "RPi Stats" "$(rpi_stats)" ;;
pankso@105 400 gpu-mem)
pankso@105 401 gpu_mem_box ;;
pankso@137 402 boards)
pankso@137 403 boards_box ;;
pankso@105 404 act-led)
pankso@105 405 brightness="/sys/class/leds/led0/brightness"
pankso@105 406 (echo "1" > ${brightness}
pankso@105 407 sleep 3; echo "0" > ${brightness}) & ;;
pankso@100 408 oclock)
pankso@100 409 oclock_box ;;
pankso@44 410 rpi-turbo)
pankso@44 411 rpi_turbo && newline
pankso@147 412 tazberry_back ;;
pankso@105 413 boot-cmdline)
pankso@105 414 text_box /boot/cmdline.txt ;;
pankso@105 415 boot-config)
pankso@105 416 text_box ${config} ;;
pankso@147 417 linux-up)
pankso@147 418 rpi_linux_up
pankso@147 419 tazberry_back ;;
pankso@44 420 packages)
pankso@88 421 spk-dialog ;;
pankso@88 422 config)
pankso@88 423 slitaz-config ;;
pankso@44 424 reboot)
pankso@44 425 reboot ;;
pankso@44 426 halt)
pankso@115 427 poweroff ;;
pankso@44 428 quit)
pankso@44 429 rm -rf ${tmpdir} && exit 0 ;;
pankso@44 430 esac
pankso@44 431 }
pankso@44 432
pankso@44 433 # Progress bar testsuite
pankso@44 434 gauge_box() {
pankso@44 435 { for i in $(seq 1 100); do
pankso@44 436 echo $i
pankso@44 437 sleep 0.01
pankso@44 438 done
pankso@44 439 echo 100; } | dialog --title "{ TazBerry }" \
pankso@44 440 --gauge "Work in progress..." 6 ${width} 0
pankso@44 441 }
pankso@44 442
pankso@44 443 #
pankso@44 444 # Handle commands
pankso@44 445 #
pankso@44 446
pankso@44 447 case "$1" in
pankso@44 448 oclock)
pankso@122 449 oclock_box ;;
pankso@44 450
pankso@134 451 cam-setup)
pankso@134 452 picam_setup ;;
pankso@134 453
pankso@44 454 ls-functions)
pankso@44 455 newline
pankso@44 456 boldify "$(gettext 'TazBerry functions list')"
pankso@44 457 separator
pankso@44 458 grep "^rpi_*" $0 | awk '{print " ", $1}'
pankso@44 459 newline ;;
pankso@44 460
pankso@44 461 testsuite)
pankso@44 462 gauge_box
pankso@44 463 msg_box "Testsuite" "Test message"
pankso@44 464 rpi_stats
pankso@44 465 newline ;;
pankso@44 466
pankso@44 467 rpi_*)
pankso@44 468 # Execute functions
pankso@44 469 $@ ;;
pankso@44 470
pankso@44 471 "")
pankso@44 472 # No args: display Ncurses dialog
pankso@44 473 while true; do
pankso@44 474 main_box
pankso@44 475 done ;;
pankso@44 476
pankso@44 477 *|*help|-h)
pankso@44 478 # Display help
pankso@44 479 help ;;
pankso@44 480 esac
pankso@44 481
pankso@44 482 # Clean exit
pankso@44 483 rm -rf ${tmpdir}
pankso@44 484 exit 0