LakeMaps / pi

Lake Maps' boat Raspberry Pi image build script
Open Software License 3.0
1 stars 0 forks source link

Add service for poweroff and restart via GPIO #3

Closed whymarrh closed 7 years ago

whymarrh commented 7 years ago

Closes LakeMaps/boat#16

This PR adds a service to poweroff or reboot the Pi when a particular GPIO pin is driven low (pins 23 and 24, respectively). The configuration of the GPIO pins—enabling the pull-up resistors—is done via a device tree overlay (see poweroff-pins.dts in the diff below).

Refs:

I have not tested any of this.

whymarrh commented 7 years ago

I still have yet to boot [off] the image with this loaded

I have successfully booted an image with this loaded. I'm now looking into a way to test the pin config.

whymarrh commented 7 years ago

Something seems to be working:

$ cat /sys/kernel/debug/pinctrl/3f200000.gpio/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (gpio0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 1 (gpio1): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 2 (gpio2): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 3 (gpio3): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 4 (gpio4): (MUX UNCLAIMED) pinctrl-bcm2835:4
pin 5 (gpio5): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 6 (gpio6): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 7 (gpio7): 3f204000.spi (GPIO UNCLAIMED) function gpio_out group gpio7
pin 8 (gpio8): 3f204000.spi (GPIO UNCLAIMED) function gpio_out group gpio8
pin 9 (gpio9): 3f204000.spi (GPIO UNCLAIMED) function alt0 group gpio9
pin 10 (gpio10): 3f204000.spi (GPIO UNCLAIMED) function alt0 group gpio10
pin 11 (gpio11): 3f204000.spi (GPIO UNCLAIMED) function alt0 group gpio11
pin 12 (gpio12): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 13 (gpio13): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 14 (gpio14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 15 (gpio15): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 16 (gpio16): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 17 (gpio17): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 18 (gpio18): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 19 (gpio19): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 20 (gpio20): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 21 (gpio21): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 22 (gpio22): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 23 (gpio23): (MUX UNCLAIMED) pinctrl-bcm2835:23
pin 24 (gpio24): (MUX UNCLAIMED) pinctrl-bcm2835:24
pin 25 (gpio25): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 26 (gpio26): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 27 (gpio27): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 28 (gpio28): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 29 (gpio29): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 30 (gpio30): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 31 (gpio31): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 32 (gpio32): 3f201000.uart (GPIO UNCLAIMED) function alt3 group gpio32
pin 33 (gpio33): 3f201000.uart (GPIO UNCLAIMED) function alt3 group gpio33
pin 34 (gpio34): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio34
pin 35 (gpio35): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio35
pin 36 (gpio36): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio36
pin 37 (gpio37): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio37
pin 38 (gpio38): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio38
pin 39 (gpio39): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio39
pin 40 (gpio40): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 41 (gpio41): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 42 (gpio42): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 43 (gpio43): 3f201000.uart (GPIO UNCLAIMED) function alt0 group gpio43
pin 44 (gpio44): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 45 (gpio45): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 46 (gpio46): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 47 (gpio47): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 48 (gpio48): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio48
pin 49 (gpio49): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio49
pin 50 (gpio50): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio50
pin 51 (gpio51): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio51
pin 52 (gpio52): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio52
pin 53 (gpio53): 3f202000.sdhost (GPIO UNCLAIMED) function alt0 group gpio53

Looking at pins 23 and 24 in particular:

$ cat /sys/kernel/debug/pinctrl/3f200000.gpio/pinmux-pins | awk '/pin 2[34]/ {print;}'
pin 23 (gpio23): (MUX UNCLAIMED) pinctrl-bcm2835:23
pin 24 (gpio24): (MUX UNCLAIMED) pinctrl-bcm2835:24
arandell93 commented 7 years ago

So did it work?

whymarrh commented 7 years ago

I don't know. The above is a sign that it might be working but I have no way to influence the GPIO pins.

arandell93 commented 7 years ago

I have no way to influence the GPIO pins.

I picked those pins because they are right next to ground pins. Short them each to ground individually by putting a piece of metal between the pin and the ground pin next to it, that's exactly what the switch does anyway. A screwdriver, a coin, anything.

The worst that will happen is you short two other pins and you likely blow the self-resetting fuse onboard the pi. It'll be dead for a few minutes and then be good to go again.

whymarrh commented 7 years ago

To confirm, I am touching pins 14 and 16 together and 18 and 20, according to this pinout: pinout.xyz

arandell93 commented 7 years ago

I am touching pins 14 and 16 together and 18 and 20

Correct, on separate occasions. First try 14 and 16 and see what it does, then reboot and try 18 and 20.

whymarrh commented 7 years ago

Welp, touching 14+16 nor 18+20 together does anything. I'll try to debug this.

whymarrh commented 7 years ago

This is pending a decision on the LED (see https://github.com/LakeMaps/boat/issues/16#issuecomment-274704717). The rest of this works:

pi@test1:~ $ systemctl status gpio-{poweroff,reboot}
● gpio-poweroff.service - Poweroff via GPIO PIN #23
   Loaded: loaded (/etc/systemd/system/gpio-poweroff.service; enabled)
   Active: active (running) since Fri 2016-11-25 17:56:26 UTC; 1 months 29 days ago
 Main PID: 403 (bash)
   CGroup: /system.slice/gpio-poweroff.service
           ├─403 bash /usr/local/bin/gpio-command 23 poweroff
           └─446 python -c import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.wait_for_edge(23, GPI...

● gpio-reboot.service - Reboot via GPIO PIN #24
   Loaded: loaded (/etc/systemd/system/gpio-reboot.service; enabled)
   Active: active (running) since Fri 2016-11-25 17:56:26 UTC; 1 months 29 days ago
 Main PID: 411 (bash)
   CGroup: /system.slice/gpio-reboot.service
           ├─411 bash /usr/local/bin/gpio-command 24 reboot
           └─445 python -c import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.wait_for_edge(24, GPI...