CN117707434A - Data writing method and device of Flash, vehicle and storage medium - Google Patents

Data writing method and device of Flash, vehicle and storage medium Download PDF

Info

Publication number
CN117707434A
CN117707434A CN202410147850.8A CN202410147850A CN117707434A CN 117707434 A CN117707434 A CN 117707434A CN 202410147850 A CN202410147850 A CN 202410147850A CN 117707434 A CN117707434 A CN 117707434A
Authority
CN
China
Prior art keywords
storage unit
information
preset
writing
preset area
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.)
Pending
Application number
CN202410147850.8A
Other languages
Chinese (zh)
Inventor
杨永超
王佳慧
蔡朱平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Anhui Xihe Microelectronics Co ltd
Shuimu Blue Whale Nanning Semiconductor Technology Co ltd
Shenzhen Xihua Technology Co Ltd
Original Assignee
Anhui Xihe Microelectronics Co ltd
Shuimu Blue Whale Nanning Semiconductor Technology Co ltd
Shenzhen Xihua Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Anhui Xihe Microelectronics Co ltd, Shuimu Blue Whale Nanning Semiconductor Technology Co ltd, Shenzhen Xihua Technology Co Ltd filed Critical Anhui Xihe Microelectronics Co ltd
Priority to CN202410147850.8A priority Critical patent/CN117707434A/en
Publication of CN117707434A publication Critical patent/CN117707434A/en
Pending legal-status Critical Current

Links

Abstract

The application relates to the field of data storage, and provides a data writing method, device, vehicle and storage medium of Flash, wherein the method comprises the following steps: when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit; writing second preset information in a second preset area of the second storage unit, and starting writing effective data into the second storage unit; after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit; and erasing the data in the first storage unit, and writing fourth preset information into a fourth preset area of the second storage unit after the erasing is completed. According to the method and the device, the preset information is written into the preset area of the second storage unit so as to record the progress of the writing process, so that even if the writing process is interrupted due to unexpected conditions, the writing process before unexpected conditions can be recovered according to the writing conditions of the preset information after the power is on again.

Description

Data writing method and device of Flash, vehicle and storage medium
Technical Field
The invention relates to the field of data storage, in particular to a data writing method and device of Flash, a vehicle and a storage medium.
Background
In the related art, when one storage unit in FLash is full, data is written into the other storage unit, and this process may be referred to as data handling, but when an unexpected situation occurs, such as FLash suddenly fails, the data handling process is interrupted, resulting in data loss and incomplete handling.
Disclosure of Invention
Aiming at the defects in the prior art, the application provides a data writing method, a device, a vehicle and a storage medium of Flash, when accidents happen in the data carrying process of Flash, the carrying progress before the accidents can be recovered after the Flash is powered on again, and the data safety is ensured.
In order to solve the problems, the invention provides the following technical scheme:
in a first aspect, an embodiment of the present application provides a data writing method of Flash, where the Flash includes a first storage unit and a second storage unit, and the method includes:
when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state;
Writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit;
after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state;
and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state.
In some embodiments, if the available writing space of the first storage unit is insufficient, writing first preset information in a first preset area of the second storage unit to identify the second storage unit as the first state includes:
if the available writing space of the first storage unit is insufficient, determining whether the second storage unit is in a full-erasure state;
when the second storage unit is in the full-erase state, first preset information is written in a first preset area of the second storage unit to identify that the second storage unit is in the first state.
In some embodiments, the method further comprises:
when the Flash is powered on, acquiring the state of the second storage unit;
and executing different preset operations according to the state of the second storage unit.
In some embodiments, when writing data to the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information in a first preset area of the second storage unit to identify that the second storage unit is in a first state includes:
when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state;
changing the identification of the second storage unit into a preset identification in the RAM;
the executing different preset operations according to the state of the second storage unit includes:
and when the first preset area of the second storage unit is written with the first preset information and the other preset areas are not written with the preset information, returning to the execution step to change the identification of the second storage unit into the preset identification in the RAM.
In some embodiments, the performing different preset operations according to the state of the second storage unit includes:
and when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, and the rest preset areas are not written with preset information, returning to the execution step to determine the effective data in the first storage unit.
In some embodiments, the performing different preset operations according to the state of the second storage unit includes:
when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, determining whether the first storage unit is erased;
and when the first storage unit is determined to be completely erased, writing fourth preset information in a fourth preset area of the second storage unit to identify that the second storage unit is in a fourth state.
In some embodiments, the first storage unit and the second storage unit each include a header information storage space, the header information storage space includes the first preset area, a first address of the header information storage space is a lowest address in the first storage unit, a first address of the first preset area is a lowest address in the header information storage space, the first preset information includes identification information and verification information, and the verification information is generated by the identification information.
In some embodiments, the performing different preset operations according to the state of the second storage unit includes:
when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, generating pre-verification information according to the identification information, and comparing the pre-verification information with the verification information;
when the comparison fails, determining whether the first storage unit is erased;
and erasing the first storage unit when the first storage unit is not erased.
In some embodiments, the first storage unit and the second storage unit further include a tail information storage space including a fifth preset area corresponding to the fourth preset area of the head information storage space, and after the erasing of the first storage unit, the method further includes:
determining whether a fourth preset area of the second storage unit can be written with information when the first storage unit is erased;
Writing the fourth preset information into the fourth preset area of the second storage unit when the information can be written into the fourth preset area;
and when the fourth preset area cannot write information, writing the fourth preset information into the fifth preset area of the second storage unit.
In some embodiments, the method further comprises:
and writing fourth preset information in the fifth preset area into the fourth preset area when the fourth preset area is changed from non-writable information to writable information.
In some embodiments, the first storage unit further comprises a data unit storage space, an information unit storage space, and a reserved extension space, the reserved extension space being located between the data unit storage space and the information unit storage space;
the method further comprises the steps of:
determining the number of addresses of the reserved expansion space between the data unit storage space and the information unit storage space;
and when the number of addresses is smaller than or equal to a preset number, determining that the available writing space of the first storage unit is insufficient.
In a second aspect, an embodiment of the present application provides a data writing device for Flash, where the Flash includes a first storage unit and a second storage unit, and the device includes:
The first writing unit is used for writing first preset information in a first preset area of the second storage unit to identify that the second storage unit is in a first state if the available writing space of the first storage unit is insufficient when writing data into the first storage unit;
a second writing unit, configured to write second preset information in a second preset area of the second storage unit to identify that the second storage unit is in a second state, determine valid data in the first storage unit, and start writing the valid data into the second storage unit;
a third writing unit, configured to write third preset information in a third preset area of the second storage unit after the writing of the valid data is completed, so as to identify that the second storage unit is in a third state;
and the fourth writing unit is used for erasing the data in the first storage unit, and writing fourth preset information into a fourth preset area of the second storage unit after the erasing is completed so as to mark the second storage unit to be in a fourth state.
In a third aspect, embodiments of the present application provide a vehicle, including:
at least one processor; the method comprises the steps of,
A memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the data writing method of Flash of the first aspect.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium storing an executable program that is executed by a processor to implement a data writing method of Flash as in the first aspect.
The application provides a data writing method and device of Flash, a vehicle and a storage medium, wherein the Flash comprises a first storage unit and a second storage unit, and the method comprises the following steps: when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state; writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit; after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state; and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state. According to the method and the device, the available writing space of the first storage unit is insufficient, the preset information is written into the preset area of the second storage unit in the process of writing data into the second storage unit, so that the progress of the writing process is recorded, even if the writing process is interrupted due to unexpected conditions, the writing process before unexpected conditions can be recovered according to the writing conditions of the preset information after the writing process is electrified again, so that operation resources are saved, and the data safety can be guaranteed.
Drawings
Fig. 1 is a flowchart of a first embodiment of a data writing method of Flash provided in the present application.
Fig. 2 is a schematic structural diagram of a storage unit according to an embodiment of the present application.
Fig. 3 is a schematic structural diagram of a header information storage space according to an embodiment of the present application.
Fig. 4 is a schematic diagram of a refinement flow of step 110 in fig. 1.
Fig. 5 is a schematic flow chart of a second embodiment of a data writing method of Flash according to an embodiment of the present application.
Fig. 6 is a schematic structural diagram of a tail information storage space according to an embodiment of the present application.
Fig. 7 is a schematic structural diagram of a data writing device of Flash according to an embodiment of the present application.
Fig. 8 is a schematic structural diagram of a vehicle according to an embodiment of the present application.
Fig. 9 is a block diagram of a computer-readable storage medium according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the present invention, the meaning of "a plurality" is two or more, unless explicitly defined otherwise.
For convenience in description of the first direction and the second direction in the embodiments of the present application, the first direction is an up-down direction in the drawing, the second direction is a front-back direction in the drawing, and the third direction is a left-right direction in the drawing. The x-axis arrow direction is taken as an "up" direction, the y-axis arrow direction is taken as a "back" direction, and the z-axis arrow direction is taken as a "right" direction, which is not limited in the practical application of the present application.
Referring to fig. 1, fig. 1 is a flowchart of a first embodiment of a data writing method of Flash provided in the present application. The Flash includes a first storage unit and a second storage unit, as shown in fig. 1, a data writing method 100 of Flash includes: steps 110 to 140.
Step 110: when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state.
In some embodiments, the storage unit is a logical sector (logic sector), and the Flash in the present application includes at least two logical sectors, so that when one logical sector is full, valid data can be carried into the other logical sector.
In some embodiments, referring to fig. 2, fig. 2 is a schematic structural diagram of a storage unit according to an embodiment of the present application. As shown in fig. 2, the Flash in fig. 2 includes a storage unit 1000, and at least a data unit storage space 1200 and an information unit storage space 1400 are included in the storage unit 1000; wherein,
the data unit storage space 1200 is used for storing data units, the information unit 1400 is used for storing information units, the data units correspond to the information units one by one, and the information units at least comprise description information and storage addresses of the corresponding data units.
In some embodiments, the storage unit 1000 further includes a head information storage space 1100 and a tail information storage space 1500.
In some embodiments, the header information storage space 1100 is used to store header information, and the trailer information storage space 1500 is used to store trailer information, where the header information and trailer information are identical, so as to implement mutual backup of the header information and trailer information.
In some embodiments, the header information is used to identify the storage unit 1000, for example, to identify the state of the storage unit 1000, which will be described in detail in the following section of the specification.
In some embodiments, the storage unit 1000 further includes a reserved expansion space 1300.
In some embodiments, reserved extension space 1300 is located between data unit storage space 1200 and information unit storage space 1400.
In some embodiments, the data of reserved expansion space 1300 is a preset value, for example, 0x00.
In some embodiments, the information units in the information unit storage space 1400 include description information and physical addresses, the description information is used for describing the corresponding data units, the physical addresses are used for searching the corresponding data units, and the user can search the physical addresses of the data units corresponding to the description information by inputting the description information, so as to read the corresponding data units.
In some embodiments, the method for writing data into Flash provided in the embodiments of the present application further includes the following steps.
(1) And when power is on, traversing the information unit storage space from a high address to a low address, and sequentially reading information included in the information units in the information unit storage space.
(2) After the information included in the information unit is read each time, the storage address included in the information unit is stored in the RAM, and a corresponding relation between the storage address and the description information is established.
(3) After the description information input by the user is received, the storage address of the data unit corresponding to the description information is determined according to the description information, and the corresponding data unit is found according to the storage address.
By the method, when the power is on, the information units are traversed from high address to low address, namely from bottom to top, so that after the information units with the same description information are read successively, the storage address in the information unit read first is covered by the storage address in the information unit read later, and the data unit searched by a user is the latest written data unit, and the intelligence of data management is improved.
Therefore, the data writing method 100 of Flash provided in the embodiment of the present application further includes the following steps.
(1) When a new data unit needs to be written, writing the new data unit below the latest written data unit; when a new information unit needs to be written, the new information unit is written above the newly written information unit.
Based on the above-described writing manner of the data units and the information units, in some embodiments, the sizes of the data unit storage space 1200, the reserved expansion space 1300, and the information unit storage space 1400 may vary with the number of the written data units.
Illustratively, when a new data unit is written into the data unit storage space, because the data unit corresponds to an information unit, the information unit storage space is also written into a new information unit, and at this time, the addresses occupied by the data unit storage space 1200 and the information unit storage space 1400 are increased, that is, the size is increased, and the address occupied by the reserved expansion space 1300 therebetween is decreased, that is, the size is decreased.
Therefore, in some embodiments, the data writing method 100 of Flash provided in the present application further includes the following steps.
(1) Determining the number of addresses of the reserved expansion space between the data unit storage space and the information unit storage space;
(2) And when the number of addresses is smaller than or equal to a preset number, determining that the available writing space of the first storage unit is insufficient.
In some embodiments, the number of addresses between the data unit storage space 1200 and the information unit storage space 1400 is the number of addresses occupied by the reserved expansion space 1300.
By the mode, information of the information unit and information of the data unit can be prevented from being mutually covered, and effectiveness of data storage is guaranteed.
In some embodiments, referring to fig. 3, fig. 3 is a schematic structural diagram of a header information storage space according to an embodiment of the present application. As shown in fig. 3, the header information storage space 1100 includes: a first preset region 1110, a second preset region 1120, a third preset region 1130, and a fourth preset region 1140.
In some embodiments, the header information storage space 1100 further includes a reserved space 1150, and the reserved space 1150 may be used for subsequent scheme expansion.
In some embodiments, the first preset area has a size of 8 bytes, and the first preset information includes first information and second information each occupying four bytes, and illustratively, the first information is sequentially 0x5A, 0x01, 0x00, and 0xCA from a low address to a high address, the second information is the same as the first information and the second information is written below the first information, and is also sequentially 0x5A, 0x01, 0x00, and 0xCA from the low address to the high address.
In some embodiments, referring to fig. 4, fig. 4 is a detailed flow diagram of step 110 in fig. 1. As shown in fig. 4, step 110 includes steps 111 to 112.
Step 111: if the available writing space of the first storage unit is insufficient, determining whether the second storage unit is in a full-erasing state.
Step 112: when the second storage unit is in the full-erase state, first preset information is written in a first preset area of the second storage unit to identify that the second storage unit is in the first state.
In some embodiments, the second storage unit being in the full erase state means that the data of the second storage unit are all predetermined information, for example, all 0x00 or 0xff.
By the mode, the data to be carried is written when the second storage unit is in the full-erasure state, and data writing errors can be prevented.
Step 120: writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit.
In some embodiments, the data unit storage space of the first storage unit stores a plurality of data units, and the sequence of data units stored from low address to high address is as follows: block1, block2, block3, block4, block5, block1, at this time, there are a total of 5 data units with different description information, and the data unit storage space includes 2 blocks 1 at the same time, defined as block1A and block1B respectively, at this time, the sequence of the data units stored from low address to high address is: in the embodiment above, for example, the writing sequence of the data unit is written from a low address to a high address, then the block1B is valid data because it is the latest written data unit, and at this time, the valid data in the data unit storage space is the block2, the block3, the block4, the block5, and the block1B.
The step of determining valid data in said first storage unit therefore comprises the following steps.
(1) Traversing the data unit storage space and determining effective data according to the writing sequence of the data units.
In some embodiments, the size of the second preset area is 8 bytes, the second preset information includes third information and fourth information each occupying four bytes, and illustratively, the third information is 0x5A, 0x02, 0x00, and 0x1E in order from a low address to a high address, the fourth information is the same as the third information and the fourth information is written below the third information, and also 0x5A, 0x02, 0x00, and 0x1E in order from the low address to the high address.
Step 130: and after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state.
In some embodiments, the size of the third preset area is 8 bytes, and the third preset information includes fifth information and sixth information each occupying four bytes, and illustratively, the fifth information is 0x5A, 0x03, 0x00, and 0x52 in order from a low address to a high address, the fifth information is the same as the sixth information, and the sixth information is written below the fifth information, and is also 0x5A, 0x03, 0x00, and 0x52 in order from the low address to the high address.
Step 140: and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state.
In some embodiments, erasing the data in the first storage unit refers to changing the data in the first storage unit to a null value, e.g., 0x00 or 0xff.
In some embodiments, the fourth preset area has a size of 8 bytes, and the fourth preset information includes seventh information and eighth information each occupying four bytes, and illustratively, the seventh information is 0x5A, 0x04, 0x00, and 0xAB in order from a low address to a high address, the seventh information is the same as the eighth information, and the eighth information is written below the seventh information, and is also 0x5A, 0x04, 0x00, and 0xAB in order from the low address to the high address.
In some embodiments, referring to fig. 5, fig. 5 is a flowchart of a second example of a data writing method of Flash provided in the embodiments of the present application. As shown in fig. 5, a method 200 for writing data into Flash according to an embodiment of the present application includes steps 210 to 260.
Step 210: when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state.
Step 220: writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit.
Step 230: and after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state.
Step 240: and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state.
Step 250: and when the Flash is powered on, acquiring the state of the second storage unit.
In some embodiments, the Flash is powered off during the process of transferring data, that is, the Flash is powered off during the process of executing steps 210 to 240, and after the Flash is powered on again, the state of the second storage unit may be obtained to restore the transferring process before the power off.
Step 260: and executing different preset operations according to the state of the second storage unit.
In some embodiments, different states of the second storage unit correspond to different progress rates during the handling process, so that different preset operations need to be performed.
Through when Flash is electrified, acquire the state of second storage unit, can detect whether Flash is in the handling when last outage, if be in the handling then resume last handling progress, improve the intelligent degree of Flash, practice thrift user time and prevent data loss.
In some embodiments, after performing step 210, the method further comprises the following steps before performing step 220.
(1) And changing the identification of the second storage unit into a preset identification in the RAM.
Based on the above steps, the identifier of the second storage unit is changed to a preset identifier in the RAM, and step 260 includes the following steps.
(2) And when the first preset area of the second storage unit is written with the first preset information and the other preset areas are not written with the preset information, returning to the execution step to change the identification of the second storage unit into the preset identification in the RAM.
In some embodiments, the first preset area of the second storage unit is written with the first preset information, and when the remaining preset areas are not written with the preset information to reflect the last power failure, the Flash has not yet started to transfer data to the second storage unit, and at this time, the transfer process is performed again.
In some embodiments, the preset identifier is used to identify the storage unit as a Backup Sector (Backup Sector) in the RAM, and to transfer the data to the Backup Sector when the data is transferred.
By the mode, when the Flash does not start to carry data to the storage unit, the power is cut off, and after the Flash is powered on again, the Flash can restart the data carrying process, so that the anti-interference capability of the Flash is improved.
In some embodiments, step 260 includes the following steps.
And when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, and the rest preset areas are not written with preset information, returning to the execution step to determine the effective data in the first storage unit.
In some embodiments, the first preset area of the second storage unit is written with the first preset information, the second preset area is written with the second preset information, and the other preset areas are not written with the preset information, which reflects that the Flash is carrying data to the second storage unit when the power is turned off last time, but the data is not carried, and the carrying process is carried again at this time.
In some embodiments, before returning to the step of performing to determine valid data in the first storage unit, the step further includes changing the identification of the second storage unit to a preset identification in the RAM, that is, identifying the second storage unit as a backup sector.
Through the mode, when the Flash carries data to the storage unit, but the data is not carried, the power is cut off, and after the Flash is electrified again, the Flash can restart the data carrying process, so that the anti-interference capability of the Flash is improved.
In some embodiments, step 260 includes the following steps.
(1) And when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, determining whether the first storage unit is erased or not.
(2) And when the first storage unit is determined to be completely erased, writing fourth preset information in a fourth preset area of the second storage unit to identify that the second storage unit is in a fourth state.
In some embodiments, the first preset area of the second storage unit is written with the first preset information, the second preset area is written with the second preset information, the third preset area is written with the third preset information, the fourth preset area is not written with the fourth preset information, and it is reflected that the step of carrying data by Flash to the second storage unit when the power is turned off last time is completed, and the step of erasing the data of the first storage unit is being executed, and at this time, it is required to query whether the first storage unit is erased, because the data can be written only after the first storage unit is erased.
If it is determined that the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to identify that the second storage unit is in a fourth state, wherein at this time, the first preset area of the second storage unit is written with the first preset information, the second preset area is written with the second preset information, the third preset area is written with the third preset information, and the fourth preset area is written with the fourth preset information, and when a storage unit satisfying the four conditions is detected, the storage unit is marked as an ACTIVE (ACTIVE) state in the RAM, and when Flash is written with new data, the storage unit is written into the ACTIVE state.
By the mode, whether the step executed in the second storage unit is finished or not can be detected through the state of the second storage unit, and whether the step executed in the first storage unit is finished or not can be detected, so that the power failure detection covers the whole data carrying process, and the data safety is guaranteed.
In some embodiments, the method for writing data into Flash provided in the embodiments of the present application further includes the following steps.
(1) When power is on, whether a first preset area is written with first preset information or not is detected, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is written with a storage unit of fourth preset information.
(2) When the storage unit does not exist, a storage unit is selected, first preset information is written into a first preset area of the storage unit, second preset information is written into a second preset area, third preset information is written into a third preset area, fourth preset information is written into a fourth preset area, and the storage unit is marked as an activated state in the RAM.
When the Flash is powered on for the first time, the data stored in the storage units in the Flash are all null values, and at the moment, because the storage units in the activated state do not exist, a user cannot write information into the Flash, the steps are executed, and one storage unit is optionally changed into the activated state.
In some embodiments, the first storage unit and the second storage unit each include a header information storage space, the header information storage space includes the first preset area, a first address of the header information storage space is a lowest address in the first storage unit, a first address of the first preset area is a lowest address in the header information storage space, the first preset information includes identification information and verification information, and the verification information is generated by the identification information.
In some embodiments, referring to fig. 2, the first address of the header information storage space 1100 being the lowest address in the first storage unit means that the header information storage space 1100 is located at the top of the storage unit 1000, and when erasing data in the storage unit, the data in the header information storage space is erased first.
In some embodiments, referring to fig. 3, the first address of the first preset area 1110 being the lowest address in the header information storage space 1100 means that the first preset area 1110 is located at the top of the header information storage space 1100, and when the data in the storage unit is erased, the data in the first preset area 1110 is erased first.
In some embodiments, the information located at the top of the first preset area 1110 is identification information.
In the above arrangement, when the data in the storage unit is erased, the first erased information is the identification information in the first preset area, once the identification information is erased, the pre-verification information generated according to the identification information after the Flash is powered on again is different from the originally stored verification information, and at this time, the storage unit can be known to be in the erased state when the storage unit is powered off last time.
In some embodiments, step 260 includes the following steps.
(1) And when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, generating pre-verification information according to the identification information, and comparing the pre-verification information with the verification information.
(2) And when the comparison fails, determining whether the first storage unit is erased.
(3) And erasing the first storage unit when the first storage unit is not erased.
By the method, whether the erasing process of the first storage unit is finished or not can be detected, and the phenomenon that after power failure, the storage unit which is not erased is left is prevented from being abnormal when data is written into the storage unit later.
In some embodiments, if the comparison between the pre-verification information and the verification information fails, that is, the pre-verification information is different from the verification information, it is indicated that the first storage unit is in the erasing process when the power is turned off last time, and because the fourth preset information is not written into the fourth preset area in the second storage unit, the first storage unit at least includes two possible cases, case 1 is that the erasing is completed but not erased, and case 2 is that the erasing is completed but not reached to write the fourth preset information into the fourth preset area of the second storage unit.
In some embodiments, when the case 2 occurs, the fourth preset information needs to be written to the fourth preset area of the second storage unit, but the fourth preset area of the second storage unit may be in a state of being unable to write information because of power failure.
Therefore, in some embodiments, the first storage unit and the second storage unit further include a tail information storage space, where the tail information storage space includes a fifth preset area corresponding to the fourth preset area of the head information storage space, and the data writing method of Flash further includes the following steps.
(1) And when the first storage unit is erased, determining whether the fourth preset area of the second storage unit can write information.
(2) And when the fourth preset area can write information, writing the fourth preset information into the fourth preset area of the second storage unit.
(3) And when the fourth preset area cannot write information, writing the fourth preset information into the fifth preset area of the second storage unit.
In some embodiments, the above steps further comprise the following steps.
(4) And writing fourth preset information in the fifth preset area into the fourth preset area when the fourth preset area is changed from non-writable information to writable information.
In some embodiments, referring to fig. 6, fig. 6 is a schematic structural diagram of a tail information storage space according to an embodiment of the present application. As shown in fig. 6, the tail information storage space further includes a sixth preset area corresponding to the first preset area of the head information storage space, a seventh preset area corresponding to the second preset area of the head information storage space, and an eighth preset area corresponding to the third preset area of the head information storage space.
In some embodiments, the head information storage space and the tail information storage space are backed up with respect to each other.
Taking the fourth preset area and the fifth preset area as examples, mutual backup refers to: if the fourth preset area stores the written fourth preset information and the fifth preset area does not write the fourth preset information, writing the fourth preset information into the fifth preset area when the situation is detected; if the fourth preset area is not written with the fourth preset information, the fifth preset area is written with the fourth preset information, and when the situation is detected, the fourth preset information is written into the fourth preset area.
The other areas are the same and are not described in detail herein.
By the mode, even if the head information storage space cannot be written in and the progress of data carrying cannot be recorded because of power failure, information can be written into the tail information storage space to continue the data carrying process, so that interruption of the data carrying process or information missing is prevented, and the accuracy of power-on detection is improved.
Referring to fig. 7, fig. 7 is a schematic structural diagram of a Flash data writing device according to an embodiment of the present application. Flash includes a first storage unit and a second storage unit, and as shown in fig. 7, a data writing device 300 of Flash includes: the first writing unit 310, the second writing unit 320, the third writing unit 330, and the fourth writing unit 340.
The first writing unit 310 is configured to, when writing data to the first storage unit, if the available writing space of the first storage unit is insufficient, write first preset information in a first preset area of the second storage unit to identify that the second storage unit is in a first state.
And a second writing unit 320, configured to write second preset information in a second preset area of the second storage unit to identify that the second storage unit is in a second state, determine valid data in the first storage unit, and start writing the valid data into the second storage unit.
And a third writing unit 330, configured to write third preset information in a third preset area of the second storage unit after the writing of the valid data is completed, so as to identify that the second storage unit is in a third state.
And a fourth writing unit 340, configured to erase the data in the first storage unit, and after the erasing is completed, write fourth preset information in a fourth preset area of the second storage unit to identify that the second storage unit is in a fourth state.
Referring to fig. 8, fig. 8 is a schematic structural diagram of a vehicle according to an embodiment of the present application. As shown in fig. 8, the vehicle 400 includes: one or more processors 410, and a memory 420, one processor 410 being illustrated in fig. 8.
In some embodiments, processor 410 and memory 420 may be connected by a bus or otherwise, for example in FIG. 8.
In some embodiments, the processor 410 is configured to, when writing data to the first storage unit, if the available writing space of the first storage unit is insufficient, write first preset information in a first preset area of the second storage unit to identify that the second storage unit is in a first state; writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit; after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state; and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state.
In some embodiments, the memory 420 is used as a non-volatile computer readable storage medium, and may be used to store non-volatile software programs, non-volatile computer executable programs, and modules, such as program instructions/modules of a Flash data writing method in the embodiments of the present application. The processor 410 executes various functional applications of the vehicle and data processing, i.e., a data writing method of Flash implementing the above-described method embodiment, by running nonvolatile software programs, instructions, and modules stored in the memory 420.
In some implementations, the memory 420 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the vehicle, etc. In addition, memory 420 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 420 optionally includes memory remotely located relative to processor 410, which may be connected to the controller via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
In some implementations, one or more modules are stored in memory 420 that, when executed by one or more processors 410, perform the data writing method of Flash in any of the method embodiments described above, e.g., perform method steps 110-140 in fig. 1 described above.
Referring to fig. 9, fig. 9 is a block diagram of a computer readable storage medium according to an embodiment of the present application. The computer readable storage medium 500 has stored therein program code 510, the program code 510 being executable by a processor to invoke a data writing method for performing Flash as described in the above method embodiments.
The computer readable storage medium 500 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium comprises a non-volatile computer readable medium (non-transitory computer-readable storage medium). The computer readable storage medium 500 has a storage space for program code to perform any of the method steps in the control method described above. The program code can be read from or written to one or more computer program products. The program code may be compressed, for example, in a suitable form.
In summary, the present application provides a data writing method, device, vehicle and storage medium for Flash, where the Flash includes a first storage unit and a second storage unit, and the method includes: when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state; writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit; after the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state; and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state. According to the method and the device, the available writing space of the first storage unit is insufficient, the preset information is written into the preset area of the second storage unit in the process of writing data into the second storage unit, so that the progress of the writing process is recorded, even if the writing process is interrupted due to unexpected conditions, the writing process before unexpected conditions can be recovered according to the writing conditions of the preset information after the writing process is electrified again, so that operation resources are saved, and the data safety can be guaranteed.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting thereof; although the present application has been described in detail with reference to the foregoing embodiments, one of ordinary skill in the art will appreciate that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not drive the essence of the corresponding technical solutions to depart from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (14)

1. The data writing method of Flash is characterized in that the Flash comprises a first storage unit and a second storage unit, and the method comprises the following steps:
when writing data into the first storage unit, if the available writing space of the first storage unit is insufficient, writing first preset information into a first preset area of the second storage unit to identify that the second storage unit is in a first state;
writing second preset information in a second preset area of the second storage unit to identify the second storage unit as a second state, determining valid data in the first storage unit, and starting writing the valid data into the second storage unit;
After the writing of the effective data is completed, writing third preset information in a third preset area of the second storage unit to identify that the second storage unit is in a third state;
and after the data in the first storage unit is erased, writing fourth preset information into a fourth preset area of the second storage unit to mark the second storage unit as a fourth state.
2. The method of claim 1, wherein writing first preset information in a first preset area of the second storage unit to identify the second storage unit as the first state if the available writing space of the first storage unit is insufficient, comprises:
if the available writing space of the first storage unit is insufficient, determining whether the second storage unit is in a full-erasure state;
when the second storage unit is in the full-erase state, first preset information is written in a first preset area of the second storage unit to identify that the second storage unit is in the first state.
3. The method according to claim 1, wherein the method further comprises:
when the Flash is powered on, acquiring the state of the second storage unit;
And executing different preset operations according to the state of the second storage unit.
4. The method of claim 3, wherein after writing first preset information to the first preset area of the second storage unit to identify the second storage unit as the first state, the method further comprises:
changing the identification of the second storage unit into a preset identification in the RAM;
the executing different preset operations according to the state of the second storage unit includes:
and when the first preset area of the second storage unit is written with the first preset information and the other preset areas are not written with the preset information, returning to the execution step to change the identification of the second storage unit into the preset identification in the RAM.
5. A method according to claim 3, wherein said performing different preset operations according to the state of the second storage unit comprises:
and when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, and the rest preset areas are not written with preset information, returning to the execution step to determine the effective data in the first storage unit.
6. A method according to claim 3, wherein said performing different preset operations according to the state of the second storage unit comprises:
when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, determining whether the first storage unit is erased;
and when the first storage unit is determined to be completely erased, writing fourth preset information in a fourth preset area of the second storage unit to identify that the second storage unit is in a fourth state.
7. A method according to claim 3, wherein the first storage unit and the second storage unit each comprise a header information storage space, the header information storage space comprising the first preset area, a first address of the header information storage space being a lowest address in the first storage unit, a first address of the first preset area being a lowest address in the header information storage space, the first preset information comprising identification information and verification information, the verification information being generated from the identification information.
8. The method of claim 7, wherein the performing different preset operations according to the state of the second storage unit comprises:
when the first preset area of the second storage unit is written with first preset information, the second preset area is written with second preset information, the third preset area is written with third preset information, and the fourth preset area is not written with fourth preset information, generating pre-verification information according to the identification information, and comparing the pre-verification information with the verification information;
when the comparison fails, determining whether the first storage unit is erased;
and erasing the first storage unit when the first storage unit is not erased.
9. The method of claim 8, wherein the first storage unit and the second storage unit further comprise a tail information storage space comprising a fifth preset area corresponding to the fourth preset area of the head information storage space, the method further comprising, after the erasing the first storage unit:
Determining whether a fourth preset area of the second storage unit can be written with information when the first storage unit is erased;
writing the fourth preset information into the fourth preset area of the second storage unit when the information can be written into the fourth preset area;
and when the fourth preset area cannot write information, writing the fourth preset information into the fifth preset area of the second storage unit.
10. The method according to claim 9, wherein the method further comprises:
and writing fourth preset information in the fifth preset area into the fourth preset area when the fourth preset area is changed from non-writable information to writable information.
11. The method of any of claims 1-10, wherein the first storage unit further comprises a data unit storage space, an information unit storage space, and a reserved extension space, the reserved extension space being located between the data unit storage space and the information unit storage space;
the method further comprises the steps of:
determining the number of addresses of the reserved expansion space between the data unit storage space and the information unit storage space;
And when the number of addresses is smaller than or equal to a preset number, determining that the available writing space of the first storage unit is insufficient.
12. A data writing device of Flash, wherein the Flash comprises a first storage unit and a second storage unit, the device comprising:
the first writing unit is used for writing first preset information in a first preset area of the second storage unit to identify that the second storage unit is in a first state if the available writing space of the first storage unit is insufficient when writing data into the first storage unit;
a second writing unit, configured to write second preset information in a second preset area of the second storage unit to identify that the second storage unit is in a second state, determine valid data in the first storage unit, and start writing the valid data into the second storage unit;
a third writing unit, configured to write third preset information in a third preset area of the second storage unit after the writing of the valid data is completed, so as to identify that the second storage unit is in a third state;
and the fourth writing unit is used for erasing the data in the first storage unit, and writing fourth preset information into a fourth preset area of the second storage unit after the erasing is completed so as to mark the second storage unit to be in a fourth state.
13. A vehicle, characterized in that the vehicle comprises:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the Flash data writing method of any one of claims 1-11.
14. A computer-readable storage medium, characterized in that the computer-readable storage medium stores an executable program that is executed by a processor to implement the data writing method of Flash according to any one of claims 1 to 11.
CN202410147850.8A 2024-02-02 2024-02-02 Data writing method and device of Flash, vehicle and storage medium Pending CN117707434A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410147850.8A CN117707434A (en) 2024-02-02 2024-02-02 Data writing method and device of Flash, vehicle and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410147850.8A CN117707434A (en) 2024-02-02 2024-02-02 Data writing method and device of Flash, vehicle and storage medium

Publications (1)

Publication Number Publication Date
CN117707434A true CN117707434A (en) 2024-03-15

Family

ID=90148218

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410147850.8A Pending CN117707434A (en) 2024-02-02 2024-02-02 Data writing method and device of Flash, vehicle and storage medium

Country Status (1)

Country Link
CN (1) CN117707434A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1567256A (en) * 2003-06-20 2005-01-19 深圳市朗科科技有限公司 Protection method for data in flash memory media
CN108874298A (en) * 2017-05-15 2018-11-23 深圳市奇辉电气有限公司 A kind of method and device of data storage
CN109669889A (en) * 2018-12-24 2019-04-23 青岛方寸微电子科技有限公司 A kind of light-type Nor Flash flash memory control method and device
US20210056023A1 (en) * 2019-08-22 2021-02-25 SK Hynix Inc. Storage device and method of operating the same
CN112466371A (en) * 2020-12-17 2021-03-09 宁波拓普集团股份有限公司 Method for circularly utilizing flash memory to simulate byte erasing function
CN116027973A (en) * 2022-12-07 2023-04-28 绍兴埃瓦科技有限公司 Data writing method and device based on flash memory
CN116225985A (en) * 2022-12-17 2023-06-06 浙江凌骁能源科技有限公司 SOC parameter power-down nonvolatile storage method and device and computer equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1567256A (en) * 2003-06-20 2005-01-19 深圳市朗科科技有限公司 Protection method for data in flash memory media
CN108874298A (en) * 2017-05-15 2018-11-23 深圳市奇辉电气有限公司 A kind of method and device of data storage
CN109669889A (en) * 2018-12-24 2019-04-23 青岛方寸微电子科技有限公司 A kind of light-type Nor Flash flash memory control method and device
US20210056023A1 (en) * 2019-08-22 2021-02-25 SK Hynix Inc. Storage device and method of operating the same
CN112466371A (en) * 2020-12-17 2021-03-09 宁波拓普集团股份有限公司 Method for circularly utilizing flash memory to simulate byte erasing function
CN116027973A (en) * 2022-12-07 2023-04-28 绍兴埃瓦科技有限公司 Data writing method and device based on flash memory
CN116225985A (en) * 2022-12-17 2023-06-06 浙江凌骁能源科技有限公司 SOC parameter power-down nonvolatile storage method and device and computer equipment

Similar Documents

Publication Publication Date Title
JP4371771B2 (en) Power management block used in non-volatile memory system
US7911840B2 (en) Logged-based flash memory system and logged-based method for recovering a flash memory system
US8397017B2 (en) Controller and data storage device
CN107818269B (en) File storage method and system based on Flash
US7558904B2 (en) Controller, data memory system, data rewriting method, and computer program product
CN106648463B (en) Nand Flash block management method and system
US11467645B2 (en) Storage device and method for sudden power off recovery thereof
CN112397128A (en) Control method and device for Flash memory
CN110941394A (en) Data reading and writing method and device for automatic train control system
CN114237984A (en) Recovery method and system of Trim data under abnormal power failure and solid state disk
US8959416B1 (en) Memory defect management using signature identification
US9792070B2 (en) Data storage device, method of storing data, and on-vehicle control apparatus
KR101826778B1 (en) EEPROM Emulation Method Considering implementation of Flash Life Cycle and Performance Improvement
CN114089915B (en) File additional writing operation method and device based on FLASH memory
CN117707434A (en) Data writing method and device of Flash, vehicle and storage medium
JP5541194B2 (en) Control device for reading and writing data to flash memory
CN112908390B (en) Data storage method, device, electronic equipment and storage medium
CN115469911A (en) Parameter configuration method, system and computer readable storage medium
CN110781031B (en) Controller data recovery method and device, controller and automobile
CN110865906B (en) Motor initial position angle storage method and device, vehicle and storage medium
CN113918485A (en) Method, device, equipment and storage medium for preventing flash memory data from being lost
JP6040895B2 (en) Microcomputer and non-volatile memory block management method
CN111209132A (en) Embedded system, power failure protection method, electronic device and storage medium
CN110990052A (en) Configuration saving method and device
CN117687580A (en) Data management system, micro-control unit and vehicle of Flash

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