2

I am not very experienced with Embedded Linux, just some projects with the Raspberry Pi.

I would like to know if there are any recommended ways to shutdown the Embedded Linux if the device's power is removed suddenly, or if common-practice is to just ignore it.

mFeinstein
  • 4,333
  • 13
  • 47
  • 85
  • if power is removed, I don't see how you'd shut down, or do you mean if some external power is removed and you still have some time? In that case, you'd just have something that triggers a userland process to initiate the shutdown routine. – Marcus Müller Oct 04 '19 at 18:20
  • Yeah, something like that, like: "do people that implement Embedded Linux, on environments where power cab be (and usually is) just cut-off, make protections on the hardware to give the OS time to proper shut-down, like with super-caps, or don't they even care at all?" – mFeinstein Oct 04 '19 at 18:24

1 Answers1

2

A journaling filesystem is less prone to corruption, so ext4 is used, still it is not 100% safe. By default in raspbian you have option flags in fstab, that upon power up, it does a filsystem check and repairs corrupted SD card.

Well there are lot of UPS boards, but many of them are useless, they just invoke sudo shutdown -h nowscript at detected power outage and the capacitors supply the board for few seconds. But if you reconnect the power before the capacitors are drained out, then the board won't start again automatically.

A good UPS has to have an additional MCU that handles the correct sequence. For example the Beaglebone has an standalone PMIC, but they never thought about to use it correctly. Most of these boards are stamped in millions copies, but they lack of very basic functionality, shutdown sequence.

Marko Buršič
  • 23,961
  • 2
  • 20
  • 33
  • I see, so to be on the safe side of things the common practice is to use a PMIC + caps? – mFeinstein Oct 04 '19 at 18:47
  • A journaling file system is one thing, but if the storage device's internal, closed flash translation layer isn't safe against unexpected shutdown, neither a journal nor keeping the block device allegedly read only is necessarily enough to save things. Modern MLC flash SD cards are made to store vacation pictures with multiple bits crammed next to each other as analog levels that need to be occasionally maintained just from reading, it's not made to store root filesystems. – Chris Stratton Oct 04 '19 at 18:56
  • @mFeinstein There are some UPS boards, that use an Atmel or PIC MCU as PMIC. It is also essential that UPS has separate connection for power in and out, those UPS boards which use the same 5V pin and they have a bidirectional DC DC converter (for charging and draining caps) are useless, because after the shutdown the power has to be taken off. Not necessarily it has to be a PMIC with all bells and whistles, but also not a general DC DC converter IC. – Marko Buršič Oct 04 '19 at 19:11
  • @Chris yeah I read about it, but most production embedded Linux devices use EEPROM right? So this shouldn't be a problem? – mFeinstein Oct 04 '19 at 19:16
  • @mFeinstein um, flash memory is eeprom (it's just not called that), and yes, that is a problem, still. (a camera is an embedded system, you mean industrial embedded systems, and they tend to eMMC flash &similar technologies, often at higher price per GB, but that really doesn't help you with storage consistency in case of an unexpected poweroff – proper power management that gives your board a heads up before the lights go out is necessary. A raspberry pi isn't an industrial embedded device at all – the SoC is just a TV settop box SoC, and thus has none of the desirable hardware features.) – Marcus Müller Oct 04 '19 at 20:10
  • Good point, I forgot most if not all ROM memory nowadays is flash. Routers are a perfect example of what I have in mind, they use embedded Linux and users tend to pull the plug when the internet goes down, in order to restart them. They do lots of filesystem transactions to keep statistics, and still are not industrial devices, but usually last many years. Do devices like routers have any protection to shutdown properly when the power is removed, or do they just risk being corrupted? – mFeinstein Oct 04 '19 at 20:17
  • not really – they don't usually have to be hiRel nor have a lot of things to write to storage – Marcus Müller Oct 04 '19 at 21:27
  • @mFeinstein no, home routers boot from an SPI flash and then barely touch it. Infrastructure routers are a whole different story, more like other servers than embedded systems. – Chris Stratton Oct 05 '19 at 04:13
  • Hmm I got the impression they did as my Asus router is pretty advanced and I remember reading something about file access on its error logs. – mFeinstein Oct 05 '19 at 21:43
  • Looking at the logs I found entries like: Oct 4 23:00:34 disk_monitor: Got SIGALRM... and Oct 4 18:56:26 kernel: jffs2_flush_wbuf(): Write failed with -5, so I got the impression there's active disk access – mFeinstein Oct 05 '19 at 23:05