Container mirror image construction and use method oriented to embedded cross compiling
By packaging the cross-compilation environment as a container image as a whole, and starting the container through the image at compile time, the compile operation is solved in cross-compilation technology with large workloads of tool chain adaptation, complex version management, compatibility issues, and low operation efficiency in confidential environments, and cross-compilation solutions are achieved with strong environmental adaptability, flexible deployment and good platform security.
Patent Information
- Application Number
- CN202411800852.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-11
AI Technical Summary
Cross-compilation technology has problems such as large toolchain adaptation workload, complex version management, possible compatibility defects, and low operating efficiency in confidential environments.
The embedded cross-compilation implementation method based on the container mechanism is adopted to package the cross-compilation environment into a container image as a whole, and the container is started through the image during compilation to complete the compilation operation.
It realizes a cross-compilation solution with strong environmental adaptability, flexible deployment and good platform security, supports the compilation of multiple types of engineering source codes, and improves product delivery efficiency and maintainability of compilation software.
Smart Images

Figure CN119806530A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of operating system compilation, and in particular to a container image construction and use method for embedded cross-compilation. Background Art
[0002] Embedded cross-compilation is a technology that compiles programs on one computer architecture (host machine) on another computer architecture (target machine). Due to the special application environment and hardware resource limitations of embedded systems, executable files running on them often need to be generated using cross-compilation technology. The tools required for cross-compilation generally include compilers, linkers, header files, and library files. Through cross-compilation, developers can compile and debug codes on a powerful host machine, and then deploy the generated executable files to resource-constrained embedded devices to run, which improves development efficiency and shortens product time to market. It is a common method for embedded software development.
[0003] Due to the differences between the compilation environment and the running environment, as well as the uncertainty of the host environment, the construction of the cross-compilation environment is relatively complicated. Taking the JARI-Works embedded operating system developed by our unit as an example, when building the cross-compilation environment of this system, the tool chain is adapted for the commonly used foreign desktop operating systems such as Windows and Ubuntu, as well as domestic desktop operating systems such as deepin, Kylin, and Ubuntu Kylin. The overall workload is large, the time taken to put it on the market is long, and the version management is complicated, which is not conducive to the delivery and maintenance of the product.
[0004] In addition, in production practice, cross-compilation technology has also exposed other defects. For example, with the upgrading of embedded devices, the cross-compilation tool chain needs to be continuously upgraded to support new hardware and software features, and different versions of cross-compilation tool chains may have compatibility issues, resulting in deviations in the operation of the tool chain. In the process of equipment software development, due to confidentiality requirements, antivirus software and audit software are often installed on the host machine. The scanning rules of these security software may also have some negative impact on the operating efficiency of the tool chain. Summary of the invention
[0005] The purpose of the present invention is to solve the problems of large tool chain adaptation workload, complex version management, possible compatibility defects, low operating efficiency in confidential environments, etc. in cross-compilation technology, and propose an embedded cross-compilation implementation method based on a container mechanism. The method packages the cross-compilation environment as a whole and builds it into a container image. During cross-compilation, the container is started through the image to complete the compilation operation. It has the characteristics of strong environmental adaptability, flexible and convenient deployment, good platform security, etc., supports the compilation of various types of engineering source codes such as application programs, library files, and drivers, and can provide strong support for the cross-compilation of embedded programs.
[0006] The technical solution to achieve the purpose of the present invention is: a container image construction and use method for embedded cross-compilation, the method comprising:
[0007] Step 1: Build a cross-compilation tool chain for the target system, including compiler, linker, assembler and binary tools;
[0008] Step 2, obtain the target machine system files, including header files and library files;
[0009] Step 3, build scripts for project configuration management mode;
[0010] Step 4: Integrate the contents obtained from step 1 to step 3 to build a new image;
[0011] Step 5: When compiling an embedded application, build a container startup command based on the new image, mount the source code directory and the build directory, and select the corresponding script as the container entry point;
[0012] Step 6: After the compilation is complete, stop and delete the container to recycle system resources.
[0013] Furthermore, the cross-compilation tool chain in step 1 and the target machine system files in step 2 are integrated into the container image.
[0014] Furthermore, the cross-compilation tool chain constructed in step 1 and the target machine system files obtained in step 2 are stored in designated directories respectively.
[0015] Furthermore, the project configuration management modes in step 3 include: a project management mode based on a pro file, a project management mode based on a cmakelist file, and a project management mode based on a custom makefile.
[0016] Furthermore, in step 4, by pulling a container image with the same system version as the target machine in step 1, based on the container image, the contents obtained in steps 1 to 3 are integrated to form a new image.
[0017] Furthermore, after the new image is built in step 4, use docker save to export the image into a cross_compiler.tar.gz file.
[0018] Furthermore, in step 5, the source directory and the build directory are mounted into the container as data volumes, and the entire compilation process runs in the container.
[0019] Furthermore, the source code path and the build path are mounted as data volumes.
[0020] Compared with the prior art, the present invention has the following significant advantages:
[0021] (1) The present invention can free the construction of a cross-compilation environment from the constraints of the host operating system, and has the characteristics of strong environmental adaptability, flexible and convenient deployment, good platform security, etc. It supports the compilation of engineering source codes such as application programs, library files, and drivers, and can provide strong support for the cross-compilation of embedded programs.
[0022] (2) By integrating the tool chain, header files, and library files into the container image, there is no need to provide a separate compilation environment for each host platform, which can effectively improve product delivery efficiency.
[0023] (3) In production scenarios, only the compilation-related image files in the server warehouse need to be maintained, which can effectively improve the maintainability and stability of the compiled software.
[0024] (4) The entire compilation process runs in the container, which will not interfere with the software environment of the host machine. It has better security and runs more efficiently on machines equipped with confidentiality audit software.
[0025] (5) Support for multiple project configuration management is achieved through the build script integrated in the image.
[0026] (6) The cross-compilation environment will be delivered to users in the form of a container image rather than an ordinary software package.
[0027] (7) The method designed in the present invention is applicable to the field of embedded cross-compilation and can be promoted in scenarios related to embedded software, with broad application prospects.
[0028] The present invention is further described in detail below in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a schematic diagram of the method for building and using a container image for embedded cross-compilation according to the present invention.
[0030] Figure 2 The present invention is a flowchart of a method for building and using a container image for embedded cross-compilation in one embodiment.
[0031] Figure 3 This is a screenshot of a script code portion for compiling a Qt project in an embodiment. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0033] It should be noted that if there are descriptions involving "first", "second", etc. in the embodiments of the present invention, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0034] In one embodiment, in combination Figure 1 , provides a method for building and using a container image for embedded cross-compilation, the method comprising:
[0035] Step 1: Build the cross-compilation tool chain of the target system, including compiler, linker, assembler and binary tools;
[0036] Here, based on the basic Docker image such as Ubuntu or other mainstream Linux operating systems, install the tool chain used for cross-compilation such as compiler and linker.
[0037] Step 2, obtain the target machine system files, including header files (including kernel header files) and library files (glibc library files, qt library files, etc.);
[0038] The cross-compilation toolchain in step 1 and the target system files in step 2 are integrated into the container image.
[0039] Step 3: Build a script for the project configuration management mode, which includes: a project management mode based on a pro file, a project management mode based on a cmakelist file, and a project management mode based on a custom makefile
[0040] Step 4: Integrate the contents obtained from step 1 to step 3 to build a new image;
[0041] Step 5: When compiling an embedded application, build a container startup command based on the new image, mount the source code directory and the build directory, and select the corresponding script as the container entry point;
[0042] Step 6: After the compilation is complete, stop and delete the container to recycle system resources.
[0043] Furthermore, in one of the embodiments, the cross-compilation tool chain constructed in step 1 and the target machine system files obtained in step 2 are respectively stored in designated directories.
[0044] Preferably, in some embodiments, the compilation tool chain is stored in the " / TARGET_OS / CPU_ARCH / gcc / GCC_VERSION / " directory, and the installation path of the debugger is " / TARGET_OS / CPU_ARCH / gdb / GDB_VERSION / bin", where TARGET_OS refers to the embedded operating system on the target machine, such as jari_works, etc.; CPU_ARCH refers to the processor model of the target machine, such as phytium_d2000 (Feitian D2000), loongson_3a5000 (Loongson 3A5000), etc.; GCC_VERSION and GDB_VERSION respectively refer to the compiler and debugger versions, such as 9.5.0, 9.1.0, etc.
[0045] The header files (including kernel header files) and library files of the target system are stored in the " / TARGET_OS / CPU_ARCH / gcc / GCC_VERSION / sysroot" directory, and the Qt-related header files and library files are stored in the " / TARGET_OS / CPU_ARCH / qt / QT_VERSION / " directory, where TARGET_OS, CPU_ARC, and GCC_VERSION have the same meanings as above. QT_VERSION indicates the version of Qt on the target system, such as 4.8.3, 5.6.3, 5.12.11, etc.
[0046] Furthermore, in one of the embodiments, in step 4, by pulling a container image with the same system version as the target machine in step 1, based on the container image, the contents obtained in steps 1 to 3 are integrated to form a new image.
[0047] Furthermore, in one of the embodiments, after the new image is built in step 4, docker save is used to export the image into a cross_compiler.tar.gz file.
[0048] Furthermore, in one of the embodiments, in step 5, the source code directory and the build directory are mounted into the container in the form of data volumes, and the entire compilation process runs in the container.
[0049] Table 1 below shows the parameters required to be passed in when compiling various projects in the present invention.
[0050] qmake project cmake project Custom Makefile Project Source code path √ √ √ Build Path √ √ √ Debug / Release √ √ ○ Qt Version √ ○ ○ GCC Version √ ○ ○
[0051] As a specific example, the present invention is further described in detail in one of the embodiments.
[0052] Take the construction of the cross-compilation environment of the Feiteng 2000 platform JARI-Works system as an example. Figure 2 As shown, the present invention comprises the following steps:
[0053] Step 1, complete the construction of the JARI-Works cross-compilation tool chain for Phytium 2000 in Ubuntu, including the compiler (gcc), linker (ld), assembler (as), etc. The compiler version is 9.3.0, so the compiler, linker, assembler, etc. are placed in the / jari_works / phytium_2000 / gcc / 9.3.0 / bin directory, and the corresponding debugging tools are placed in the / jari_works / phytium_2000 / gdb / 9.1.0 / bin directory;
[0054] Step 2, copy header files (including kernel header files), glibc library files, qt library files, etc. from the target system. Put header files, glibc library files, etc. in the / jari_works / phytium_2000 / gcc / 9.3.0 / sysroot directory, and all files corresponding to Qt-5.6.3 in the / jari_works / phytium_2000 / qt / 5.6.3 directory;
[0055] Step 3: Write a build script qmake_compile.sh for the Qt project based on the pro file management configuration, such as Figure 3 As shown;
[0056] Step 4: Use the dockerbuild command to package the files generated in steps 1, 2, and 3 to build the cross_compiler:default image file. After the build is complete, use docker save to export the image into a cross_compiler.tar.gz file to facilitate subsequent migration and deployment.
[0057] Step 5. When compiling an embedded application, if there is no image file that supports cross-compilation in the current environment, load this image through the docker load cross_compiler.tar.gz command, and then select the corresponding script in step 3 as the container entry point according to the type of project management file, mount the source code path ( / home / user01 / qtest_01 / src) and the build path ( / home / user01 / qtest_01 / build) as data volumes, and start the container through the "dockerrun–rm–entrypoint / jari_works / phytium_2000 / qmake_compile.sh–v / home / user01 / qtest_01 / src–v / home / user01 / qtest_01 / build cross_compiler:default9.3.05.6.3debug" command to complete the compilation;
[0058] Step 6: After the compilation is complete, the daemon process stops and deletes the container and reclaims system resources.
[0059] In one embodiment, a container image construction and use system for embedded cross-compilation is provided, the system comprising:
[0060] The first module is used to build the cross-compilation tool chain of the target system, including compiler, linker, assembler and binary tools;
[0061] The second module is used to obtain the target machine system files, including header files and library files;
[0062] The third module is used to build scripts for the engineering configuration management mode;
[0063] The fourth module is used to integrate the above contents and build a new image;
[0064] The fifth module is used to build a container startup command based on the new image when compiling an embedded application, mount the source code directory and the build directory, and select the corresponding script as the container entry point;
[0065] The sixth module is used to stop and delete the container and recycle system resources after the compilation is completed.
[0066] For the specific limitations of the container image construction and use system for embedded cross-compilation, please refer to the limitations of the container image construction and use method for embedded cross-compilation above, which will not be repeated here. Each module in the above-mentioned container image construction and use system for embedded cross-compilation can be implemented in whole or in part through software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0067] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following is achieved:
[0068] Step 1: Build a cross-compilation tool chain for the target system, including compiler, linker, assembler and binary tools;
[0069] Step 2, obtain the target machine system files, including header files and library files;
[0070] Step 3, build scripts for project configuration management mode;
[0071] Step 4: Integrate the contents obtained from step 1 to step 3 to build a new image;
[0072] Step 5: When compiling an embedded application, build a container startup command based on the new image, mount the source code directory and the build directory, and select the corresponding script as the container entry point;
[0073] Step 6: After the compilation is complete, stop and delete the container to recycle system resources.
[0074] For the specific limitations of each step, please refer to the limitations on container image construction and use methods for embedded cross-compilation mentioned above, which will not be repeated here.
[0075] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements:
[0076] Step 1: Build a cross-compilation tool chain for the target system, including compiler, linker, assembler and binary tools;
[0077] Step 2, obtain the target machine system files, including header files and library files;
[0078] Step 3, build scripts for project configuration management mode;
[0079] Step 4: Integrate the contents obtained from step 1 to step 3 to build a new image;
[0080] Step 5: When compiling an embedded application, build a container startup command based on the new image, mount the source code directory and the build directory, and select the corresponding script as the container entry point;
[0081] Step 6: After the compilation is complete, stop and delete the container to recycle system resources.
[0082] For the specific limitations of each step, please refer to the limitations on container image construction and use methods for embedded cross-compilation mentioned above, which will not be repeated here.
[0083] The method proposed in the present invention is applicable to the field of embedded cross-compilation and can be promoted in scenarios related to embedded software, with broad application prospects.
[0084] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for building and using a container image for embedded cross-compilation, characterized in that: The method comprises: Step 1: Build a cross-compilation tool chain for the target system, including compiler, linker, assembler and binary tools; Step 2, obtain the target machine system files, including header files and library files; Step 3, build scripts for project configuration management mode; Step 4: Integrate the contents obtained from step 1 to step 3 to build a new image; Step 5: When compiling an embedded application, build a container startup command based on the new image, mount the source code directory and the build directory, and select the corresponding script as the container entry point; Step 6: After the compilation is complete, stop and delete the container to recycle system resources.
2. The method for building and using a container image for embedded cross-compilation according to claim 1, characterized in that: The cross-compilation toolchain in step 1 and the target system files in step 2 are integrated into the container image.
3. The method for building and using a container image for embedded cross-compilation according to claim 1, characterized in that: The cross-compilation tool chain built in step 1 and the target machine system files obtained in step 2 are stored in the specified directories respectively.
4. The method for building and using a container image for embedded cross-compilation according to claim 1, characterized in that: The project configuration management modes in step 3 include: a project management mode based on pro files, a project management mode based on cmakelist files, and a project management mode based on custom makefiles.
5. The method for building and using a container image for embedded cross-compilation according to claim 2, characterized in that: In step 4, by pulling the container image with the same system version as the target machine in step 1, based on this container image, the contents obtained from steps 1 to 3 are integrated to form a new image.
6. The method for building and using a container image for embedded cross-compilation according to claim 5, characterized in that: After the new image is built in step 4, use docker save to export the image into a cross_compiler.tar.gz file.
7. The method for building and using a container image for embedded cross-compilation according to claim 1, characterized in that: In step 5, the source directory and build directory are mounted into the container as data volumes, and the entire compilation process runs in the container.
8. The method for building and using a container image for embedded cross-compilation according to claim 7, characterized in that: Mount the source and build directories as data volumes.
Citation Information
Cited By
Driver management method and device, equipment, storage medium and program product
CN121029225A
Method for realizing AGV cross compiling based on docker
CN121187594A
A method for realizing AGV cross-compilation based on docker
CN121187594B