Method and device for updating data blocks of non-volatile memory
The method and device for updating non-volatile memory data blocks in embedded devices address firmware version changes by using unique indexes for seamless migration and expansion/deletion, ensuring data continuity and reducing storage waste.
Patent Information
- Application Number
- CN202110677144.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-18
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2041-06-18
AI Technical Summary
Existing methods for updating firmware in embedded devices with non-volatile memory face challenges due to the need to manage data block changes between different versions, often requiring complex compatibility handling and inefficient use of storage resources.
A method and device that utilize unique indexes for data blocks in new and old versions to facilitate seamless migration and expansion or deletion of data blocks, ensuring data continuity and reducing storage waste by allowing blocks to be added or deleted at any position, thus simplifying maintenance.
Ensures data continuity and reduces storage resource waste by allowing data block expansion or deletion based on index references, eliminating the need for complex compatibility handling and reducing maintenance workload.
Smart Images

Figure CN113377793B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of power systems, and in particular to a method and device for updating a data block of a non-volatile memory. Background Art
[0002] With the rapid development of industrialization and the power Internet of Things (IoT), an increasing number of embedded devices are being used, such as charging stations and sensors. Due to cost constraints, these embedded devices often use smaller non-volatile memory (NVM). NVM, such as FLASH or EEPROM, ensures that data is not lost if the embedded device loses power. NVM contains multiple data blocks, which are sequentially arranged in a continuous sequence.
[0003] In practical applications, when the firmware of the embedded device needs to be updated, for example, from an old version to a new version, the data blocks of the non-volatile memory need to be adjusted accordingly. Therefore, how to effectively perform version updates has become an urgent problem to be solved. Summary of the Invention
[0004] In view of this, the present invention proposes a method for updating data blocks in a non-volatile memory. The updating method is applied to an embedded device, wherein the embedded device has a non-volatile memory, and the data blocks in the non-volatile memory are arranged continuously. The updating method comprises:
[0005] After the firmware of an embedded device is updated from an old version to a new version, a default index of each data block in the new version is obtained, where each data block in the new version has a unique default index, and each data block in the old version has a unique original index, and at least one of the default indexes is different from the original index value, or at least one data block with the same index value has a different size in the old version and the new version;
[0006] If it is identified that the original index and the default index have the same index value, the data of the data block corresponding to the original index is migrated to the data block corresponding to the default index.
[0007] According to the updating method described above, optionally, the total number of data blocks in the new version is different from the total number of data blocks in the old version.
[0008] According to the updating method described above, optionally, the total number of data blocks in the new version is greater than the total number of data blocks in the old version, and the extra data blocks in the new version are located before the last data block.
[0009] According to the updating method described above, optionally, migrating the data of the data block corresponding to the original index to the data block corresponding to the default index includes:
[0010] The data in the data block corresponding to the original index is migrated to the data block corresponding to the default index in sequence until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is filled, and the migration operation is stopped.
[0011] According to the update method described above, optionally, obtaining the default index of each data block in the new version includes:
[0012] The default index of each data block in the new version is obtained in a structure, which is located in front of the first data block. The structure includes the default index, offset and size information of each data block.
[0013] The present invention provides another device for updating data blocks of a non-volatile memory. The device is applied to an embedded device having a non-volatile memory, wherein the data blocks in the non-volatile memory are arranged continuously. The device comprises:
[0014] An acquisition unit is configured to, after firmware of an embedded device is updated from an old version to a new version, acquire a default index of each data block in the new version, wherein each data block in the new version has a unique default index, each data block in the old version has a unique original index, at least one of the default indexes is different from the original index, or at least one data block with the same index value has a different size in the old version and the new version;
[0015] A migration unit is configured to migrate data of a data block corresponding to the original index to a data block corresponding to the default index if it is identified that the original index and the default index have the same index value.
[0016] According to the updating device as described above, optionally, the total number of data blocks in the new version is different from the total number of data blocks in the old version.
[0017] According to the updating device as described above, optionally, the total number of data blocks in the new version is greater than the total number of data blocks in the old version, and the extra data blocks in the new version are located before the last data block.
[0018] According to the updating device as described above, optionally, the migration unit is specifically configured to:
[0019] The data in the data block corresponding to the original index is migrated to the data block corresponding to the default index in sequence until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is filled, and the migration operation is stopped.
[0020] According to the updating device as described above, optionally, the acquiring unit is specifically configured to:
[0021] The default index of each data block in the new version is obtained in a structure, which is located in front of the first data block. The structure includes the default index, offset and size information of each data block.
[0022] The present invention further provides a device for updating data blocks of a non-volatile memory, the updating device being applied to an embedded device having a non-volatile memory, wherein the data blocks in the non-volatile memory are arranged continuously, comprising:
[0023] at least one memory for storing instructions;
[0024] At least one processor is configured to execute the method for updating a data block of a non-volatile memory according to any one of the above items according to instructions stored in the memory.
[0025] The present invention further provides a readable storage medium, wherein the readable storage medium stores machine-readable instructions. When the machine-readable instructions are executed by a machine, the machine executes the method for updating a data block of a non-volatile memory according to any one of the above items.
[0026] As can be seen from the above scheme, since the present invention uses the indexes of the data blocks in the new version and the indexes of the data blocks in the old version as references when migrating data, the order of the data blocks themselves is unrelated. Therefore, if the new version expands the data blocks, they can be added at any position, and data continuity is still guaranteed. In addition, data blocks can be deleted based on the index, saving storage resources in non-volatile memory. Furthermore, since this update method obtains data from the old version, there is no need to deal with compatibility issues for this data, which can greatly reduce the workload of subsequent maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, so that those skilled in the art will understand the above and other features and advantages of the present invention more clearly. In the accompanying drawings:
[0028] Figure 1 FIG. 4 is a flow chart of a method for updating a data block of a non-volatile memory according to an embodiment of the present invention.
[0029] Figure 2AFIG. 1 is a schematic diagram of a structure of a version upgrade of a non-volatile memory according to an embodiment of the present invention.
[0030] Figure 2B FIG. 1 is a schematic structural diagram of a non-volatile memory having a structure according to an embodiment of the present invention.
[0031] Figure 3 FIG. 1 is a schematic structural diagram of a device for updating a data block of a non-volatile memory according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described in detail with reference to the following examples.
[0033] Example 1
[0034] This embodiment provides a method for updating data blocks in a non-volatile memory. The method is performed by a non-volatile memory data block update device, which can be integrated into an embedded device. Step 101: After an embedded device's firmware is updated from an old version to a new version, the default index of each data block in the new version is obtained.
[0035] Each data block in the new version and the old version has a unique index. To facilitate distinction, the index in the new version is referred to as the default index, and the index in the old version is referred to as the original index. In this embodiment, at least one default index in the new version has a different value from the original index, or at least one data block with the same index value has a different size in the old version and the new version. Specifically, the total number of data blocks in the new version can be different from the total number of data blocks in the old version; for example, the total number of data blocks in the new version is greater than the total number of data blocks in the old version.
[0036] Embedded devices are devices capable of independent operation. Compared to general computer processing systems, embedded devices are significantly different because they lack large-capacity storage capabilities. To prevent data loss after a power outage, the embedded device in this embodiment includes non-volatile memory, in which data blocks are arranged contiguously.
[0037] In this embodiment, firmware refers to the device driver stored within the device. The data used by the firmware is stored in data blocks. With technological advancements, firmware often needs to be updated, that is, from an old version to a new version. In the new version, the total number of data blocks is usually different from that in the old version, or the size of data blocks with the same index value is different from that in the old version.
[0038] In this embodiment, a matching unique index is assigned to each data block in both versions. For the new version, the required data in its firmware and where the data blocks need to be expanded are already pre-defined. That is, before step 101, default indexes and default values can be configured for all data blocks in the new version.
[0039] As an example, a default index is configured for a data block in the new version, and the value of this default index is different from the values of each original index. In this way, at least one data block in the new version will not be migrated because the default index does not find a matching original index in the old version. This is equivalent to expanding the data block, and the location of the newly added data block can be arbitrarily selected according to actual needs. For example, it can be placed before the last data block, which is equivalent to inserting the data block at any position before the last data block. In other words, in addition to being able to add new data blocks after the last data block, this embodiment can also add data blocks at any other position, which is very convenient.
[0040] As another example, the default index of a data block in the new version is the same as the original index of a data block in the old version, but the two data blocks are of different sizes. The data block in the new version can be larger or smaller than the data block in the old version. For example, for data blocks with the same index value, if the data block in the new version is larger, all the data in the old version can be migrated, and the remaining bytes in the data block are pre-set to the default value; if the data block in the new version is smaller, the first portion of the data in the old version can be migrated to the new version, and the remaining data in the old version can be deleted, thus achieving space recovery. In addition, the order of data blocks in the new version and the old version with the same index value can be the same or different. For example, the order of the data block in the old version is 4th, and the order of the data block in the new version is 3rd. Since each data block is arranged consecutively, each data block has its own order, such as whether it is the first or second data block. Therefore, the same order means that they have the same sequence number after the consecutive arrangement. The starting position of two data blocks with the same order can be the same or different.
[0041] The index here can be in any form, such as numbers, letters, or a combination of numbers and letters, or special symbols. It can be set according to actual needs and is not limited here.
[0042] Step 102: If it is identified that the value of the original index is the same as the value of the default index, the data of the data block corresponding to the original index is migrated to the data block corresponding to the default index.
[0043] The update device compares the indexes of the data blocks in the two versions. If the values are equal, the data in the data block corresponding to the original index is migrated to the data block corresponding to the default index with the same value. For example, if the original index is 1a and the default index is also 1a, the data in the data block corresponding to 1a in the old version can be migrated to the data block in the new version with the same index 1a. The specific method of migrating data from the old version to the new version belongs to the existing technology and will not be detailed here.
[0044] More specifically, the update device can traverse the default index of each data block in the new version. Every time it identifies one, it goes to the old version to see if there is an original index with the same value. If so, it migrates the data. If not, it identifies the default index of the next data block.
[0045] Optionally, a structure may be provided in front of the first data block, and the structure includes the default index, offset, and size information of each data block. In this way, the update device does not need to traverse each data block, and can obtain the relevant information of all data blocks in the structure, and determine whether the value of the original index is the same as the value of the default index. If the value is the same, the data of the data block in the old version is migrated to the corresponding data block in the new version. The use of a structure to store the relevant information of each data block makes it very convenient to find the default index, takes less time, and has a fast processing speed. A similar structure may also be provided for the old version. The structure in the old version and the structure in the new version may be stored in the same non-volatile memory location. The structure stores the old version index and data before the update. After the update is completed, the new version of the firmware first reads the default index and data of the old version and performs data migration. After the data migration is completed, the default index and data of the new version are written back to the corresponding location stored in the non-volatile memory.
[0046] Specifically, step 102 may include sequentially migrating the data in the data block corresponding to the original index to the data block corresponding to the default index until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is full, and then stopping the migration operation. If the data block in the new version is larger than the data block with the same index value in the old version, the data in the old version can be completely migrated to the new version. If the data block in the new version is smaller than the data block in the old version, the first part of the data block in the old version can be migrated to the new version, and the remaining content is deleted in the new version.
[0047] According to the non-volatile memory data block update method of this embodiment, since the reference for data migration is the index of the data block in the new version and the index of the data block in the old version, the order of the data blocks themselves is irrelevant. Therefore, if the new version expands the data block, it can be added at any position, and data continuity is still guaranteed. In addition, data blocks can be deleted based on the index, saving storage resources in the non-volatile memory. Furthermore, since this update method obtains data from the old version, there is no need to deal with compatibility issues for this data, which can greatly reduce the workload of subsequent maintenance.
[0048] Example 2
[0049] This embodiment specifically illustrates the method for updating a data block of the non-volatile memory in the first embodiment.
[0050] like Figure 2A As shown in Figure 2, the firmware in an embedded device is upgraded from the old version V1.0 to the new version V2.0. Figure 2 shows the final upgrade result. Two modules are shown in each version: Module 1 and Module 2. In V1.0, Module 1 has three data blocks: 1a, 1b, and 1c. 1a, 1b, and 1c are the original indexes mentioned above. Module 2 has two data blocks: 2a and 2b. 2a and 2b are the original indexes mentioned above. In V2.0, Module 1 has four data blocks: 1a, 1b, 1c, and 1d. 1a, 1b, 1c, and 1d are the default indexes, which are pre-set based on actual needs. Module 2 has one data block: 2a. 2a is the default index. This means that in V2.0, a new data block 1d belonging to Module 1 is added, and data block 2b in V1.0 needs to be discarded. The size of data block 1c in the old version is 56 bytes, and the size of data block 1c in the new version is 60 bytes.
[0051] First, after the firmware upgrade of the embedded device is completed, start the embedded device and restore the data block in V2.0 to the default value. Then traverse the default index of the data block in V2.0. If there is an original index with the same value in V1.0, the data corresponding to the original index will be migrated to V2.0. Figure 2AAs shown by the arrows, the data of data blocks 1a, 1b, 1c and 2a in V1.0 are all migrated to V2.0, and it is recognized that data block 1d does not have the same index as the data block in V1.0, so data block 1d is skipped. The 56 bytes of data in data block 1c in V1.0 are all migrated to data block 1c in V2.0. The last 4 bytes of data block 1c in V2.0 have been restored to the default value when the embedded device is started after the update is completed, and data can be written to it later according to actual needs. The data in data block 2b in V1.0 is deleted. Since the data blocks are continuous, it is equivalent to the position of data block 2b in V1.0 being replaced by other data blocks and can be used by other data blocks to avoid wasting space.
[0052] like Figure 2B As shown, a structure 201 can be added before the first data block in the old version and the new version. The structure defines the order, offset, and size of each data block, which facilitates identification of the data block. The structure 201 can be pre-configured before the firmware upgrade and exists in the non-volatile memory after the firmware upgrade is completed.
[0053] Example 3
[0054] This embodiment provides a device for updating data blocks in a non-volatile memory. The device is applied to an embedded device, such as an embedded device comprising a non-volatile memory in which the data blocks are arranged consecutively. The device is capable of executing the method for updating data blocks in the non-volatile memory described in the preceding embodiment.
[0055] like Figure 3 As shown, a device for updating data blocks of a non-volatile memory according to this embodiment is shown. The updating device includes an acquisition unit 301 and a migration unit 302, wherein the acquisition unit 301 is used to obtain the default index of each data block in the new version after the firmware of an embedded device is updated from an old version to a new version, each data block in the new version has a unique default index, each data block in the old version has a unique original index, at least one default index is different from the original index value, or at least one data block with the same index value has a different size in the old version and the new version; the migration unit 302 is used to, if it is recognized that the original index and the default index have the same index value, migrate the data of the data block corresponding to the original index to the data block corresponding to the default index.
[0056] Optionally, the total number of data blocks in the new version is different from the total number of data blocks in the old version.
[0057] Optionally, the total number of data blocks in the new version is greater than the total number of data blocks in the old version, and the extra data blocks in the new version are located before the last data block.
[0058] Optionally, the migration unit 302 is specifically used to migrate the data in the data block corresponding to the original index to the data block corresponding to the default index in sequence until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is filled and the migration operation is stopped.
[0059] Optionally, the acquiring unit 301 is specifically configured to:
[0060] Get the default index of each data block in the new version in a structure. The structure is located before the first data block. The structure includes the default index, offset, and size information of each data block.
[0061] The working methods of the various units in this embodiment are the same as those in the previous embodiment and will not be described again here.
[0062] According to the non-volatile memory data block update device of this embodiment, since the reference for data migration is the index of the data block in the new version and the index of the data block in the old version, the order of the data blocks themselves is irrelevant. Therefore, if the new version expands the data block, it can be added at any position, and data continuity is still guaranteed. In addition, data blocks can be deleted by index, saving storage resources in the non-volatile memory. Furthermore, since this update method obtains data from the old version, there is no need to deal with compatibility issues for this data, which can greatly reduce the workload of subsequent maintenance.
[0063] The present invention also provides a device for updating data blocks in a non-volatile memory. The device is applied to an embedded device having a non-volatile memory in which the data blocks are arranged consecutively. The device includes at least one memory and at least one processor. The memory is configured to store instructions. The processor is configured to execute the method for updating data blocks in a non-volatile memory described in any of the aforementioned embodiments according to the instructions stored in the memory.
[0064] An embodiment of the present invention further provides a readable storage medium having machine-readable instructions stored therein, wherein when the machine-readable instructions are executed by a machine, the machine executes the method for updating a data block of a non-volatile memory described in any of the aforementioned embodiments.
[0065] The readable medium stores machine-readable instructions that, when executed by a processor, cause the processor to perform any of the aforementioned methods. Specifically, a system or device equipped with a readable storage medium may be provided, wherein the readable storage medium stores software program code that implements the functions of any of the aforementioned embodiments, and causes a computer or processor of the system or device to read and execute the machine-readable instructions stored in the readable storage medium.
[0066] In this case, the program code itself read from the machine-readable medium can realize the function of any one of the above embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute part of the present invention.
[0067] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (e.g., CD-ROMs, CD-Rs, CD-RWs, DVD-ROMs, DVD-RAMs, DVD-RWs, DVD+RWs), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.
[0068] Those skilled in the art will appreciate that the various embodiments disclosed above may be modified and altered in various ways without departing from the essence of the invention. Therefore, the scope of protection of the present invention shall be defined by the appended claims.
[0069] It should be noted that not all steps and units in the above processes and system structure diagrams are required, and certain steps or units can be omitted according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The device structure described in the above embodiments can be a physical structure or a logical structure, that is, some units may be implemented by the same physical entity, or some units may be implemented by multiple physical entities, or may be implemented by certain components in multiple independent devices.
[0070] In the above embodiments, the hardware unit can be realized by mechanical means or electrical means. For example, a hardware unit or a processor can include a permanent dedicated circuit or logic (such as a special processor, FPGA or ASIC) to complete the corresponding operation. The hardware unit or the processor can also include programmable logic or circuit (such as a general-purpose processor or other programmable processors), which can be temporarily set up by software to complete the corresponding operation. Concrete implementation (mechanical means or dedicated permanent circuit or temporarily set circuit) can be determined based on the consideration in cost and time.
[0071] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for updating a data block of a non-volatile memory, wherein the updating method is applied to an embedded device, wherein the embedded device has a non-volatile memory, wherein each data block in the non-volatile memory is arranged continuously, and wherein: The updating method comprises: After the firmware of an embedded device is updated from an old version to a new version, a default index of each data block in the new version is obtained, each data block in the new version has a unique default index, each data block in the old version has a unique original index, at least one of the default indexes is different from the original index, or at least one data block with the same index value has a different size in the old version and the new version, and the data in each data block in the new version is a default value; If it is identified that the original index and the default index have the same index value, the data of the data block corresponding to the original index is migrated to the data block corresponding to the default index; The total number of data blocks in the new version is different from the total number of data blocks in the old version, and the location of the newly added data blocks in the new version can be arbitrarily selected according to actual needs to achieve expansion of the data blocks; If the data blocks with the same index value have different sizes in the old version and the new version, if the data blocks in the new version are larger, all the data in the old version will be migrated, and the remaining bytes in the data blocks in the new version will be pre-set to default values; if the data blocks in the new version are smaller, the first part of the data in the old version will be migrated to the new version, and the remaining data in the old version will be deleted.
2. The updating method according to claim 1, characterized in that: The total number of data blocks in the new version is greater than the total number of data blocks in the old version, and the extra data blocks in the new version are located before the last data block.
3. The updating method according to claim 1, characterized in that: Migrating the data of the data block corresponding to the original index to the data block corresponding to the default index includes: The data in the data block corresponding to the original index is migrated to the data block corresponding to the default index in sequence until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is filled, and the migration operation is stopped.
4. The updating method according to any one of claims 1 to 3, characterized in that: The default indexes for getting each data block in the new version include: The default index of each data block in the new version is obtained in a structure, which is located in front of the first data block and includes the default index, offset and size information of each data block.
5. A device for updating a data block of a non-volatile memory, the updating device being applied to an embedded device, the embedded device having a non-volatile memory, the data blocks in the non-volatile memory being arranged continuously, characterized in that: The updating device comprises: An acquisition unit is used to acquire default indexes of data blocks in a new version after a firmware of an embedded device is updated from an old version to a new version, wherein each data block in the new version has a unique default index, each data block in the old version has a unique original index, at least one of the default indexes is different from the original index, or at least one data block with the same index value has a different size in the old version and the new version, and data in each data block in the new version is a default value; A migration unit is used to migrate the data of the data block corresponding to the original index to the data block corresponding to the default index if it is identified that the index value of the original index is the same as that of the default index, the total number of data blocks in the new version is different from the total number of data blocks in the old version, and the position of the newly added data block in the new version can be arbitrarily selected according to actual needs to achieve the expansion of the data block; if the data blocks with the same index value are different in size in the old version and the new version, if the data blocks in the new version are larger, all the data in the old version are migrated, and the remaining bytes in the data blocks in the new version are pre-set to default values; if the data blocks in the new version are small, the first part of the data in the old version is migrated to the new version, and the remaining data in the old version is deleted.
6. The updating device according to claim 5, characterized in that: The total number of data blocks in the new version is greater than the total number of data blocks in the old version, and the extra data blocks in the new version are located before the last data block.
7. The updating device according to claim 5, characterized in that: The migration unit is specifically used for: The data in the data block corresponding to the original index is migrated to the data block corresponding to the default index in sequence until the data in the data block corresponding to the original index is completely migrated to the data block corresponding to the default index, or until the data block corresponding to the default index is filled, and the migration operation is stopped.
8. The updating device according to any one of claims 5 to 7, characterized in that: The acquisition unit is specifically used for: The default index of each data block in the new version is obtained in a structure, which is located in front of the first data block and includes the default index, offset and size information of each data block.
9. A device for updating a data block of a non-volatile memory, the updating device being applied to an embedded device, the embedded device having a non-volatile memory, wherein each data block in the non-volatile memory is arranged continuously, and characterized in that: include: at least one memory for storing instructions; At least one processor is configured to execute the method for updating a data block of a non-volatile memory according to any one of claims 1 to 4 according to the instructions stored in the memory.
10. A readable storage medium, characterized in that: The readable storage medium stores machine-readable instructions. When the machine-readable instructions are executed by a machine, the machine executes the method for updating a data block of a non-volatile memory according to any one of claims 1 to 4.
Citation Information
Patent Citations
Data block comparison based data updating method
CN101770515A
Method and device for version migration of software package
CN102200915A
System and method of updating data in a contactless flash memory device
US20070283078A1
