An embedded data storage method and device, a terminal device and a storage medium

By dividing the Flash memory space into a data area, a mapping area, and an index area, the problems of long power-on time, uneven read/write operations, and redundancy in existing technologies are solved, enabling dynamic storage and data verification, and improving storage efficiency and reliability.

CN120353386BActive Publication Date: 2025-11-18SUNLUX IOT TECHNOLOGY (GUANGDONG) INC

Patent Information

Application Number
CN202510391457.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-11-18
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

Existing Flash memory suffers from problems such as long power-on time, uneven read/write operations, space redundancy, inability to dynamically adapt to storage needs, lack of data verification mechanisms, and complex management.

Method used

The storage space is divided into a data area, a mapping area, an index area, and a backup index area. The index area records data status information, the mapping area records data storage information, and a verification mechanism ensures successful data writing, thereby achieving dynamic storage and balanced read/write.

Benefits of technology

It improves storage efficiency and reliability, shortens system startup time, extends the lifespan of storage devices, and ensures data accuracy and integrity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353386B_ABST
    Figure CN120353386B_ABST
Patent Text Reader

Abstract

The application provides an embedded data storage method and device, terminal equipment and storage medium. The method comprises the following steps: when the memory is powered on for the first time, the storage space of the memory is divided into several functional areas located in different sectors; whenever the memory is powered on, the data state record information of the index area is acquired, and the data write position of the previous data write instruction and the next data write address are acquired based on the data state record information; when the data write instruction uploaded by the user is received, the data state information of the index area and the mapping area is updated, the data state update information of the index area is synchronously updated to the backup index area, and the corresponding data block is written in the data area according to the next data write address; the written data block is checked according to the data storage information; and when the data checking result of the data block is passed, it is determined that the data write is successful. The application can improve the efficiency and reliability of data storage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded systems technology, and in particular to an embedded data storage method, apparatus, terminal device, and storage medium. Background Technology

[0002] Flash memory (hereinafter referred to as Flash memory) is a non-volatile storage medium based on a floating-gate transistor structure. It achieves persistent data storage through charge storage. In the embedded field, when faced with situations requiring large amounts of data to be saved even after power loss and frequent read / write operations, Flash memory is the mainstream approach. Its storage capacity ranges from 1MB to 1GB, and its read speed can reach over 100Mbps. When the memory is powered on, it divides the storage space into N regions based on the required area and the actual size. The base address of the first region is obtained first, and the addresses of the remaining regions are obtained by offsetting from the base address. In terms of data management, specific small spaces are allocated at the beginning and end of each region. The front end stores the data size of the current region, and the back end stores the checksum of the data in the current region. During read / write operations, the storage segment to be read or written is determined based on the index number, and then the corresponding address is directly offset for reading or writing.

[0003] However, existing Flash memory usage methods also have many drawbacks. First, upon power-up, the entire storage space needs to be traversed to find the latest cache area, a process that is time-consuming. Second, under frequent read / write operations, it is impossible to determine data usage, easily leading to read / write imbalances. Third, space redundancy is a significant issue; fixed-size partitions cannot adapt to dynamic changes in storage needs, resulting in lower efficiency when storing large amounts of small data and an inability to handle dynamically changing data lengths. Fourth, there is a lack of cross-checking mechanisms, making it difficult to identify bad data. Fifth, maintenance and management are complex; when there are many partitions in the Flash memory, additional management mechanisms are needed to prevent partitions from becoming overcrowded or idle, and the verification and index management of each partition increases code complexity, especially when partition fragmentation exists. Summary of the Invention

[0004] The present invention aims to provide an embedded data storage method, apparatus, terminal device, and storage medium to solve the above-mentioned technical problems and improve the efficiency and reliability of data storage.

[0005] To address the aforementioned technical problems, this invention provides an embedded data storage method applied to flash memory, comprising:

[0006] When the memory is powered on for the first time, the memory space is divided into several functional areas located in different sectors; wherein, the types of functional areas include data area, mapping area, index area and backup index area;

[0007] Whenever the memory is powered on, the data status record information of the index area is obtained, and the data write position of the previous data write instruction and the next data write address are obtained based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information;

[0008] When a user uploads a data write instruction, the system updates the data status information of the indexed area and the mapped area, and synchronously updates the data status information of the indexed area to the backup indexed area. Based on the next data write address, the system writes the corresponding data block to the data area. The system verifies the written data block based on the data storage information. When the data block verification result is passed, the data write is deemed successful. The backup indexed area is used for backup storage of the indexed area.

[0009] In the above scheme, the storage space is divided into functional areas such as a data area, a mapping area, an index area, and a backup index area upon initial power-on. The data area can dynamically allocate space based on the actual data volume, no longer limited by fixed partitions. The mapping area records the data storage information of each data block, accurately recording its storage location regardless of changes in data block length, achieving dynamic storage of data length. The concept of an index area partition is introduced; upon power-on, data status records can be directly obtained from the index area, quickly determining the data write location of the previous write instruction and the address of the next write instruction. The index area acts as a fast index for data storage locations, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving system startup speed. Furthermore, the index area and mapping area work together; the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data write instruction is received, data can be written to the appropriate location based on the data status information, avoiding over-reading and writing in certain areas, achieving a balanced distribution of read and write operations, and extending the lifespan of the storage device. During the data writing process, the data blocks being written are verified based on the data storage information recorded in the mapping area. Only when the data block passes the verification is the data write considered successful. This verification mechanism can promptly detect errors that may occur during data transmission or storage, ensuring the accuracy and integrity of the data.

[0010] In one implementation, the step of acquiring the data status record information of the index area whenever the storage is powered on specifically includes:

[0011] When the memory is powered on, the memory interface is initialized and the data storage status of the index area is determined;

[0012] If the index area is not empty and the data status record information does not conform to the preset data storage rules, then erase the current storage content of the index area, copy the storage content of the backup index area to the index area, and update the index area;

[0013] Read the data status information recorded in the index area to obtain the data status record information.

[0014] In one implementation, the mapping area is used to record the data storage information of each data block in the data area, specifically:

[0015] The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but not read, and read.

[0016] In one implementation, when a user-uploaded data write instruction is received, updating the data status information of the indexed area and the mapped area, and writing the corresponding data block in the data area according to the next data write address, specifically includes:

[0017] Based on the data write instruction, the data status information of the index area and the mapping area is updated to "written but not read", and the starting address of the data block is recorded in the mapping area;

[0018] The next data write address is used as the starting address, and the corresponding data block is written in the data area based on the starting address.

[0019] In one implementation, the step of verifying the written data block based on the data storage information, and determining that the data writing was successful when the data block verification result is passed, specifically includes:

[0020] After the data block is written, a check byte is generated based on a preset check rule as the last data byte of the data block; wherein, the preset check rule is to add each byte of the data block one by one to obtain a sum byte as the check code of the data block;

[0021] Obtain the starting address and data length of the data block, and generate a checksum based on the preset checksum rules;

[0022] When the data byte matches the checksum, the data block is determined to have been successfully written.

[0023] In one implementation, the backup index area is used for backup storage of the index area, and further includes:

[0024] The data storage space of the index area is monitored in real time. When the data storage space of the index area is full, the data status record information of the index area is copied to the backup index area and the storage content of the index area is erased.

[0025] Read the data status record information copied from the backup index area and clear the records whose data status information is marked as read, then rewrite the cleared data status record information into the index area.

[0026] In one implementation, the embedded data storage method further includes:

[0027] When a user uploads a data read instruction, the data status information of the index area and the mapping area is updated to "read" and the starting address of the target data block of the read instruction recorded in the mapping area is obtained.

[0028] The data length control pointer of the target data block is offset from the starting address to read the target data block.

[0029] Secondly, this application also provides an embedded data storage device for use in flash memory, comprising: a functional partitioning module, a data recording module, and a data writing module;

[0030] The functional partitioning module is used to divide the storage space of the memory into several functional areas located in different sectors when the memory is first powered on; wherein, the types of the functional areas include data area, mapping area, index area and backup index area;

[0031] The data recording module is used to acquire the data status recording information of the index area whenever the memory is powered on, and to acquire the data write position of the previous data write instruction and the next data write address based on the data status recording information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information;

[0032] The data writing module is used to update the data status information of the indexed area and the mapped area when it receives a data writing instruction uploaded by the user, and synchronously update the data status update information of the indexed area to the backup indexed area. It writes the corresponding data block in the data area according to the next data writing address; verifies the written data block according to the data storage information; and determines that the data writing is successful when the data verification result of the data block is passed. The backup indexed area is used to back up and store the indexed area.

[0033] In the above scheme, the storage space is divided into functional areas such as a data area, a mapping area, an index area, and a backup index area upon initial power-on. The data area can dynamically allocate space based on the actual data volume, no longer limited by fixed partitions. The mapping area records the data storage information of each data block, accurately recording its storage location regardless of changes in data block length, achieving dynamic storage of data length. The concept of an index area partition is introduced; upon power-on, data status records can be directly obtained from the index area, quickly determining the data write location of the previous write instruction and the address of the next write instruction. The index area acts as a fast index for data storage locations, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving system startup speed. Furthermore, the index area and mapping area work together; the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data write instruction is received, data can be written to the appropriate location based on the data status information, avoiding over-reading and writing in certain areas, achieving a balanced distribution of read and write operations, and extending the lifespan of the storage device. During the data writing process, the data blocks being written are verified based on the data storage information recorded in the mapping area. Only when the data block passes the verification is the data write considered successful. This verification mechanism can promptly detect errors that may occur during data transmission or storage, ensuring the accuracy and integrity of the data.

[0034] In one implementation, the data recording module is used to acquire data status recording information of the index area whenever the memory is powered on, specifically including:

[0035] When the memory is powered on, the memory interface is initialized and the data storage status of the index area is determined;

[0036] If the index area is not empty and the data status record information does not conform to the preset data storage rules, then erase the current storage content of the index area, copy the storage content of the backup index area to the index area, and update the index area;

[0037] Read the data status information recorded in the index area to obtain the data status record information.

[0038] In one implementation, the mapping area is used to record the data storage information of each data block in the data area, specifically:

[0039] The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but not read, and read.

[0040] In one implementation, the data writing module is used to update the data status information of the indexed area and the mapped area when it receives a data writing instruction uploaded by a user, and write the corresponding data block in the data area according to the next data writing address, specifically including:

[0041] Based on the data write instruction, the data status information of the index area and the mapping area is updated to "written but not read", and the starting address of the data block is recorded in the mapping area;

[0042] The next data write address is used as the starting address, and the corresponding data block is written in the data area based on the starting address.

[0043] In one implementation, the step of verifying the written data block based on the data storage information, and determining that the data writing was successful when the data block verification result is passed, specifically includes:

[0044] After the data block is written, a check byte is generated based on a preset check rule as the last data byte of the data block; wherein, the preset check rule is to add each byte of the data block one by one to obtain a sum byte as the check code of the data block;

[0045] Obtain the starting address and data length of the data block, and generate a checksum based on the preset checksum rules;

[0046] When the data byte matches the checksum, the data block is determined to have been successfully written.

[0047] In one implementation, the backup index area is used for backup storage of the index area, and further includes:

[0048] The data storage space of the index area is monitored in real time. When the data storage space of the index area is full, the data status record information of the index area is copied to the backup index area and the storage content of the index area is erased.

[0049] Read the data status record information copied from the backup index area and clear the records whose data status information is marked as read, then rewrite the cleared data status record information into the index area.

[0050] In one implementation, the embedded data storage device further includes:

[0051] When a user uploads a data read instruction, the data status information of the index area and the mapping area is updated to "read" and the starting address of the target data block of the read instruction recorded in the mapping area is obtained.

[0052] The data length control pointer of the target data block is offset from the starting address to read the target data block.

[0053] Thirdly, this application also provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the embedded data storage method described above.

[0054] Fourthly, this application also provides a computer-readable storage medium, which includes a stored computer program, wherein the computer program controls the device where the computer-readable storage medium is located to execute the embedded data storage method described above when it is running. Attached Figure Description

[0055] Figure 1 This is a flowchart illustrating an embedded data storage method provided in one embodiment of the present invention;

[0056] Figure 2 This is a schematic diagram of an embedded data storage device provided in one embodiment of the present invention. Detailed Implementation

[0057] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0058] The terms "first" and "second," etc., in the specification, claims, and drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or apparatus.

[0059] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0060] Example 1

[0061] See Figure 1 , Figure 1 This is a flowchart illustrating an embedded data storage method according to an embodiment of the present invention. The embodiment includes steps 101 to 103, each step of which is detailed below:

[0062] Step 101: When the memory is powered on for the first time, the storage space of the memory is divided into several functional areas located in different sectors; wherein, the types of the functional areas include data area, mapping area, index area and backup index area.

[0063] In this embodiment of the invention, a partitioning operation is performed when the flash memory is first powered on. Since flash memory erase and write operations are performed in sectors, to ensure that each functional area can be erased, written, and updated independently, the four areas—data area, mapping area, index area, and backup index area—must be allocated to different sectors. The space size of each functional area is pre-allocated and can be set according to specific needs. For example, the index area and backup index area are each 4KB, the mapping area is 512KB, and the data area is 1400KB. This partitioning mechanism effectively ensures the efficiency, reliability, and flexibility of the storage.

[0064] Step 102: Whenever the memory is powered on, obtain the data status record information of the index area, and obtain the data write position of the previous data write instruction and the next data write address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information.

[0065] Each time the memory is powered on, the index area is operated on first. The index area records the data status information of the mapping area, with three statuses: unused, written but not read, and read. By reading the data status record information in the index area, the data write position of the previous data write instruction can be quickly located, and the address of the next data write can also be determined. The mapping area records detailed information about each data block in the data area, such as the starting address, length, and usage status of the data block. This information helps the system manage the storage of the data area more efficiently.

[0066] In one embodiment, the step of acquiring the data status record information of the index area whenever the storage is powered on specifically includes: when the storage is powered on, initializing the interface of the storage and judging the data storage status of the index area; if the index area is not empty and the data status record information does not conform to the preset data storage rules, then erasing the current storage content of the index area and copying the storage content of the backup index area to the index area to update the index area; and reading the data status record information recorded in the index area to obtain the data status record information.

[0067] In this embodiment of the invention, after the memory is powered on, the memory interface is first initialized to ensure that the interface can work normally. The data storage status of the index area is then determined. Due to the characteristics of Flash memory, only binary 1s can be written as 0s. During erasure, the storage space is entirely 0xff; after writing data, it becomes 0x55; after reading data, it becomes 0x00. Data reading and writing are sequential. If the data in the index area does not conform to the order 0xff->0x55->0x00, the data is considered abnormal. If the index area is not empty and the data state machine's I-way information conforms to the preset data storage rules, it can be read directly. If the index area is not empty and the data does not conform to the preset storage rules, the current storage content of the index area is erased first. Because Flash erasure is necessary, data can only be rewritten after erasure. Then, the content stored in the backup index area is copied to the index area to restore the index area data. Afterward, the index area is updated to ensure that the data in the index area is accurate and valid. After completing the above operations, the data status information recorded in the index area is read. Since each index in the index area is 1 byte, the space size is 4KB, meaning there are 4096 indexes. Reading these indexes sequentially yields complete data status record information, providing a basis for subsequent data operations. It should be noted that the preset storage rules in this embodiment are illustrative examples based on the basic storage requirements of flash memory devices. Further custom settings can be made according to user requirements, and are not limited here.

[0068] In one embodiment, the mapping area is used to record the data storage information of each data block in the data area, specifically: the data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but not read, and read.

[0069] In this embodiment of the invention, the main function of the mapping area is to index the storage structure of the data area. The data storage information it records includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block. The starting address of the data block helps to quickly locate the data in the data area, while the length of the data block specifies the size of the data. The data status information is divided into three types: unused, written but not read, and read. Through this status information, the data in the data area can be managed efficiently, avoiding direct operations on the data area and improving the stability and performance of the system. For example, the data format of the mapping area can be pre-defined, i.e., the starting address of the data block occupies 3 bytes, the data length occupies 1.5 bytes, and the data usage flag occupies 0.5 bytes (0xf indicates unused, 0x5 indicates written, and 0x0 indicates read), with each mapping being a constant 5 bytes in size.

[0070] Step 103: When a user uploads a data write instruction, update the data status information of the indexed area and the mapped area, and synchronously update the data status update information of the indexed area to the backup indexed area. Write the corresponding data block in the data area according to the next data write address. Verify the written data block according to the data storage information. When the data verification result of the data block is passed, it is determined that the data write is successful. The backup indexed area is used to back up and store the indexed area.

[0071] In one embodiment, when a user-uploaded data write instruction is received, updating the data status information of the indexed area and the mapped area, and writing the corresponding data block in the data area according to the next data write address, specifically includes: updating the data status information of the indexed area and the mapped area to "written but not read" based on the data write instruction, and recording the starting address of the data block in the mapped area; using the next data write address as the starting address, and writing the corresponding data block in the data area based on the starting address.

[0072] In this embodiment of the invention, upon receiving a user's data write instruction, the data status information of the index area and the mapping area is immediately updated. The data status of these two areas is updated to "written but not read," indicating that data has been written but not yet read. Simultaneously, the starting address of the data block is recorded in the mapping area; this starting address is the previously determined next data write address. This allows for accurate location of the data in the data area during subsequent data reading. The next data write address determined at startup is used as the starting address of the data block, and the corresponding data block is written to the data area based on this starting address. During the writing process, data is written sequentially according to the length of the data block, ensuring accurate storage of data in the data area. If the system is not in a newly booted state, the next data write address can also be obtained directly by querying the data status record information in the index area.

[0073] In one embodiment, the step of verifying the written data block according to the data storage information, and determining that the data writing is successful when the data verification result of the data block is passed, specifically includes: after the data block is written, generating a one-bit check byte as the last data byte of the data block based on a preset verification rule; wherein, the preset verification rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block; obtaining the starting address and data length of the data block, and generating a check code based on the preset verification rule; when the data byte matches the check code, determining that the data block is written successfully.

[0074] In this embodiment of the invention, after the data block is written, a checksum is generated according to a preset verification rule. Specifically, each byte of the data block is added together to obtain a sum byte, which is the checksum. This checksum is then stored as the last data byte of the data block in the data area. This way, when reading data subsequently, the integrity of the data can be verified by recalculating the checksum and comparing it with the stored checksum. To perform data verification, the starting address and data length of the data block are obtained from the mapping area. Then, the data block is read from the data area based on this information, and the checksum is regenerated according to the preset verification rule (adding each byte). The regenerated checksum is compared with the last byte of the data block (i.e., the stored checksum). If they match, it indicates that no errors occurred during the data writing process, and the data block was successfully written; if they do not match, it indicates that errors may have occurred during the data writing process, and a rewrite operation is performed to ensure the accuracy and integrity of the data.

[0075] In one embodiment, the backup index area is used to back up and store the index area, and further includes: real-time detection of the data storage space of the index area; when the data storage space of the index area is full, copying the data status record information of the index area to the backup index area and erasing the storage content of the index area; reading the data status record information copied from the backup index area and clearing the record information whose data status information is read, and rewriting the cleared data status record information back into the index area.

[0076] In this embodiment of the invention, the data storage space of the index area is monitored in real time. Since each index in the index area is 1 byte, the space size is 4KB, meaning there is a storage limit of 4096 indexes. When the number of indexes in the index area reaches 4096, it indicates that the data storage space of the index area is full. At this time, the data status record information of the index area is copied to the backup index area to prevent data loss. Then, the storage content of the index area is erased to free up space for subsequent data writing. After copying the data from the index area to the backup index area and erasing the index area content, the copied data status record information is read from the backup index area. Then, this information is organized, and records with a data status of "read" are cleared. Because these read data records may no longer be needed later, clearing them saves storage space in the index area. Finally, the cleared record information is rewritten to the index area, completing the index area update.

[0077] In one embodiment, the embedded data storage method further includes: when a user-uploaded data reading instruction is received, updating the data status information of the index area and the mapping area to "read", and obtaining the starting address of the target data block of the reading instruction recorded in the mapping area; and offsetting the data length control pointer of the target data block at the starting address to realize the reading of the target data block.

[0078] In this embodiment of the invention, when a user's data read instruction is received, the data status information in the index area and mapping area is first updated to "read," indicating that the data block has been read. Then, the starting address of the target data block is obtained from the mapping area. Since the mapping area records the starting address of each data block in the data area, the location of the target data block in the data area can be quickly located using this address. After obtaining the starting address of the target data block, the data length of the data block is also obtained from the mapping area. Then, based on the data length, the control pointer is offset from the starting address, and each byte in the data block is read sequentially until the entire data block is read. Preferably, after reading, the read data can be verified by adding each byte of the read data to obtain the read sum and comparing it with the write sum. If they match, the data is error-free and can be used safely; if they do not match, it indicates that an error may have occurred during the reading process, invalid data is discarded, and a warning is issued.

[0079] In this embodiment of the invention, an embedded data storage device is also provided, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the above-described embedded data storage method.

[0080] In this embodiment of the invention, a computer-readable storage medium is also provided, which includes a stored computer program, wherein the computer program controls the device where the computer-readable storage medium is located to execute the above-described embedded data storage method when it is running.

[0081] For example, a computer program can be divided into one or more modules, one or more of which are stored in memory and executed by a processor to perform the present invention. The one or more modules can be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in an embedded data storage device.

[0082] The embedded data storage device can be a computing device such as a desktop computer, laptop, handheld computer, or cloud server. The embedded data storage device may include, but is not limited to, a processor, memory, and a display. Those skilled in the art will understand that the above components are merely examples of embedded data storage devices and do not constitute a limitation on the embedded data storage device. It may include more or fewer components than the specified components, or a combination of certain components, or different components. For example, the embedded data storage device may also include input / output devices, network access devices, buses, etc.

[0083] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the embedded data storage device, connecting all parts of the embedded data storage device through various interfaces and lines.

[0084] Memory can be used to store computer programs and / or modules. The processor performs various functions on the embedded data storage device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. Memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, at least one application program required for a function (such as sound playback, text conversion, etc.), etc.; the data storage area can store data created based on the use of the mobile phone (such as audio data, text message data, etc.). In addition, memory can include high-speed random access memory, and can also include non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital cards (SD cards), flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.

[0085] Wherein, if the module for embedded data storage is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. Those skilled in the art can understand and implement this without any inventive effort.

[0086] This invention provides an embedded data storage method that divides the storage space into functional areas such as a data area, a mapping area, an index area, and a backup index area upon initial power-on. The data area can dynamically allocate space based on the actual data volume, no longer limited by fixed partitions. The mapping area records the data storage information of each data block, accurately recording its storage location regardless of changes in data block length, achieving dynamic storage of data length. The concept of an index area partitioning is introduced; upon power-on, data status records can be directly obtained from the index area, quickly determining the data write location of the previous write instruction and the address of the next write instruction. The index area acts as a fast index for data storage locations, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving system startup speed. Furthermore, the index area and mapping area work together; the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data write instruction is received, data can be written to the appropriate location based on the data status information, avoiding over-reading and writing in certain areas, achieving a balanced distribution of read and write operations, and extending the lifespan of the storage device. During the data writing process, the data blocks being written are verified based on the data storage information recorded in the mapping area. Only when the data block passes the verification is the data write considered successful. This verification mechanism can promptly detect errors that may occur during data transmission or storage, ensuring the accuracy and integrity of the data.

[0087] Example 2

[0088] See Figure 2 , Figure 2 This is a schematic diagram of an embedded data storage device according to an embodiment of the present invention. The embodiment of the present invention provides an embedded data storage device applied to a flash memory, comprising: a functional partitioning module 201, a data recording module 202, and a data writing module 203;

[0089] The functional partitioning module 201 is used to divide the storage space of the memory into several functional areas located in different sectors when the memory is first powered on; wherein, the types of the functional areas include data area, mapping area, index area and backup index area;

[0090] The data recording module 202 is used to acquire the data status recording information of the index area whenever the memory is powered on, and to acquire the data write position of the previous data write instruction and the next data write address based on the data status recording information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information;

[0091] The data writing module 203 is used to update the data status information of the indexed area and the mapped area when it receives a data writing instruction uploaded by the user, and synchronously update the data status update information of the indexed area to the backup indexed area. It writes the corresponding data block in the data area according to the next data writing address; verifies the written data block according to the data storage information; and determines that the data writing is successful when the data verification result of the data block is passed. The backup indexed area is used to back up and store the indexed area.

[0092] In one embodiment, the data recording module is used to acquire the data status recording information of the index area whenever the memory is powered on. Specifically, this includes: when the memory is powered on, initializing the interface of the memory and judging the data storage status of the index area; if the index area is not empty and the data status recording information does not conform to the preset data storage rules, erasing the current storage content of the index area and copying the storage content of the backup index area to the index area to update the index area; and reading the data status information recorded in the index area to obtain the data status recording information.

[0093] In one embodiment, the mapping area is used to record the data storage information of each data block in the data area, specifically: the data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but not read, and read.

[0094] In one embodiment, the data writing module is used to update the data status information of the indexed area and the mapping area when it receives a data writing instruction uploaded by the user, and write the corresponding data block in the data area according to the next data writing address. Specifically, it includes updating the data status information of the indexed area and the mapping area to "written but not read" based on the data writing instruction, and recording the starting address of the data block in the mapping area.

[0095] The next data write address is used as the starting address, and the corresponding data block is written in the data area based on the starting address.

[0096] In one embodiment, the step of verifying the written data block according to the data storage information, and determining that the data writing is successful when the data verification result of the data block is passed, specifically includes: after the data block is written, generating a one-bit check byte as the last data byte of the data block based on a preset verification rule; wherein, the preset verification rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block; obtaining the starting address and data length of the data block, and generating a check code based on the preset verification rule; when the data byte matches the check code, determining that the data block is written successfully.

[0097] In one embodiment, the backup index area is used for backup storage of the index area, and further includes:

[0098] The data storage space of the index area is monitored in real time. When the data storage space of the index area is full, the data status record information of the index area is copied to the backup index area and the storage content of the index area is erased. The data status record information copied from the backup index area is read and the record information with the data status information marked as read is cleared. The cleared data status record information is then rewritten into the index area.

[0099] In one embodiment, the embedded data storage device further includes: when receiving a data reading instruction uploaded by a user, updating the data status information of the index area and the mapping area to "read", and obtaining the starting address of the target data block of the reading instruction recorded in the mapping area; and offsetting the data length control pointer of the target data block at the starting address to realize the reading of the target data block.

[0100] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0101] This invention provides an embedded data storage device that, upon initial power-on, divides the storage space into functional areas such as a data area, a mapping area, an index area, and a backup index area. The data area can dynamically allocate space based on the actual data volume, no longer limited by fixed partitions. The mapping area records the data storage information of each data block, accurately recording its storage location regardless of changes in data block length, achieving dynamic storage of data length. The concept of an index area partitioning is introduced; upon power-on, data status records can be directly retrieved from the index area, quickly determining the data write location of the previous write instruction and the address of the next write instruction. The index area acts as a fast index for data storage locations, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving system startup speed. Furthermore, the index area and mapping area work together; the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data write instruction is received, data can be written to the appropriate location based on the data status information, avoiding over-reading and writing in certain areas, achieving a balanced distribution of read and write operations, and extending the lifespan of the storage device. During the data writing process, the data blocks being written are verified based on the data storage information recorded in the mapping area. Only when the data block passes the verification is the data write considered successful. This verification mechanism can promptly detect errors that may occur during data transmission or storage, ensuring the accuracy and integrity of the data.

[0102] The above are merely preferred embodiments of the present invention. It should be noted that those skilled in the art can make several improvements and substitutions without departing from the technical principles of the present invention, and these improvements and substitutions should also be considered within the scope of protection of the present invention.

Claims

1. An embedded data storage method applied to flash memory, characterized in that, include: When the memory is powered on for the first time, the memory space is divided into several functional areas located in different sectors; wherein, the types of functional areas include data area, mapping area, index area and backup index area; Whenever the memory is powered on, the data status record information of the index area is acquired, and the data write position of the previous data write instruction and the next data write address are obtained based on the data status record information. The index area is used to record the data status information in the mapping area, and the mapping area is used to record the data storage information of each data block in the data area. The data storage information includes the data status information. Specifically, acquiring the data status record information of the index area whenever the memory is powered on includes: when the memory is powered on, initializing the memory interface and judging the data storage status of the index area; if the index area is not empty and the data status record information does not conform to the preset data storage rules, erasing the current storage content of the index area, copying the storage content of the backup index area to the index area, and updating the index area; reading the data status information recorded in the index area to obtain the data status record information. When a user uploads a data write instruction, the system updates the data status information of the indexed area and the mapped area, and synchronously updates the data status information of the indexed area to the backup indexed area. Based on the next data write address, the system writes the corresponding data block to the data area. The system verifies the written data block based on the data storage information. When the data block verification result is passed, the data write is deemed successful. The backup indexed area is used for backup storage of the indexed area.

2. The embedded data storage method as described in claim 1, characterized in that, The mapping area is used to record the data storage information of each data block in the data area, specifically: The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but not read, and read.

3. The embedded data storage method as described in claim 1, characterized in that, When a user-uploaded data write instruction is received, the data status information of the indexed area and the mapped area is updated, and the corresponding data block is written to the data area according to the next data write address. Specifically, this includes: Based on the data write instruction, the data status information of the index area and the mapping area is updated to "written but not read", and the starting address of the data block is recorded in the mapping area; The next data write address is used as the starting address, and the corresponding data block is written in the data area based on the starting address.

4. The embedded data storage method as described in claim 2, characterized in that, The step of verifying the written data block based on the data storage information; when the data verification result of the data block is passed, it is determined that the data writing is successful, specifically including: After the data block is written, a check byte is generated based on a preset check rule as the last data byte of the data block; wherein, the preset check rule is to add each byte of the data block one by one to obtain a sum byte as the check code of the data block; Obtain the starting address and data length of the data block, and generate a checksum based on the preset checksum rules; When the data byte matches the checksum, the data block is determined to have been successfully written.

5. The embedded data storage method as described in claim 1, characterized in that, The backup index area is used for backup storage of the index area, and further includes: The data storage space of the index area is monitored in real time. When the data storage space of the index area is full, the data status record information of the index area is copied to the backup index area and the storage content of the index area is erased. Read the data status record information copied from the backup index area and clear the records whose data status information is marked as read, then rewrite the cleared data status record information into the index area.

6. The embedded data storage method as described in claim 1, characterized in that, The embedded data storage method further includes: When a user uploads a data read instruction, the data status information of the index area and the mapping area is updated to "read" and the starting address of the target data block of the read instruction recorded in the mapping area is obtained. The data length control pointer of the target data block is offset from the starting address to read the target data block.

7. An embedded data storage device applied to flash memory, characterized in that, include: Functional partitioning module, data recording module, and data writing module; The functional partitioning module is used to divide the storage space of the memory into several functional areas located in different sectors when the memory is first powered on; wherein, the types of the functional areas include data area, mapping area, index area and backup index area; The data recording module is used to acquire the data status recording information of the index area whenever the memory is powered on, and to acquire the data write position of the previous data write instruction and the next data write address based on the data status recording information. The index area is used to record the data status information in the mapping area, and the mapping area is used to record the data storage information of each data block in the data area. The data storage information includes the data status information. Acquiring the data status recording information of the index area whenever the memory is powered on specifically includes: when the memory is powered on, initializing the memory interface and judging the data storage status of the index area; if the index area is not empty and the data status recording information does not conform to the preset data storage rules, erasing the current storage content of the index area, copying the storage content of the backup index area to the index area, and updating the index area; reading the data status information recorded in the index area to obtain the data status recording information. The data writing module is used to update the data status information of the indexed area and the mapped area when it receives a data writing instruction uploaded by the user, and synchronously update the data status update information of the indexed area to the backup indexed area. It writes the corresponding data block in the data area according to the next data writing address; verifies the written data block according to the data storage information; and determines that the data writing is successful when the data verification result of the data block is passed. The backup indexed area is used to back up and store the indexed area.

8. A terminal device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the embedded data storage method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device on which the computer-readable storage medium resides to perform the embedded data storage method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Train automatic control system data read-write method and device

    CN110941394A

  • Data reading / writing method and system, medium, and device

    WO2023179243A1

Cited By

  • High-reliability embedded storage structure, forming method thereof, electronic equipment and storage medium

    CN122240011A