diff --git a/install.md b/install.md index b97f508..c257b58 100644 --- a/install.md +++ b/install.md @@ -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 ----------------- @@ -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 + diff --git a/pidesktop-base.deb b/pidesktop-base.deb index 3098530..6b8d627 100644 Binary files a/pidesktop-base.deb and b/pidesktop-base.deb differ diff --git a/pidesktop-base/DEBIAN/control b/pidesktop-base/DEBIAN/control index 169e1b5..fb04f40 100755 --- a/pidesktop-base/DEBIAN/control +++ b/pidesktop-base/DEBIAN/control @@ -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 diff --git a/pidesktop-base/DEBIAN/postinst b/pidesktop-base/DEBIAN/postinst index 950eb63..de67c7f 100755 --- a/pidesktop-base/DEBIAN/postinst +++ b/pidesktop-base/DEBIAN/postinst @@ -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 diff --git a/pidesktop-base/DEBIAN/postrm b/pidesktop-base/DEBIAN/postrm index a4f4cfe..e26db14 100755 --- a/pidesktop-base/DEBIAN/postrm +++ b/pidesktop-base/DEBIAN/postrm @@ -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 diff --git a/pidesktop-base/lib/systemd/system/pidesktop-powerkey.service b/pidesktop-base/lib/systemd/system/pidesktop-powerkey.service new file mode 100644 index 0000000..ba57957 --- /dev/null +++ b/pidesktop-base/lib/systemd/system/pidesktop-powerkey.service @@ -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 diff --git a/pidesktop-base/lib/systemd/system/pidesktop-rtcsync.service b/pidesktop-base/lib/systemd/system/pidesktop-rtcsync.service deleted file mode 100644 index eacdc1f..0000000 --- a/pidesktop-base/lib/systemd/system/pidesktop-rtcsync.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=pidesktop sync rtc -DefaultDependencies=no -Before=shutdown.target - -[Service] -Type=oneshot -ExecStart=/bin/bash /usr/share/pidesktop/script/pd-rtcsync - -[Install] -WantedBy=reboot.target poweroff.target diff --git a/pidesktop-base/lib/systemd/system/pidesktop-shutdown.service b/pidesktop-base/lib/systemd/system/pidesktop-shutdown.service index 7649159..3482f03 100644 --- a/pidesktop-base/lib/systemd/system/pidesktop-shutdown.service +++ b/pidesktop-base/lib/systemd/system/pidesktop-shutdown.service @@ -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 diff --git a/pidesktop-base/usr/share/pidesktop/python/pd-powerkey.py b/pidesktop-base/usr/share/pidesktop/python/pd-powerkey.py new file mode 100755 index 0000000..c8c49a5 --- /dev/null +++ b/pidesktop-base/usr/share/pidesktop/python/pd-powerkey.py @@ -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) diff --git a/pidesktop-base/usr/share/pidesktop/python/pd-restart.py b/pidesktop-base/usr/share/pidesktop/python/pd-restart.py deleted file mode 100644 index d38d35e..0000000 --- a/pidesktop-base/usr/share/pidesktop/python/pd-restart.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/user/bin/env python - -import RPi.GPIO as GPIO -import time -import os,sys -import signal - -GPIO.setwarnings(False) -GPIO.setmode(GPIO.BOARD) -GPIO.setup(31,GPIO.OUT) -GPIO.setup(33,GPIO.IN) - -GPIO.output(31,GPIO.LOW) - -def shutdown_system(channels): - os.system("sync") - time.sleep(1) - os.system("shutdown -h now") - sys.exit() - - -GPIO.add_event_detect(33,GPIO.RISING,callback=shutdown_system) - -while True: - time.sleep(1) diff --git a/pidesktop-base/usr/share/pidesktop/python/pd-shutdown.py b/pidesktop-base/usr/share/pidesktop/python/pd-shutdown.py new file mode 100755 index 0000000..9f23e47 --- /dev/null +++ b/pidesktop-base/usr/share/pidesktop/python/pd-shutdown.py @@ -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