# This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # raspberrypi-gpioshutdown # raspberrypi-gpioshutdown/pkg-plist # raspberrypi-gpioshutdown/pkg-message # raspberrypi-gpioshutdown/files # raspberrypi-gpioshutdown/files/gpioshutdown # raspberrypi-gpioshutdown/Makefile # raspberrypi-gpioshutdown/distinfo # raspberrypi-gpioshutdown/pkg-descr # echo c - raspberrypi-gpioshutdown mkdir -p raspberrypi-gpioshutdown > /dev/null 2>&1 echo x - raspberrypi-gpioshutdown/pkg-plist sed 's/^X//' >raspberrypi-gpioshutdown/pkg-plist << '247618a89fa643fab9923bef2938f969' X/%%KMODDIR%%/gpioshutdown.ko Xetc/rc.d/gpioshutdown Xman/man4/gpioshutdown.4.gz 247618a89fa643fab9923bef2938f969 echo x - raspberrypi-gpioshutdown/pkg-message sed 's/^X//' >raspberrypi-gpioshutdown/pkg-message << '6715dc25a0f60a67d6658043f9057efb' Xraspberrypi-gpioshutdown kernel module X XWARNING: this port installs a startup script in your ${LOCALBASE} X etc/rc.d directory called 'gpioshutdown'. X XOnce you've installed the port, you can either install the kernel module at Xboot time (using /boot/loader.conf) or by adding the following entry to the X/etc/rc.conf file (this is the recommended method): X X gpioshutdown_enable="YES" X XOr, you can simply load the module using the 'rc' system, by adding this Xline to /etc/rc.conf instead: X X kld_list=gpioshutdown X XNOTE: if you have other modules in 'kld_list' just add 'gpioshutdown' to the X end of that list. X Xfor more detailed information, type 'man 4 gpioshutdown'. X X 6715dc25a0f60a67d6658043f9057efb echo c - raspberrypi-gpioshutdown/files mkdir -p raspberrypi-gpioshutdown/files > /dev/null 2>&1 echo x - raspberrypi-gpioshutdown/files/gpioshutdown sed 's/^X//' >raspberrypi-gpioshutdown/files/gpioshutdown << '0fc6582bc92fb1a978e2208623bbe28d' X#!/bin/sh X# X# PROVIDE: gpioshutdown X# REQUIRE: syslogd X# BEFORE: LOGIN X# KEYWORD: shutdown X X. /etc/rc.subr X Xname="gpioshutdown" Xstart_cmd=${name}_start Xunload_cmd=${name}_unload Xreload_cmd=${name}_reload Xstop_cmd=${name}_stop Xrcvar=`set_rcvar` Xextra_commands="unload reload" X X## Set defaults X Xload_rc_config "$name" X: ${gpioshutdown_enable="NO"} X: ${gpioshutdown_led_pin="auto"} X: ${gpioshutdown_led_pin_set="1"} X X Xgpioshutdown_get_led_pin() X{ X if test "${gpioshutdown_led_pin}" == "auto" ; then X if test -e /dev/led/pwr -o -e /dev/led/PWR ; then X __led_pin=`ofwdump -P gpios /leds/pwr | grep -v "gpios:" | grep -v "Node" | \ X awk 'function hexdigit(x) { xx = index("0123456789ABCDEF",toupper(x)) - 1; return xx; } X function hexval(x) { return hexdigit(substr(x,1,1)) * 16 + hexdigit(substr(x,2,1)); } X { print hexval($5) * 65536 * 256 + hexval($6) * 65536 + hexval($7) * 256 + hexval($8); }'` X __led_pin_set="1" X elif test -e /dev/led/ok -o -e /dev/led/OK ; then X __led_pin=`ofwdump -P gpios /leds/ok | grep -v "gpios:" | grep -v "Node" | \ X awk 'function hexdigit(x) { xx = index("0123456789ABCDEF",toupper(x)) - 1; return xx; } X function hexval(x) { return hexdigit(substr(x,1,1)) * 16 + hexdigit(substr(x,2,1)); } X { print hexval($5) * 65536 * 256 + hexval($6) * 65536 + hexval($7) * 256 + hexval($8); }'` X __led_pin_set="0" X else X __led_pin="" X __led_pin_set="" X fi X else X if test -z "${gpioshutdown_led_pin}" ; then X __led_pin="" X __led_pin_set="" X else X __led_pin=`expr "${gpioshutdown_led_pin}" + 0` X __led_pin_set=`expr "${gpioshutdown_led_pin_set}" + 0` X X # if 'gpioshutdown_led_pin' is not a number, led_pin will be blank X fi X fi X X# echo "TEMPORARY: $__led_pin" >&2 X X if test -z "$__led_pin" ; then X echo "" X else X echo "$__led_pin $__led_pin_set" X fi X} X Xgpioshutdown_enable_led_pin() X{ X led_pin="$1" X led_pin_set="$2" X X# echo "TEMPORARY: LED pin is on '"$led_pin"'" X X sysctl kern.gpioshutdown.led_gpio=${led_pin} X sysctl kern.gpioshutdown.led_gpio_set=${led_pin_set} X X # LED is enabled - energize it! X gpioctl -c ${led_pin} OUT X gpioctl ${led_pin} ${led_pin_set} X} X Xgpioshutdown_start() X{ X if ( kldstat -q -m gpioshutdown ) ; then X echo "gpioshutdown installed" ; X else X echo "installing gpioshutdown" X kldload gpioshutdown.ko X fi X X led_pin=`gpioshutdown_get_led_pin` X X if test -n "$led_pin" ; then X gpioshutdown_enable_led_pin ${led_pin} X fi X} X X# 'stop' assumes system shutdown and does NOT Xgpioshutdown_stop() X{ X echo "gpioshutdown - system shutdown" X echo "(kernel module NOT unloading; use 'unload' if you want to unload it)" X} X Xgpioshutdown_unload() X{ X led_pin=`sysctl kern.gpioshutdown.led_gpio | awk '{ print $2; }'` X X if test -n "$led_pin" ; then X # disable the pin [this is a 'safe mode' way of doing it] X sysctl kern.gpioshutdown.led_gpio=-1 X X # LED was enabled - turn it back into an input X if test -n "$led_pin" ; then X if test "$led_pin" -ge 0 ; then X gpioctl -c ${led_pin} IN X fi X fi X fi X X if ( kldstat -q -m gpioshutdown ) ; then X echo "unloading gpioshutdown" ; X kldunload gpioshutdown X else X echo "gpioshutdown module not loaded" X fi X} X Xgpioshutdown_reload() X{ X gpioshutdown_unload X gpioshutdown_start X} X X Xrun_rc_command "$1" X X 0fc6582bc92fb1a978e2208623bbe28d echo x - raspberrypi-gpioshutdown/Makefile sed 's/^X//' >raspberrypi-gpioshutdown/Makefile << '5bf5f9789da4343512625692cad9e6ec' X# Created by: $FreeBSD$ X# $FreeBSD$ X# X# Author: 'Big Bad Bombastic Bob' Frazier X# X# Makefile for raspberrypi-gpioshutdown X# X# Installing this port should resolve bug report 211979. X# This port is for the Raspberry Pi model 1B and model 2 X XPORTNAME= raspberrypi-gpioshutdown XDISTVERSION= 1.0 XPORTREVISION= 1 XCATEGORIES= misc XMASTER_SITES= http://mrp3.com/ XDISTNAME= raspberrypi-gpioshutdown-${DISTVERSION} X XMAINTAINER= bobf@mrp3.com XCOMMENT= Kernel driver to reset GPIO pins on shutdown for Raspberry Pi X XLICENSE= BSD2CLAUSE X XONLY_FOR_ARCHS= armv6 armv7 X XKMODNAME= gpioshutdown XUSES= kmod XUSES_RC_SUBR= ${KMODNAME} X#MODULESDIR= boot/modules X#PLIST_FILES= ${KMODDIR}/gpioshutdown.ko X X.include X Xdo-install: X ${INSTALL_KLD} ${WRKSRC}/${KMODNAME}.ko ${STAGEDIR}${KMODDIR} X ${INSTALL} files/gpioshutdown ${STAGEDIR}${LOCALBASE}/etc/rc.d/ X gzip -k ${WRKSRC}/gpioshutdown.4 X ${INSTALL} ${WRKSRC}/gpioshutdown.4.gz ${STAGEDIR}${LOCALBASE}/man/man4/gpioshutdown.4.gz X X.include 5bf5f9789da4343512625692cad9e6ec echo x - raspberrypi-gpioshutdown/distinfo sed 's/^X//' >raspberrypi-gpioshutdown/distinfo << '550a42f292c11fbb9f951b1d89305d5c' XTIMESTAMP = 1521490257 XSHA256 (raspberrypi-gpioshutdown-1.0.tar.gz) = 25d647309b54d253a11e7ae74998a7d382ce3a9fddb6bd7adace67f0d4f83c9f XSIZE (raspberrypi-gpioshutdown-1.0.tar.gz) = 7320 550a42f292c11fbb9f951b1d89305d5c echo x - raspberrypi-gpioshutdown/pkg-descr sed 's/^X//' >raspberrypi-gpioshutdown/pkg-descr << '1f32dadf14e2633b0d873636dd434cd3' Xraspberrypi-gpioshutdown kernel module X XWritten by 'Big Bad Bombastic Bob' Frazier. X XGPIO 'shutdown' Kernel module for the Raspberry Pi Model 1B and Model 2 X XThe purpose of this module is to shut down all GPIOs prior to powering off Xor rebooting a Raspberry Pi. The main reason for this is due to there being Xno real indicators that the shutdown process has completed. By doing a Xshutdown of all of the GPIOs (such that they act like inputs without pullup Xresistors), you can detect the 'high impedence' state either with an LED or Xusing some kind of exernal board (such as an 'ATX Raspi' board). An external Xboard could then detect the shutdown, and power off the Raspberry Pi safely, Xand you won't have to fix the file system due to problems caused by powering Xit down before it's safe to do so. X XThe Linux kernel effectively does this very same thing. However, a kernel Xdeveloper was concerned because SOME arm kernels (apparently open-wrt needs Xthis) have to maintain the GPIO state after shutting down. Rather than Xdealing with the limitations that SOME platforms may have, at the expense of Xothers, I created this port with the dynamically loadable module instead. X XFor more information you can read about it in bug report 211979. Installing Xthis port effectively resolves that bug. 1f32dadf14e2633b0d873636dd434cd3 exit