aboutsummaryrefslogtreecommitdiff
path: root/misc/raspberrypi-gpioshutdown
diff options
context:
space:
mode:
authorSteve Wills <swills@FreeBSD.org>2018-08-29 17:30:03 +0000
committerSteve Wills <swills@FreeBSD.org>2018-08-29 17:30:03 +0000
commit32078c8a43d71201284a07ddd0fa694228cb6d51 (patch)
tree6b545f2555e80e74cc7cc3ad777f907f82cd76ed /misc/raspberrypi-gpioshutdown
parent04c5ee837c6bc5b89878c96f1bfda9c036ae4273 (diff)
downloadports-32078c8a43d71201284a07ddd0fa694228cb6d51.tar.gz
ports-32078c8a43d71201284a07ddd0fa694228cb6d51.zip
Notes
Diffstat (limited to 'misc/raspberrypi-gpioshutdown')
-rw-r--r--misc/raspberrypi-gpioshutdown/Makefile26
-rw-r--r--misc/raspberrypi-gpioshutdown/distinfo3
-rw-r--r--misc/raspberrypi-gpioshutdown/files/gpioshutdown.in129
-rw-r--r--misc/raspberrypi-gpioshutdown/pkg-descr12
-rw-r--r--misc/raspberrypi-gpioshutdown/pkg-message20
-rw-r--r--misc/raspberrypi-gpioshutdown/pkg-plist2
6 files changed, 192 insertions, 0 deletions
diff --git a/misc/raspberrypi-gpioshutdown/Makefile b/misc/raspberrypi-gpioshutdown/Makefile
new file mode 100644
index 000000000000..70eaf9a36230
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/Makefile
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+PORTNAME= raspberrypi-gpioshutdown
+DISTVERSION= 1.0
+CATEGORIES= misc
+MASTER_SITES= http://mrp3.com/
+
+MAINTAINER= bobf@mrp3.com
+COMMENT= Kernel driver to reset GPIO pins on shutdown for Raspberry Pi
+
+LICENSE= BSD2CLAUSE
+
+ONLY_FOR_ARCHS= armv6 armv7
+
+KMODNAME= gpioshutdown
+USES= kmod
+USE_RC_SUBR= ${KMODNAME}
+
+.include <bsd.port.options.mk>
+
+do-install:
+ ${INSTALL_KLD} ${WRKSRC}/${KMODNAME}.ko ${STAGEDIR}${KMODDIR}
+ ${GZIP_CMD} ${WRKSRC}/gpioshutdown.4
+ ${INSTALL} ${WRKSRC}/gpioshutdown.4.gz ${STAGEDIR}${LOCALBASE}/man/man4/gpioshutdown.4.gz
+
+.include <bsd.port.mk>
diff --git a/misc/raspberrypi-gpioshutdown/distinfo b/misc/raspberrypi-gpioshutdown/distinfo
new file mode 100644
index 000000000000..667aaef46c81
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1521490257
+SHA256 (raspberrypi-gpioshutdown-1.0.tar.gz) = 25d647309b54d253a11e7ae74998a7d382ce3a9fddb6bd7adace67f0d4f83c9f
+SIZE (raspberrypi-gpioshutdown-1.0.tar.gz) = 7320
diff --git a/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in b/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in
new file mode 100644
index 000000000000..c2f9a169eb2a
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in
@@ -0,0 +1,129 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+# PROVIDE: gpioshutdown
+# REQUIRE: syslogd
+# BEFORE: LOGIN
+# KEYWORD: shutdown
+
+. /etc/rc.subr
+
+name="gpioshutdown"
+start_cmd=${name}_start
+unload_cmd=${name}_unload
+reload_cmd=${name}_reload
+stop_cmd=${name}_stop
+rcvar=${name}_enable
+extra_commands="unload reload"
+
+## Set defaults
+
+load_rc_config $name
+: ${gpioshutdown_enable:="NO"}
+: ${gpioshutdown_led_pin:="auto"}
+: ${gpioshutdown_led_pin_set:="1"}
+
+
+gpioshutdown_get_led_pin()
+{
+ if test "${gpioshutdown_led_pin}" == "auto" ; then
+ if test -e /dev/led/pwr -o -e /dev/led/PWR ; then
+ __led_pin=`ofwdump -P gpios /leds/pwr | grep -v "gpios:" | grep -v "Node" | \
+ awk 'function hexdigit(x) { xx = index("0123456789ABCDEF",toupper(x)) - 1; return xx; }
+ function hexval(x) { return hexdigit(substr(x,1,1)) * 16 + hexdigit(substr(x,2,1)); }
+ { print hexval($5) * 65536 * 256 + hexval($6) * 65536 + hexval($7) * 256 + hexval($8); }'`
+ __led_pin_set="1"
+ elif test -e /dev/led/ok -o -e /dev/led/OK ; then
+ __led_pin=`ofwdump -P gpios /leds/ok | grep -v "gpios:" | grep -v "Node" | \
+ awk 'function hexdigit(x) { xx = index("0123456789ABCDEF",toupper(x)) - 1; return xx; }
+ function hexval(x) { return hexdigit(substr(x,1,1)) * 16 + hexdigit(substr(x,2,1)); }
+ { print hexval($5) * 65536 * 256 + hexval($6) * 65536 + hexval($7) * 256 + hexval($8); }'`
+ __led_pin_set="0"
+ else
+ __led_pin=""
+ __led_pin_set=""
+ fi
+ else
+ if test -z "${gpioshutdown_led_pin}" ; then
+ __led_pin=""
+ __led_pin_set=""
+ else
+ __led_pin=`expr "${gpioshutdown_led_pin}" + 0`
+ __led_pin_set=`expr "${gpioshutdown_led_pin_set}" + 0`
+ fi
+ fi
+
+ if test -z "$__led_pin" ; then
+ echo ""
+ else
+ echo "$__led_pin $__led_pin_set"
+ fi
+}
+
+gpioshutdown_enable_led_pin()
+{
+ led_pin="$1"
+ led_pin_set="$2"
+
+ sysctl kern.gpioshutdown.led_gpio=${led_pin}
+ sysctl kern.gpioshutdown.led_gpio_set=${led_pin_set}
+
+ gpioctl -c ${led_pin} OUT
+ gpioctl ${led_pin} ${led_pin_set}
+}
+
+gpioshutdown_start()
+{
+ if ( kldstat -q -m gpioshutdown ) ; then
+ echo "gpioshutdown installed" ;
+ else
+ echo "installing gpioshutdown"
+ kldload gpioshutdown.ko
+ fi
+
+ led_pin=`gpioshutdown_get_led_pin`
+
+ if test -n "$led_pin" ; then
+ gpioshutdown_enable_led_pin ${led_pin}
+ fi
+}
+
+# 'stop' assumes system shutdown and does NOT
+gpioshutdown_stop()
+{
+ echo "gpioshutdown - system shutdown"
+ echo "(kernel module NOT unloading; use 'unload' if you want to unload it)"
+}
+
+gpioshutdown_unload()
+{
+ led_pin=`sysctl kern.gpioshutdown.led_gpio | awk '{ print $2; }'`
+
+ if test -n "$led_pin" ; then
+ # disable the pin [this is a 'safe mode' way of doing it]
+ sysctl kern.gpioshutdown.led_gpio=-1
+
+ # LED was enabled - turn it back into an input
+ if test -n "$led_pin" ; then
+ if test "$led_pin" -ge 0 ; then
+ gpioctl -c ${led_pin} IN
+ fi
+ fi
+ fi
+
+ if ( kldstat -q -m gpioshutdown ) ; then
+ echo "unloading gpioshutdown" ;
+ kldunload gpioshutdown
+ else
+ echo "gpioshutdown module not loaded"
+ fi
+}
+
+gpioshutdown_reload()
+{
+ gpioshutdown_unload
+ gpioshutdown_start
+}
+
+run_rc_command "$1"
diff --git a/misc/raspberrypi-gpioshutdown/pkg-descr b/misc/raspberrypi-gpioshutdown/pkg-descr
new file mode 100644
index 000000000000..df9f5be61bad
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/pkg-descr
@@ -0,0 +1,12 @@
+GPIO 'shutdown' Kernel module for the Raspberry Pi Model 1B and Model 2
+
+The purpose of this module is to shut down all GPIOs prior to powering off
+or rebooting a Raspberry Pi.
+
+The main reason for this is due to there being no real indicators that the
+shutdown process has completed. By doing a shutdown of all of the GPIOs (such
+that they act like inputs without pullup resistors), you can detect the 'high
+impedence' state either with an LED or using some kind of exernal board (such
+as an 'ATX Raspi' board). An external board could then detect the shutdown,
+and power off the Raspberry Pi safely, and you won't have to fix the file
+system due to problems caused by powering it down before it's safe to do so.
diff --git a/misc/raspberrypi-gpioshutdown/pkg-message b/misc/raspberrypi-gpioshutdown/pkg-message
new file mode 100644
index 000000000000..ea5e13999adf
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/pkg-message
@@ -0,0 +1,20 @@
+raspberrypi-gpioshutdown kernel module:
+
+This port installs a startup script in your ${LOCALBASE} etc/rc.d directory
+called 'gpioshutdown'.
+
+Once installed, either load the kernel module at boot time (using
+/boot/loader.conf) or by adding the following entry to the /etc/rc.conf file
+(recommended) by running this command:
+
+ sysrc gpioshutdown_enable="YES"
+
+Or, you can simply load the module using the 'rc' system, by adding this
+line to /etc/rc.conf instead:
+
+ kld_list=gpioshutdown
+
+If you have other modules in 'kld_list' just add 'gpioshutdown' to the end of
+that list.
+
+For more detailed information, type 'man 4 gpioshutdown'.
diff --git a/misc/raspberrypi-gpioshutdown/pkg-plist b/misc/raspberrypi-gpioshutdown/pkg-plist
new file mode 100644
index 000000000000..cf5dbebe7c6c
--- /dev/null
+++ b/misc/raspberrypi-gpioshutdown/pkg-plist
@@ -0,0 +1,2 @@
+/%%KMODDIR%%/gpioshutdown.ko
+man/man4/gpioshutdown.4.gz