From eMMC to NAND: Software Optimization Strategies for Embedded System Storage

In the embedded system development, as the core carrier of information interaction, the technical characteristics of the memory directly affect the system's performance and stability. However, when dealing with complex OS environments like Linux and Android, some struggle with understanding their storage mechanisms. Forlinx Embedded aims to overcome these hurdles by sharing storage knowledge to help build a comprehensive framework.

First, the media commonly used to store data in embedded scenarios can be divided into two categories:

Managed NAND: Mainly includes eMMC (embedded Multi - Media Card), TF cards, and SD cards, which have an internal storage management controller.

Raw NAND: Mainly based on NAND, without storage management functions, only containing simple IO logic control.

From eMMC to NAND: Software Optimization Strategies for Embedded System Storage

The figure above describes the relationship between NAND storage and eMMC storage. The NAND Controller refers to the CPU of the SoM, and NAND refers to the actual storage area. It can be seen that the difference between eMMC and NAND actually lies in whether the storage management control is inside the eMMC or in the CPU of the SoM. Storage management mainly includes the following functions: bad block management, ECC verification, wear leveling, data retention, address management and mapping, etc.

01 Related Concepts of Storage

Storage Types: SLC, MLC, TLC, and QLC. In embedded systems, SLC and MLC are commonly used for low - capacity storage, while TLC is generally used for high-capacity storage.

SLC (Single-Level Cell) It has high speed, long lifespan, and high price, with a theoretical erase-write cycle of about 100,000 times.

MLC (Multi-Level Cell) It has relatively high speed, relatively long lifespan, and relatively high price, with a theoretical erase-write cycle of 3000-5000 times.

TLC (Trinary-Level Cell) It has low speed, short lifespan, and the lowest price, with a theoretical erase-write cycle of 1000-3000 times.

QLC (Quad-Level Cell) It can have a larger capacity and lower cost, but its P/E lifespan is shorter.

pSLC (pseudo SLC) It is based on MLC FLASH, but only stores 1 bit of data in each cell instead of 2 bits. Since it only stores 1 bit per cell like SLC but is not a real SLC, it is called pSLC.

According to the above principle, if MLC is used as pSLC, the storage space will be halved, and the lifespan can usually be increased to about 30,000 times.

P/E (Program/Erase Count) Erase-write lifespan, one of the two indicators of durability.

TBW (Total Bytes Written) Total write volume, which is the value used by manufacturers to define the warranty period. That is, after the write volume exceeds this value, the manufacturer will no longer provide warranty services. It is also one of the two indicators of durability.

FW (Firmware) Since the internal controller of eMMC is a software-programmable controller, it requires firmware. The corresponding firmware has been flashed into the eMMC before it leaves the storage manufacturer.

WA (Write amplification) Write amplification. It indicates how many times the actual physical data written is compared to the written data volume, i.e., the data volume written to the flash memory ÷ the data volume written by the main controller = write amplification.

GC(Garbage Collection) Garbage collection. The storage writing of NAND media is carried out page by page and erased block by block.

02 Differences Between eMMC and NAND

(1) Comparison Between eMMC and NAND

NAND eMMC
Address Mapping Each time the CPU is mounted and read into memory, it is stored in NAND before being unloaded. Internal firmware management, using internal reservations
Wear leveling, bad block management and garbage collection NAND and file system drivers running on the CPU Internal firmware management, firmware maintenance by storage manufacturer
ECC error correction The CPU software or hardware is responsible for the error correction logic, and the error correction capability depends on the SoC controller and driver configuration. Internal firmware management with hardware ECC error correction
Write Amplification Determined by the CPU driver strategy. Determined by internal firmware, and some manufacturers provide interfaces to query write-amplification information.
Partition A unified area, and the partitioning is determined by the CPU. There are specific security partitions and boot partitions for storing different types of data.

(2) Related Features of eMMC

eMMC uses a separate hardware controller to manage storage, which is more reliable than NAND driver management under Linux.

The internal firmware integrates multiple functions, such as recording health information like service life and dynamically adjusting internal storage strategies according to different scenarios.

It has a standardized interface, with good compatibility among different manufacturers and capacities.

Generally, the storage lifespan of eMMC is shorter than that of NAND. Most NAND uses SLC or MLC, while most eMMC uses MLC or TLC. The unit lifespan of eMMC is lower than that of NAND. However, since the storage capacity of eMMC is generally large, it offsets the disadvantage of the low unit lifespan to a certain extent.

(3) Related Features of NAND

The driver of the system is mainly determined by the SoC manufacturer and the upstream logic of the system, which can not give full play to the advantages of different NAND storage media, or has the compatibility problem of the driver logic.

NAND is prone to bit flips, bad blocks, etc. Compared with the internal management of eMMC, CPU management requires a large amount of system overhead to maintain the stored content.

The interface standard uses the ONFI interface protocol, but there are differences in the configuration of the page, OOB area, and block size of NAND from different manufacturers. If the material is discontinued and needs to be replaced, there is a risk of image incompatibility.

The layout control of NAND is managed by the CPU, so the corresponding partition management and logic customization have great flexibility. Different management strategies can be formulated according to the actual application scenarios.

The unit storage lifespan of NAND is relatively long.

In summary, it is recommended to use eMMC with management functions for product storage selection.

03 Storage Usage Recommendations

eMMC: It is recommended to reserve 25% of the space to avoid frequent triggering of GC.

Since the minimum write unit of storage is a page and the minimum erase unit is a block, taking a 16K page as an example, if the data written at a single time is less than one page, it will cause write amplification. If the data written at a single time is much smaller than the page size, the write amplification will be very serious, ultimately leading to a significant reduction in lifespan. It is recommended to buffer small data first through DDR memory and then combine and write after buffering a certain amount of data.

If there is an abnormal power outage during use, the file system should be scanned and repaired regularly using tools to avoid file system abnormalities caused by data not being saved in time due to the abnormal power outage. In the scenario of frequent abnormal power outages, hardware power-outage protection measures can be added to ensure system stability.

At the initial stage of product design, it is necessary to combine the frequency of data storage in the actual application scenario. To ensure the product's lifespan requirements, the appropriate storage type and capacity should be evaluated and selected.

04 Folinx Embedded

(1) For eMMC

Based on the reading and analysis of lifespan and health information, the application can have a more comprehensive understanding of storage information and make reasonable adjustments.

The application can monitor the current storage lifespan in real-time to send an alarm signal for specific processing when the device's storage lifespan drops to a user-defined threshold.

The application can also view the system's health information in real-time, evaluate the write-amplification coefficient of the storage, and use it to evaluate the impact of application software upgrades on the storage, thereby estimating the remaining lifespan.

(2) For NAND

By adding means to count the actual erase-write, relocation, and marking information of NAND, suggestions for improving application IO operations can be provided.

(3) For all types of storage

Based on the collection and analysis of the characteristics of different usage scenarios of terminal devices, a reference for writing applications more suitable for the scenarios can be evaluated.

The actual application scenarios of terminals are mainly concentrated in: cyclic log storage, storage of key application data parameters, and buffer data.

Cyclic Log Storage: It features cyclic erase-write, frequent writing, and infrequent reading. When coexisting with the file system, the mixed storage of frequently written and read-only data will affect the overall stability. For example, the wear-leveling characteristic of most eMMC is across the entire disk, and the file system partitioning in software fails to achieve the desired data isolation effect, which can actually be solved in the initial evaluation stage.

Key Data: It consists of small-volume status information, which is relatively important but with a small amount of information.

Buffer Data: It features sequential writing and overall erasure.

In the actual software development process, to ensure product stability, optimization solutions are provided in the following three stages:

Before product development: Select the corresponding storage solution to assess risks in advance. Evaluate the storage type, file system type, application data read-write suggestions, and flashing method based on the target lifespan of the product in the actual application scenario.

Before the completion of product development: Optimize the actual storage. During the prototype testing stage of the product, it is necessary to statistically analyze the actual read-write frequency and size of the system and analyze the data stability of the storage (e.g., NAND storage bit-flipping and bad-block analysis). Based on the analysis, suggestions for optimizing the read-write data unit size and continuous/random read-write can be provided.

Before product deployment: Make a final assessment of the estimated lifespan. Provide an estimated lifespan in the actual application based on the final optimization effect.

In addition to the above optimization strategies, different eMMC and NAND manufacturers provide different optimization features on the premise of meeting the interface protocol standards. Some optimization features need to be combined with operating system modifications to achieve better results.

05 Summary

The stability of storage is directly related to the stability of the final product. This article compares and introduces the characteristics of eMMC and NAND, aiming to help R & D engineers develop products more simply and efficiently in the actual development process.




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!