Keil Logo

MDK MIDDLEWARE: Filesystem Corruption after power failure


Information in this knowledgebase article applies to:

  • MDK v5.x and newer versions
  • Middleware File System Component v5.x and newer versions

QUESTION

Embedded File System (EFS) from MDK-ARM Middleware is used on a NOR flash in my project. After a sudden power failure during a file operation on this EFS, I realized the EFS turned to be corrupted and the file system cannot be used without a proper reformatting. How can I prevent such a file system corruption on EFS caused by a power failure?

ANSWER

EFS is designed as a simple, efficient file system with a limited set of features. Power failure while writing to NOR flash or erasing a NOR flash sector using EFS can be critical and often results in a corruption of the file system.

Another reason of potential corrupted FS caused by power failure is due to NOR flash itself. For example, if the device is erasing a flash sector, while power failure occurs, this flash sector might be only partially erased. That means the sector content will become undefined. The same could happen if power goes out, while the NOR flash is being written. The content of that flash page could also become undefined.

In a word, EFS is not a power-failure safe file system. Using EFS on a NOR flash is not a proper choice. if there are frequent file writes and frequent power failures are expected.

If using EFS on a NOR Flash is inevitable in your project, a possible solution to this problem is an early notification of power failure (e.g. by monitoring 50Hz signal on main powered device). When the system is notified with a power failure, the system completes file operations on NOR flash and halts. The Power supply unit (PSU) must be capable of providing additional power for about 100ms to complete all file operations, like closing all open files etc., before the system shuts down. But this solution would help preventing the file system to be corrupted. But you won't be able to know which files were open etc, because EFS doesn't support journaling.

In order to have a power-failure safe FS, it is better using FAT file system with a NAND flash. When writing to NAND flash, everything is committed in one step. And the NAND flash translation layer is designed to be power-failure safe as well. But note that FAT file system, which is on top of NAND flash translation layer (NFTL), is not power-failure safe. To prevent a FAT file system to be corrupted, journaling mechanism for FAT should be enabled and used in your project.

MORE INFORMATION

Last Reviewed: Wednesday, December 2, 2020


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.