CN110096451B - Data storage method and device - Google Patents
Data storage method and device Download PDFInfo
- Publication number
- CN110096451B CN110096451B CN201810084375.9A CN201810084375A CN110096451B CN 110096451 B CN110096451 B CN 110096451B CN 201810084375 A CN201810084375 A CN 201810084375A CN 110096451 B CN110096451 B CN 110096451B
- Authority
- CN
- China
- Prior art keywords
- data
- terminal
- memory
- length
- packet
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0238—Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
- G06F12/0246—Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/06—Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
- G06F12/0646—Configuration or reconfiguration
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/06—Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
- G06F3/0601—Interfaces specially adapted for storage systems
- G06F3/0602—Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
- G06F3/0614—Improving the reliability of storage systems
- G06F3/0616—Improving the reliability of storage systems in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/06—Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
- G06F3/0601—Interfaces specially adapted for storage systems
- G06F3/0628—Interfaces specially adapted for storage systems making use of a particular technique
- G06F3/0629—Configuration or reconfiguration of storage systems
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/06—Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
- G06F3/0601—Interfaces specially adapted for storage systems
- G06F3/0668—Interfaces specially adapted for storage systems adopting a particular infrastructure
- G06F3/0671—In-line storage system
- G06F3/0673—Single storage device
- G06F3/0679—Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Techniques For Improving Reliability Of Storages (AREA)
Abstract
本申请实施例公开了一种数据存储方法及装置,该方法包括:终端接收待存储的有效数据;终端根据预设参数和有效数据配置数据头,数据头用于指示有效数据的属性;终端根据数据头、有效数据和无效数据生成数据包,无效数据用于填充数据包以使数据包的长度与待写入数据页的长度相同,待写入数据页为闪存的备份区域内数据块的数据页;终端将数据包存储至待写入数据页中。本申请实施例可以使每个数据块在擦除一次后存储多个数据包,从而极大的提高了每个数据块的写入次数,进而满足在模拟EEPROM的过程中使用寿命上的要求。
The embodiment of the present application discloses a data storage method and device. The method includes: the terminal receives valid data to be stored; the terminal configures a data header according to preset parameters and valid data, and the data header is used to indicate the attribute of the valid data; The data header, valid data and invalid data generate a data packet, and the invalid data is used to fill the data packet so that the length of the data packet is the same as the length of the data page to be written, and the data page to be written is the data of the data block in the backup area of the flash memory page; the terminal stores the data packet into the data page to be written. The embodiment of the present application enables each data block to store multiple data packets after being erased once, thereby greatly increasing the writing times of each data block, and further meeting the service life requirement in the process of simulating EEPROM.
Description
技术领域technical field
本申请实施例涉及通信技术领域,更具体的说,涉及数据存储方法及装置。The embodiments of the present application relate to the technical field of communications, and more specifically, to a data storage method and device.
背景技术Background technique
EEPROM(Electrically Erasable Programmable Read-Only Memory,电可擦除可编程只读存储器)是一种被广泛应用于小型嵌入式系统中的小容量存储设备,可用于存储简单的配置参数和用户音量设置等数据。EEPROM具有以下三个特性:1.非易失性:掉电时数据不丢失;2.随机存取:可以使用任意偏移地址按字节为单位读数据和写数据;3.寿命长:可以支持百万次级别的写入次数。目前,为了降低终端的成本,业内通常利用终端的闪存和内存来模拟EEPROM,从而省去EEPROM带来的硬件开销。EEPROM (Electrically Erasable Programmable Read-Only Memory, Electrically Erasable Programmable Read-Only Memory) is a small-capacity storage device widely used in small embedded systems, which can be used to store simple configuration parameters and user volume settings, etc. data. EEPROM has the following three characteristics: 1. Non-volatile: data will not be lost when power is off; 2. Random access: you can use any offset address to read and write data in bytes; 3. Long life: you can Supports million-level write times. At present, in order to reduce the cost of the terminal, the industry usually uses the flash memory and memory of the terminal to simulate the EEPROM, thereby saving the hardware overhead brought by the EEPROM.
下面简要介绍相关技术如何利用终端的闪存和内存来模拟EEPROM:在终端存在需要存储到EEPROM中的目标数据时,终端会将目标数据分别存储到内存和闪存中。将目标数据存储到内存的目的是为了模拟EEPROM能够快速的读取数据,将目标数据存储到闪存的目的是为了模拟EERPOM在掉电时数据不丢失。在终端开机初始化的过程中,终端会将闪存内的目标数据复制到内存中,以使终端能够快速的获取内存中的目标数据。The following briefly introduces how related technologies use the flash memory and memory of the terminal to simulate EEPROM: when the terminal has target data that needs to be stored in the EEPROM, the terminal will store the target data in the memory and flash memory respectively. The purpose of storing the target data in memory is to simulate that EEPROM can read data quickly, and the purpose of storing target data in flash memory is to simulate that the data of EERPOM will not be lost when the power is turned off. During the initialization process of the terminal, the terminal will copy the target data in the flash memory to the internal memory, so that the terminal can quickly obtain the target data in the internal memory.
在将目标数据存储到闪存的过程中,上述相关技术会将目标数据存储到闪存内固定的数据块中。通常情况下,闪存内的一个数据块具有10万次的擦除寿命,即一个数据块写入10万次就会报废。然而,EEPROM可以支持百万次级别的写入次数,所以上述模拟EEPROM的相关技术无法满足在使用寿命上的要求。In the process of storing the target data in the flash memory, the above related technologies will store the target data in fixed data blocks in the flash memory. Normally, a data block in the flash memory has an erasure life of 100,000 times, that is, a data block will be scrapped after being written 100,000 times. However, the EEPROM can support millions of times of write times, so the above-mentioned technologies related to simulating the EEPROM cannot meet the requirement on service life.
发明内容Contents of the invention
本申请实施例提供一种数据存储方法及装置,以便于在模拟EEPROM的过程中满足使用寿命上的要求。The embodiment of the present application provides a data storage method and device, so as to meet the service life requirement in the process of simulating the EEPROM.
本申请实施例是这样实现的:The embodiment of this application is implemented in this way:
第一方面,本申请实施例提供了一种数据存储方法,该方法包括:In the first aspect, the embodiment of the present application provides a data storage method, the method comprising:
终端接收待存储的有效数据;The terminal receives valid data to be stored;
终端根据预设参数配置和有效数据数据头,数据头用于指示有效数据的属性;The terminal is configured according to the preset parameters and the valid data header, which is used to indicate the attributes of the valid data;
终端根据数据头、有效数据和无效数据生成数据包,无效数据用于填充数据包以使数据包的长度与待写入数据页的长度相同,待写入数据页为闪存的备份区域内数据块的数据页;The terminal generates a data packet according to the data header, valid data and invalid data. The invalid data is used to fill the data packet so that the length of the data packet is the same as the length of the data page to be written. The data page to be written is a data block in the backup area of the flash memory data page;
终端将数据包存储至待写入数据页中。The terminal stores the data packet into the data page to be written.
其中,终端在根据数据头、有效数据和无效数据生成数据包的过程中,需要保证数据包的长度与待写入数据页的长度相同,从而使得数据包与数据页之间具有对应关系。在闪存的备份子区域的数据块内存入多个数据包以后,终端可以基于数据包与数据页之间的对应关系快速的读取出闪存的备份子区域的数据块内的每个数据包。因此,本申请实施例提供的方案可以使每个数据块在擦除一次后存储多个数据包,从而极大的提高了每个数据块的写入次数,进而满足在模拟EEPROM的过程中使用寿命上的要求。Wherein, in the process of generating the data packet according to the data header, valid data and invalid data, the terminal needs to ensure that the length of the data packet is the same as the length of the data page to be written, so that there is a corresponding relationship between the data packet and the data page. After storing multiple data packets in the data block of the backup sub-area of the flash memory, the terminal can quickly read each data packet in the data block of the backup sub-area of the flash memory based on the correspondence between data packets and data pages. Therefore, the solution provided by the embodiment of the present application can enable each data block to store multiple data packets after being erased once, thereby greatly increasing the number of write times of each data block, and then satisfying the requirements for use in the process of simulating EEPROM. life expectancy requirements.
在一种可能的实现方式中,终端根据数据头、有效数据和无效数据生成数据包,包括:In a possible implementation manner, the terminal generates a data packet according to the data header, valid data and invalid data, including:
终端根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;The terminal calculates the length to be filled according to the length of the data header, the length of the valid data and the length of the data page to be written;
终端按照待填充长度生成无效数据;The terminal generates invalid data according to the length to be filled;
终端将数据头、有效数据和无效数据组合成数据包。The terminal combines the data header, valid data and invalid data into a data packet.
可选的,终端还可以将待填充长度写入数据头中。Optionally, the terminal may also write the length to be filled into the data header.
其中,终端根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度,并且按照待填充长度生成无效数据,从而可以保证将数据头、有效数据和无效数据组合成数据包的长度与待写入数据页的长度相同。Among them, the terminal calculates the length to be filled according to the length of the data header, the length of the valid data and the length of the data page to be written, and generates invalid data according to the length to be filled, so as to ensure that the data header, valid data and invalid data are combined into data The length of the packet is the same as the length of the data page to be written.
在一种可能的实现方式中,终端根据数据头、有效数据和无效数据生成数据包,包括:In a possible implementation manner, the terminal generates a data packet according to the data header, valid data and invalid data, including:
终端获取数据头内的校验标识;The terminal obtains the verification identifier in the data header;
终端按照校验标识对应的校验算法对有效数据进行计算得到校验结果;The terminal calculates the valid data according to the verification algorithm corresponding to the verification identifier to obtain the verification result;
终端将校验结果写入数据头中以得到目标数据头;The terminal writes the verification result into the data header to obtain the target data header;
终端根据目标数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;The terminal calculates the length to be filled according to the length of the target data header, the length of the valid data, and the length of the data page to be written;
终端按照待填充长度生成无效数据;The terminal generates invalid data according to the length to be filled;
终端将目标数据头、有效数据和无效数据组合成数据包。The endpoint combines the destination header, valid data, and invalid data into packets.
其中,终端将校验结果存储在目标数据头中,从而可以随时对有效数据进行校验,以判断有效数据的正确性。Wherein, the terminal stores the verification result in the target data header, so that the valid data can be verified at any time to judge the correctness of the valid data.
在一种可能的实现方式中,终端根据数据头、有效数据和无效数据生成数据包,包括:In a possible implementation manner, the terminal generates a data packet according to the data header, valid data and invalid data, including:
终端获取数据头内的压缩标识;The terminal obtains the compression identifier in the data header;
终端按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;The terminal compresses the valid data according to the compression algorithm corresponding to the compression identifier to obtain the compressed data;
终端根据数据头的长度、压缩数据的长度和待写入数据页的长度计算待填充长度;The terminal calculates the length to be filled according to the length of the data header, the length of the compressed data, and the length of the data page to be written;
终端按照待填充长度生成无效数据;The terminal generates invalid data according to the length to be filled;
终端将数据头、压缩数据和无效数据组合成数据包。The endpoint combines headers, compressed data, and invalid data into packets.
其中,由于压缩数据相对于有效数据占用的存储空间更小,终端将数据头、压缩数据和无效数据组合成数据包,可以节省终端的闪存的存储空间。Wherein, since the storage space occupied by the compressed data is smaller than that of the valid data, the terminal combines the data header, the compressed data and the invalid data into a data packet, which can save the storage space of the flash memory of the terminal.
在一种可能的实现方式中,终端根据数据头、有效数据和无效数据生成数据包,包括:In a possible implementation manner, the terminal generates a data packet according to the data header, valid data and invalid data, including:
终端获取数据头内的加密标识;The terminal obtains the encrypted identifier in the data header;
终端按照加密标识对应的加密算法对有效数据进行加密得到加密数据;The terminal encrypts the valid data according to the encryption algorithm corresponding to the encryption identifier to obtain the encrypted data;
终端根据数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;The terminal calculates the length to be filled according to the length of the data header, the length of the encrypted data, and the length of the data page to be written;
终端按照待填充长度生成无效数据;The terminal generates invalid data according to the length to be filled;
终端将数据头、加密数据和无效数据组合成数据包。The endpoint combines the data header, encrypted data, and invalid data into a data packet.
其中,由于加密数据相对于有效数据具有更高的安全性,终端将数据头、加密数据和无效数据组合成数据包,可以提高有效数据的安全性。Wherein, since the encrypted data has higher security than the valid data, the terminal combines the data header, the encrypted data and the invalid data into a data packet, which can improve the security of the valid data.
在一种可能的实现方式中,终端根据数据头、有效数据和无效数据生成数据包,包括:In a possible implementation manner, the terminal generates a data packet according to the data header, valid data and invalid data, including:
终端获取数据头内的压缩标识、加密标识和校验标识;The terminal acquires the compression identifier, encryption identifier and verification identifier in the data header;
终端按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;The terminal compresses the valid data according to the compression algorithm corresponding to the compression identifier to obtain the compressed data;
终端按照加密标识对应的加密算法对压缩数据进行加密得到加密数据;The terminal encrypts the compressed data according to the encryption algorithm corresponding to the encryption identifier to obtain the encrypted data;
终端按照校验标识对应的校验算法对加密数据进行计算得到校验结果;The terminal calculates the encrypted data according to the verification algorithm corresponding to the verification identifier to obtain the verification result;
终端将校验结果写入数据头中以得到目标数据头;The terminal writes the verification result into the data header to obtain the target data header;
终端根据目标数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;The terminal calculates the length to be filled according to the length of the target data header, the length of the encrypted data, and the length of the data page to be written;
终端按照待填充长度生成无效数据;The terminal generates invalid data according to the length to be filled;
终端将目标数据头、加密数据和无效数据组合成数据包。The terminal combines the target data header, encrypted data, and invalid data into a data packet.
其中,终端对有效数据进行了压缩以得到压缩数据,然后又对压缩数据进行加密以得到加密数据,不仅可以节省终端的闪存的存储空间,而且还能提高有效数据的安全性。另外,终端基于校验标识对应的校验算法对加密数据进行计算得到校验结果,并将校验结果存储在目标数据头中,从而可以随时对有效数据进行校验,以判断有效数据的正确性。Wherein, the terminal compresses the valid data to obtain the compressed data, and then encrypts the compressed data to obtain the encrypted data, which not only saves the storage space of the flash memory of the terminal, but also improves the security of the valid data. In addition, the terminal calculates the encrypted data based on the verification algorithm corresponding to the verification identifier to obtain the verification result, and stores the verification result in the target data header, so that the valid data can be verified at any time to determine the validity of the valid data. sex.
在一种可能的实现方式中,无效数据的长度为待写入数据页的长度与初始数据长度之差,初始数据长度为数据头的长度与有效数据的长度之和。In a possible implementation manner, the length of the invalid data is the difference between the length of the data page to be written and the length of the initial data, and the length of the initial data is the sum of the length of the data header and the length of the valid data.
在一种可能的实现方式中,终端接收待存储的有效数据以后,方法还包括:In a possible implementation manner, after the terminal receives the valid data to be stored, the method further includes:
终端获取有效数据的偏移地址;The terminal obtains the offset address of the valid data;
终端将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。The terminal stores the valid data in the storage space corresponding to the offset address in the simulated storage area of the memory.
其中,为了保证终端可以快速的读取到有效数据,终端会将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。Wherein, in order to ensure that the terminal can quickly read the valid data, the terminal will store the valid data in the storage space corresponding to the offset address in the simulated storage area of the memory.
在一种可能的实现方式中,终端将数据包存储至待写入数据页中以后,方法还包括:In a possible implementation manner, after the terminal stores the data packet in the data page to be written, the method further includes:
在终端初始化时,终端获取闪存的备份区域中每个数据块的数据页内存储的N个数据包,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,至少两个数据块中的每个数据块均包括至少两个数据页,N大于或等于1;When the terminal is initialized, the terminal obtains N data packets stored in the data page of each data block in the backup area of the flash memory. The backup area of the flash memory includes at least two backup sub-areas, and each backup in the at least two backup sub-areas The sub-areas each include at least two data blocks, each of the at least two data blocks includes at least two data pages, and N is greater than or equal to 1;
终端将N个数据包的有效数据存储至内存的模拟存储区域内。The terminal stores the valid data of the N data packets in the analog storage area of the internal memory.
其中,每个数据块在擦除一次后可以存储多个数据包,从而极大的提高了每个数据块的写入次数;而且,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,所以本申请实施例拥有更多的数据块用于存储数据包,即使存在某些数据块损坏也不会影响模拟EEPROM的过程,从而可以更好的满足在模拟EEPROM的过程中使用寿命上的要求。Wherein, each data block can store multiple data packets after being erased once, thereby greatly improving the writing times of each data block; moreover, the backup area of the flash memory includes at least two backup sub-areas, at least two Each backup sub-area in the backup sub-area includes at least two data blocks, so the embodiment of the present application has more data blocks for storing data packets, even if some data blocks are damaged, it will not affect the process of simulating EEPROM , so as to better meet the service life requirement in the process of simulating the EEPROM.
在一种可能的实现方式中,终端将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation manner, the terminal stores the valid data of N data packets in an analog storage area of the memory, including:
终端在内存中申请临时存储区域;The terminal applies for a temporary storage area in the memory;
终端将N个数据包存入内存的临时存储区域内;The terminal stores N data packets in the temporary storage area of the memory;
终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内;The terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory;
终端释放内存的临时存储区域。Temporary storage area where the terminal frees memory.
其中,为了快速的将闪存的备份区域中每个数据块的数据页内存储的N个数据包存储到内存的模拟存储区域内,需要一次性将闪存的备份区域中每个数据块的数据页内存储的N个数据包存储到内存的临时存储区域内,然后,再从内存的临时存储区域内将N个数据包内的有效数据存储到内存的模拟存储区域内,所以本申请实施例可以更加快速的将闪存内的N个数据包的有效数据存储至内存的模拟存储区域内。而且,内存的临时存储区域为临时在内存中申请的存储区域,在使用完临时存储区域以后,还需要释放内存的临时存储区域,从而节省终端的系统资源。Among them, in order to quickly store N data packets stored in the data pages of each data block in the backup area of the flash memory to the simulated storage area of the memory, it is necessary to save the data pages of each data block in the backup area of the flash memory at one time. The N data packets stored in the internal memory are stored in the temporary storage area of the internal memory, and then the valid data in the N data packets are stored in the analog storage area of the internal memory from the temporary storage area of the internal memory, so the embodiment of the present application can Store the valid data of N data packets in the flash memory to the analog storage area of the memory more quickly. Moreover, the temporary storage area of the internal memory is a storage area temporarily applied for in the internal memory. After the temporary storage area is used up, the temporary storage area of the internal memory needs to be released, thereby saving system resources of the terminal.
在一种可能的实现方式中,终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation, the terminal stores the valid data of the N data packets in the temporary storage area of the memory in the simulated storage area of the memory, including:
终端在内存的临时存储区域内选择N个数据包内的目标数据包;The terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
终端提取目标数据包的目标数据;The terminal extracts the target data of the target data packet;
终端提取目标数据包的数据头内的偏移地址;The terminal extracts the offset address in the data header of the target data packet;
终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;The terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的目标数据的步骤;When the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the step of the terminal extracting the target data of the target data packet;
在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域的步骤。When the target data packet is the last data packet in the N data packets, continue to perform the step of releasing the temporary storage area of the memory by the terminal.
其中,在终端将N个数据包存入内存的临时存储区域内以后,终端需要根据内存的临时存储区域内每个数据包的数据头的偏移地址,将每个数据包的目标数据存储到内存的模拟存储区域内。Wherein, after the terminal stores N data packets in the temporary storage area of the memory, the terminal needs to store the target data of each data packet in the within the simulated storage area of memory.
在一种可能的实现方式中,终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation, the terminal stores the valid data of the N data packets in the temporary storage area of the memory in the simulated storage area of the memory, including:
终端在内存的临时存储区域内选择N个数据包内的目标数据包;The terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
终端提取目标数据包的目标数据;The terminal extracts the target data of the target data packet;
终端提取目标数据包的数据头内的校验标识、第一校验结果和和偏移地址;The terminal extracts the verification identifier, the first verification result and the offset address in the data header of the target data packet;
终端按照校验标识对应的校验算法对目标数据进行计算得到第二校验结果;The terminal calculates the target data according to the verification algorithm corresponding to the verification identifier to obtain a second verification result;
在第一校验结果和第二校验结果相同时,终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;When the first verification result is the same as the second verification result, the terminal stores the target data in the storage space corresponding to the offset address in the analog storage area of the memory;
在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的目标数据的步骤;When the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the step of the terminal extracting the target data of the target data packet;
在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域的步骤。When the target data packet is the last data packet in the N data packets, continue to perform the step of releasing the temporary storage area of the memory by the terminal.
其中,为了验证目标数据包的目标数据是否在传输过程中出现错误,终端需要提取目标数据包的数据头内的校验标识和第一校验结果,然后,终端按照校验标识对应的校验算法对目标数据进行计算得到第二校验结果。如果第一校验结果和第二校验结果相同,说明目标数据在传输过程中未出现错误,此时便可以将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。如果第一校验结果和第二校验结果不同,说明目标数据在传输过程中出现错误,那么终端便不可以将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。Among them, in order to verify whether the target data of the target data packet has an error during transmission, the terminal needs to extract the verification identifier and the first verification result in the data header of the target data packet, and then, the terminal performs the verification according to the corresponding verification identifier. The algorithm calculates the target data to obtain the second verification result. If the first verification result is the same as the second verification result, it means that there is no error in the transmission process of the target data. At this time, the target data can be stored in the storage space corresponding to the offset address in the analog storage area of the memory. If the first verification result is different from the second verification result, it means that the target data has an error during transmission, and the terminal cannot store the target data in the storage space corresponding to the offset address in the analog storage area of the memory.
在一种可能的实现方式中,终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation, the terminal stores the valid data of the N data packets in the temporary storage area of the memory in the simulated storage area of the memory, including:
终端在内存的临时存储区域内选择N个数据包内的目标数据包;The terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
终端提取目标数据包的加密数据;The terminal extracts the encrypted data of the target data packet;
终端提取目标数据包的数据头内的加密标识和偏移地址;The terminal extracts the encryption identifier and offset address in the data header of the target data packet;
终端根据加密标识对应的加密算法对加密数据进行解密以得到目标数据;The terminal decrypts the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the target data;
终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;The terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的加密数据的步骤;When the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the step of terminal extracting the encrypted data of the target data packet;
在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域的步骤。When the target data packet is the last data packet in the N data packets, continue to perform the step of releasing the temporary storage area of the memory by the terminal.
其中,如果目标数据包的数据头内具有加密标识,说明目标数据包内存储的是将目标数据经过加密后得到的加密数据,所以需要终端根据加密标识对应的加密算法对加密数据进行解密以得到目标数据,并将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,从而保证了目标数据的安全性。Among them, if the data header of the target data packet has an encryption identifier, it means that the encrypted data obtained by encrypting the target data is stored in the target data packet, so the terminal needs to decrypt the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain target data, and store the target data in the storage space corresponding to the offset address in the analog storage area of the memory, thus ensuring the security of the target data.
在一种可能的实现方式中,终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation, the terminal stores the valid data of the N data packets in the temporary storage area of the memory in the simulated storage area of the memory, including:
终端在内存的临时存储区域内选择N个数据包内的目标数据包;The terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
终端提取目标数据包的压缩数据;The terminal extracts the compressed data of the target data packet;
终端提取目标数据包的数据头内的压缩标识和偏移地址;The terminal extracts the compression identifier and offset address in the data header of the target data packet;
终端根据压缩标识对应的压缩算法对压缩数据进行解压缩以得到目标数据;The terminal decompresses the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data;
终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;The terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的压缩数据的步骤;When the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the step of terminal extracting the compressed data of the target data packet;
在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域的步骤。When the target data packet is the last data packet in the N data packets, continue to perform the step of releasing the temporary storage area of the memory by the terminal.
其中,如果目标数据包的数据头内具有压缩标识,说明目标数据包内存储的是将目标数据经过压缩后得到的压缩数据,所以需要终端根据压缩标识对应的压缩算法对压缩数据进行解压缩以得到目标数据,并将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,从而节省了闪存的存储空间。Among them, if the data header of the target data packet has a compression identifier, it means that the compressed data stored in the target data packet is the compressed data obtained after compressing the target data, so the terminal needs to decompress the compressed data according to the compression algorithm corresponding to the compression identifier. The target data is obtained, and the target data is stored in the storage space corresponding to the offset address in the simulated storage area of the memory, thereby saving the storage space of the flash memory.
在一种可能的实现方式中,终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内,包括:In a possible implementation, the terminal stores the valid data of the N data packets in the temporary storage area of the memory in the simulated storage area of the memory, including:
终端在内存的临时存储区域内选择N个数据包内的目标数据包;The terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
终端提取目标数据包的加密数据;The terminal extracts the encrypted data of the target data packet;
终端提取目标数据包的数据头内的校验标识、第一校验结果、加密标识、压缩标识和偏移地址;The terminal extracts the verification identification, the first verification result, the encryption identification, the compression identification and the offset address in the data header of the target data packet;
终端按照校验标识对应的校验算法对加密数据进行计算得到第二校验结果;The terminal calculates the encrypted data according to the verification algorithm corresponding to the verification identifier to obtain a second verification result;
在第一校验结果和第二校验结果相同时,终端根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据;When the first verification result is the same as the second verification result, the terminal decrypts the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the compressed data;
终端根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据;The terminal decrypts the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data;
终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;The terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的加密数据的步骤;When the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the step of terminal extracting the encrypted data of the target data packet;
在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域的步骤。When the target data packet is the last data packet in the N data packets, continue to perform the step of releasing the temporary storage area of the memory by the terminal.
其中,如果目标数据包的数据头内具有压缩标识、加密标识、校验标识和第一校验结果,说明目标数据包内存储的是将目标数据经过压缩后得到的压缩数据,并将压缩数据经过加密后得到的加密数据,而且,还可以验证目标数据包的加密数据是否在传输过程中出现错误。在终端提取目标数据包的加密数据以后,终端需要先验证第一校验结果和第二校验结果相同是否相同,如果是,说明目标数据在传输过程中未出现错误;然后,终端需要根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据,再根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据,最后将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,不仅节省了闪存的存储空间,而且提高了有效数据的安全性,另外,还可以验证目标数据包的加密数据是否在传输过程中出现错误。Wherein, if the data header of the target data packet has a compression identifier, an encryption identifier, a verification identifier, and a first verification result, it means that the target data packet stores compressed data obtained after compressing the target data, and the compressed data The encrypted data obtained after encryption can also verify whether an error occurs in the encrypted data of the target data packet during transmission. After the terminal extracts the encrypted data of the target data packet, the terminal needs to first verify whether the first verification result is the same as the second verification result. If yes, it means that no error occurred in the target data during transmission; The encryption algorithm corresponding to the logo decrypts the encrypted data to obtain the compressed data, and then decrypts the compressed data according to the compression algorithm corresponding to the compression logo to obtain the target data, and finally stores the target data in the analog storage area of the memory corresponding to the offset address In the storage space, not only the storage space of the flash memory is saved, but also the security of valid data is improved. In addition, it is also possible to verify whether the encrypted data of the target data packet has errors during transmission.
第二方面,本申请实施例提供了一种数据存储装置,该装置包括:In a second aspect, an embodiment of the present application provides a data storage device, which includes:
接收模块,用于接收待存储的有效数据;A receiving module, configured to receive valid data to be stored;
配置模块,用于根据预设参数和有效数据配置数据头,数据头用于指示有效数据的属性;The configuration module is used to configure the data header according to preset parameters and valid data, and the data header is used to indicate the attributes of the valid data;
生成模块,用于根据数据头、有效数据和无效数据生成数据包,无效数据用于填充数据包以使数据包的长度与待写入数据页的长度相同,待写入数据页为闪存的备份区域内数据块的数据页;The generation module is used to generate a data packet according to the data header, valid data and invalid data, and the invalid data is used to fill the data packet so that the length of the data packet is the same as the length of the data page to be written, and the data page to be written is a backup of the flash memory the data pages of the data blocks in the region;
存储模块,用于将数据包存储至待写入数据页中。The storage module is used for storing the data packet in the data page to be written.
在一种可能的实现方式中,生成模块,具体用于根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将数据头、有效数据和无效数据组合成数据包。In a possible implementation, the generating module is specifically configured to calculate the length to be filled according to the length of the data header, the length of the valid data, and the length of the data page to be written; the terminal generates invalid data according to the length to be filled; the terminal generates the data The header, valid data, and invalid data are combined into a packet.
在一种可能的实现方式中,生成模块,具体用于获取数据头内的压缩标识、加密标识和校验标识;按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;按照加密标识对应的加密算法对压缩数据进行加密得到加密数据;按照校验标识对应的校验算法对加密数据进行计算得到校验结果;将校验结果写入数据头中以得到目标数据头;根据目标数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;按照待填充长度生成无效数据;将目标数据头、加密数据和无效数据组合成数据包。In a possible implementation, the generation module is specifically used to obtain the compression identifier, encryption identifier, and verification identifier in the data header; compress the valid data according to the compression algorithm corresponding to the compression identifier to obtain compressed data; The encryption algorithm encrypts the compressed data to obtain the encrypted data; calculates the encrypted data according to the verification algorithm corresponding to the verification identification to obtain the verification result; writes the verification result into the data header to obtain the target data header; according to the target data header The length of the encrypted data and the length of the data page to be written calculate the length to be filled; generate invalid data according to the length to be filled; combine the target data header, encrypted data and invalid data into a data packet.
在一种可能的实现方式中,装置还包括:In a possible implementation manner, the device further includes:
第一获取模块,用于获取有效数据的偏移地址;The first obtaining module is used to obtain the offset address of the valid data;
第二存储模块,用于将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。The second storage module is used to store valid data in the storage space corresponding to the offset address in the simulated storage area of the internal memory.
在一种可能的实现方式中,装置还包括:In a possible implementation manner, the device further includes:
第二获取模块,用于在终端初始化时,获取闪存的备份区域中每个数据块的数据页内存储的N个数据包,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,至少两个数据块中的每个数据块均包括至少两个数据页,N大于或等于1;The second obtaining module is used to obtain N data packets stored in the data page of each data block in the backup area of the flash memory when the terminal is initialized. The backup area of the flash memory includes at least two backup sub-areas, and at least two backup sub-areas Each backup sub-area in the area includes at least two data blocks, each of the at least two data blocks includes at least two data pages, and N is greater than or equal to 1;
第三存储模块,用于将N个数据包的有效数据存储至内存的模拟存储区域内。The third storage module is used to store the valid data of the N data packets in the analog storage area of the internal memory.
在一种可能的实现方式中,第三存储模块,具体用于在内存中申请临时存储区域;将N个数据包存入内存的临时存储区域内;在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内;释放内存的临时存储区域。In a possible implementation, the third storage module is specifically used to apply for a temporary storage area in the memory; store N data packets in the temporary storage area of the memory; store N data packets in the temporary storage area of the memory The valid data of the package is stored in the simulated storage area of the memory; the temporary storage area of the memory is released.
在一种可能的实现方式中,第三存储模块,具体用于在内存的临时存储区域内选择N个数据包内的目标数据包;提取目标数据包的加密数据;提取目标数据包的数据头内的校验标识、第一校验结果、加密标识、压缩标识和偏移地址;按照校验标识对应的校验算法对加密数据进行计算得到第二校验结果;在第一校验结果和第二校验结果相同时,根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据;根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据;将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的目标数据;在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域。In a possible implementation, the third storage module is specifically used to select a target data packet in the N data packets in the temporary storage area of the memory; extract the encrypted data of the target data packet; extract the data header of the target data packet The verification identification, the first verification result, the encryption identification, the compression identification and the offset address in the verification identification; the encrypted data is calculated according to the verification algorithm corresponding to the verification identification to obtain the second verification result; the first verification result and When the second verification results are the same, decrypt the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the compressed data; decrypt the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data; store the target data to the memory simulation In the storage space corresponding to the offset address in the storage area; when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the terminal to extract the target The target data of the data packet; when the target data packet is the last data packet in the N data packets, continue to execute the terminal to release the temporary storage area of the internal memory.
第三方面,本申请实施例提供了一种数据存储装置,该装置包括:收发器、处理器和存储器,其中,该收发器、该存储器和该处理器通过内部连接通路互相通信,该存储器用于存储指令,该处理器用于执行该存储器存储的指令,以控制收发器接收信号,并控制收发器发送信号,并且当该处理器执行该存储器存储的指令时,该装置使得该处理器执行上述第一方面或第一方面的任一种可能实现方式中的方法。In a third aspect, the embodiment of the present application provides a data storage device, which includes: a transceiver, a processor, and a memory, wherein the transceiver, the memory, and the processor communicate with each other through an internal connection path, and the memory uses For storing instructions, the processor is used to execute the instructions stored in the memory to control the transceiver to receive signals and to control the transceiver to send signals, and when the processor executes the instructions stored in the memory, the device causes the processor to perform the above-mentioned The first aspect or the method in any possible implementation manner of the first aspect.
第四方面,本申请实施例提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一种可能实现方式中的方法。In the fourth aspect, the embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores instructions, and when it is run on a computer, the computer executes the above-mentioned first aspect or any of the first aspects. A method in one possible implementation.
第五方面,本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一种可能实现方式中的方法。In the fifth aspect, the embodiments of the present application provide a computer program product including instructions, which, when run on a computer, cause the computer to execute the method in the above-mentioned first aspect or any possible implementation manner of the first aspect.
第六方面,本申请实施例提供了一种芯片,所述芯片包括处理器和/或程序指令,当所述芯片运行时,实现上述第一方面或第一方面的任一种可能实现方式中的方法。In the sixth aspect, the embodiment of the present application provides a chip, the chip includes a processor and/or program instructions, and when the chip is running, it can implement the above-mentioned first aspect or any of the possible implementations of the first aspect Methods.
附图说明Description of drawings
图1所示的为本申请实施例提供的一种终端的示意图;FIG. 1 is a schematic diagram of a terminal provided in an embodiment of the present application;
图2所示的为本申请实施例提供的在闪存的数据块内多个数据页存储多个数据包的示意图;Figure 2 is a schematic diagram of storing multiple data packets in multiple data pages in the data block of the flash memory provided by the embodiment of the present application;
图3所示的为本申请实施例提供的一种数据存储方法的流程图;FIG. 3 is a flowchart of a data storage method provided by an embodiment of the present application;
图4所示的为本申请实施例提供的另一种数据存储方法的流程图;Figure 4 is a flowchart of another data storage method provided by the embodiment of the present application;
图5所示的为本申请实施例提供的基于图4的步骤S26细化的实施例的流程图;The flowchart shown in FIG. 5 is a detailed embodiment based on step S26 in FIG. 4 provided by the embodiment of the present application;
图6所示的为本申请实施例提供的一种数据存储装置的示意图;FIG. 6 is a schematic diagram of a data storage device provided by an embodiment of the present application;
图7所示的为本申请实施例提供的另一种数据存储装置的示意图。FIG. 7 is a schematic diagram of another data storage device provided by the embodiment of the present application.
具体实施方式Detailed ways
在前文的背景技术中提到,目前模拟EEPROM的相关技术无法满足在使用寿命上的要求。模拟EEPROM的相关技术采用的数据存储方式为:将数据头和有效数据组成的数据包直接存储到数据块中,而且每个数据块存储一个数据包。其中,由于每个数据头和每个有效数据的长度是不同的,所以每个数据包的长度也是不同的,在这种情况下,如果在一个数据块中存储多个数据包,那么控制器便无法得知多个数据包与数据块的多个数据页的对应关系,控制器在数据块的多个数据页中也就无法正确的提取出多个数据包。As mentioned above in the background art, the related technology of simulating EEPROM cannot meet the requirement on service life. The data storage method adopted by the relevant technology of simulating EEPROM is: directly store the data packet composed of the data header and valid data into the data block, and each data block stores a data packet. Among them, since the length of each data header and each valid data is different, the length of each data packet is also different. In this case, if multiple data packets are stored in one data block, then the controller It is impossible to know the corresponding relationship between the multiple data packets and the multiple data pages of the data block, and the controller cannot correctly extract multiple data packets from the multiple data pages of the data block.
为了避免控制器在数据块的多个数据页中提取数据包的过程出现混乱,所以背景技术中提到的相关技术只能在每个数据块中存储一个数据包,每个存储了一个数据包的数据块只有在被擦除以后才能存储下一个数据包。由于一个数据块通常具有10万次的擦除寿命,而且每个数据块在擦除一次后只能存储一个数据包,所以一个数据块在存储10万个数据包后便会报废,即一个数据块写入10万次就会报废。然而,EEPROM可以支持百万次级别的写入次数,所以背景技术中提到的模拟EEPROM的相关技术无法满足在使用寿命上的要求。In order to avoid confusion in the process of the controller extracting data packets from multiple data pages of the data block, the related technologies mentioned in the background technology can only store one data packet in each data block, each storing a data packet The data block in the block can only store the next data packet after being erased. Since a data block usually has an erasure life of 100,000 times, and each data block can only store one data packet after being erased once, a data block will be scrapped after storing 100,000 data packets, that is, a data block A block is written to 100,000 times before it becomes obsolete. However, the EEPROM can support write times of millions of times, so the related technology of simulating EEPROM mentioned in the background art cannot meet the requirement on service life.
为此,本申请实施例提供了一种数据存储方法及装置,可以在模拟EEPROM的过程中满足使用寿命上的要求。For this reason, the embodiment of the present application provides a data storage method and device, which can meet the service life requirement in the process of simulating the EEPROM.
请参见图1和图2所示,图1所示的为本申请实施例提供的一种终端的示意图,图2所示的为本申请实施例提供的在闪存的数据块内多个数据页存储多个数据包的示意图。Please refer to Figure 1 and Figure 2, Figure 1 shows a schematic diagram of a terminal provided by the embodiment of the present application, and Figure 2 shows multiple data pages in the data block of the flash memory provided by the embodiment of the present application Schematic diagram of storing multiple packets.
在图1和图2所示的实施例中,本申请实施例提供的终端00包括控制器01、内存02、闪存03和输入输出接口04。其中,内存02包括模拟存储区域和临时存储区域,模拟存储区域用于模拟EEPROM的存储空间,临时存储区域用于临时存储闪存03提供的数据包;闪存03包括至少两个备份子区域,每个备份子区域包括至少两个备份子区域,每个数据块包括至少两个数据页;输入输出接口04可以包括AV输出接口、信号输入接口和红外遥控器信号接收器等。In the embodiments shown in FIG. 1 and FIG. 2 , the terminal 00 provided in the embodiment of the present application includes a controller 01 , a memory 02 , a flash memory 03 and an input/output interface 04 . Wherein, the memory 02 includes a simulated storage area and a temporary storage area, the simulated storage area is used to simulate the storage space of the EEPROM, and the temporary storage area is used to temporarily store the data packets provided by the flash memory 03; the flash memory 03 includes at least two backup sub-areas, each The backup sub-area includes at least two backup sub-areas, and each data block includes at least two data pages; the input and output interface 04 may include an AV output interface, a signal input interface, an infrared remote control signal receiver, and the like.
本申请实施例提供的终端00主要包括三种工作场景,第一种工作场景为终端00接收外部设备20发送的有效数据的过程,第二种工作场景为终端00初始化的过程,第三种工作场景为读取终端00的有效数据的过程。The terminal 00 provided by the embodiment of the present application mainly includes three working scenarios. The first working scenario is the process in which the terminal 00 receives valid data sent by the external device 20. The second working scenario is the process of initializing the terminal 00. The third working scenario is The scenario is the process of reading valid data of terminal 00.
请结合图1和图2所示,下面简要介绍终端00的第一种工作场景,即终端00接收外部设备20发送的有效数据的过程。Please combine FIG. 1 and FIG. 2 to briefly introduce the first working scenario of the terminal 00 , that is, the process in which the terminal 00 receives valid data sent by the external device 20 .
在终端00处于开机状态下,如果外部设备20向终端00发送有效数据和偏移地址,那么终端00利用输入输出接口04接收外部设备20发送的有效数据。首先,为了保证控制器01可以快速的读取到有效数据,控制器01会将有效数据存储至内存02的模拟存储区域内偏移地址对应的存储空间中。然后,为了保证有效数据可以始终保存在终端00内,控制器01会将有效数据存储到闪存03中。When the terminal 00 is turned on, if the external device 20 sends valid data and offset address to the terminal 00 , then the terminal 00 uses the input and output interface 04 to receive the valid data sent by the external device 20 . First, in order to ensure that the controller 01 can quickly read valid data, the controller 01 will store the valid data in the storage space corresponding to the offset address in the analog storage area of the memory 02 . Then, in order to ensure that the valid data can always be stored in the terminal 00, the controller 01 will store the valid data in the flash memory 03.
其中,控制器01会按照以下方式将有效数据存储到闪存03中。具体的,控制器01会根据预设参数配置和有效数据数据头,并根据闪存03的备份子区域的数据块的数据页的长度、数据头的长度和有效数据的长度生成无效数据,以使根据数据头、有效数据和无效数据生成的数据包的长度等于闪存03的备份子区域的数据块内一个数据页的长度的倍数,并基于倍数的具体数值利用闪存03的备份子区域的数据块内一个或多个数据页存储一个数据包,从而保证每个数据包的长度与一个数据页的长度的倍数是相等的。在每个数据包的长度与一个数据页的长度的倍数相等的情况下,控制器01可以基于数据包与数据页的对应关系,在数据块的多个数据页内提取出多个数据包,所以每个数据块在擦除一次后可以存储多个数据包,从而极大的提高了每个数据块的写入次数,因此,本申请实施例提供的方案可以在模拟EEPROM的过程中满足使用寿命上的要求。Among them, the controller 01 will store valid data in the flash memory 03 in the following manner. Specifically, the controller 01 will configure the valid data data header according to the preset parameters, and generate invalid data according to the length of the data page of the data block in the backup sub-area of the flash memory 03, the length of the data header and the length of the valid data, so that The length of the data packet generated according to the data header, valid data and invalid data is equal to the multiple of the length of a data page in the data block of the backup sub-area of the flash memory 03, and the data block of the backup sub-area of the flash memory 03 is utilized based on the specific value of the multiple Store a data packet in one or more data pages, so as to ensure that the length of each data packet is equal to the multiple of the length of a data page. When the length of each data packet is equal to a multiple of the length of a data page, the controller 01 can extract multiple data packets from multiple data pages of the data block based on the correspondence between the data packet and the data page, Therefore, each data block can store multiple data packets after being erased once, thereby greatly improving the write times of each data block. Therefore, the solution provided by the embodiment of the present application can meet the requirements of use in the process of simulating EEPROM life expectancy requirements.
下面结合图1、图2和具体实例来说明终端00的第一种工作场景。The first working scenario of the terminal 00 will be described below with reference to FIG. 1 , FIG. 2 and specific examples.
例如,假设闪存03的一个备份子区域内的每个数据块的长度均为128K字节,每个数据块包括64个数据页,那么每个数据页的长度均为2K字节,即2048字节。在外部设备20向终端00的输入输出接口04发送20字节的有效数据以后,首先,控制器01会将20字节的有效数据存储至内存02的模拟存储区域内,以保证存储在内存02的模拟存储区域内的有效数据可以快速的被读取出来。然后,控制器01根据预设参数配置和有效数据数据头,假设配置成功的数据头的长度为28字节,为了保证每个数据包的长度与一个数据页的长度的倍数是相等的,需要计算出无效数据的长度。在数据头的长度与有效数据的长度之和小于一个数据页的长度,那么无效数据的长度=数据页的长度-有效数据的长度-数据头的长度=2048字节-20字节-28字节=2000字节。其次,控制器01生成2000字节的无效数据,并将28字节的数据头、20字节的有效数据和2000字节的无效数据组合成数据包A(如图2中的数据包A),该数据包A的长度为2048字节,即2K字节。最后,控制器01利用闪存03的备份子区域的数据块内的数据页0(如图2中的数据页0)存储该数据包A。For example, assuming that the length of each data block in a backup sub-area of flash memory 03 is 128K bytes, and each data block includes 64 data pages, then the length of each data page is 2K bytes, that is, 2048 words Festival. After the external device 20 sends 20 bytes of valid data to the input and output interface 04 of the terminal 00, first, the controller 01 will store the 20 bytes of valid data in the analog storage area of the memory 02 to ensure that the data stored in the memory 02 Valid data in the simulated storage area can be read out quickly. Then, the controller 01 configures the valid data header according to the preset parameters, assuming that the length of the successfully configured data header is 28 bytes, in order to ensure that the length of each data packet is equal to the multiple of the length of a data page, it is necessary to Calculate the length of invalid data. When the sum of the length of the data header and the length of the valid data is less than the length of a data page, then the length of the invalid data=the length of the data page-the length of the valid data-the length of the data header=2048 bytes-20 bytes-28 words Section = 2000 bytes. Secondly, the controller 01 generates 2000 bytes of invalid data, and combines the 28 bytes of data header, 20 bytes of valid data and 2000 bytes of invalid data into data packet A (as shown in data packet A in Figure 2) , the length of the data packet A is 2048 bytes, that is, 2K bytes. Finally, the controller 01 uses the data page 0 (such as data page 0 in FIG. 2 ) in the data block of the backup sub-area of the flash memory 03 to store the data packet A.
在上述实例中,由于数据页与数据包的长度均为2K字节,所以保证了数据包的长度与数据页的长度是相等的。在上述例子中,一个数据块包括64个2K字节的数据页,如果每个数据包的长度均为2K字节,那么一个数据块用于存储数据包的次数为64次,即一个数据块擦除一次可以使用64次,而且一个数据块具有10万次的擦除寿命,那么本申请实施例提供的数据存储方法可以使得一个数据块存入数据的使用次数达到64次×10万次=640万次,从而可以满足模拟EEPROM的过程中在使用寿命上的要求。In the above example, since the lengths of the data page and the data packet are both 2K bytes, it is ensured that the length of the data packet is equal to the length of the data page. In the above example, a data block includes 64 data pages of 2K bytes. If the length of each data packet is 2K bytes, then the number of times a data block is used to store data packets is 64 times, that is, a data block Erase can be used 64 times once, and a data block has an erasure life of 100,000 times, then the data storage method provided by the embodiment of the present application can make the number of times a data block is stored in data reach 64 times×100,000 times= 6.4 million times, which can meet the service life requirements in the process of simulating EEPROM.
另外,在控制器01接收到有效数据并生成数据头时,如果控制器01计算出有效数据的长度与数据头的长度之和小于一个数据页的长度,那么控制器01根据数据头、有效数据和无效数据生成的数据包的长度要等于一个数据页的长度。如果控制器01计算出有效数据的长度与数据头的长度之和大于一个数据页的长度且小于两个数据页的长度,那么控制器01根据数据头、有效数据和无效数据生成的数据包的长度要等于两个数据页的长度。如果控制器01计算出有效数据的长度与数据头的长度之和大于两个数据页的长度且小于三个数据页的长度,那么控制器01根据数据头、有效数据和无效数据生成的数据包的长度要等于三个数据页的长度,以此类推,一直保持生成的数据包的长度等于数据页的长度的倍数。In addition, when the controller 01 receives the valid data and generates the data header, if the controller 01 calculates that the sum of the length of the valid data and the length of the data header is less than the length of a data page, then the controller 01 will The length of the data packet generated with invalid data must be equal to the length of a data page. If the controller 01 calculates that the sum of the length of the valid data and the length of the data header is greater than the length of one data page and less than the length of two data pages, then the data packet generated by the controller 01 according to the data header, valid data and invalid data The length should be equal to the length of two data pages. If the controller 01 calculates that the sum of the length of the valid data and the length of the data header is greater than the length of two data pages and less than the length of three data pages, then the data packet generated by the controller 01 according to the data header, valid data and invalid data The length of the packet must be equal to the length of three data pages, and so on, always keeping the length of the generated data packet equal to a multiple of the length of the data page.
例如,假设闪存03的一个备份子区域内的每个数据块的长度均为128K字节,每个数据块包括64个数据页,那么每个数据页的长度均为2K字节。假设数据头的长度与有效数据的第一部分的长度之和等于2K字节,有效数据的第二部分的长度为1K字节,那么无效数据的长度=数据页的长度-有效数据的第二部分的长度=2K字节-1K字节=1K字节。控制器01生成1K字节的无效数据,并将数据头、有效数据的第一部分、有效数据的第二部分和无效数据组合成数据包E(如图2的数据包E),该数据包E的长度为4K字节,需要占用两个2K字节的数据页。最后,控制器01利用闪存03的备份子区域的数据块内的数据页i和数据页i+1(如图2中的数据页i和数据页i+1)存储该数据包E。For example, assuming that the length of each data block in a backup subarea of the flash memory 03 is 128K bytes, and each data block includes 64 data pages, then the length of each data page is 2K bytes. Suppose the sum of the length of the data header and the length of the first part of the valid data is equal to 2K bytes, and the length of the second part of the valid data is 1K bytes, then the length of the invalid data = the length of the data page - the second part of the valid data The length of = 2K bytes - 1K bytes = 1K bytes. The controller 01 generates invalid data of 1K bytes, and combines the data header, the first part of the valid data, the second part of the valid data and the invalid data into a data packet E (such as the data packet E in Figure 2), the data packet E The length of 4K bytes needs to occupy two data pages of 2K bytes. Finally, the controller 01 uses data page i and data page i+1 in the data block of the backup sub-area of the flash memory 03 (such as data page i and data page i+1 in FIG. 2 ) to store the data packet E.
请结合图1和图2所示,下面简要介绍终端00的第二种工作场景,即终端00初始化的过程。Please combine FIG. 1 and FIG. 2 to briefly introduce the second working scenario of the terminal 00, that is, the initialization process of the terminal 00.
在终端关机时,存储至内存02的模拟存储区域的有效数据会全部丢失,但是存储至闪存03的备份子区域的数据块的数据页内的有效数据会被保存下来。在终端重新开机以后,为了保证控制器01可以快速的读取到有效数据,控制器01会将存储至闪存03的备份子区域的数据块的数据页内的数据包提取出来,并在内存02中申请临时存储区域,将提取出来的数据包全部存储至内存02的临时存储区域内;然后,控制器01在内存02的临时存储区域内将所有数据包的有效数据存储至内存02的模拟存储区域内,其中,每个数据包的数据头内均存储有效数据的偏移地址,每个数据包的有效数据均是按照数据头内的偏移地址存储至内存02的模拟存储区域内;最后,控制器01会释放内存02的临时存储区域。When the terminal is turned off, all the valid data stored in the analog storage area of the memory 02 will be lost, but the valid data stored in the data page of the data block in the backup sub-area of the flash memory 03 will be preserved. After the terminal restarts, in order to ensure that the controller 01 can quickly read valid data, the controller 01 will extract the data packets stored in the data page of the data block in the backup sub-area of the flash memory 03, and store them in the memory 02 Apply for a temporary storage area, and store all the extracted data packets in the temporary storage area of memory 02; then, controller 01 stores the valid data of all data packets in the temporary storage area of memory 02 to the analog storage of memory 02 In the region, the offset address of valid data is stored in the data header of each data packet, and the valid data of each data packet is stored in the analog storage area of memory 02 according to the offset address in the data header; finally , the controller 01 will release the temporary storage area of the memory 02.
请结合图1和图2所示,下面简要介绍终端00的第三种工作场景,即读取终端00的有效数据的过程。Please combine FIG. 1 and FIG. 2 to briefly introduce the third working scenario of the terminal 00, that is, the process of reading valid data of the terminal 00.
在终端00处于开机状态下,如果控制器01需要读取内存02的模拟存储区域内的某个有效数据,那么控制器01需要基于该有效数据的偏移地址在内存02的模拟存储区域内读取该有效数据。When the terminal 00 is turned on, if the controller 01 needs to read certain valid data in the analog storage area of the memory 02, then the controller 01 needs to read the valid data in the analog storage area of the memory 02 based on the offset address of the valid data. Get the valid data.
请参见图3所示,图3所示的为本申请实施例提供的一种数据存储方法的流程图。图3所示的方法可以应用于图1所示的终端内,图3所示的方法可以使终端在模拟EEPROM的过程中满足使用寿命上的要求。该方法包括以下步骤。Please refer to FIG. 3 , which is a flowchart of a data storage method provided by an embodiment of the present application. The method shown in FIG. 3 can be applied to the terminal shown in FIG. 1 , and the method shown in FIG. 3 can make the terminal meet the service life requirement in the process of simulating the EEPROM. The method includes the following steps.
步骤S11、终端接收待存储的有效数据。Step S11, the terminal receives valid data to be stored.
其中,待存储的有效数据指的是外部设备向终端发送的需要存储的数据。Wherein, the valid data to be stored refers to the data that needs to be stored and is sent from the external device to the terminal.
例如,假设终端为机顶盒,外部设备为遥控器,在用户操作遥控器的按键时,遥控器会基于被用户按下的按键生成控制指令,并将控制指令发送给机顶盒。在机顶盒接收到遥控器发送的控制指令时,机顶盒会提取该控制指令中需要存储的有效数据,并将有效数据存储至终端的闪存中。For example, assuming that the terminal is a set-top box and the external device is a remote controller, when the user operates a button on the remote controller, the remote controller will generate a control instruction based on the button pressed by the user, and send the control instruction to the set-top box. When the set-top box receives the control command sent by the remote controller, the set-top box will extract valid data to be stored in the control command, and store the valid data in the flash memory of the terminal.
步骤S12、终端根据预设参数和有效数据配置数据头,数据头用于指示有效数据的属性。Step S12, the terminal configures the data header according to the preset parameters and the valid data, and the data header is used to indicate the attribute of the valid data.
其中,预设参数为终端预先配置好的参数,预设参数可以包括标签、校验标识、校验结果、加密标识、加密秘钥、压缩标识、有效数据的偏移地址和无效数据的长度等参数。Among them, the preset parameters are parameters pre-configured by the terminal, and the preset parameters may include labels, verification identifiers, verification results, encryption identifiers, encryption keys, compression identifiers, offset addresses of valid data, and lengths of invalid data, etc. parameter.
在终端根据预设参数和有效数据配置数据头以后,数据头便具有了预设参数的值和与有效数据先关的信息。After the terminal configures the data header according to the preset parameters and valid data, the data header has the values of the preset parameters and information related to the valid data.
标签为终端预先配置好的内容。如果预设参数内包含有标签,那么终端只需要将标签存入数据头中。Tabs are pre-configured content for the terminal. If the preset parameters include a tag, the terminal only needs to store the tag in the data header.
例如,假设终端预先配置好的标签为“0x12345678”,那么终端根据预设参数和有效数据配置数据头过程中,会将标签“0x12345678”存入到数据头中。For example, assuming that the pre-configured label of the terminal is "0x12345678", then the terminal will store the label "0x12345678" in the data header during the process of configuring the data header according to the preset parameters and valid data.
校验标识为终端预先配置好的内容,校验结果为基于校验标识对应的校验算法对有效数据进行计算得到的校验结果。如果预设参数内包含有校验标识和校验结果,那么终端需要将校验标识存入数据头中,然后基于校验标识对应的校验算法对有效数据进行计算得到的校验结果,并将检验结果存入数据头中。The verification identifier is the content pre-configured by the terminal, and the verification result is the verification result obtained by calculating the valid data based on the verification algorithm corresponding to the verification identifier. If the preset parameters include the verification identifier and the verification result, the terminal needs to store the verification identifier in the data header, and then calculate the verification result based on the verification algorithm corresponding to the verification identifier for the valid data, and Store the test result in the data header.
例如,假设终端预先配置好的校验标识为“1”,有效数据为“A”那么终端根据预设参数和有效数据配置数据头过程中,会将校验标识“1”存入到数据头中,然后终端基于校验标识“1”对应的校验算法“循环冗余校验(Cyclic Redundancy Check,CRC)”对有效数据“A”进行计算得到的校验结果“B”,并将检验结果“B”存入数据头中。For example, assuming that the pre-configured verification flag of the terminal is "1" and the valid data is "A", then the terminal will store the verification flag "1" in the data header during the process of configuring the data header according to the preset parameters and valid data. , then the terminal calculates the verification result "B" obtained by calculating the valid data "A" based on the verification algorithm "Cyclic Redundancy Check (CRC)" corresponding to the verification identifier "1", and checks The result "B" is stored in the data header.
加密标识和加密秘钥为终端预先配置好的内容。如果预设参数内包含有加密标识和加密秘钥,那么终端需要将加密标识和加密秘钥存入数据头中,然后基于加密标识对应的加密算法和加密秘钥对有效数据进行加密得到的加密结果。加密结果可以用来替换真实的有效数据,以提高有效数据的安全性。The encryption ID and the encryption key are pre-configured contents of the terminal. If the preset parameters include an encryption ID and encryption key, the terminal needs to store the encryption ID and encryption key in the data header, and then encrypt the valid data based on the encryption algorithm and encryption key corresponding to the encryption ID. result. The encryption result can be used to replace the real valid data to improve the security of the valid data.
例如,假设终端预先配置好的加密标识为“2”,加密秘钥为“C”,有效数据为“A”,终端需要将加密标识“2”和加密秘钥“C”存入数据头中,然后基于加密标识“2”对应的加密算法“高级加密标准(Advanced Encryption Standard,AES)”和加密秘钥“C”对有效数据“A”进行加密得到的加密结果“D”。加密结果“D”可以用来替换真实的有效数据“A”,以提高有效数据的安全性。For example, assuming that the pre-configured encryption ID of the terminal is "2", the encryption key is "C", and the valid data is "A", the terminal needs to store the encryption ID "2" and the encryption key "C" in the data header , and then based on the encryption algorithm "Advanced Encryption Standard (AES)" corresponding to the encryption identifier "2" and the encryption key "C", the encryption result "D" obtained by encrypting the valid data "A" is obtained. The encryption result "D" can be used to replace the real valid data "A" to improve the security of the valid data.
压缩标识为终端预先配置好的内容。如果预设参数内包含有压缩标识,那么终端需要将压缩标识存入数据头中,然后基于压缩标识对应的压缩算法对有效数据进行压缩得到的压缩结果。压缩结果可以用来替换真实的有效数据,以节省终端的闪存的存储空间。The compressed flag is pre-configured content for the terminal. If the preset parameter contains a compression identifier, the terminal needs to store the compression identifier in the data header, and then compress the valid data based on the compression algorithm corresponding to the compression identifier to obtain a compression result. The compressed result can be used to replace real valid data, so as to save the storage space of the flash memory of the terminal.
例如,假设终端预先配置好的压缩标识为“1”,有效数据为“A”,终端需要将压缩标识“1”存入数据头中,然后基于压缩标识“1”对应的压缩算法“gzip”对有效数据“A”进行压缩得到的压缩结果“E”。压缩结果“E”可以用来替换真实的有效数据“A”,以节省终端的闪存的存储空间。For example, assuming that the pre-configured compression identifier of the terminal is "1" and the valid data is "A", the terminal needs to store the compression identifier "1" in the data header, and then based on the compression algorithm "gzip" corresponding to the compression identifier "1", Compression result "E" obtained by compressing valid data "A". The compression result "E" can be used to replace the real effective data "A", so as to save the storage space of the flash memory of the terminal.
有效数据的偏移地址为终端分配的偏移地址。如果预设参数内包含有有效数据的偏移地址,那么终端需要将有效数据的偏移地址存入数据头中。The offset address of valid data is the offset address allocated by the terminal. If the preset parameter contains the offset address of the valid data, the terminal needs to store the offset address of the valid data in the data header.
无效数据的长度为终端根据数据头的长度、有效数据的长度和待写入数据页的长度计算出来的。其中,首先需要计算数据头的长度与有效数据的长度之和以得到初始数据长度,然后,计算待写入数据页的长度与初始数据长度之差以得到无效数据的长度,从而可以保证终端根据数据头、有效数据和无效数据生成的数据包的长度等于待写入数据页的长度。The length of the invalid data is calculated by the terminal according to the length of the data header, the length of the valid data and the length of the data page to be written. Among them, it is first necessary to calculate the sum of the length of the data header and the length of the valid data to obtain the initial data length, and then calculate the difference between the length of the data page to be written and the length of the initial data to obtain the length of the invalid data, so that the terminal can be guaranteed to The length of the data packet generated by the data header, valid data and invalid data is equal to the length of the data page to be written.
步骤S13、终端根据数据头、有效数据和无效数据生成数据包。Step S13, the terminal generates a data packet according to the data header, valid data and invalid data.
其中,无效数据用于填充数据包以使数据包的长度与待写入数据页的长度相同,待写入数据页为闪存的备份区域内数据块的数据页。Wherein, the invalid data is used to fill the data packet so that the length of the data packet is the same as the length of the data page to be written, and the data page to be written is a data page of a data block in the backup area of the flash memory.
在终端接收待存储的有效数据且配置好数据头以后,如果终端计算出有效数据的长度与数据头的长度之和小于一个数据页的长度,那么终端根据数据头、有效数据和无效数据生成的数据包的长度要等于一个数据页的长度。After the terminal receives the valid data to be stored and configures the data header, if the terminal calculates that the sum of the length of the valid data and the length of the data header is less than the length of one data page, then the The length of the data packet should be equal to the length of a data page.
如果终端计算出有效数据的长度与数据头的长度之和大于一个数据页的长度且小于两个数据页的长度,那么终端根据数据头、有效数据和无效数据生成的数据包的长度要等于两个数据页的长度。If the terminal calculates that the sum of the length of the valid data and the length of the data header is greater than the length of one data page and less than the length of two data pages, then the length of the data packet generated by the terminal based on the data header, valid data and invalid data must be equal to two The length of data pages.
如果终端计算出有效数据的长度与数据头的长度之和大于两个数据页的长度且小于三个数据页的长度,那么终端根据数据头、有效数据和无效数据生成的数据包的长度要等于三个数据页的长度,以此类推,以使生成的数据包的长度等于数据页的长度的倍数。If the terminal calculates that the sum of the length of the valid data and the length of the data header is greater than the length of two data pages and less than the length of three data pages, then the length of the data packet generated by the terminal based on the data header, valid data and invalid data must be equal to The length of three data pages, and so on, so that the length of the resulting data packet is a multiple of the length of the data page.
由于“终端根据数据头、有效数据和无效数据生成数据包”的方式有很多种,下面简要介绍几种方式。Since there are many ways for "the terminal to generate a data packet according to the data header, valid data, and invalid data", several ways are briefly introduced below.
在一种可选择的方式中,“终端根据数据头、有效数据和无效数据生成数据包”还可以包括以下步骤:终端根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将数据头、有效数据和无效数据组合成数据包。其中,终端还可以将待填充长度写入数据头中。In an optional manner, "the terminal generates a data packet according to the data header, valid data, and invalid data" may also include the following steps: the terminal calculates the packet according to the length of the data header, the length of the valid data, and the length of the data page to be written The length to be filled; the terminal generates invalid data according to the length to be filled; the terminal combines the data header, valid data and invalid data into a data packet. Wherein, the terminal may also write the length to be filled into the data header.
其中,终端根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度,并且按照待填充长度生成无效数据,从而可以保证将数据头、有效数据和无效数据组合成数据包的长度与待写入数据页的长度相同。Among them, the terminal calculates the length to be filled according to the length of the data header, the length of the valid data and the length of the data page to be written, and generates invalid data according to the length to be filled, so as to ensure that the data header, valid data and invalid data are combined into data The length of the packet is the same as the length of the data page to be written.
在一种可选择的方式中,“终端根据数据头、有效数据和无效数据生成数据包”还可以包括以下步骤:终端获取数据头内的校验标识;终端按照校验标识对应的校验算法对有效数据进行计算得到校验结果;终端将校验结果写入数据头中以得到目标数据头;终端根据目标数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将目标数据头、有效数据和无效数据组合成数据包。In an optional manner, "the terminal generates a data packet according to the data header, valid data, and invalid data" may also include the following steps: the terminal obtains the verification identifier in the data header; the terminal obtains the verification algorithm according to the verification identifier Calculate the valid data to obtain the verification result; the terminal writes the verification result into the data header to obtain the target data header; the terminal calculates the length to be filled according to the length of the target data header, the length of the valid data and the length of the data page to be written ; The terminal generates invalid data according to the length to be filled; the terminal combines the target data header, valid data and invalid data into a data packet.
其中,终端将校验结果存储在目标数据头中,从而可以随时对有效数据进行校验,以判断有效数据的正确性。Wherein, the terminal stores the verification result in the target data header, so that the valid data can be verified at any time to judge the correctness of the valid data.
在一种可选择的方式中,“终端根据数据头、有效数据和无效数据生成数据包”还可以包括以下步骤:终端获取数据头内的压缩标识;终端按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;终端根据数据头的长度、压缩数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将数据头、压缩数据和无效数据组合成数据包。In an optional manner, "the terminal generates a data packet according to the data header, valid data, and invalid data" may also include the following steps: the terminal obtains the compression identifier in the data header; the terminal compresses the valid data according to the compression algorithm corresponding to the compression identifier Perform compression to obtain compressed data; the terminal calculates the length to be filled according to the length of the data header, the length of the compressed data, and the length of the data page to be written; the terminal generates invalid data according to the length to be filled; the terminal combines the data header, compressed data and invalid data into packets.
其中,由于压缩数据相对于有效数据占用的存储空间更小,终端将数据头、压缩数据和无效数据组合成数据包,可以节省终端的闪存的存储空间。Wherein, since the storage space occupied by the compressed data is smaller than that of the valid data, the terminal combines the data header, the compressed data and the invalid data into a data packet, which can save the storage space of the flash memory of the terminal.
在一种可选择的方式中,“终端根据数据头、有效数据和无效数据生成数据包”还可以包括以下步骤:终端获取数据头内的加密标识;终端按照加密标识对应的加密算法对有效数据进行加密得到加密数据;终端根据数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将数据头、加密数据和无效数据组合成数据包。In an optional manner, "the terminal generates a data packet according to the data header, valid data, and invalid data" may also include the following steps: the terminal acquires the encryption identifier in the data header; the terminal encrypts the valid data according to the encryption algorithm corresponding to the encryption identifier Encrypt to obtain encrypted data; the terminal calculates the length to be filled according to the length of the data header, the length of the encrypted data, and the length of the data page to be written; the terminal generates invalid data according to the length to be filled; the terminal combines the data header, encrypted data and invalid data into packets.
其中,由于加密数据相对于有效数据具有更高的安全性,终端将数据头、加密数据和无效数据组合成数据包,可以提高有效数据的安全性。Wherein, since the encrypted data has higher security than the valid data, the terminal combines the data header, the encrypted data and the invalid data into a data packet, which can improve the security of the valid data.
在一种可选择的方式中,“终端根据数据头、有效数据和无效数据生成数据包”还可以包括以下步骤:终端获取数据头内的压缩标识、加密标识和校验标识;终端按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;终端按照加密标识对应的加密算法对压缩数据进行加密得到加密数据;终端按照校验标识对应的校验算法对加密数据进行计算得到校验结果;终端将校验结果写入数据头中以得到目标数据头;终端根据目标数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将目标数据头、加密数据和无效数据组合成数据包。In an optional manner, "the terminal generates a data packet according to the data header, valid data, and invalid data" may also include the following steps: the terminal obtains the compression identifier, encryption identifier, and verification identifier in the data header; The corresponding compression algorithm compresses the valid data to obtain compressed data; the terminal encrypts the compressed data according to the encryption algorithm corresponding to the encryption identifier to obtain encrypted data; the terminal calculates the encrypted data according to the verification algorithm corresponding to the verification identifier to obtain the verification result; The terminal writes the verification result into the data header to obtain the target data header; the terminal calculates the length to be filled according to the length of the target data header, the length of the encrypted data, and the length of the data page to be written; the terminal generates invalid data according to the length to be filled; The terminal combines the target data header, encrypted data, and invalid data into a data packet.
其中,终端对有效数据进行了压缩以得到压缩数据,然后又对压缩数据进行加密以得到加密数据,不仅可以节省终端的闪存的存储空间,而且还能提高有效数据的安全性。另外,终端基于校验标识对应的校验算法对加密数据进行计算得到校验结果,并将校验结果存储在目标数据头中,从而可以随时对有效数据进行校验,以判断有效数据的正确性。Wherein, the terminal compresses the valid data to obtain the compressed data, and then encrypts the compressed data to obtain the encrypted data, which not only saves the storage space of the flash memory of the terminal, but also improves the security of the valid data. In addition, the terminal calculates the encrypted data based on the verification algorithm corresponding to the verification identifier to obtain the verification result, and stores the verification result in the target data header, so that the valid data can be verified at any time to determine the validity of the valid data. sex.
步骤S14、终端将数据包存储至待写入数据页中。Step S14, the terminal stores the data packet in the data page to be written.
在图3所示的实施例中,终端在根据数据头、有效数据和无效数据生成数据包的过程中,需要保证数据包的长度与待写入数据页的长度相同,从而使得数据包与数据页之间具有对应关系。在闪存的备份子区域的数据块内存入多个数据包以后,终端可以基于数据包与数据页之间的对应关系快速的读取出闪存的备份子区域的数据块内的每个数据包。因此,本申请实施例提供的方案可以使每个数据块在擦除一次后存储多个数据包,从而极大的提高了每个数据块的写入次数,进而满足在模拟EEPROM的过程中使用寿命上的要求。In the embodiment shown in Figure 3, in the process of generating a data packet according to the data header, valid data and invalid data, the terminal needs to ensure that the length of the data packet is the same as the length of the data page to be written, so that the data packet and the data There is a corresponding relationship between pages. After storing multiple data packets in the data block of the backup sub-area of the flash memory, the terminal can quickly read each data packet in the data block of the backup sub-area of the flash memory based on the correspondence between data packets and data pages. Therefore, the solution provided by the embodiment of the present application can enable each data block to store multiple data packets after being erased once, thereby greatly increasing the number of write times of each data block, and then satisfying the requirements for use in the process of simulating EEPROM. life expectancy requirements.
另外,在步骤S11以后,图3所示的实施例还可以包括以下步骤:终端获取有效数据的偏移地址;终端将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。其中,为了保证终端可以快速的读取到有效数据,终端会将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。In addition, after step S11, the embodiment shown in FIG. 3 may further include the following steps: the terminal obtains the offset address of the valid data; the terminal stores the valid data in the storage space corresponding to the offset address in the simulated storage area of the internal memory. Wherein, in order to ensure that the terminal can quickly read the valid data, the terminal will store the valid data in the storage space corresponding to the offset address in the simulated storage area of the memory.
请参见图4所示,图4所示的为本申请实施例提供的另一种数据存储方法的流程图。图4所示的方法可以应用于图1所示的终端内,图4所示的方法可以使终端在模拟EEPROM的过程中满足使用寿命上的要求。该方法包括以下步骤。Please refer to FIG. 4 , which is a flowchart of another data storage method provided by the embodiment of the present application. The method shown in FIG. 4 can be applied to the terminal shown in FIG. 1 , and the method shown in FIG. 4 can make the terminal meet the service life requirement in the process of simulating the EEPROM. The method includes the following steps.
步骤S21、终端接收待存储的有效数据。Step S21, the terminal receives valid data to be stored.
步骤S22、终端根据预设参数和有效数据配置数据头,数据头用于指示有效数据的属性。Step S22, the terminal configures the data header according to the preset parameters and the valid data, and the data header is used to indicate the attribute of the valid data.
步骤S23、终端根据数据头、有效数据和无效数据生成数据包。Step S23, the terminal generates a data packet according to the data header, valid data and invalid data.
步骤S24、终端将数据包存储至待写入数据页中。Step S24, the terminal stores the data packet in the data page to be written.
步骤S25、在终端初始化时,终端获取闪存的备份区域中每个数据块的数据页内存储的N个数据包。Step S25, when the terminal is initialized, the terminal acquires N data packets stored in the data page of each data block in the backup area of the flash memory.
其中,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,至少两个数据块中的每个数据块均包括至少两个数据页,N大于或等于1。终端初始化指的是在终端开机时的状态。Wherein, the backup area of the flash memory includes at least two backup sub-areas, each backup sub-area in the at least two backup sub-areas includes at least two data blocks, and each data block in the at least two data blocks includes at least two data pages, N greater than or equal to 1. Terminal initialization refers to the state when the terminal is turned on.
在终端关机时,存储至内存的模拟存储区域的有效数据会全部丢失,但是存储至闪存的备份子区域的数据块的数据页内的有效数据会被保存下来。在终端初始化时,为了保证终端可以快速的读取到有效数据,终端会将存储至闪存的备份区域的数据块的数据页内的数据包提取出来,并将提取出来的数据包的有效数据存储至内存的模拟存储区域内。When the terminal is turned off, all the valid data stored in the analog storage area of the memory will be lost, but the valid data stored in the data page of the data block in the backup sub-area of the flash memory will be preserved. When the terminal is initialized, in order to ensure that the terminal can quickly read valid data, the terminal will extract the data packets stored in the data page of the data block in the backup area of the flash memory, and store the effective data of the extracted data packets to the simulated storage area of memory.
步骤S26、终端将N个数据包的有效数据存储至内存的模拟存储区域内。Step S26, the terminal stores the valid data of the N data packets in the analog storage area of the internal memory.
在图4所示的实施例中,每个数据块在擦除一次后可以存储多个数据包,从而极大的提高了每个数据块的写入次数;而且,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,所以本申请实施例拥有更多的数据块用于存储数据包,即使存在某些数据块损坏也不会影响模拟EEPROM的过程,从而可以更好的满足在模拟EEPROM的过程中使用寿命上的要求。In the embodiment shown in Fig. 4, each data block can store a plurality of data packets after erasing once, thereby greatly improving the write times of each data block; and, the backup area of the flash memory includes at least two backup sub-areas, and each backup sub-area in at least two backup sub-areas includes at least two data blocks, so the embodiment of the present application has more data blocks for storing data packets, even if some data blocks are damaged It will not affect the process of simulating the EEPROM, so that the service life requirement in the process of simulating the EEPROM can be better met.
请参见图5所示,图5所示的为本申请实施例提供的基于图4的步骤S26细化的实施例的流程图。其中,图4的步骤S26中“终端将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤。Please refer to FIG. 5 , which is a flow chart of an embodiment refined based on step S26 in FIG. 4 provided by the embodiment of the present application. Wherein, "the terminal stores the valid data of N data packets in the analog storage area of the memory" in step S26 of FIG. 4 may also include the following steps.
步骤S31、终端在内存中申请临时存储区域。Step S31, the terminal applies for a temporary storage area in the internal memory.
步骤S32、终端将N个数据包存入内存的临时存储区域内。Step S32, the terminal stores the N data packets in the temporary storage area of the internal memory.
步骤S33、终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内。Step S33, the terminal stores the valid data of the N data packets in the temporary storage area of the internal memory in the analog storage area of the internal memory.
步骤S34、终端释放内存的临时存储区域。Step S34, the terminal releases the temporary storage area of the internal memory.
在图5所示的实施例中,为了快速的将闪存的备份区域中每个数据块的数据页内存储的N个数据包存储到内存的模拟存储区域内,需要一次性将闪存的备份区域中每个数据块的数据页内存储的N个数据包存储到内存的临时存储区域内,然后,再从内存的临时存储区域内将N个数据包内的有效数据存储到内存的模拟存储区域内,所以本申请实施例可以更加快速的将闪存内的N个数据包的有效数据存储至内存的模拟存储区域内。而且,内存的临时存储区域为临时在内存中申请的存储区域,在使用完临时存储区域以后,还需要释放内存的临时存储区域,从而节省终端的系统资源。In the embodiment shown in Figure 5, in order to quickly store the N data packets stored in the data page of each data block in the backup area of the flash memory into the simulated storage area of the memory, it is necessary to save the backup area of the flash memory at one time. Store the N data packets stored in the data page of each data block in the temporary storage area of the memory, and then store the valid data in the N data packets from the temporary storage area of the memory to the analog storage area of the memory Therefore, the embodiment of the present application can more quickly store the valid data of N data packets in the flash memory to the simulated storage area of the memory. Moreover, the temporary storage area of the internal memory is a storage area temporarily applied for in the internal memory. After the temporary storage area is used up, the temporary storage area of the internal memory needs to be released, thereby saving system resources of the terminal.
由于“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”的方式有很多种,下面简要介绍几种方式。Since there are many ways that "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory", several ways are briefly introduced below.
在一种可选择的方式中,“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤:In an optional manner, "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory" may also include the following steps:
步骤A1、终端在内存的临时存储区域内选择N个数据包内的目标数据包;Step A1, the terminal selects a target data packet in the N data packets in the temporary storage area of the memory;
步骤A2、终端提取目标数据包的目标数据;Step A2, the terminal extracts the target data of the target data packet;
步骤A3、终端提取目标数据包的数据头内的偏移地址;Step A3, the terminal extracts the offset address in the data header of the target data packet;
步骤A4、终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;Step A4, the terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
步骤A5、在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行步骤A2;Step A5, when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute step A2;
步骤A6、在目标数据包为N个数据包内的最后一个数据包时,继续执行步骤S34。Step A6. When the target data packet is the last data packet in the N data packets, continue to execute step S34.
其中,在终端将N个数据包存入内存的临时存储区域内以后,终端需要根据内存的临时存储区域内每个数据包的数据头的偏移地址,将每个数据包的目标数据存储到内存的模拟存储区域内。Wherein, after the terminal stores N data packets in the temporary storage area of the memory, the terminal needs to store the target data of each data packet in the within the simulated storage area of memory.
另外,步骤A1至步骤A6中提到的目标数据包指的是N个数据包内的一个数据包,目标数据包的目标数据指的是目标数据包内的有效数据。In addition, the target data packet mentioned in step A1 to step A6 refers to a data packet in N data packets, and the target data of the target data packet refers to valid data in the target data packet.
在一种可选择的方式中,“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤:In an optional manner, "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory" may also include the following steps:
步骤B1、终端在内存的临时存储区域内选择N个数据包内的目标数据包;Step B1, the terminal selects a target data packet in the N data packets in the temporary storage area of the memory;
步骤B2、终端提取目标数据包的目标数据;Step B2, the terminal extracts the target data of the target data packet;
步骤B3、终端提取目标数据包的数据头内的校验标识、第一校验结果和和偏移地址;Step B3, the terminal extracts the verification identifier, the first verification result and the offset address in the data header of the target data packet;
步骤B4、终端按照校验标识对应的校验算法对目标数据进行计算得到第二校验结果;Step B4, the terminal calculates the target data according to the verification algorithm corresponding to the verification identifier to obtain a second verification result;
步骤B5、在第一校验结果和第二校验结果相同时,终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;Step B5, when the first verification result is the same as the second verification result, the terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
步骤B6、在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行步骤B2;Step B6, when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute step B2;
步骤B7、在目标数据包为N个数据包内的最后一个数据包时,继续执行步骤S34。Step B7. When the target data packet is the last data packet in the N data packets, continue to execute step S34.
其中,为了验证目标数据包的目标数据是否在传输过程中出现错误,终端需要提取目标数据包的数据头内的校验标识和第一校验结果,然后,终端按照校验标识对应的校验算法对目标数据进行计算得到第二校验结果。如果第一校验结果和第二校验结果相同,说明目标数据在传输过程中未出现错误,此时便可以将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。如果第一校验结果和第二校验结果不同,说明目标数据在传输过程中出现错误,那么终端便不可以将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。Among them, in order to verify whether the target data of the target data packet has an error during transmission, the terminal needs to extract the verification identifier and the first verification result in the data header of the target data packet, and then, the terminal performs the verification according to the corresponding verification identifier. The algorithm calculates the target data to obtain the second verification result. If the first verification result is the same as the second verification result, it means that there is no error in the transmission process of the target data. At this time, the target data can be stored in the storage space corresponding to the offset address in the analog storage area of the memory. If the first verification result is different from the second verification result, it means that the target data has an error during transmission, and the terminal cannot store the target data in the storage space corresponding to the offset address in the analog storage area of the memory.
另外,步骤B1至步骤B7中提到的目标数据包指的是N个数据包内的一个数据包,目标数据包的目标数据指的是目标数据包内的有效数据。In addition, the target data packet mentioned in step B1 to step B7 refers to a data packet in the N data packets, and the target data of the target data packet refers to valid data in the target data packet.
在一种可选择的方式中,“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤:In an optional manner, "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory" may also include the following steps:
步骤C1、终端在内存的临时存储区域内选择N个数据包内的目标数据包;Step C1, the terminal selects a target data packet in the N data packets in the temporary storage area of the memory;
步骤C2、终端提取目标数据包的加密数据;Step C2, the terminal extracts the encrypted data of the target data packet;
步骤C3、终端提取目标数据包的数据头内的加密标识和偏移地址;Step C3, the terminal extracts the encryption identifier and offset address in the data header of the target data packet;
步骤C4、终端根据加密标识对应的加密算法对加密数据进行解密以得到目标数据;Step C4, the terminal decrypts the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the target data;
步骤C5、终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;Step C5, the terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
步骤C6、在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行步骤C2;Step C6, when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute step C2;
步骤C7、在目标数据包为N个数据包内的最后一个数据包时,继续执行步骤S34。Step C7, when the target data packet is the last data packet in the N data packets, continue to execute step S34.
其中,如果目标数据包的数据头内具有加密标识,说明目标数据包内存储的是将目标数据经过加密后得到的加密数据,所以需要终端根据加密标识对应的加密算法对加密数据进行解密以得到目标数据,并将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,从而保证了目标数据的安全性。Among them, if the data header of the target data packet has an encryption identifier, it means that the encrypted data obtained by encrypting the target data is stored in the target data packet, so the terminal needs to decrypt the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain target data, and store the target data in the storage space corresponding to the offset address in the analog storage area of the memory, thereby ensuring the security of the target data.
另外,步骤C1至步骤C7中提到的目标数据包指的是N个数据包内的一个数据包,目标数据指的是有效数据。In addition, the target data packet mentioned in step C1 to step C7 refers to one data packet in the N data packets, and the target data refers to valid data.
在一种可选择的方式中,“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤:In an optional manner, "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory" may also include the following steps:
步骤D1、终端在内存的临时存储区域内选择N个数据包内的目标数据包;Step D1, the terminal selects the target data packet in the N data packets in the temporary storage area of the memory;
步骤D2、终端提取目标数据包的压缩数据;Step D2, the terminal extracts the compressed data of the target data packet;
步骤D3、终端提取目标数据包的数据头内的压缩标识和偏移地址;Step D3, the terminal extracts the compression identifier and offset address in the data header of the target data packet;
步骤D4、终端根据压缩标识对应的压缩算法对压缩数据进行解压缩以得到目标数据;Step D4, the terminal decompresses the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data;
步骤D5、终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;Step D5, the terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
步骤D6、在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行步骤D2;Step D6, when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute step D2;
步骤D7、在目标数据包为N个数据包内的最后一个数据包时,继续执行步骤S34。Step D7, when the target data packet is the last data packet in the N data packets, continue to execute step S34.
其中,如果目标数据包的数据头内具有压缩标识,说明目标数据包内存储的是将目标数据经过压缩后得到的压缩数据,所以需要终端根据压缩标识对应的压缩算法对压缩数据进行解压缩以得到目标数据,并将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,从而节省了闪存的存储空间。Among them, if the data header of the target data packet has a compression identifier, it means that the compressed data stored in the target data packet is the compressed data obtained after compressing the target data, so the terminal needs to decompress the compressed data according to the compression algorithm corresponding to the compression identifier. The target data is obtained, and the target data is stored in the storage space corresponding to the offset address in the simulated storage area of the memory, thereby saving the storage space of the flash memory.
另外,步骤D1至步骤D7中提到的目标数据包指的是N个数据包内的一个数据包,目标数据指的是有效数据。In addition, the target data packet mentioned in step D1 to step D7 refers to one data packet in the N data packets, and the target data refers to valid data.
在一种可选择的方式中,“终端在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内”还可以包括以下步骤:In an optional manner, "the terminal stores the valid data of N data packets in the temporary storage area of the memory in the simulated storage area of the memory" may also include the following steps:
步骤E1、终端在内存的临时存储区域内选择N个数据包内的目标数据包;Step E1, the terminal selects a target data packet in the N data packets in the temporary storage area of the memory;
步骤E2、终端提取目标数据包的加密数据;Step E2, the terminal extracts the encrypted data of the target data packet;
步骤E3、终端提取目标数据包的数据头内的校验标识、第一校验结果、加密标识、压缩标识和偏移地址;Step E3, the terminal extracts the verification identifier, the first verification result, the encryption identifier, the compression identifier and the offset address in the data header of the target data packet;
步骤E4、终端按照校验标识对应的校验算法对加密数据进行计算得到第二校验结果;Step E4, the terminal calculates the encrypted data according to the verification algorithm corresponding to the verification identifier to obtain a second verification result;
步骤E5、在第一校验结果和第二校验结果相同时,终端根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据;Step E5, when the first verification result is the same as the second verification result, the terminal decrypts the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the compressed data;
步骤E6、终端根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据;Step E6, the terminal decrypts the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data;
步骤E7、终端将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;Step E7, the terminal stores the target data in the storage space corresponding to the offset address in the simulated storage area of the memory;
步骤E8、在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行步骤E2;Step E8, when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute step E2;
步骤E9、在目标数据包为N个数据包内的最后一个数据包时,继续执行步骤S34。Step E9, when the target data packet is the last data packet in the N data packets, continue to execute step S34.
其中,如果目标数据包的数据头内具有压缩标识、加密标识、校验标识和第一校验结果,说明目标数据包内存储的是将目标数据经过压缩后得到的压缩数据,并将压缩数据经过加密后得到的加密数据,而且,还可以验证目标数据包的加密数据是否在传输过程中出现错误。在终端提取目标数据包的加密数据以后,终端需要先验证第一校验结果和第二校验结果相同是否相同,如果是,说明目标数据在传输过程中未出现错误;然后,终端需要根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据,再根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据,最后将目标数据存储到内存的模拟存储区域内偏移地址对应的存储空间中,不仅节省了闪存的存储空间,而且提高了有效数据的安全性,另外,还可以验证目标数据包的加密数据是否在传输过程中出现错误。Wherein, if the data header of the target data packet has a compression identifier, an encryption identifier, a verification identifier, and a first verification result, it means that the target data packet stores compressed data obtained after compressing the target data, and the compressed data The encrypted data obtained after encryption can also verify whether an error occurs in the encrypted data of the target data packet during transmission. After the terminal extracts the encrypted data of the target data packet, the terminal needs to verify whether the first verification result is the same as the second verification result. If yes, it means that no error occurred in the target data during transmission; then, the terminal needs to The encryption algorithm corresponding to the logo decrypts the encrypted data to obtain the compressed data, and then decrypts the compressed data according to the compression algorithm corresponding to the compression logo to obtain the target data, and finally stores the target data in the analog storage area of the memory corresponding to the offset address In the storage space, not only the storage space of the flash memory is saved, but also the security of valid data is improved. In addition, it is also possible to verify whether the encrypted data of the target data packet has errors during transmission.
另外,步骤E1至步骤E9中提到的目标数据包指的是N个数据包内的一个数据包,目标数据指的是有效数据。In addition, the target data packet mentioned in step E1 to step E9 refers to one data packet in the N data packets, and the target data refers to valid data.
请参见图6所示,图6所示的为本申请实施例提供的一种数据存储装置的示意图。该数据传输装置包括以下模块:Please refer to FIG. 6 , which is a schematic diagram of a data storage device provided by an embodiment of the present application. The data transmission device includes the following modules:
接收模块11,用于接收待存储的有效数据;A receiving module 11, configured to receive valid data to be stored;
配置模块12,用于根据预设参数和有效数据配置数据头,数据头用于指示有效数据的属性;The configuration module 12 is configured to configure the data header according to preset parameters and valid data, and the data header is used to indicate the attributes of the valid data;
生成模块13,用于根据数据头、有效数据和无效数据生成数据包,无效数据用于填充数据包以使数据包的长度与待写入数据页的长度相同,待写入数据页为闪存的备份区域内数据块的数据页;Generating module 13, is used for generating data packet according to header, valid data and invalid data, and invalid data is used for filling data packet so that the length of data packet is identical with the length of data page to be written, and the data page to be written is flash memory Data pages of data blocks in the backup area;
存储模块14,用于将数据包存储至待写入数据页中。The storage module 14 is configured to store the data packet in the data page to be written.
可选的,生成模块13,具体用于根据数据头的长度、有效数据的长度和待写入数据页的长度计算待填充长度;终端按照待填充长度生成无效数据;终端将数据头、有效数据和无效数据组合成数据包。Optionally, the generation module 13 is specifically used to calculate the length to be filled according to the length of the data header, the length of the valid data, and the length of the data page to be written; the terminal generates invalid data according to the length to be filled; the terminal generates the data header, valid data and invalid data into a data packet.
可选的,生成模块13,具体用于获取数据头内的压缩标识、加密标识和校验标识;按照压缩标识对应的压缩算法对有效数据进行压缩得到压缩数据;按照加密标识对应的加密算法对压缩数据进行加密得到加密数据;按照校验标识对应的校验算法对加密数据进行计算得到校验结果;将校验结果写入数据头中以得到目标数据头;根据目标数据头的长度、加密数据的长度和待写入数据页的长度计算待填充长度;按照待填充长度生成无效数据;将目标数据头、加密数据和无效数据组合成数据包。Optionally, the generation module 13 is specifically used to obtain the compression identification, encryption identification and verification identification in the data header; compress the valid data according to the compression algorithm corresponding to the compression identification to obtain compressed data; according to the encryption algorithm corresponding to the encryption identification Encrypt the compressed data to obtain the encrypted data; calculate the encrypted data according to the verification algorithm corresponding to the verification identification to obtain the verification result; write the verification result into the data header to obtain the target data header; according to the length of the target data header, encrypt The length of the data and the length of the data page to be written calculate the length to be filled; generate invalid data according to the length to be filled; combine the target data header, encrypted data and invalid data into a data packet.
可选的,数据存储装置还可以包括:Optionally, the data storage device may also include:
第一获取模块,用于获取有效数据的偏移地址;The first obtaining module is used to obtain the offset address of the valid data;
第二存储模块,用于将有效数据存储至内存的模拟存储区域内偏移地址对应的存储空间中。The second storage module is used to store valid data in the storage space corresponding to the offset address in the simulated storage area of the internal memory.
可选的,数据存储装置还可以包括:Optionally, the data storage device may also include:
第二获取模块,用于在终端初始化时,获取闪存的备份区域中每个数据块的数据页内存储的N个数据包,闪存的备份区域包括至少两个备份子区域,至少两个备份子区域中的每个备份子区域均包括至少两个数据块,至少两个数据块中的每个数据块均包括至少两个数据页,N大于或等于1;The second obtaining module is used to obtain N data packets stored in the data page of each data block in the backup area of the flash memory when the terminal is initialized. The backup area of the flash memory includes at least two backup sub-areas, and at least two backup sub-areas Each backup sub-area in the area includes at least two data blocks, each of the at least two data blocks includes at least two data pages, and N is greater than or equal to 1;
第三存储模块,用于将N个数据包的有效数据存储至内存的模拟存储区域内。The third storage module is used to store the valid data of the N data packets in the analog storage area of the internal memory.
可选的,第三存储模块,具体用于在内存中申请临时存储区域;将N个数据包存入内存的临时存储区域内;在内存的临时存储区域内将N个数据包的有效数据存储至内存的模拟存储区域内;释放内存的临时存储区域。Optionally, the third storage module is specifically used to apply for a temporary storage area in the memory; store N data packets in the temporary storage area of the memory; store the effective data of the N data packets in the temporary storage area of the memory to the simulated storage area of memory; to release the temporary storage area of memory.
可选的,第三存储模块,具体用于在内存的临时存储区域内选择N个数据包内的目标数据包;提取目标数据包的加密数据;提取目标数据包的数据头内的校验标识、第一校验结果、加密标识、压缩标识和偏移地址;按照校验标识对应的校验算法对加密数据进行计算得到第二校验结果;在第一校验结果和第二校验结果相同时,根据加密标识对应的加密算法对加密数据进行解密以得到压缩数据;根据压缩标识对应的压缩算法对压缩数据进行解密以得到目标数据;将目标数据存储至内存的模拟存储区域内偏移地址对应的存储空间中;在目标数据包不为N个数据包内的最后一个数据包时,终端确定目标数据包的下一个数据包为目标数据包,继续执行终端提取目标数据包的目标数据;在目标数据包为N个数据包内的最后一个数据包时,继续执行终端释放内存的临时存储区域。Optionally, the third storage module is specifically used to select the target data packet in the N data packets in the temporary storage area of the memory; extract the encrypted data of the target data packet; extract the check mark in the data header of the target data packet , the first verification result, the encrypted identification, the compression identification and the offset address; the encrypted data is calculated according to the verification algorithm corresponding to the verification identification to obtain the second verification result; the first verification result and the second verification result At the same time, decrypt the encrypted data according to the encryption algorithm corresponding to the encryption identifier to obtain the compressed data; decrypt the compressed data according to the compression algorithm corresponding to the compression identifier to obtain the target data; store the target data to the offset in the simulated storage area of the memory In the storage space corresponding to the address; when the target data packet is not the last data packet in the N data packets, the terminal determines that the next data packet of the target data packet is the target data packet, and continues to execute the terminal to extract the target data of the target data packet ; When the target data packet is the last data packet in the N data packets, continue to execute the terminal to release the temporary storage area of the memory.
图7所示的为本申请实施例提供的另一种数据存储装置的示意图。参照图7,该装置包括处理器21、存储器22和收发器23,其中,处理器21、存储器22和收发器23通过内部连接通路互相通信,存储器22用于存储指令,处理器21用于执行存储器22存储的指令,以控制收发器23接收信号,并控制收发器23发送信号,并且当处理器21执行该存储器22存储的指令时,该装置使得该处理器21执行上述图3、图4和图5所示的方法。FIG. 7 is a schematic diagram of another data storage device provided by the embodiment of the present application. 7, the device includes a processor 21, a memory 22 and a transceiver 23, wherein the processor 21, the memory 22 and the transceiver 23 communicate with each other through an internal connection path, the memory 22 is used for storing instructions, and the processor 21 is used for executing The instructions stored in the memory 22 are used to control the transceiver 23 to receive signals and to control the transceiver 23 to send signals, and when the processor 21 executes the instructions stored in the memory 22, the device causes the processor 21 to execute the above-mentioned FIG. 3 and FIG. 4 and the method shown in Figure 5.
本申请实施例提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述图3、图4和图5所示的方法。An embodiment of the present application provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, it causes the computer to execute the methods shown in FIG. 3 , FIG. 4 and FIG. 5 .
本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述图3、图4和图5所示的方法。An embodiment of the present application provides a computer program product including instructions, which, when run on a computer, cause the computer to execute the methods shown in FIG. 3 , FIG. 4 and FIG. 5 .
本申请实施例提供了一种芯片,所述芯片包括处理器和/或程序指令,当所述芯片运行时,实现上述图3、图4和图5所示的方法。An embodiment of the present application provides a chip, the chip includes a processor and/or program instructions, and when the chip is running, implements the above methods shown in FIG. 3 , FIG. 4 and FIG. 5 .
另外,本申请实施例提到的闪存具体可以为Nand Flash(与非闪存)、Nor Flash(或非闪存)或EMMC(Embedded Multi Media Card,嵌入式多媒体卡)等存储介质。当然,在本申请实施例中,终端内的闪存仅是一种实现方式,还可以采用其他的存储介质来替代,例如,可以采用SSD(Solid State Drives,固态硬盘)或HDD(Hard Disk Drive,硬盘驱动器)等存储介质来替代闪存。In addition, the flash memory mentioned in the embodiment of the present application may specifically be storage media such as Nand Flash (and non-flash memory), Nor Flash (or non-flash memory), or EMMC (Embedded Multi Media Card, embedded multimedia card). Of course, in the embodiment of the present application, the flash memory in the terminal is only an implementation, and other storage media can also be used instead, for example, SSD (Solid State Drives, solid state disk) or HDD (Hard Disk Drive, Hard disk drive) and other storage media instead of flash memory.
因此,本申请实施例使用的存储介质包括但不限于Nand Flash、Nor Flash、EMMC、SSD和HDD等,还可以采用其他类型的存储介质。Therefore, the storage medium used in the embodiment of the present application includes but is not limited to Nand Flash, Nor Flash, EMMC, SSD, HDD, etc., and other types of storage media can also be used.
需要说明的是,本申请提供实施例只是本申请所介绍的可选实施例,本领域技术人员在此基础上,完全可以设计出更多的实施例,因此不再此处赘述。It should be noted that the embodiments provided in the present application are only optional embodiments introduced in the present application, and those skilled in the art can design more embodiments on this basis, so details are not repeated here.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art can appreciate that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。A unit described as a separate component may or may not be physically separated, and a component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-OnlyMemory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the functions are realized in the form of software functional units 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 is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) execute all or part of the steps of the methods in various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, and other media that can store program codes.
以上,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。The above is only the specific implementation of the application, but the scope of protection of the application is not limited thereto. Anyone familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the application, and should cover Within the protection scope of this application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims (13)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810084375.9A CN110096451B (en) | 2018-01-29 | 2018-01-29 | Data storage method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810084375.9A CN110096451B (en) | 2018-01-29 | 2018-01-29 | Data storage method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110096451A CN110096451A (en) | 2019-08-06 |
CN110096451B true CN110096451B (en) | 2023-08-04 |
Family
ID=67442773
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810084375.9A Active CN110096451B (en) | 2018-01-29 | 2018-01-29 | Data storage method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110096451B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110888605B (en) * | 2019-12-11 | 2023-10-20 | 重庆超力高科技股份有限公司 | EEPROM data writing method and device and electronic equipment |
CN111176579B (en) * | 2019-12-30 | 2023-05-30 | 航天信息股份有限公司 | Method for simulating eporom by using norflash |
CN111241005A (en) * | 2020-01-09 | 2020-06-05 | 杭州涂鸦信息技术有限公司 | Key value pair-based safe partition storage method and system |
CN111367496B (en) * | 2020-02-26 | 2022-05-17 | 杭州涂鸦信息技术有限公司 | Method and system for rapidly storing and reading self-generating switch flash memory |
CN113490112B (en) * | 2021-07-02 | 2022-11-25 | 歌尔科技有限公司 | Wireless earphone, data processing method of wireless earphone and storage medium |
CN113595557B (en) * | 2021-09-30 | 2021-12-28 | 阿里云计算有限公司 | Data processing method and device |
CN115309323A (en) * | 2022-07-07 | 2022-11-08 | 东软睿驰汽车技术(沈阳)有限公司 | Data storage method, device, device and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101622594A (en) * | 2006-12-06 | 2010-01-06 | 弗森多系统公司(dba弗森-艾奥) | Apparatus, system, and method for managing data from a requesting device using null data token directives |
EP2755132A1 (en) * | 2011-10-12 | 2014-07-16 | Huawei Technologies Co., Ltd. | Virtual machine memory snapshot generating and recovering method, device and system |
CN105808151A (en) * | 2014-12-29 | 2016-07-27 | 华为技术有限公司 | Solid-state disk storage device and data access method of solid-state disk storage device |
CN106816175A (en) * | 2015-12-01 | 2017-06-09 | 中芯国际集成电路制造(上海)有限公司 | The control method and device of memory |
-
2018
- 2018-01-29 CN CN201810084375.9A patent/CN110096451B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101622594A (en) * | 2006-12-06 | 2010-01-06 | 弗森多系统公司(dba弗森-艾奥) | Apparatus, system, and method for managing data from a requesting device using null data token directives |
EP2755132A1 (en) * | 2011-10-12 | 2014-07-16 | Huawei Technologies Co., Ltd. | Virtual machine memory snapshot generating and recovering method, device and system |
CN105808151A (en) * | 2014-12-29 | 2016-07-27 | 华为技术有限公司 | Solid-state disk storage device and data access method of solid-state disk storage device |
CN106816175A (en) * | 2015-12-01 | 2017-06-09 | 中芯国际集成电路制造(上海)有限公司 | The control method and device of memory |
Also Published As
Publication number | Publication date |
---|---|
CN110096451A (en) | 2019-08-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110096451B (en) | Data storage method and device | |
CN105808151B (en) | Solid-state hard disk storage device and data access method for solid-state hard disk storage device | |
US11301175B2 (en) | Method for controlling storage device | |
US9811678B2 (en) | Method and system for transferring data and instructions through a host file system | |
TWI516921B (en) | Data processing method, memory storage device and memory controlling circuit unit | |
US8909900B2 (en) | Storage device and method for updating data in a partition of the storage device | |
US8135903B1 (en) | Non-volatile semiconductor memory compressing data to improve performance | |
KR101457451B1 (en) | Encrypted transport solidstate disk controller | |
US8560926B2 (en) | Data writing method, memory controller and memory storage apparatus | |
TWI459396B (en) | Data writing and reading method, memory controller and memory storage apparatus | |
JP7458763B2 (en) | Flash translation layer with layered security | |
CN110022558B (en) | Method for encrypting and decrypting upgrade package, electronic device and storage medium | |
TWI733375B (en) | Data transfer method and memory storage device | |
US10353584B2 (en) | Data storage device and method for rewriting parameters thereof | |
CN104881240A (en) | Data writing method, memory storage device and memory control circuit unit | |
TW201618112A (en) | Data access method, memoey control circuit unit and memory storage apparatus | |
CN104573537B (en) | Data processing method, memory storage device and memory control circuit unit | |
CN105653391B (en) | Data access method, memory control circuit unit and memory storage device | |
CN102591737B (en) | Data writing and reading method, memory controller and memory storage device | |
TWI546667B (en) | Method for managing memory card, memory storage device and memory control circuit unit | |
TWI541809B (en) | Data accessing method, memory controlling circuit unit and memory storage apparatus | |
CN106155564B (en) | Storage device management method and system and storage device thereof | |
CN114003431B (en) | Non-4 k aligned Trim data verification method, system and device for Nvme solid state disk | |
US10754548B2 (en) | Data storage device and method for rewriting parameters thereof | |
JP4892901B2 (en) | IC card and IC card program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |