Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Aug 2018 17:30:03 +0000 (UTC)
From:      Steve Wills <swills@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r478362 - in head/misc: . raspberrypi-gpioshutdown raspberrypi-gpioshutdown/files
Message-ID:  <201808291730.w7THU3E6011895@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: swills
Date: Wed Aug 29 17:30:03 2018
New Revision: 478362
URL: https://svnweb.freebsd.org/changeset/ports/478362

Log:
  misc/raspberrypi-gpioshutdown: create port
  
  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.
  
  PR:		226787
  Submitted by:	Bob Frazier <bobf@mrp3.com>

Added:
  head/misc/raspberrypi-gpioshutdown/
  head/misc/raspberrypi-gpioshutdown/Makefile   (contents, props changed)
  head/misc/raspberrypi-gpioshutdown/distinfo   (contents, props changed)
  head/misc/raspberrypi-gpioshutdown/files/
  head/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in   (contents, props changed)
  head/misc/raspberrypi-gpioshutdown/pkg-descr   (contents, props changed)
  head/misc/raspberrypi-gpioshutdown/pkg-message   (contents, props changed)
  head/misc/raspberrypi-gpioshutdown/pkg-plist   (contents, props changed)
Modified:
  head/misc/Makefile

Modified: head/misc/Makefile
==============================================================================
--- head/misc/Makefile	Wed Aug 29 16:49:57 2018	(r478361)
+++ head/misc/Makefile	Wed Aug 29 17:30:03 2018	(r478362)
@@ -457,6 +457,7 @@
     SUBDIR += qt5-l10n
     SUBDIR += qt5ct
     SUBDIR += qtchooser
+    SUBDIR += raspberrypi-gpioshutdown
     SUBDIR += raspberrypi-userland
     SUBDIR += raspbsd-led
     SUBDIR += ree

Added: head/misc/raspberrypi-gpioshutdown/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/Makefile	Wed Aug 29 17:30:03 2018	(r478362)
@@ -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>

Added: head/misc/raspberrypi-gpioshutdown/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/distinfo	Wed Aug 29 17:30:03 2018	(r478362)
@@ -0,0 +1,3 @@
+TIMESTAMP = 1521490257
+SHA256 (raspberrypi-gpioshutdown-1.0.tar.gz) = 25d647309b54d253a11e7ae74998a7d382ce3a9fddb6bd7adace67f0d4f83c9f
+SIZE (raspberrypi-gpioshutdown-1.0.tar.gz) = 7320

Added: head/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/files/gpioshutdown.in	Wed Aug 29 17:30:03 2018	(r478362)
@@ -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"

Added: head/misc/raspberrypi-gpioshutdown/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/pkg-descr	Wed Aug 29 17:30:03 2018	(r478362)
@@ -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.

Added: head/misc/raspberrypi-gpioshutdown/pkg-message
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/pkg-message	Wed Aug 29 17:30:03 2018	(r478362)
@@ -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'.

Added: head/misc/raspberrypi-gpioshutdown/pkg-plist
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/misc/raspberrypi-gpioshutdown/pkg-plist	Wed Aug 29 17:30:03 2018	(r478362)
@@ -0,0 +1,2 @@
+/%%KMODDIR%%/gpioshutdown.ko
+man/man4/gpioshutdown.4.gz



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808291730.w7THU3E6011895>