An embedded file system and data management method based on serial Flash chip
By performing sector classification and circular buffer cache strategies on serial Flash chips, the problem of low garbage collection efficiency in embedded file systems is solved, efficient data management and long-life use of Flash chips are achieved, and data backup and history are supported.
Patent Information
- Application Number
- CN202211342537.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2042-10-28
AI Technical Summary
Existing embedded file systems are difficult to achieve efficient garbage collection on embedded platforms with resource-constrained resources, resulting in low utilization of Flash chips and difficult to implement data backup, data playback and data classification.
Design an embedded file system based on serial Flash chip. By classifying Flash memory by sector, using circular buffer cache strategy and data classification method, it realizes efficient access to fixed-length and variable-length data, and manages data through initialization, writing, reading, backup and backtracking modules.
It improves data reading and writing efficiency, reduces running memory requirements, extends the service life of the Flash chip, and has the functions of saving power-down data, reading and writing fixed length and variable-length data and playback history.
Smart Images

Figure CN116339614B_ABST
Abstract
Description
Technical Field
[0001] The invention discloses an embedded file system and a data management method based on a serial Flash chip, belonging to the technical field of data storage. Background Art
[0002] With the widespread adoption of embedded systems and the increasing complexity of embedded products, a single file system suitable for all embedded products is difficult to implement due to the limited resources and specialized nature of embedded systems. To meet the data access needs of the embedded field, implementing functions such as power-off data preservation, reading and writing fixed-length and variable-length data, and historical playback, it is crucial to implement a specialized file system and data management method based on serial Flash chips. However, existing embedded file systems struggle to achieve efficient garbage collection on resource-constrained embedded platforms, resulting in low Flash chip utilization.
[0003] Serial Flash memory has the advantages of power-off data preservation, online programming and fast data reading. Its composition is as shown in the attached figure. Figure 1 As shown, storage space is generally composed of multiple blocks. One block consists of 16 sectors, one sector consists of 16 pages, and one page can store 256 bytes. The smallest erase and write unit is a sector. In existing technologies, users have a simple way to manage embedded files, making it difficult to implement data backup, data playback, and data classification. Summary of the Invention
[0004] In view of the deficiencies in the prior art, the present invention discloses an embedded file system based on a serial Flash chip.
[0005] The invention also discloses a method for data management using the system.
[0006] The present invention partitions the Flash memory and adopts different access methods for fixed-length and variable-length data. At the same time, a circular buffer cache strategy is used to realize backtracking of various types of data, so as to achieve high data reading and writing efficiency, small running memory and simple implementation logic. SUMMARY OF THE INVENTION
[0008] The present invention aims to solve the problem that the existing embedded file management method is simple and difficult to implement data backup, data playback and data classification. The present invention designs and implements an embedded file system and data management system EFMS (Embedded File Management System) based on a serial Flash chip. The overall framework is shown in the attached figure. Figure 2 As shown:
[0009] First, all Flash blocks are classified by sector, with sector 1 defined as the read and write address storage area for various data storage areas. For variable-length data, the first sector of its storage area is defined as the directory area. All file data is read and written cyclically in a ring buffer to achieve load balancing for erase and write operations across sectors. This invention can effectively manage large amounts of embedded data, extend the life of Flash chips, and provide functions such as power-off data preservation, reading and writing fixed-length and variable-length data, and historical playback.
[0010] The detailed technical solutions of the present invention are as follows:
[0011] An embedded file system based on a serial Flash chip, characterized by comprising: an external interface, a functional module group, and a serial Flash memory;
[0012] The external interface is used to provide embedded file operations;
[0013] The functional module group includes: an initialization module, a data writing module, a data reading module, a backup module and a backtracking module;
[0014] The sectors in the serial Flash memory are divided into zones according to the types of stored data, wherein sector 1 is used to store the read and write addresses of various types of data.
[0015] A method for data management using the above system, characterized by comprising:
[0016] The initialization module is used to control the read, write and erase operations of all types of data, and the initialization module is only executed once. The flowchart of the initialization module is shown in the attached figure. Figure 3 As shown:
[0017] include:
[0018] 1-1) Determine whether it has been initialized:
[0019] If it has been initialized, exit;
[0020] If not initialized, proceed to step 1-2);
[0021] 1-2) Perform data classification;
[0022] 1-3) Determine the sector size occupied by various types of data;
[0023] 1-4) Confirm whether all types of data are backed up, update the read and write pointers of all types of data and store them in sector 1;
[0024] 1-5) Initialization operation completed.
[0025] With the increasing complexity of embedded product functions, existing Flash storage is difficult to adapt to the read and write operations of various types of data. The present invention classifies the Flash memory according to the minimum erase unit and allocates sector space according to the required maximum capacity. The data classification, occupied sector size, and whether to back up data are determined by the following methods: Figure 4 The structure type shown is given, where the occupied sector type is an integer, and 1 sector is 4K in size; whether to back up is a Boolean type, 1 indicates whether data backup is performed, and 0 indicates not to back up data; variable-length data indicates whether this type of data is variable-length data, and 1 indicates variable-length data; the end marker indicates the end of this classification.
[0026] According to the preferred embodiment of the present invention, the initialization module updates the read and write pointers of each type of data according to the data classification structure and saves it to sector 1, where Type 0 represents the read and write pointer data of sector 1; the read and write starting address of each type of data is the second sector; the calculation formula for the read and write starting address of each type of data and the maximum address of the occupied sector is as follows:
[0027]
[0028] sectorNm=sectorSN+4096×(Length en i +(1+Bakeup i )Size n )-1(II)
[0029] In formulas (I) and (II), sectorSN represents the first address of a certain type of data to be read or written; sectorNm represents the maximum address of a sector occupied by a certain type of data; 4096 represents that a sector occupies 4096 bytes; n represents the data type; Size i When it indicates the sector size occupied by a certain type of data; Bakeup i Indicates whether to back up. If such data needs to be backed up, the occupied sectors will be doubled. i Indicates whether the data is variable-length data. If it is variable-length data, an additional sector is required to store the data index.
[0030] The initialization module updates the calculated read and write starting addresses of various types of data to sector 1, where the write address, read address, and backtracking address are initially sectorSN, where the maximum address represents the maximum address length to which such data can be written, which is sectorNm. After the initialization module completes the initialization operation, the file operation is completed by calling the read, write, erase, and backtracking interfaces in the external interface.
[0031] Preferably, according to the present invention, the working process of the data writing module includes:
[0032] According to the different data types, two different types of data write operations are provided: fixed-length data and variable-length data. For variable-length data, an additional sector is required. Sector 1 where the initial address of the variable-length data is located is used as the index of this type of data. The flowchart of the write data module is as follows: Figure 6 As shown:
[0033] 2-1) Read the write address of the written data type in sector 1; determine whether the storage area is full:
[0034] If full, read;
[0035] If not, determine whether the maximum address is reached; if so, write from the starting address of the corresponding type of data and proceed to step 2-2); if not, proceed directly to step 2-2);
[0036] 2-2) Determine whether it is variable-length data: If yes, update the index data and proceed to step 2-3); if not, proceed directly to step 2-3);
[0037] 2-3) Write data in the same way as the data writing module;
[0038] 2-4) Update the corresponding type of data write address and write it into sector 1;
[0039] 2-5) The data write operation is completed.
[0040] Preferably, according to the present invention, the working process of the data writing module also includes: data packaging and writing. Since the Flash chip has the characteristics of erasing first and then writing, and can only be erased in units of sectors or blocks, the erasing time is relatively long. Therefore, the present invention proposes a data packaging and writing strategy. When the amount of written data is less than 1 / 100 of the sector size, that is, less than 40KB, the data is temporarily stored in the memory until the temporary data in the memory is greater than 1 / 10 of the sector size, that is, greater than 400KB, the temporary data is packaged and written to the Flash chip at one time.
[0041] Preferably, according to the present invention, the process of packaging the temporarily stored data at one time and writing the data into the Flash chip includes:
[0042] 2-6) Before the data write module runs, it first reads the write address of the current data type stored in sector 1;
[0043] 2-7) The data write module will determine whether the storage area is full based on the read and write addresses it reads:
[0044] If it is full, the user will be reminded to read the data to ensure that the unread data is not overwritten. A diagram of a certain type of data storage area being full is shown in the attached diagram. Figure 7 As shown;
[0045] The conditions for determining whether the storage area is full are as follows:
[0046] writeAddr+dataLength+1<=readAddr (III)
[0047] In formula (III), writeAddr represents the write address of such data updated in sector 1, dataLength represents the length of the data to be written, and readAddr represents the read address of such data updated in sector 1.
[0048] Preferably, according to the present invention, the working process of the data writing module further includes determining whether the data is written to the maximum address:
[0049] If the maximum address is written, the circular buffer cache strategy is used to write again from the starting address of the corresponding type of data. This method can retain the original data for data backtracking. The schematic diagram of writing the address pointer of a certain type of data to the maximum address is shown in the attached figure. Figure 8 As shown;
[0050] The conditions for determining whether the write pointer has reached the maximum address are as follows:
[0051] writeAddr+dataLength<=maxAddr(IV)
[0052] In formula (IV), writeAddr represents the write address of such data updated in sector 1, dataLength represents the length of the data to be written, and maxAddr represents the maximum address of such data updated in sector 1.
[0053] According to the preferred embodiment of the present invention, the working process of the data writing module also includes a data writing operation in a manner of reading first, then spelling and finally writing. In order to ensure that the original data in the storage area is not destroyed, the schematic diagram is shown in the attached figure. Figure 9 As shown;
[0054] First, calculate the actual address of the sector where the write address is located. The calculation formula is:
[0055] sectorSN=[writeAddr / 4096]*4096 (V)
[0056] In formula (V), [writeAddr / 4096] represents the maximum integer not exceeding writeAddr / 4096;
[0057] Secondly, read data from the starting address of the current sector of the write address to the write address;
[0058] Then, the data to be written is spliced onto the back of the read data, and the remaining data of this sector is read out and written into this sector after the splicing operation is continued;
[0059] For fixed-length data, write the data directly to the sector according to the data writing module. For variable-length data, add an index and record the index in the first sector of the starting address of such data. Use the second sector as a backup sector and point to the actual data storage location according to the data address and data length. The schematic diagram is as follows: Figure 10 As shown;
[0060] In order to consider the load balance of Flash chip erasure, after erasing the first sector of the corresponding category data, the directory is written in sequence until the end of the sector without the need for a second erasure operation; when the directory area is full, the directory area is backed up to the second sector according to the backup module for data backtracking and other operations, and the directory storage sector is erased again, after which the directory data can be rewritten in sequence.
[0061] Preferably, according to the present invention, the working process of the data writing module further includes: the data writing module finally updates the write pointer writeAddr=writeAddr+dataLen, and writes the updated write pointer into sector 1.
[0062] Preferably, according to the present invention, the working process of the data reading module includes:
[0063] According to the different data types, two different types of data reading operations are provided: fixed-length data and variable-length data. For variable-length data, an additional sector is required. The first sector where the initial address of the corresponding type of data is located is used as the index of the corresponding type of data. The flow chart of the data reading module is as follows: Figure 11 As shown;
[0064] 3-1) Obtaining a read address for a read data type in sector 1;
[0065] 3-2) Determine whether the storage area is empty:
[0066] If yes, it will prompt that the storage area is empty and data needs to be written;
[0067] If not, proceed to step 3-3);
[0068] 3-3) Determine whether the maximum address is read:
[0069] If yes, then read from the starting address of the corresponding type of data and perform steps 3-4);
[0070] If not, proceed to step 3-4);
[0071] 3-4) Determine whether it is variable-length data:
[0072] If yes, then read the index data and proceed to steps 3-5);
[0073] If not, proceed to step 3-5);
[0074] 3-5) Read data in accordance with the data read module, update the corresponding type of data read address and write to sector 1;
[0075] 3-6) The data read operation is completed.
[0076] Preferably, according to the present invention, the working process of the data reading module further includes:
[0077] 3-7) Before the data read module runs, it first reads the read address of the current data type stored in sector 1;
[0078] 3-8) The data reading module determines whether the storage area is empty based on the read and write addresses it reads:
[0079] If it is empty, the user needs to be reminded to write data. The schematic diagram of an empty data storage area is as follows: Figure 12 As shown;
[0080] The conditions for judging whether the storage area is empty are as follows:
[0081] writeAddr=readAddr (VI)
[0082] In formula (VI), writeAddr represents the write address of the corresponding class data updated in sector 1, and readAddr represents the read address of the corresponding class data updated in sector 1.
[0083] Preferably, according to the present invention, the working process of the data reading module further includes: determining whether the maximum address is read:
[0084] If the maximum address is read, the circular buffer cache strategy is used to read again from the starting address of the corresponding category data. The diagram of the maximum address read by the address pointer of a certain type of data is as follows Figure 13 As shown;
[0085] The conditions for judging whether the read pointer reads the maximum address are as follows:
[0086] readAddr+dataLength<=maxAddr (VII)
[0087] In formula (VII), readAddr represents the read address of such data updated in sector 1, dataLength represents the length of the data to be read, and maxAddr represents the maximum address of such data updated in sector 1.
[0088] Preferably, according to the present invention, the working process of the data reading module further includes: the data reading module performs a reading operation directly on the sector for fixed-length data, and needs to read the data index first for variable-length data. The index is recorded in the first sector of the starting address of such data, and the data pointing to the actual data storage location is read through the data address and data length recorded by the index. The schematic diagram is shown as follows Figure 14 shown.
[0089] Preferably, according to the present invention, the working process of the data reading module further includes: the data reading module finally updates the read pointer readAddr=readAddr+dataLen, and writes the updated read pointer into sector 1.
[0090] Preferably, according to the present invention, the working process of the backup module includes:
[0091] The backup operation will be selected according to the needs of each type of data. The backup operation has the advantage of recoverability in case of erroneous operation, providing a protection mechanism to ensure data security. Since the data reading module and the data writing module will not delete the existing data, when the ring storage area is full or the maximum address is written, the written data will be overwritten and the backup module will perform the backup operation. The backup operation will perform sector-level copy operation to improve the backup speed. The backup process is as follows: Figure 15 shown.
[0092] Preferably, according to the present invention, the working process of the backtracking module includes:
[0093] The backtracking module can choose to read out all or part of the historical data, providing a protection mechanism similar to a recycle bin to ensure data security. The backtracking pointer can be used to backtrack historical data. Since the data reading module and data writing module of the EFMS system do not delete existing data, when the ring storage area is full, the written data is overwritten. The backtracking module updates the backtracking address. The update process is as follows: Figure 16 shown.
[0094] The advantages of the present invention are:
[0095] 1. The present invention implements an embedded file system and data management method based on a serial Flash chip, which can meet the data access needs of the embedded field. By classifying data to determine the occupied sector size, the initialization module, data writing module, data reading module, backup module and backtracking module are used to implement functions such as power-off data preservation, erase and write load balancing, reading and writing fixed-length and variable-length data, ensuring data security and replaying historical records.
[0096] 2. The present invention uses a circular buffer cache strategy to implement the reading, writing, backup, and backtracking of various types of data. Different file operations are implemented for fixed-length and variable-length data, and variable-length data is stored using indexes. This not only allows for recording variable-length data but also improves data access speed. Furthermore, the circular buffer cache strategy enables backtracking of some or all data, achieving high data read and write efficiency and minimal memory usage.
[0097] 3. In view of the problem that it is difficult to achieve efficient garbage collection in the existing technology, resulting in low utilization of Flash chips, the present invention adopts the method of updating the read and write pointers to append written data, which not only ensures the persistence of historical data but also avoids fragmented data and the need for garbage collection.
[0098] 4. The erasure and writing of Flash chips have a certain lifespan. The existing embedded file system does not fully balance the erasure and writing times of each sector. The present invention performs cyclic reading and writing according to the concept of a ring storage area to achieve load balancing of the erasure times of each sector, thereby ensuring the service life of the Flash chip.
[0099] 5. By utilizing the two features described in 3 and 4, since the space occupied by historical data is always stored in the ring storage area of the Flash chip before it is overwritten, the embedded file system proposed by the present invention can efficiently perform data backtracking operations by simply updating the read pointer, and additionally provides a protection mechanism similar to a recycle bin to ensure data security. BRIEF DESCRIPTION OF THE DRAWINGS
[0100] Figure 1 This is a diagram of the serial Flash memory structure;
[0101] Figure 2 This is a system framework diagram of an embedded file system based on a serial Flash chip according to the present invention;
[0102] Figure 3 It is the initialization module flow chart;
[0103] Figure 4 It is a schematic diagram of the data classification structure;
[0104] Figure 5 This is a schematic diagram of the storage data of sector 1;
[0105] Figure 6 It is to write the data module flow chart;
[0106] Figure 7 It is a schematic diagram of a certain type of data storage area being full;
[0107] Figure 8 A certain type of data is written to the maximum address;
[0108] Figure 9 It is to write data schematic diagram;
[0109] Figure 10 It is a schematic diagram of writing variable-length data;
[0110] Figure 11 This is the flow chart of the data reading module;
[0111] Figure 12 It is an empty schematic diagram of a certain type of data storage area;
[0112] Figure 13 It is the maximum address to which a certain type of data is read;
[0113] Figure 14 This is a schematic diagram of reading variable-length data;
[0114] Figure 15 This is a schematic diagram of backup data;
[0115] Figure 16 This is a schematic diagram of the backtrace address offset. DETAILED DESCRIPTION
[0116] The present invention will be described in detail below with reference to the embodiments and the accompanying drawings, but is not limited thereto.
[0117] Example 1
[0118] As attached Figure 2 As shown, an embedded file system based on a serial Flash chip includes: an external interface, a functional module group, and a serial Flash memory;
[0119] The external interface is used to provide embedded file operations;
[0120] The functional module group includes: an initialization module, a data writing module, a data reading module, a backup module and a backtracking module;
[0121] The sectors in the serial Flash memory are divided into zones according to the types of stored data, wherein sector 1 is used to store the read and write addresses of various types of data.
[0122] Example 2
[0123] A method for data management using the above system, comprising:
[0124] The initialization module is used to control the read, write and erase operations of all types of data, and the initialization module is only executed once. The flowchart of the initialization module is shown in the attached figure. Figure 3 As shown:
[0125] include:
[0126] 1-1) Determine whether it has been initialized:
[0127] If it has been initialized, exit;
[0128] If not initialized, proceed to step 1-2);
[0129] 1-2) Perform data classification;
[0130] 1-3) Determine the sector size occupied by various types of data;
[0131] 1-4) Confirm whether all types of data are backed up, update the read and write pointers of all types of data and store them in sector 1;
[0132] 1-5) Initialization operation completed.
[0133] With the increasing complexity of embedded product functions, existing Flash storage is difficult to adapt to the read and write operations of various types of data. The present invention classifies the Flash memory according to the minimum erase unit and allocates sector space according to the required maximum capacity. The data classification, occupied sector size, and whether to back up data are determined by the following methods: Figure 4 The structure type shown is given, where the occupied sector type is an integer, and 1 sector is 4K in size; whether to back up is a Boolean type, 1 indicates whether data backup is performed, and 0 indicates not to back up data; variable-length data indicates whether this type of data is variable-length data, and 1 indicates variable-length data; the end marker indicates the end of this classification.
[0134] The initialization module will update the read and write pointers of each type of data according to the data classification structure and save it to sector 1. Type 0 represents the read and write pointer data of sector 1. The read and write starting address of each type of data is the second sector. The calculation formula for the read and write starting address of each type of data and the maximum address of the occupied sector is as follows:
[0135]
[0136] sectorNm=sectorSN+4096×(Length en i +(1+Bakeup i )Size n )-1(II)
[0137] In formulas (I) and (II), sectorSN represents the first address of a certain type of data to be read or written; sectorNm represents the maximum address of a sector occupied by a certain type of data; 4096 represents that a sector occupies 4096 bytes; n represents the data type; Size i When it indicates the sector size occupied by a certain type of data; Bakeup i Indicates whether to back up. If such data needs to be backed up, the occupied sectors will be doubled.i Indicates whether the data is variable-length data. If it is variable-length data, an additional sector is required to store the data index.
[0138] The initialization module updates the calculated read and write starting addresses of various types of data to sector 1, where the write address, read address, and backtracking address are initially sectorSN, where the maximum address represents the maximum address length to which such data can be written, which is sectorNm. After the initialization module completes the initialization operation, the file operation is completed by calling the read, write, erase, and backtracking interfaces in the external interface.
[0139] The working process of the data writing module includes:
[0140] According to the different data types, two different types of data write operations are provided: fixed-length data and variable-length data. For variable-length data, an additional sector is required. Sector 1 where the initial address of the variable-length data is located is used as the index of this type of data. The flowchart of the write data module is as follows: Figure 6 As shown:
[0141] 2-1) Read the write address of the written data type in sector 1; determine whether the storage area is full:
[0142] If full, read;
[0143] If not, determine whether the maximum address is reached; if so, write from the starting address of the corresponding type of data and proceed to step 2-2); if not, proceed directly to step 2-2);
[0144] 2-2) Determine whether it is variable-length data: If yes, update the index data and proceed to step 2-3); if not, proceed directly to step 2-3);
[0145] 2-3) Write data in the same way as the data module:
[0146] 2-4) Update the corresponding type of data write address and write it into sector 1;
[0147] 2-5) The data write operation is completed.
[0148] The working process of the data writing module also includes: data packaging and writing. Since the Flash chip has the characteristic of erasing before writing and can only be erased in units of sectors or blocks, the erasing time is relatively long. Therefore, the present invention proposes a data packaging and writing strategy. When the amount of data to be written is less than 1 / 100 of the sector size, that is, less than 40KB, the data is temporarily stored in the memory. When the temporary data in the memory is greater than 1 / 10 of the sector size, that is, greater than 400KB, the temporary data is packaged and written to the Flash chip at one time.
[0149] The process of packaging the temporarily stored data at one time and writing it into the Flash chip includes:
[0150] 2-6) Before the data write module runs, it first reads the write address of the current data type stored in sector 1;
[0151] 2-7) The data write module will determine whether the storage area is full based on the read and write addresses it reads:
[0152] If it is full, the user will be reminded to read the data to ensure that the unread data is not overwritten. A diagram of a certain type of data storage area being full is shown in the attached diagram. Figure 7 As shown:
[0153] The conditions for determining whether the storage area is full are as follows:
[0154] writeAddr+dataLength+1<=readAddr (III)
[0155] In formula (III), writeAddr represents the write address of such data updated in sector 1, dataLength represents the length of the data to be written, and readAddr represents the read address of such data updated in sector 1.
[0156] The working process of the data writing module also includes determining whether the data is written to the maximum address:
[0157] If the maximum address is written, the circular buffer cache strategy is used to write again from the starting address of the corresponding type of data. This method can retain the original data for data backtracking. The schematic diagram of writing the address pointer of a certain type of data to the maximum address is shown in the attached figure. Figure 8 As shown;
[0158] The conditions for determining whether the write pointer has reached the maximum address are as follows:
[0159] writeAddr+dataLength<=maxAddr (IV)
[0160] In formula (IV), writeAddr represents the write address of such data updated in sector 1, dataLength represents the length of the data to be written, and maxAddr represents the maximum address of such data updated in sector 1.
[0161] The working process of the data writing module also includes the following steps: first read, then spell and finally write to perform data writing operation. In order to ensure that the original data in the storage area is not destroyed, the schematic diagram is shown in the attached figure. Figure 9 As shown;
[0162] First, calculate the actual address of the sector where the write address is located. The calculation formula is:
[0163] sectorSN=[writeAddr / 4096]*4096 (V)
[0164] In formula (V), [writeAddr / 4096] represents the maximum integer not exceeding writeAddr / 4096;
[0165] Secondly, read data from the starting address of the current sector of the write address to the write address;
[0166] Then, the data to be written is spliced onto the end of the read data, and the remaining data of this sector is read out and spliced together before being written into this sector:
[0167] For fixed-length data, write the data directly to the sector according to the data writing module. For variable-length data, add an index and record the index in the first sector of the starting address of such data. Use the second sector as a backup sector and point to the actual data storage location according to the data address and data length. The schematic diagram is as follows: Figure 10 As shown;
[0168] In order to consider the load balance of Flash chip erasure, after erasing the first sector of the corresponding category data, the directory is written in sequence until the end of the sector without the need for a second erasure operation; when the directory area is full, the directory area is backed up to the second sector according to the backup module for data backtracking and other operations, and the directory storage sector is erased again, after which the directory data can be rewritten in sequence.
[0169] The working process of the data writing module also includes: the data writing module finally updates the write pointer writeAddr=writeAddr+dataLen, and writes the updated write pointer into sector 1.
[0170] The working process of the data reading module includes:
[0171] According to the different data types, two different types of data reading operations are provided: fixed-length data and variable-length data. For variable-length data, an additional sector is required. The first sector where the initial address of the corresponding type of data is located is used as the index of the corresponding type of data. The flow chart of the data reading module is as follows: Figure 11 As shown;
[0172] 3-1) Obtaining a read address for a read data type in sector 1;
[0173] 3-2) Determine whether the storage area is empty:
[0174] If yes, it will prompt that the storage area is empty and data needs to be written;
[0175] If not, proceed to step 3-3);
[0176] 3-3) Determine whether the maximum address is read:
[0177] If yes, then read from the starting address of the corresponding type of data and perform steps 3-4);
[0178] If not, proceed to step 3-4);
[0179] 3-4) Determine whether it is variable-length data:
[0180] If yes, then read the index data and proceed to steps 3-5);
[0181] If not, proceed to step 3-5);
[0182] 3-5) Read data in accordance with the data read module, update the corresponding type of data read address and write to sector 1;
[0183] 3-6) The data read operation is completed.
[0184] The working process of the data reading module also includes:
[0185] 3-7) Before the data read module runs, it first reads the read address of the current data type stored in sector 1:
[0186] 3-8) The data reading module determines whether the storage area is empty based on the read and write addresses it reads:
[0187] If it is empty, the user needs to be reminded to write data. The schematic diagram of an empty data storage area is as follows: Figure 12 As shown;
[0188] The conditions for judging whether the storage area is empty are as follows:
[0189] writeAddr=readAddr (VI)
[0190] In formula (VI), writeAddr represents the write address of the corresponding class data updated in sector 1, and readAddr represents the read address of the corresponding class data updated in sector 1.
[0191] The working process of the data reading module also includes: determining whether the maximum address is read:
[0192] If the maximum address is read, the circular buffer cache strategy is used to read again from the starting address of the corresponding category data. The diagram of the maximum address read by the address pointer of a certain type of data is as follows Figure 13 As shown;
[0193] The conditions for judging whether the read pointer reads the maximum address are as follows:
[0194] readAddr+dataLength<=maxAddr (VII)
[0195] In formula (VII), readAddr represents the read address of such data updated in sector 1, dataLength represents the length of the data to be read, and maxAddr represents the maximum address of such data updated in sector 1.
[0196] The working process of the data reading module also includes: the data reading module directly performs a reading operation on the sector for fixed-length data, and needs to read the data index first for variable-length data. The index is recorded in the first sector of the starting address of such data, and the data address and data length recorded by the index are read to point to the data storage location. The schematic diagram is shown as follows: Figure 14 shown.
[0197] The working process of the data reading module further includes: the data reading module finally updates the read pointer readAddr=readAddr+dataLen, and writes the updated read pointer into sector 1.
[0198] The working process of the backup module includes:
[0199] The backup operation will be selected according to the needs of each type of data. The backup operation has the advantage of recoverability in case of erroneous operation, providing a protection mechanism to ensure data security. Since the data reading module and the data writing module will not delete the existing data, when the ring storage area is full or the maximum address is written, the written data will be overwritten and the backup module will perform the backup operation. The backup operation will perform sector-level copy operation to improve the backup speed. The backup process is as follows: Figure 15 shown.
[0200] The working process of the backtracking module includes:
[0201] The backtracking module can choose to read out all or part of the historical data, providing a protection mechanism similar to a recycle bin to ensure data security. The backtracking pointer can be used to backtrack historical data. Since the data reading module and data writing module of the EFMS system do not delete existing data, when the ring storage area is full, the written data is overwritten. The backtracking module updates the backtracking address. The update process is as follows: Figure 16 shown.
Claims
1. A method for data management using an embedded file system based on a serial Flash chip, characterized in that: The embedded file system based on the serial Flash chip includes: an external interface, a function module group, and a serial Flash memory; The external interface is used to provide embedded file operations; The functional module group includes: an initialization module, a data writing module, a data reading module, a backup module and a backtracking module; The data write module is used to provide write operations for two different types of data: fixed-length data and variable-length data according to different data types; The data reading module is used to provide read operations for two different types of data: fixed-length data and variable-length data according to different data types; The backup module is used to perform backup operations on demand; The backtracking module is used to update the backtracking address; The sectors in the serial Flash memory are partitioned according to the type of data stored, where sector 1 is used to store the read and write addresses of various types of data; The initialization module is used to control the read, write, and erase operations of all types of data, and the initialization module is only executed once, including: 1-1) Determine whether it has been initialized: If it has been initialized, exit; If not initialized, proceed to steps 1-2); 1-2) Classify data; 1-3) Determine the sector size occupied by various types of data; 1-4) Confirm whether all types of data are backed up, update the read and write pointers of all types of data and store them in sector 1; 1-5) Initialization operation completed; The initialization module will update the read and write pointers of each type of data according to the data classification structure and save it to sector 1. Type 0 represents the read and write pointer data of sector 1. The read and write starting address of each type of data is the second sector. The calculation formula for the read and write starting address of each type of data and the maximum address of the occupied sector is as follows: (I) (II) In formulas (I) and (II) Indicates the first read and write address of a certain type of data; Indicates the maximum address of a sector occupied by a certain type of data; Indicates that a sector occupies 4096 bytes; Indicates which data type it is; Indicates the sector size occupied by a certain type of data; Indicates the data of category i as backup; Indicates the data length of the i-th type of data; The initialization module updates the calculated read and write first addresses of various data to sector 1, where the write address, read address, and backtrack address are initially , where the maximum address is After the initialization module completes the initialization operation, the file operation is completed by calling the read, write, erase and backtrack interfaces in the external interface.
2. The data management method according to claim 1, characterized in that: The working process of the data writing module includes: Provides write operations for two different types of data: fixed-length data and variable-length data, depending on the data type. Variable-length data requires an additional sector, and sector 1, where the initial address of the variable-length data is located, serves as the index for this type of data. 2-1) Read the write address of the written data type in sector 1; determine whether the storage area is full: If full, read; If not, determine whether the address has been written to the maximum address; if so, write from the starting address of the corresponding type of data and then proceed to step 2-2); if not, proceed directly to step 2-2); 2-2) Determine whether it is variable-length data: If so, update the index data and proceed to step 2-3); if not, proceed directly to step 2-3); 2-3) Write data in the same way as the data writing module; 2-4) Update the corresponding type of data write address and write it into sector 1; 2-5) The data write operation is completed.
3. The data management method according to claim 2, characterized in that: The working process of the data writing module also includes: data packaging and writing. When the amount of written data is less than 1 / 100 of the sector size, the data is temporarily stored in the memory. When the temporary data in the memory is greater than 1 / 10 of the sector size, the temporary data is packaged and written to the Flash chip at one time; The process of packaging the temporarily stored data at one time and writing it into the Flash chip includes: 2-6) Before the data write module runs, it first reads the write address of the current data type stored in sector 1; 2-7) The write data module will determine whether the storage area is full based on the read and write addresses it reads: If it is full, remind the user to read the data; The conditions for determining whether the storage area is full are as follows: (Ⅲ) In formula (III), Indicates that the write address of this type of data in sector 1 is updated. Represents the length of the data to be written, Represents updating the read address of such data in sector 1; The working process of the data writing module also includes determining whether the data is written to the maximum address: If the maximum address is reached, a circular buffer cache strategy is used to write again from the starting address of the corresponding type of data; The conditions for determining whether the write pointer has reached the maximum address are as follows: (Ⅳ) In formula (IV), Indicates that the write address of this type of data in sector 1 is updated. Represents the length of the data to be written, Indicates the maximum address of this type of data updated in sector 1; The working process of the data writing module also includes performing data writing operations in a manner of first reading, then spelling and finally writing; First, calculate the starting address of the sector where the write address is located. The calculation formula is: (Ⅴ) In formula (V), [writeAddr / 4096] represents the maximum integer not exceeding writeAddr / 4096; Secondly, read data from the starting address of the current sector of the write address to the write address; Then, the data to be written is spliced onto the back of the read data, and the remaining data of this sector is read out and written into this sector after the splicing operation is continued; For fixed-length data, write the data directly to the sector according to the data writing module. For variable-length data, add an index and record the index in the first sector of the starting address of such data. The second sector is used as a backup sector. At the same time, the data address and data length are used to point to the actual data storage location. After erasing the first sector of the corresponding category data, the directory is written in sequence until the end of the sector without the need for a second erasing operation; when the directory area is full, the directory area is backed up to the second sector for data operations according to the backup module, and the directory storage sector is erased again.
4. The data management method according to claim 3, characterized in that: The working process of the data writing module also includes the following steps: the data writing module will finally update the write pointer and write the updated write pointer to sector 1.
5. The data management method according to claim 1, characterized in that: The working process of the data reading module includes: According to the different data types, two different types of data reading operations are provided: fixed-length data and variable-length data. For variable-length data, an additional sector is required. The first sector where the initial address of the corresponding type of data is located is used as the index of the corresponding type of data. 3-1) Obtain the read address of the read data type in sector 1; 3-2) Determine whether the storage area is empty: If yes, it will prompt that the storage area is empty and data needs to be written; If not, proceed to step 3-3); 3-3) Determine whether the maximum address is read: If yes, then read from the starting address of the corresponding type of data and proceed to steps 3-4); If not, proceed to steps 3-4); 3-4) Determine whether it is variable-length data: If yes, read the index data and proceed to steps 3-5); If not, proceed to steps 3-5); 3-5) Read data in the same way as the data read module, update the corresponding data read address and write it into sector 1; 3-6) Read data operation completed; The working process of the data reading module also includes: 3-7) Before the data read module runs, it first reads the read address of the current data type stored in sector 1; 3-8) The data reading module determines whether the storage area is empty based on the read and write addresses it reads: If it is empty, the user needs to be reminded to write data; The conditions for judging whether the storage area is empty are as follows: (Ⅵ) In formula (VI), Indicates updating the corresponding category data write address in sector 1. Indicates updating the corresponding category data read address in sector 1; The working process of the data reading module also includes: determining whether the maximum address is read: If the maximum address is read, a circular buffer cache strategy is used to read again from the starting address of the corresponding category data; The conditions for judging whether the read pointer reads the maximum address are as follows: (Ⅶ) In formula (VII), Represents the update of the data read address in sector 1. Represents the length of the data to be read. Indicates the maximum address of this type of data updated in sector 1; The working process of the data reading module also includes: the data reading module performs reading operations directly on the sector for fixed-length data, and needs to read the data index first for variable-length data. The index is recorded in the first sector of the starting address of such data, and the data pointing to the actual data storage location is read through the data address and data length recorded by the index.
6. The data management method according to claim 5, characterized in that: The working process of the data reading module also includes: the data reading module will finally update the read pointer and write the updated read pointer to sector 1.
7. The data management method according to claim 1, characterized in that: The working process of the backup module includes: When the ring storage area is full or the data is written to the maximum address, the backup module performs a backup operation.
8. The data management method according to claim 1, characterized in that: The working process of the backtracking module includes: When the ring storage area is full, the written data is overwritten, and the backtracking module performs an operation of updating the backtracking address.
Citation Information
Patent Citations
Flash memory based magnetic tape simulation method
CN101968722A
A Flash memory data storage method and a read method
CN109271100A
A flash memory data protection and restoration method
CN113010110A