utopianemo
Posts: 6
Joined: Fri May 01, 2015 6:33 pm

If the P6 header reset is totally safe, then what about.....

Mon Jun 22, 2015 4:39 am

I'm using a Pi2 to run Emulation Station, using an old Sega Genesis shell as a case. I've read the tutorials on how to use the P6 header for a hard reset, as well as how to create soft shutdown protocols that can be activated by using a button or switch. I have installed a momentary contact button for the reset and it works flawlessly.

My question is this: If the hard reset is safe and powerful enough to force a restart when the Pi is in any energized state(even frozen) without risk of corrupting the OS image, then wouldn't it also be true that cutting power while holding reset would be a safe way to power down?

And if that's true, then couldn't one devise a control scheme(external to the software) that activates the reset for a second or so before cutting power to the Pi2? Since the P6 reset seems to supercede any software function, wouldn't this idea be as safe and more foolproof than a soft shutdown routine?

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 5:30 am

I am not sure that it is necessarily safe to reset the SoC in the middle of writing to the SD card. However, your logic seems good. If reset is always safe, then holding in reset for a second or two before removing power would be better than removing power without warning.

I often wondered whether maintaining the 3.3V supply to the SD card for a little longer than to the rest of the board would allow it to complete or abort any in-progress operations. You scheme may be easier to test and likely gives the same answer.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 6:38 am

That the hard reset has not corrupted anything yet seems to be pure coincidence to me. You should try this apporach with other cards and
firmwares and report the results to be sure.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

klricks
Posts: 7172
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 1:02 pm

utopianemo wrote:....

My question is this: If the hard reset is safe and powerful enough to force a restart when the Pi is in any energized state(even frozen) without risk of corrupting the OS image, ....
Please quote a reference to that statement.

Also on B+ and 2B the reset header is labeled RUN. P6 is only on the older B and A models.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

utopianemo
Posts: 6
Joined: Fri May 01, 2015 6:33 pm

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 6:56 pm

klricks wrote: Please quote a reference to that statement.

Also on B+ and 2B the reset header is labeled RUN. P6 is only on the older B and A models.
I can't post a reference to the statement because it's a totally conditional one. The hardware reset labeled RUN has been discussed here and elsewhere as the preferred method of restarting the Pi(particularly but not limited to a frozen condition) over pulling the power. The conditional statement was 'if using a hard reset is safe and powerful enough'.....then holding down reset while cutting power must be safe. In the end, it seems that the danger of corrupting the SD card with a power off(or reset) comes primarily from doing so whilst the Pi is writing to the card. I'll try to avoid that and I'm also using an external hard drive that I'm trying to customize to do everything except that which is essential to the OS.

Thank you for pointing out that the reset header is labeled RUN now. I started planning this project as the Pi2 was just being released, and at that time I could not find one reference to RUN as being the same as P6, even though cross-referencing the older Pi pics with the Pi2 I had in my hand seemed to indicate as much. In the end I soldered it up and crossed my fingers, hoping I was right.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 8:10 pm

I don't think I've ever seen anyone claim that RUN/reset is safe when talking about a system that hasn't been shut down properly.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 8:43 pm

There is no difference between initiating a reset and cutting the power, neither performs any shutdown procedures. It works just like the reset on a PC, press it and it instantly reboots. Anything you were working on is lost, any data in the drive buffers that hadn't been written to disk is lost, the RAM is cleared and all processes instantly stop when the reset is initiated.

The reset (run) works well if you have shut down the RPi but not cut the power. The "run" pads allow you to restart it without having to unplug the power and plug it back in, I find that feature pretty handy sometimes. And should the RPi freeze up and is non-responsive you can use the reset to boot it back up. In those cases it is indeed preferable to removing the power and plugging it back in as it saves some wear and tear on the micro USB connector.

"'if using a hard reset is safe..." it's not, and no different than just pulling the power plug and then powering back up.
"holding down reset while cutting power must be safe", it's as "safe", one or both doesn't matter as either way you just dumped everything that was running in midstream and started over. The fact that you pulled the power before it had a chance to reboot doesn't make it any better.

utopianemo
Posts: 6
Joined: Fri May 01, 2015 6:33 pm

Re: If the P6 header reset is totally safe, then what about.

Mon Jun 22, 2015 9:46 pm

Thanks for the help! I'll get working on the safe shutdown protocol.

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: If the P6 header reset is totally safe, then what about.

Fri Jun 26, 2015 2:47 pm

JimmyN wrote:There is no difference between initiating a reset and cutting the power, neither performs any shutdown procedures.
Of course, without a clean shutdown there is always the risk of losing data that was unsaved or very recently saved, along with introducing errors or inconsistencies into files (especially databases) that were being written at the time. However, I think this thread was more about filesystem corruption, and there is reason to believe that resetting might be safer than powering down in that respect.

When you pull the power, the 3.3V supply to the SD card collapses, while the card may have been in the middle of a flash write or erase, or moving data around for wear levelling or to maintain its pool of pre-erased blocks. If the card's records become out of date or corrupt, reads from the affected blocks will return the wrong data. There may also be some caching of writes in the controller's RAM. Unlikely an SSD, there is no room for a large capacitor to store the energy to write this back.

The RUN line does not connect to the SD card at all. When you reset the board, all that happens is the SoC stops talking. The card ought to be able to handle that gracefully. Even if it was in middle of a write operation, it should be able to detect a CRC error from the host, and abort. Even if it actually does write incomplete data, it has no excuse for writing it in the wrong place. If it was filesystem metadata that was being written, the kernel will have made a journal entry about it, and should be able to recover on the next boot.
"'if using a hard reset is safe..." it's not, and no different than just pulling the power plug and then powering back up.
I have still not tested it. To be honest I have had no issues with filesystem corruption except for one card that failed completely, so I am not very motivated to worry. But I do suspect that reset may be safer than pulling power.

utopianemo
Posts: 6
Joined: Fri May 01, 2015 6:33 pm

Re: If the P6 header reset is totally safe, then what about.

Fri Jun 26, 2015 6:45 pm

This is interesting news. I should mention that I don't have a SSD; I'm using a Toshiba hard drive, which is fortuitously similar in dimensions to a Sega Genesis/Mega Drive cartridge. I opened the cartridge slot up a bit and it sits there nicely, looking just like it belongs there. I'm contemplating creating a mock cartridge sticker in the classic Genesis/Mega Drive style that reads, "Everything".

Another topic is how difficult it was to get it the hard drive to work, since the Pi2 doesn't produce enough power through its USB ports(this is not because of my power supply; I'm using a 5 amp supply built for industrial controls). Also interesting is that if you use one of those USB "Y" cables that has a separate(power-only) USB jack that can augment power for situations like this, pulling power from the micro USB port will not kill the Pi. The USB rails will keep the Pi active because they're all interconnected.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: If the P6 header reset is totally safe, then what about.

Fri Jun 26, 2015 7:32 pm

jojopi wrote:
JimmyN wrote:There is no difference between initiating a reset and cutting the power, neither performs any shutdown procedures.
Of course, without a clean shutdown there is always the risk of losing data that was unsaved or very recently saved, along with introducing errors or inconsistencies into files (especially databases) that were being written at the time. However, I think this thread was more about filesystem corruption, and there is reason to believe that resetting might be safer than powering down in that respect.

When you pull the power, the 3.3V supply to the SD card collapses, while the card may have been in the middle of a flash write or erase, or moving data around for wear levelling or to maintain its pool of pre-erased blocks. If the card's records become out of date or corrupt, reads from the affected blocks will return the wrong data. There may also be some caching of writes in the controller's RAM. Unlikely an SSD, there is no room for a large capacitor to store the energy to write this back.

The RUN line does not connect to the SD card at all. When you reset the board, all that happens is the SoC stops talking. The card ought to be able to handle that gracefully. Even if it was in middle of a write operation, it should be able to detect a CRC error from the host, and abort. Even if it actually does write incomplete data, it has no excuse for writing it in the wrong place. If it was filesystem metadata that was being written, the kernel will have made a journal entry about it, and should be able to recover on the next boot.
"'if using a hard reset is safe..." it's not, and no different than just pulling the power plug and then powering back up.
I have still not tested it. To be honest I have had no issues with filesystem corruption except for one card that failed completely, so I am not very motivated to worry. But I do suspect that reset may be safer than pulling power.
Is there generally enough capacitance there to avoid exactly that sort of thing? I guess it depends on the characteristics of the card itself, but I haven't had much luck trying to get the official card to corrupt data either way.

Return to “Beginners”