Method and system for generating and dynamically updating tree file of Linux equipment
By obtaining and decrypting the device tree file, performing security verification, and using device tree hot plug technology to dynamically update the device tree file, the problem of traditional device tree files cannot be dynamically changed and insufficient security is solved, and the hardware configuration of Linux system is realized Flexible management and dynamic adjustment.
Patent Information
- Application Number
- CN202410967952.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-12-03
AI Technical Summary
Traditional device tree files cannot be dynamically changed in fixed locations, which limits the flexibility and scalability of the system and has problems with low security.
By obtaining the encrypted and compressed device tree files passed by the boot loader, decryption and decompression, performing security verification. If passed, it will be passed to the Linux kernel for initialization, and monitoring hardware changes information dynamically update the device tree file, using device tree hot Plug-out technology adds or removes hardware devices without restarting the system.
It realizes flexible management and dynamic adjustment of hardware configuration by Linux systems, improves system flexibility and security, and ensures that only authorized users or components can modify it.
Smart Images

Figure CN119065722A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of operating system startup, and in particular to a method and system for generating and dynamically updating a Linux device tree file. Background Art
[0002] ARM architecture is a processor architecture widely used in embedded systems. Its design aims at high performance and low power consumption, and it has been widely used and developed in the past few decades. The ARM architecture has the characteristics of modular design, customizability and good software support, making it one of the preferred architectures in the field of embedded systems. During the ARM startup process, the boot loader is usually used to load the operating system image, and the device tree blob (DTB) file can be specified to describe the hardware configuration. In the Linux operating system, the device tree is a data structure that describes the hardware configuration and is used to provide hardware information to the operating system. The device tree binary (DTB) file is a binary representation of this data structure, which is read by the boot loader and passed to the kernel so that the kernel can identify and initialize the hardware device. The device tree file involves a wide range of aspects, that is, a new text format for describing device hardware information is added, and a tool for compiling this text is added. At the same time, the boot loader also needs to support passing the compiled device tree file to the Linux kernel. However, the traditional device tree file is stored in a fixed location and cannot be changed dynamically, which limits the flexibility and scalability of the system. In addition, the device tree file in the prior art can be accessed and modified arbitrarily by tools, which has the problem of low security. Summary of the invention
[0003] Technical problem to be solved by the present invention: In view of the above-mentioned problems in the prior art, a method and system for generating and dynamically updating a Linux device tree file are provided. The present invention aims to realize the generation and dynamic updating of a Linux device tree file, and realize the flexible management and dynamic adjustment of hardware configuration by the Linux system.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is: A method for generating and dynamically updating a Linux device tree file comprises the following steps: S1, obtain the encrypted and compressed device tree file passed by the bootloader; S2, storing the encrypted and compressed device tree file in a specified path and then performing decryption and decompression; S3, perform security verification on the decrypted and decompressed device tree file. If the verification passes, jump to step S4; otherwise, end and exit; S4, passing the decrypted and decompressed device tree file to the Linux kernel, so that the Linux kernel is initialized according to the hardware configuration information in the decrypted and decompressed device tree file when initializing the hardware device; S5, monitors the change information of the hardware devices in the Linux kernel. If the change information of the hardware devices in the Linux kernel is monitored, the decrypted and decompressed device tree file is updated according to the hardware change information, and the decrypted and decompressed device tree file generates security verification information and then encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
[0005] Optionally, steps S1 to S5 are implemented by a device tree file optimization and dynamic update module added to the Linux kernel code.
[0006] Optionally, before step S1, the device tree file optimization and dynamic update module is also added to the Linux kernel and compiled to obtain a Linux kernel including the device tree file optimization and dynamic update module, and the Linux kernel including the device tree file optimization and dynamic update module replaces the original Linux kernel in the system.
[0007] Optionally, storing in a specified path in step S2 refers to storing as a / sys / firmware / fdt file.
[0008] Optionally, the security verification of the decrypted and decompressed device tree file in step S3 includes segmenting and extracting the original device tree file and the original security verification information from the decrypted and decompressed device tree file, calculating the calculated security verification information for the original device tree file, and if the calculated security verification information matches the original security verification information, the verification is determined to be successful, otherwise the verification is determined to be unsuccessful.
[0009] Optionally, step S5 includes: S5.1, monitor the change information of the hardware devices in the Linux kernel, if the change information of the hardware devices in the Linux kernel is monitored, jump to step S5.2; S5.2, output the prompt to switch to the root user to update the device tree file; S5.3, detect the login authorization operation of the root user, if the login authorization operation of the root user is detected, jump to step S5.4; if it times out, end and exit; S5.4, updates the decrypted and decompressed device tree file according to the hardware change information, and generates security verification information for the decrypted and decompressed device tree file, encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
[0010] Optionally, the change information of the hardware device in step S5.1 includes information of adding or removing the hardware device.
[0011] In addition, the present invention also provides a Linux device tree file generation and dynamic update system, comprising a microprocessor and a memory connected to each other, wherein the microprocessor is programmed or configured to execute the Linux device tree file generation and dynamic update method.
[0012] In addition, the present invention also provides a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute the method for generating and dynamically updating the Linux device tree file through a processor.
[0013] In addition, the present invention also provides a computer program product, including a computer program or instruction, wherein the computer program or instruction is programmed or configured to execute the method for generating and dynamically updating the Linux device tree file through a processor.
[0014] Compared with the prior art, the present invention mainly has the following advantages: the present invention comprises obtaining the encrypted and compressed device tree file transmitted by the boot loader, storing it in a designated path, performing decryption and decompression, and then performing security verification. If the verification passes, the file is transmitted to the Linux kernel, so that the Linux kernel initializes the hardware device according to the hardware configuration information in the decrypted and decompressed device tree file when initializing the hardware device; if the change information of the hardware device in the Linux kernel is monitored, the decrypted and decompressed device tree file and the encrypted and compressed device tree file are updated, and the device tree hot-swap technology is used to support the dynamic addition or removal of hardware devices without restarting the system, thereby realizing the generation and dynamic update of the Linux device tree file, and realizing the flexible management and dynamic adjustment of the hardware configuration of the Linux system. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 Schematic diagram of the basic flow of the method of the embodiment of the present invention. DETAILED DESCRIPTION
[0016] The following takes the installation of the Kylin V10 desktop system on an ARM architecture physical machine as an example to further explain in detail the generation and dynamic update method and system of the Linux device tree file of the present invention.
[0017] like Figure 1 As shown, the method for generating and dynamically updating a Linux device tree file in this embodiment includes the following steps: S1, obtain the encrypted and compressed device tree file passed by the bootloader; S2, storing the encrypted and compressed device tree file in a specified path and then performing decryption and decompression; S3, perform security verification on the decrypted and decompressed device tree file. If the verification passes, jump to step S4; otherwise, end and exit; S4, passing the decrypted and decompressed device tree file to the Linux kernel, so that the Linux kernel is initialized according to the hardware configuration information in the decrypted and decompressed device tree file when initializing the hardware device; S5, monitors the change information of the hardware devices in the Linux kernel. If the change information of the hardware devices in the Linux kernel is monitored, the decrypted and decompressed device tree file is updated according to the hardware change information, and the decrypted and decompressed device tree file generates security verification information and then encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
[0018] like Figure 1 As shown, steps S1 to S5 in this embodiment are implemented by the device tree file optimization and dynamic update module added in the Linux kernel code. Before step S1 of this embodiment, the device tree file optimization and dynamic update module added in the Linux kernel is also included and compiled, so as to obtain a Linux kernel including the device tree file optimization and dynamic update module, and replace the original Linux kernel in the system with the Linux kernel including the device tree file optimization and dynamic update module. For example, in this embodiment, the device tree file optimization and dynamic update module is added to the Linux kernel of the Kylin V10 desktop system and compiled, so as to obtain the Linux kernel of the Kylin V10 desktop system including the device tree file optimization and dynamic update module, and replace the original Linux kernel in the Kylin V10 desktop system with the Linux kernel including the device tree file optimization and dynamic update module.
[0019] In step S2 of this embodiment, storing in the specified path means storing as / sys / firmware / fdt file. The process of generating the encrypted and compressed device tree file includes: First, export the original device tree file using the following command: cat / sys / firmware / fdt>modify.dtb; Through the above method, the export file of the original device tree file can be obtained, and the command is modify.dtb.
[0020] Then, modify.dtb is encrypted and compressed. Encryption and compression can be completed at one time or independently. The encryption and compression algorithms can be selected according to actual needs. On this basis, the encrypted and compressed device tree file can be obtained. The decryption and decompression process is the reverse process of encryption and compression. Similarly, decryption and decompression can be completed at one time or independently.
[0021] In step S3 of this embodiment, the security verification of the decrypted and decompressed device tree file includes segmenting and extracting the original device tree file and the original security verification information from the decrypted and decompressed device tree file, calculating the calculated security verification information for the original device tree file, and if the calculated security verification information matches the original security verification information, it is determined that the verification is passed, otherwise it is determined that the verification is failed.
[0022] Step S5 of this embodiment includes: S5.1, monitor the change information of the hardware devices in the Linux kernel, if the change information of the hardware devices in the Linux kernel is monitored, jump to step S5.2; S5.2, output the prompt to switch to the root user to update the device tree file; S5.3, detect the login authorization operation of the root user, if the login authorization operation of the root user is detected, jump to step S5.4; if it times out, end and exit; S5.4, updates the decrypted and decompressed device tree file according to the hardware change information, and generates security verification information for the decrypted and decompressed device tree file, encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
[0023] The change information of the hardware device in step S5.1 of this embodiment includes the information of adding or removing the hardware device. In this embodiment, after the device tree file optimization and dynamic update module detects the insertion of a new device, a prompt "New hardware insertion detected, please switch to root user for update" will pop up in the terminal, and the authorized user or system component will be switched to update. The user switches to the user prompted by the terminal and operates according to the prompt until "Update successful" is displayed.
[0024] In summary, the generation and dynamic update method of the Linux device tree file in this embodiment mainly includes the following mechanisms: Device tree file optimization mechanism: By introducing a compression algorithm, the device tree file is compressed to reduce the file size, improve the loading efficiency and ensure the security of the device tree file. Moreover, the device tree file is based on an encrypted and compressed structure to reduce redundant information and improve data reading efficiency. Device tree file dynamic update mechanism: A dynamic update mechanism is designed to allow new device tree files to be dynamically generated according to changes in hardware configuration during the operation of the Linux system, and new device tree files are generated through device tree files and replace the original device tree files. The device tree hot-swap technology is introduced to support dynamic addition or removal of hardware devices without restarting the system, and automatically update the device tree file. Security guarantee mechanism: The generation and update process of the device tree file is securely verified to ensure that only authorized users or system components can make modifications. Encryption technology is introduced to encrypt and protect the device tree file to prevent unauthorized access and tampering. The method for generating and dynamically updating the Linux device tree file in this embodiment provides a Linux device tree (DTB) file optimization and dynamic update technology. By dynamically generating and updating the DTB file, the Linux system can realize flexible management and dynamic adjustment of the hardware configuration. The method in this embodiment compresses the DTB file to reduce the file size; designs an optimized device tree file (compression) to reduce redundant information; dynamically generates a new device tree file and replaces the original device tree file according to the changes in the hardware configuration during the operation of the Linux system; introduces the device tree hot-swap technology to support the dynamic addition or removal of hardware devices without restarting the system; the method in this embodiment performs security verification and encryption protection on the generation and update process of the device tree file, and the method in this embodiment can use the device tree hot-swap technology to support the dynamic addition or removal of hardware devices without restarting the system.
[0025] In addition, the present invention also provides a Linux device tree file generation and dynamic update system, comprising a microprocessor and a memory connected to each other, wherein the microprocessor is programmed or configured to execute the Linux device tree file generation and dynamic update method.
[0026] In addition, the present invention also provides a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute the method for generating and dynamically updating the Linux device tree file through a processor.
[0027] In addition, the present invention also provides a computer program product, including a computer program or instruction, wherein the computer program or instruction is programmed or configured to execute the method for generating and dynamically updating the Linux device tree file through a processor.
[0028] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0029] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A method for generating and dynamically updating a Linux device tree file, characterized in that: The steps include: S1, obtain the encrypted and compressed device tree file passed by the bootloader; S2, storing the encrypted and compressed device tree file in a specified path and then performing decryption and decompression; S3, perform security verification on the decrypted and decompressed device tree file. If the verification passes, jump to step S4; otherwise, end and exit; S4, passing the decrypted and decompressed device tree file to the Linux kernel, so that the Linux kernel is initialized according to the hardware configuration information in the decrypted and decompressed device tree file when initializing the hardware device; S5, monitors the change information of the hardware devices in the Linux kernel. If the change information of the hardware devices in the Linux kernel is monitored, the decrypted and decompressed device tree file is updated according to the hardware change information, and the decrypted and decompressed device tree file generates security verification information and then encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
2. The method for generating and dynamically updating a Linux device tree file according to claim 1, characterized in that: Steps S1 to S5 are implemented by optimizing the device tree file and dynamically updating the module added in the Linux kernel code.
3. The method for generating and dynamically updating a Linux device tree file according to claim 2, characterized in that: Before step S1, the device tree file optimization and dynamic update module is also added to the Linux kernel and compiled to obtain a Linux kernel including the device tree file optimization and dynamic update module, and the Linux kernel including the device tree file optimization and dynamic update module replaces the original Linux kernel in the system.
4. The method for generating and dynamically updating a Linux device tree file according to claim 1, characterized in that: Storing to the specified path in step S2 refers to storing as the / sys / firmware / fdt file.
5. The method for generating and dynamically updating a Linux device tree file according to claim 1, characterized in that: In step S3, the security verification of the decrypted and decompressed device tree file includes segmenting and extracting the original device tree file and the original security verification information from the decrypted and decompressed device tree file, calculating the calculated security verification information for the original device tree file, and if the calculated security verification information matches the original security verification information, it is determined that the verification is passed, otherwise it is determined that the verification fails.
6. The method for generating and dynamically updating a Linux device tree file according to claim 1, characterized in that: Step S5 includes: S5.1, monitor the change information of the hardware devices in the Linux kernel, if the change information of the hardware devices in the Linux kernel is monitored, jump to step S5.2; S5.2, output the prompt to switch to the root user to update the device tree file; S5.3, detect the login authorization operation of the root user, if the login authorization operation of the root user is detected, jump to step S5.4; if it times out, end and exit; S5.4, updates the decrypted and decompressed device tree file according to the hardware change information, and generates security verification information for the decrypted and decompressed device tree file, encrypts and compresses it to replace the encrypted and compressed device tree file stored in the specified path, and supports dynamic addition or removal of hardware devices without restarting the system through the device tree hot-swap technology.
7. The method for generating and dynamically updating a Linux device tree file according to claim 6, characterized in that: The change information of the hardware device in step S5.1 includes information of adding or removing the hardware device.
8. A system for generating and dynamically updating a Linux device tree file, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the method for generating and dynamically updating a Linux device tree file as described in any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program or instruction stored therein, characterized in that: The computer program or instruction is programmed or configured to execute the method for generating and dynamically updating a Linux device tree file as described in any one of claims 1 to 7 through a processor.
10. A computer program product comprising a computer program or instructions, characterized in that The computer program or instruction is programmed or configured to execute the method for generating and dynamically updating a Linux device tree file as described in any one of claims 1 to 7 through a processor.
