Data storage method, device and equipment and readable storage medium

By backing up and restoring data in the nonvolatile memory of the embedded system, the problems of data loss and high resource consumption are solved, and efficient and reliable data storage in the embedded system is achieved.

CN119621419APending Publication Date: 2025-03-14智行盒子(河南)科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411432484.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

In embedded systems, nonvolatile memory has problems such as data loss and high resource consumption when programming, especially when the microcontroller unit is powered down or reset, data in memory will be lost, resulting in the loss of original data in nonvolatile memory.

Method used

When writing the data to be stored into the data area of ​​the memory, it is determined whether the data area is writable. If it is not writable, the original data in the data area is backed up to the backup area, the data in the data area is erased, and the backup data is restored to the data area to write the data to be stored.

Benefits of technology

While ensuring that the original data is not lost, the resource consumption in the stored data process is reduced and the efficiency and reliability of data storage are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621419A_ABST
    Figure CN119621419A_ABST
Patent Text Reader

Abstract

The invention provides a data storage method, device and equipment and a readable storage medium, and the method comprises the steps: when to-be-stored data is written into a data area of a memory, determining whether the data area is writable, and the memory comprises the data area and a backup area; when it is determined that the data area is not writable, backing up original data in the data area to a backup area to obtain backup data; and erasing the data in the data area, recovering the backup data to the data area, and writing the to-be-stored data into the data area. By means of the method, the effect of reducing resource consumption in the data storage process can be achieved under the condition that it is guaranteed that original data are not lost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data storage, and in particular, to a method, apparatus, device and readable storage medium for storing data. Background Art

[0002] In embedded systems, microcontrollers are usually used as carriers for software operation and data storage. The microcontroller contains non-volatile memory for storing software code and data. When programming non-volatile memory, data bits can only be written from 1 to 0, but not 0 to 1. Therefore, before programming the non-volatile memory, the corresponding sectors / blocks must be erased. However, the service life of non-volatile memory is usually limited. In current applications, in order to realize the writing of non-fixed length data in non-volatile memory, the original data of non-volatile memory is usually read and stored in the temporary memory before erasing the sector.

[0003] However, the memory is a volatile memory. When the microcontroller loses power or is reset, the data in the memory will be lost, which will cause the original data in the non-volatile memory to be lost. The microcontroller needs to temporarily store at least one block / sector of data, which will consume the memory resources of the microcontroller. The number of times the non-volatile memory is erased increases, reducing the service life of the non-volatile memory.

[0004] Therefore, how to reduce resource consumption in the process of storing data while ensuring that the original data is not lost is a technical problem that needs to be solved. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a method for storing data. Through the technical solution of the embodiments of the present application, it is possible to reduce the resource consumption in the process of storing data while ensuring that the original data is not lost.

[0006] In a first aspect, an embodiment of the present application provides a method for storing data, comprising, when writing data to be stored into a data area of ​​a memory, determining whether the data area is writable, wherein the memory comprises: a data area and a backup area; when it is determined that the data area is not writable, backing up the original data in the data area to the backup area to obtain backup data; erasing the data in the data area, restoring the backup data to the data area, and writing the data to be stored into the data area.

[0007] In the above embodiment of the present application, when it is determined that the data area cannot be written, the original data can be backed up first to prevent the loss of the original data in the data area, and then when writing data in the data area, the original data in the data area can be erased and the backup data can be restored to the data area. This can achieve the effect of reducing resource consumption in the process of storing data while ensuring that the original data is not lost.

[0008] In some embodiments, after determining whether the data area is writable, the method further includes: when it is determined that the data area is writable, writing the data to be stored into the data area.

[0009] In the above embodiments of the present application, when it is determined that the data area is writable, the data can be directly stored in the data area, thereby achieving a fast storage effect.

[0010] In some embodiments, determining whether the data area is writable includes: performing a bitwise AND operation on the original data and the data to be stored to obtain an output result; determining whether the output result and the data to be stored are consistent; when it is determined that the output result and the data to be stored are consistent, determining that the data area is writable; when it is determined that the output result and the data to be stored are inconsistent, determining that the data area is not writable.

[0011] In the above embodiment of the present application, by comparing the output result with the stored data after a bitwise AND operation, it can be determined whether the data area is writable.

[0012] In some embodiments, erasing data in the data area, restoring backup data to the data area, and writing data to be stored into the data area include: erasing data in the data area, restoring backup data to the data area; determining whether the data to be stored is written into the data area; and erasing data in the backup area when determining that the data to be stored is written into the data area.

[0013] In the above-mentioned embodiment of the present application, when writing data in the data area, the backup data can be restored to the data area and the data in the backup area can be erased, thereby ensuring that the original data in the data area is not lost.

[0014] In some embodiments, erasing data in the data area and restoring the backup data to the data area includes: calculating a redundant check value of the backup data in the backup area; determining whether the redundant check value is consistent with a ring redundant check value stored at the end of the backup data; when it is determined that the ring redundant check value is consistent with the ring redundant check value stored at the end of the backup data, erasing the data in the data area and restoring the backup data to the data area.

[0015] In the above embodiment of the present application, when there are backup data and corresponding ring redundancy check values ​​in the backup area, the ring redundancy check value of the current backup data can be compared with the ring redundancy check value stored at the end of the backup data. If the two values ​​are the same, the data in the data area can be quickly restored.

[0016] In some embodiments, after determining whether the redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data, it also includes: when it is determined that the ring redundancy check value is inconsistent with the ring redundancy check value stored at the end of the backup data, erasing the backup data in the backup area.

[0017] In the above embodiment of the present application, when it is determined that the ring redundancy check value is inconsistent with the ring redundancy check value stored at the end of the backup data, the backup data in the backup area can be erased to ensure that the backup area is in an unprogrammed state.

[0018] In some embodiments, data in the data area is erased, and backup data is restored to the data area and data to be stored is written to the data area, including: when the system where the data area is located loses power abnormally or the system is reset and restarted, the backup data is restored to the data area; the data to be stored is written to the data area, and it is determined whether the data to be stored is successfully written to the data area; when it is determined that the data to be stored is successfully written to the data area, the backup data in the backup area is erased.

[0019] In the above embodiment of the present application, when an abnormality occurs in the data in the system data area, the backup data can be quickly restored and the backup data can be erased when writing the data in the data area to ensure that the original data in the data area will not be lost.

[0020] In a second aspect, an embodiment of the present application provides a device for storing data, including:

[0021] A determination module, used to determine whether the data area is writable when writing the data to be stored into the data area of ​​the memory, wherein the memory includes: a data area and a backup area;

[0022] A backup module, used for backing up the original data in the data area to the backup area to obtain backup data when it is determined that the data area is not writable;

[0023] The storage module is used to erase the data in the data area, restore the backup data to the data area, and write the data to be stored into the data area.

[0024] Optionally, the device further comprises:

[0025] The writing module is used for, after the determining module determines whether the data area is writable, to write the data to be stored into the data area when it is determined that the data area is writable.

[0026] Optionally, determine whether the module is specifically used for:

[0027] Perform a bitwise AND operation on the original data and the data to be stored to obtain the output result;

[0028] Determine whether the output result is consistent with the data to be stored;

[0029] When it is determined that the output result is consistent with the data to be stored, it is determined that the data area is writable;

[0030] When it is determined that the output result is inconsistent with the data to be stored, it is determined that the data area is not writable.

[0031] Optionally, the storage module is specifically used for:

[0032] Erase the data in the data area and restore the backup data to the data area;

[0033] Determine whether the data to be stored is written into the data area;

[0034] When it is determined that the data to be stored is written into the data area, the data in the backup area is erased.

[0035] Optionally, the storage module is specifically used for:

[0036] Calculate the redundancy check value of the backup data in the backup area;

[0037] Determine whether the redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data;

[0038] When it is determined that the ring redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data, the data in the data area is erased, and the backup data is restored to the data area.

[0039] Optionally, the device further comprises:

[0040] The erasing module is used for erasing the backup data in the backup area after the storage module determines whether the redundant check value and the ring redundant check value stored at the end of the backup data are consistent. When it is determined that the ring redundant check value and the ring redundant check value stored at the end of the backup data are inconsistent, the storage module erases the backup data in the backup area.

[0041] Optionally, the storage module is specifically used for:

[0042] When the system where the data area is located loses power abnormally or is reset and restarted, the backup data will be restored to the data area;

[0043] Writing the data to be stored into the data area, and determining whether the data to be stored is successfully written into the data area;

[0044] When it is determined that the data to be stored is successfully written into the data area, the backup data in the backup area is erased.

[0045] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method provided in the first aspect are performed.

[0046] In a fourth aspect, an embodiment of the present application provides a readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the method provided in the first aspect are performed.

[0047] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0049] Figure 1 A flowchart of a method for storing data provided in an embodiment of the present application;

[0050] Figure 2 A flowchart of a method for erasing data in a data area provided in an embodiment of the present application;

[0051] Figure 3 A flowchart of an implementation method for storing data provided in an embodiment of the present application;

[0052] Figure 4 A schematic block diagram of a data storage device provided in an embodiment of the present application

[0053] Figure 5 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0055] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0056] First, some terms involved in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.

[0057] MCU (Microcontroller Unit) is a microcontroller unit, also known as a single-chip microcomputer. It is a computer system that integrates a central processing unit (CPU), memory (ROM and RAM), input and output interface (I / O), serial port, counter, etc. on a single chip.

[0058] Nor Flash (also known as NOR flash memory) is a non-volatile memory commonly used in embedded systems and storage devices. NOR Flash is a type of flash memory that can be used to store program code, firmware, operating systems, and other data.

[0059] RAM (Random Access Memory) is an internal memory that directly exchanges data with the CPU, also known as main memory or memory.

[0060] The bitwise AND operation is a basic bitwise operation used to compare the binary bits of two numbers. The result bit is 1 only when the corresponding bits of the two numbers are both 1, otherwise it is 0. This operation is usually used to process binary data, and the two numbers involved in the operation appear in the form of complement.

[0061] Erasing a data area means completely erasing the data in a specific sector of the memory to restore it to its initial unprogrammed state. This operation is very important in embedded systems because it ensures that the old data is completely cleared before writing new data, thus avoiding data conflicts and errors.

[0062] The present application is applied to the scenario of data storage. The specific scenario is that when it is determined that the data area is not writable, the original data in the data area is backed up, and after erasing the data in the data area, the data to be stored in the data area is written, and the backup data in the backup area is restored to the data area.

[0063] In embedded systems, microcontrollers are usually used as carriers for software operation and data storage. The microcontroller contains non-volatile memory for storing software code and data. When programming non-volatile memory, data bits can only be written from 1 to 0, but not from 0 to 1. Therefore, the corresponding sectors / blocks must be erased before programming the non-volatile memory. In current applications, in order to realize the writing of non-fixed length data in non-volatile memory, the original data of non-volatile memory is usually read and temporarily stored in memory before erasing the sector. However, the memory is a volatile memory. When the microcontroller is powered off or reset, the data in the memory will be lost, which will cause the original data in the non-volatile memory to be lost; the microcontroller needs to temporarily store at least one block / sector of data, which will consume the memory resources of the microcontroller; the number of times the non-volatile memory is erased increases, and the service life of the non-volatile memory is reduced.

[0064] To this end, the present application determines whether the data area is writable when writing the data to be stored into the data area of ​​the memory, wherein the memory includes: a data area and a backup area; when it is determined that the data area is not writable, backing up the original data in the data area to the backup area to obtain backup data; erasing the data in the data area, and restoring the backup data to the data area and writing the data to be stored into the data area. In the above embodiment of the present application, when it is determined that the data area is not writable, the original data can be backed up first to prevent the loss of the original data in the data area, and then when writing the data in the data area, the original data in the data area can be erased and the backup data can be restored to the data area. The effect of reducing resource consumption in the process of storing data can be achieved while ensuring that the original data is not lost.

[0065] In the embodiment of the present application, the execution subject may be a data storage device in a data storage system. In actual applications, the data storage device may be an electronic device such as a terminal device and a server, which is not limited here.

[0066] Combine the following Figure 1 The method for storing data in an embodiment of the present application is described in detail.

[0067] Please see Figure 1 , Figure 1 A flowchart of a method for storing data provided in an embodiment of the present application is shown in FIG. Figure 1 The methods shown for storing data include:

[0068] Step 110: When writing the data to be stored into the data area of ​​the memory, determine whether the data area is writable.

[0069] Among them, the memory includes: a data area and a backup area. The memory can be a Nor Flash memory, which is an internal component of the MCU. The data area referred to in this application is the data area to be written in the entire data area. Since the entire data area is relatively large, for example, 8KByte, each data storage only needs to write a small amount of data to a fixed location, for example, write 10Byte of data to the position with a starting address of 100 (that is, the data area to be written).

[0070] In some embodiments of the present application, determining whether a data area is writable includes: performing a bitwise AND operation on the original data and the data to be stored to obtain an output result; determining whether the output result and the data to be stored are consistent; when it is determined that the output result and the data to be stored are consistent, determining that the data area is writable; when it is determined that the output result and the data to be stored are inconsistent, determining that the data area is not writable.

[0071] In the above process, the present application can determine whether the data area is writable by comparing the output result with the stored data after a bitwise AND operation.

[0072] The original data refers to all the data stored before the new data is written into the data area. The data to be stored may refer to various data that need to be stored in the flash memory, including but not limited to downloaded applications, photographs, recorded videos, and various files used in daily life.

[0073] In some embodiments of the present application, after determining whether the data area is writable, Figure 1 The method shown also includes: when it is determined that the data area is writable, writing the data to be stored into the data area.

[0074] In the above process, the present application can directly store data in the data area when it is determined that the data area is writable, thereby achieving a fast storage effect.

[0075] Step 120: When it is determined that the data area is not writable, the original data in the data area is backed up to the backup area to obtain backup data.

[0076] The backup data includes all the original data.

[0077] In some embodiments, erasing data in the data area and restoring the backup data to the data area includes: calculating a redundant check value of the backup data in the backup area; determining whether the redundant check value is consistent with a ring redundant check value stored at the end of the backup data; when it is determined that the ring redundant check value is consistent with the ring redundant check value stored at the end of the backup data, erasing the data in the data area and restoring the backup data to the data area.

[0078] In the above embodiment of the present application, when there are backup data and corresponding ring redundancy check values ​​in the backup area, the ring redundancy check value of the current backup data can be compared with the ring redundancy check value stored at the end of the backup data. If the two values ​​are the same, the data in the data area can be quickly restored.

[0079] The backup data is the original data in the backup data area before writing the data in the data area.

[0080] For example, use the CRC32 algorithm to calculate the CRC value of the backup area data and obtain result A; compare result A with the CRC value B at the end of the backup area. If A and B are consistent, the backup area data is valid, the data area is erased, and the backup area data is written to the data area; otherwise, the backup area data is invalid and the backup area data is directly erased.

[0081] In some embodiments, after determining whether the redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data, it also includes: when it is determined that the ring redundancy check value is inconsistent with the ring redundancy check value stored at the end of the backup data, erasing the backup data in the backup area.

[0082] In the above embodiment of the present application, when it is determined that the ring redundancy check value is inconsistent with the ring redundancy check value stored at the end of the backup data, the backup data in the backup area can be erased to ensure that the backup area is in an unprogrammed state.

[0083] Step 130: Erasing the data in the data area, restoring the backup data to the data area, and writing the data to be stored into the data area.

[0084] In some embodiments of the present application, erasing data in a data area, restoring backup data to the data area, and writing data to be stored to the data area include: erasing data in a data area, and restoring backup data to the data area; determining whether the data to be stored is written to the data area; and when determining that the data to be stored is written to the data area, erasing data in the backup area.

[0085] In the above process, the present application can restore the backup data to the data area and erase the data in the backup area when writing the data in the data area, thereby ensuring that the original data in the data area is not lost.

[0086] Optionally, data in the data area can be erased by Figure 2 See the method shown in Figure 2 , Figure 2 A flowchart of a method for erasing data in a data area provided by the present application, such as Figure 2 The method for erasing data in the data area shown includes:

[0087] Step 201: Whether the backup area is deleted.

[0088] Specifically: if there is no data in the backup area, go to step 203; otherwise, go to step 202.

[0089] Step 202: Erase the backup area.

[0090] Specific: Erase all backup data in the backup area.

[0091] Step 203: All original data in the data area are written into the backup area.

[0092] Specifically: back up the original data in the data area.

[0093] Step 204: Check whether the original data in the data area is successfully written into the backup area.

[0094] Specifically: if the original data in the data area is successfully written into the backup area, the process goes to step 205 ; otherwise, the process goes to step 211 .

[0095] Step 205: Calculate the CRC value of the backup area data.

[0096] Specifically: calculate the ring redundancy check value of the backup data in the backup area.

[0097] Step 206: Write the CRC value to the end of the backup area.

[0098] Specifically: write the ring redundancy check value to the end of the backup area.

[0099] Step 207: Check whether the CRC value is written into the backup area successfully.

[0100] Specifically: if the CRC value is written into the backup area successfully, the process proceeds to step 208 ; otherwise, the process proceeds to step 211 .

[0101] Step 208: Erase the data area.

[0102] Specifically: erase the original data in the data area.

[0103] Step 209: Restore the original data in the data area.

[0104] Specifically: restore the backup data in the backup area to the data area.

[0105] Step 210: The data area is erased successfully.

[0106] Step 211: Data area erasure fails.

[0107] also, Figure 2 The specific methods and steps shown can be found in Figure 1 The method shown will not be described in detail here.

[0108] In some embodiments of the present application, data in a data area is erased, and backup data is restored to the data area and data to be stored is written to the data area, including: when a system where the data area is located loses power abnormally or the system is reset and restarted, the backup data is restored to the data area; the data to be stored is written to the data area, and it is determined whether the data to be stored is successfully written to the data area; when it is determined that the data to be stored is successfully written to the data area, the backup data in the backup area is erased.

[0109] In the above process, when the data in the system data area is abnormal, the backup data can be quickly restored and the backup data can be erased when writing the data in the data area to ensure that the original data in the data area will not be lost.

[0110] The data in the data area may be abnormal due to abnormal write data, loss of stored data, or unavailable data.

[0111] Optionally, when it is determined that writing the data to be stored into the data area fails, the data in the data area is erased, and the backup data is restored to the data area.

[0112] In the above Figure 1 In the process shown, the present application determines whether the data area is writable when writing the data to be stored into the data area of ​​the memory, wherein the memory includes: a data area and a backup area; when it is determined that the data area is not writable, backing up the original data in the data area to the backup area to obtain backup data; erasing the data in the data area, and restoring the backup data to the data area and writing the data to be stored into the data area. In the above embodiment of the present application, when it is determined that the data area is not writable, the original data can be backed up first to prevent the loss of the original data in the data area, and then when writing the data in the data area, the original data in the data area can be erased and the backup data can be restored to the data area. The effect of reducing resource consumption in the process of storing data can be achieved while ensuring that the original data is not lost.

[0113] Combine the following Figure 3 The implementation method of storing data in the embodiment of the present application is described in detail.

[0114] Please see Figure 3 , Figure 3 A flowchart of an implementation method for storing data provided in an embodiment of the present application is shown in FIG. Figure 3 The implementation method of storing data shown includes:

[0115] Step 310: Check whether the data to be stored is consistent with the original data.

[0116] Specifically: if the data to be stored is consistent with the original data, then go to step 380 ; otherwise, then go to step 320 .

[0117] Step 320: Whether the data area is writable.

[0118] Specifically: if the data area is writable, go to step 350 ; otherwise, go to step 330 .

[0119] Step 330: Erase the data in the data area.

[0120] Specifically: erase the data in the data area to be written in the data area, and restore the backup data to other data areas outside the data area to be written.

[0121] Step 340: Check whether the data in the data area to be written is erased successfully.

[0122] Specifically: if the data in the data area to be written is erased successfully, the process proceeds to step 350 ; otherwise, the process proceeds to step 390 .

[0123] Step 350: Write the data to be stored into the data area to be written.

[0124] Specifically: the data to be stored is stored in the data area to be written.

[0125] Step 360: Whether the data to be stored is successfully written into the data area to be written.

[0126] Specifically: if the data to be stored is written into the data area to be written successfully, the process goes to step 370 ; otherwise, the process goes to step 390 .

[0127] Step 370: Erase the backup area.

[0128] Specifically: erase all data stored in the backup area.

[0129] Step 380: Data writing is successful.

[0130] Step 390: Failed to write data.

[0131] also, Figure 3 The specific methods and steps shown can be found in Figure 1 The method shown will not be described in detail here.

[0132] Previous article Figure 1 Describes the method of storing data, the following is combined with Figure 4-Figure 5 Describes a device that stores data.

[0133] Please refer to Figure 4 , is a schematic block diagram of a data storage device 400 provided in an embodiment of the present application, and the device 400 may be a module, program segment or code on an electronic device. Figure 1 The method embodiment corresponds to and can be executed Figure 1 The various steps involved in the method embodiment and the specific functions of the device 400 can be found in the description below. To avoid repetition, the detailed description is appropriately omitted here.

[0134] Optionally, the device 400 includes:

[0135] The determination module 410 is used to determine whether the data area is writable when writing the data to be stored into the data area of ​​the memory, wherein the memory includes: a data area and a backup area;

[0136] The backup module 420 is used to back up the original data in the data area to the backup area to obtain backup data when it is determined that the data area is not writable;

[0137] The storage module 430 is used to erase the data in the data area, restore the backup data to the data area, and write the data to be stored into the data area.

[0138] Optionally, the device further comprises:

[0139] The writing module is used for, after the determining module determines whether the data area is writable, to write the data to be stored into the data area when it is determined that the data area is writable.

[0140] Optionally, determine whether the module is specifically used for:

[0141] Performing a bitwise AND operation on the original data and the data to be stored to obtain an output result; determining whether the output result is consistent with the data to be stored; when it is determined that the output result is consistent with the data to be stored, determining that the data area is writable; when it is determined that the output result is inconsistent with the data to be stored, determining that the data area is not writable.

[0142] Optionally, the storage module is specifically used for:

[0143] Erasing the data in the data area and restoring the backup data to the data area; determining whether the data to be stored is written into the data area; and erasing the data in the backup area when determining that the data to be stored is written into the data area.

[0144] Optionally, the storage module is specifically used for:

[0145] Calculate the redundancy check value of the backup data in the backup area;

[0146] Determine whether the redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data;

[0147] When it is determined that the ring redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data, the data in the data area is erased, and the backup data is restored to the data area.

[0148] Optionally, the device further comprises:

[0149] The erasing module is used for erasing the backup data in the backup area after the storage module determines whether the redundant check value and the ring redundant check value stored at the end of the backup data are consistent. When it is determined that the ring redundant check value and the ring redundant check value stored at the end of the backup data are inconsistent, the storage module erases the backup data in the backup area.

[0150] Optionally, the storage module is specifically used for:

[0151] When the system where the data area is located loses power abnormally or is reset and restarted, the backup data is restored to the data area; the data to be stored is written into the data area, and it is determined whether the data to be stored is written into the data area successfully; when it is determined that the data to be stored is written into the data area successfully, the backup data in the backup area is erased.

[0152] Please refer to Figure 5 5 is a schematic block diagram of a data storage device provided in an embodiment of the present application. The device may include a memory 510 and a processor 520. Optionally, the device may also include: a communication interface 530 and a communication bus 540. The device is similar to the above Figure 1 The method embodiment corresponds to and can be executed Figure 1 The various steps involved in the method embodiment and the specific functions of the device can be found in the description below.

[0153] Specifically, the memory 510 is used to store computer-readable instructions.

[0154] Processor 520 is used to process the readable instructions stored in the memory and can execute Figure 1 The steps in the method.

[0155] The communication interface 530 is used for signaling or data communication with other node devices, for example, for communication with a server or a terminal, or for communication with other device nodes, but the embodiments of the present application are not limited thereto.

[0156] The communication bus 540 is used to realize direct connection and communication among the above components.

[0157] The communication interface 530 of the device in the embodiment of the present application is used to communicate signals or data with other node devices. The memory 510 can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The memory 510 can also be at least one storage device located away from the aforementioned processor. The memory 510 stores computer-readable instructions. When the computer-readable instructions are executed by the processor 520, the electronic device executes the aforementioned Figure 1The method process shown. The processor 520 can be used on the device 400 and used to perform the functions in the present application. Exemplarily, the above-mentioned processor 520 can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and the embodiments of the present application are not limited thereto.

[0158] The embodiment of the present application also provides a readable storage medium, when the computer program is executed by a processor, Figure 1 The method process in the method embodiment shown is executed by the electronic device.

[0159] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.

[0160] In summary, the embodiments of the present application provide a method, device, equipment and readable storage medium for storing data, the method comprising, when writing data to be stored into a data area of ​​a memory, determining whether the data area is writable, wherein the memory comprises: a data area and a backup area; when determining that the data area is not writable, backing up the original data in the data area to the backup area to obtain backup data; erasing the data in the data area, restoring the backup data to the data area and writing the data to be stored into the data area. The effect of reducing resource consumption in the process of storing data can be achieved while ensuring that the original data is not lost.

[0161] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0162] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0163] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0164] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0165] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0166] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

Claims

1. A method for storing data, characterized in that: include: When writing data to be stored into a data area of ​​a memory, determining whether the data area is writable, wherein the memory comprises: the data area and a backup area; When it is determined that the data area is not writable, backing up the original data in the data area to the backup area to obtain backup data; The data in the data area is erased, and the backup data is restored to the data area and the data to be stored is written into the data area.

2. The method according to claim 1, characterized in that After determining whether the data area is writable, the method further includes: When it is determined that the data area is writable, the data to be stored is written into the data area.

3. The method according to claim 1 or 2, characterized in that: The determining whether the data area is writable comprises: Performing a bitwise AND operation on the original data and the data to be stored to obtain an output result; Determining whether the output result is consistent with the data to be stored; When it is determined that the output result is consistent with the data to be stored, determining that the data area is writable; When it is determined that the output result is inconsistent with the data to be stored, it is determined that the data area is not writable.

4. The method according to claim 1 or 2, characterized in that: The erasing of the data in the data area, restoring the backup data to the data area, and writing the data to be stored into the data area comprises: Erasing the data in the data area and restoring the backup data to the data area; Determining whether the data to be stored is written into the data area; When it is determined that the data to be stored is written into the data area, the data in the backup area is erased.

5. The method according to claim 4, characterized in that The erasing the data in the data area and restoring the backup data to the data area includes: Calculating a redundancy check value of the backup data in the backup area; Determine whether the redundancy check value is consistent with the ring redundancy check value stored at the tail of the backup data; When it is determined that the ring redundancy check value is consistent with the ring redundancy check value stored at the end of the backup data, the data in the data area is erased, and the backup data is restored to the data area.

6. The method according to claim 5, characterized in that After determining whether the redundancy check value is consistent with the ring redundancy check value stored at the tail of the backup data, the method further includes: When it is determined that the ring redundancy check value is inconsistent with the ring redundancy check value stored at the end of the backup data, the backup data in the backup area is erased.

7. The method according to claim 1 or 2, characterized in that: The erasing of the data in the data area, restoring the backup data to the data area, and writing the data to be stored into the data area comprises: When the system where the data area is located loses power abnormally or the system is reset and restarted, the backup data is restored to the data area; Writing the data to be stored into the data area, and determining whether the data to be stored is successfully written into the data area; When it is determined that the data to be stored is successfully written into the data area, the backup data in the backup area is erased.

8. A device for storing data, characterized in that: include: A determination module, used for determining whether the data area is writable when writing the data to be stored into the data area of ​​the memory, wherein the memory comprises: the data area and the backup area; A backup module, used for backing up the original data in the data area to the backup area to obtain backup data when it is determined that the data area is not writable; The storage module is used to erase the data in the data area, restore the backup data to the data area, and write the data to be stored into the data area.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method according to any one of claims 1 to 7 are executed.

10. A computer-readable storage medium, characterized in that: include: A computer program, when the computer program is run on a computer, causes the computer to execute the method according to any one of claims 1 to 7.