Disclosure of Invention
In view of the above, a method for downloading program firmware of a chip, an electronic device, and a storage medium are provided.
One object of the present invention is to prevent the chip from being bricked during the downloading of the program firmware.
It is another object of the invention to maintain consistency of the firmware versions of the programs in the chip.
According to an aspect of the present invention, the present invention provides a method for downloading program firmware of a chip, including:
receiving a downloading instruction of the program firmware;
enabling the chip to enter a downloading mode according to the downloading instruction;
downloading the agent program;
erasing, by the agent, a boot program firmware stored in a storage medium in the chip;
and downloading the boot program firmware to a storage medium in the chip through the agent program.
Optionally, after erasing, by the agent program, the boot program firmware stored in the storage medium in the chip, the method further includes:
erasing, by the agent, non-boot program firmware stored in a storage medium in the chip;
before downloading the boot program firmware to the storage medium in the chip through the agent program, the method further comprises the following steps:
downloading, by the agent, non-boot program firmware to the storage medium.
Optionally, the non-boot program firmware comprises at least one of:
application processor program firmware, baseband chip plus coprocessor program firmware, trusted area program firmware, non-volatile data program firmware, user data program firmware.
Optionally, before erasing, by the agent program, the boot program firmware stored in the storage medium in the chip, the method includes:
and backing up the program firmware stored in the storage medium in the chip.
Optionally, after downloading the boot program firmware to the storage medium in the chip through the agent, the method includes:
and restarting the chip.
Optionally, the storage medium is a flash memory.
According to another aspect of the present invention, the present invention also provides a chip comprising:
the chip comprises a memory and a processor, wherein a control program is stored in the memory, and the control program is used for realizing the downloading method of the program firmware of the chip according to any one of the above items when being executed by the processor.
According to still another aspect of the present invention, there is also provided an electronic device including:
the chip described above.
According to a further aspect of the invention, the invention also provides a machine-readable storage medium having stored thereon a machine-executable program which, when executed by a processor, implements a method of downloading program firmware for a chip according to any one of the preceding claims.
In the downloading method of the program firmware of the chip, the downloading instruction of the program firmware is received, the chip enters a downloading mode according to the downloading instruction, the agent program is downloaded, the bootstrap program firmware stored in the storage medium in the chip is erased through the agent program, the bootstrap program firmware is downloaded into the storage medium in the chip through the agent program, the downloading mode can be re-entered no matter which step the downloading is interrupted, and the problem of the brick change of the chip is avoided.
Further, after the boot program firmware stored in the storage medium is erased, the non-boot program firmware stored in the storage medium is also erased, which may be understood as a full erase, and the full erase may ensure that the non-boot program firmware may be updated each time downloading is performed, which is beneficial to maintaining the consistency of the versions of the non-boot program firmware and the boot program firmware, compared with a partial erase.
The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments thereof, taken in conjunction with the accompanying drawings.
Detailed Description
At present, in the process of upgrading program firmware in a chip, if the chip is powered off or disconnected, boot of the chip may be suspended, and a system kernel cannot be booted normally to load, that is, the chip becomes a brick. In the face of the problem of chip brick changing, the chip can be disassembled at present, so that the disassembled chip is subjected to short circuit to enter an upgrading mode again, but the mode not only easily causes the chip to be damaged, but also greatly increases the labor cost; or, a design mode that the chip is shorted to enable the chip to enter an emergency download mode is considered during chip design, but the design mode may cause a product structure to need redesign, and may also bring potential safety hazards to user data in the product.
In view of the foregoing problems, an embodiment of the present invention provides a method for downloading a program firmware of a chip.
Fig. 1 is a flowchart of a method for downloading program firmware of a chip according to an embodiment of the present invention. Referring to fig. 1, the method for downloading the program firmware of the chip may include the following steps S102 to S110.
Step S102: and receiving a downloading instruction of the program firmware.
Step S104: and enabling the chip to enter a downloading mode according to the downloading instruction.
Step S106: download the agent (programmer).
Step S108: the boot loader firmware (bootloader) stored in the storage medium in the chip is erased by the agent program. In this step, the storage medium may be a flash memory (flash), but of course, the storage medium may also be other types of storage media.
Step S110: the boot program firmware is downloaded to the storage medium in the chip through the agent program.
In this embodiment, it is predetermined that if the storage medium of the chip is empty, the download mode can be directly entered. The manner of determining that the storage medium is empty may include: if the storage medium is not detected to have the boot program firmware, determining that the storage medium is empty; or, performing integrity check on the boot program firmware in the storage medium, and if the check fails, determining that the storage medium is empty. Specifically, the above-mentioned manner of determining that the storage medium is empty may be implemented by a boot loader (Bootrom Provider). The method comprises the steps of receiving a downloading instruction of program firmware, enabling a chip to enter a downloading mode according to the downloading instruction, downloading an agent program, erasing the boot program firmware stored in a storage medium in the chip through the agent program, downloading the boot program firmware to the storage medium in the chip through the agent program, and reentering the downloading mode no matter which step the downloading is interrupted, so that the problem that the chip is changed into bricks is avoided.
In an embodiment of the present invention, after erasing the boot program firmware stored in the storage medium in the chip by the agent program, the method may further include: the non-boot program firmware stored in the storage medium in the chip is erased by the agent program.
Before downloading the boot program firmware to the storage medium in the chip through the agent program, the method may further include: the non-boot program firmware is downloaded to the storage medium via the agent program.
In this embodiment, the sequence of erasing the boot loader program firmware, erasing the non-boot loader program firmware, downloading the non-boot loader program firmware, and downloading the boot loader program firmware is adopted, so that the downloading mode can be re-entered no matter which step is interrupted, and the phenomenon that the chip is changed into a brick is avoided. Erasing only the boot program firmware stored in the storage medium can be understood as partial erasing, which is more efficient. After the boot program firmware stored in the storage medium is erased, the non-boot program firmware stored in the storage medium is also erased, which can be understood as total erasure, and compared with partial erasure, the total erasure can ensure that the non-boot program firmware can be updated every time of downloading, which is beneficial to maintaining the consistency of the versions of the non-boot program firmware and the boot program firmware.
In one embodiment of the invention, the non-boot program firmware may include, and is not limited to, the following:
application processor program firmware (ap), baseband chip plus coprocessor program firmware (cp), trusted zone program firmware (tz), non-volatile data program firmware (nv), and user data program firmware (userdata).
In one embodiment of the present invention, before erasing the boot program firmware stored in the storage medium in the chip by the agent, the method may include:
and backing up the program firmware stored in the storage medium in the chip.
In this embodiment, before erasing the boot program firmware stored in the storage medium in the chip by the agent program, the program firmware stored in the storage medium in the chip is backed up, so that the original program firmware can be prevented from being lost, thereby being beneficial to restoring the original program firmware.
In one embodiment of the present invention, after downloading the boot program firmware to the storage medium in the chip through the agent, the method may include: and restarting the chip. By restarting the chip, the downloaded program firmware can be validated.
Fig. 2 is a flowchart of a downloading method of program firmware of a chip according to another embodiment of the present invention, including steps S202 to S218.
Step S202: and receiving a downloading instruction of the program firmware.
Step S204: and enabling the chip to enter a downloading mode according to the downloading instruction.
Step S206: and downloading the agent program.
Step S208: and backing up the program firmware stored in the storage medium in the chip. In this step, the program firmware stored in the storage medium in the chip may be backed up by the agent program.
Step S210: the boot program firmware stored in the storage medium in the chip is erased by the agent program.
Step S212: the non-boot program firmware stored in the storage medium in the chip is erased by the agent program.
Step S214: the non-boot program firmware is downloaded to the storage medium via the agent program.
Step S216: the boot program firmware is downloaded to the storage medium in the chip through the agent program.
Step S218: and restarting the chip.
Referring to fig. 3, the present invention also provides a chip 300 based on the same concept. Chip 300 may include memory 301 and processor 302. The memory 301 stores a control program, which when executed by the processor 302, is used to implement the method for downloading the program firmware of the chip 300 according to any of the above-described embodiments.
Based on the same conception, the invention also provides the electronic equipment. The electronic device comprises the chip 300 of the above embodiment. In this embodiment, the electronic device may be a mobile phone, a tablet computer, a wearable device, a car machine, or the like.
Based on the same concept, the present invention also provides a machine-readable storage medium on which a machine-executable program is stored, which when executed by a processor implements a method for downloading program firmware of a chip according to any of the above embodiments.
The above embodiments can be combined arbitrarily, and according to any one of the above preferred embodiments or a combination of multiple preferred embodiments, the embodiments of the present invention can achieve the following beneficial effects:
the method comprises the steps of receiving a downloading instruction of program firmware, enabling a chip to enter a downloading mode according to the downloading instruction, downloading an agent program, erasing the boot program firmware stored in a storage medium in the chip through the agent program, downloading the boot program firmware to the storage medium in the chip through the agent program, and reentering the downloading mode no matter which step the downloading is interrupted, so that the problem that the chip is changed into bricks is avoided.
Thus, it should be appreciated by those skilled in the art that while a number of exemplary embodiments of the invention have been illustrated and described in detail herein, many other variations or modifications consistent with the principles of the invention may be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Accordingly, the scope of the invention should be understood and interpreted to cover all such other variations or modifications.