Embedded System On/Off Switch

Hi guys.
Thanks for the recent podcast episodes. I am an experienced embedded developer but an Embedded Linux noob and have enjoyed all episodes immensely.
I have a question regarding implementing an on/off switch for an Embedded Linux System. Is there an established methodology for providing this functionality, or does the implementation vary depending on system? Presumably external logic is also required for the final power removal?

This is a good topic to think about, as you typically want to do a safe powerdown of your Linux system before removing power (like you would a PC). After you execute the poweroff command (or something equivalent), you can find in the kernel the last bit of code that runs, and then add a GPIO call that controls external logic that actually removes power.

We’ll often use a bridge battery or super cap circuit in products to provide enough power to do a safe powerdown in case main power is removed.

As long as you don’t have any pending “disk” writes, just turn the power off hard with no warning to software. For truly embedded things which don’t look anything like a computer to normal people, this (in my opinion) should be a perfectly safe way to turn a thing off but it needs to be designed into the product.

For things that looks somewhat like a computer (ie: a phone or other device which has a computery looking UI on it) then having a clean shutdown button is a good idea and most users will probably shut it down that way most of the time. But you should still make sure the product is robust against unexpected power loss.

If you want to get real fancy, build in the electronics to have enough capacitance to keep your system running for a few seconds and then have the ability to sense when the input power goes away. As soon as the input power goes away, make sure you flush all your “disk” writes out and try to do a clean poweroff. Often this is too expensive to implement for consumer goods.