From a261a1cd26335d182d2431f30c6aaa834db4b82b Mon Sep 17 00:00:00 2001 From: Mayeul Cantan Date: Thu, 22 Feb 2018 23:10:19 +0100 Subject: [PATCH] Add a maximum-attention hook to help with debugging boot issues (#1238) The hook flashes every LED it can find, as well as the vibration motor. More paths are probably necessary to support more devices and kernels. --- .../00-maximum-attention.sh | 56 +++++++++++++++++++ .../APKBUILD | 16 ++++++ 2 files changed, 72 insertions(+) create mode 100644 aports/main/postmarketos-mkinitfs-hook-maximum-attention/00-maximum-attention.sh create mode 100644 aports/main/postmarketos-mkinitfs-hook-maximum-attention/APKBUILD diff --git a/aports/main/postmarketos-mkinitfs-hook-maximum-attention/00-maximum-attention.sh b/aports/main/postmarketos-mkinitfs-hook-maximum-attention/00-maximum-attention.sh new file mode 100644 index 00000000..2d628cc5 --- /dev/null +++ b/aports/main/postmarketos-mkinitfs-hook-maximum-attention/00-maximum-attention.sh @@ -0,0 +1,56 @@ +#!/bin/sh +. ./init_functions.sh + +BLINK_INTERVAL=2 # seconds +VIBRATION_DURATION=400 #ms +VIBRATION_INTERVAL=2 #s + +find_leds() { + find /sys -name "max_brightness" | xargs -I{} dirname {} +} + +find_vibrator() { + echo /sys/class/timed_output/vibrator +} + + +# blink_leds takes a list of LEDs as parameters, +# it iterates over every LED, and changes their value, +# alternating between max_brightness and 0 every BLINK_INTERVAL +blink_leds() { + state=false # false = off, true=on + while true; do + for led in $@; do + if [ "$state" = true ]; then + cat $led/max_brightness > $led/brightness + else + echo 0 > $led/brightness + fi + echo blinking LED: $led + done + sleep ${BLINK_INTERVAL}s + if [ "$state" = true ]; then + state=false + else + state=true + fi + done +} + +# vibrate_loop vibrates each VIBRATION_INTERVAL for VIBRATION_DURATION +# it takes a timed_device path to the vibrator as $1 +vibrate_loop() { + if [ ! -f $1/enable ]; then + return; + fi + + while true; do + echo $VIBRATION_DURATION > $1/enable + sleep ${VIBRATION_INTERVAL}s + done +} + +blink_leds $(find_leds) & +vibrate_loop $(find_vibrator) & + +loop_forever diff --git a/aports/main/postmarketos-mkinitfs-hook-maximum-attention/APKBUILD b/aports/main/postmarketos-mkinitfs-hook-maximum-attention/APKBUILD new file mode 100644 index 00000000..da7a5df1 --- /dev/null +++ b/aports/main/postmarketos-mkinitfs-hook-maximum-attention/APKBUILD @@ -0,0 +1,16 @@ +pkgname=postmarketos-mkinitfs-hook-maximum-attention +pkgver=0.1.0 +pkgrel=0 +pkgdesc="Script to activate all user-visible outputs from the initramfs (to confirm working kernel, for debugging only)" +url="https://github.com/postmarketOS" +depends="postmarketos-mkinitfs" +source="00-maximum-attention.sh" +arch="noarch" +license="GPL2" + +package() { + mkdir -p "$pkgdir"/etc/postmarketos-mkinitfs/hooks/ + install -Dm644 "$srcdir"/00-maximum-attention.sh \ + "$pkgdir"/etc/postmarketos-mkinitfs/hooks/ +} +sha512sums="c29cc41649c284c0ec8201715cd9452f838801a22ea6c2a312ea87a58c61c1caa05a3b1ff33ce4a4d680a95e79fb10108308b72173f1fa97bac5cefde7ab30ee 00-maximum-attention.sh"