Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a method and a device for starting an embedded Linux main and standby operating system based on a ping-pong mechanism, which can realize the quick starting of the embedded Linux main and standby operating system.
In order to solve the technical problems, the invention discloses a method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism, which is applied to a microprocessor chip internal ROM of the embedded system and comprises ROMCODE of the main system and ROMCODE of a standby system, wherein the architecture of the embedded system comprises a flash storage area, the flash storage area is provided with a main area and a standby area, the main area is configured with a main system image file, and the standby area is configured with a standby system image file, and the method comprises the following steps:
executing ROMCODE of the primary system and ROMCODE of the backup system;
the method comprises the steps of checking a secondary guide program image file in a main system image file and a secondary guide program image file in a backup system image file, and storing a checking result into a checking record, wherein the checking result comprises a system identifier, an image file name and a checking success or failure identifier;
if the verification of the secondary boot program image file in the main system image file is successful, starting the secondary boot program image file in the main system image file;
if the verification of the secondary boot image file in the backup system image file is successful, the secondary boot image file in the backup system image file is started.
Further, the method further comprises:
checking Uboot image files in the main system image files and Uboot image files in the backup system image files, and storing the checking results into checking records;
if the Uboot image file in the main system image file is successfully checked, starting the Uboot image file in the main system image file;
if the Uboot image file in the backup system image file is successfully checked, starting the Uboot image file in the backup system image file.
Further, the method further comprises:
Checking the kernel image file in the main system image file and the kernel image file in the backup system image file;
If the verification of the kernel mirror image file in the main system mirror image file is successful, guiding the kernel mirror image file in the main system mirror image file to the memory for running, mounting the root file system, and ending the starting process;
If the verification of the kernel image file in the image file of the main system fails, and the verification of the kernel image file in the image file of the backup system succeeds, the kernel image file in the image file of the backup system is guided to the memory for running, the root file system is mounted, and the starting process is ended.
Further, the method further comprises:
acquiring a check record in an idle state after the system is started;
If the verification record contains a verification result of verification failure, acquiring the position of the mirror image file which fails to be verified in the flash storage area according to the system identifier and the mirror image file name in the verification result;
And repairing the mirror image file with verification failure.
Further, the method adopts an fdisk tool to repair the image file which fails to be checked.
On the other hand, the invention also discloses a device for starting the embedded Linux main and standby operating system based on the ping-pong mechanism, which comprises ROMCODE of the main system and ROMCODE of the standby system in the ROM inside the microprocessor chip of the embedded system, wherein the architecture of the embedded system comprises a flash storage area, the flash storage area is provided with a main area and a standby area, the main area is configured with a main system image file, and the standby area is configured with a standby system image file, and the device comprises:
ROMCODE a start-up module for executing ROMCODE of the primary system and ROMCODE of the backup system;
the system comprises a first verification module, a second verification module and a first verification module, wherein the first verification module is used for verifying a second-level guide program image file in a main system image file and a second-level guide program image file in a backup system image file;
The first starting module is used for starting the secondary guide program image file in the main system image file if the secondary guide program image file in the main system image file is successfully checked, and starting the secondary guide program image file in the backup system image file if the secondary guide program image file in the backup system image file is successfully checked.
Further, the apparatus further comprises:
The second checking module is used for checking the Uboot image files in the main system image files and the backup system image files;
The second starting module is used for starting the Uboot image file in the main system image file if the Uboot image file in the main system image file is successfully checked, and starting the Uboot image file in the backup system image file if the Uboot image file in the backup system image file is successfully checked.
Further, the apparatus further comprises:
The third checking module is used for checking the kernel image file in the main system image file and the kernel image file in the backup system image file;
and the third starting module is used for guiding the kernel mirror image file in the mirror image file of the main system to run to the memory if the kernel mirror image file in the mirror image file of the main system is successfully checked, mounting the root file system and ending the starting process, and guiding the kernel mirror image file in the mirror image file of the backup system to run to the memory if the kernel mirror image file in the mirror image file of the main system is successfully checked and mounting the root file system and ending the starting process.
Further, the apparatus further comprises:
the system comprises a repair module, a flash storage area, a storage module and a storage module, wherein the repair module is used for acquiring a check record in an idle state after the system is started, and if the check record contains a check result of check failure, acquiring the position of a mirror file of the check failure in the flash storage area according to a system identifier and a mirror file name in the check result;
further, the repair module repairs the image file with the check failure by adopting an fdisk tool.
Compared with the prior art, the embedded Linux main and standby operating system starting method and device based on the ping-pong mechanism have the advantages that in the starting process, the main system and the backup system are started simultaneously, if a certain stage in the starting process of the main system fails, the corresponding mirror image file of the backup system is started, the starting is not stopped, the mirror image file of the main system in the flash is not repaired, the verification result is recorded only, the repair of the flash is placed in an idle state after the system is started, the starting time is not occupied, the starting smoothness is ensured, and the running time of an application program is not influenced.
Detailed Description
The embodiment discloses a method for starting an embedded Linux active/standby operating system based on a ping-pong mechanism, as shown in fig. 1. The ROM inside the microprocessor chip of the embedded system contains ROMCODE of the main system and ROMCODE of the backup system. ROMCODE is a piece of code that is solidified into the ROM inside the microprocessor chip, which cannot be modified, as the first boot program of the system. In this embodiment, ROMCODE of the main system starts at the 0 address of the on-chip ROM and ROMCODE of the backup system starts at the offset address of the on-chip ROM.
The framework of the embedded system comprises a flash storage area, wherein the flash storage area is provided with a main area and a backup area, the main area is configured with a main system image file, and the backup area is configured with a backup system image file, and in the embodiment, the image file used for starting comprises a secondary boot program image file, a Uboot image file and a kernel image file. The secondary boot program SPL (Secondary program loader) is used for initializing necessary devices of the embedded board card, such as a clock, a memory and a flash, and is used for preparing for loading UBoot, UBoot (Universal Boot Loader) is used for starting necessary hardware of the system, providing a debugging interface for initializing environment variables, preparing for loading a kernel, and kernel is a kernel of the system, and providing memory management, process management, a device driver, a system call interface and the like. After the kernel runs in the memory, the root file system rootfs is mounted, which is a system for logically storing and recovering named files and placed files, and then the running user application program can be started.
The method for starting the embedded Linux active/standby operating system disclosed by the embodiment comprises the following steps:
S101, executing ROMCODE of a main system and ROMCODE of a backup system;
ROMCODE is an MPU curing program, and according to the constraints of the MPU, the ROMCODE data is checked, and each MPU checking method may be different. If the verification fails, the chip cannot be started normally.
S102, checking a secondary guide program image file in a main system image file and a secondary guide program image file in a backup system image file, and storing a checking result into a checking record, wherein the checking result comprises a system identifier, an image file name and a checking success or failure identifier;
if the verification result of a certain time is that the verification of the secondary boot image file in the primary system image file is successful, the verification failure of the secondary boot image file in the backup system image file can be recorded as:
main system SPL 1 and backup system SPL 0
Here, "1" means that the check succeeds, and "0" means that the check fails.
S103, if the secondary boot program image file in the main system image file is successfully checked, starting the secondary boot program image file in the main system image file;
if the verification of the secondary boot image file in the backup system image file is successful, the secondary boot image file in the backup system image file is started.
If the SPL image files in the image files of the main system and the SPL image files in the image files of the backup system are successfully checked, after the step is finished, the SPL in the main system and the SPL in the backup system are started.
S201, checking Uboot image files in the main system image files and Uboot image files in the backup system image files;
S202, if the Uboot image file in the main system image file is successfully checked, starting the Uboot image file in the main system image file;
if the Uboot image file in the backup system image file is successfully checked, starting the Uboot image file in the backup system image file.
S301, checking the kernel image file in the main system image file and the kernel image file in the backup system image file;
S302, if the verification of the kernel mirror image file in the mirror image file of the main system is successful, guiding the kernel mirror image file in the mirror image file of the main system to the memory for running, mounting the root file system, and ending the starting process;
If the verification of the kernel image file in the image file of the main system fails, and the verification of the kernel image file in the image file of the backup system succeeds, the kernel image file in the image file of the backup system is guided to the memory for running, the root file system is mounted, and the starting process is ended.
In the starting process, the main system and the backup system are started at the same time, if a certain stage in the starting process of the main system fails, the corresponding image file of the backup system is started, the starting is not stopped, the image file of the main system in the flash is not repaired, only the verification result is recorded, the starting is cut to the corresponding position of the backup system, the action is equivalent to ping-pong once, if the follow-up starting process fails again, the ping-pong action is triggered, the system is started to be switched back and forth in the main system and the backup system, the starting smoothness is ensured, and the running time of an application program is not influenced.
In order to ensure that the data of the main and standby systems are correct, the flash data needs to be repaired, and the repair of the flash data is performed after the system is started, namely, after the steps are executed, the method further comprises the following steps:
after the system is started, acquiring a check record in an idle state;
If the verification record contains a verification result of verification failure, acquiring the position of the mirror image file which fails to be verified in the flash storage area according to the system identifier and the mirror image file name in the verification result;
And repairing the mirror image file with verification failure.
The verification record data volume is extremely small, the storage time is hardly occupied, the time consumption of the starting process is not influenced, and the flash can be conveniently repaired.
The repair of flash data does not occupy the starting time, so that the main and standby system is started with the characteristic of a pipeline, and the system can be started on time like normal conditions under abnormal conditions, thereby ensuring the normal operation of the system on-line program. Specifically, the flash repair can repair the image file which fails to be checked by calling a disk repair tool, such as an fdisk tool of Linux, through the system.
The embodiment also discloses a device for realizing the embedded Linux active/standby operating system starting method based on the ping-pong mechanism, as shown in fig. 2. The embedded system comprises a microprocessor chip, a backup system and a device, wherein the ROM in the microprocessor chip of the embedded system comprises ROMCODE of a main system and ROMCODE of the backup system, the architecture of the embedded system comprises a flash storage area, the flash storage area is provided with a main area and a backup area, the main area is configured with a main system image file, and the backup area is configured with a backup system image file, and the device comprises:
ROMCODE a start-up module for executing ROMCODE of the primary system and ROMCODE of the backup system;
the system comprises a first verification module, a second verification module and a first verification module, wherein the first verification module is used for verifying a second-level guide program image file in a main system image file and a second-level guide program image file in a backup system image file;
The first starting module is used for starting the secondary guide program image file in the main system image file if the secondary guide program image file in the main system image file is successfully checked, and starting the secondary guide program image file in the backup system image file if the secondary guide program image file in the backup system image file is successfully checked.
The second checking module is used for checking the Uboot image files in the main system image files and the backup system image files;
The second starting module is used for starting the Uboot image file in the main system image file if the Uboot image file in the main system image file is successfully checked, and starting the Uboot image file in the backup system image file if the Uboot image file in the backup system image file is successfully checked.
The third checking module is used for checking the kernel image file in the main system image file and the kernel image file in the backup system image file;
and the third starting module is used for guiding the kernel mirror image file in the mirror image file of the main system to run to the memory if the kernel mirror image file in the mirror image file of the main system is successfully checked, mounting the root file system and ending the starting process, and guiding the kernel mirror image file in the mirror image file of the backup system to run to the memory if the kernel mirror image file in the mirror image file of the main system is successfully checked and mounting the root file system and ending the starting process.
In order to ensure that the data of the main and standby systems are correct, the flash data needs to be repaired, and the device further comprises:
the system comprises a repair module, a flash storage area, a storage module and a storage module, wherein the repair module is used for acquiring a check record in an idle state after the system is started, and if the check record contains a check result of check failure, acquiring the position of a mirror file of the check failure in the flash storage area according to a system identifier and a mirror file name in the check result;
In this embodiment, the repair module repairs the image file with the fdisk tool that fails in verification.
The invention provides a concept and a method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism, and particularly provides a method and a plurality of ways for realizing the technical scheme, wherein the method and the method are only preferred embodiments of the invention, and it should be pointed out that a plurality of improvements and modifications can be made by a person with ordinary skill in the art without departing from the principle of the invention, and the improvements and the modifications are also regarded as the protection scope of the invention. The components not explicitly described in this embodiment can be implemented by using the prior art.