Method and apparatus for starting a device
By setting the lastbootdev and currentbootdev variables in the BootLoader, the appropriate storage medium can be quickly identified and loaded, solving the boot delay problem during system startup and achieving a faster boot process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INTEWELL (GUANGZHOU) SOFEWARE TECH CO LTD
- Filing Date
- 2022-12-27
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies require traversing multiple storage media during system startup, resulting in boot delays, especially when multiple storage media selection is not required, thus reducing the real-time performance of system startup.
By setting the two environment variables lastbootdev and currentbootdev, the appropriate and real storage media can be quickly identified and loaded, optimizing the bootloader's startup process and reducing redundant access.
It improves the real-time performance and maintainability of system startup, reduces boot time, and enhances the user's fast startup experience.
Smart Images

Figure CN115934174B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer operating system boot technology, and in particular to a device boot method and apparatus, a computing device, a computer-readable storage medium, and a computer program product. Background Technology
[0002] Currently, operating systems primarily boot from various storage media (such as eMMC, SD cards, USB, etc.) by having a Bootloader traverse a range of available and suitable storage media. Most third-party hardware development boards on the market come with multiple storage media options, allowing the Bootloader to select these media before system startup. This improves board-level compatibility with different storage media, enabling different operating systems to load into memory from various storage media. However, the downside is reduced system startup real-time performance, especially when users don't need multiple storage media for boot selection; traversing these media can lead to boot delays. Summary of the Invention
[0003] In view of the above-mentioned problems of the prior art, this application provides a device startup method and apparatus, a computing device, a computer-readable storage medium and a computer program product, which can quickly select a suitable and real-world storage medium to load the real-time system more quickly and provide real-time performance during the startup of the real-time system.
[0004] To achieve the above objectives, the first aspect of this application provides a method for starting a device, comprising:
[0005] Obtain a first environment variable and a second environment variable, wherein the first environment variable is used to store the storage medium identifier of the last booted image, and the second environment variable is used to store the storage medium identifier of the image to be booted now;
[0006] The target storage medium is determined based on the first and second environmental variables;
[0007] The boot image is loaded from the target storage medium to start the operating system on the target storage medium. This application, by setting two environment variables that store the identifiers of the storage medium containing the boot image, can quickly select a suitable and actually existing storage medium, thereby loading the real-time system faster and providing real-time performance during startup.
[0008] To achieve the above objectives, a second aspect of this application provides a device starting apparatus, comprising:
[0009] The variable acquisition module is used to acquire a first environment variable and a second environment variable, wherein the first environment variable is used to store the storage medium identifier of the last booted image, and the second environment variable is used to store the storage medium identifier of the image to be booted now.
[0010] The target storage medium determination module is used to determine the target storage medium based on the first environment variable and the second environment variable;
[0011] A loading module is used to load a boot image from the target storage medium to start the operating system in the target storage medium.
[0012] This application enables the rapid selection of a suitable and real-world storage medium by setting two environment variables that store the identifier of the boot image, thereby loading the real-time system faster and providing real-time performance during startup.
[0013] A third aspect of this application provides a computing device, including: a communication interface and at least one processor; wherein the at least one processor is configured to execute program instructions, which, when executed by the at least one processor, cause the computing device to perform any of the methods described in the first aspect above.
[0014] A fourth aspect of this application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a computer, cause the computer to perform any of the methods described in the first aspect above.
[0015] The fifth aspect of this application provides a computer program product comprising program instructions that, when executed by a computer, cause the computer to perform any of the methods described in the first aspect above. Attached Figure Description
[0016] Figure 1 This is a flowchart of an embodiment of the device startup method of this application;
[0017] Figure 2 This is a system operation diagram of the startup method of the device in this application;
[0018] Figure 3 This is a system operation diagram of the device startup method corresponding to Embodiment 1 of this application;
[0019] Figure 4 This is a system operation diagram of the device startup method corresponding to Embodiment 2 of this application;
[0020] Figure 5 This is a structural schematic diagram of the starting device of the equipment in this application;
[0021] Figure 6This is a schematic structural diagram of a computing device provided in an embodiment of this application.
[0022] It should be understood that the dimensions and shapes of the block diagrams in the above structural diagrams are for reference only and should not constitute an exclusive interpretation of the embodiments of this application. The relative positions and inclusion relationships between the block diagrams presented in the structural diagrams are only schematic representations of the structural relationships between the block diagrams, and are not intended to limit the physical connection methods of the embodiments of this application. Detailed Implementation
[0023] The technical solutions provided in this application will be further described below with reference to the accompanying drawings and embodiments. It should be understood that the system architecture and business scenarios provided in the embodiments of this application are mainly for illustrating possible implementations of the technical solutions of this application and should not be construed as the sole limitation on the technical solutions of this application. Those skilled in the art will recognize that the technical solutions provided in this application are equally applicable to similar technical problems as system architectures evolve and new business scenarios emerge.
[0024] It should be understood that the message debugging solutions provided in this application include message debugging methods and apparatus. Since these technical solutions solve problems based on the same or similar principles, some repetitive details may not be repeated in the following descriptions of specific embodiments. However, it should be considered that these specific embodiments have mutual references and can be combined with each other.
[0025] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. In case of any inconsistency, the meaning set forth in this specification or derived from the content described herein shall prevail. Furthermore, the terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit the scope of this application.
[0026] Because booting the operating system requires traversing all available and suitable storage media, the real-time performance of system startup is reduced, especially when the user does not require multiple storage media for boot selection; traversing these media leads to boot delays. Therefore, this application sets two environment variables that identify the storage media containing the boot image. Based on these two environment variables, a suitable and actually existing storage media can be quickly selected, thereby loading the real-time system faster and improving the real-time performance of the system startup.
[0027] The device startup method provided in this application embodiment can adapt to various storage media and start the real-time system in the fastest way to meet the needs of occasions with higher real-time requirements.
[0028] like Figure 1 As shown, this application provides a method for starting a device. The following refers to... Figure 1 The flowchart shown illustrates a first embodiment of the startup method for the device of this application. Wherein, as... Figure 1 As shown, in this first embodiment, the method includes:
[0029] S110: Obtain the first environment variable and the second environment variable, wherein the first environment variable is used to store the storage medium identifier of the last booted image, and the second environment variable is used to store the storage medium identifier of the image to be booted now.
[0030] In one embodiment, such as Figure 2 As shown, when the hardware device is powered on, an optimization mechanism is added to the boot mechanism of DistroBootcmd (boot command). Two new environment variables are added to the BootLoader: lastbootdev and currentbootdev. Lastbootdev stores the storage media number of the image that the user last booted, and currentbootdev stores the storage media number of the image that the user wants to boot.
[0031] The storage media can include eMMC, SD card, USB, and other storage media.
[0032] S120: Determine the target storage medium based on the first environmental variable and the second environmental variable;
[0033] S130: Load the boot image from the target storage medium to start the operating system in the target storage medium.
[0034] This application enables the BootLoader to quickly and dynamically identify available boot images from various storage media by judging the differences between the two values, and then start the operating system.
[0035] In one embodiment, determining the target storage medium based on the first environmental variable and the second environmental variable includes:
[0036] When the first and second environment variables are empty, identify each storage medium;
[0037] The first identified storage medium containing the boot image is determined to be the target storage medium.
[0038] Specifically, when lastbootdev and currentbootdev are empty, that is, when the user does not specify which storage medium to load the boot image from, and when an available boot image is identified in one of the storage media, that storage medium is determined as the target storage medium.
[0039] In one embodiment, identifying each storage medium includes:
[0040] Identify each storage medium in the order listed in the storage medium list.
[0041] The storage medium list can be ordered as follows: SD card, eMMC, USB, other storage media, or eMMC, USB, SD card, other storage media, etc. The order of the storage medium list is preset.
[0042] In one embodiment, after identifying the target storage medium, the method further includes:
[0043] Adjust the order of the storage media list, placing the target storage media containing the boot image at the beginning of the storage media list.
[0044] In one embodiment, determining the target storage medium based on the first environmental variable and the second environmental variable includes:
[0045] When the second environment variable is not empty and the first environment variable and the second environment variable are different, the storage medium corresponding to the storage medium identifier in the second environment variable is determined as the target storage medium.
[0046] Specifically, when currentbootdev is not empty, it means the user loads the boot image from the specified storage medium. When the values of lastbootdev and currentbootdev are different, it means the previously identified storage medium is different from the currently set storage medium. In this case, the storage medium corresponding to currentbootdev is determined to be the target storage medium.
[0047] In one embodiment, determining the target storage medium based on the first environmental variable and the second environmental variable includes:
[0048] When the second environment variable is empty and the first environment variable and the second environment variable are different, the storage medium corresponding to the storage medium identifier in the first environment variable is determined as the target storage medium.
[0049] Specifically, when currentbootdev is empty, that is, when the user does not specify which storage medium to load the boot image from, the previously identified storage medium is used as the target storage medium, that is, the storage medium corresponding to lastbootdev is determined as the target storage medium. At this time, the values of lastbootdev and currentbootdev are different.
[0050] In one embodiment, determining the target storage medium based on the first environmental variable and the second environmental variable includes:
[0051] When the first environment variable and the second environment variable are not empty and the first environment variable and the second environment variable are the same, the storage medium corresponding to the storage medium identifier in the first environment variable or the second environment variable is determined as the target storage medium.
[0052] Specifically, when both lastbootdev and currentbootdev are not empty, that is, the user has specified which storage medium to load the boot image from and the previously identified storage medium also exists; when the values of lastbootdev and currentbootdev are the same, that is, the previously identified storage medium is the same as the currently set storage medium, then the storage medium corresponding to both lastbootdev and currentbootdev can be determined as the target storage medium.
[0053] The hardware device in this application checks the values of these two variables each time it boots up. If they are equal, no modification is needed; otherwise, the value of currentbootdev needs to be replaced with the value of the first element of the original list of storage media to be recognized. After the replacement, lastbootdev is set to the same value as currentbootdev.
[0054] When a user wants to switch between different storage media to boot different systems under this dynamic identification and optimization mechanism, they only need to set currentbootdev to the corresponding storage media number in BootLoader. As long as the value of currentbootdev is not modified, the operating system will be loaded into memory from the previously set storage media each time the system is booted.
[0055] This application integrates a dynamic storage media identification optimization mechanism into the BootLoader. Only a short piece of code needs to be written and embedded in the BootLoader. The code removes redundant access by judging the values of two environment variables and adjusting the identification order, thus quickly selecting a suitable and real storage medium to load the real-time system faster. This provides real-time performance during system startup, eliminating the need to spend time traversing other storage media every time the system boots up. This speeds up system startup, improves the maintainability and robustness of the real-time system startup code, and enhances the user's fast and real-time boot experience.
[0056] This application provides two specific implementation examples.
[0057] Example 1
[0058] When a user has three storage media capable of loading bootable images, such as an SD card, eMMC, and USB, where the SD card does not load a bootable image and the other two do, the boot mechanism is activated when no specific storage medium is specified to load the bootable image into memory during hardware boot (i.e., lastbootdev and currentbootdev are empty). The mechanism identifies the bootable media by traversing the storage medium list in order. For example, if the current list is SD card, eMMC, and USB, and the SD card does not contain a bootable image file, the BootLoader will not find a suitable image file when accessing the SD card. Instead, it will access the eMMC. Once a bootable image file is found in the eMMC, the eMMC will be placed at the beginning of the list of storage media to be identified, and the eMMC card number will be assigned to lastbootdev, after which the operating system will boot. If the user does not specify which storage medium to load the bootable image from on the next boot, the system will directly select the first storage medium in the storage medium list as the boot image storage medium based on lastbootdev, thus booting the system without iterating through the list and improving the real-time performance of system startup. An operational diagram of Example 1 is shown below. Figure 3 .
[0059] Example 2
[0060] When a user has three storage media capable of loading bootable images (e.g., USB, SD card, eMMC), all three will load the bootable image. When specifying which storage medium to load the bootable image from into memory during hardware boot (i.e., when `currentbootdev` is set in the BootLoader and its value is not equal to `lastbootdev`), the BootLoader selects the unique storage medium based on the value of `currentbootdev` to load the image file into memory, and simultaneously sets the value of `lastbootdev` to be the same as `currentbootdev`. For example, if the user specifies that the bootable image is loaded from the SD card, and `currentbootdev` is set to the SD card's ID in the BootLoader (placing the SD card at the top of the list of storage media to be recognized), the BootLoader will directly load the image file from the SD card and assign the SD card's ID to `lastbootdev`. The next time the user boots, if `currentbootdev` is not modified, the bootable image will be directly read from the SD card, thus improving real-time performance.
[0061] Example 2 Operation Diagram as follows Figure 4 As shown.
[0062] like Figure 5As shown, this application embodiment provides a device startup apparatus, which can be used to implement the device startup method in the above embodiments, such as... Figure 5 As shown, the starting device 400 of the device has a variable acquisition module 410, a target storage medium determination module 420 and a loading module 430.
[0063] The variable acquisition module is used to acquire a first environment variable and a second environment variable. The first environment variable is used to store the storage medium identifier of the last image startup, and the second environment variable is used to store the storage medium identifier of the image to be started now.
[0064] The target storage medium determination module is used to determine the target storage medium based on the first environment variable and the second environment variable;
[0065] A loading module is used to load a boot image from the target storage medium to start the operating system in the target storage medium.
[0066] Figure 6 This is a schematic structural diagram of a computing device 900 provided in an embodiment of this application. This computing device can serve as a device startup device, executing various optional embodiments of the device startup method described above. The computing device can be a terminal, or a chip or chip system within the terminal. Figure 6 As shown, the computing device 900 includes: a processor 910, a memory 920, and a communication interface 930.
[0067] It should be understood that Figure 6 The communication interface 930 in the computing device 900 shown can be used to communicate with other devices, and may specifically include one or more transceiver circuits or interface circuits.
[0068] The processor 910 can be connected to the memory 920. The memory 920 can be used to store the program code and data. Therefore, the memory 920 can be a storage unit inside the processor 910, an external storage unit independent of the processor 910, or a component that includes both the storage unit inside the processor 910 and the external storage unit independent of the processor 910.
[0069] Optionally, the computing device 900 may also include a bus. The memory 920 and communication interface 930 can be connected to the processor 910 via the bus. The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The symbol is represented by a line without an arrow, but this does not mean that there is only one bus or one type of bus.
[0070] It should be understood that in the embodiments of this application, the processor 910 may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. Alternatively, the processor 910 may employ one or more integrated circuits to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0071] The memory 920 may include read-only memory and random access memory, and provides instructions and data to the processor 910. A portion of the processor 910 may also include non-volatile random access memory. For example, the processor 910 may also store device type information.
[0072] When the computing device 900 is running, the processor 910 executes computer execution instructions stored in the memory 920 to perform any of the operational steps of the above method and any of the optional embodiments thereof.
[0073] It should be understood that the computing device 900 according to the embodiments of this application can correspond to the corresponding subject in executing the methods according to the various embodiments of this application, and the above and other operations and / or functions of each module in the computing device 900 are respectively for implementing the corresponding processes of the methods of this embodiment. For the sake of brevity, they will not be described in detail here.
[0074] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0075] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0076] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0077] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0078] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0079] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0080] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is used to perform the above-described method, which includes at least one of the schemes described in the above embodiments.
[0081] The computer storage medium in this application embodiment can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. For example, a computer-readable storage medium can be, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0082] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0083] The program code contained on a computer-readable medium may be transmitted using any suitable medium, including, but not limited to, wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0084] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0085] Furthermore, the terms "first, second, third, etc." or similar terms such as module A, module B, and module C used in the specification and claims are only used to distinguish similar objects and do not represent a specific ordering of objects. It is understood that, where permissible, a specific order or sequence may be interchanged so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0086] In the above description, the labels of the steps involved, such as S110, S120, etc., do not mean that the steps will necessarily be executed. The order of the steps can be interchanged or executed simultaneously if permitted.
[0087] The term "comprising" as used in the specification and claims should not be construed as limiting itself to what follows; it does not exclude other elements or steps. Therefore, it should be interpreted as specifying the presence of the mentioned feature, integral, step, or component, but does not exclude the presence or addition of one or more other features, integrals, steps, or components, or groups thereof. Thus, the statement "device comprising means A and B" should not be limited to a device consisting solely of components A and B.
[0088] The terms "an embodiment" or "an embodiment" as used in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in at least one embodiment of this application. Therefore, the terms "in one embodiment" or "in an embodiment" appearing throughout this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. Furthermore, in one or more embodiments, the particular features, structures, or characteristics can be combined in any suitable manner, as will be apparent to those skilled in the art from this disclosure.
[0089] Note that the above are merely preferred embodiments and the technical principles employed in this application. Those skilled in the art will understand that this application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application, all of which fall within the scope of protection of this application.
Claims
1. A method for starting a device, characterized in that, The method is executed in the BootLoader of the device, including: Obtain a first environment variable and a second environment variable, wherein the first environment variable is used to store the storage medium identifier of the last booted image, and the second environment variable is used to store the storage medium identifier of the image to be booted now; Determining the target storage medium based on the first environment variable and the second environment variable includes: when the second environment variable is not empty, determining the storage medium corresponding to the storage medium identifier in the second environment variable as the target storage medium; when the second environment variable is not empty and the first environment variable and the second environment variable are different, replacing the value of the second environment variable with the value of the first digit of the original list of storage media to be identified, and after the replacement, replacing the value of the first environment variable with the value of the second environment variable; when the second environment variable is empty and the first environment variable and the second environment variable are different, determining the storage medium corresponding to the storage medium identifier in the first environment variable as the target storage medium. Load the boot image from the target storage medium to start the operating system on the target storage medium.
2. The method according to claim 1, characterized in that, The step of determining the target storage medium based on the first environmental variable and the second environmental variable further includes: When the first and second environment variables are empty, identify each storage medium; The first identified storage medium containing the boot image is determined to be the target storage medium.
3. The method according to claim 2, characterized in that, The identification of each storage medium includes: Identify each storage medium in the order listed in the storage medium list.
4. The method according to claim 3, characterized in that, Also includes: Adjust the order of the storage media list, placing the target storage media containing the boot image at the beginning of the storage media list.
5. A starting device for an apparatus, characterized in that, The device is disposed in the BootLoader of the device, and the device includes: The variable acquisition module is used to acquire a first environment variable and a second environment variable, wherein the first environment variable is used to store the storage medium identifier of the last booted image, and the second environment variable is used to store the storage medium identifier of the image to be booted now. The target storage medium determination module is used to determine the target storage medium based on the first environment variable and the second environment variable; wherein, when the second environment variable is not empty, the storage medium corresponding to the storage medium identifier in the second environment variable is determined as the target storage medium; when the second environment variable is not empty and the first environment variable and the second environment variable are different, the value of the second environment variable is replaced with the value of the first digit of the original list of storage media to be identified, and after the replacement, the value of the first environment variable is replaced with the value of the second environment variable; when the second environment variable is empty and the first environment variable and the second environment variable are different, the storage medium corresponding to the storage medium identifier in the first environment variable is determined as the target storage medium. A loading module is used to load a boot image from the target storage medium to start the operating system in the target storage medium.
6. A computing device, characterized in that, include: processor, and A memory having stored program instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 4.