Secondary starting system and method based on U-Boot
By designing a secondary startup system based on U-Boot, using redundant process design in SPL and U-Boot stages, supporting multiple board-level environments and startup media, the customized design and single secondary startup program in the existing technology are solved. Media support issues achieve high reliability and fast system startup.
Patent Information
- Application Number
- CN202411542349.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-10-31
AI Technical Summary
The existing secondary startup program is designed to be customized and cannot be adapted to multiple board-level environments. It only supports one startup medium. Failure to load will reduce the reliability of system startup and extend the overall startup time.
Design a secondary boot system based on U-Boot. Through the redundant process design of SPL and U-Boot stages, it supports multiple board-level environments and startup media, dynamically configures startup media code and bootargs environment variables, and improves startup success rate. and reliability.
It realizes the universality of the secondary startup program, improves the loading success rate of the startup media image file and the reliability of system startup, and shortens the system startup time.
Smart Images

Figure CN119396478A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded systems, and in particular to a secondary startup system and method based on U-Boot. Background Art
[0002] In the startup process of the main control chip, the secondary startup program is usually between the main control chip ROMCODE and the operating system; after the chip is powered on, the on-chip ROMCODE is started first, then the secondary startup program in the external startup medium is loaded, and finally the secondary startup program loads the operating system to complete the startup process.
[0003] U-Boot is the abbreviation of "the Universal Boot Loader" and is an open source bootloader project. As a commonly used open source secondary boot program, U-Boot is widely used in the field of embedded devices and has become the de facto standard in the field of embedded Linux devices. It is a mainstream bootloader.
[0004] At present, in actual applications, for a specific board-level environment, the secondary boot program is usually customized and only applies to one board-level environment; the secondary boot program generally only supports one boot medium on the board, and loads the software image in the boot medium. If the loading fails, the current boot fails; for the case of supporting multiple boot media, the boot order of these boot media is generally fixed, that is, the subsequent boot media is used for booting only after the previous boot media fails to load. The loading failure here generally includes an error in the external media reading process or a data verification failure of the loaded image.
[0005] In summary, existing secondary startup procedures and startup methods generally have the following shortcomings:
[0006] 1) The secondary boot program is a customized design and cannot adapt to a variety of board-level environments;
[0007] 2) In the case where only one type of boot media is supported, if the booting of this type of media fails, the reliability of the normal booting of the system will be reduced;
[0008] 3) For the case where multiple boot media are supported to be loaded in a fixed order, the subsequent boot media can only be used to load after the previous boot media fails to load, which prolongs the overall boot time of the system. Summary of the invention
[0009] In order to solve the above technical problems, the present invention provides a two-level boot system based on U-Boot, wherein the hardware part of the two-level boot system includes a main control chip, wherein the main control chip integrates ROM, SRAM and special registers, wherein ROMCODE is solidified in the ROM; meanwhile, the main control chip is connected to a boot medium, DDR and a serial port through an output and input interface, wherein the boot medium includes a boot medium I and a boot medium II, wherein the boot medium I and the boot medium II both store image files required for system startup (including SPL, U-Boot, operating system and file system), the DDR provides a loading and running storage space for the image file, and the serial port is used to output a system startup log;
[0010] The software part of the secondary boot system includes a secondary boot program, which includes two images: SPL and U-Boot. By executing different board-level compilation configurations, the U-boot image is divided into two types, namely u-boot.img without integrated firmware and u-boot.itb with integrated firmware.
[0011] In one embodiment of the present invention, the SPL first reads the boot media code transmitted by ROMCODE; then the SPL loads the U-Boot image in a corresponding set of boot media sequence, and transmits the successfully loaded boot media code to U-Boot; U-Boot loads the operating system image in a corresponding set of boot media sequence according to the boot media code transmitted by SPL, and prints the used media type information through the serial port;
[0012] Different board-level compilation configurations are carried in compilation script files, which include different board-level compilation configurations corresponding to different compilation options. Secondary startup programs suitable for different board levels are generated by executing the compilation script + options.
[0013] In one embodiment of the present invention, the U-Boot is compiled once to generate two images, SPL and U-Boot, at the same time, wherein ROMCODE starts SPL and SPL starts U-Boot; by executing different board-level compilation configurations, the U-boot image is divided into u-boot.img without firmware integration and u-boot.itb with firmware integration, wherein u-boot.itb is a packaging format of firmware and u-boot.bin files; for the RISCV architecture, the corresponding firmware is OpenSBI.
[0014] The present invention also provides a secondary startup method based on U-Boot, the secondary startup method is based on the two stages of SPL loading U-boot and U-boot loading the operating system in claim 1, and the SPL loading U-boot stage includes the following steps:
[0015] Step S11: After the SPL starts running, it first reads the boot media code transmitted by ROMCODE, and the boot media code is stored in a dedicated register inside the main control chip;
[0016] Step S12: Then, the U-boot image is loaded in the order of a group of boot media corresponding to the boot media code; if the current boot media loads the U-boot image successfully, the subsequent boot media in the group will not be loaded, and the boot media code will be maintained, and the successfully loaded media code will be written into the dedicated register;
[0017] Step S13: If the current boot medium fails to load the U-boot image, the U-boot image in the next boot medium is loaded in the order of the boot media in this group; if all the boot media in this group fail to load the U-boot image, the U-boot loading failure information is printed through the serial port.
[0018] In one embodiment of the present invention, the U-boot loading operating system stage includes the following steps:
[0019] Step S21: After U-boot starts running, it first reads the boot medium code transmitted by SPL, and the boot medium code is stored in a dedicated register inside the main control chip;
[0020] Step S22: then load the operating system image in the order of a group of boot media corresponding to the boot medium code; if the current boot medium loads the operating system image successfully, then no subsequent boot media in the group will be loaded;
[0021] Step S23: If the current boot medium fails to load the operating system image, the operating system image in the next boot medium is loaded in the order of the boot media in this group; if all the boot media in this group fail to load the operating system image, the operating system loading failure information is printed through the serial port.
[0022] In one embodiment of the present invention, SPL first reads the boot medium code, and the boot medium code is divided into '01' and '02', wherein the boot medium sequence corresponding to '01' is boot medium I and boot medium II, and the boot medium sequence corresponding to '02' is boot medium II and boot medium I; when the boot medium code is '01', SPL first loads the U-boot image in boot medium I, and if the U-boot image in boot medium I is loaded successfully, '01' is written to a dedicated register; if the U-boot image in boot medium I fails to load, the U-boot image in boot medium II continues to be loaded, and if the U-boot image in boot medium II is loaded successfully, '02' is written to a dedicated register, otherwise the U-boot loading failure information is printed through the serial port, and the boot process ends.
[0023] In one embodiment of the present invention, when the boot medium code is '02', SPL first loads the U-boot image in the boot medium II. If the U-boot image in the boot medium II is loaded successfully, '02' is written to the dedicated register; if the U-boot image in the boot medium II fails to load, the U-boot image in the boot medium I continues to be loaded. If the U-boot image in the boot medium I is loaded successfully, '01' is written to the dedicated register, otherwise the U-boot loading failure information is printed through the serial port to end the current boot process.
[0024] In one embodiment of the present invention, U-boot first reads the boot medium code, and the boot medium code is divided into '01' and '02', wherein the boot medium sequence corresponding to '01' is boot medium I, boot medium II, and the boot medium sequence corresponding to '02' is boot medium II, boot medium I. When the boot medium code is '01', U-boot first loads the operating system image in the boot medium I. If the operating system image in the boot medium I is successfully loaded, '01' is written to the dedicated register, and the bootargs environment variable is configured, and bootargs is configured to load the file system in the boot medium I for subsequent operating system to start the file system; if the operating system image in the boot medium I fails to load, the operating system image in the boot medium II continues to load. If the operating system image in the boot medium II is successfully loaded, '02' is written to the dedicated register, and the bootargs environment variable is configured, and bootargs is configured to load the file system in the boot medium II for subsequent operating system to start the file system, otherwise the failure information of loading the operating system is printed through the serial port, and the current boot process is terminated.
[0025] In one embodiment of the present invention, when the boot medium code is '02', U-boot first loads the operating system image in the boot medium II. If the operating system image in the boot medium II is loaded successfully, '02' is written to the dedicated register, and the bootargs environment variable is configured. Bootargs is configured to load the file system in the boot medium II for subsequent operating system to start the file system; if the operating system image in the boot medium II fails to load, the operating system image in the boot medium I continues to be loaded. If the operating system image in the boot medium I is loaded successfully, '01' is written to the dedicated register, and the bootargs environment variable is configured. Bootargs is configured to load the file system in the boot medium I for subsequent operating system to start the file system. Otherwise, the failure information of loading the operating system is printed through the serial port, and the current boot process is ended.
[0026] The above technical solution of the present invention has the following advantages compared with the prior art:
[0027] (1) Supports multiple board-level compilation options to support multiple board-level environments, achieving the versatility of the secondary boot program;
[0028] (2) The redundant process design of the boot media in the SPL and U-Boot stages is implemented, which improves the success rate and reliability of loading the image file in the boot media;
[0029] (3) Dynamic configuration and step-by-step transmission of boot media code and bootargs environment variables are implemented, which speeds up system startup in the event of some boot media loading failures. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to make the contents of the present invention more clearly understood, the present invention is further described in detail below based on specific embodiments of the present invention in conjunction with the accompanying drawings.
[0031] Figure 1 It is a schematic diagram of the hardware components of the secondary boot system based on U-Boot of the present invention;
[0032] Figure 2 It is a software flow diagram of the secondary startup method based on U-Boot of the present invention. DETAILED DESCRIPTION
[0033] like Figure 1As shown, this embodiment provides a two-level boot system based on U-Boot, the hardware part of the two-level boot system includes a main control chip, the main control chip integrates ROM, SRAM and special registers, wherein ROMCODE is solidified in the ROM; at the same time, the main control chip is connected to a boot medium, DDR, and a serial port through an output and input interface, the boot medium includes a boot medium I and a boot medium II, wherein the boot medium I and the boot medium II both store image files required for system startup (including SPL, U-Boot, operating system and file system), the DDR provides loading and running storage space for the image file, and the serial port is used to output the system startup log.
[0034] like Figure 2 As shown, this embodiment also provides a secondary startup method based on U-Boot, where the RISCV architecture is taken as an example, the compilation script is build.sh, and the compilation option of the RISCV architecture board level is set to riscv_board_config. The compilation command for generating the secondary startup program is as follows:
[0035] . / build.shriscv_board_config.
[0036] By executing the make menuconfig command, open the U-Boot compilation configuration interface and enable the SPL configuration, so that the secondary boot program generated by compiling U-Boot includes two images, SPL and U-Boot, in which ROMCODE loads SPL and SPL loads U-boot.
[0037] By executing different board-level compilation configurations, the compiled U-boot images are divided into two types, namely u-boot.img without firmware integration and u-boot.itb with firmware integration. u-boot.itb is the packaging format of firmware and u-boot.bin files. Different firmware is selected for different hardware architectures; for RISCV architecture, the selected firmware is OpenSBI.
[0038] For the u-boot.itb of the above-mentioned integrated firmware, add the .its source file to the corresponding board-level source file directory, open the U-Boot compilation configuration interface by executing make menuconfig, and configure the corresponding .its source file path; taking the RISCV architecture as an example, its .its source file can be named riscv_opensbi.its.
[0039] For the above u-boot.img without integrated firmware, there is no need to add the board-level .its source file.
[0040] like Figure 1 As shown in the figure, the main control chip integrates ROM, SRAM and dedicated registers; ROMCODE is solidified in ROM, and ROMCODE starts to run after the main control chip is powered on. ROMCODE loads the SPL in the external boot medium and writes the successfully loaded boot medium code into the dedicated register for subsequent reading after SPL is started; SRAM provides loading and running storage space for the firmware integrated by SPL and U-boot.
[0041] Boot medium I and boot medium II store the image files required for system startup, including SPL, U-Boot, operating system and file system. The boot medium I and boot medium II are non-volatile storage media, and the types include MMC, QSPIflash, NOR flash, SATA disk and NVMe SSD, among which the subtypes of MMC include TF card, SD card and eMMC.
[0042] DDR provides loading and running storage space for U-Boot, operating system and file system.
[0043] The serial port is used to output the system startup log, including the startup process, U-boot loading results, operating system loading results and other information.
[0044] like Figure 2 As shown, each group of boot media used in the software process of the secondary boot method based on U-Boot includes two types. In this embodiment, boot medium I uses MMC, and boot medium II uses NVMe SSD.
[0045] The above process includes two stages: SPL loading U-boot and U-boot loading the operating system.
[0046] During the U-boot loading phase of SPL, SPL first reads the boot media code, which is divided into '01' and '02'. The boot media order corresponding to '01' is MMC, NVMe SSD, and the boot media order corresponding to '02' is NVMeSSD, MMC. When the boot media code is '01', SPL first loads the U-boot image in MMC. If the U-boot image in MMC is loaded successfully, '01' is written to the dedicated register; if the U-boot image in MMC fails to load, the U-boot image in NVMe SSD continues to load. If the U-boot image in NVMe SSD is loaded successfully, '02' is written to the dedicated register, otherwise the U-boot loading failure information is printed through the serial port, and the boot process ends. When the boot medium code is '02', SPL first loads the U-boot image in the NVMe SSD. If the U-boot image in the NVMe SSD is loaded successfully, '02' is written to the dedicated register. If the U-boot image in the NVMe SSD fails to load, the U-boot image in the MMC continues to be loaded. If the U-boot image in the MMC is loaded successfully, '01' is written to the dedicated register. Otherwise, the U-boot loading failure information is printed through the serial port to end the current boot process.
[0047] During the U-boot operating system loading phase, U-boot first reads the boot media code, which is divided into '01' and '02'. The boot media order corresponding to '01' is MMC, NVMe SSD, and the boot media order corresponding to '02' is NVMe SSD, MMC. When the boot media code is '01', U-boot first loads the operating system image in the MMC. If the operating system image in the MMC is loaded successfully, '01' is written to the dedicated register, and the bootargs environment variable is configured. Bootargs is configured to load the file system in the MMC for subsequent operating system to start the file system; if the operating system image in the MMC fails to load, the operating system image in the NVMe SSD continues to load. If the operating system image in the NVMe SSD is loaded successfully, '02' is written to the dedicated register, and the bootargs environment variable is configured. Bootargs is configured to load the file system in the NVMe SSD for subsequent operating system to start the file system. Otherwise, the failure information of loading the operating system is printed through the serial port, and the current boot process ends. When the boot medium code is '02', U-boot first loads the operating system image in the NVMe SSD. If the operating system image in the NVMe SSD is loaded successfully, '02' is written to the dedicated register, and the bootargs environment variable is configured to configure bootargs to load the file system in the NVMe SSD for subsequent operating system to start the file system; if the operating system image in the NVMe SSD fails to load, the operating system image in the MMC continues to be loaded. If the operating system image in the MMC is loaded successfully, '01' is written to the dedicated register, and the bootargs environment variable is configured to configure bootargs to load the file system in the MMC for subsequent operating system to start the file system. Otherwise, the failure information of loading the operating system is printed through the serial port, and the current boot process ends.
[0048] In the secondary startup system described in this embodiment, build.sh is a compilation script, and board1_config and board2_config are compilation options for board1 and board2 respectively.
[0049] Generate the compilation command of the board1 secondary startup program: . / build.shboard1_config;
[0050] Generate the compilation command for the board-level board2 secondary startup program: . / build.shboard2_config.
[0051] By enabling the SPL configuration of U-Boot, the secondary boot program generated by compiling U-Boot includes two images, SPL and U-Boot, in which ROMCODE loads SPL and SPL loads U-Boot.
[0052] By executing different board-level compilation configurations, the compiled U-boot images are divided into two types, namely u-boot.img without firmware integration and u-boot.itb with firmware integration. u-boot.itb is the packaging format of firmware and u-boot.bin files. Different firmware is selected for different hardware architectures; preferably, for RISCV architecture, the selected firmware is OpenSBI.
[0053] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.
Claims
1. A two-stage boot system based on U-Boot, characterized in that: The hardware part of the secondary boot system includes a main control chip, which integrates ROM, SRAM and special registers, wherein ROMCODE is solidified in the ROM; at the same time, the main control chip is connected to a boot medium, DDR and a serial port through an output and input interface, wherein the boot medium includes a boot medium I and a boot medium II, wherein both the boot medium I and the boot medium II store the image file required for system startup, the DDR provides a loading and running storage space for the image file, and the serial port is used to output the system startup log; At the same time, the software part of the secondary boot system includes the secondary boot program, and the secondary boot program includes two images, SPL and U-Boot; by executing different board-level compilation configurations, the U-boot image is divided into two types, namely u-boot.img without integrated firmware and u-boot.itb with integrated firmware.
2. The two-stage starting system according to claim 1, characterized in that: The SPL first reads the boot media code transmitted by ROMCODE; then the SPL loads the U-Boot image in a corresponding set of boot media sequence, and transmits the successfully loaded boot media code to U-Boot; U-Boot loads the operating system image in the order of a corresponding set of boot media according to the boot media code passed by SPL, and prints the media type information used through the serial port; Different board-level compilation configurations are carried in compilation script files, which include different board-level compilation configurations corresponding to different compilation options. Secondary startup programs suitable for different board levels are generated by executing the compilation script + options.
3. The two-stage starting system according to claim 1, characterized in that: The U-Boot is compiled once and two images, SPL and U-Boot, are generated at the same time, wherein ROMCODE starts SPL and SPL starts U-Boot; by executing different board-level compilation configurations, the U-boot image is divided into u-boot.img without integrated firmware and u-boot.itb with integrated firmware, wherein u-boot.itb is the packaging format of firmware and u-boot.bin files; for the RISCV architecture, the corresponding firmware is OpenSBI.
4. A two-stage startup method based on U-Boot, the two-stage startup method is based on the two stages of SPL loading U-boot and U-boot loading the operating system in claim 1, characterized in that: The SPL loading U-boot stage includes the following steps: Step S11: After the SPL starts running, it first reads the boot media code transmitted by ROMCODE, and the boot media code is stored in a dedicated register inside the main control chip; Step S12: then load the U-boot image in a set of boot media sequence corresponding to the boot media code; If the current boot medium loads the U-boot image successfully, the subsequent boot medium in this group will no longer be loaded, and the boot medium code will be maintained, and the successfully loaded medium code will be written to the dedicated register; Step S13: If the current boot medium fails to load the U-boot image, then load the U-boot image in the next boot medium in the order of the boot media in this group; If all boot media in this group fail to load the U-boot image, the U-boot loading failure information is printed through the serial port.
5. The two-stage startup method according to claim 4, characterized in that: The U-boot operating system loading stage includes the following steps: Step S21: After U-boot starts running, it first reads the boot medium code transmitted by SPL, and the boot medium code is stored in a dedicated register inside the main control chip; Step S22: then load the operating system image in the order of a group of boot media corresponding to the boot medium code; if the current boot medium loads the operating system image successfully, then no subsequent boot media in the group will be loaded; Step S23: if the current boot medium fails to load the operating system image, then load the operating system image in the next boot medium in the order of the boot media in the current group; If all boot media in this group fail to load the operating system image, the operating system loading failure information is printed through the serial port.
6. The two-stage startup method according to claim 4, characterized in that: SPL first reads the boot media code, which is divided into '01' and '02'. The boot media sequence corresponding to '01' is boot media I, boot media II, and the boot media sequence corresponding to '02' is boot media II, boot media I. When the boot medium code is '01', SPL first loads the U-boot image in boot medium Ⅰ. If the U-boot image in boot medium Ⅰ is loaded successfully, '01' is written to the dedicated register; if the U-boot image in boot medium Ⅰ fails to load, the U-boot image in boot medium Ⅱ continues to be loaded. If the U-boot image in boot medium Ⅱ is loaded successfully, '02' is written to the dedicated register. Otherwise, the U-boot loading failure information is printed through the serial port to end this boot process.
7. The two-stage startup method according to claim 6, characterized in that: When the boot medium code is '02', SPL first loads the U-boot image in boot medium II. If the U-boot image in boot medium II is loaded successfully, '02' is written to the dedicated register; If the U-boot image in boot medium II fails to load, continue to load the U-boot image in boot medium I. If the U-boot image in boot medium I is loaded successfully, write '01' to the dedicated register. Otherwise, print the U-boot loading failure information through the serial port and end the current boot process.
8. The two-stage startup method according to claim 5, characterized in that: U-boot first reads the boot media code. The boot media code is divided into '01' and '02'. The boot media sequence corresponding to '01' is boot media I, boot media II, and the boot media sequence corresponding to '02' is boot media II, boot media I. When the boot medium code is '01', U-boot first loads the operating system image in boot medium Ⅰ. If the operating system image in boot medium Ⅰ is loaded successfully, '01' is written to the dedicated register and the bootargs environment variable is configured. Bootargs is configured to load the file system in boot medium Ⅰ for subsequent operating system to start the file system. If the operating system image in boot medium I fails to load, continue to load the operating system image in boot medium II. If the operating system image in boot medium II is loaded successfully, write '02' to the dedicated register and configure the bootargs environment variable. Configure bootargs to load the file system in boot medium II for subsequent operating system to start the file system. Otherwise, print the operating system loading failure information through the serial port and end this boot process.
9. The two-stage startup method according to claim 8, characterized in that: When the boot medium code is '02', U-boot first loads the operating system image in boot medium II. If the operating system image in boot medium II is loaded successfully, '02' is written to the dedicated register, and the bootargs environment variable is configured to configure bootargs to load the file system in boot medium II for subsequent operating system to start the file system; if the operating system image in boot medium II fails to load, the operating system image in boot medium I continues to load. If the operating system image in boot medium I is loaded successfully, '01' is written to the dedicated register, and the bootargs environment variable is configured to configure bootargs to load the file system in boot medium I for subsequent operating system to start the file system, otherwise the failure information of loading the operating system is printed through the serial port, and the current boot process ends.
Citation Information
Patent Citations
Embedded system, control method and device thereof and storage medium
CN113485764A
Multi-core processor first-level startup program architecture based on U-Boot
CN114489821A
Multistage boot image loading by configuration of a bus interface
US20170123815A1
Cited By
Two-stage fusion starting method, device and equipment for embedded system and medium
CN121579093A