Embedded Linux main and standby operating system starting method and device based on ping-pong mechanism
By using the ping-pong mechanism startup method in embedded Linux systems, the rapid switching and startup of the main and standby system is solved, and the problem of long startup time of the main and standby system in the existing technology is solved, ensuring the rapid startup of the device and the normal operation of the application.
Patent Information
- Application Number
- CN202411607028.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-12
AI Technical Summary
In the prior art, the startup time of the embedded Linux main and standby operating system is relatively long, especially when the main system cannot start, it requires 2 times the normal startup time or the startup time of the device is extended by repairing the flash memory.
The embedded Linux main and backup operating system startup method based on the ping-pong mechanism is adopted. By including the ROM of the main system and the backup system in the ROM of the microprocessor chip, and setting the main area and the backup area in the flash memory area, the main system and the backup system are simultaneously started. If the main system fails during startup, switch to the corresponding image file of the backup system to start without repairing the main system image file in flash until the system starts in idle state.
It realizes the rapid startup of the embedded Linux main and backup operating system, ensures the smooth startup of the device and the timely operation of the application, and avoids the extension of the startup time.
Smart Images

Figure HDA0005129866480000011 
Figure HDA0005129866480000012
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of embedded technology, and specifically relates to a method and device for starting an embedded Linux main and standby operating system based on a ping-pong mechanism Background Art
[0002] As embedded Linux is developing rapidly in the emerging field of embedded operating systems, its application products are becoming more and more extensive, and its functions are becoming more and more complex, which puts forward new requirements for system stability. In order to ensure the reliability and stable operation of the system, industrial embedded products are usually configured with active and standby dual systems.
[0003] At present, there are two ways to start the main and standby dual systems: the first is to start the backup system when the main system cannot be started. For example, the Chinese invention patent application with application number 2014108371866 discloses a method for starting the main and standby embedded boot programs. The method first reads the main boot program for loading. If the loading fails, the device is restarted and the backup boot program is read for loading. This method is equivalent to consuming twice the normal startup time. The second is that when the main system cannot be started, the main system is restored using the files in the backup area, and then the main system is started again. For example, the Chinese invention patent application with application number 202211304625.8 discloses a backup startup method for an embedded system architecture. The embedded system architecture used in this method includes configuring the first system partition, the second system partition and the mirror area in the storage area. If both the first system partition and the second system partition cannot be started, the system files of the first system partition and the second system partition are restored according to the system mirror file in the mirror area; then, based on the system files restored by the first system partition, the system is started from the first system partition. Since the repair write flash memory is very slow, the startup time of the device is also extended.
[0004] Both of the above methods have the problem that when the main system cannot start, the entire device will take a long time to start, resulting in the application being unable to go online on time. In some application scenarios, there are requirements for the device's startup time. For example, if the startup time of the data acquisition terminal in the power industry is too long, the application will fail to connect to the power server. Summary of the invention
[0005] Purpose of the invention: The technical problem to be solved by the present invention is to provide a method and device for starting an embedded Linux main and standby operating system based on a ping-pong mechanism in view of the deficiencies in the prior art, which can realize the rapid startup of the embedded Linux main and standby operating system.
[0006] In order to solve the above technical problems, the present invention discloses a method for starting an embedded Linux main and backup operating system based on a ping-pong mechanism, wherein the internal ROM of a microprocessor chip of the embedded system includes a ROMCODE of a main system and a ROMCODE of a backup system; the architecture of the embedded system includes 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; the method comprises:
[0007] Execute the ROMCODE of the main system and the ROMCODE of the backup system;
[0008] Verify the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; save the verification result to the verification record; the verification result includes: system identification, image file name and verification success or failure identification;
[0009] If the secondary boot program image file in the main system image file is verified successfully, the secondary boot program image file in the main system image file is started;
[0010] If the secondary boot program image file in the backup system image file is verified successfully, the secondary boot program image file in the backup system image file is started.
[0011] Furthermore, the method further comprises:
[0012] Verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; save the verification result to the verification record;
[0013] If the Uboot image file in the main system image file is verified successfully, start the Uboot image file in the main system image file;
[0014] If the Uboot image file in the backup system image file is verified successfully, start the Uboot image file in the backup system image file.
[0015] Furthermore, the method further comprises:
[0016] Verify the kernel image file in the main system image file and the kernel image file in the backup system image file; save the verification result to the verification record;
[0017] If the kernel image file in the main system image file is verified successfully, the kernel image file in the main system image file is booted to the memory for execution, the root file system is mounted, and the startup process ends;
[0018] If the kernel image file in the main system image file fails to be verified, and the kernel image file in the backup system image file succeeds in being verified, the kernel image file in the backup system image file is booted to run in the memory, the root file system is mounted, and the startup process ends.
[0019] Furthermore, the method further comprises:
[0020] After the system is started, the verification record is obtained in the idle state;
[0021] If the verification record includes a verification result of a verification failure, obtaining the location of the image file that failed the verification in the flash storage area according to the system identifier and the image file name in the verification result;
[0022] Repair the image file that failed the verification.
[0023] Furthermore, the method uses the fdisk tool to repair the image file that fails verification.
[0024] On the other hand, the present invention also discloses an embedded Linux main-standby operating system startup device based on a ping-pong mechanism, wherein the internal ROM of a microprocessor chip of the embedded system includes a ROMCODE of a main system and a ROMCODE of a backup system; the architecture of the embedded system includes 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; the device comprises:
[0025] ROMCODE startup module, used to execute the ROMCODE of the main system and the ROMCODE of the backup system;
[0026] The first verification module is used to verify the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; and save the verification result to the verification record; the verification result includes: system identification, image file name and verification success or failure identification;
[0027] The first startup module is used to start the secondary boot program image file in the main system image file if the secondary boot program image file in the main system image file is verified successfully; if the secondary boot program image file in the backup system image file is verified successfully, start the secondary boot program image file in the backup system image file.
[0028] Furthermore, the device also includes:
[0029] The second verification module is used to verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; and save the verification result to the verification record;
[0030] The second startup module is used to start the Uboot image file in the main system image file if the Uboot image file in the main system image file is successfully verified; if the Uboot image file in the backup system image file is successfully verified, start the Uboot image file in the backup system image file.
[0031] Furthermore, the device also includes:
[0032] The third verification module is used to verify the kernel image file in the main system image file and the kernel image file in the backup system image file; and save the verification result to the verification record;
[0033] The third startup module is used to guide the kernel image file in the main system image file to the memory for execution, mount the root file system, and end the startup process if the kernel image file in the main system image file is successfully verified; if the kernel image file in the main system image file fails to be verified and the kernel image file in the backup system image file is successfully verified, guide the kernel image file in the backup system image file to the memory for execution, mount the root file system, and end the startup process.
[0034] Furthermore, the device also includes:
[0035] A repair module, used to obtain a verification record in an idle state after the system is started; if the verification record contains a verification result of a verification failure, the location of the image file that failed the verification in the flash storage area is obtained according to the system identifier and the image file name in the verification result;
[0036] Furthermore, the repair module uses the fdisk tool to repair the image file that fails the verification.
[0037] Beneficial effect: Compared with the prior art, the method and device for starting an embedded Linux main-standby operating system based on a ping-pong mechanism disclosed in the present invention start the main system and the backup system at the same time during the startup process. If the main system fails at a certain stage during the startup process, since the corresponding image file of the backup system is also started, the startup does not stop, and the image file of the main system in the flash is not repaired, but only the verification result is recorded. The repair of the flash is placed in an idle state after the system is started, which does not take up the startup time, thereby ensuring smooth startup and unaffected application running time. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments, and the above and / or other advantages of the present invention will become more clear.
[0039] Figure 1 It is a flowchart of a method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism;
[0040] Figure 2 The present invention is a block diagram of the composition of an embedded Linux main-standby operating system startup device based on the ping-pong mechanism. DETAILED DESCRIPTION
[0041] This embodiment discloses a method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism. Figure 1 As shown. The internal ROM of the microprocessor chip in which the embedded system is applied contains the ROMCODE of the main system and the ROMCODE of the backup system. ROMCODE is a section of code solidified into the internal ROM of the microprocessor chip. This code cannot be modified and serves as the first boot program of the system. In this embodiment, the ROMCODE of the main system starts from the address 0 of the internal ROM of the chip, and the ROMCODE of the backup system starts from the offset address of the internal ROM of the chip.
[0042] The architecture of the embedded system used includes a flash storage area, the flash storage area is set 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; in this embodiment, the image files used for startup include a secondary boot program image file, a Uboot image file, and a kernel image file. Among them, the secondary boot program SPL (Secondary program loader) is used to initialize the necessary components of the embedded board such as clock, memory, flash, and prepare for loading UBoot; UBoot (Universal Boot Loader) turns on the necessary hardware of the system, provides a debugging interface to initialize the environment variables, and prepares for loading the kernel; the kernel is the kernel, which is the core of the system and provides memory management, process management, device driver, system call interface, etc. After the kernel runs in the memory, the root file system rootfs is mounted. Rootfs is a system for logical storage and recovery of named files and placed files; then the user application can be started and run.
[0043] The embedded Linux main and standby operating system startup method disclosed in this embodiment includes:
[0044] S101, executing the ROMCODE of the main system and the ROMCODE of the backup system;
[0045] ROMCODE is the MPU firmware. According to the constraints of the MPU, the ROMCODE data will be verified. The verification method for each MPU may be different. If the verification fails, the chip cannot start normally.
[0046] S102, verifying the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; saving the verification result to a verification record; the verification result includes: a system identifier, an image file name, and a verification success or failure identifier;
[0047] If the verification result of a certain time is that the verification of the secondary boot program image file in the main system image file is successful, but the verification of the secondary boot program image file in the backup system image file fails, it can be recorded as:
[0048] Primary system SPL 1; backup system SPL 0
[0049] Here, "1" indicates successful verification, and "0" indicates failed verification.
[0050] S103, if the secondary boot program image file in the main system image file is successfully verified, start the secondary boot program image file in the main system image file;
[0051] If the secondary boot program image file in the backup system image file is verified successfully, the secondary boot program image file in the backup system image file is started.
[0052] If the SPL image file in the main system image file and the SPL image file in the backup system image file are both verified successfully, after this step is completed, the SPL in the main system and the backup system are both started.
[0053] S201, verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; save the verification result to the verification record;
[0054] S202, if the Uboot image file in the main system image file is successfully verified, start the Uboot image file in the main system image file;
[0055] If the Uboot image file in the backup system image file is verified successfully, start the Uboot image file in the backup system image file.
[0056] S301, verify the kernel image file in the main system image file and the kernel image file in the backup system image file; save the verification result to the verification record;
[0057] S302: If the kernel image file in the main system image file is successfully verified, the kernel image file in the main system image file is booted to the memory for execution, the root file system is mounted, and the boot process is terminated;
[0058] If the kernel image file in the main system image file fails to be verified, and the kernel image file in the backup system image file succeeds in being verified, the kernel image file in the backup system image file is booted to run in the memory, the root file system is mounted, and the startup process ends.
[0059] During the above startup process, the main system and the backup system are started at the same time. If the main system fails at some stage during the startup process, since the corresponding image file of the backup system is also started, the startup does not stop, nor does it repair the image file of the main system in the flash. Instead, it only records the verification result, which is equivalent to switching the startup to the corresponding position of the backup system. This action is equivalent to playing ping-pong once. If there is another failure in the subsequent startup process, the ping-pong action will be triggered, so that the system startup switches back and forth between the main and backup systems, ensuring smooth startup and unaffected application running time.
[0060] To ensure that the data in the active and standby systems is correct, the flash data needs to be repaired. The flash data repair is performed after the system is started, that is, after the above steps are completed, it also includes:
[0061] After the system is started, obtain the verification record in the idle state;
[0062] If the verification record includes a verification result of a verification failure, obtaining the location of the image file that failed the verification in the flash storage area according to the system identifier and the image file name in the verification result;
[0063] Repair the image file that failed the verification.
[0064] The amount of verification record data is extremely small, and saving it takes almost no time, does not affect the time-consuming startup process, and can facilitate the repair of the flash.
[0065] The repair of flash data does not take up the boot time, so the main and standby system startup has the characteristics of pipeline, and it can be started and completed on time in abnormal situations as in normal situations, ensuring the normal operation of the system and the online program. Specifically, the flash repair can be repaired by the system calling the disk repair tool, such as the Linux fdisk tool to repair the image file that failed the verification.
[0066] This embodiment also discloses a device for implementing the above-mentioned embedded Linux main and standby operating system startup method based on the ping-pong mechanism, such as Figure 2The internal ROM of the microprocessor chip of the embedded system includes the ROMCODE of the main system and the ROMCODE of the backup system; the architecture of the embedded system includes 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; the device includes:
[0067] ROMCODE startup module, used to execute the ROMCODE of the main system and the ROMCODE of the backup system;
[0068] The first verification module is used to verify the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; and save the verification result to the verification record; the verification result includes: system identification, image file name and verification success or failure identification;
[0069] The first startup module is used to start the secondary boot program image file in the main system image file if the secondary boot program image file in the main system image file is verified successfully; if the secondary boot program image file in the backup system image file is verified successfully, start the secondary boot program image file in the backup system image file.
[0070] The second verification module is used to verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; and save the verification result to the verification record;
[0071] The second startup module is used to start the Uboot image file in the main system image file if the Uboot image file in the main system image file is successfully verified; if the Uboot image file in the backup system image file is successfully verified, start the Uboot image file in the backup system image file.
[0072] The third verification module is used to verify the kernel image file in the main system image file and the kernel image file in the backup system image file; and save the verification result to the verification record;
[0073] The third startup module is used to guide the kernel image file in the main system image file to the memory for execution, mount the root file system, and end the startup process if the kernel image file in the main system image file is successfully verified; if the kernel image file in the main system image file fails to be verified and the kernel image file in the backup system image file is successfully verified, guide the kernel image file in the backup system image file to the memory for execution, mount the root file system, and end the startup process.
[0074] In order to ensure that the data of the main and standby systems are correct, the flash data needs to be repaired. The above device also includes:
[0075] A repair module, used to obtain a verification record in an idle state after the system is started; if the verification record contains a verification result of a verification failure, the location of the image file that failed the verification in the flash storage area is obtained according to the system identifier and the image file name in the verification result;
[0076] In this embodiment, the repair module uses the fdisk tool to repair the image file that fails verification.
[0077] The present invention provides a method and idea for starting an embedded Linux main and standby operating system based on a ping-pong mechanism. There are many methods and approaches to implement the technical solution. The above is only a preferred implementation of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the protection scope of the present invention. All components not specified in this embodiment can be implemented using existing technologies.
Claims
1. A method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism, characterized in that: The internal ROM of the microprocessor chip of the embedded system includes the ROMCODE of the main system and the ROMCODE of the backup system; The architecture of the embedded system includes a flash storage area, wherein the flash storage area is provided with a main area and a backup area, wherein the main area is configured with a main system image file, and the backup area is configured with a backup system image file; The method comprises: Execute the ROMCODE of the main system and the ROMCODE of the backup system; Verify the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; save the verification result to the verification record; the verification result includes: system identification, image file name and verification success or failure identification; If the secondary boot program image file in the main system image file is verified successfully, the secondary boot program image file in the main system image file is started; If the secondary boot program image file in the backup system image file is verified successfully, the secondary boot program image file in the backup system image file is started.
2. The method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism according to claim 1, characterized in that: Also includes: Verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; Save the verification results to the verification record; If the Uboot image file in the main system image file is verified successfully, start the Uboot image file in the main system image file; If the Uboot image file in the backup system image file is verified successfully, start the Uboot image file in the backup system image file.
3. The method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism according to claim 2, characterized in that: Also includes: Verify the kernel image file in the main system image file and the kernel image file in the backup system image file; Save the verification results to the verification record; If the kernel image file in the main system image file is verified successfully, the kernel image file in the main system image file is booted to the memory for execution, the root file system is mounted, and the startup process ends; If the kernel image file in the main system image file fails to be verified, and the kernel image file in the backup system image file succeeds in being verified, the kernel image file in the backup system image file is booted to run in the memory, the root file system is mounted, and the startup process ends.
4. The method for starting an embedded Linux active / standby operating system based on a ping-pong mechanism according to any one of claims 1 to 3, characterized in that: Also includes: After the system is started, the verification record is obtained in the idle state; If the verification record includes a verification result of a verification failure, obtaining the location of the image file that failed the verification in the flash storage area according to the system identifier and the image file name in the verification result; Repair the image file that failed the verification.
5. The method for starting an embedded Linux main and standby operating system based on a ping-pong mechanism according to claim 4, characterized in that: Use the fdisk tool to repair the image file that failed the verification.
6. An embedded Linux main and standby operating system startup device based on ping-pong mechanism, characterized in that: The internal ROM of the microprocessor chip of the embedded system includes the ROMCODE of the main system and the ROMCODE of the backup system; The architecture of the embedded system includes a flash storage area, wherein the flash storage area is provided with a main area and a backup area, wherein the main area is configured with a main system image file, and the backup area is configured with a backup system image file; The device comprises: ROMCODE startup module, used to execute the ROMCODE of the main system and the ROMCODE of the backup system; The first verification module is used to verify the secondary boot program image file in the main system image file and the secondary boot program image file in the backup system image file; and save the verification result to the verification record; the verification result includes: system identification, image file name and verification success or failure identification; The first startup module is used to start the secondary boot program image file in the main system image file if the secondary boot program image file in the main system image file is verified successfully; if the secondary boot program image file in the backup system image file is verified successfully, start the secondary boot program image file in the backup system image file.
7. The embedded Linux main and standby operating system startup device based on ping-pong mechanism according to claim 6 is characterized in that: Also includes: The second verification module is used to verify the Uboot image file in the main system image file and the Uboot image file in the backup system image file; Save the verification results to the verification record; The second startup module is used to start the Uboot image file in the main system image file if the Uboot image file in the main system image file is successfully verified; If the Uboot image file in the backup system image file is verified successfully, start the Uboot image file in the backup system image file.
8. The embedded Linux main-standby operating system startup device based on ping-pong mechanism according to claim 7 is characterized in that: Also includes: A third verification module is used to verify the kernel image file in the main system image file and the kernel image file in the backup system image file; Save the verification results to the verification record; The third startup module is used to guide the kernel image file in the main system image file to the memory to run, mount the root file system, and end the startup process if the kernel image file in the main system image file is successfully verified; If the kernel image file in the main system image file fails to be verified, and the kernel image file in the backup system image file succeeds in being verified, the kernel image file in the backup system image file is booted to run in the memory, the root file system is mounted, and the startup process ends.
9. The embedded Linux main and standby operating system startup device based on ping-pong mechanism according to any one of claims 6 to 8, characterized in that: Also includes: A repair module is used to obtain the calibration record in the idle state after the system is started; If the verification record includes a verification result of a verification failure, the location of the image file of the verification failure in the flash storage area is obtained according to the system identifier and the image file name in the verification result; 10. The embedded Linux main and standby operating system startup device based on ping-pong mechanism according to claim 9, characterized in that: The repair module uses the fdisk tool to repair the image file that fails verification.
Citation Information
Patent Citations
Backup starting method and device of embedded system architecture, equipment and chip
CN115373906A
Linux system startup method, device and equipment
CN108647119A
Embedded system, control method and device thereof and storage medium
CN113485764A
Operating system starting method and device, computing equipment and storage medium
CN118426848A
Virtual machine providing system
JP2013186692A