From ff87719efe0a43a24d630524b942917b9c8095ad Mon Sep 17 00:00:00 2001 From: hoopsurfer Date: Tue, 13 Mar 2018 01:58:22 -0700 Subject: [PATCH 1/3] Note reboot but and suggested workaround --- install.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.md b/install.md index b97f508..1839b6a 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 ----------------- From a8b7fa81b43f5459fbd1a5590d84c4779fc67371 Mon Sep 17 00:00:00 2001 From: hoopsurfer Date: Tue, 13 Mar 2018 21:06:34 -0700 Subject: [PATCH 2/3] Update install.md --- install.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/install.md b/install.md index 1839b6a..c257b58 100644 --- a/install.md +++ b/install.md @@ -44,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 + From 9a5738e6758e1aba96045ab27e1d159b1481fdc6 Mon Sep 17 00:00:00 2001 From: hoopsurfer Date: Wed, 14 Mar 2018 00:55:06 -0700 Subject: [PATCH 3/3] Reimplemented systemd services and scripts, cleaning up naming and comments --- pidesktop-base.deb | Bin 3512 -> 4148 bytes pidesktop-base/DEBIAN/control | 5 ++- pidesktop-base/DEBIAN/postinst | 10 +++--- pidesktop-base/DEBIAN/postrm | 6 ++-- .../systemd/system/pidesktop-powerkey.service | 10 ++++++ .../systemd/system/pidesktop-rtcsync.service | 11 ------- .../systemd/system/pidesktop-shutdown.service | 12 +++---- .../usr/share/pidesktop/python/pd-powerkey.py | 30 ++++++++++++++++++ .../usr/share/pidesktop/python/pd-restart.py | 25 --------------- .../usr/share/pidesktop/python/pd-shutdown.py | 25 +++++++++++++++ 10 files changed, 82 insertions(+), 52 deletions(-) create mode 100644 pidesktop-base/lib/systemd/system/pidesktop-powerkey.service delete mode 100644 pidesktop-base/lib/systemd/system/pidesktop-rtcsync.service create mode 100755 pidesktop-base/usr/share/pidesktop/python/pd-powerkey.py delete mode 100644 pidesktop-base/usr/share/pidesktop/python/pd-restart.py create mode 100755 pidesktop-base/usr/share/pidesktop/python/pd-shutdown.py diff --git a/pidesktop-base.deb b/pidesktop-base.deb index 30985309183dd969c97339371363197eb9cea5e3..6b8d627d54f858786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_;iDmUMwt$wDNmztup3YThW%^gN_3DlClRFFunX3@bV1*2w zoHE+*%3_w_JkOw^l4v(B4kI$1Z`Q^;M(@%W`cE9gy47jk`4aK@ zBj>X&d@i4 zbu<4>&LwTGoWst)BMcetUSXwU#hBwY(m?&M+DLAg5pLiDbovy5}~{@|XqwTRw$r4Yfsn{*Xzk8uKU zR=uWKH+zeVMh_~LU>|=d3q>pTD{;D1LQhrqCFEa-;d1%(qlnRO8$+5_xziaY;8-zs z@l6jK)r@foEJIH=rKvi~F6}R8^9p_lJLiKjj%bY@+k%K)g#{ABpwqn?=GLk}2orfW zfQLl|;R_~{lohHCJS;#3LyK1`O3L(AU;Y*K6u6GR-JL0A3IGAB6M&!r03Fe&ak0c_`vL#}000D8TBg8l AdH?_b 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