CN115437674B - Firmware upgrading method, device, medium and electronic equipment - Google Patents

Firmware upgrading method, device, medium and electronic equipment Download PDF

Info

Publication number
CN115437674B
CN115437674B CN202211194151.6A CN202211194151A CN115437674B CN 115437674 B CN115437674 B CN 115437674B CN 202211194151 A CN202211194151 A CN 202211194151A CN 115437674 B CN115437674 B CN 115437674B
Authority
CN
China
Prior art keywords
data
block
firmware
frame
memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211194151.6A
Other languages
Chinese (zh)
Other versions
CN115437674A (en
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.)
Hangzhou Huasu Technology Co ltd
Original Assignee
Hangzhou Huasu 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 Hangzhou Huasu Technology Co ltd filed Critical Hangzhou Huasu Technology Co ltd
Priority to CN202211194151.6A priority Critical patent/CN115437674B/en
Publication of CN115437674A publication Critical patent/CN115437674A/en
Application granted granted Critical
Publication of CN115437674B publication Critical patent/CN115437674B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

The present application relates to the field of computer technologies, and in particular, to a firmware upgrade method, apparatus, medium, and electronic device. The method comprises the following steps: acquiring an upgrade file corresponding to firmware to be upgraded; the upgrade file comprises multi-frame data; backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing first block data in the first frame data with null data to obtain first target frame data; storing the first target frame data in a flash memory; storing the rest frame data in the upgrade file into a flash memory; when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on the target address; the target address is the storage address corresponding to the empty data in the flash memory. The memory space can be saved, the firmware upgrading process is simplified, the fault tolerance rate of the firmware upgrading is improved, and meanwhile, the integrity of the firmware upgrading is ensured.

Description

Firmware upgrading method, device, medium and electronic equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a firmware upgrade method, apparatus, medium, and electronic device.
Background
Bootloader is used as an embedded micro control unit (Microcontroller Unit, MCU) to start the running boot program and is responsible for upgrading the application program firmware. For example, while the MCU is powered on, the upgrade tool pushes upgrade files of the firmware to the bootloader, and the bootloader program upgrades the firmware.
However, the bug of the bootloader program may seriously affect the normal operation of the MCU, for example, the current bootloader program has a complex upgrading process, low security and large backup space, for example, when the firmware to be upgraded is upgraded, the upgrade file of the firmware to be upgraded is written into the flash memory to complete the firmware upgrade, specifically, the upgrade file is written into the memory (Random Access Memory, RAM) at one time, so that all the upgrade files are written into the flash memory at one time; therefore, the memory space is occupied, and after power failure occurs, the memory needs to be rewritten to finish the upgrading of the firmware to be upgraded.
Therefore, it is necessary to provide a firmware upgrading method, device, medium and electronic equipment, which can save memory space, simplify firmware upgrading process, improve firmware upgrading fault tolerance, and ensure the integrity of firmware upgrading.
Disclosure of Invention
The embodiment of the application provides a firmware upgrading method, a device, a medium and electronic equipment, which can save memory space, simplify firmware upgrading flow, improve firmware upgrading fault tolerance and ensure the integrity of firmware upgrading.
In a first aspect, an embodiment of the present application provides a firmware upgrade method, including:
acquiring an upgrade file corresponding to firmware to be upgraded; the upgrade file comprises multi-frame data;
backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing the first block data in the first frame data with null data to obtain first target frame data;
Storing the first target frame data in a flash memory;
storing the rest frame data in the upgrade file into the flash memory;
when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on a target address; and the target address is a storage address corresponding to the empty data in the flash memory.
In some alternative embodiments, before performing the step of storing the first block of data in the memory into the flash memory based on a target address, the method further comprises:
acquiring candidate block data from the memory; the candidate block data is any block data in the multiple blocks of data in the memory;
Checking whether the candidate block data is the first block data of the upgrade file;
And under the condition that the candidate block data is determined to be the first block data of the upgrade file, executing the step of storing the first block data in the memory into the flash memory based on a target address.
In some alternative embodiments, storing the first target frame data in a flash memory includes:
determining a firmware storage address of the firmware to be upgraded in the flash memory;
Erasing the data stored in the firmware storage address under the condition that the firmware storage address stores the data;
Storing the first target frame data in the firmware memory address in the flash memory; the firmware memory address includes the target address.
In some optional embodiments, before performing the step of backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further includes:
Checking the first frame data to obtain a first frame check value;
And under the condition that the first frame check value meets the preset first frame check value, executing the step of backing up the first block data of the first frame data in the upgrade file in the memory.
In some optional embodiments, the first block of data is used to identify the upgrade file;
Before backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further includes:
determining a minimum writable unit of the flash memory;
based on the number of bytes of the minimum writable unit, the number of bytes of the first block of data is determined.
In some alternative embodiments, after storing the first block of data in the memory into the flash memory based on a target address, the method further comprises:
identifying the first block of data in the flash memory;
and under the condition that the first block data is identified, determining that the firmware to be upgraded is successfully upgraded.
In some optional embodiments, storing the remaining frame data in the upgrade file in the flash memory includes:
And storing the rest frame data in the upgrade file into the flash memory frame by frame.
In a second aspect, an embodiment of the present application provides a firmware upgrade apparatus, including:
the first acquisition module is used for acquiring an upgrade file corresponding to the firmware to be upgraded; the upgrade file comprises multi-frame data;
the first processing module is used for backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing the first block data in the first frame data with null data to obtain first target frame data;
the first storage module is used for storing the first target frame data in the flash memory;
the second storage module is used for storing the rest frame data in the upgrade file into the flash memory;
The third storage module is used for storing the first block of data in the memory into the flash memory based on a target address when the storage of the residual frame data is determined to be completed; and the target address is a storage address corresponding to the empty data in the flash memory.
In some alternative embodiments, the apparatus further comprises:
The second acquisition module is used for acquiring candidate block data from the memory; the candidate block data is any block data in the multiple blocks of data in the memory;
A first checking module, configured to check whether the candidate block data is the first block data of the upgrade file;
And the first determining module is used for executing the step of storing the first block data in the memory into the flash memory based on a target address under the condition that the candidate block data is determined to be the first block data of the upgrade file.
In some alternative embodiments, the first storage module includes:
The first storage sub-module is used for determining a firmware storage address of the firmware to be upgraded in the flash memory;
the second storage sub-module is used for erasing the data stored in the firmware storage address under the condition that the data is stored in the firmware storage address;
a third storage sub-module for storing the first target frame data at the firmware storage address in the flash memory; the firmware memory address includes the target address.
In some alternative embodiments, the apparatus further comprises:
the second checking module is used for checking the first frame data to obtain a first frame check value;
And the second determining module is used for executing the step of backing up the first block data of the first frame data in the upgrade file in the memory under the condition that the first frame check value meets the preset first frame check value.
In some optional embodiments, the first block of data is used to identify the upgrade file, and the apparatus further includes:
A third determining module, configured to determine a minimum writable unit of the flash memory;
And a fourth determining module, configured to determine the byte number of the first block of data based on the byte number of the minimum writable unit.
In some alternative embodiments, the apparatus further comprises:
a first identification module for identifying the first block of data in the flash memory;
and the upgrade determining module is used for determining that the firmware to be upgraded is successfully upgraded under the condition that the first block of data is identified.
In some alternative embodiments, the second memory module is further configured to:
And storing the rest frame data in the upgrade file into the flash memory frame by frame.
In a third aspect, an embodiment of the present application provides a computer storage medium, where at least one instruction or at least one program is stored, where the at least one instruction or at least one program is loaded by a processor and executed by the firmware upgrade method described above.
In a fourth aspect, an embodiment of the present application provides an electronic device, where the electronic device includes a processor and a memory, where at least one instruction or at least one section of program is stored in the memory, where the at least one instruction or the at least one section of program is loaded by the processor and executes the firmware upgrading method described above.
The method comprises the steps of obtaining an upgrade file corresponding to firmware to be upgraded; wherein the upgrade file comprises multi-frame data; backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing first block data in the first frame data with null data to obtain first target frame data; storing the first target frame data in a flash memory; storing the rest frame data in the upgrade file into a flash memory; when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on the target address; the target address is the storage address corresponding to the empty data in the flash memory. The memory space can be saved, the firmware upgrading process is simplified, the fault tolerance rate of firmware upgrading is improved, and meanwhile, the integrity of firmware upgrading is ensured; if power failure occurs in the upgrading process, aiming at the firmware to be upgraded which is not upgraded, the upgrading file does not need to be written into the flash memory again.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a firmware upgrade scenario diagram provided by an embodiment of the present application;
fig. 2 is a flow chart of a firmware upgrading method according to an embodiment of the present application;
FIG. 3 is a flowchart of firmware upgrade based on bootloader program according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a firmware upgrading apparatus according to an embodiment of the present application;
Fig. 5 is a block diagram of a hardware structure of an electronic device for implementing a firmware upgrade method according to an embodiment of the present application.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
Reference herein to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic may be included in at least one implementation of the invention. In the description of the present invention, it should be understood that the terms "first," "second," "third," and "fourth," etc. in the description and claims of the invention and in the above-described figures are used for distinguishing between different objects and not for describing a particular sequential order. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
First, a firmware upgrade scenario is described by way of example. Referring to fig. 1, fig. 1 is a firmware upgrade scenario diagram according to an embodiment of the present application. As shown in fig. 1, the original file data of the firmware is stored in a preset storage area in the flash memory, when the firmware needs to be updated, an upgrade file corresponding to the firmware to be upgraded is obtained from the nonvolatile memory, and the upgrade file is written into the memory at one time, so that all the upgrade files are written into the flash memory at one time. Therefore, a large amount of memory space is occupied in the firmware upgrading process, and after power failure occurs, the memory needs to be rewritten to finish the upgrading of the firmware to be upgraded.
In order to solve the problems, the application provides a firmware upgrading method, in particular to a firmware upgrading method by acquiring an upgrading file corresponding to firmware to be upgraded; wherein the upgrade file comprises multi-frame data; backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing first block data in the first frame data with null data to obtain first target frame data; storing the first target frame data in a flash memory; storing the rest frame data in the upgrade file into a flash memory; when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on the target address; the target address is the storage address corresponding to the empty data in the flash memory. The memory space can be saved, the firmware upgrading process is simplified, the firmware upgrading file can be ensured to be completely written into the flash memory, the firmware upgrading fault tolerance rate is improved, and meanwhile, the integrity of the firmware upgrading is ensured; if power failure occurs in the upgrading process, aiming at the firmware to be upgraded which is not upgraded, the upgrading file does not need to be written into the flash memory again. For example, in the event of a power failure or occasional data transmission failure during an upgrade, when the bootloader does not recognize the first block of data of the firmware to be upgraded in the flash memory (i.e., abnormal data) when the power is turned back on or communication resumes, the bootloader may request the upgrade tool again to retransmit the data, for example, to retransmit the first frame of data, or to retransmit the remaining data. That is, the bootloader can identify whether an error occurs in the upgrading process, and as long as the upgrading tool is still online, the firmware updating operation (or the remaining data is continuously transmitted) can be performed again, so that no extra flash memory or memory space is needed to backup the whole upgraded firmware.
The following describes a specific embodiment of a firmware upgrading method of the present application, and fig. 2 is a schematic flow chart of a firmware upgrading method provided by the embodiment of the present application; the present specification provides method operational steps as an example or a flowchart, but may include more or fewer operational steps based on conventional or non-inventive labor. The order of steps recited in the embodiments is merely one way of performing the order of steps and does not represent a unique order of execution. When implemented in a real system or server product, the methods illustrated in the embodiments or figures may be performed sequentially or in parallel (e.g., in a parallel processor or multithreaded environment). As shown in fig. 2, the method may include:
s202: acquiring an upgrade file corresponding to firmware to be upgraded; the upgrade file comprises multi-frame data.
Specifically, the upgrade tool obtains the upgrade file, and stores the upgrade file in a nonvolatile memory of the upgrade tool. The bootloader program acquires the upgrade file from the upgrade tool frame by frame.
S204: backing up a first block of data of a first frame of data in the upgrade file in a memory; and replacing the first block data in the first frame data with null data to obtain first target frame data.
In some alternative embodiments, the first block of data may be the top of stack data of the upgrade file or entry address data of the firmware to be upgraded. The top of stack data and entry address data may be used to identify the firmware to be upgraded. Wherein the entry address data is used to support the running of the program.
To determine that the upgrade file is secure, verification of the correctness of the upgrade file is typically required. In some optional embodiments, before performing the step of backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further includes:
Checking the first frame data to obtain a first frame check value;
And under the condition that the first frame check value meets the preset first frame check value, executing the step of backing up the first block data of the first frame data in the upgrade file in the memory.
In this embodiment, the preset first frame check value may be a preset first frame check value generated according to a fixed segment character of the first frame data in the upgrade file after the upgrade file is developed, for example, the preset first frame check value is generated according to a character at the end of the first frame data; and under the condition that the first frame check value is consistent with the preset first frame check value, determining that the first frame data is safe and correct.
In some alternative embodiments, each frame of data of the upgrade file in the subsequent step S208 may be checked to ensure that each frame of data written is correct.
S206: and storing the first target frame data in a flash memory.
In order to occupy as little memory space as possible during the firmware upgrade, in some optional embodiments, the first block of data is used to identify the upgrade file;
Before backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further includes:
determining a minimum writable unit of the flash memory;
based on the number of bytes of the minimum writable unit, the number of bytes of the first block of data is determined.
The first block of data in this embodiment has the least bytes under the condition that the upgrade file can be identified and the flash memory can be written, so that the space occupied by the memory is reduced as much as possible in the firmware upgrade process.
S208: and storing the rest frame data in the upgrade file into the flash memory.
Typically, the flash memory stores original file data of firmware to be upgraded before upgrading, and in order to write an upgrade file, in some alternative embodiments, the storing the first target frame data in the flash memory includes:
determining a firmware storage address of the firmware to be upgraded in the flash memory;
Erasing the data stored in the firmware storage address under the condition that the firmware storage address stores the data;
Storing the first target frame data in the firmware memory address in the flash memory; the firmware memory address includes the target address.
In this embodiment, when the first frame data is written, all the multiple storage data corresponding to the firmware to be upgraded in the flash memory are deleted, so as to avoid confusion between the original data and the upgrade data, that is, ensure that the first block data of the firmware to be upgraded in the flash memory is the data in the stored upgrade file when the first block data of the firmware to be upgraded is empty, and then complete the upgrade of the firmware to be upgraded when the non-empty first block data is written into the flash memory.
S210: when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on a target address; and the target address is a storage address corresponding to the empty data in the flash memory.
To further reduce the amount of memory space consumed during firmware upgrades. In some optional embodiments, storing the remaining frame data in the upgrade file in the flash memory includes:
And storing the rest frame data in the upgrade file into the flash memory frame by frame.
According to the embodiment, in the firmware upgrading process, the memory stores data of not more than one frame into the flash memory each time, so that the storage space of the memory is saved.
In order to determine that the first block of data in the memory belongs to the upgrade file, and ensure the correctness of the upgrade file written into the flash memory, in some alternative embodiments, before performing the step of storing the first block of data in the memory into the flash memory based on the target address in step S210, the method further includes:
acquiring candidate block data from the memory; the candidate block data is any block data in the multiple blocks of data in the memory;
Checking whether the candidate block data is the first block data of the upgrade file;
And under the condition that the candidate block data is determined to be the first block data of the upgrade file, executing the step of storing the first block data in the memory into the flash memory based on a target address.
Specifically, in the step S204, when the first block of data is backed up in the memory, the target block check value may be generated based on the first block of data; and generating a first check value based on the candidate block data in the flash memory, determining whether the first check value is correct based on the target block check value, and determining the candidate block data as the first block data of the upgrade file under the condition that the first check value is correct.
In this embodiment, the first block data corresponding to the upgrade file is determined by checking the first block data, so that the first block data is written into the target address in the firmware storage address corresponding to the firmware to be upgraded in the flash memory, and the integrity of firmware upgrade is ensured.
To verify that the upgrade was successful. In some optional embodiments, after storing the first block of data in the memory in the flash memory based on a target address, the method further includes:
identifying the first block of data in the flash memory;
and under the condition that the first block data is identified, determining that the firmware to be upgraded is successfully upgraded.
By the embodiment, whether the first block of data in the flash memory is valid or not can be verified, so that whether the firmware to be upgraded is successfully upgraded or not is verified, and the integrity of firmware upgrade is ensured.
The application provides a firmware upgrading process based on bootloader programs. Fig. 3 is a schematic flow chart of firmware upgrade based on bootloader program according to an embodiment of the present application, and specific steps are as follows:
S301: and (5) powering up.
In some alternative embodiments, the embedded system is powered on and the upgrade tool determines the update time of the upgrade file in the nonvolatile memory.
In some alternative embodiments, the embedded system may be powered on, and the upgrade tool may send upgrade file data in the nonvolatile memory directly to the bootloader program.
Specifically, the execution subject of the following steps S302 to S316 may be bootloader program.
S302: and judging whether an upgrade command is received. Specifically, the bootloader program determines whether an upgrade command for firmware sent by the upgrade tool is received.
If an upgrade command is received, step S303 is performed to obtain and check whether the current frame data is correct; if the upgrade order is not received, the step S304 is performed, and whether the time waiting for the upgrade order is overtime is judged.
S303: and acquiring and checking whether the current frame data is correct.
For example, when an upgrade command is sent to the bootloader program by the upgrade tool, the first frame data in the upgrade file is sent to the bootloader program at the same time, and at this time, the first frame data is current frame data.
Specifically, a current frame check value is generated based on the obtained fixed segment characters of the current frame data; and under the condition that the current frame check value is consistent with the preset current check value, determining that the current frame data is safe and correct. For example, the first frame check value is generated based on the acquired fixed segment characters of the first frame data; and under the condition that the first frame check value is consistent with the preset first frame check value, determining that the first frame data is safe and correct.
If the upgrade file is correct, the process advances to step S306, where it is determined whether the acquired current frame data is the first frame data. In the case that the upgrade file is incorrect, step S305, a request for acquiring the upgrade file frame by frame is sent to re-acquire the current frame data of the upgrade file.
S304: judging whether the time is overtime.
Specifically, if the time of the judgment step in step S302 exceeds a certain time, a timeout is determined. If the time-out is over, the process proceeds to step S315, where it is determined whether the first block of data in the flash memory is valid, i.e., whether the firmware has completed the upgrade. If the time-out is not exceeded, the step S302 is re-entered, and it is determined whether an upgrade command is received.
S305: and sending a request for acquiring the upgrade file frame by frame.
Specifically, the upgrade file includes multi-frame data. The bootloader program acquires an upgrade file from the upgrade tool frame by frame; the data in the upgrade file is temporarily stored in the memory frame by frame so as to write the data in each frame into the flash memory, thereby avoiding the situation that all the upgrade file contents are acquired at one time and stored in the memory, occupying the memory space and further affecting the running speed of the embedded system.
S306: it is determined whether the acquired current frame data is first frame data.
When the extracted current frame data is the first frame data, the process proceeds to step S307 to backup the first block data in the first frame data in the memory.
S307: backing up a first block of data in the first frame of data in a memory; and checking the first block data to obtain a target block check value.
Specifically, the target block check value is used to identify the first block of data in the flash memory in the subsequent step S312.
S308: and replacing the first block data in the first frame data with null data to obtain first target frame data.
In this embodiment, the first block data is replaced by the null data to ensure that the first block data for identifying the upgrade file is finally written into the flash memory (i.e., step S315).
S309: and erasing the data stored in the firmware storage address, and storing the current frame data in the firmware storage address in the flash memory.
Specifically, the flash memory includes a storage area for storing data of each firmware file, and the processor of the embedded system reads the data of each firmware file, that is, runs each firmware.
S310: it is determined whether the current frame data is the last frame data.
Specifically, it is determined whether the current frame data acquired in step S303 is the last frame data, and if the current frame data is the last frame data, step S311 is entered to acquire and check the first block data backed up in the memory. If the current frame data is not the last frame data, the process proceeds to step S305 to continue to extract the next frame data of the upgrade file.
S311: and acquiring and checking the backed-up first block of data.
Specifically, a first block of data is obtained from the flash memory, and a first check value is generated.
S312: and judging whether the check of the first block of data is passed.
Specifically, the target block check data is used to determine whether the first check value in step S311 is correct. If the first check value is incorrect, the check is not passed, and step S313 is performed to determine that the upgrade has failed. If the first check value is correct, the check is passed, and the process proceeds to step S314, where the backed-up first block data is written into the flash memory.
S313: the upgrade failed. I.e. the upgrade of the firmware to be upgraded fails.
In some alternative embodiments, a re-upgrade may be performed. Specifically, after determining that the upgrade has failed in step S313, the process may proceed to step S302, where the bootloader program continues to wait for the upgrade command.
S314: and writing the backed-up first block of data into the flash memory.
Specifically, the first block of data is written into the target address corresponding to the empty data in the flash memory, so that a complete upgrade file is written into the flash memory, and the success of upgrading the firmware to be upgraded is ensured.
S315: and judging whether the first block of data in the flash memory is valid or not.
Specifically, whether the first block of data corresponding to the target address in the flash memory is empty is judged. And when the first block data is in a non-empty state, determining that the first block data is valid. In the case where it is determined that the first block data is valid, the flow proceeds to step S316, where the firmware is run. In the case where it is determined that the first block data is invalid, the flow advances to step S302, and the reception of the upgrade command is continued.
S316: and running firmware.
Specifically, the embedded system runs the firmware, that is, runs the data stored in the firmware storage address corresponding to the firmware in the flash memory.
In the above embodiment, the firmware is upgraded based on the bootloader program, so that the upgrade file of the firmware can be ensured to be completely written into the flash memory; and improves the fault tolerance of firmware upgrade, for example, in case of upgrade error, such as power-off, the upgrade can be continuously completed based on the steps shown in fig. 3 after power-up. Because the upgrade file is written into the flash memory frame by frame, the space of the memory is saved.
Fig. 4 is a schematic structural diagram of a firmware upgrading apparatus according to an embodiment of the present application, as shown in fig. 4, where the firmware upgrading apparatus includes:
the first acquisition module is used for acquiring an upgrade file corresponding to the firmware to be upgraded; the upgrade file comprises multi-frame data;
the first processing module is used for backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing the first block data in the first frame data with null data to obtain first target frame data;
the first storage module is used for storing the first target frame data in the flash memory;
the second storage module is used for storing the rest frame data in the upgrade file into the flash memory;
The third storage module is used for storing the first block of data in the memory into the flash memory based on a target address when the storage of the residual frame data is determined to be completed; and the target address is a storage address corresponding to the empty data in the flash memory.
In some alternative embodiments, the apparatus further comprises:
The second acquisition module is used for acquiring candidate block data from the memory; the candidate block data is any block data in the multiple blocks of data in the memory;
A first checking module, configured to check whether the candidate block data is the first block data of the upgrade file;
And the first determining module is used for executing the step of storing the first block data in the memory into the flash memory based on a target address under the condition that the candidate block data is determined to be the first block data of the upgrade file.
In some alternative embodiments, the first storage module includes:
The first storage sub-module is used for determining a firmware storage address of the firmware to be upgraded in the flash memory;
the second storage sub-module is used for erasing the data stored in the firmware storage address under the condition that the data is stored in the firmware storage address;
a third storage sub-module for storing the first target frame data at the firmware storage address in the flash memory; the firmware memory address includes the target address.
In some alternative embodiments, the apparatus further comprises:
the second checking module is used for checking the first frame data to obtain a first frame check value;
And the second determining module is used for executing the step of backing up the first block data of the first frame data in the upgrade file in the memory under the condition that the first frame check value meets the preset first frame check value.
In some optional embodiments, the first block of data is used to identify the upgrade file, and the apparatus further includes:
A third determining module, configured to determine a minimum writable unit of the flash memory;
And a fourth determining module, configured to determine the byte number of the first block of data based on the byte number of the minimum writable unit.
In some alternative embodiments, the apparatus further comprises:
a first identification module for identifying the first block of data in the flash memory;
and the upgrade determining module is used for determining that the firmware to be upgraded is successfully upgraded under the condition that the first block of data is identified.
In some alternative embodiments, the second memory module is further configured to:
And storing the rest frame data in the upgrade file into the flash memory frame by frame.
The device and method embodiments in the embodiments of the present application are based on the same application concept.
Fig. 5 is a block diagram of a hardware structure of an electronic device for implementing a firmware upgrade method according to an embodiment of the present application. The electronic device may be a server or a terminal device, and the internal structure of the electronic device may be as shown in fig. 5. As shown in fig. 5, the electronic device 500 may vary considerably in configuration or performance, and may include one or more central processing units (Central Processing Units, CPU) 510 (the processor 510 may include, but is not limited to, a microprocessor MPU, a programmable logic device FPGA, or other processing device), a memory 530 for storing data, one or more storage mediums 520 (e.g., one or more mass storage devices) storing applications 523 or data 522. Wherein the memory 530 and storage medium 520 may be transitory or persistent storage. The program stored on the storage medium 520 may include one or more modules, each of which may include a series of instruction operations on a server. Still further, the central processor 510 may be arranged to communicate with a storage medium 520, and to execute a series of instruction operations in the storage medium 520 on the electronic device 500. The electronic device 500 may also include one or more power supplies 550, one or more wired or wireless network interfaces 550, one or more input/output interfaces 540, and/or one or more operating systems 521, such as Windows, mac OS, unix, linux, freeBSD, etc.
Input-output interface 540 may be used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the electronic device 500. In one example, input/output interface 540 includes a network adapter (Network Interface Controller, NIC) that may be connected to other network devices via a base station to communicate with the internet. In one example, the input/output interface 540 may be a Radio Frequency (RF) module for communicating with the internet wirelessly.
The power supply 550 may be logically connected to the processor 510 through a power management system, so that functions of managing charging, discharging, and power consumption management are implemented through the power management system.
It will be appreciated by those of ordinary skill in the art that the configuration shown in fig. 5 is merely illustrative and is not intended to limit the configuration of the electronic device described above. For example, electronic device 500 may also include more or fewer components than shown in FIG. 5, or have a different configuration than shown in FIG. 5.
The embodiment of the application also provides a computer storage medium, wherein at least one instruction or at least one section of program is stored in the computer storage medium, and the at least one instruction or the at least one section of program is loaded and executed by a processor to realize the firmware upgrading method.
Alternatively, in this embodiment, the storage medium may be located in at least one network server among a plurality of network servers of the computer network. Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a usb disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The embodiment of the present application further provides an electronic device, where the electronic device at least includes a processor 510 and a memory 530, where at least one instruction or at least one program is stored in the memory 530, and the at least one instruction or at least one program is loaded by the processor 510 and executes the firmware upgrade method described above.
As can be seen from the above embodiments of the firmware upgrading method, device, medium and electronic device provided by the present application, the present application obtains an upgrade file corresponding to a firmware to be upgraded; wherein the upgrade file comprises multi-frame data; backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing first block data in the first frame data with null data to obtain first target frame data; storing the first target frame data in a flash memory; storing the rest frame data in the upgrade file into a flash memory; when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on the target address; the target address is the storage address corresponding to the empty data in the flash memory. The memory space can be saved, the firmware upgrading process is simplified, the fault tolerance rate of firmware upgrading is improved, and meanwhile, the integrity of firmware upgrading is ensured; if power failure occurs in the upgrading process, aiming at the firmware to be upgraded which is not upgraded, the upgrading file does not need to be written into the flash memory again.
It should be noted that: the sequence of the embodiments of the present application is only for description, and does not represent the advantages and disadvantages of the embodiments. And the foregoing description has been directed to specific embodiments of this specification. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the apparatus embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments in part.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The foregoing description of the preferred embodiments of the application is not intended to limit the application to the precise form disclosed, and any such modifications, equivalents, and alternatives falling within the spirit and scope of the application are intended to be included within the scope of the application.

Claims (10)

1. A method of firmware upgrade, the method comprising:
acquiring an upgrade file corresponding to firmware to be upgraded; the upgrade file comprises multi-frame data;
backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing the first block data in the first frame data with null data to obtain first target frame data; the first block data is stack top data of the upgrade file or entry address data of the firmware to be upgraded;
Storing the first target frame data in a flash memory;
storing the rest frame data in the upgrade file into the flash memory;
when the storage of the residual frame data is determined to be completed, storing the first block of data in the memory into the flash memory based on a target address; and the target address is a storage address corresponding to the empty data in the flash memory.
2. The method of claim 1, wherein prior to performing the step of storing the first block of data in the memory into the flash memory based on a target address, the method further comprises:
acquiring candidate block data from the memory; the candidate block data is any block data in the multiple blocks of data in the memory;
Checking whether the candidate block data is the first block data of the upgrade file;
And under the condition that the candidate block data is determined to be the first block data of the upgrade file, executing the step of storing the first block data in the memory into the flash memory based on a target address.
3. The method of claim 1 or 2, wherein storing the first target frame data in flash memory comprises:
determining a firmware storage address of the firmware to be upgraded in the flash memory;
Erasing the data stored in the firmware storage address under the condition that the firmware storage address stores the data;
Storing the first target frame data in the firmware memory address in the flash memory; the firmware memory address includes the target address.
4. The method according to claim 1 or 2, wherein before performing the step of backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further comprises:
Checking the first frame data to obtain a first frame check value;
And under the condition that the first frame check value meets the preset first frame check value, executing the step of backing up the first block data of the first frame data in the upgrade file in the memory.
5. The method according to claim 1 or 2, wherein the first block data is used to identify the upgrade file;
Before backing up the first block of data of the first frame of data in the upgrade file in the memory, the method further includes:
determining a minimum writable unit of the flash memory;
based on the number of bytes of the minimum writable unit, the number of bytes of the first block of data is determined.
6. The method of claim 1 or 2, wherein after storing the first block of data in the memory into the flash memory based on a target address, the method further comprises:
identifying the first block of data in the flash memory;
and under the condition that the first block data is identified, determining that the firmware to be upgraded is successfully upgraded.
7. The method according to claim 1 or 2, wherein storing the remaining frame data in the upgrade file into the flash memory comprises:
And storing the rest frame data in the upgrade file into the flash memory frame by frame.
8. A firmware upgrade apparatus, the apparatus comprising:
the first acquisition module is used for acquiring an upgrade file corresponding to the firmware to be upgraded; the upgrade file comprises multi-frame data;
The first processing module is used for backing up a first block of data of a first frame of data in the upgrade file in a memory; replacing the first block data in the first frame data with null data to obtain first target frame data; the first block data is stack top data of the upgrade file or entry address data of the firmware to be upgraded;
the first storage module is used for storing the first target frame data in the flash memory;
the second storage module is used for storing the rest frame data in the upgrade file into the flash memory;
The third storage module is used for storing the first block of data in the memory into the flash memory based on a target address when the storage of the residual frame data is determined to be completed; and the target address is a storage address corresponding to the empty data in the flash memory.
9. A computer storage medium having stored therein at least one instruction or at least one program loaded by a processor and performing the firmware upgrade method of any of claims 1-7.
10. An electronic device comprising a processor and a memory, wherein the memory has stored therein at least one instruction or at least one program, the at least one instruction or the at least one program being loaded by the processor and executing the firmware upgrade method of any one of claims 1-7.
CN202211194151.6A 2022-09-28 2022-09-28 Firmware upgrading method, device, medium and electronic equipment Active CN115437674B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211194151.6A CN115437674B (en) 2022-09-28 2022-09-28 Firmware upgrading method, device, medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211194151.6A CN115437674B (en) 2022-09-28 2022-09-28 Firmware upgrading method, device, medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN115437674A CN115437674A (en) 2022-12-06
CN115437674B true CN115437674B (en) 2024-04-30

Family

ID=84251873

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211194151.6A Active CN115437674B (en) 2022-09-28 2022-09-28 Firmware upgrading method, device, medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN115437674B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104007996A (en) * 2014-06-16 2014-08-27 南京融教科技有限公司 Reliable firmware upgrading realizing method for distributed control system
CN108572848A (en) * 2018-06-26 2018-09-25 深圳市未来感知科技有限公司 The bottom firmware on line upgrading method, apparatus and storage medium of interactive system
CN109284117A (en) * 2018-09-26 2019-01-29 深圳市慧嘉智科技有限公司 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller
CN111966385A (en) * 2020-06-24 2020-11-20 上海昊博影像科技有限公司 Flat panel detector online upgrading method, flat panel detector and upper computer
CN113238789A (en) * 2021-05-27 2021-08-10 闻泰通讯股份有限公司 Electronic equipment, firmware upgrading method and device thereof and computer readable storage medium
CN114020521A (en) * 2021-09-22 2022-02-08 北京空间飞行器总体设计部 Device and method for realizing satellite-borne data backup based on RMAP protocol
WO2022142153A1 (en) * 2020-12-31 2022-07-07 威胜集团有限公司 Electricity meter upgrading method and system, smart meter, and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104007996A (en) * 2014-06-16 2014-08-27 南京融教科技有限公司 Reliable firmware upgrading realizing method for distributed control system
CN108572848A (en) * 2018-06-26 2018-09-25 深圳市未来感知科技有限公司 The bottom firmware on line upgrading method, apparatus and storage medium of interactive system
CN109284117A (en) * 2018-09-26 2019-01-29 深圳市慧嘉智科技有限公司 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller
CN111966385A (en) * 2020-06-24 2020-11-20 上海昊博影像科技有限公司 Flat panel detector online upgrading method, flat panel detector and upper computer
WO2022142153A1 (en) * 2020-12-31 2022-07-07 威胜集团有限公司 Electricity meter upgrading method and system, smart meter, and storage medium
CN113238789A (en) * 2021-05-27 2021-08-10 闻泰通讯股份有限公司 Electronic equipment, firmware upgrading method and device thereof and computer readable storage medium
CN114020521A (en) * 2021-09-22 2022-02-08 北京空间飞行器总体设计部 Device and method for realizing satellite-borne data backup based on RMAP protocol

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Efficient Partial Firmware Update for IoT Devices with Lua Scripting Interface;Marek Novak等;《2019 29th International Conference Radioelektronika (RADIOELEKTRONIKA)》;20190610;1-4 *
基于WiFi的STM32固件远程升级系统;陈以安等;《单片机与嵌入式系统应用》;20220701;46-50 *

Also Published As

Publication number Publication date
CN115437674A (en) 2022-12-06

Similar Documents

Publication Publication Date Title
CN110083374B (en) Upgrade rollback method, system and terminal equipment
CN110597542B (en) Software automatic OTA (over the air) upgrading method and device and electronic equipment
CN106020875B (en) Firmware update management method and device of embedded terminal
CN105094927A (en) Equipment firmware updating method and device
CN103106083B (en) A kind of loading method of firmware and device
EP3879399A1 (en) Method and apparatus for upgrading vehicle-mounted tbox, device, and storage medium
CN108345464A (en) A kind of the startup method and Android vehicle device of Android system
CN111309354A (en) OTA (over the air) upgrading method and device of networking equipment
CN111316235A (en) Method for starting system, electronic device and machine-readable storage medium
CN109002305B (en) Method and system for updating equipment program
CN114840242A (en) System upgrading method and device of electronic equipment and readable storage medium
CN114138295A (en) Method, device and system for upgrading application program firmware of electronic equipment
CN115437674B (en) Firmware upgrading method, device, medium and electronic equipment
CN111984287A (en) Equipment upgrading method and system
CN115827069A (en) Starting control method, system and device for server mainboard
CN114546455A (en) MCU software upgrading method and device for double partitions
CN115658152A (en) Firmware upgrading method, firmware, electronic device and computer readable storage medium
EP4086756A1 (en) Method and apparatus for processing virtual machine component
CN114995854A (en) Application program online upgrading method and device, terminal and operation machine
CN113377425A (en) BMC firmware generation method and device, BMC starting method and device and storage medium
CN114237722A (en) System starting method, device, equipment and engineering vehicle
CN112667444A (en) System upgrading method, storage medium and terminal equipment
CN111190627A (en) System upgrading method and device
CN112631637B (en) OTA upgrading method, system, equipment and storage medium based on RTOS
CN114430565B (en) Method and device for starting equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant