The invention discloses an embedded
file system implementation method based on SPI Flash, which comprises the following steps: reading a super block during initialization, and establishing a state mapping table of
file record items and data sectors; when the file is opened, quickly matching
record items through file name
metadata, and if the matching fails, allocating new items; during reading and writing, aggregating data through the write cache, asynchronously updating the data to the
flash memory and refreshing the mapping table; if a change occurs when the file is closed, distributing a new space and marking the original space as failure to avoid real-time erasing; and finally,
garbage collection and
defragmentation are executed in the idle period of the
system. According to the method, the direct access to the SPI Flash is reduced through the
memory mapping table, the erasing frequency is reduced by utilizing the write cache and an asynchronous mechanism, and the time-consuming erasing operation is transferred to the background, so that the
processing efficiency of file operation and the real-time performance of the
system are remarkably improved, and meanwhile, the service life of a storage medium is prolonged.