Data reading and writing method, device, equipment and medium
By paging the Flash memory and combining it with the security strategy of electrically erasable programmable read-only memory, the shortcomings of EEPROM and Flash storage units are solved, efficient data read and write operations are achieved, costs are reduced and device life is extended.
Patent Information
- Application Number
- CN202510991577.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2045-07-18
AI Technical Summary
In the prior art, EEPROM as a configuration information storage unit has the problems of high price, small storage space, and slow read and write speed; when Flash is used as a storage unit, the erase efficiency is low, the device life is short, and it needs to be operated in block units, which has low utilization.
By dividing the Flash memory into blocks, generating different types of pages, and using electrically erasable programmable read-only memory to store basic configuration information, combined with preset security policies, and simulating EEPROM data read and write operations, efficient use of Flash is achieved.
It meets the needs of repeated erasing and writing of small-scale configuration information, while supporting the reading and writing of large-scale configuration files, reducing product prices and improving the competitiveness of equipment and data security.
Smart Images

Figure CN120508261B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data reading and writing method, device, equipment and medium. Background Art
[0002] Device configuration information refers to user-defined settings for the device system, which are used to define the operating conditions of embedded devices. Device configuration information must support user modification based on usage scenarios, persistent storage, power-off saving, real-time validation, and user readability. Based on these requirements, device configuration information storage must support fast erase and write, efficient readout, and power-off preservation.
[0003] Currently, in embedded systems, device configuration information is primarily stored in EEPROM (Electrically Erasable Programmable Read-Only Memory) and Flash memory. Built-in or external EEPROMs have limited storage space for configuration information, low erase and write efficiency, and are expensive, limiting the expansion of configuration storage. Flash storage is also an alternative. While inexpensive, offers fast read and write speeds, and a large storage capacity, its block erase feature prevents individual byte erases and writes during use, effectively limiting Flash storage space utilization and potentially leading to wasted erases and writes, shortening Flash's lifespan. Summary of the Invention
[0004] The present application provides a data reading and writing method, apparatus, device and medium to at least solve the problems in the related art of using EEPROM as a configuration information storage unit, such as high component prices, small storage space and slow reading and writing speeds; and the problems of low device erasure efficiency, short device life and low utilization rate when using Flash as a storage unit, such as the need to operate the device in block units.
[0005] In a first aspect, the present application provides a data reading and writing method, comprising:
[0006] Determining a target block in the flash memory and dividing the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information;
[0007] Storing basic configuration storage information corresponding to different pages in an electrically erasable programmable read-only memory, and determining an actual storage address of the configuration information in a flash memory based on the updated basic configuration storage information stored in the electrically erasable programmable read-only memory;
[0008] Based on a preset security policy, the actual storage address and basic configuration storage information in the electrically erasable programmable read-only memory are used to determine the result of data reading and writing operations in the flash memory.
[0009] The present application also provides a data reading and writing device, comprising:
[0010] A flash memory paging module is used to determine a target block in the flash memory and divide the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information;
[0011] an emulation management module, configured to store basic configuration storage information corresponding to different pages in an electrically erasable programmable read-only memory, and determine an actual storage address of the configuration information in the flash memory based on the updated basic configuration storage information stored in the electrically erasable programmable read-only memory;
[0012] The data read and write module is used to determine the results of data read and write operations in the flash memory based on a preset security policy, using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory to simulate data reading and writing in the electrically erasable programmable read-only memory.
[0013] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned data reading and writing methods when executing the computer program.
[0014] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned data reading and writing methods are implemented.
[0015] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned data reading and writing methods when executed by a processor.
[0016] Beneficial effects: Based on the characteristics of Flash, the storage area of Flash is divided into blocks to plan the storage units of configuration information. After the Flash is divided into different pages, only the basic configuration storage information corresponding to the key pages is stored in the small-capacity on-chip EEPROM. Furthermore, the actual storage address in the Flash is calculated using the basic configuration storage information, and data is read and written in the Flash according to the actual storage address to implement EEPROM-like simulation operations. It not only meets the needs of repeated erasing and writing of small-scale configuration information, but also supports the reading and writing of large-scale configuration files. In addition, Flash is fast to read and write and inexpensive. On the basis of ensuring data security and enriching device functions, it effectively reduces the price of the product and improves the competitiveness of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0018] Figure 1 A flow chart of a data reading and writing method disclosed in this application;
[0019] Figure 2 A block paging diagram disclosed in this application;
[0020] Figure 3 This is a schematic diagram of a dynamic adjustment strategy for configuration items disclosed in this application;
[0021] Figure 4 This is a structural diagram of a data reading and writing device disclosed in this application. DETAILED DESCRIPTION
[0022] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0023] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0024] Currently, configuration information is primarily stored in EEPROM and Flash. Flash is further divided into NOR Flash (NotOR Flash Memory, or non-logic gate array structure flash memory) and NAND Flash (Not AND Flash Memory, and non-logic gate array structure flash memory). The following is a comparison of EEPROM and Flash storage:
[0025] Table 1 compares the physical structure and erase / write mechanism between EEPROM and Flash:
[0026] Table 1 Comparison of physical structure and erase / write mechanism
[0027]
[0028] Table 2 shows the performance comparison between EEPROM and Flash:
[0029] Table 2 Performance comparison
[0030]
[0031] Table 3 compares the application scenarios between EEPROM and Flash:
[0032] Table 3 Comparison of application scenarios
[0033]
[0034] 1. Using EEPROM as a configuration information storage unit has the following disadvantages: expensive components, small storage space, and slow read and write speed;
[0035] 2. Using Flash as a configuration information storage unit has the following disadvantages: low device erasure efficiency, short device life, the device needs to be operated in block units, and low utilization.
[0036] To this end, this application provides a data reading and writing solution that can not only meet the needs of repeatedly erasing and writing small-scale configuration information, but also support the reading and writing of large-scale configuration files. In order to enable those skilled in the art to better understand the application solution, the application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0037] In conjunction with the specific application environment architecture or specific hardware architecture on which the execution of the data reading and writing method depends, the specific application environment architecture or specific hardware architecture is described here.
[0038] The embodiment of the present application provides a data reading and writing method. Figure 1 As shown, the method is described in detail, and the method includes:
[0039] Step S11: determining a target block in the flash memory, and dividing the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information.
[0040] In the embodiment of the present application, based on the characteristics of Flash, the Flash storage area is divided into blocks to plan the storage units of configuration information. Specifically, the physical blocks in the Flash are further subdivided into several logical pages, and the paging granularity can be dynamically adjusted according to the size of the configuration information, such as 32k, 64k, etc.
[0041] Before flash memory paging is performed, the basic logic is to first group the blocks in the Flash memory and then perform paging operations on the target blocks in each group. Specifically, based on the number of blocks in the Flash memory, the multiple blocks in the Flash memory are divided into multiple groups; each group contains at least two blocks. For example, assume that the Flash memory has seven individually erasable blocks, A1-A7, each 512KB in size. Now, A1-A2, A3-A4, and A5-A7 are combined and divided into three groups. Then, paging operations are performed on each group. Furthermore, the target group in the Flash memory is determined, and the target block is determined within the target group.
[0042] In an embodiment of the present application, paging refers to the division of a block. When performing area division, paging rules are preset, including: one paging stores one type of configuration information, and one type of configuration information stores one associated configuration item; the paging addresses of the pages corresponding to the same type of configuration information in the target block are continuous, and the paging sizes corresponding to the same type of configuration information are the same.
[0043] For example, assuming that the A1-A2 group only stores three types of paging classes: Type-A, Type-B, and Type-C, the 512k consecutive storage addresses of block A1 can be divided as follows:
[0044] [0~32,Page1,Type-A], [32~64,Page2,Type-A], [64~96,Page3,Type-A], [96~128,Page4,Type-A];
[0045] [128~192,Page5,Type-B], [192~256,Page6,Type-B];
[0046] [256~384,Page7,Type-C], [384~512,Page8,Type-C];
[0047] Among them, a page stores one type of configuration information, for example, Page1 stores Type-A, and Page5 stores Type-B. One type of configuration information stores one associated configuration item, that is, the same type of page stores one configuration information, such as Figure 2 As shown in the figure, Type-A stores configuration 1, and Type-B stores configuration 2. Configuration pages of the same type have consecutive addresses and the same page size. For example, Page 1 to Page 4 are all Type-A, and the page size is 32k.
[0048] It should be pointed out that the page division of blocks in the same group is consistent, that is, the paging settings of block A1 and block A2 are consistent, but the configuration items associated with the pages may be inconsistent. For example, in block A2, Type-A can store configuration 2. Specifically, based on the preset paging rules, other blocks in the same group as the target block are divided into the same area as the target block; when the page corresponding to the configuration information of the target type in the target block is full, it switches to other blocks to continue writing data. The two blocks 1 and 2 serve as each other's configuration pages respectively. After they are full, they switch to store configuration information. When block A1 has a full write operation for configuration item 1, the write operation of configuration 1 will be switched to block A2.
[0049] Step S12: storing basic configuration storage information corresponding to different pages in the EEPROM, and determining the actual storage address of the configuration information in the flash memory based on the updated basic configuration storage information stored in the EEPROM.
[0050] In the embodiment of the present application, a collaborative architecture with Flash as the main storage and on-chip EEPROM as the auxiliary configuration is used, combined with simulation management at the software layer, to replace the EEPROM function and avoid the defects of both, realize simulation management, and achieve the same effect as EEPROM memory.
[0051] Write the paged basic configuration storage information to the EEPROM, then read the stored basic configuration storage information from the EEPROM and determine the actual storage address of the configuration information in the Flash memory based on the read information. The basic configuration storage information includes [block identifier, page address, page identifier, page type, offset, data length, checksum, and write count]. Based on this basic configuration storage information in the EEPROM, the actual storage address of the configuration information in the Flash memory can be calculated.
[0052] It should be noted that after calculating the actual storage address of the indicator in Flash using the above parameters, the indicator data can be quickly read through the SPI (Serial Peripheral Interface). The data CRC (Cyclic Redundancy Check) value is then calculated and compared with the CRC check value in the EEPROM to ensure data integrity.
[0053] Specifically, the actual storage address is sent to the flash memory using a preset communication interface, so that the flash memory determines a second verification value based on the actual storage address; the second verification value is compared with the verification value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison result is consistent, a step is triggered to determine the result of the data reading and writing operation in the flash memory based on the preset security policy using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory.
[0054] Step S13: Based on the preset security policy, the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory are used to determine the result of the data reading and writing operation in the flash memory.
[0055] In a specific embodiment, the preset security policy includes a write security policy. When data is written, the write address in the Flash is calculated using the actual storage address of the calculated indicator and the data length of the basic configuration storage information stored in the EEPROM. It is then determined whether data exists at the write address. If data exists, it indicates that there was an abnormality in the previous operation, such as dirty data or the data information in the EEPROM was not updated in a timely manner during the previous write. The user is then prompted that an abnormal write operation occurred and the write address is recalculated. In this way, by calculating the configuration information write address through paging information, and writing to the Flash in a loop, continuous utilization of the Flash storage is achieved.
[0056] In another specific embodiment, the preset security policy includes a read security policy. Specifically, based on the preset read security policy, a read address for reading data from the flash memory is determined using the actual storage address and basic configuration storage information in the electrically erasable programmable read-only memory; corresponding target configuration information is obtained from the flash memory based on the read address, and a third check value is determined based on the target configuration information; the third check value is compared with the check value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison results are inconsistent, an operation result indicating that the target configuration information is damaged is returned.
[0057] When reading data, the read address is calculated first, and then the configuration information is read from the Flash according to the address, its CRC check value is calculated, and compared with the CRC check value in the EEPROM. If they are inconsistent, it means that the configuration information is damaged and the user is prompted.
[0058] Beneficial effects: Based on the characteristics of Flash, the storage area of Flash is divided into blocks to plan the storage units of configuration information. After the Flash is divided into different pages, only the basic configuration storage information corresponding to the key pages is stored in the small-capacity on-chip EEPROM. Furthermore, the actual storage address in the Flash is calculated using the basic configuration storage information, and data is read and written in the Flash according to the actual storage address to implement EEPROM-like simulation operations. It not only meets the needs of repeated erasing and writing of small-scale configuration information, but also supports the reading and writing of large-scale configuration files. In addition, Flash is fast to read and write and inexpensive. On the basis of ensuring data security and enriching device functions, it effectively reduces the price of the product and improves the competitiveness of the product.
[0059] Based on the above embodiment, this embodiment performs analog management, and specifically describes the use of software management methods for Flash memory to achieve the same effect as EEPROM memory. Its basic implementation is based on the division of Flash and the classification and planning of configuration information. First, after paging the Flash, its corresponding basic configuration storage information is determined, and then the basic configuration storage information of the page is written into the built-in EEPROM. Among them, the basic configuration storage information includes: block identifier, paging address, paging identifier, paging type, offset, data length, check value, and write count;
[0060] When calculating the actual storage address of the configuration information in the Flash based on the basic configuration storage information stored in the EEPROM, the calculation method is as follows:
[0061] The actual storage address of the configuration information in the flash memory is determined based on the paging address, paging identifier, paging type, and offset stored in the electrically erasable programmable read-only memory after the update.
[0062] ;
[0063] in, The actual storage address of the current indicator in Flash; is the paging address, The paging position of the current indicator in Flash, corresponding to the paging mark; The paging type corresponding to the current indicator; The offset of the current indicator in the page it belongs to.
[0064] Furthermore, after calculating the actual storage address of the configuration information in the flash memory, a data write process is simulated. Specifically, based on a preset write security policy, the write address for writing data in the flash memory is determined using the actual storage address and the data length of the basic configuration storage information in the electrically erasable programmable read-only memory.
[0065] In the embodiment of the present application, before writing, the write address is calculated as follows:
[0066] ;
[0067] in, The data length.
[0068] Based on the above embodiments, it can be seen that data writing is based on a write security policy, that is, when data is written, the write address is first calculated, and then it is determined whether there is data at the write address. Specifically, the data writing process includes the following steps:
[0069] Determine whether there is data at the write address;
[0070] If there is data under the write address, the operation result indicating a write operation exception is returned;
[0071] If there is no data under the write address, determine whether the write address is an even number;
[0072] If the write address is an even number of bits, the data is directly written to the flash memory to obtain a corresponding write result, and a first check value corresponding to the write result is determined. Then, based on the write result and the first check value, the data length, the check value, and the write count in the basic configuration storage information in the electrically erasable programmable read-only memory are synchronously updated;
[0073] If the write address is an odd number of bits, the write address is shifted backward by one byte and then a step of writing data to the flash memory is triggered to obtain a corresponding write result.
[0074] In the embodiment of the present application, the embedded system needs to write an even number of bits to the Flash address. Therefore, if If the write address is an odd number, the write address is offset backward by 1 byte, and then the data is written. After the write is completed, the CRC check value is calculated, and the write result is updated to the EEPROM configuration and the data length, CRC check value, and number of writes are updated synchronously. It can be understood that when the write address is offset backward by 1 byte, if paged writing is involved, the page page also needs to be offset backward by 1 page, and then the data is written. After the write is completed, the CRC check value is calculated, and the write result is updated to the EEPROM configuration and the data length, CRC check value, and number of writes are updated synchronously.
[0075] Based on the above embodiment, in a feasible implementation, in order to implement the rollback of configuration information through the cyclic writing and deletion switching of Flash, the preset security policy in the embodiment of the present application also includes a preset rollback policy. Specifically, it can also include the following steps:
[0076] Determine the configuration record corresponding to the configuration information when a data read or write exception occurs, and perform configuration rollback based on the configuration record.
[0077] In this embodiment, when a data read / write exception occurs, the user can query the historical configuration information based on the default base Flash address saved in the EEPROM, prompt the customer with all configuration records of the configuration information in the EEPROM, and perform a configuration item rollback strategy based on the customer's operation.
[0078] In another feasible implementation, the write pressure is balanced by dynamically optimizing the paging method (type, number, combination, etc.) of the configuration information in the Flash, thereby minimizing the number of Flash erase and write cycles and extending the device life. In the embodiment of the present application, the preset security policy also includes a preset dynamic adjustment policy. Specifically, the following steps may also be included:
[0079] When the pages corresponding to the configuration information of the target type in the target block are full, the write count corresponding to the configuration information of the target type is counted. If the write count is greater than a preset threshold, the configuration information of the target type is copied to the backup block corresponding to the target block, and the target block is re-divided into regions to dynamically adjust the paging structure of the pages, and initialize the basic configuration storage information stored in the electrically erasable programmable read-only memory according to the current paging structure.
[0080] In the embodiment of the present application, the dynamic adjustment strategy is not executed at any time, but is triggered in a specific scenario. The dynamic strategy refers to the dynamic adjustment of the paging type and paging combination of the configuration information during the Flash block simulation process. Figure 3 As shown in the figure, assuming that during device operation, when a certain configuration information in a data page is full, the system will count the write count of the block and then adjust the configuration information paging status based on the configuration information write count.
[0081] The dynamic adjustment strategy follows the block erase minimization strategy. That is, when a certain indicator in a certain data page is full and a sector needs to be switched, the block information is calculated. If the count value is greater than the set value, the dynamic adjustment strategy is implemented. The calculation method is as follows:
[0082] ;
[0083] The meaning of this formula is: The cumulative number of writes to type-a pages in the current block. The average cumulative number of writes to type-a pages in the first n blocks (e.g., the first two blocks). The difference between the two indicates whether the write pressure on type-a pages in the current block is higher than the historical average. The sum of these differences is calculated for all page types, and the maximum value is used as count. A larger count indicates that a certain type of page in the current block is written much more frequently than other blocks / pages, posing a risk of localized overwrites and requiring load balancing by adjusting the paging method.
[0084] To avoid data loss during the adjustment process, first copy all valid configuration information in the current block to the backup sector, then initialize the configuration information in the EEPROM, adjust it, and update it; finally, based on the adjusted EEPROM configuration, re-divide the pages in the Flash to meet the paging rules. After the adjustment is completed, restore the read-write mapping.
[0085] It can be seen that the dynamic adjustment strategy calculates the write of the configuration item during the block switching process by using the write count and combining it with the block information of the configuration item. It dynamically adjusts the default write address of the Flash page where the configuration item is located, thereby achieving effective utilization of the Flash block. When using Flash to simulate EEPROM, it maintains efficient reading and writing while minimizing the number of Flash erase and write cycles, reducing the load generated by the system during the block erase and write process, and improving the service life of the device storage.
[0086] In a feasible implementation, an intelligent predictive adjustment strategy can be further implemented based on a dynamic adjustment strategy. For example, based on historical write count data, a machine learning algorithm is introduced to predict the configuration information writing trend in advance. The paging combination and storage location are actively adjusted before the page is full to reduce the performance loss caused by real-time adjustment and achieve preventive wear leveling. At the same time, encryption keys can be dynamically generated in combination with paging adjustments, and the keys are stored in the on-chip EEPROM. The encryption algorithm and key are updated every time the paging is adjusted to ensure the security of the configuration information storage and prevent the data from being maliciously tampered with or read. In addition, new storage media can also be introduced in the future as a supplement to store key configurations that are written frequently in a more durable medium, and Flash only stores low-frequency data, giving full play to the advantages of different storage technologies.
[0087] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0088] The embodiment of the present application also provides a data reading and writing device, see Figure 4 As shown, the device includes:
[0089] The flash memory paging module 11 is used to determine a target block in the flash memory and divide the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information;
[0090] The simulation management module 12 is used to store basic configuration storage information corresponding to different pages in the electrically erasable programmable read-only memory, and determine the actual storage address of the configuration information in the flash memory based on the basic configuration storage information stored in the electrically erasable programmable read-only memory after update;
[0091] The data reading and writing module 13 is used to determine the operation results of data reading and writing in the flash memory based on the preset security policy using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory to simulate the data reading and writing of the electrically erasable programmable read-only memory.
[0092] For the description of the features in the embodiment corresponding to the data reading and writing device, reference can be made to the relevant description of the embodiment corresponding to the data reading and writing method, which will not be repeated here.
[0093] Beneficial effects: Based on the characteristics of Flash, the storage area of Flash is divided into blocks to plan the storage units of configuration information. After the Flash is divided into different pages, only the basic configuration storage information corresponding to the key pages is stored in the small-capacity on-chip EEPROM. Furthermore, the actual storage address in the Flash is calculated using the basic configuration storage information, and data is read and written in the Flash according to the actual storage address to implement EEPROM-like simulation operations. It not only meets the needs of repeated erasing and writing of small-scale configuration information, but also supports the reading and writing of large-scale configuration files. In addition, Flash is fast to read and write and inexpensive. On the basis of ensuring data security and enriching device functions, it effectively reduces the price of the product and improves the competitiveness of the product.
[0094] In a specific embodiment, the data reading and writing device further includes:
[0095] The grouping module is used to divide the multiple blocks in the flash memory into multiple groups according to the number of blocks in the flash memory; wherein each group contains at least two blocks.
[0096] The rollback module is used to determine the configuration record corresponding to the configuration information when a data read or write abnormal event occurs based on a preset rollback strategy, and perform configuration rollback according to the configuration record.
[0097] The dynamic adjustment module is used to count the write counts corresponding to the target type configuration information based on a preset dynamic adjustment strategy. When the page corresponding to the target type configuration information in the target block is full, if the write count is greater than a preset threshold, the target type configuration information is copied to the backup block corresponding to the target block, and the target block is re-divided into regions to dynamically adjust the paging structure of the paging and initialize the basic configuration storage information stored in the electrically erasable programmable read-only memory according to the current paging structure.
[0098] A verification module is used to use a preset communication interface to send the actual storage address to the flash memory so that the flash memory determines a second verification value based on the actual storage address; compare the second verification value with the verification value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison results are consistent, trigger a step of determining the result of the data reading and writing operation in the flash memory based on the preset security policy using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory.
[0099] In a specific embodiment, the simulation management module 12 is specifically configured to:
[0100] The actual storage address of the configuration information in the flash memory is determined based on the paging address, paging identifier, paging type, and offset stored in the electrically erasable programmable read-only memory after the update.
[0101] In a specific embodiment, the data reading and writing module 13 includes a writing module for:
[0102] Based on a preset write security policy, determining a write address for writing data in the flash memory using an actual storage address and a data length in basic configuration storage information in the electrically erasable programmable read-only memory;
[0103] Determine whether there is data at the write address;
[0104] If there is data under the write address, the operation result indicating a write operation exception is returned;
[0105] If there is no data under the write address, determine whether the write address is an even number;
[0106] If the write address is an even number of bits, the data is directly written to the flash memory to obtain a corresponding write result, and a first check value corresponding to the write result is determined. Then, based on the write result and the first check value, the data length, the check value, and the write count in the basic configuration storage information in the electrically erasable programmable read-only memory are synchronously updated;
[0107] If the write address is an odd number of bits, the write address is shifted backward by one byte and then a step of writing data to the flash memory is triggered to obtain a corresponding write result.
[0108] In a specific embodiment, the data reading and writing module 13 includes a reading module configured to:
[0109] Based on a preset read security policy, a read address for reading data in the flash memory is determined using an actual storage address and basic configuration storage information in the electrically erasable programmable read-only memory;
[0110] Obtaining corresponding target configuration information from the flash memory according to the read address, and determining a third check value according to the target configuration information;
[0111] The third check value is compared with the check value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison results are inconsistent, an operation result indicating that the target configuration information is damaged is returned.
[0112] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned data reading and writing method embodiments.
[0113] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above-mentioned data reading and writing method embodiments when running.
[0114] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0115] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any of the above-mentioned data reading and writing method embodiments are implemented.
[0116] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned data reading and writing method embodiments.
[0117] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0118] The above is a detailed introduction to a data reading and writing method, device, equipment and medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A data reading and writing method, characterized in that: include: Determining a target block in the flash memory and dividing the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information; Storing basic configuration storage information corresponding to different pages in an electrically erasable programmable read-only memory, and determining an actual storage address of the configuration information in the flash memory based on the updated basic configuration storage information stored in the electrically erasable programmable read-only memory; Based on a preset security policy, determining a result of a data reading and writing operation in the flash memory using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory; The basic configuration storage information includes: block identifier, page address, page identifier, page type, offset, data length, check value, and write count; accordingly, determining the actual storage address of the configuration information in the flash memory based on the basic configuration storage information stored in the electrically erasable programmable read-only memory after updating includes: Determining an actual storage address of the configuration information in the flash memory based on the paging address, the paging identifier, the paging type, and the offset stored in the electrically erasable programmable read-only memory after updating; The determining, based on a preset security policy, a result of a data reading and writing operation in the flash memory using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory, includes: Based on a preset write security policy, determining a write address for writing data in the flash memory using the actual storage address and the data length in the basic configuration storage information in the electrically erasable programmable read-only memory; Determine whether there is data at the write address; If data exists under the write address, an operation result indicating a write operation exception is returned; If no data exists at the write address, determining whether the write address is an even number; If the write address is an even number of bits, directly writing data to the flash memory to obtain a corresponding write result, determining a first check value corresponding to the write result, and then synchronously updating the data length, the check value, and the write count in the basic configuration storage information in the electrically erasable programmable read-only memory based on the write result and the first check value; If the write address is an odd number of bits, the write address is shifted backward by one byte and then the step of writing data into the flash memory is triggered to obtain a corresponding write result; Based on a preset read security policy, determining a read address for reading data in the flash memory using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory; Obtaining corresponding target configuration information from the flash memory according to the read address, and determining a third check value according to the target configuration information; The third check value is compared with the check value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison results are inconsistent, an operation result indicating that the target configuration information is damaged is returned.
2. The data reading and writing method according to claim 1, wherein: Also includes: Dividing the multiple blocks in the flash memory into multiple groups according to the number of blocks in the flash memory; wherein each group includes at least two blocks; Accordingly, determining the target block in the flash memory includes: A target group in the flash memory is determined, and a target block is determined in the target group.
3. The data reading and writing method according to claim 2, wherein: The preset paging rules include: One page stores one type of configuration information, and one type of configuration information stores one associated configuration item; The paging addresses of the pages corresponding to the same type of configuration information in the target block are continuous, and the sizes of the pages corresponding to the same type of configuration information are the same; Accordingly, the data reading and writing method further includes: Based on the preset paging rule, dividing other blocks in the same group as the target block into the same area as the target block; When the page corresponding to the configuration information of the target type in the target block is full, data writing is switched to the other block to continue.
4. The data reading and writing method according to claim 3, wherein: Also includes: Based on the preset rollback strategy, determine the configuration record corresponding to the configuration information when the data read and write abnormal event occurs, and perform configuration rollback according to the configuration record; Based on a preset dynamic adjustment strategy, when the page corresponding to the target type configuration information in the target block is full, the write count corresponding to the target type configuration information is counted. If the write count is greater than a preset threshold, the target type configuration information is copied to the backup block corresponding to the target block, and the target block is re-divided into regions to dynamically adjust the paging structure of the page, and initialize the basic configuration storage information stored in the electrically erasable programmable read-only memory according to the current paging structure.
5. The data reading and writing method according to claim 1, wherein: After determining the actual storage address of the configuration information in the flash memory based on the basic configuration storage information stored in the electrically erasable programmable read-only memory after the update, the method further includes: Sending the actual storage address to the flash memory using a preset communication interface, so that the flash memory determines a second check value based on the actual storage address; The second check value is compared with the check value in the basic configuration storage information in the electrically erasable programmable read-only memory. When the comparison results are consistent, the step of determining the result of the data reading and writing operation in the flash memory based on the preset security policy using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory is triggered.
6. A data reading and writing device, characterized in that: include: A flash memory paging module is used to determine a target block in the flash memory and divide the target block into regions based on a preset paging rule to generate pages for storing different types of configuration information; an emulation management module, configured to store basic configuration storage information corresponding to different pages in an electrically erasable programmable read-only memory, and determine an actual storage address of the configuration information in the flash memory based on the updated basic configuration storage information stored in the electrically erasable programmable read-only memory; a data reading and writing module, configured to determine, based on a preset security policy, a result of a data reading and writing operation in the flash memory using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory, so as to simulate data reading and writing in the electrically erasable programmable read-only memory; The basic configuration storage information includes: block identifier, page address, page identifier, page type, offset, data length, check value, and write count; accordingly, the simulation management module is specifically used to: Determining an actual storage address of the configuration information in the flash memory based on the paging address, the paging identifier, the paging type, and the offset stored in the electrically erasable programmable read-only memory after updating; The data reading and writing module includes a writing module, which is used to: Based on a preset write security policy, determining a write address for writing data in the flash memory using the actual storage address and the data length in the basic configuration storage information in the electrically erasable programmable read-only memory; Determine whether there is data at the write address; If data exists under the write address, an operation result indicating a write operation exception is returned; If no data exists at the write address, determining whether the write address is an even number; If the write address is an even number of bits, directly writing data to the flash memory to obtain a corresponding write result, determining a first check value corresponding to the write result, and then synchronously updating the data length, the check value, and the write count in the basic configuration storage information in the electrically erasable programmable read-only memory based on the write result and the first check value; If the write address is an odd number of bits, the write address is shifted backward by one byte and then the step of writing data into the flash memory is triggered to obtain a corresponding write result; Read module for: Based on a preset read security policy, determining a read address for reading data in the flash memory using the actual storage address and the basic configuration storage information in the electrically erasable programmable read-only memory; Obtaining corresponding target configuration information from the flash memory according to the read address, and determining a third check value according to the target configuration information; The third check value is compared with the check value in the basic configuration storage information in the electrically erasable programmable read-only memory, and when the comparison results are inconsistent, an operation result indicating that the target configuration information is damaged is returned.
7. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the data reading and writing method according to any one of claims 1 to 5 when executing the computer program.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the data reading and writing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Write operation method and device of Flash memory
CN106502919A
Solid state disk metadata management method and system based on NVM
CN111506255A