Chris Vogel<p>Follow-up to <a href="https://chrichri.ween.de/o/289704403f2f4abea071c3d9cc9f2ab8" rel="nofollow noopener" target="_blank">this note</a>.</p>
<p>Dragan had asked me to do <strong>repeated power-cycle tests</strong> with different kernel versions using the patched dtb for <a href="https://chrichri.ween.de/t/rockpro64" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>RockPro64</span></a> to make sure the kernel <a href="https://chrichri.ween.de/t/oops" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>oops</span></a> wouldn't still be an issue.</p>
<p>I learned that cutting the power of the device could kill the <a href="https://chrichri.ween.de/t/lpddr4" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>LPDDR4</span></a> <a href="https://chrichri.ween.de/t/ram" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>RAM</span></a>. This is documented in the specification referenced on the <a href="https://wiki.pine64.org/wiki/ROCKPro64#Datasheets_for_Components_and_Peripherals" rel="nofollow noopener" target="_blank">RockPro64 wiki page</a> for <a href="https://files.pine64.org/doc/datasheet/rockpro64/SM512M32Z01MD2BNP(200BALL).pdf" rel="nofollow noopener" target="_blank">Micron LPDDR4 Mobile LPDDR4 Datasheet</a> as stated on page 37 in <em>Uncontrolled Power-Off</em>:</p>
<blockquote>
<p>An uncontrolled power-off sequence can occur a maximum of 400 times over the life of the device.</p>
</blockquote>
<p>I never had heard about this before! <strong>Cutting power without shutdown can kill my RAM?</strong></p>
<p><strong>show dmesg and shutdown</strong></p>
<p>To get all the debugging information I needed I wanted the system after booting to print <code>dmesg</code> to the serial console, wait a short time and then actually shutdown.</p>
<pre><code>
root:~# cat /root/bin/dmesg_and_shutdown.sh
#!/bin/bash
# a small script that outputs dmesg to serial
# console, waits 20 seconds and shuts down
dmesg > /dev/ttyS2
# show a message how to stop this script and wait 20 seconds
echo "Will shutdown in 20 seconds - to stop me call 'pkill dmesg_and_shut'" > /dev/ttyS2
sleep 20
echo "shutdown -h" > /dev/ttyS2
shutdown -h now
# a cronjob that runs after each boot
root:~# crontab -l
@reboot /root/bin/dmesg_and_shutdown.sh
</code></pre>
<p><strong>powercycle the board</strong></p>
<p>I took the time needed for a complete cycle of booting, showing dmesg, waiting and shutting down: well below 2 minutes.</p>
<p>To automate the power cycle I used an <a href="https://chrichri.ween.de/t/esp8266" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>esp8266</span></a> based power switch made by <a href="https://chrichri.ween.de/t/sonoff" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Sonoff</span></a> (Powr2) running <a href="https://github.com/letscontrolit/ESPEasy" rel="nofollow noopener" target="_blank">ESP Easy</a> (mega-20210503).</p>
<p><a href="https://chrichri.ween.de/t/espeasy" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>ESPeasy</span></a> offers a simple scripting language I used to powercycle after 120 seconds of being switched on:</p>
<pre><code>
On System#Boot do
gpio,12,0
gpio,13,1
endon
On button#button_state do
if [blue_led#blue_led_state]=1
gpio,13,0
timerSet,1,2
else
gpio,13,1
gpio,12,1
timerSet,1,0
timerSet,2,0
endif
endon
On Rules#Timer=1 do
gpio,12,0
timerSet,2,1
endon
On Rules#Timer=2 do
gpio,12,1
timerSet,1,2
endon
</code></pre>
<p>Pressing the button on the Sonoff device toggles between:</p>
<ul>
<li>blue led off: timers disabled, relay on permanently</li>
<li>blue led on: timers switch the relay off for 5 seconds, on for 120 seconds and then repeat</li>
</ul>
<p><strong>logging</strong></p>
<p><code>minicom</code> logged the serial output to a file.</p>
<p>Further down the <a href="https://chrichri.ween.de/t/rabbithole" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>RabbitHole</span></a> I went when looking at the resulting logfile…</p>