CN113064604B - Firmware upgrading method and device - Google Patents

Firmware upgrading method and device Download PDF

Info

Publication number
CN113064604B
CN113064604B CN202110289003.1A CN202110289003A CN113064604B CN 113064604 B CN113064604 B CN 113064604B CN 202110289003 A CN202110289003 A CN 202110289003A CN 113064604 B CN113064604 B CN 113064604B
Authority
CN
China
Prior art keywords
partition
firmware
upgrading
mirror image
upgraded
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
CN202110289003.1A
Other languages
Chinese (zh)
Other versions
CN113064604A (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.)
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 CN202110289003.1A priority Critical patent/CN113064604B/en
Publication of CN113064604A publication Critical patent/CN113064604A/en
Application granted granted Critical
Publication of CN113064604B publication Critical patent/CN113064604B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • G06F8/63Image based installation; Cloning; Build to order
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

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 invention discloses a firmware upgrading method and a firmware upgrading device, wherein the method comprises the following steps: formulating a firmware upgrade package, and storing the firmware upgrade package in a preset storage medium; the equipment to be upgraded enters an upgrading mode, a first instruction is analyzed, and firmware upgrading is started; reading the firmware upgrading packet according to the path information of the firmware upgrading packet in the preset storage medium, reprogramming the partition table of the equipment to be upgraded according to the partition table description file to obtain an upgrading result, and writing the upgrading result and the second path information into a second position of the guide control partition; the second path information corresponds to the first path information. The firmware upgrading method can completely upgrade the old platform firmware in the equipment to be upgraded into the new platform firmware, supports the random change of the physical partition table of the equipment to be upgraded and effectively meets the requirements under different application scenes.

Description

Firmware upgrading method and device
Technical Field
The present invention relates to the field of firmware upgrade, and in particular, to a firmware upgrade method and apparatus.
Background
The Firmware upgrading technology is realized by using an FOTA (Firmware Over-the-Air) Firmware upgrading engine and taking a Firmware upgrading package as input.
Most of the existing Linux and Android firmware upgrades depend on equipment partition nodes, and the corresponding firmware upgrade engines basically complete firmware upgrade of corresponding partitions based on the existing equipment partition nodes, which means that a partition table of equipment cannot be changed in the upgrade process. In order to solve the problem that the partition table of the existing device cannot be changed, the existing firmware upgrading method supporting partition table upgrading is generally realized by adopting the following modes:
firstly, the partition is realized by a logical partition mode, namely only one partition is physically arranged, and a plurality of logical partitions are simulated on the physical partition through software to support the upgrading of a logical partition table. This approach does not involve a change to the device physical partition table and does not actually update the physical partition table when upgraded (i.e., the physical partition is not yet changed).
And secondly, the physical partition table is changed, but only partial change of the partition table or change of some specific mode can be supported, for example, an actual physical partition associated with a bootstrap program cannot be changed, or only the size of an existing partition can be adjusted.
However, in many application scenarios, there is a need to support arbitrary changes to the device physical partition table. For example, a device early constructed its basic firmware platform in an architectural manner, which includes A, B, C, D, E five partitions, appeared in several years and adopted a new incompatible system firmware architecture, which includes nine completely different partitions, a1, a2, B1, B2 and C, E, F, G, K, and it is desirable to upgrade the device firmware to the new system firmware, which requires a FOTA firmware upgrade scheme that supports any changes to the device physical partition table. However, the existing technical solutions do not support any changes to the device physical partition table.
Disclosure of Invention
Therefore, a technical scheme for firmware upgrade needs to be provided to solve the technical problem that the physical partition table of the device cannot be changed arbitrarily in the prior art.
To achieve the above object, the present application provides, in a first aspect, a firmware upgrade method, including:
formulating a firmware upgrade package, and storing the firmware upgrade package in a preset storage medium; the firmware upgrade package comprises a partition table description file;
the equipment to be upgraded enters an upgrading mode, a first instruction is analyzed, and firmware upgrading is started; the equipment to be upgraded comprises a firmware partition, the firmware partition comprises a boot control partition, and the first instruction is written into a first position of the boot control partition in advance; the first position corresponds to the first path information, and the first path information is the path information of the firmware upgrade package in the preset storage medium;
reading the firmware upgrading packet according to the path information of the firmware upgrading packet in the preset storage medium, reprogramming the partition table of the equipment to be upgraded according to the partition table description file to obtain an upgrading result, and writing the upgrading result and the second path information into a second position of the guide control partition; the second path information corresponds to the first path information.
Further, "writing the upgrade result and the second path information to the second location of the boot control partition" includes:
and erasing the information written in advance in the first position, synchronously writing an upgrading mark instruction and a data erasing instruction in the first position, and then restarting the equipment to be upgraded.
Further, after restarting the device to be upgraded, the method further includes:
reading the upgrading mark instruction of the first position, and reentering an upgrading mode;
erasing the readable and writable area of the equipment to be upgraded according to the data erasing instruction of the first position;
and reading the upgrading result and the second path information of the second position, creating an upgrading success mark file under a specified specific directory, writing the upgrading result and the second path information of the second position into the upgrading success mark file, and clearing all information corresponding to the current first position and the current second position.
Further, after clearing all information corresponding to the current first location and the second location, the method further includes:
and entering a new firmware system which is successfully upgraded, judging whether the upgrade success mark file exists, if so, indicating that the firmware is successfully upgraded, and executing the data recovery operation of the readable and writable area according to a data recovery instruction of a user.
Furthermore, the firmware upgrade package further comprises identification information, partition data and preset check information; after the firmware upgrade package is read, verifying the read firmware upgrade package, which specifically includes:
reading the identification information of the firmware upgrading package, comparing the identification information with preset identification information, quitting the upgrading if the identification information is inconsistent, reading the partition data in the firmware upgrading package if the identification information is consistent, calculating verification information according to the partition data, comparing the calculated verification information with the preset verification information, continuing the firmware upgrading if the identification information is consistent, and otherwise quitting the firmware upgrading.
Further, the firmware upgrade package further includes a partition image number to be upgraded, and the method further includes:
and traversing each partition image according to the number of the partition images to be upgraded, judging whether the data length of each partition image in the firmware upgrade package is larger than the actual size allocated to the image partition in the partition description file, and if so, quitting the firmware upgrade.
Further, the partition table description file includes a dependent partition list, and reprogramming the partition table of the device to be upgraded according to the partition table description file includes:
s1: when traversing each partition mirror image, sequentially judging whether the name of each partition mirror image is contained in the dependent partition list, and if so, reading mirror image data to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package;
s2: searching the position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s3: and reading back each mirror image data written into the storage partition of the equipment to be upgraded, comparing the mirror image data with the corresponding partition data in the firmware upgrade package, and if the mirror image data is inconsistent with the corresponding partition data, executing the steps S1-S3 again.
Further, the partition table description file includes a dependent partition list, and reprogramming the partition table of the device to be upgraded according to the partition table description file includes:
s4: when traversing each partition mirror image, sequentially judging whether the name of each partition mirror image is contained in the dependency partition list, if not, reading the data of the mirror image to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package;
s5: searching the storage position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s6: if the partition mirror image is judged to be in the binary Android Sparse format, all the storage partitions of the block are forcibly assigned to be 0 according to the position and the length of the partition in the storage partition of the equipment to be upgraded, which are indicated by the partition table, the partition mirror image is analyzed according to the Sparse file format, and the analyzed binary raw data are sequentially written into the storage partition position corresponding to the partition mirror image;
s7: if the partition mirror image is judged to be in a binary raw format, reading data corresponding to the partition mirror image in the firmware upgrade package, and writing the data according to the storage position corresponding to the storage partition in the partition table description file; and if the data of the current partition mirror image is smaller than the actual size allocated to the mirror image partition in the partition table description file, all the residual contents corresponding to the storage partition are forcibly assigned to be 0.
The second aspect of the present application further provides a firmware upgrading apparatus, which is configured to execute the firmware upgrading method according to the first aspect of the present application.
Different from the prior art, the firmware upgrading method and device can completely upgrade the version of an Android operating system platform to another large version, completely reprogram and upgrade the whole storage medium of legacy equipment, upgrade all firmware from the partition table to all new version platforms, enable the firmware in the legacy equipment to be completely consistent with the launch equipment after upgrading, and enjoy all innovative technical experiences that all the launch equipment can enjoy.
Drawings
FIG. 1 is a flowchart illustrating a firmware upgrade method according to an embodiment of the present invention;
FIG. 2 is a flowchart of a firmware upgrade method according to another embodiment of the present invention;
FIG. 3 is a flowchart of a firmware upgrade method according to another embodiment of the present invention;
FIG. 4 is a flowchart of a firmware upgrade method according to another embodiment of the present invention;
fig. 5 is a flowchart of a firmware upgrade method according to another embodiment of the present invention.
Detailed Description
To explain technical contents, structural features, and objects and effects of the technical solutions in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
Fig. 1 is a flowchart of a firmware upgrading method according to an embodiment of the present invention. The method comprises the following steps:
firstly, entering a step S101 to formulate a firmware upgrade package, and storing the firmware upgrade package in a preset storage medium; the firmware upgrade package comprises a partition table description file;
then step S102 is entered, the equipment to be upgraded enters an upgrading mode, the first instruction is analyzed, and the firmware upgrading is started; the equipment to be upgraded comprises a firmware partition, the firmware partition comprises a boot control partition, and the first instruction is written into a first position of the boot control partition in advance; the first position corresponds to the first path information, and the first path information is the path information of the firmware upgrade package in the preset storage medium;
then, step S103 is carried out, wherein the firmware upgrading packet is read according to the path information of the firmware upgrading packet in the preset storage medium, the partition table of the equipment to be upgraded is reprogrammed according to the partition table description file, an upgrading result is obtained, and the upgrading result and the second path information are written into a second position of the guide control partition; the second path information corresponds to the first path information. Preferably, the second path information is a mirror image of the first path information, that is, the original first path information is copied and stored in the second location.
As a preferred embodiment, the firmware upgrade package described in step S101 is a binary file, which includes the following 4 parts: header information, partition table description file, partition image file (i.e. upgrade data), and MD5 values, and the specific definitions of these 4 parts are as follows:
(1) header information (HEAD): the size of the header information is fixed, and the header information mainly comprises the following contents: a. magic number TAG; b. the partition table describes the offset (i.e., starting location) and length of the file in the firmware upgrade package; c. information of each partition image to be upgraded, including the name of the partition image (which matches the corresponding partition name in the "partition table description file"), the offset (i.e., the starting position) and the length in the firmware upgrade package; d. the actual number of the images of the partition to be upgraded.
(2) Partition table description file: the space layout in a storage medium (such as a flash) for describing the whole system of the device comprises how many total partitions of the device to be upgraded currently exist, a partition table type (GPT or MBR), the name of each partition, and the storage position and length of the flash in which each partition is located. Meanwhile, the 'partition table description file' comprises a field description 'upgrade mode dependent partition list' for writing all partition names on which the upgrade mode depends. The "upgrade mode dependent partition list" includes, but is not limited to, the following partitions: "boot image partition", "upgrade mode image partition".
The partition table description file of the device to be upgraded needs to include but is not limited to the following partitions: "boot image partition", "boot control block partition", "boot image partition", "upgrade mode image partition", "system image partition". The partition table description file may also include a "trusted secure mirror partition" if the device hardware supports a secure trusted environment (either through the main chip built-in or using a third party module), while the partition table description file may also include a "secure check information partition" if the device supports secure boot and the check information is stored in a separate partition.
"boot image partition started": booting for a device typically includes multiple levels of boot procedures as needed. If the device has multiple stages of boot programs, each stage of boot program has a separate partition image, for example, when there is two stages, the partition is a "first stage boot program image partition" and a "second stage boot program image partition", respectively.
The partition table of the device usually includes:
a. boot control block partitioning: the method is used for communication among various stages of the system software of the embedded device;
b. starting a mirror image partition: boot systems for storage devices, typically including kernel, ramdisk, dts, and the like;
c. upgrading the mode mirror image partition: an upgrade subsystem program for a storage device, which is generally a recovery system in an Android system;
d. partitioning a system image: a system program for a storage device, in the Android system, typically system or super, and in the Linux system, typically rootfs;
e. trusted secure mirror partitioning: storing a trusted operating system program;
f. and (4) safe verification information partition: for storing integrity check information when the device supports secure booting.
(3) Partition image (image) file: i.e. compiled firmware applicable to the respective partitions of the corresponding device. The complete system image file constituting the embedded device includes, but is not limited to: the method comprises the steps of starting a bootstrap program image file, starting a Boot image file, upgrading mode image file and system image file. A "trusted secure image" may also be included if the device hardware supports a secure trusted environment (either through the main chip built-in or using a third party module), while a "secure verification information image" may also be included if the device supports secure boot and the verification information is stored in a separate partition.
The software comprises a Boot image file, an upgrade mode image file, a trusted security image file and a security check information image file, wherein the Boot image file, the upgrade mode image file, the trusted security image file and the security check information image file are binary raw files; the system image file and all possible other image files may be binary raw files or binary Android sparse format files. The region table describes that all the partition images in the "upgrade mode dependent partition list" in the file are binary raw files.
If the device to be upgraded has a multi-stage boot loader, each stage of boot loader has a separate partition image file, for example, when there is a second stage, there are two boot loader image files, which are respectively a "first stage boot loader image file" and a "second stage boot loader image file". The primary boot image file and the secondary boot image file support the GPT partition table format. In the Android system, an "upgrade mode image file" refers to a recovery system image.
(4) MD5 value: the value of MD5 is calculated from the first three contents (including header information, partition table description file, partition image file), and the value of MD5 can be used for subsequent verification.
In some embodiments, "writing the upgrade result and the second path information to the second location of the boot control partition" further comprises: and erasing the information written in advance in the first position, synchronously writing an upgrading mark instruction and a data erasing instruction in the first position, and then restarting the equipment to be upgraded.
As shown in fig. 2, after restarting the device to be upgraded, the method further includes:
firstly, step S201 is entered to read the upgrading mark instruction of the first position, and the upgrading mode is entered again; then, step S202 is carried out, and the readable and writable area of the equipment to be upgraded is erased according to the data erasing instruction of the first position; and then, step S203 is executed to read the upgrade result and the second path information of the second location, create an upgrade success flag file in the specified specific directory, write the upgrade result and the second path information of the second location into the upgrade success flag file, and clear all information corresponding to the current first location and the current second location.
In some embodiments, after clearing all information corresponding to the current first location and the second location, the method further includes: and entering a new firmware system which is successfully upgraded, judging whether the upgrade success mark file exists, if so, indicating that the firmware is successfully upgraded, and executing the data recovery operation of the readable and writable area according to a data recovery instruction of a user.
In some embodiments, the firmware upgrade package further includes identification information, partition data, and preset verification information; after the firmware upgrade package is read, verifying the read firmware upgrade package, which specifically includes: reading the identification information of the firmware upgrading package, comparing the identification information with preset identification information, quitting the upgrading if the identification information is inconsistent, reading the partition data in the firmware upgrading package if the identification information is consistent, calculating verification information according to the partition data, comparing the calculated verification information with the preset verification information, continuing the firmware upgrading if the identification information is consistent, and otherwise quitting the firmware upgrading. The identification information is the aforementioned HEAD header information, the partition data is the aforementioned partition mirror data, and the predetermined check information is the MD5 value.
In some embodiments, the firmware upgrade package further includes a partition image number to be upgraded, and the method further includes: and traversing each partition image according to the number of the partition images to be upgraded, judging whether the data length of each partition image in the firmware upgrade package is larger than the actual size allocated to the image partition in the partition description file, and if so, quitting the firmware upgrade.
As shown in fig. 3, in some embodiments, the partition table description file includes a dependent partition list, and the reprogramming the partition table of the device to be upgraded according to the partition table description file includes:
s1: when traversing each partition mirror image, sequentially judging whether the name of each partition mirror image is contained in the dependency partition list, and if so, reading mirror image data to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package;
s2: searching the position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s3: and reading back each mirror image data written into the storage partition of the equipment to be upgraded, comparing the mirror image data with the corresponding partition data in the firmware upgrade package, and if the mirror image data is inconsistent with the corresponding partition data, executing the steps S1-S3 again.
As shown in fig. 4, in some embodiments, the partition table description file includes a dependent partition list, and the reprogramming the partition table of the device to be upgraded according to the partition table description file includes:
s4: when traversing each partition mirror image, sequentially judging whether the name of each partition mirror image is contained in the dependency partition list, if not, reading the data of the mirror image to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package;
s5: searching the storage position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s6: if the partition mirror image is judged to be in the binary Android Sparse format, all the storage partitions of the block are forcibly assigned to be 0 according to the position and the length of the partition in the storage partition of the equipment to be upgraded, which are indicated by the partition table, the partition mirror image is analyzed according to the Sparse file format, and the analyzed binary raw data are sequentially written into the storage partition position corresponding to the partition mirror image;
s7: if the partition mirror image is judged to be in a binary raw format, reading data corresponding to the partition mirror image in the firmware upgrade package, and writing the data according to the storage position corresponding to the storage partition in the partition table description file; and if the data of the current partition mirror image is smaller than the actual size allocated to the mirror image partition in the partition table description file, all the residual contents corresponding to the storage partition are forcibly assigned to be 0.
The second aspect of the present application also provides a firmware upgrading apparatus, which is used for executing the firmware upgrading method according to the first aspect of the present application.
Taking an actual firmware upgrade application scenario as an example, the firmware upgrade method of the present application is discussed in detail below, and the firmware upgrade method of the present application may be completed by a firmware upgrade engine, which is an engine designed for completely upgrading firmware across platforms, and may support any change of new and old firmware partition tables, including a format change of the partition table, such as changing MBR into GPT. Meanwhile, the firmware upgrading engine can also support complete upgrading of different Android operating system platforms across large-version platforms, complete upgrading of Android system firmware in one device to firmware based on a common Linux system, and complete upgrading of one device with the common Linux system to one Android system. The following conditions need only be satisfied:
(1) the system of the equipment to be upgraded is based on the linux kernel, and the whole Flash equipment is enumerated into a single equipment node. An available external storage medium (TF/SD card or U disk) exists during firmware upgrading, and the upgraded new platform firmware and the upgraded old platform firmware all contain a boot control block partition and an upgrade mode partition, wherein the boot control block partition is used for communication of different stages of firmware upgrading; the upgrade mode partition is used for storing an upgrade mode image file, which contains a firmware upgrade instruction.
(2) The firmware upgrade package is required to contain the complete system firmware that makes up the embedded device, including but not limited to the following system images: the method comprises the steps of starting a bootstrap program image file, starting a Boot image file, upgrading mode image file and system image file. The "boot loader" typically includes multiple levels of boot up procedures as needed. If the device has a multi-stage boot loader, each stage boot loader has a separate partition image file, for example, when there is a second stage, the stage boot loader image file is a "first stage boot loader image file" and a "second stage boot loader image file", respectively.
(3) The firmware upgrade package is constructed according to the following rule, namely according to the mode of HEAD header information + partition table description file + partition image file + MD5 value.
As shown in fig. 5, the general idea and the complete execution flow of the technical solution of the present application are as follows:
the process first proceeds to step S501, where a firmware upgrade package is created according to the configuration requirements of the upgrade package.
And then, the upgrading client acquires the firmware upgrading packet in an online or offline mode in step S502, and places the firmware upgrading packet on an external storage medium of the device or an idle storage medium of the device. The equipment is to be upgraded, and the external storage medium can be a TF/SD card, a U disk and the like.
Then, the upgrade client triggers the upgrade engine by writing a specific instruction 1 into a specific location 1 of the "boot control block partition" in step S503, where the instruction has a firmware upgrade package path as a parameter. The specific instruction 1 is the first instruction mentioned above, and the specific instruction 1 has a firmware upgrade package path as a parameter. The issuing of the instruction is achieved by writing said specific instruction 1 into a specific location 1, i.e. the first location mentioned before, of the "boot control block" partition. For the Android-based system, the instruction can also be issued through a recovery command file.
And then, in step S504, restarting the equipment to enter an upgrading mode, analyzing the specific instruction 1, and setting a marking variable to true to indicate that the firmware upgrading starts and simultaneously record a firmware upgrading packet path carried by the specific instruction 1 to an upgrading packet path variable. When the equipment to be upgraded is an Android system, restarting the equipment to enter an upgrading mode comprises the following steps: the device enters recovery; when the equipment to be upgraded is a Linux system, entering a corresponding upgrading mode, and restarting the equipment to enter the upgrading mode comprises the following steps: the device enters a corresponding upgrade mode. The flag variable may be denoted as fw _ flag, and records a firmware upgrade package path carried by the specific instruction 1 to an upgrade package path variable (the path variable may be denoted as fw _ image _ path in the following).
And then, checking the validity of the firmware upgrade package, which specifically comprises the following steps: step S505, reading a HEAD size HEAD fixed in the firmware upgrade package, and reading a magic digital field; and step S506, determining whether the value is consistent with a predefined magic value, if the determination in step S506 is yes, then entering step S507, calculating MD5 values of the first three parts in the firmware upgrade package (where the first three parts refer to header information, a partition table description file, and a partition image file), then entering step S508, determining whether the calculated MD5 value is consistent with a MD value preset at the end of the firmware upgrade package, if the determination in step S508 is yes (which indicates that each part of the upgrade package is complete at this time), then entering step S509, according to the "actual number of partition images to be upgraded" of the firmware upgrade package header, traverse each partition image. And if the judgment of any one of the step S506 or the step S509 is that the error is reported and the firmware upgrading engine is exited, stopping the firmware from being upgraded continuously.
Then, the validity of the size of the partition table can be checked, which specifically comprises the following steps: step S510 determines whether the data length of each partition image in the firmware upgrade package is greater than the actual size allocated to the partition in the partition table, if yes, step S510 determines that the data length is greater than the actual size allocated to the partition (which indicates that the size of the partition image exceeds the size of the partition allocated to the partition), an error is reported to exit the firmware upgrade engine, and if not, step S511 is performed.
And then, the operation system kernel enumerates the whole flash storage medium space into a single block device node in the step S511. The subsequent flash operation of the read-write device is realized by performing read-write operation on the device node.
Then, the process proceeds to step S512 to read and store the specific instruction 1 and the upgrade package storage path related information in the specific location 1 of the "boot control block partition" of the current device.
Then, the process proceeds to step S513 to reprogram the partition table of the device according to the "partition table descriptor". Specifically, the partition table of the device may be reprogrammed according to the partition table type in the partition table descriptor, and the programming manner of the partition table depends on the partition table type supported by the corresponding boot loader.
Then, updating the partition image file can be started, and the method specifically comprises the following two stages:
step S514 is a first stage of partition image upgrading, which reads the "upgrade mode dependent partition list" in the "partition table description file" and first upgrades all partition images in the list. Generally, all partition image files in the partition list are small, so that the partition list can be quickly upgraded, and power failure is not allowed in the upgrading process at this stage.
The first stage process specifically comprises:
(1) and traversing each partition mirror image according to the actual number of the partition mirror images to be upgraded at the head of the firmware upgrade package, reading the data of the partition mirror images to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package if the name of the corresponding partition mirror image is contained in the upgrade mode dependent partition list, and then writing the data by searching the storage position and the length of the corresponding partition in the flash space of the equipment according to the name of the partition mirror image. If the data mirrored by the partition is smaller than the actual size of the partition allocated in the partition table, the remaining content corresponding to the flash partition is all forced to write data 0x 0.
(2) And reading back the data written into the corresponding partition of the flash to perform binary comparison with the corresponding partition data in the firmware upgrade package so as to ensure that the data written into the flash is consistent with the data in the firmware upgrade package. If the two are not consistent, the upgrading process is repeated, and the upgrading process in the step (1) is repeated.
(3) And performing forced write 0x0 operation on all storage positions and lengths of the device flash space according to the boot control block partition in the partition table description file, and then writing the specific instruction 1 and the related information of the upgrade package storage path saved in the step S512 into the specific position 1.
Step S514 may be followed by step S515 of upgrading the partition image of the second stage, and upgrading all other partition image files except the partition image of the first stage. The partition image file upgraded at this stage is usually large, and power failure is allowed in the upgrading process. If the power is off and the power is on again, the specific instruction 1 and the upgrade package path information are stored in the position 1 of the "boot control block partition", and the upgrade process is executed from step S504 again.
The second stage process specifically comprises:
(1) traversing each partition image according to the actual number of the partition images to be upgraded of the head of the firmware upgrade package, reading the data of the partition images to be upgraded in the firmware upgrade package according to the position and the length of each partition image in the firmware upgrade package if the name of the corresponding partition image is not contained in the upgrade mode dependent partition list, and then searching the storage position and the length of the corresponding partition in the flash space of the equipment according to the name of the partition image.
Preferably, if the partition image is in the binary Android Sparse format, first, 0x0 is forcibly written into the flash area of the block according to the position and the length of the partition in the flash as indicated by the partition table. After the operation of forcibly writing 0x0 is completed, the partition mirror image is analyzed according to the spare file format, and the analyzed binary raw data is written into the flash storage position corresponding to the partition mirror image in sequence.
And if the partition mirror image is in a binary raw format, reading data corresponding to the partition mirror image in the firmware upgrade package, and writing the data in a storage position corresponding to the flash according to the partition table. If the data mirrored by the partition is smaller than the actual size of the partition allocated in the partition table, the remaining content corresponding to the flash partition is all forced to write data 0x 0.
(2) And reading back the data written into the corresponding partition of the flash to perform binary comparison with the corresponding partition data in the firmware upgrade package so as to ensure that the data written into the flash is consistent with the data in the firmware upgrade package. If not, directly reporting an error, restarting the equipment, and re-executing the upgrading process. This is because this step usually performs a relatively large image file write operation, and if the DDR of the device is unstable, an inconsistency will usually occur, and then the reboot is a better strategy.
After step S515, step S516 may be proceeded to record the firmware upgrade package path and the upgrade result attached to the image upgrade instruction to the specific location 2 of the "boot control block partition" according to the flag variable.
Then, the process proceeds to step S517 to erase the information of the specific location 1 of the "boot control block partition", and at this location, the flag command and the data erase command for entering the upgrade mode are written simultaneously, and the apparatus is restarted.
Then, the boot program after the upgrade enters step S518 to reenter the upgrade mode of the upgraded firmware (i.e. boot the "recovery image file") according to the information of the specific location 1 of the "boot control block" partition.
Then, the process proceeds to step S519, where the specific location 1 and the specific location 2 information of the "boot control block" partition are read in the upgrade mode (recovery) of the new firmware.
Then step S520 is carried out, according to the field information of the data erasing instruction stored in the specific position 1, the user readable data writing area in the equipment, such as cache, data and the like, is reformatted and erased;
then, step S521 is performed to create an upgrade success flag file (hereinafter referred to as last _ fw _ reprogramming _ flag) in a specific directory (e.g., cache/recovery) of the specified non-encrypted user-readable write data area according to the firmware upgrade package path and the field information of the upgrade result carried by the firmware upgrade instruction stored in the specific location 2, and write the "firmware upgrade package path and the field information of the upgrade result carried by the firmware upgrade instruction" into the file.
The flow then proceeds to step S522 to clear the information of the specific position 1 and the specific position 2 of the "boot control block partition".
Then step S523 is performed to restart the firmware system, and the upgrade client in the new firmware system completes possible data recovery operations as needed after confirming that the firmware of the new system has been successfully upgraded according to the upgrade success flag file (e.g., last _ fw _ reprogramming _ flag).
By adopting the firmware upgrading method, the following beneficial effects can be realized:
(1) the firmware upgrading engine can completely upgrade one Android operating system platform version to another large version, completely reprograms and upgrades the whole storage medium of legacy equipment, upgrades all firmware from the partition table to all new version platforms, can enable the firmware in the legacy equipment to be completely consistent with the launch equipment after upgrading, and enjoys all innovative technical experiences that all the launch equipment can enjoy.
(2) And through a customized unified upgrade package format, random change upgrade aiming at the equipment partition table is supported, so that the change of the equipment partition table does not depend on partition equipment nodes any more. The firmware upgrading engine can support complete upgrading of different Android operating system platforms across large-version platforms, such as upgrading from Android 7.1 to Android 10; the Android system firmware in one device is also supported to be completely upgraded to the firmware based on the common Linux system, and similarly, the device of the common Linux system is also supported to be completely upgraded to a certain Android system, for example, a certain embedded Linux distribution firmware in a certain device is upgraded to the firmware based on the Android operating system, or the firmware based on the Android system in a certain device is completely upgraded to the firmware based on a certain embedded Linux distribution. Through the firmware upgrading engine, seamless change upgrading of an equipment bottom layer architecture platform can be realized, bold technical innovation is realized, and the restriction on compatibility of new and old firmware is not considered, so that the imagination of an engineer can be released, and the optimal technical scheme and experience are provided for a user.
(3) The firmware upgrading engine can completely upgrade the old platform firmware in the equipment to the new platform firmware, so that all innovative features of the new firmware platform can be used by the old equipment, and user experience is improved. Meanwhile, the firmware used in the equipment is unified through the complete upgrade of the firmware of the new platform, so that the maintenance workload is reduced, and the unified management and maintenance of the equipment are facilitated.
When the firmware upgrading is carried out by the firmware upgrading engine (namely the firmware upgrading device), any change and upgrade aiming at the equipment partition table can be supported by the customized unified upgrading packet format (only new and old partition tables are required to have a boot control block partition and an upgrading mode partition), so that the partition table change does not depend on partition equipment nodes any more. And through the firmware upgrading engine, seamless change upgrading of an equipment bottom layer architecture platform can be realized, and bold technical innovation is realized without considering the limit in the compatibility aspect of new and old firmware. Meanwhile, the firmware upgrading engine can completely upgrade the old platform firmware in the equipment to the new platform firmware, so that all innovative features of the new firmware platform can be used by the old equipment, and user experience is improved. Meanwhile, the firmware used in the equipment is unified through the complete upgrade of the new platform firmware, so that the maintenance workload is reduced, and the unified management and maintenance of the equipment are facilitated.
Finally, it should be noted that, although the above embodiments have been described herein, the scope of the present invention is not limited thereby. Therefore, based on the innovative concepts of the present invention, the technical solutions of the present invention can be directly or indirectly applied to other related technical fields by making changes and modifications to the embodiments described herein, or by using equivalent structures or equivalent processes performed in the content of the present specification and the attached drawings, which are included in the scope of the present invention.

Claims (8)

1. A method of firmware upgrade, the method comprising:
formulating a firmware upgrade package, and storing the firmware upgrade package in a preset storage medium; the firmware upgrade package comprises a partition table description file;
the equipment to be upgraded enters an upgrading mode, analyzes the first instruction and starts firmware upgrading; the equipment to be upgraded comprises a firmware partition, the firmware partition comprises a boot control partition, and the first instruction is written into a first position of the boot control partition in advance; the first position corresponds to first path information, and the first path information is path information of the firmware upgrade package in the preset storage medium;
reading the firmware upgrading packet according to the path information of the firmware upgrading packet in the preset storage medium, reprogramming the partition table of the equipment to be upgraded according to the partition table description file to obtain an upgrading result, and writing the upgrading result and the second path information into a second position of the guide control partition; the second path information corresponds to the first path information;
the firmware upgrade package also includes a number of partition images to be upgraded, the partition table description file includes a dependent partition list, and reprogramming the partition table of the device to be upgraded according to the partition table description file includes:
s1: traversing each partition mirror image according to the number of the partition mirror images to be upgraded, sequentially judging whether the name of each partition mirror image is contained in the dependency partition list when traversing each partition mirror image, and reading the data of the partition mirror images to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package if the name of each partition mirror image is contained in the dependency partition list;
s2: searching the position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s3: and reading back each mirror image data written into the storage partition of the equipment to be upgraded, comparing the mirror image data with the corresponding partition data in the firmware upgrade package, and if the mirror image data is inconsistent with the corresponding partition data, executing the steps S1-S3 again.
2. The firmware upgrade method according to claim 1, wherein, after writing the upgrade result and the second path information to the second location of the boot control partition, further comprising:
and erasing the information written in advance in the first position, synchronously writing an upgrading mark instruction and a data erasing instruction in the first position, and then restarting the equipment to be upgraded.
3. The firmware upgrade method according to claim 2, wherein after restarting the device to be upgraded, the method further comprises:
reading the upgrading mark instruction of the first position, and reentering an upgrading mode;
erasing the readable and writable area of the equipment to be upgraded according to the data erasing instruction of the first position;
and reading the upgrading result and the second path information of the second position, creating an upgrading success mark file under a specified specific directory, writing the upgrading result and the second path information of the second position into the upgrading success mark file, and clearing all information corresponding to the current first position and the current second position.
4. The firmware upgrade method according to claim 3, further comprising, after clearing all information currently corresponding to the first and second locations:
and entering a new firmware system which is successfully upgraded, judging whether the upgrade success mark file exists, if so, indicating that the firmware is successfully upgraded, and executing the data recovery operation of the readable and writable area according to a data recovery instruction of a user.
5. The firmware upgrade method according to claim 1, wherein the firmware upgrade package further includes identification information, partition data, and preset check information; after the firmware upgrade package is read, verifying the read firmware upgrade package, which specifically includes:
and reading the identification information of the firmware upgrading packet, comparing the identification information with preset identification information, exiting the upgrading if the identification information is inconsistent, reading the partition data in the firmware upgrading packet if the identification information is consistent, calculating verification information according to the partition data, comparing the calculated verification information with the preset verification information, continuing the firmware upgrading if the identification information is consistent, and exiting the firmware upgrading if the identification information is inconsistent.
6. The firmware upgrade method according to claim 1, further comprising:
and judging whether the data length of each partition mirror image in the firmware upgrade package is larger than the actual size allocated to the mirror image partition in the partition description file, and if so, exiting the firmware upgrade.
7. The firmware upgrade method of claim 6, wherein the partition table description file includes a dependent partition list, and the reprogramming of the partition table of the device to be upgraded according to the partition table description file comprises:
s4: when traversing each partition mirror image, sequentially judging whether the name of each partition mirror image is contained in the dependency partition list, if not, reading the data of the mirror image to be upgraded in the firmware upgrade package according to the position and the length of each partition mirror image in the firmware upgrade package;
s5: searching the storage position and the length of the corresponding partition mirror image in the partition table description file in the storage partition of the equipment to be upgraded according to the name of each partition mirror image, and writing data;
s6: if the partition mirror image is judged to be in the binary Android Sparse format, all the storage partitions of the block are forcibly assigned to be 0 according to the position and the length of the partition mirror image in the storage partition of the equipment to be upgraded, which are indicated by the partition table, the partition mirror image is analyzed according to the Sparse file format, and the analyzed binary raw data are sequentially written into the storage partition position corresponding to the partition mirror image;
s7: if the partition mirror image is judged to be in a binary raw format, reading data corresponding to the partition mirror image in the firmware upgrade package, and writing the data according to the storage position corresponding to the storage partition in the partition table description file; and if the data of the current partition mirror image is smaller than the actual size allocated to the mirror image partition in the partition table description file, all the residual contents corresponding to the storage partition are forcibly assigned to be 0.
8. A firmware upgrade apparatus, characterized in that the firmware upgrade apparatus is configured to perform the firmware upgrade method according to any one of claims 1 to 7.
CN202110289003.1A 2021-03-18 2021-03-18 Firmware upgrading method and device Active CN113064604B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110289003.1A CN113064604B (en) 2021-03-18 2021-03-18 Firmware upgrading method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110289003.1A CN113064604B (en) 2021-03-18 2021-03-18 Firmware upgrading method and device

Publications (2)

Publication Number Publication Date
CN113064604A CN113064604A (en) 2021-07-02
CN113064604B true CN113064604B (en) 2022-06-21

Family

ID=76561193

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110289003.1A Active CN113064604B (en) 2021-03-18 2021-03-18 Firmware upgrading method and device

Country Status (1)

Country Link
CN (1) CN113064604B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113448608B (en) * 2021-07-14 2022-05-20 浙江国利网安科技有限公司 FPGA (field programmable Gate array) increment upgrading method and device based on region slicing technology
CN114706620A (en) * 2022-02-25 2022-07-05 瑞芯微电子股份有限公司 Parameter configuration method and device and computer readable medium
CN118192991A (en) * 2022-12-13 2024-06-14 富联精密电子(天津)有限公司 Firmware burning method, device, electronic equipment and computer storage medium
CN117539518B (en) * 2024-01-02 2024-06-07 江苏天华汽车电子科技有限公司 Application program upgrading method and electronic equipment
CN117971283A (en) * 2024-03-28 2024-05-03 深流微智能科技(深圳)有限公司 Firmware upgrading method of graphic processor, terminal equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103473067A (en) * 2013-09-23 2013-12-25 福建三元达软件有限公司 Embedded Linux partitioning and data recovery method, embedded Linux partitioning and data recovery system and system development method
CN108108270A (en) * 2015-05-06 2018-06-01 广东欧珀移动通信有限公司 Mobile terminal system backup-and-restore method, mobile terminal, computer and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103392174B (en) * 2012-11-29 2015-11-25 华为技术有限公司 Based on the system of flash memory storage, partition method and device
CN104317618B (en) * 2014-10-24 2018-03-27 福州瑞芯微电子股份有限公司 A kind of firmware partition treating method and apparatus

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103473067A (en) * 2013-09-23 2013-12-25 福建三元达软件有限公司 Embedded Linux partitioning and data recovery method, embedded Linux partitioning and data recovery system and system development method
CN108108270A (en) * 2015-05-06 2018-06-01 广东欧珀移动通信有限公司 Mobile terminal system backup-and-restore method, mobile terminal, computer and system

Also Published As

Publication number Publication date
CN113064604A (en) 2021-07-02

Similar Documents

Publication Publication Date Title
CN113064604B (en) Firmware upgrading method and device
WO2022007656A1 (en) Bootloader software updating method and apparatus, embedded controller, and storage medium
KR100987628B1 (en) Method for updating firmware in embedded controller and medium recorded update firmware
CN110096300B (en) FPGA program file backup management system, operation method and upgrading method
CN102023908A (en) Method and device for backing up boot program
US8601464B2 (en) Memory online update system and method
CN113238771B (en) Android system-based FOTA firmware upgrading method and device
CN101978357A (en) Data updating method, memory system and memory device
CN107783776B (en) Processing method and device of firmware upgrade package and electronic equipment
CN102270144A (en) Embedded network equipment and method for upgrading firmware by using same
WO2007105120A1 (en) Automatically configurable smart card and method of automatically configuring a smart card
TWI588742B (en) Program codes loading method of application and computing system using the same
CN109213510A (en) A kind of application program updating method and storage medium for embedded device
CN109375953B (en) Operating system starting method and device
CN116954674A (en) eMMC firmware upgrading method, firmware upgrading equipment and storage device
CN113791812B (en) Firmware upgrading method and storage device
CN113467797B (en) Program updating method, device and system and computer readable storage medium
JP5157789B2 (en) Program update method and program update apparatus
JP2002175193A (en) Device and method for rewriting program
CN112764778A (en) Processing method for remotely upgrading underlying root file system and related equipment
JPWO2012077604A1 (en) Processing apparatus, program update method, and program
US20070208929A1 (en) Device information managements systems and methods
JP5950290B1 (en) Nonvolatile storage device and processing method of nonvolatile storage device
CN113791811B (en) Firmware upgrading method and storage device
JP4575112B2 (en) Firmware rewriting method, disk drive device, and information processing system

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