From b561fdaec9ea1a647cf66aec19fbf83237a2868c Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Mon, 31 Jul 2023 18:34:50 +0900 Subject: [PATCH] buildroot: specify an override directory to add files into the buildroot rootfs --- buildroot | 2 +- os-buildroot/override/root/blink.sh | 74 +++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 os-buildroot/override/root/blink.sh diff --git a/buildroot b/buildroot index e39044f..cf3ea90 160000 --- a/buildroot +++ b/buildroot @@ -1 +1 @@ -Subproject commit e39044fa44394042e22f503fb53ba96122956bce +Subproject commit cf3ea901082f470449bd174272d8407e039522b2 diff --git a/os-buildroot/override/root/blink.sh b/os-buildroot/override/root/blink.sh new file mode 100755 index 0000000..00f125e --- /dev/null +++ b/os-buildroot/override/root/blink.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +set -u + +if [ $# -ne 3 ]; then + echo "Usage: blink.sh RANGE_FROM RANGE_TO SLEEP" + exit 1 +fi + +if [ "$(id -u)" -ne "0" ]; then + echo "Error: please run as root" + exit 1 +fi + +FROM=$1 +TO=$2 +SLEEP=$3 +GPIOS=$(seq $FROM $TO) +AVAILABLE_GPIOS="" + +export_gpio() { + echo $1 > /sys/class/gpio/export +} + +set_direction() { + echo out > /sys/class/gpio/gpio$1/direction +} + +set_value() { + echo $2 > /sys/class/gpio/gpio$1/value +} + +for i in $GPIOS; do + if [ ! -e "/sys/class/gpio/gpio$i" ]; then + export_gpio $i 2>/dev/null + if [ $? -ne 0 ]; then + echo "Error: failed to export the pin $i" + continue + fi + fi + + set_direction $i 2>/dev/null + if [ $? -ne 0 ]; then + # Ignore the failure if the actual direction is out + if grep -vq "out" /dsys/class/gpio/gpio$i/direction; then + echo "Error: failed to set the direction of the pin $i to out" + continue + fi + fi + + AVAILABLE_GPIOS="$AVAILABLE_GPIOS$i " +done + +echo "Available GPIOs: $AVAILABLE_GPIOS" + +while [ 1 ]; do + for i in $AVAILABLE_GPIOS; do + set_value $i 1 2>/dev/null + if [ $? -ne 0 ]; then + echo "Warning: failed to set the value of the pin $i to high" + fi + done + + sleep $SLEEP + + for i in $AVAILABLE_GPIOS; do + set_value $i 0 2>/dev/null + if [ $? -ne 0 ]; then + echo "Warning: failed to set the value of the pin $i to low" + fi + done + + sleep $SLEEP +done