CN117608627A - Method for upgrading firmware, electronic device and storage medium - Google Patents

Method for upgrading firmware, electronic device and storage medium Download PDF

Info

Publication number
CN117608627A
CN117608627A CN202311656714.3A CN202311656714A CN117608627A CN 117608627 A CN117608627 A CN 117608627A CN 202311656714 A CN202311656714 A CN 202311656714A CN 117608627 A CN117608627 A CN 117608627A
Authority
CN
China
Prior art keywords
firmware
upgrade
upgrading
mode
partition
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311656714.3A
Other languages
Chinese (zh)
Inventor
纪大峣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Rockchip Electronics Co Ltd
Original Assignee
Rockchip Electronics 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 Rockchip Electronics Co Ltd filed Critical Rockchip Electronics Co Ltd
Priority to CN202311656714.3A priority Critical patent/CN117608627A/en
Publication of CN117608627A publication Critical patent/CN117608627A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/658Incremental updates; Differential updates

Landscapes

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

Abstract

The invention discloses a method for upgrading firmware, electronic equipment and a storage medium. The method comprises the following steps: acquiring a firmware upgrade package, wherein the firmware upgrade package comprises a complete image file of upgrade mode firmware and complete firmware image files of all dependent firmware in a dependent firmware list of the upgrade mode firmware; reading a complete image file of the upgrade mode firmware in the firmware upgrade package, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to an upgrade mode temporary storage partition set in a device partition table; upgrading each dependent firmware in the dependent firmware list of the upgrade mode firmware; copying the firmware upgrade package which is currently upgraded to a preset path of a firmware repair partition which is set in the equipment partition table so as to cover a firmware upgrade complete package under the preset path of the firmware repair partition. The invention can improve the upgrading reliability.

Description

Method for upgrading firmware, electronic device and storage medium
Technical Field
The present invention relates to the field of embedded devices, and in particular, to a method for upgrading firmware, an electronic device, and a storage medium.
Background
Upgrade mode firmware refers to firmware that actually performs a firmware upgrade, such as recovery firmware. The dependent firmware of the upgrade mode firmware refers to all relevant firmware involved in boot-loading the upgrade mode firmware during boot-up, including but not limited to: boot strap firmware (e.g., u-boot firmware) at each level, firmware relied upon during the running of upgrade mode firmware (e.g., ARM trusted firmware, ARM Trusted Firmware). The dependent firmware list of the upgrade mode firmware is a list made up of all the dependent firmware of the upgrade mode firmware. The boot communication partition is a bare partition for communicating between the system, boot strap firmware, and upgrade mode firmware.
In the prior art, when a dependent firmware list of upgrade mode firmware is upgraded, if accidents occur in the process of upgrading the dependent firmware contained in the dependent firmware list, the dependent firmware is damaged, and the equipment is changed. Even if the upgrade of the dependent firmware list of the upgrade mode firmware does not happen accidentally, the upgrade of the upgrade mode firmware itself happens accidentally, or the dependency firmware list of the upgrade mode firmware with different versions is potentially mismatched with the upgrade mode firmware, the equipment is changed into a brick, so that the upgrade cannot be continued.
Disclosure of Invention
The invention provides a method for upgrading firmware, electronic equipment and a storage medium, which can improve the reliability of upgrading.
In one aspect of the invention, a method of upgrading firmware is provided. The method comprises the following steps: acquiring a firmware upgrade package, wherein the firmware upgrade package comprises a complete image file of upgrade mode firmware and complete firmware image files of all dependent firmware in a dependent firmware list of the upgrade mode firmware; reading a complete image file of the upgrade mode firmware in the firmware upgrade package, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to an upgrade mode temporary storage partition set in a device partition table; upgrading each dependent firmware in the dependent firmware list of the upgrade mode firmware; copying the firmware upgrade package which is currently upgraded to a preset path of a firmware repair partition which is set in the equipment partition table so as to cover a firmware upgrade complete package under the preset path of the firmware repair partition.
In yet another aspect of the present invention, an electronic device is provided. The electronic device includes a memory configured to store an executable program; and a processor configured to execute the program to perform the method of upgrading firmware described above.
In yet another aspect of the invention, a computer-readable medium is provided. The medium has stored thereon a computer program to be executed by a processor to implement the method of upgrading firmware described above.
According to the invention, the read complete image file of the upgrade mode firmware is written into the block equipment node corresponding to the upgrade mode temporary storage partition set in the equipment partition table, each dependent firmware and the upgrade mode firmware in the dependency firmware list of the upgrade mode firmware are upgraded, the current upgrade firmware upgrade package is copied to the preset path of the firmware repair partition set in the equipment partition table so as to cover the firmware upgrade complete package under the preset path of the firmware repair partition, and in the upgrade process, even if the equipment is changed due to accidents, the upgrade mode temporary storage partition is used for loading the guide upgrade mode firmware, so that the upgrade mode firmware which can normally work always exists is ensured, and if the equipment cannot automatically recover to a normal state due to upgrade failure, the complete firmware upgrade package in the firmware repair partition can be used for recovering the system to the state of successful upgrade of the last complete package, thereby improving the upgrade reliability.
Drawings
FIG. 1 is a flow chart of steps of a method of upgrading firmware according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method for upgrading firmware according to an embodiment of the invention;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to describe the technical contents, the achieved objects and effects of the present invention in detail, the following description will be made with reference to the embodiments in conjunction with the accompanying drawings.
A firmware upgrade method using a firmware upgrade mode has been proposed in the prior art, and generally has the following problems. Most of the methods cause damage to the dependent firmware if accidents occur in the process of upgrading the dependent firmware contained in the dependent firmware list when upgrading the dependent firmware list of the firmware in the upgrading mode, so that the equipment becomes brick and cannot be continuously upgraded. For example, unexpected power failure in the process of upgrading the boot strap firmware in the dependency firmware list of the upgrade mode firmware will cause damage to the boot strap firmware, and then the boot strap firmware cannot be normally operated after the power is turned on again, so that the upgrade mode firmware cannot be normally booted through the boot strap firmware.
In order to solve the problem of equipment brick change possibly existing when the dependent firmware list of the firmware in the upgrade mode is upgraded, one method is that the dependent firmware list of the firmware in the upgrade mode is not upgraded after the equipment leaves the factory, and although the method can solve the problem of potential equipment brick change, when the dependent firmware list of the firmware in the upgrade mode is required to be upgraded in some scenes, the problem existing in the dependent firmware cannot be solved.
In addition, the other method allows the upgrade of the dependent firmware list of the upgrade mode firmware, and simultaneously solves the problem of equipment brick change possibly existing when the upgrade mode firmware is upgraded, but cannot solve the problem of equipment brick change caused by accidents when the upgrade mode firmware is upgraded, and cannot solve the problem of equipment brick change caused by mismatch existing between the dependent firmware list of the upgrade mode firmware with different potential versions and the upgrade mode firmware. For example, in the firmware upgrading process, the upgrading of the dependent firmware list of the upgrading mode firmware is normally completed, but the upgrading of the upgrading mode firmware is not completed or is performed, at this time, the corresponding dependent firmware in the device is the new version firmware, but the upgrading mode firmware is the old version firmware, if accidents occur at this time, the new version dependent firmware is booted and loaded after being powered up again, and if the new version dependent firmware and the old version upgrading mode firmware have a matching problem, the old version upgrading mode firmware is likely to continuously crash and restart when running, and cannot work normally.
The existing firmware upgrading method cannot automatically restore the current equipment to a normal state when the upgrading fails and the resume upgrading is unsuccessful. For example, when an accident occurs in the process of differential upgrading and the continuous differential upgrading cannot succeed, the equipment is always in a state of prompting upgrading failure, and the system can be restored to a normal state only through manual intervention.
In order to solve at least the above technical problems, the present disclosure provides a method of upgrading firmware. According to the method, the read complete image file of the upgrade mode firmware is written into a block device node corresponding to the upgrade mode temporary storage partition set in the device partition table, each dependent firmware in the dependency firmware list of the upgrade mode firmware and the upgrade mode firmware are upgraded, and the current upgrade firmware upgrade package is copied to a preset path of the firmware repair partition set in the device partition table so as to cover the firmware upgrade complete package under the preset path of the firmware repair partition. In this way, in the upgrading process, even if the equipment changes bricks due to accidents, the upgrading mode temporary storage partition can be used for loading and guiding the upgrading mode firmware, so that the situation that the upgrading mode firmware capable of normally working is always available is ensured, and if the equipment cannot automatically recover to a normal state due to upgrading failure, a complete firmware upgrading package in the firmware repairing partition can be used for recovering the system to a state that the last complete package is successfully upgraded, thereby improving the upgrading reliability.
Hereinafter, a technical scheme according to the present disclosure will be described with reference to specific embodiments and with reference to the accompanying drawings.
Fig. 1 is a flowchart illustrating a method 100 of upgrading firmware according to an embodiment of the present disclosure. Referring to fig. 1, the method 100 includes the following steps 102-108.
In step 102, a firmware upgrade package is obtained, where the firmware upgrade package includes a complete image file of upgrade mode firmware and complete firmware image files of each dependent firmware in a dependent firmware list of the upgrade mode firmware.
In step 104, the complete image file of the upgrade mode firmware in the firmware upgrade package is read, and the read complete image file of the upgrade mode firmware is written into the block device node corresponding to the upgrade mode temporary storage partition set in the device partition table.
In step 106, each of the dependent firmware in the dependent firmware list of the upgrade mode firmware and the upgrade mode firmware are upgraded.
In step 108, the firmware upgrade package currently upgraded is copied to a preset path of the firmware repair partition set in the device partition table, so as to cover a firmware upgrade complete package under the preset path of the firmware repair partition.
In some embodiments, the method 100 may further comprise, prior to step 102: the upgrade mode temporary storage partition and the firmware repair partition are additionally arranged on the equipment partition table, the upgrade mode temporary storage partition is used for storing new version upgrade mode firmware, and the firmware repair partition is used for storing complete firmware upgrade package.
In some embodiments, obtaining the firmware upgrade package by a firmware upgrade client and verifying the legitimacy of the firmware upgrade package; if the verification is legal, writing a preset firmware upgrading instruction in a first preset position in a guiding communication partition, setting upgrading instruction additional information based on the firmware upgrading packet, and writing the upgrading instruction additional information in a second preset position in the guiding communication partition; restarting the device, and guiding the device to enter a firmware upgrade mode based on a first preset position and a second preset position in the guiding communication partition; and in the firmware upgrade mode, performing firmware upgrade on the upgrade mode firmware and the dependent firmware in the firmware upgrade package based on the upgrade mode temporary storage partition and the firmware repair partition. In this way, whether the current firmware needs to be upgraded can be judged by presetting the firmware upgrading instruction, and the security of the firmware upgrading is ensured by checking the validity of the firmware upgrading package.
In some embodiments, setting a firmware upgrade package path as a path in which the firmware upgrade package is located; setting an upgrade mode guide area as an upgrade mode firmware partition; setting the pilot retry number as a preset pilot retry number; and generating additional information of the upgrade instruction according to the firmware upgrade package path, the upgrade mode guide area and the guide retry number. In this way, the subsequent firmware upgrade package path, upgrade mode boot area, and boot retry number in the additional information based on the upgrade instruction can complete an efficient firmware upgrade.
In some embodiments, in starting a boot program firmware, determining whether the first preset location in the boot communication partition has the preset firmware upgrade instruction; if not, guiding the equipment according to a preset flow; if yes, the equipment is guided to enter a firmware upgrading mode according to the upgrading instruction additional information of the second preset position in the guiding communication partition.
In some embodiments, determining whether the upgrade mode boot area in the upgrade instruction attachment information of the second preset location in the boot communication partition is the upgrade mode firmware partition; if yes, the number of the guide retries in the additional information of the upgrade instruction is reduced by one, whether the number of the guide retries in the additional information of the upgrade instruction is larger than a first preset value is judged, if yes, the upgrade mode firmware is loaded from the upgrade mode firmware partition, and the equipment is guided to enter a firmware upgrade mode; if the updating mode firmware is not greater than the updating mode firmware, setting the updating mode guide area in the updating instruction additional information as the updating mode temporary storage partition, loading the updating mode firmware from the updating mode temporary storage partition, and guiding the equipment to enter a firmware updating mode; if not, judging whether the upgrade mode guide area in the upgrade instruction additional information is the upgrade mode temporary storage partition, and if so, loading the upgrade mode firmware from the upgrade mode temporary storage partition to guide the equipment to enter a firmware upgrade mode; and if the updating mode is not the temporary storage partition of the updating mode, loading the updating mode firmware from the updating mode firmware partition, and guiding the equipment to enter a firmware updating mode. In this way, after the firmware upgrade is started to enter the firmware upgrade mode, the new version upgrade mode firmware contained in the firmware upgrade package is upgraded to the upgrade mode temporary storage partition, and meanwhile, when the boot firmware cannot be loaded from the upgrade mode firmware partition normally in the boot firmware is started, the boot upgrade mode firmware is loaded from the upgrade mode temporary storage partition, so that the situation that one upgrade mode firmware capable of working normally exists always is ensured, and the equipment brick changing problem caused by accidents when the upgrade mode firmware is upgraded per se and the equipment brick changing problem caused by mismatch between a dependence firmware list of the upgrade mode firmware of different potential versions and the upgrade mode firmware are solved.
In some embodiments, the complete firmware image file of each dependent firmware in the list of dependent firmware of the upgrade mode firmware includes at least two identical pieces of firmware data. In some embodiments, the firmware data is a preset firmware size (e.g., 1 MB) that is aligned with a multiple of a minimum write unit of the boot storage medium, and the preset firmware size of the different firmware data is the same or different. In this way, even if accidents occur in the upgrading process, only a certain part of firmware data in the dependent firmware is damaged, a part of firmware data capable of working normally always exists, equipment is guided by guiding the part of firmware data capable of working normally, starting and guiding can be completed always, the firmware in an upgrading mode is loaded normally, and the equipment is guided to enter the firmware upgrading mode to be upgraded continuously, so that the reliability of firmware upgrading is improved.
In some embodiments, loading the upgrade mode firmware, booting the device into a firmware upgrade mode includes: acquiring a start address and an end address of a physical partition corresponding to each dependent firmware, and setting the start address of firmware data as the start address of the physical partition corresponding to each dependent firmware; reading a firmware head, magic number, firmware body size, digital digest algorithm type and firmware body digital digest value of a preset size from the starting address of the firmware data; judging whether the magic number is a preset magic number or not; if yes, starting from the initial position of the firmware body behind the firmware head, reading data with the length of the firmware body, and calculating according to the type of the digital digest algorithm to obtain a digital digest of the firmware body; judging whether the calculated firmware body digital abstract is the same as the firmware body digital abstract value; if the firmware volume data is the same, the firmware volume data corresponding to the firmware data is read to a preset starting loading address by using the firmware data guide, and the execution is carried out by jumping to the preset starting loading address; if not, repositioning the starting address of the firmware data according to the starting address of the old firmware data and the preset firmware size, and judging whether the sum of the starting address of the repositioned firmware data and the preset firmware size is larger than the ending address of the physical partition corresponding to the dependent firmware; if the number is larger than the preset number, reporting an error, and stopping guiding; and if the digital digest algorithm type is not greater than the initial address of the firmware data, returning to execute the step of reading the firmware head, the magic number, the firmware volume size, the digital digest algorithm type and the firmware volume digital digest value with preset sizes. In this way, there is always a piece of firmware data that can work normally, the device is booted by booting the piece of firmware data that can work normally, boot booting can always be completed, the firmware in the upgrade mode is loaded normally, and the device is booted to enter the firmware upgrade mode to continue upgrade, thereby improving the reliability of firmware upgrade.
In some embodiments, in the firmware upgrade mode, determining whether the preset firmware upgrade instruction exists at the first preset position in the boot communication partition, and if not, exiting a firmware upgrade procedure; if yes, setting the guide retry number in the upgrade instruction additional information as the preset guide retry number; reading a complete image file of the upgrade mode firmware in the firmware upgrade package from the firmware upgrade package path in the upgrade instruction additional information, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode temporary storage partition; upgrading all firmware except the firmware in the upgrading mode to obtain a first upgrading result; if the first upgrading result is that the upgrading fails, recovering the system based on the complete firmware upgrading packet under the preset path of the firmware repairing partition; if the first upgrading result is that the upgrading is successful, upgrading the firmware in the upgrading mode to obtain a second upgrading result; if the second upgrading result is that the upgrading fails, recovering the system based on the complete firmware upgrading packet under the preset path of the firmware repairing partition; if the second upgrading result is that the upgrading is successful, judging whether to update the complete firmware upgrading package recovery system under the preset path of the firmware repairing partition based on the firmware upgrading package. In this way, when the firmware upgrade fails, for example, accidents occur in the process of differential upgrade, and the scene that the differential upgrade is continued and the upgrade cannot be successful is adopted, the complete firmware upgrade package under the preset path of the firmware repair partition can be used for upgrading the system, the system is restored to the state that the last complete firmware upgrade package is successfully upgraded, and the reliability of the upgrade is ensured.
In some embodiments, the complete firmware image file of each dependent firmware in the dependent firmware list of the upgrade mode firmware is sequentially read from the firmware upgrade package, and the complete firmware image file of each dependent firmware is updated to a block device node corresponding to the dependent firmware, so as to complete the upgrade of the dependent firmware; in the process of upgrading the dependent firmware, if any dependent firmware fails to upgrade, determining that a first upgrading result is failed to upgrade, otherwise, upgrading other firmware except the upgrading mode firmware and the dependent firmware list of the upgrading mode firmware in the firmware upgrading package; in the process of upgrading the other firmware, if any other firmware fails to upgrade, determining that a first upgrade result is failed upgrade, otherwise, determining that the first upgrade result is successful upgrade. In this way, as long as any dependent firmware or other firmware fails to upgrade, the upgrade is deemed unsuccessful, thereby ensuring the effectiveness of the firmware upgrade.
In some embodiments, reading a complete image file of the upgrade mode firmware from the firmware upgrade package, and writing the complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode firmware partition to complete upgrade of the upgrade mode firmware; in the upgrading process of the firmware in the upgrading mode, if the upgrading fails, determining that the second upgrading result is the upgrading failure, otherwise, determining that the second upgrading result is the upgrading success.
In some embodiments, determining whether the firmware upgrade package is subjected to a preset conversion process according to the firmware upgrade package path in the upgrade instruction additional information; restarting the equipment to enter an upgraded system if the equipment is subjected to preset conversion treatment; if the firmware upgrade package is not subjected to the preset conversion treatment, judging whether the firmware upgrade package is a complete package or not; if the firmware upgrading packet is the complete packet, copying the firmware upgrading packet of the current upgrade to a preset path of the firmware repairing partition according to the firmware upgrading packet path indicated by the firmware upgrading packet path in the upgrading instruction additional information so as to cover the complete firmware upgrading packet under the preset path of the firmware repairing partition, and restarting the equipment to enter an upgraded system; if the packet is not the complete packet, restarting the equipment to enter the upgraded system. In this way, in the upgrading process, the original complete firmware upgrading packet which is not subjected to conversion processing is copied to the preset path of the firmware repairing partition, the complete firmware upgrading packet under the preset path of the firmware repairing partition is covered, the firmware repairing partition is ensured to always store the original complete firmware upgrading packet, and the upgrading reliability is ensured.
In some embodiments, judging whether the packet name of the firmware upgrade packet is a preset conversion name according to the firmware upgrade packet path in the upgrade instruction additional information; if yes, determining that the firmware upgrade package is subjected to preset conversion treatment; if not, determining that the firmware upgrade package does not undergo preset conversion processing. In this way, whether the package has undergone the preset conversion processing can be simply and quickly determined using the package name of the firmware upgrade package.
In some embodiments, determining whether the upgrade instruction file in the firmware upgrade package includes one or more differential algorithms in a preset differential algorithm list; if so, determining the firmware upgrade package as a differential package; and if not, determining the firmware upgrade package as a complete package. In this way, whether the firmware upgrade package is a complete package or not is judged through the upgrade instruction file in the firmware upgrade package, so that the method is faster and more efficient.
In some embodiments, upgrade failure information is output, and system recovery confirmation information corresponding to the upgrade failure information is obtained; if the system recovery confirmation information is that the system is not recovered, outputting upgrading failure information and exiting the firmware upgrading process; if the system recovery confirmation information is a recovery system, the complete firmware upgrade package under the preset path of the firmware repair partition is used for upgrading the system so as to recover the system to a state that the last complete package upgrade is successful; and clearing the preset firmware upgrading instruction in the first preset position and the upgrading instruction additional information in the second preset position in the guiding communication partition, and restarting the equipment to enter the upgraded system. In this way, when the upgrade fails, the user is prompted, the user can select whether the system needs to be restored or not by himself, if so, the complete firmware upgrade package under the preset path of the partition can be restored by using the firmware, the problem that unexpected equipment cannot be restored to a normal state during the upgrade is avoided, and the reliability of the firmware upgrade is improved.
In some embodiments, the preset firmware upgrade instructions in the first preset location and the upgrade instruction additional information in the second preset location in the boot communication partition are cleared, and the device is restarted to enter the upgraded system. In this way, preparation is made for the next firmware upgrade.
Hereinafter, application scenarios of a method and apparatus for upgrading firmware according to an embodiment of the present invention will be described by way of example.
Fig. 2 is a flowchart illustrating a method of upgrading firmware according to an embodiment of the present invention, including the following steps 201 to 207.
In step 201, an upgrade mode temporary storage partition (e.g., recovery_tmp) for storing a new version of upgrade mode firmware and a firmware repair partition (e.g., fail_restore) for storing a complete firmware upgrade package are added to the device partition table.
In step 202, a firmware upgrade package is obtained by a firmware upgrade client.
In step 203, it is checked whether the firmware upgrade package is legal, if the check is illegal, the firmware upgrade process is exited, and if the check is legal, step 204 is executed.
The firmware upgrade package includes a complete image file (e.g., recovery. Img) of the upgrade mode firmware and a complete firmware image file of each of the dependent firmware in the dependency firmware list of the upgrade mode firmware. The complete firmware image file of each dependent firmware in the dependent firmware list of the upgrade mode firmware contains at least two identical firmware data.
Each firmware data consists of a firmware head part, a firmware body and filling data with preset sizes: the firmware header contains a preset magic number, firmware body size, digital digest algorithm type, and firmware body digital digest value. The firmware body size represents the size of the firmware body, and the firmware body digital digest value represents a digital digest value calculated for the firmware body using an algorithm specified by the type of digital digest algorithm. The firmware body is located behind a firmware header of a preset size. When the firmware header of the preset size and the firmware body size are smaller than the preset firmware size, the firmware body is filled with preset data of the size of the firmware header of the preset firmware size and the firmware body size.
At step 204, a preset firmware upgrade instruction is written at a first preset location in the boot communication partition.
In step 205, upgrade instruction additional information is set based on the firmware upgrade package, and the upgrade instruction additional information is written into a second preset location in the boot communication partition.
Setting upgrade instruction additional information based on the firmware upgrade package, specifically including the following (1) - (4):
(1) Setting a firmware upgrade package path as a path (such as/cache/update. Zip) where the firmware upgrade package is located.
(2) The upgrade mode boot area is set to an upgrade mode firmware partition (e.g., recovery).
(3) The pilot retry number is set to a preset pilot retry number (e.g., 5).
(4) And generating additional information of the upgrade instruction according to the firmware upgrade package path, the upgrade mode guide area and the guide retry number.
At step 206, restarting the device, and guiding the device to enter a firmware upgrade mode based on the first preset position and the second preset position in the guiding communication partition, specifically including the following (1) - (4):
(1) And (3) in the boot program firmware, judging whether the first preset position in the boot communication partition has the preset firmware upgrading instruction, if not, booting the equipment according to a preset flow, and if so, executing the step (2).
(2) Judging whether the upgrade mode guide area in the upgrade instruction additional information of the second preset position in the guide communication partition is the upgrade mode firmware partition, if so, executing (3), and if not, executing (4).
(3) And subtracting one from the number of the guide retries in the additional information of the upgrading instruction, judging whether the number of the guide retries in the additional information of the upgrading instruction is larger than a first preset value, if so, executing (3-1), and if not, executing (3-2).
(3-1) loading the upgrade mode firmware from the upgrade mode firmware partition, directing the device to enter a firmware upgrade mode.
(3-2) setting the upgrade mode guide area in the upgrade instruction additional information as the upgrade mode temporary storage partition, and loading the upgrade mode firmware from the upgrade mode temporary storage partition to guide the device to enter a firmware upgrade mode.
(4) Judging whether the upgrade mode guide area in the upgrade instruction additional information is the upgrade mode temporary storage partition, if so, executing (4-1), and if not, executing (4-2).
(4-1) loading the upgrade mode firmware from the upgrade mode temporary storage partition, and directing the device to enter a firmware upgrade mode.
(4-2) loading the upgrade mode firmware from the upgrade mode firmware partition, directing the device to enter a firmware upgrade mode.
Wherein, loading the upgrade mode firmware, guiding the device to enter a firmware upgrade mode, and specifically comprising the following (1) - (6):
(1) And acquiring a start address and an end address of the physical partition corresponding to each dependent firmware, and setting the start address of the firmware data as the start address of the physical partition corresponding to each dependent firmware.
(2) And reading a firmware head, magic number, firmware volume size, digital digest algorithm type and firmware volume digital digest value of a preset size from the starting address of the firmware data.
(3) Judging whether the magic number is a preset magic number, if so, executing (4) - (5), and if not, executing (6).
(4) Starting from the initial position of the firmware body behind the firmware head, reading data with the length of the firmware body, and calculating according to the type of the digital digest algorithm to obtain a digital digest of the firmware body;
(5) Judging whether the calculated firmware body digital abstract is the same as the firmware body digital abstract, if so, using the firmware data to guide, reading the firmware body data corresponding to the firmware data to a preset starting loading address, jumping to the preset starting loading address for execution, and if not, executing (6).
(6) The starting address of the relocation firmware data is: and judging whether the sum of the initial address of the relocated firmware data and the preset firmware size is larger than the end address of the physical partition corresponding to the dependent firmware, if so, reporting an error, stopping booting, and if not, returning to the execution (2).
In step 207, in the firmware upgrade mode, firmware upgrade is performed on the upgrade mode firmware and the dependent firmware in the firmware upgrade package based on the upgrade mode temporary storage partition and the firmware repair partition, specifically including the following (1) - (8):
(1) In the firmware upgrading mode, judging whether the first preset position in the guiding communication partition has the preset firmware upgrading instruction, if not, exiting the firmware upgrading process, and if so, executing the step (2).
(2) Setting the guide retry number in the upgrade instruction additional information as the preset guide retry number.
(3) And reading the complete image file of the upgrade mode firmware in the firmware upgrade package from the firmware upgrade package path in the upgrade instruction additional information, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode temporary storage partition.
(4) And (3) upgrading all the firmware except the firmware in the upgrading mode to obtain a first upgrading result, if the first upgrading result is that the upgrading is failed, executing (5), and if the first upgrading result is that the upgrading is successful, executing (6).
Wherein, upgrading all firmware except the upgrade mode firmware to obtain a first upgrade result specifically includes the following (4-1) - (4-3):
(4-1) sequentially reading the complete firmware image file of each dependent firmware in the dependent firmware list of the upgrade mode firmware from the firmware upgrade package, and updating the complete firmware image file of each dependent firmware into a block device node corresponding to the dependent firmware to complete the upgrade of the dependent firmware.
(4-2) in the process of upgrading the dependent firmware, if any dependent firmware fails to upgrade, determining that a first upgrade result is upgrade failure, otherwise, upgrading other firmware except the upgrade mode firmware and the dependent firmware list of the upgrade mode firmware in the firmware upgrade package.
And (4-3) in the process of upgrading the other firmware, if any other firmware fails to upgrade, determining that a first upgrade result is failed upgrade, otherwise, determining that the first upgrade result is successful upgrade.
(5) And recovering the system based on the complete firmware upgrade package under the preset path of the firmware repair partition.
(6) And upgrading the firmware in the upgrading mode to obtain a second upgrading result, if the second upgrading result is that the upgrading is failed, executing (7), and if the second upgrading result is that the upgrading is successful, executing (8).
Wherein, upgrade the said upgrade mode firmware, get the second upgrade result to include the following (6-1) - (6-2) specifically:
(6-1) reading the complete image file of the upgrade mode firmware from the firmware upgrade package, and writing the complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode firmware partition, so as to complete the upgrade of the upgrade mode firmware.
And (6-2) in the upgrading process of the firmware in the upgrading mode, if the upgrading fails, determining that the second upgrading result is the upgrading failure, otherwise, determining that the second upgrading result is the upgrading success.
(7) The complete firmware upgrade package recovery system based on the preset path of the firmware repair partition specifically comprises the following (7-1) - (7-4):
(7-1) outputting upgrade failure information, and acquiring system recovery confirmation information corresponding to the upgrade failure information.
And (7-2) if the system recovery confirmation information is that the system is not recovered, outputting upgrading failure information and exiting the firmware upgrading process.
And (7-3) if the system recovery confirmation information is a recovery system, upgrading the system by using the complete firmware upgrade package under the preset path of the firmware repair partition so as to recover the system to a state that the last complete package upgrade is successful.
(7-4) clearing the preset firmware upgrade instruction in the first preset location and the upgrade instruction additional information in the second preset location in the boot communication partition, and restarting the device to enter the upgraded system.
(8) Judging whether to update the complete firmware upgrade package recovery system under the preset path of the firmware repair partition based on the firmware upgrade package, wherein the complete firmware upgrade package recovery system specifically comprises the following (8-1) - (8-5):
(8-1) judging whether the firmware upgrade package is subjected to preset conversion processing according to the firmware upgrade package path in the upgrade instruction additional information.
Specifically, whether the packet name of the firmware upgrade packet is a preset conversion name (such as block. Map) is judged according to the firmware upgrade packet path in the upgrade instruction additional information, if yes, the firmware upgrade packet is determined to be subjected to preset conversion processing, and if not, the firmware upgrade packet is determined to not be subjected to preset conversion processing.
And (8-2) restarting the equipment to enter an upgraded system if the equipment is subjected to preset conversion treatment.
And (8-3) if the preset conversion processing is not performed, judging whether the firmware upgrade package is a complete package.
Specifically, whether an upgrade instruction file (such as a system. Transfer. List) in the firmware upgrade package contains one or more differential algorithms in a preset differential algorithm list (such as imgdiff and bsdiff) is judged, if so, the firmware upgrade package is determined to be a differential package, and if not, the firmware upgrade package is determined to be a complete package.
And (8-4) if the firmware upgrade package is a complete package, copying the firmware upgrade package of the current upgrade to a preset path of the firmware repair partition according to the firmware upgrade package path indicated by the firmware upgrade package path in the upgrade instruction additional information so as to cover the complete firmware upgrade package under the preset path of the firmware repair partition, and restarting the device to enter the upgraded system.
And (8-5) restarting the equipment to enter an upgraded system if the equipment is not a complete packet.
Specifically, the preset firmware upgrading instruction in the first preset position and the upgrading instruction additional information in the second preset position in the guiding communication partition are cleared, and the device is restarted to enter the upgraded system.
According to yet another aspect of the invention, FIG. 3 is a schematic diagram illustrating an apparatus 300 for upgrading firmware according to an embodiment of the invention. Referring to fig. 3, the electronic device 300 comprises a memory 302, a processor 304 and a computer program stored on said memory and executable on the processor, which processor, when executing said computer program, implements the steps of the method of upgrading firmware as described above.
According to yet another aspect of the present invention, a computer-readable medium is provided. The computer readable medium has stored thereon a computer program for execution by a processor to implement the method of upgrading firmware as described above.
In summary, the method, electronic device and storage medium for upgrading firmware provided by the invention writes the read complete image file of the upgrade mode firmware into the block device node corresponding to the upgrade mode temporary storage partition set in the device partition table, upgrades each dependent firmware and upgrade mode firmware in the dependency firmware list of the upgrade mode firmware, copies the current upgrade package of the upgraded firmware to the preset path of the firmware repair partition set in the device partition table to cover the complete package of the firmware upgrade under the preset path of the firmware repair partition, and in the upgrade process, even if the device changes brick due to accidents, the upgrade mode temporary storage partition can be used for loading the guide upgrade mode firmware, so that the upgrade mode firmware which can normally work always exists is ensured, and if the upgrade failure occurs, the device can not automatically recover to the normal state, and the complete firmware upgrade package in the firmware repair partition can be used for recovering the system to the successful state of the last complete package upgrade, thereby improving the upgrade reliability. In addition, the complete firmware image file of each dependent firmware in the dependent firmware list of the firmware in the upgrade mode contains at least two consistent firmware data, even if accidents occur in the upgrade process, only a certain part of firmware data in the dependent firmware is damaged, one part of firmware data capable of working normally always exists, the equipment is guided by guiding the firmware data capable of working normally, starting and guiding can be completed always, the firmware in the upgrade mode is loaded normally, the equipment is guided to enter the firmware upgrade mode to be upgraded continuously, and the reliability of firmware upgrade is further improved.
The foregoing description is only illustrative of the present invention and is not intended to limit the scope of the invention, and all equivalent changes made by the specification and drawings of the present invention, or direct or indirect application in the relevant art, are included in the scope of the present invention.

Claims (17)

1. A method of upgrading firmware, comprising:
acquiring a firmware upgrade package, wherein the firmware upgrade package comprises a complete image file of upgrade mode firmware and complete firmware image files of all dependent firmware in a dependent firmware list of the upgrade mode firmware;
reading a complete image file of the upgrade mode firmware in the firmware upgrade package, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to an upgrade mode temporary storage partition set in a device partition table;
upgrading each dependent firmware in the dependent firmware list of the upgrade mode firmware; and
copying the firmware upgrade package which is currently upgraded to a preset path of a firmware repair partition which is set in the equipment partition table so as to cover a firmware upgrade complete package under the preset path of the firmware repair partition.
2. The method as recited in claim 1, further comprising:
the upgrade mode temporary storage partition and the firmware repair partition are additionally arranged on the equipment partition table, the upgrade mode temporary storage partition is used for storing new version upgrade mode firmware, and the firmware repair partition is used for storing complete firmware upgrade package.
3. The method of claim 1, wherein obtaining a firmware upgrade package comprises: the firmware upgrading client acquires the firmware upgrading package and verifies the validity of the firmware upgrading package; if the verification is legal, writing a preset firmware upgrading instruction in a first preset position in the guiding communication partition, wherein the method further comprises the following steps:
setting upgrade instruction additional information based on the firmware upgrade package, and writing the upgrade instruction additional information into a second preset position in the guide communication partition;
restarting the device, and guiding the device to enter a firmware upgrade mode based on a first preset position and a second preset position in the guiding communication partition; and
and in the firmware upgrading mode, carrying out firmware upgrading on the upgrading mode firmware and the dependent firmware in the firmware upgrading packet based on the upgrading mode temporary storage partition and the firmware repairing partition.
4. The method of claim 3, wherein setting upgrade instruction additional information based on the firmware upgrade package comprises:
setting a firmware upgrade package path as a path in which the firmware upgrade package is located;
setting an upgrade mode guide area as an upgrade mode firmware partition;
setting the pilot retry number as a preset pilot retry number; and
and generating additional information of the upgrade instruction according to the firmware upgrade package path, the upgrade mode guide area and the guide retry number.
5. The method of claim 4, wherein directing the device to enter a firmware upgrade mode based on the first preset location and the second preset location in the boot communication zone comprises:
in the boot program firmware starting, judging whether the first preset position in the boot communication partition has the preset firmware upgrading instruction or not;
if not, guiding the equipment according to a preset flow; and
if yes, the equipment is guided to enter a firmware upgrading mode according to the upgrading instruction additional information of the second preset position in the guiding communication partition.
6. The method of claim 5, wherein directing the device into a firmware upgrade mode based on the upgrade instruction additional information for the second preset location in the boot communication partition comprises:
Judging whether the upgrade mode guide area in the upgrade instruction additional information of the second preset position in the guide communication partition is the upgrade mode firmware partition or not;
if yes, the number of the guide retries in the additional information of the upgrade instruction is reduced by one, whether the number of the guide retries in the additional information of the upgrade instruction is larger than a first preset value is judged, if yes, the upgrade mode firmware is loaded from the upgrade mode firmware partition, and the equipment is guided to enter a firmware upgrade mode;
if the updating mode firmware is not greater than the updating mode firmware, setting the updating mode guide area in the updating instruction additional information as the updating mode temporary storage partition, loading the updating mode firmware from the updating mode temporary storage partition, and guiding the equipment to enter a firmware updating mode;
if not, judging whether the upgrade mode guide area in the upgrade instruction additional information is the upgrade mode temporary storage partition, and if so, loading the upgrade mode firmware from the upgrade mode temporary storage partition to guide the equipment to enter a firmware upgrade mode; and
and if the updating mode is not the temporary storage partition of the updating mode, loading the updating mode firmware from the updating mode firmware partition, and guiding the equipment to enter a firmware updating mode.
7. The method of claim 6, wherein the complete firmware image file of each dependent firmware in the list of dependent firmware of the upgrade mode firmware comprises at least two pieces of identical firmware data;
loading the upgrade mode firmware, the booting the device into the firmware upgrade mode comprising:
acquiring a start address and an end address of a physical partition corresponding to each dependent firmware, and setting the start address of firmware data as the start address of the physical partition corresponding to each dependent firmware;
reading a firmware head, magic number, firmware body size, digital digest algorithm type and firmware body digital digest value of a preset size from the starting address of the firmware data;
judging whether the magic number is a preset magic number or not;
if yes, starting from the initial position of the firmware body behind the firmware head, reading data with the length of the firmware body, and calculating according to the type of the digital digest algorithm to obtain a digital digest of the firmware body;
judging whether the calculated firmware body digital abstract is the same as the firmware body digital abstract value;
if the firmware volume data is the same, the firmware volume data corresponding to the firmware data is read to a preset starting loading address by using the firmware data guide, and the execution is carried out by jumping to the preset starting loading address;
If not, repositioning the starting address of the firmware data according to the starting address of the old firmware data and the preset firmware size, and judging whether the sum of the starting address of the repositioned firmware data and the preset firmware size is larger than the ending address of the physical partition corresponding to the dependent firmware;
if the number is larger than the preset number, reporting an error, and stopping guiding; and
and if the digital digest algorithm type is not greater than the initial address of the firmware data, returning to execute the step of reading the firmware head, the magic number, the firmware volume size, the digital digest algorithm type and the firmware volume digital digest value with preset sizes.
8. The method of claim 4, wherein in the firmware upgrade mode, firmware upgrading the upgrade mode firmware and the dependent firmware in the firmware upgrade package based on the upgrade mode temporary storage partition and the firmware repair partition comprises:
in the firmware upgrading mode, judging whether the first preset position in the guiding communication partition has the preset firmware upgrading instruction, and if not, exiting the firmware upgrading flow;
if yes, setting the guide retry number in the upgrade instruction additional information as the preset guide retry number;
Reading a complete image file of the upgrade mode firmware in the firmware upgrade package from the firmware upgrade package path in the upgrade instruction additional information, and writing the read complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode temporary storage partition;
upgrading all firmware except the firmware in the upgrading mode to obtain a first upgrading result;
if the first upgrading result is that the upgrading fails, recovering the system based on the complete firmware upgrading packet under the preset path of the firmware repairing partition;
if the first upgrading result is that the upgrading is successful, upgrading the firmware in the upgrading mode to obtain a second upgrading result;
if the second upgrading result is that the upgrading fails, recovering the system based on the complete firmware upgrading packet under the preset path of the firmware repairing partition; and
if the second upgrading result is that the upgrading is successful, judging whether to update the complete firmware upgrading package recovery system under the preset path of the firmware repairing partition based on the firmware upgrading package.
9. The method of claim 8, wherein upgrading all firmware except the upgrade mode firmware to obtain a first upgrade result comprises:
Sequentially reading the complete firmware image file of each dependent firmware in the dependent firmware list of the upgrade mode firmware from the firmware upgrade package, and updating the complete firmware image file of each dependent firmware into a block device node corresponding to the dependent firmware to complete the upgrade of the dependent firmware;
in the process of upgrading the dependent firmware, if any dependent firmware fails to upgrade, determining that a first upgrading result is failed to upgrade, otherwise, upgrading other firmware except the upgrading mode firmware and the dependent firmware list of the upgrading mode firmware in the firmware upgrading package; and
in the process of upgrading the other firmware, if any other firmware fails to upgrade, determining that a first upgrade result is failed upgrade, otherwise, determining that the first upgrade result is successful upgrade.
10. The method of claim 8, wherein upgrading the upgrade mode firmware to obtain a second upgrade result comprises:
reading the complete image file of the upgrade mode firmware from the firmware upgrade package, and writing the complete image file of the upgrade mode firmware into a block device node corresponding to the upgrade mode firmware partition to complete upgrade of the upgrade mode firmware; and
In the upgrading process of the firmware in the upgrading mode, if the upgrading fails, determining that the second upgrading result is the upgrading failure, otherwise, determining that the second upgrading result is the upgrading success.
11. The method of claim 10, wherein determining whether to update the complete firmware upgrade package restoration system under the preset path of the firmware repair partition based on the firmware upgrade package comprises:
judging whether the firmware upgrade package is subjected to preset conversion processing according to the firmware upgrade package path in the upgrade instruction additional information;
restarting the equipment to enter an upgraded system if the equipment is subjected to preset conversion treatment;
if the firmware upgrade package is not subjected to the preset conversion treatment, judging whether the firmware upgrade package is a complete package or not;
if the firmware upgrading packet is the complete packet, copying the firmware upgrading packet of the current upgrade to a preset path of the firmware repairing partition according to the firmware upgrading packet path indicated by the firmware upgrading packet path in the upgrading instruction additional information so as to cover the complete firmware upgrading packet under the preset path of the firmware repairing partition, and restarting the equipment to enter an upgraded system; and
If the packet is not the complete packet, restarting the equipment to enter the upgraded system.
12. The method of claim 11, wherein determining whether the firmware upgrade package has undergone a preset conversion process according to the firmware upgrade package path in the upgrade instruction additional information comprises:
judging whether the packet name of the firmware upgrade packet is a preset conversion name according to the firmware upgrade packet path in the upgrade instruction additional information;
if yes, determining that the firmware upgrade package is subjected to preset conversion treatment; and
if not, determining that the firmware upgrade package does not undergo preset conversion processing.
13. The method of claim 11, wherein determining whether the firmware upgrade package is a complete package comprises:
judging whether an upgrade instruction file in the firmware upgrade package contains one or more differential algorithms in a preset differential algorithm list;
if so, determining the firmware upgrade package as a differential package; and
and if not, determining the firmware upgrade package as a complete package.
14. The method of claim 8, wherein the complete firmware upgrade package restoration system under a preset path based on the firmware repair partition comprises:
Outputting upgrade failure information, and acquiring system recovery confirmation information corresponding to the upgrade failure information;
if the system recovery confirmation information is that the system is not recovered, outputting upgrading failure information and exiting the firmware upgrading process;
if the system recovery confirmation information is a recovery system, the complete firmware upgrade package under the preset path of the firmware repair partition is used for upgrading the system so as to recover the system to a state that the last complete package upgrade is successful; and
and clearing the preset firmware upgrading instruction in the first preset position and the upgrading instruction additional information in the second preset position in the guiding communication partition, and restarting the equipment to enter the upgraded system.
15. The method of claim 11, wherein restarting the device into the upgraded system comprises:
and clearing the preset firmware upgrading instruction in the first preset position and the upgrading instruction additional information in the second preset position in the guiding communication partition, and restarting the equipment to enter the upgraded system.
16. An electronic device, comprising:
A memory configured to store an executable program; and
a processor configured to execute the program to perform the method of any one of claims 1 to 15.
17. A computer readable medium, on which a computer program is stored, characterized in that the computer program is executed to implement the method according to any one of claims 1 to 15.
CN202311656714.3A 2023-12-05 2023-12-05 Method for upgrading firmware, electronic device and storage medium Pending CN117608627A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311656714.3A CN117608627A (en) 2023-12-05 2023-12-05 Method for upgrading firmware, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311656714.3A CN117608627A (en) 2023-12-05 2023-12-05 Method for upgrading firmware, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN117608627A true CN117608627A (en) 2024-02-27

Family

ID=89949699

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311656714.3A Pending CN117608627A (en) 2023-12-05 2023-12-05 Method for upgrading firmware, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN117608627A (en)

Similar Documents

Publication Publication Date Title
TWI384367B (en) System of updating firmware and method thereof
KR100750132B1 (en) Method and system for booting, updating software automatically and recovering update error, and computer readable medium recording the method
US20110004871A1 (en) Embedded electronic device and firmware updating method thereof
US7971199B1 (en) Mobile device with a self-updating update agent in a wireless network
CN105260215A (en) Method of updating vehicle-mounted automobile data recorder terminal by USB flash disk
CN106775610B (en) Electronic equipment starting method and electronic equipment
US20170242685A1 (en) Updating of firmware
CN109634781B (en) Double-area backup image system based on embedded program and starting method
CN113157303A (en) Upgrading method, embedded system, terminal and computer storage medium
WO2015184732A1 (en) Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium
KR101601751B1 (en) Ecu of vehicle and boot software re-programming method thereof
CN111273928B (en) Bootloader design method for self-upgrading
JP2005284902A (en) Terminal device, control method and control program thereof, host device, control method and control program thereof, and method, system, and program for remote updating
JP3805195B2 (en) Program rewriting apparatus and program rewriting method
CN117608627A (en) Method for upgrading firmware, electronic device and storage medium
CN116909611A (en) Electronic device firmware updating method, cleaning device and storage medium
CN116301995A (en) Firmware upgrading method based on bootloader architecture
JP2011053984A (en) Firmware protection apparatus and program thereof
US11768669B2 (en) Installing application program code on a vehicle control system
CN112596749A (en) Method and device for system power-on self-test and self-repair
CN112395130A (en) System backup method and device
CN117407022A (en) Method for upgrading firmware, electronic device and storage medium
EP4113288B1 (en) Systems and method for bootup activation of firmware images
CN117369847A (en) Method for upgrading firmware, electronic device and storage medium
JP2005242930A (en) Information processor, program updating method, program updating program, and computer-readable storage medium recording program updating program

Legal Events

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