Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for booting a generic bootloader-based device according to an embodiment of the present invention. The execution subject in this example is a generic bootloader-based device, which includes: the system comprises a Central Processing Unit (CPU) and a memory for storing a Universal Boot Loader (U-Boot), wherein the CPU and the memory can be connected through a Bootbus bus. The memory can be nand Flash or nor Flash. The number of the memories for storing the U-Boot can be one or two. When one memory for storing the U-Boot is used, storing a first U-Boot file and a second U-Boot file in different storage areas of the same memory; when the number of the memories for storing the U-boots is two, the first U-Boot file and the second U-Boot file are respectively stored in two different memories.
The method for starting the device based on the universal boot loader in the embodiment comprises the following steps:
s101: and when the preset operation of starting the universal Boot loader U-Boot is detected, running a first U-Boot file stored in a first storage area.
For example, when a device based on the U-Boot detects a power-on operation or a restart operation, a first U-Boot file pre-stored in a first storage area is acquired, and the first U-Boot file stored in the first storage area is operated.
The preset operation for starting the universal Boot loader U-Boot includes, but is not limited to, a power-on operation or a restart operation, and may also be other preset operations.
When the device based on the U-Boot comprises two memories, and the first storage area and the second storage area belong to different memories, the device based on the U-Boot can select the first storage area by controlling the first chip selection signal, and select the second storage area by controlling the second chip selection signal.
When the device based on the U-Boot comprises a memory, and the first storage area and the second storage area belong to different storage address partitions of the memory respectively, the first storage area or the second storage area is selected by controlling an address selector.
S102: and reading a second U-Boot file stored in a second storage area, and judging whether the second U-Boot file is complete.
And running the code of the initial stage of the first U-Boot file by the U-Boot-based equipment, reading a second U-Boot file stored in a second storage area, and judging whether the second U-Boot file is complete.
The method for judging whether the second U-Boot file is complete may be to compare the content contained in the second U-Boot file with a pre-stored U-Boot reference file for verification to judge whether the content contained in the second U-Boot file is completely the same as the content contained in the U-Boot reference file for verification, and when it is confirmed that the two are completely the same, identify that the second U-Boot file is complete; and when only the two files are partially identical or completely different, identifying that the second U-Boot file is incomplete. And the version information of the pre-stored U-Boot reference file for verification corresponds to the version information of the second U-Boot file.
When the second U-Boot file is complete, executing step S103;
and when the second U-Boot file is not complete, executing the steps S104 to S105.
S103: and when the second U-Boot file is complete, starting the equipment through the second U-Boot file.
And when the device based on the U-Boot confirms that the second U-Boot file is complete, confirming that the upgrade of the U-Boot which is closest to the starting time is successful.
And the device based on the U-Boot only upgrades the second U-Boot file stored in the second storage area. The first storage area is used for backing up U-Boot files.
S104: and when the second U-Boot file is incomplete, copying the first U-Boot file to the second storage area, and replacing the second U-Boot file.
And when the device based on the U-Boot confirms that the second U-Boot file is incomplete, identifying that the U-Boot upgrade which is closest to the starting time of this time fails.
The device based on the U-Boot copies the first U-Boot file from the first storage area, stores the copied first U-Boot file into the second storage area, and replaces the original second U-Boot file with the copied first U-Boot file to form a new second U-Boot file.
S105: and starting the equipment through the replaced second U-Boot file.
And after the copied first U-Boot file is replaced by the original second U-Boot file, the device based on the U-Boot starts the device through the replaced second U-Boot file.
According to the scheme, the device based on the U-Boot backs up the first U-Boot file through the first storage area, when the upgrade failure of the second U-Boot file stored in the second storage area is confirmed, the first U-Boot file is copied to the second storage area and replaces the second U-Boot file, and the device is started through the replaced second U-Boot file, so that the normal starting of the device is guaranteed. The first U-Boot file in the first storage area is not supported to be changed, so that the first U-Boot file cannot be damaged by any software operation after delivery, the safety of the first U-Boot file is ensured, the normal starting of the U-Boot is ensured, the normal starting of the equipment is further ensured, the success rate of starting the equipment is improved, and the problem that the equipment cannot be started due to the failure of upgrading of the U-Boot is avoided.
Referring to fig. 2, fig. 2 is a flowchart illustrating another embodiment of a boot method for a generic bootloader-based device according to the present invention. The execution subject in this example is a generic bootloader-based device, which includes: the system comprises a Central Processing Unit (CPU) and a memory for storing a Universal Boot Loader (U-Boot), wherein the CPU and the memory can be connected through a Bootbus bus. The memory can be nand Flash or nor Flash. The number of the memories for storing the U-Boot can be one or two. When one memory for storing the U-Boot is used, storing a first U-Boot file and a second U-Boot file in different storage areas of the same memory; when the number of the memories for storing the U-boots is two, the first U-Boot file and the second U-Boot file are respectively stored in two different memories.
The method for starting the device based on the universal boot loader in the embodiment comprises the following steps:
s201: and when the preset operation of starting the universal Boot loader U-Boot is detected, running a first U-Boot file stored in a first storage area.
For example, when a device based on the U-Boot detects a power-on operation or a restart operation, a first U-Boot file pre-stored in a first storage area is acquired, and the first U-Boot file stored in the first storage area is operated.
The preset operation for starting the universal Boot loader U-Boot includes, but is not limited to, a power-on operation or a restart operation, and may also be other preset operations.
When the device based on the U-Boot comprises two memories, and the first storage area and the second storage area belong to different memories, the device based on the U-Boot can select the first storage area by controlling the first chip selection signal, and select the second storage area by controlling the second chip selection signal.
When the device based on the U-Boot comprises a memory, and the first storage area and the second storage area belong to different storage address partitions of the memory respectively, the first storage area or the second storage area is selected by controlling an address selector.
Optionally, after step S201, the method for starting the device based on the generic bootstrap loader may further include: when the first U-Boot file is incomplete, starting equipment through the second U-Boot file; and when the equipment is started, prompting a user that the equipment is abnormal.
For example, when a device based on the U-Boot obtains a first U-Boot file pre-stored in a first storage area, the device compares the first U-Boot file stored in the first storage area with an original first U-Boot file, determines whether the first U-Boot file is complete, reads a second U-Boot file stored in a second storage area when the first U-Boot file is confirmed to be incomplete, and starts the device through the second U-Boot file. And prompting the user that the equipment is abnormal when the equipment based on the U-Boot is started through completion. When the second U-Boot file is complete, the device based on the U-Boot can complete the starting; otherwise, the normal start cannot be performed.
And the device based on the U-Boot executes the step S202 when the first U-Boot file is confirmed to be complete.
S202: and reading a second U-Boot file stored in a second storage area, and judging whether the second U-Boot file is complete.
And running the code of the initial stage of the first U-Boot file by the U-Boot-based equipment, reading a second U-Boot file stored in a second storage area, and judging whether the second U-Boot file is complete.
The method for judging whether the second U-Boot file is complete may be to compare the content contained in the second U-Boot file with a pre-stored U-Boot reference file for verification to judge whether the content contained in the second U-Boot file is completely the same as the content contained in the U-Boot reference file for verification, and when it is confirmed that the two are completely the same, identify that the second U-Boot file is complete; and when only the two files are partially identical or completely different, identifying that the second U-Boot file is incomplete. And the version information of the pre-stored U-Boot reference file for verification corresponds to the version information of the second U-Boot file.
When the second U-Boot file is complete, executing step S203;
and when the second U-Boot file is not complete, executing the steps S204 to S205 or step S209.
S203: and when the second U-Boot file is complete, starting the equipment through the second U-Boot file.
And when the device based on the U-Boot confirms that the second U-Boot file is complete, confirming that the upgrade of the U-Boot which is closest to the starting time is successful.
And the device based on the U-Boot only upgrades the second U-Boot file stored in the second storage area. The first storage area is used for backing up U-Boot files.
When the device based on the U-Boot is started through a second U-Boot stored in a second storage area, starting a CPU watchdog program to detect whether the device is jammed in the starting process.
When the Device based on the U-Boot detects that the phenomenon of jamming occurs in the starting process, a Complex Programmable Logic Device (CPLD) connected with the CPU triggers a reset instruction.
When a stuck phenomenon or a failed start occurs during the start-up process, executing step S206; when the seizure phenomenon does not occur during the startup process, steps S207 to S208 are performed. The failed start may be a stuck state in the start process or a repeated restart in the start process.
S204: and when the second U-Boot file is incomplete, copying the first U-Boot file to the second storage area, and replacing the second U-Boot file.
And when the device based on the U-Boot confirms that the second U-Boot file is incomplete, identifying that the U-Boot upgrade which is closest to the starting time of this time fails.
The device based on the U-Boot copies the first U-Boot file from the first storage area, stores the copied first U-Boot file into the second storage area, and replaces the original second U-Boot file with the copied first U-Boot file to form a new second U-Boot file.
S205: and starting the equipment through the replaced second U-Boot file.
And after the copied first U-Boot file is replaced by the original second U-Boot file, the device based on the U-Boot starts the device through the replaced second U-Boot file.
For example, when the device based on the U-Boot is started through a second U-Boot stored in a second storage area, a CPU watchdog program is started to detect whether the device is jammed in the starting process.
When the Device based on the U-Boot detects that the phenomenon of jamming occurs in the starting process, a Complex Programmable Logic Device (CPLD) connected with the CPU triggers a reset instruction.
When a stuck phenomenon or a failed start occurs during the start-up process, executing step S206; the failed start may be a stuck state in the start process or a repeated restart in the start process.
When the seizure phenomenon does not occur during the startup process, steps S207 to S208 are performed.
S206: and when a reset instruction is detected or a preset operation for restarting the U-Boot is detected, executing the first U-Boot file which is operated and stored in the first storage area.
When the device based on the U-Boot detects a reset instruction or detects a preset operation triggering the restart of the U-Boot, the device based on the U-Boot is identified to be jammed in the starting process, and the step S201 is returned to restart the device.
Triggering the preset operation of restarting the U-Boot, wherein the preset operation can be that the equipment fails to successfully start the equipment system through a second U-Boot file within preset time; it may also be interrupted during the start-up of the device. The preset time may be 2 minutes, but is not limited thereto, and may be specifically set according to actual needs, and is not limited herein.
S207: and when the equipment finishes starting, judging whether the version information of the second U-Boot file is the same as that of the first U-Boot file.
And after the device based on the U-Boot is normally started, judging whether the version information of the second U-Boot file is the same as that of the first U-Boot file.
And when the version information of the second U-Boot file is different from the version information of the first U-Boot file, no processing is performed, and the device based on the U-Boot normally works.
And when the version information of the second U-Boot file is the same as the version information of the first U-Boot file, performing step S208.
S208: and when the version information of the second U-Boot file is the same as that of the first U-Boot file, prompting a user to upgrade the second U-Boot file again.
And the device based on the U-Boot identifies that the latest U-Boot upgrade before the current start fails when confirming that the version information of the second U-Boot file is the same as the version information of the first U-Boot file, and prompts a user to upgrade the second U-Boot file stored in the second storage area again.
At the moment, the user needs to upgrade the second U-Boot file stored in the second storage area again, and when the user upgrades the second U-Boot file manually, only new U-Boot software is allowed to be upgraded to the second storage area.
S209: and when the second U-Boot file is incomplete and the second storage area is abnormal, starting the equipment through the first U-Boot file.
And when the device based on the U-Boot judges that a second U-Boot file stored in a second storage area is incomplete, detecting whether the second storage area is abnormal or detecting whether the second storage area is damaged.
And when the device based on the U-Boot confirms that the second U-Boot file is incomplete and the second storage area is abnormal/damaged, starting the device through the first U-Boot file stored in the first storage area.
According to the scheme, the device based on the U-Boot backs up the first U-Boot file through the first storage area, when the upgrade failure of the second U-Boot file stored in the second storage area is confirmed, the first U-Boot file is copied to the second storage area and replaces the second U-Boot file, and the device is started through the replaced second U-Boot file, so that the normal starting of the device is guaranteed. The first U-Boot file in the first storage area is not supported to be changed, so that the first U-Boot file cannot be damaged by any software operation after delivery, the safety of the first U-Boot file is ensured, the normal starting of the U-Boot is ensured, the normal starting of the equipment is further ensured, the success rate of starting the equipment is improved, and the problem that the equipment cannot be started due to the failure of upgrading of the U-Boot is avoided.
When the second U-Boot file is incomplete and the second storage area is abnormal/damaged, the device based on the U-Boot is started through the first U-Boot file stored in the first storage area, and the problem that the device cannot be started due to damage of the storage area storing the U-Boot can be solved.
When the first U-Boot file is incomplete, starting the equipment through a second U-Boot file; when the second U-Boot file is incomplete and the first U-Boot file is complete, copying the first U-Boot file to a second storage area, and starting the copied U-Boot file; the first storage area and the second storage area can be monitored mutually, and if one storage area is damaged, the U-Boot file of the other storage area is replaced for starting.
Referring to fig. 3, fig. 3 is a schematic structural diagram of an apparatus based on a generic bootloader according to an embodiment of the present invention. For details, please refer to fig. 1 and the related description in the embodiment corresponding to fig. 1, which are not repeated herein. The generic bootloader-based device of the present embodiment includes a running module 310, a reading module 320, a first starting module 330, an updating module 340, and a second starting module 350.
The running module 310 is configured to run a first U-Boot file stored in a first storage area when detecting a preset operation of starting the universal Boot loader U-Boot.
For example, the running module 310 runs a first U-Boot file stored in a first storage area when detecting a preset operation of starting the universal Boot loader U-Boot.
The reading module 320 is configured to read a second U-Boot file stored in a second storage area, and determine whether the second U-Boot file is complete.
For example, the reading module 320 reads a second U-Boot file stored in a second storage area, and determines whether the second U-Boot file is complete. The reading module 320 sends the determination result to the first starting module 330 and the updating module 340.
The first starting module 330 is configured to receive the determination result sent by the reading module 320, and start the device through the second U-Boot file when the second U-Boot file is complete.
For example, the first Boot module 330 receives the determination result sent by the reading module 320, and when the determination result is that the second U-Boot file is complete, the device is booted through the second U-Boot file.
The updating module 340 is configured to receive the determination result sent by the reading module 320, copy the first U-Boot file to the second storage area when the second U-Boot file is incomplete, and replace the second U-Boot file.
For example, the updating module 340 receives the determination result sent by the reading module 320, and copies the first U-Boot file to the second storage area and replaces the second U-Boot file when the determination result is that the second U-Boot file is not complete.
The update module 340 sends notification information to the second Boot module 350 after replacing the second U-Boot file.
The second Boot module 350 is configured to receive the notification information sent by the update module 340, and Boot the device through the replaced second U-Boot file.
For example, the second Boot module 350 receives the notification information sent by the update module 340, and boots the device through the replaced second U-Boot file.
According to the scheme, the device based on the U-Boot backs up the first U-Boot file through the first storage area, when the upgrade failure of the second U-Boot file stored in the second storage area is confirmed, the first U-Boot file is copied to the second storage area and replaces the second U-Boot file, and the device is started through the replaced second U-Boot file, so that the normal starting of the device is guaranteed. The first U-Boot file in the first storage area is not supported to be changed, so that the first U-Boot file cannot be damaged by any software operation after delivery, the safety of the first U-Boot file is ensured, the normal starting of the U-Boot is ensured, the normal starting of the equipment is further ensured, the success rate of starting the equipment is improved, and the problem that the equipment cannot be started due to the failure of upgrading of the U-Boot is avoided.
Referring to fig. 4, fig. 4 is a schematic structural diagram of another embodiment of a device based on a generic bootloader according to the present invention. For details, please refer to fig. 2 and the related description in the embodiment corresponding to fig. 2, which are not repeated herein. The device based on the generic bootloader of this embodiment includes an operation module 401, a reading module 402, a first starting module 403, an updating module 404, a second starting module 405, a determining module 406, a first prompting module 407, a third starting module 408, a second prompting module 409, a fourth starting module 410, and a restarting module 411.
The running module 401 is configured to run a first U-Boot file stored in a first storage area when detecting a preset operation of starting the universal Boot loader U-Boot.
The reading module 402 is configured to read a second U-Boot file stored in a second storage area, and determine whether the second U-Boot file is complete. The reading module 402 sends the determination result to the first starting module 403, the updating module 404 and the fourth starting module 410.
The first starting module 403 is configured to receive the determination result sent by the reading module 402, and start the device through the second U-Boot file when the determination result is that the second U-Boot file is complete.
The updating module 404 is configured to receive the determination result sent by the reading module 402, copy the first U-Boot file to the second storage area when the determination result is that the second U-Boot file is not complete, and replace the second U-Boot file.
The second Boot module 405 is configured to Boot the device through the replaced second U-Boot file.
The determining module 406 is configured to determine whether the version information of the second U-Boot file is the same as the version information of the first U-Boot file when the device is started. The judgment module 406 sends the judgment result to the first prompting module 407.
The first prompting module 407 is configured to receive the determination result sent by the determining module 406, and prompt the user to upgrade the second U-Boot file again when the version information of the second U-Boot file is the same as the version information of the first U-Boot file.
The third starting module 408 is configured to start the device through the second U-Boot file when the first U-Boot file is incomplete.
The second prompting module 409 is used for prompting the user that the equipment is abnormal when the equipment is started.
The fourth starting module 410 is configured to receive the determination result sent by the reading module 402, and start the device through the first U-Boot file when the second U-Boot file is incomplete and the second storage area is abnormal.
Further, the restart module 411 is configured to run the first U-Boot file stored in the first storage area when a reset instruction is detected or a preset operation that triggers restarting of the U-Boot is detected.
For example, when detecting a reset instruction or detecting a preset operation triggering the restart of the U-Boot, the restart module 411 runs a first U-Boot file stored in the first storage area. When the first U-Boot file is run, the restart module 411 sends notification information to the read module 402 to notify the read module 402 to read a second U-Boot file stored in a second storage area, and determines whether the second U-Boot file is complete.
According to the scheme, the device based on the U-Boot backs up the first U-Boot file through the first storage area, when the upgrade failure of the second U-Boot file stored in the second storage area is confirmed, the first U-Boot file is copied to the second storage area and replaces the second U-Boot file, and the device is started through the replaced second U-Boot file, so that the normal starting of the device is guaranteed. The first U-Boot file in the first storage area is not supported to be changed, so that the first U-Boot file cannot be damaged by any software operation after delivery, the safety of the first U-Boot file is ensured, the normal starting of the U-Boot is ensured, the normal starting of the equipment is further ensured, the success rate of starting the equipment is improved, and the problem that the equipment cannot be started due to the failure of upgrading of the U-Boot is avoided.
When the second U-Boot file is incomplete and the second storage area is abnormal/damaged, the device based on the U-Boot is started through the first U-Boot file stored in the first storage area, and the problem that the device cannot be started due to damage of the storage area storing the U-Boot can be solved.
When the first U-Boot file is incomplete, starting the equipment through a second U-Boot file; when the second U-Boot file is incomplete and the first U-Boot file is complete, copying the first U-Boot file to a second storage area, and starting the copied U-Boot file; the first storage area and the second storage area can be monitored mutually, and if one storage area is damaged, the U-Boot file of the other storage area is replaced for starting.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.