A method, apparatus, device and medium for guiding parameter modification
Patent Information
- Application Number
- CN202310700124.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-13
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2043-06-13
AI Technical Summary
[0003]在引导参数修改的相关技术中,一般通过调用用户交互接口(shell)执行命令来修改引导参数的值,每次修改启动参数时需要重新对启动程序进行编译,当有多个不同版本的产品需要不同的启动参数而需要对启动参数进行多次修改时,需要对启动程序进行多次编译,增加了维护成本,降低了系统的调试效率
[0015]本发明至少具有以下有益效果:本发明提出的一种引导参数修改的方法提供用于参数修改的配置文件以及将配置文件和存放环境变量的文件同时加载到一个应用程序中,通过配置文件引入需要进行修改的引导参数的名称及其修改值,将存放环境变量的文件的字符数组与该名称进行对比处理后将该修改值写入到需要进行修改的字符数组的位置,将引导参数的修改过程从引导程序的编译过程中独立出来,作为引导程序可以正常编译的前置条件,因此每次修改启动参数的参数值时不需要重新编译引导程序,提高了系统修改引导参数的效率,减少了系统的维护成本。
Smart Images

Figure CN116719577B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software development, and in particular to a method, apparatus, device, and medium for modifying boot parameters. Background Technology
[0002] The Linux operating system is a clone system developed based on the UNIX operating system. For current embedded systems, the Linux kernel is typically booted by loading the Linux operating system's bootloader (u-boot program). The environment variables in the Linux bootloader are global and initialized character data. Normally, they cannot be modified while the bootloader is in memory; they can only be modified after it is loaded into memory.
[0003] In technologies related to modifying boot parameters, the values of boot parameters are generally modified by calling the user interaction interface (shell) to execute commands. Each time the boot parameters are modified, the boot program needs to be recompiled. When multiple different versions of the product require different boot parameters and the boot parameters need to be modified multiple times, the boot program needs to be recompiled multiple times, which increases maintenance costs and reduces the system's debugging efficiency. Summary of the Invention
[0004] In view of this, the present invention proposes a method, apparatus, device and medium for modifying boot parameters, which at least solves the problem that in the above-mentioned related technologies for modifying boot parameters, the value of boot parameters is generally modified by calling the user interaction interface (shell) to execute commands. Each time the boot parameters are modified, the boot program needs to be recompiled. When multiple different versions of products require different boot parameters and the boot parameters need to be modified multiple times, the boot program needs to be recompiled multiple times, which increases maintenance costs and reduces the debugging efficiency of the system.
[0005] Based on the above objectives, one aspect of the present invention provides a method for modifying boot parameters, comprising: simultaneously loading a configuration file and a file storing environment variables into an application; loading the name of the boot parameter to be modified and its modified value into the configuration file through the application; searching for the current value of the boot parameter to be modified in the file storing environment variables according to the name of the boot parameter to be modified; comparing the length of the modified value and the current value, and shifting the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value in the space of the shifted character data.
[0006] In some embodiments, the step of shifting the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value in the space of the shifted character data, includes: in response to the length of the current value being less than the length of the modified value, shifting the character array storing the current value sequentially backward in the file storing environment variables by the difference in their lengths, so as to store the modified value in the space of the shifted character data; in response to the length of the current value being equal to the length of the modified value, writing the modified value into the character array storing the current value; and in response to the length of the current value being greater than the length of the modified value, shifting the character array storing the current value sequentially forward in the file storing environment variables by the difference in their lengths, so as to store the modified value in the space of the shifted character data.
[0007] In some embodiments, the step of simultaneously loading the configuration file and the file storing environment variables into the application includes: in response to the simultaneous presence of multiple boot parameters that need to be modified, simultaneously loading the configuration file and the file storing environment variables corresponding to the multiple boot parameters that need to be modified into the application.
[0008] In some embodiments, the step of simultaneously loading the configuration file and the file storing environment variables into the application further includes: simultaneously loading the configuration file and the encrypted file storing environment variables into the application.
[0009] In some embodiments, the step of searching for the current value of the boot parameter to be modified in the file storing environment variables according to the name of the boot parameter to be modified includes: obtaining a public key from memory; decrypting the encrypted file storing environment variables according to the public key to obtain the file storing environment variables; comparing the character array of the file storing environment variables with the name of the boot parameter to be modified to obtain the boot parameter and its current value that are consistent with the name of the boot parameter to be modified.
[0010] In some embodiments, the method further includes: calling the file storing environment variables to verify the parameter values through the application; verifying the modified value according to the verification rules; and updating and outputting the file storing the environment variables containing the modified value through the application in response to the modified value conforming to the verification rules.
[0011] In some embodiments, the method further includes: burning the updated file storing environment variables into a memory to start the operating system kernel using the updated file storing environment variables.
[0012] In another aspect of this invention, a device for modifying boot parameters is provided, comprising: a first module for simultaneously loading a configuration file and a file storing environment variables into an application; a second module for loading the name of the boot parameter to be modified and its modified value into the configuration file through the application; a third module for searching the current value of the boot parameter to be modified in the file storing environment variables according to the name of the boot parameter to be modified; and a fourth module for comparing the length of the modified value and the current value, and shifting the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value in the space of the shifted character data.
[0013] In another aspect of the present invention, an electronic device is provided, including at least one processor; and a memory storing computer instructions executable on the processor, which, when executed by the processor, implement the steps of the above-described method.
[0014] In another aspect of the present invention, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the method steps described above.
[0015] The present invention has at least the following beneficial effects: The method for modifying boot parameters proposed in this invention provides a configuration file for parameter modification and loads the configuration file and the file storing environment variables into an application. The configuration file introduces the name of the boot parameter to be modified and its modified value. The character array of the file storing environment variables is compared with the name, and the modified value is written to the position of the character array to be modified. The modification process of boot parameters is separated from the compilation process of the boot program, and serves as a prerequisite for the normal compilation of the boot program. Therefore, it is not necessary to recompile the boot program every time the value of the boot parameter is modified, which improves the efficiency of modifying boot parameters and reduces the maintenance cost of the system.
[0016] Furthermore, the length between the current value and the modified value to be written is determined. Based on the length, it is determined whether the character position of the modified value needs to be adjusted accordingly when writing the modified value to the current value. This ensures that the modified value is successfully written to the character position, avoiding data overwriting or gaps in other character positions, thus guaranteeing the smooth progress of the program compilation process and avoiding waste of storage resources.
[0017] Furthermore, by loading multiple different configuration files into the application, the parameter values of multiple different boot parameters can be modified simultaneously according to user needs, which improves the efficiency of modifying boot parameters in the system. Moreover, the method is simple, easy to use, and extensible.
[0018] Furthermore, by encrypting the file storing environment variables before loading it into the application, the security of the file storing environment variables during the boot parameter modification process can be improved.
[0019] Furthermore, after the modified value is written to the character array position of the file storing environment variables, the modified value is validated to determine whether it meets the requirements of the environment variable for character arrays. Only if it meets the requirements of the character array can it be exported as a new file for storing environment variables. This can improve the accuracy of the modified value for the startup program and avoid errors during the subsequent compilation of the bootloader. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings without creative effort.
[0021] Figure 1 The flowchart shown is a method for modifying guide parameters provided by an embodiment of the present invention;
[0022] Figure 2 The diagram shown is another flowchart of a method for modifying guide parameters provided in an embodiment of the present invention;
[0023] Figure 3 A schematic diagram of a device for modifying guide parameters provided in an embodiment of the present invention is shown;
[0024] Figure 4 A schematic diagram of an electronic device provided in an embodiment of the present invention is shown;
[0025] Figure 5 A schematic diagram of a computer-readable storage medium provided in an embodiment of the present invention is shown. Detailed Implementation
[0026] The following describes embodiments of the present invention. However, it should be understood that the disclosed embodiments are merely examples, and other embodiments may take various alternative forms.
[0027] Furthermore, it should be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or apparatus that comprises a list of elements may include not only those elements but also elements not expressly listed or inherent to such process, method, article, or apparatus.
[0028] One or more embodiments of this application will now be described with reference to the accompanying drawings.
[0029] Based on the above objectives, the first aspect of the present invention provides an embodiment of a method for modifying guidance parameters. Figure 1 The flowchart shown is a method for modifying guide parameters provided in an embodiment of this application. Figure 1 As shown, a method for modifying guide parameters includes:
[0030] S1. Load the configuration file and the file storing environment variables into the application at the same time;
[0031] S2. The application loads the names of the boot parameters that need to be modified and their modified values into the configuration file;
[0032] S3. Based on the name of the boot parameter that needs to be modified, search for the current value of the boot parameter that needs to be modified in the file where environment variables are stored;
[0033] S4. Compare the lengths of the modified value and the current value. Based on the comparison result, shift the character array storing the current value in the file storing environment variables so that the modified value can be stored in the space of the shifted character data.
[0034] According to several embodiments of the present invention, the step of shifting the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value through the space of the shifted character data, includes: in response to the length of the current value being less than the length of the modified value, shifting the character array storing the current value sequentially backward in the file storing environment variables by the difference between their lengths, so as to store the modified value through the space of the shifted character data; in response to the length of the current value being equal to the length of the modified value, writing the modified value into the character array storing the current value; and in response to the length of the current value being greater than the length of the modified value, shifting the character array storing the current value sequentially forward in the file storing environment variables by the difference between their lengths, so as to store the modified value through the space of the shifted character data.
[0035] According to several embodiments of the present invention, the step of simultaneously loading configuration files and files storing environment variables into an application includes: in response to the simultaneous presence of multiple boot parameters that need to be modified, simultaneously loading the configuration files and files storing environment variables corresponding to the multiple boot parameters that need to be modified into the application.
[0036] According to several embodiments of the present invention, the step of simultaneously loading the configuration file and the file storing environment variables into the application further includes: simultaneously loading the configuration file and the encrypted file storing environment variables into the application.
[0037] According to several embodiments of the present invention, the step of searching for the current value of the boot parameter to be modified in a file storing environment variables by the name of the boot parameter to be modified includes: obtaining a public key from memory; decrypting the encrypted file storing environment variables according to the public key to obtain the file storing environment variables; comparing the character array of the file storing environment variables with the name of the boot parameter to be modified to obtain the boot parameter and its current value that are consistent with the name of the boot parameter to be modified.
[0038] According to several embodiments of the present invention, the method further includes: calling the file storing environment variables through an application to verify the parameter values according to the verification rules; verifying the modified values according to the verification rules; and updating and outputting the file storing environment variables containing the modified values through the application in response to the modified values conforming to the verification rules.
[0039] According to several embodiments of the present invention, the method further includes: burning the updated file storing environment variables into a memory to boot the kernel of the operating system.
[0040] The following is another embodiment of a method for modifying guide parameters provided by the present invention.
[0041] The Linux operating system kernel needs to be started by calling a bootloader, and the boot parameters are generally different for different products. Figure 2 The following is another flowchart illustrating a method for modifying guide parameters provided in an embodiment of the present invention, as shown below. Figure 2 As shown, when the startup parameters of the environment variables of the startup program are modified, kernel information such as the location of the Linux operating system kernel is read to obtain the corresponding file storing the environment variables. The parameters in this file are stored as character arrays, including boot parameters used to start the program. The file storing the environment variables is loaded into a pre-configured executable application, and a configuration file for parameter modification is also loaded into this application. This configuration file is also stored as a character array, with at least parameter names and values stored in separate character arrays. In the specific program implementation, the configuration file and the file storing the environment variables can be encapsulated together and then loaded into the application simultaneously.
[0042] The initial configuration environment is established by reading the names of the boot parameters to be modified and their corresponding modified values into a character array in the configuration file through the application. The names of the boot parameters to be modified and their corresponding modified values are stored in the form of a character array. Preferably, the character type of the configuration file matches the character type of the file storing environment variables. The character array of the file storing environment variables is compared with the names of the boot parameters to be modified. The character position in the character array of the file storing environment variables that matches the name of the boot parameter to be modified is found, and the current value is read from that character position. The modified value of the boot parameter to be modified is then written to this character position to complete the modification of the boot parameters and replace the startup parameters in the original environment variables. Specifically, before writing the modified value of the boot parameter to be modified to this character position, it is necessary to determine whether the modified value can be directly written to this character position, and to determine the length of the current value and the modified value. Based on the determination result, it is determined whether the character array of the file storing environment variables should be shifted forward from this character position to write the modified value to the character position. When the length of the current value is less than the length of the modified value, the character array of the file storing environment variables is shifted sequentially from the character position forward by a space equal to the difference between the lengths of the current and modified values, so that the modified value is written to the character position. When the length of the current value is equal to the length of the modified value, the modified value is written to the character position. When the length of the current value is greater than the length of the modified value, after writing the modified value to the character position, the space equal to the difference between the lengths of the current and modified values is shifted sequentially from the next character position forward to avoid wasting the address space of the character array of the file storing environment variables. After completing the above judgment, the modified value to be written can be written to the corresponding character position of the character array of the file storing environment variables according to the corresponding writing method, resulting in a new array of environment variables. This new character array needs to be verified to ensure that the character array of the written modified value meets the requirements of the environment variables. Only after the character array of the written modified value meets the requirements of the environment variables can the application export the character array of this modified value as a new file for storing environment variables. Then, the new file for storing environment variables is burned into the memory to start the Linux system kernel through the new file for storing environment variables.
[0043] Furthermore, to improve the security of the file storing environment variables when modifying parameter values, the file storing environment variables can be encrypted before being loaded into the application. Then, before using the file storing environment variables, the public key needs to be retrieved from memory to decrypt it before any operation can be performed.
[0044] Furthermore, when multiple parameter values need to be modified, multiple configuration files for modifying parameter values can be set directly. By loading these different configuration files into the application and performing subsequent operations with the files storing environment variables, the modification of multiple parameter values can be completed, improving the system's efficiency in modifying parameter values and reducing resource waste.
[0045] A second aspect of the present invention provides an apparatus for modifying guiding parameters. Figure 3 A schematic diagram of a device for modifying guide parameters provided in an embodiment of the present invention is shown, such as... Figure 3 As shown, it includes: a first module 011, used to load the configuration file and the file storing environment variables into the application simultaneously; a second module 012, used to load the name of the boot parameter to be modified and its modified value into the configuration file through the application; a third module 013, used to find the current value of the boot parameter to be modified in the file storing environment variables according to the name of the boot parameter to be modified; and a fourth module 014, used to compare the length of the modified value and the current value, and shift the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value in the space of the shifted character data.
[0046] A third aspect of the present invention provides an electronic device, Figure 4 The diagram shown is a schematic representation of an electronic device provided in an embodiment of the present invention. For example... Figure 4 As shown, an electronic device provided by an embodiment of the present invention includes the following modules: at least one processor 021; and a memory 022, the memory 022 storing computer instructions 023 that can be executed on the processor 021, the computer instructions 023 implementing the steps of the method described above when executed by the processor 021.
[0047] The present invention also provides a computer-readable storage medium. Figure 5 The diagram shown is a schematic representation of a computer-readable storage medium provided in an embodiment of the present invention. Figure 5 As shown, computer-readable storage medium 031 stores a computer program 032 that, when executed by a processor, performs the steps of the method described above.
[0048] Finally, it should be noted that those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program for setting system parameters can be stored in a computer-readable storage medium. When executed, the program can include the processes of the embodiments of the above methods. The storage medium for the program can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc. The above computer program embodiments can achieve the same or similar effects as any of the corresponding foregoing method embodiments.
[0049] Furthermore, the method disclosed in the embodiments of the present invention can also be implemented as a computer program executed by a processor, which may be stored in a computer-readable storage medium. When the computer program is executed by the processor, it performs the functions defined in the method disclosed in the embodiments of the present invention.
[0050] Furthermore, the above-described method steps and system units can also be implemented using a controller and a computer-readable storage medium for storing a computer program that enables the controller to perform the functions of the above-described steps or units.
[0051] Those skilled in the art will also understand that the various exemplary logic blocks, modules, circuits, and algorithm steps described in conjunction with the disclosure herein can be implemented as electronic hardware, computer software, or a combination of both. To clearly illustrate this interchangeability between hardware and software, the functionality of various illustrative components, blocks, modules, circuits, and steps has been generally described. Whether this functionality is implemented as software or as hardware depends on the specific application and the design constraints imposed on the system as a whole. Those skilled in the art can implement the functionality in various ways for each specific application, but such implementation decisions should not be construed as departing from the scope of the embodiments disclosed herein.
[0052] In one or more exemplary designs, functionality may be implemented in hardware, software, firmware, or any combination thereof. If implemented in software, the functionality may be stored as one or more instructions or code on or transmitted via a computer-readable medium. Computer-readable media include computer storage media and communication media, including any medium that facilitates the transfer of a computer program from one location to another. Storage media may be any available medium accessible to a general-purpose or special-purpose computer. By way of example, and not limitation, computer-readable media may include RAM, ROM, EEPROM, CD-ROM or other optical disc storage devices, disk storage devices or other magnetic storage devices, or any other medium that may be used to carry or store the required program code in the form of instructions or data structures and is accessible to a general-purpose or special-purpose computer or a general-purpose or special-purpose processor. Furthermore, any connection may be appropriately referred to as computer-readable media. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwave, then the aforementioned coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are all included in the definition of media. As used herein, disks and optical discs include compact discs (CDs), laser discs, optical discs, digital versatile discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs reproduce data optically using lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0053] The above are exemplary embodiments disclosed in this invention. However, it should be noted that various changes and modifications can be made without departing from the scope of the embodiments of this invention as defined by the claims. The functions, steps, and / or actions of the methods according to the disclosed embodiments described herein do not need to be performed in any particular order. Furthermore, although the elements disclosed in the embodiments of this invention may be described or claimed individually, they may be understood as multiple unless explicitly limited to a singular number.
[0054] It should be understood that, as used herein, the singular form “a” is intended to include the plural form as well, unless the context clearly supports an exception. It should also be understood that, as used herein, “and / or” refers to any and all possible combinations of one or more of the associated listed items.
[0055] The embodiment numbers disclosed in the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0056] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0057] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples. Within the framework of the invention, technical features of the above embodiments or different embodiments can be combined, and many other variations of different aspects of the invention exist, which are not provided in the details for the sake of brevity. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the invention should be included within the protection scope of the invention.
Claims
1. A method for modifying guiding parameters, characterized in that, include: Load both the configuration file and the file storing environment variables into the application; The application loads the names of the boot parameters that need to be modified and their modified values into the configuration file. Based on the name of the boot parameter that needs to be modified, search for the current value of the boot parameter that needs to be modified in the file where environment variables are stored; The lengths of the modified value and the current value are compared. Based on the comparison result, the character array storing the current value is shifted in the file storing environment variables so that the modified value can be stored in the space of the shifted character data.
2. The method according to claim 1, characterized in that, The step of shifting the character array storing the current value in the file storing environment variables according to the comparison result, so as to store the modified value in the space of the shifted character data, includes: In response to the fact that the length of the current value is less than the length of the modified value, the character array storing the current value is shifted sequentially to the right by the length difference between the two in the file storing environment variables, so that the modified value can be stored in the space of the shifted character data; In response to the fact that the length of the current value is equal to the length of the modified value, the modified value is written to the character array storing the current value; In response to the fact that the length of the current value is greater than the length of the modified value, the character array storing the current value is shifted forward by the length difference between the two in the file storing environment variables, so that the modified value can be stored in the space of the shifted character data.
3. The method according to claim 1, characterized in that, The step of simultaneously loading the configuration file and the file storing environment variables into the application includes: In response to the simultaneous presence of multiple boot parameters that need to be modified, the configuration files and environment variable storage files corresponding to the multiple boot parameters that need to be modified are simultaneously loaded into the application.
4. The method according to claim 1, characterized in that, The step of simultaneously loading the configuration file and the file storing environment variables into the application also includes: The configuration file and the encrypted file containing environment variables are loaded into the application simultaneously.
5. The method according to claim 4, characterized in that, The step of searching for the current value of the boot parameter that needs to be modified in the file storing environment variables, based on the name of the boot parameter that needs to be modified, includes: Retrieve the public key from memory; The encrypted file storing environment variables is decrypted using the public key to obtain the file storing environment variables. The character array of the file storing environment variables is compared with the name of the boot parameter that needs to be modified to obtain the boot parameter whose name matches the name of the boot parameter that needs to be modified and its current value.
6. The method according to claim 1, characterized in that, The method further includes: The application calls the file storing environment variables to verify the parameter values according to the rules. The modified value is verified according to the verification rules. In response to the modified value conforming to the verification rules, the application updates and outputs the file containing the environment variables where the modified value was written.
7. The method according to claim 6, characterized in that, The method further includes: The updated file storing environment variables is burned into the memory so that the operating system kernel can be started using the updated file storing environment variables.
8. A device for modifying guide parameters, characterized in that, include: The first module is used to load both the configuration file and the file storing environment variables into the application. The second module is used to load the names of the boot parameters that need to be modified and their modified values into the configuration file through the application. The third module is used to find the current value of the boot parameter that needs to be modified in the file storing environment variables, based on the name of the boot parameter that needs to be modified. The fourth module is used to compare the length of the modified value and the current value, and according to the comparison result, shift the character array storing the current value in the file storing environment variables so that the modified value can be stored in the space of the shifted character data.
9. An electronic device, characterized in that, include: At least one processor; as well as A memory storing computer instructions executable on the processor, which, when executed by the processor, implement the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1-7.
Citation Information
Patent Citations
Method, system and device for realizing guide of operating system kernel
CN102541572A
Non-disruptive load-balancing of virtual machines between data centers
US8959173B1