Skip to content

Commit

Permalink
Update restart (#7)
Browse files Browse the repository at this point in the history
* Note reboot but and suggested workaround

* Update install.md

* Reimplemented systemd services and scripts, cleaning up naming and comments
  • Loading branch information
hoopsurfer authored Mar 14, 2018
1 parent 0464430 commit ec7e816
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 53 deletions.
9 changes: 8 additions & 1 deletion install.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The pidesktop add-on board functions as a USB mSATA SSD device when connected to

Before you assemble the case
----------------------------
Make sure the RP3's ["Boot from USB bit"](https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md) is set by [booting from an SD card](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) and making sure the required bit is set in hardware. Make certain: `vcgencmd otp_dump | grep 17:` shows `17:3020000a`, then shutdown and remove the SD card since it is no longer needed. You should be able to use an existing card, just *remember* to clear the /boot/config.txt changes used the set the boot bit.
Make sure the RP3's ["Boot from USB bit"](https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md) is set by [booting from an SD card](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) and making sure the required bit is set in hardware. Make certain: `vcgencmd otp_dump | grep 17:` shows `17:3020000a`, then shutdown and remove the SD card since it is no longer needed**. You should be able to use an existing card, just *remember* to clear the /boot/config.txt changes used the set the boot bit.

**FULL DISCLOSURE: The pidesktop case power management firmware has a bug in that it expects reboot will always be completed in less than 30 seconds. If your reboot times approach or exceed 30 seconds (and they can) you will experience failed or unreliable reboots which are effectively caused by the power management controller shutting off power because it cannot detect system restart during the early stages of a reboot. The workaround is to insert a blank formatted SD card into your Raspberry Pi which will generally speed reboot times by around 5 seconds. If there is no SD card inserted, the SD boot mode takes five seconds to fail before boot will start on the USB mSATA SSD. Even if you don't have any reboot issues, you may want to save the 5 seconds and have a second storage device available for use.

Assemble the case
-----------------
Expand Down Expand Up @@ -42,3 +44,8 @@ If you installed a camera you enable with "raspi-config" and then test it with `
Remember
--------
If you ever need to reimage your mSATA SSD, it is as easy as unplugging the special USB adapter and connecting the micro-USB and and power ports to the imaging machine. You *DO NOT* need to disassemble the case. Also, if you use a wireless keyboard/mouse with your new pidesktop you can install the small dongle under the special USB adapter and that makes for a very clean installation with easy access to the remaining USB ports.

References
----------
https://github.com/raspberrypi/documentation/blob/master/hardware/raspberrypi/bootmodes/bootflow.md

Binary file modified pidesktop-base.deb
Binary file not shown.
5 changes: 2 additions & 3 deletions pidesktop-base/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Package: pidesktop-base
Version: 0.1.3
Version: 0.1.4
Section: free
Priority: optional
Architecture: all
Maintainer: hoopsurfer
Description: PiDeskTop Case Power Support and mSATA Support

Description: Pi DeskTop Case Power+RTC+mSATA Support
10 changes: 5 additions & 5 deletions pidesktop-base/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
sudo chmod +x /usr/share/pidesktop/script/*
sudo chmod +x /usr/share/pidesktop/python/*

# links to make running installation steps easy
# links to make running manual installation steps easy
sudo ln -sv /usr/share/pidesktop/script/pd-check /usr/bin/pd-check
sudo ln -sv /usr/share/pidesktop/script/pd-clonessd /usr/bin/pd-clonessd
sudo ln -sv /usr/share/pidesktop/python/pd-bootssd.py /usr/bin/pd-bootssd
sudo ln -sv /usr/share/pidesktop/python/pd-fixrtc.py /usr/bin/pd-fixrtc

# uncomment to autoclone SD to SSD
#sudo /usr/share/pidesktop/python/pd-clonessd.py

# enable new sevices
sudo systemctl enable pidesktop-powerkey.service
sudo systemctl enable pidesktop-shutdown.service
sudo systemctl enable pidesktop-rtcsync.service
sudo systemctl list-unit-files | grep pidesktop

# uncomment to autoclone SD to SSD
#sudo /usr/share/pidesktop/python/pd-clonessd.py

# fix up the rtc by default
sudo /usr/share/pidesktop/python/pd-fixrtc.py
6 changes: 4 additions & 2 deletions pidesktop-base/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ sudo rm -f /usr/bin/pd-bootssd
sudo rm -f /usr/bin/pd-fixrtc

# stop systemd services
sudo systemctl stop pidesktop-rtcsync.service
sudo systemctl stop pidesktop-powerkey.service
sudo systemctl stop pidesktop-shutdown.service
sudo systemctl disable pidesktop-powerkey.service
sudo systemctl disable pidesktop-shutdown.service

# remove residual systemd files
# remove any residual systemd files
sudo rm -f /lib/systemd/system/pidesktop-*.service
sudo rm -f /etc/systemd/system/*.target.wants/pidesktop-*.service

Expand Down
10 changes: 10 additions & 0 deletions pidesktop-base/lib/systemd/system/pidesktop-powerkey.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=PiDesktop Power Button Service
After=local-fs.target

[Service]
Type=simple
ExecStart=/usr/bin/python /usr/share/pidesktop/python/pd-powerkey.py

[Install]
WantedBy=multi-user.target
11 changes: 0 additions & 11 deletions pidesktop-base/lib/systemd/system/pidesktop-rtcsync.service

This file was deleted.

12 changes: 6 additions & 6 deletions pidesktop-base/lib/systemd/system/pidesktop-shutdown.service
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[Unit]
Description=PiDesktop Shutdown Restart
After=local-fs.target
Description=PiDesktop Shutdown Reboot Service
DefaultDependencies=no
Before=shutdown.target

[Service]
Type=simple
ExecStart=/usr/bin/python /usr/share/pidesktop/python/pd-restart.py
Type=oneshot
ExecStart=/usr/bin/python /usr/share/pidesktop/python/pd-shutdown.py

[Install]
WantedBy=multi-user.target

WantedBy=reboot.target shutdown.target
30 changes: 30 additions & 0 deletions pidesktop-base/usr/share/pidesktop/python/pd-powerkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/user/bin/env python
#
# pd-powerkey.py - monitor GPIO to detect power key press
#

import RPi.GPIO as GPIO
import time,os,sys

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31,GPIO.OUT) # Pi to Power MCU - start shutdown timer
GPIO.setup(33,GPIO.IN) # Power MCU to Pi - power key pressed

GPIO.output(31,GPIO.LOW) # tell PCU we are alive
GPIO.output(31,GPIO.HIGH) # cause blink by starting shutdown timer
time.sleep(0.5)
GPIO.output(31,GPIO.LOW) # clear timer we really are alive

# callback function
def powerkey_pressed(channels):
os.system("sync")
os.system("shutdown -h now")
sys.exit()

# wait for power key press
GPIO.add_event_detect(33,GPIO.RISING,callback=powerkey_pressed)

# idle - TODO: use wait
while True:
time.sleep(10)
25 changes: 0 additions & 25 deletions pidesktop-base/usr/share/pidesktop/python/pd-restart.py

This file was deleted.

25 changes: 25 additions & 0 deletions pidesktop-base/usr/share/pidesktop/python/pd-shutdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/user/bin/env python

# pd-shutdown.py - oneshot service so do your thing and exit
#
# We are in shutdown processing either because shutdown or reboot is running or because
# the power button was pressed. If we're here because the power button was pressed then
# Power MCU is already in Waiting OFF state and will turn off immediately if it sees
# pin 31 go high. If power button has not been pressed we should inform power MCU
# shutdown/reboot is taking place so the shutdown timer can start.
#
# Note: The timer will reset when the Pi powers off so the only purpose REALLY for doing
# this is to force a power off if shutdown hangs for some reason - somewhat lame.

import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # Use physical board pin numbering
GPIO.setup(31,GPIO.OUT) # Pi to Power MCU communication
GPIO.setup(33,GPIO.IN) # Power MCU to Pi on power button press

if GPIO.input(33):
# Power Key was already pressed - shut the system down immediately
else:
# shutdown or reboot not related to power key
GPIO.output(31,GPIO.HIGH) # tell power MCU and exit immediately

0 comments on commit ec7e816

Please sign in to comment.