A device tree image version verification method and terminal device
By compiling the version information into the device tree image file during the compilation stage and comparing the version information before starting the operating system, the problem of terminal devices being unable to start the operating system due to inconsistent versions of the device tree image file is solved, and the normal startup of the terminal device and the stable operation of the operating system is achieved.
Patent Information
- Application Number
- CN202110238984.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-04
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2041-03-04
AI Technical Summary
Due to the inconsistent version of the device tree image file, the terminal device cannot execute normally before starting the operating system, resulting in the device being unable to start the operating system normally, similar to the problem of 'bricking'.
During the compilation phase, compile the version information into the main device tree image file and the overlay device tree image file, and compare the version information before starting the operating system. When the version information matches, merge the image files to start the operating system; when it does not match, use a backup overlay device tree image file that matches the main device tree image file version instead of the original file.
Ensure that the terminal device can start the operating system normally, avoiding system failures and 'bricking' problems caused by inconsistent versions of the mirror file.
Smart Images

Figure CN115033267B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of operating systems, and in particular to a method and a terminal device for verifying a device tree (DT) image version. Background Art
[0002] DT is a data structure used to describe various hardware on a terminal device. For example, it may include named nodes and attributes of various hardware. It is understandable that hardware can be understood as any physical device or equipment on a terminal device, such as a hard disk, a mouse, a speaker, a central processing unit (CPU), a graphics processing unit (GPU), a baseband chip, etc. The operating system of a terminal device can use DT to support the terminal device to use various different hardware. In some examples, for example, the Linux kernel in Android supports Android devices to use various hardware by using DT.
[0003] Different hardware providers can provide device tree source files (DTS) for their own hardware, so that DTS can be compiled (compiler) into device tree blob (DTB) files used by bootloaders (bootloaders) in the operating system. Among them, DTB files are binary files, mainly used for bootloaders to load corresponding hardware.
[0004] At present, due to the inconsistency between the DTB version corresponding to different hardware devices and the little kernel (LK) image or other kernel (kernel) image and system (system) image versions, the terminal device will not be able to execute normally before starting the operating system, and the terminal device will not be able to start the operating system normally. Since this stage is before starting the operating system, it cannot be solved by repair (erecovery). When the above situation occurs, the user's terminal device will not be able to start and use, which is commonly known as "bricked". Summary of the invention
[0005] The embodiment of the present application provides a method for checking the version of a device tree image, by compiling version information into a main device tree image file and an overlay device tree image file during the compilation phase. Before the terminal device is ready to start the operating system, the version information in the main device tree image file and the overlay device tree image file can be compared to see if they match, so that the terminal device can run the operating system normally, avoiding failures caused by different image file versions.
[0006] In a first aspect, a method for verifying the version of a device tree image is provided, and the method is applied to a terminal device, and the method includes: obtaining a pre-stored main device tree image file and an overlay device tree image file, wherein the main device tree image file includes a first version information, and the overlay device tree image file includes a second version information; when the first version information matches the second version information, merging the main device tree image file and the overlay device tree image file; and using the merged main device tree image file and the overlay device tree image file to start the operating system of the terminal device. Before starting the operating system of the terminal device, the present application obtains the version information in the main device tree image file and the overlay device tree image file, and compares whether the version information of different image files matches. When the version information of the main device tree image file and the overlay device tree image file matches, the operating system of the terminal device can be started. By comparing the version information in the image files, problems such as system failures caused by using different versions of image files before starting the operating system are avoided.
[0007] In one possible implementation, before obtaining the pre-stored main device tree image file and the overlay device tree image file, the method further includes: generating image version information; compiling the image version information as the first version information into the main device tree image file; and compiling the image version information as the second version information into the overlay device tree image file. In the compilation stage, the present application compiles the version information into different image files so that the terminal device can obtain the version information of the image file.
[0008] In one possible implementation, the first version information includes: one or more of first terminal device platform information, first terminal device product information, first terminal device code branch information, and first creation time information; the second version information includes: one or more of second terminal device platform information, second terminal device product information, second terminal device code branch information, and second creation time information.
[0009] In one possible implementation, when the first version information matches the second version information, the main device tree image file and the overlay device tree image file are merged, including: when one or more groups of information among the first terminal device platform information and the second terminal device platform information, the first terminal device product information and the second terminal device product information, the first terminal device code branch information and the second terminal device code branch information, and the first terminal device code branch information and the second terminal device code branch information are the same, the main device tree image file and the overlay device tree image file are merged.
[0010] In one possible implementation, the method further includes: when the first version information does not match the second version information, obtaining a backup overlay device tree image file, wherein the backup overlay device tree image file includes a third version information, and the third version information matches the first version information; merging the main device tree image file with the backup overlay device tree image file; and using the merged main device tree image file and the backup overlay device tree image file to start the operating system of the terminal device. In the present application, when the version information of the main device tree image file and the overlay device tree image file does not match, a backup overlay device tree image file that matches the version of the main device tree image file can be used to replace the original overlay device tree image file, so as to ensure that the terminal device can normally start the operating system, and avoid problems such as system failures caused by using different versions of image files before starting the operating system.
[0011] In one possible implementation, before obtaining the backup overlay device tree image file, the method further includes: generating image version information; and compiling the image version information as the third version information into the backup overlay device tree image file. The present application compiles the version information into the backup overlay device tree image file during the compilation phase so that the terminal device can obtain the version information of the image file.
[0012] In one possible implementation, the third version information includes: one or more of: third terminal device platform information, third terminal device product information, third terminal device code branch information and third creation time information; the third version information matches the first version information, including: the third terminal device platform information is the same as the first terminal device platform information, the third terminal device product information is the same as the first terminal device product information, the third terminal device code branch information is the same as the first terminal device code branch information, and the third terminal device code branch information is the same as the first terminal device code branch information.
[0013] In a second aspect, a terminal device for checking the version of a device tree image is provided, the terminal device comprising: a processor for coupling with a memory, and reading and executing instructions stored in the memory; when the processor is running, the instructions are executed, so that the processor is used to obtain a pre-stored main device tree image file and an overlay device tree image file, wherein the main device tree image file includes a first version information, and the overlay device tree image file includes a second version information; when the first version information matches the second version information, the main device tree image file and the overlay device tree image file are merged; and the merged main device tree image file and the overlay device tree image file are used to start the operating system of the terminal device. Before starting the operating system of the terminal device, the present application obtains the version information in the main device tree image file and the overlay device tree image file, and compares whether the version information of different image files matches. When the version information of the main device tree image file and the overlay device tree image file matches, the operating system of the terminal device can be started. By comparing the version information in the image files, problems such as system failure caused by using different versions of image files before starting the operating system are avoided.
[0014] In one possible implementation, the processor is further used to: generate image version information; compile the image version information as first version information into a main device tree image file; and compile the image version information as second version information into an overlay device tree image file. In the compilation stage, the application compiles the version information into different image files so that the terminal device can obtain the version information of the image file.
[0015] In one possible implementation, the first version information includes: one or more of first terminal device platform information, first terminal device product information, first terminal device code branch information, and first creation time information; the second version information includes: one or more of second terminal device platform information, second terminal device product information, second terminal device code branch information, and second creation time information.
[0016] In one possible implementation, the processor is also used to: merge the main device tree image file with the overlay device tree image file when one or more groups of information among the first terminal device platform information and the second terminal device platform information, the first terminal device product information and the second terminal device product information, the first terminal device code branch information and the second terminal device code branch information, and the first terminal device code branch information and the second terminal device code branch information are the same.
[0017] In one possible implementation, the processor is further used to: when the first version information does not match the second version information, obtain a backup overlay device tree image file, wherein the backup overlay device tree image file includes a third version information, and the third version information matches the first version information; merge the main device tree image file with the backup overlay device tree image file; and use the merged main device tree image file and the backup overlay device tree image file to start the operating system of the terminal device. In the present application, when the version information of the main device tree image file and the overlay device tree image file does not match, a backup overlay device tree image file that matches the version of the main device tree image file can be used to replace the original overlay device tree image file, so as to ensure that the terminal device can normally start the operating system, and avoid problems such as system failures caused by using different versions of image files before starting the operating system.
[0018] In one possible implementation, the processor is further configured to: generate image version information; and compile the image version information as the third version information into the backup overlay device tree image file. The present application compiles the version information into the backup overlay device tree image file during the compilation phase so that the terminal device can obtain the version information of the image file.
[0019] In one possible implementation, the third version information includes: one or more of: third terminal device platform information, third terminal device product information, third terminal device code branch information, and third creation time information; the processor is also used to: the third terminal device platform information is the same as the first terminal device platform information, the third terminal device product information is the same as the first terminal device product information, the third terminal device code branch information is the same as the first terminal device code branch information, and the third terminal device code branch information is the same as the first terminal device code branch information.
[0020] According to a third aspect, a computer-readable storage medium is provided, in which instructions are stored. When the instructions are executed on a terminal, the terminal executes any one of the methods according to the first aspect.
[0021] According to a fourth aspect, a computer device comprising instructions is provided, which, when executed on a terminal, enables the terminal to execute any one of the methods in the first aspect.
[0022] The present application discloses a method for verifying the version of a device tree image and a terminal device, which obtains the version information in the main device tree image file and the superimposed device tree image file before starting the operating system of the terminal device, and compares whether the version information of different image files matches. When the version information of the main device tree image file and the superimposed device tree image file match, the operating system of the terminal device can be started. When the version information of the main device tree image file and the superimposed device tree image file do not match, a backup superimposed device tree image file that matches the version of the main device tree image file can be used to replace the original superimposed device tree image file. This allows the terminal device to start the operating system normally, avoiding problems such as system failures caused by using different versions of image files before starting the operating system. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0024] Figure 2 A schematic diagram of initializing the operating system operating environment;
[0025] Figure 3 A flow chart of a method for verifying a device tree image version provided in an embodiment of the present application;
[0026] Figure 4 A flowchart of another method for verifying the device tree image version provided in an embodiment of the present application;
[0027] Figure 5 A flowchart of another method for verifying a device tree image version provided in an embodiment of the present application;
[0028] Figure 6 A schematic diagram of a mirror image comparison provided in an embodiment of the present application;
[0029] Figure 7 A flowchart of another method for verifying a device tree image version provided in an embodiment of the present application;
[0030] Figure 8 A flow chart for initializing an operating system running environment for a terminal device;
[0031] Fig. 9 A flow chart of a device tree image version verification initialization operating system running environment provided in an embodiment of the present application;
[0032] Fig.10 A schematic diagram of image file compilation provided in an embodiment of the present application;
[0033] Fig.11 A schematic diagram of the operation of a terminal device provided in an embodiment of the present application;
[0034] Fig.12 A schematic diagram of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0036] This application is mainly used in scenarios before the terminal device starts the operating system. For example Figure 1 As shown, when a user is ready to turn on a terminal device, such as a mobile phone. After the user presses the power button, the terminal device needs to initialize various hardware devices on the terminal device, such as the CPU, GPU, etc., through a boot loader (BL). At the same time, a memory space mapping map can also be established to bring the software and hardware environment of the terminal device operating system to a suitable state to prepare the correct environment for the final call to the operating system kernel. In some examples, the BL can also be called a boot small system.
[0037] However, during the process of updating the system, there may be a power outage or some unexpected circumstances that interrupt the update. At this time, some files in the system have been updated, but some files have not been updated. This will lead to inconsistent file versions in the system. Since the operation of the operating system requires a correct operating environment, when the BL is initialized, due to the inconsistency of some file versions, the initialization of the operating system operating environment fails. This will directly cause the terminal device to be unable to start the operating system. As Figure 1 ① shows that before starting the operating system, the terminal device is initializing the operating system operating environment. When the operating environment initialization fails, the terminal device enters the state shown in ②, that is, it cannot enter the operating system. At this time, the terminal device usually cannot be turned on normally. Since the terminal device has not entered the operating system at this time, it cannot be restored through the corresponding operations in the system. For example, it is impossible to modify it by restoring the factory settings in the terminal device settings.
[0038] Figure 2 Schematic diagram of initializing the operating system operating environment.
[0039] like Figure 2As shown, a schematic diagram of the terminal device initializing the operating system environment through BL before starting the operating system under normal circumstances is shown. When the user starts the terminal device through the power button of the terminal device, S201 is executed, and the terminal device jumps to the boot code (code) in the boot read-only memory (ROM) after power-on, and executes the boot code. The boot code is executed by S201, and the preloader (per-loader) in the ROM is loaded into the internal static random access memory (internal static random access memory, ISRAM), that is, S202. S203, when the per-loader is loaded in the ISRAM, the LK image in the ROM can be loaded into the dynamic random access memory (dynamic random access memory, DRAM), that is, S203 and S204. After the LK image is loaded into DRAM, the per-loader can also load the kernel and virtual memory (random access memory disk, ramdisk) stored in the ROM into DRAM respectively, for example S205. After the LK image loaded into the DRAM is compiled, S206 can be executed to compile the kernel loaded into the DRAM. When the kernel in the DRAM is compiled, S207 may be executed to compile the ramdisk, thereby completing the initialization operation of the operating system running environment of the terminal device.
[0040] Among them, when compiling the LK image and kernel in DRAM, the device tree overlay (DTO) is usually used to dynamically overlay the dedicated DT of the terminal device. Among them, DTO can be used to overlay other device information on the basis of the main DTB in the DT. So that BL can maintain the system chip (system on chip, SoC) DT. In some examples, DTO can also be called an overlay device tree. Usually SoC DT is the main device tree, and its compiled DTB file is usually suffixed with dtb, which can be called a dtb image. DTO is an overlay device tree, and its compiled DTB file is usually suffixed with dtbo, which can be called a dtbo image, to distinguish the DTB file compiled from the main device tree. It can be understood that, Figure 2When compiling an LK image, the dtb image can also be called an LK image. When compiling a kernel image, the dtb image can be called a kernel image. Obviously, the process of compiling an LK image is to compile the DTS of the LK and the DTS of the device tree overlay into an LK image and a dtbo image, and then merge them. For the process of compiling a kernel image, the DTS of the kernel and the DTS of the device tree overlay are compiled into a kernel image and a dtbo image, and then merged. Since DTO is used, the nodes corresponding to the corresponding hardware devices can be superimposed into the DT, and the properties of any node in the device tree can be changed.
[0041] Both DT and DTO store basic configuration information for supporting the operation of the operating system. In order to ensure that the operating system code can be reused, the designer of the operating system abstracts the logic of the operating system code and decouples the code logic and configuration. The configuration is stored independently in the partitions corresponding to the dtb image and the dtbo image. Obviously, the above method can bring many visible benefits in the optimization of the code structure. However, there are also some problems. For example, when the mobile phone upgrades the operating system, some abnormalities occur, resulting in the upgrade failure, which may cause the dtb image and the dtbo image to be mismatched. However, the terminal device currently does not find the mismatch between the dtb image and the dtbo image before starting the operating system. Therefore, it often causes the terminal device to fail to boot. The reason is that the mismatch between the dtb image and the dtbo image makes it impossible to initialize the environment suitable for the operation of the operating system, so that the operating system accesses the configuration information incorrectly during execution, and the operating system cannot run normally. For users, the terminal device cannot boot normally and cannot enter the operating system normally. When the LK image, kernel image, and system (system) image are used as dtb images, such problems will occur. Of course, since the terminal device cannot enter the boot operating system, the user cannot solve the above problem through recovery or eRecovery.
[0042] Some common scenarios may be the integrated circuit (IC) chips based on Android released by MediaTek (MTK). Of course, similar problems also exist for IC chips based on other operating systems released by other manufacturers.
[0043] Therefore, the present application provides a method for verifying the version of a device tree image, by obtaining the version information in the main device tree image file and the overlay device tree image file before starting the operating system of the terminal device, and comparing whether the version information of different image files matches. When the version information of the main device tree image file and the overlay device tree image file match, the operating system of the terminal device is started. When the version information of the main device tree image file and the overlay device tree image file do not match, a backup overlay device tree image file that matches the version of the main device tree image file is used to replace the original overlay device tree image file. This allows the terminal device to start the operating system normally, avoiding problems such as system failures caused by using different versions of image files before starting the operating system.
[0044] The technical solutions in the embodiments of the present application will be described in detail below in conjunction with the drawings in the embodiments of the present application.
[0045] Figure 3 A flowchart of a method for verifying a device tree image version is provided in an embodiment of the present application.
[0046] like Figure 3 As shown, the present application provides a method for verifying the version of a device tree image, which can be applied to a terminal device. The terminal device involved in the present application can be a mobile phone, a personal computer (PC), a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, and a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, a vehicle-mounted device, a smart TV, a smart home device and / or a smart city device. The embodiments of the present application do not impose any special restrictions on the specific type of the terminal device.
[0047] The method may include the following steps:
[0048] S301, obtaining a pre-stored main device tree image file and an overlay device tree image file.
[0049] Before starting the operating system, the terminal device first obtains the pre-stored main device tree image file and the overlay device tree image file.
[0050] In one example, the main device tree image file and the overlay device tree image file may be stored in the ROM of the terminal device, for example Figure 2 The ROM shown. The main device tree image file may include first version information, and the overlay device tree image file may include second version information. It can be understood that the first version information is used to describe the version of the main device tree image file, and the second version information is used to describe the version of the overlay device tree image file.
[0051] In some examples, the main device tree image file may be the LK image, kernel image, system image, etc. mentioned above, that is, a file with the suffix .dtb after being compiled into a binary file. In some examples, the overlay device tree image file may be a file with the suffix .dtbo after being compiled into a binary file.
[0052] S302: When the first version information matches the second version information, merge the main device tree image file and the overlay device tree image file.
[0053] After the terminal device obtains the first version information of the main device tree image file and the second version information of the overlay device tree image file in S301, the first version information and the second version information can be compared. If the first version information matches the second version information, the main device tree image file and the overlay device tree image file can be merged.
[0054] In one example, the first version information and the second version information may be collectively referred to as version information or fingerprint information (fingerprint). It is understandable that fingerprint is used to uniquely identify the information of the current DT configuration version of the corresponding image file. In some examples, fingerprint may be stored as a field in different image files. Among them, the fingerprint field may include one or more of terminal device platform information (platform), terminal device product information (product), terminal device code branch information (branch) and creation time information (buildtime). Of course, in some examples, the fingerprint field may also include other information that may be used to indicate the version of the image file, which is not limited in this application. The fingerprint field may be, for example, as shown in Table 1,
[0055] platform product branch buildtime
[0056] Table 1
[0057] It is understandable that Table 1 only shows a possible structure of fingerprint. Of course, it can also have more or less information, and the order of information in the fingerprint field can also be adjusted according to actual conditions, which is not limited in this application.
[0058] In one example, the terminal device obtains the main device tree image file and the overlay device tree image file in S301 as the compiled dtb image and dtbo image. Obviously, the main device tree image file and the overlay device tree image file are obtained as a compiled file. The fingerprint field can uniquely identify the version information of the current device tree image file in the compiled state. Therefore, the terminal device needs to determine the fingerprint field of the main device tree image file, which can be called the first fingerprint field or the first version information; and the terminal device needs to determine the fingerprint field of the overlay device tree image file, which can be called the second fingerprint field or the second version information. And compare whether the fingerprint fields of different image files match. That is, whether the first version information matches the second version information.
[0059] It can be understood that the information contained in the first fingerprint field can be called first terminal device platform information, first terminal device product information, first terminal device code branch information and first creation time information; the information contained in the second fingerprint field can be called second terminal device platform information, second terminal device product information, second terminal device code branch information and second creation time information.
[0060] In one example, it can be determined whether one or more of the platform, product, branch, and buildtime in different image files are the same as a basis for matching. For example, by judging whether the first fingerprint field is the same as any one of the platform, product, branch, or buildtime in the second fingerprint field, it can be considered that the first version information matches the second version information. Of course, it is also possible to choose the product and buildtime to be the same, that is, the first version information is considered to match the second version information. Alternatively, when the platform, product, branch, and buildtime in the first fingerprint field are the same as those in the second fingerprint field, the first version information is considered to match the second version information. It can be understood that the present application only lists a few examples for illustration, and any number of information in the fingerprint field can also be selected for comparison to determine whether the first version information matches the second version information.
[0061] When the terminal device determines that the first version information matches the second version information, the main device tree image file and the overlay device tree image file are merged.
[0062] S303: Start the operating system of the terminal device by using the merged main device tree image file and the overlay device tree image file.
[0063] The terminal device uses the main device tree image file and the superimposed device tree image file merged in S302 to start the operating system on the terminal device. It can be understood that when it is determined that the fingerprint fields of the main device tree image file and the superimposed device tree image file match, it can be determined that the merger of the main device tree image file and the superimposed device tree image file will not cause a system crash, and it can be ensured that the environment initialized by the terminal device is a normal environment. Therefore, the terminal device can start the operating system in a normal environment after the main device tree image file and the superimposed device tree image file are merged.
[0064] Figure 4 A flowchart of another method for verifying a device tree image version provided in an embodiment of the present application.
[0065] like Figure 4 As shown, the present application also provides another method flow chart for device tree image version verification. After S301, when the first version information does not match the second version information, the method may further include the following steps:
[0066] S401, when the first version information does not match the second version information, obtain a backup overlay device tree image file.
[0067] When the terminal device determines that the first version information does not match the second version information, a backup overlay device tree image file may also be obtained.
[0068] In one example, the backup overlay device tree image file may be a backup image file pre-stored in the terminal device, and used to merge with the main device tree image file when the overlay device tree image file cannot be used. In most cases, it can be used for terminal devices to perform recovery or erecovery. For example, the backup overlay device tree image file may be a dtbo image file for recovery, i.e., recovery_dtbo. For another example, the backup overlay device tree image file may also be a dtbo image file for erecovery, i.e., erecovery_dtbo. It is understandable that when the main device tree image file and the overlay device tree image file of the terminal device cannot start the operating system due to different versions, the backup overlay device tree image file may be used to merge with the main device tree image file so that the user can enter the operating system for recovery or erecovery.
[0069] Among them, the backup overlay device tree image file may include a third version information. The third version information matches the first version information. In an example, the fingerprint field of the backup overlay device tree image file can be referred to as a third fingerprint field or a third version information. It can be understood that the information contained in the third fingerprint field can be referred to as third terminal device platform information, third terminal device product information, third terminal device code branch information and third creation time information. For the third version information to match the first version information, it can be: the third terminal device platform information is the same as the first terminal device platform information, the third terminal device product information is the same as the first terminal device product information, the third terminal device code branch information is the same as the first terminal device code branch information, and the third terminal device code branch information is the same as the first terminal device code branch information. For details, please refer to the corresponding description of the matching of the first version information and the second version information in S302, which will not be repeated here.
[0070] S402: Merge the main device tree image file and the backup overlay device tree image file.
[0071] The terminal device merges the backup overlay device tree image file obtained in S401 with the main device tree image file.
[0072] S403, using the merged main device tree image file and the backup overlay device tree image file to start the operating system of the terminal device.
[0073] The terminal device uses the main device tree image file and the backup overlay device tree image file merged in S402 to start the operating system on the terminal device.
[0074] Figure 5 A flowchart of another method for verifying a device tree image version is provided in an embodiment of the present application.
[0075] like Figure 5 As shown, the present application also provides a flow chart of another method for checking the version of a device tree image. Before S301, the main device tree image file and the superimposed device tree image file often need to be compiled (built). Therefore, when the main device tree image file and the superimposed device tree image file are compiled, the fingerprint field can be saved in the main device tree image file and the superimposed device tree image file. Before S301, the method can also include the following steps:
[0076] S501, generate image version information.
[0077] The terminal device may generate image version information during the compilation process. It is understandable that the image version information may be a fingerprint field.
[0078] S502, compile the image version information as first version information into a main device tree image file; and compile the image version information as second version information into an overlay device tree image file.
[0079] The terminal device compiles the fingerprint field generated in S501 into the main device tree image file and the overlay device tree image file. It can be understood that the fingerprint field compiled into the main device tree image file is the first fingerprint field mentioned above; the fingerprint field compiled into the overlay device tree image file is the second fingerprint field mentioned above. Among them, the process of compiling the fingerprint field into the image file can also be understood as the process of writing the fingerprint field into the image file.
[0080] In one example, the first fingerprint field can be saved to the header of the main device tree image file. For example, a fingerprint field is added to the image header of the main device tree image file to save the version information of the image file. Figure 6As shown, the original image header contains: magic is used to represent the magic number of the image identifier. It can be understood that the magic number is usually an unexplained numeric constant or string, and the magic number can also be called a magic value. Among them, the content of the first few bytes of most files is fixed, such as intentional padding, or it is so. Obviously, the content of the first few bytes of the file is the magic number, and the terminal device can determine the type of each file based on the content of these bytes. total_size is used to indicate the total size of the image file, header_size is used to indicate the image header size, and dt_entry_size is used to indicate the size of each DT item in the device tree. It can be understood that for the main device image file or the superimposed device tree image file, the structure is exactly the same, and each DT image file contains one or more DT items for recording the content of the DT image file. dt_entry_count is used to indicate the number of DT items in the image file. dt_entries_offset is used to indicate the offset of the DT item in the image file, page_size is used to indicate the size of a single image page, and version is used to describe the structural version of the image file.
[0081] The image is described. For the new image header, that is, the image header of the image file in this application, a fingerprint field is added. Obviously, the new image header with the fingerprint field added will contain the version information of the image file. In order to subsequently identify whether different image files match. In another example, the second fingerprint field can also be as follows Figure 6 The header of the image file saved to the overlay device tree is shown.
[0082] Of course, in other examples, the fingerprint field can also be saved to any other location in the image file, and this application does not limit this.
[0083] It is understandable that version is used to indicate the version of the overall structure of the image file. For example, image files of different versions have completely different image structures. The version described by the fingerprint field involved in this application can distinguish different versions after certain parameters are modified under the same version structure. Obviously, the fingerprint field is more detailed than the version in dividing the image file version.
[0084] Understandably, Figure 6 The image header shown can be used for both dtb images and dtbo images.
[0085] After S502 is executed, you can execute Figure 3S301 in.
[0086] Figure 7 A flowchart of a method for verifying a device tree image version is provided in another embodiment of the present application.
[0087] like Figure 7 As shown, the present application also provides a flowchart of a method for verifying the version of a device tree image. It is understandable that when the versions of the main device tree image file and the overlay device tree image file do not match, the terminal device will also obtain a backup overlay device tree image file. Therefore, the terminal device also needs to compile the fingerprint field into the backup overlay device tree image file during the compilation phase. Therefore, after S501, the method may also include the following steps:
[0088] S701, compile the image version information as the third version information into the backup overlay device tree image file.
[0089] The terminal device compiles the fingerprint field generated in S501 into the backup overlay device tree image file. It can be understood that the fingerprint field compiled into the backup overlay device tree image file is the third fingerprint field mentioned above. Among them, the position of the third fingerprint field in the backup overlay device tree image file can refer to the corresponding description of the first fingerprint field or the second fingerprint field in S502, and this application will not repeat it here.
[0090] After S701 is executed, you can execute Figure 3 S301 in.
[0091] The method for verifying the device tree image version involved in the present application obtains the version information in the main device tree image file and the overlay device tree image file before starting the operating system of the terminal device, and compares whether the version information of different image files matches. When the version information of the main device tree image file and the overlay device tree image file match, the operating system of the terminal device is started. When the version information of the main device tree image file and the overlay device tree image file do not match, a backup overlay device tree image file is obtained to replace the original overlay device tree image file. This allows the terminal device to still start the operating system normally, avoiding system failures, crashes, and other problems caused by using different versions of image files before starting the operating system.
[0092] Figure 8 A flow chart of initializing an operating system running environment for a terminal device.
[0093] like Figure 8As shown, a flow chart of initializing the operating system running environment of a terminal device is provided. In this process, since there is no version information in the image file, when the image version does not match, the system will crash. It is understandable that Figure 8 The LK image is described as the main device tree image file. Figure 8 In the embodiment shown, the main device tree image file may be lk_main_dtb. Of course, in other examples, the main device tree image file may also be a kernel image, a system image, etc., which is not limited in this application. The method may include the following steps:
[0094] S801, load lk_main_dtb and dtbo.
[0095] Before the terminal device runs the operating system, it needs to initialize the operating system running environment, so it is necessary to load the LK image and overlay the device tree image files, namely lk_main_dtb and dtbo.
[0096] S802, merge lk_main_dtb and dtbo.
[0097] The terminal device merges the lk_main_dtb loaded by S801 with dtbo to start the operating system later.
[0098] S803, determine whether the merger is successful.
[0099] If the merging is successful, S804 is executed; if the merging fails, S805 is executed.
[0100] S804, a liquid crystal display (LCD) driver obtains configuration information, and the terminal device recognizes that the configuration and logic do not match.
[0101] In the terminal device, the LCD driver usually obtains the hardware configuration information and executes the logic in lk_main_dtb and dtbo. However, due to the mismatch between the versions of lk_main_dtb and dtbo, the corresponding parameters in the running logic do not match the configuration information obtained by the LCD driver. This execution leads to S806.
[0102] S805: Use recovery_dtbo or erecovery_dtbo as a backup to merge with lk_main_dtb.
[0103] If the terminal device determines in S803 that lk_main_dtb and dtbo are not merged successfully, recovery_dtbo or erecovery_dtbo is selected as the backup dtbo to be merged with lk_main_dtb, and S804 is executed.
[0104] S806, operating system crashes.
[0105] Since the corresponding parameters in the operation logic in S804 do not match the configuration information obtained by the LCD driver, the terminal device will be unable to run the operating system. For the user, the terminal device will appear to be unable to start, that is, "bricked".
[0106] Obviously, in the current solution, since the image file does not contain version information, when the image file version does not match, the user cannot enter the system to repair it, which seriously affects the user experience and even causes serious economic losses.
[0107] Therefore, this application adds version information to the image file to ensure that when the image file version does not match, the backup image file is discovered and loaded in time, thereby ensuring that the operating system of the terminal device can run normally, or the user can enter the operating system to further repair the terminal device.
[0108] Fig. 9 A device tree image version verification and initialization operating system running environment flow chart provided in an embodiment of the present application.
[0109] like Fig. 9 As shown, it shows a flow chart of device tree image version verification and initialization of operating system running environment after adding version information in the image file. Figure 8 Similarly, in this embodiment, LK image is still used as the main device tree image file for description, and the main device tree image file can be lk_main_dtb. Of course, in other examples, the main device tree image file can also be a kernel image, a system image, etc., which is not limited in this application.
[0110] The method may include the following steps:
[0111] S901, load lk_main_dtb and dtbo.
[0112] The terminal device loads the LK image and overlays the device tree image file, namely, lk_main_dtb and dtbo, and determines the fingerprint fields in lk_main_dtb and dtbo, namely, the first fingerprint field and the second fingerprint field.
[0113] S902, determine whether the fingerprint field matches
[0114] The terminal device determines whether one or more information in the first fingerprint field and the second fingerprint field match. If they match, S903 is executed; if they do not match, S904 is executed.
[0115] S903, merge lk_main_dtb and dtbo.
[0116] The terminal device merges the lk_main_dtb loaded by S901 with dtbo to start the operating system later.
[0117] S904: Use recovery_dtbo or erecovery_dtbo as a backup to merge with lk_main_dtb.
[0118] If the terminal device determines in S903 that the fingerprint field does not match, it selects recovery_dtbo or erecovery_dtbo as the backup dtbo to merge with lk_main_dtb and executes S903. It can be understood that the fingerprint field in recovery_dtbo or erecovery_dtbo in S904 matches the fingerprint field in lk_main_dtb.
[0119] S905, the operating system starts normally and is booted into repair or recovery.
[0120] If the dtbo merged with lk_main_dtb in S903 is a backup device tree image file, the operating system of the terminal device can be started normally. If the dtbo merged with lk_main_dtb in S903 is recovery_dtbo, the operating system of the terminal device boots into recovery for repair after startup. If the dtbo merged with lk_main_dtb in S903 is erecovery_dtbo, the operating system of the terminal device boots into erecovery for recovery after startup.
[0121] Among them, both recovery and erecovery allow users to repair terminal devices. The difference is that recovery only uses local configuration files for repair, while erecovery can download the latest configuration files through the network, so as to use the latest configuration files to repair the terminal device. The specific repair process can refer to the existing methods, and this application will not be repeated here.
[0122] Understandably, Fig. 9 The specific execution process of the method shown can be referred to Figures 3 to 7 , this application will not be elaborated here.
[0123] Fig.10 A schematic diagram of image file compilation provided in an embodiment of the present application.
[0124] like Fig.10 As shown, during the compilation phase, the terminal device generates a fingerprint field and writes the content of the field into the image header of the overlay device tree image file and the main device tree image file. In some examples, both can be written into the image header of the image file, or stored as a fingerprint variable in any optional position in the image file, which is not limited in this application.
[0125] Of course, in other examples, in order to ensure that when the main device tree image file and the overlay device tree image file cannot be merged, a backup overlay device tree image file can replace the overlay device tree image file and merge with the main device tree image file. Therefore, during the compilation phase, the terminal device can also write the fingerprint field into the image header of the backup overlay device tree image file, or store it as a fingerprint variable in any optional position in the image file.
[0126] It is understandable that the specific implementation process can refer to Figures 5 to 7 The corresponding description in will not be repeated here.
[0127] for Figures 5 to 7 , Fig.10 The described compilation phase may be performed before the terminal device leaves the factory or before the operating system is released.
[0128] Fig.11 A schematic diagram of the operation of a terminal device provided in an embodiment of the present application.
[0129] like Fig.11 As shown, in the running stage, the terminal device obtains the fingerprint field in the main device tree image file and compares it with the overlay device tree image file. Therefore, when the versions are different, the backup overlay device tree image file can be used to replace the overlay device tree image file in time and merged with the main device tree image file, so that the user can enter the operating system for repair.
[0130] It is understandable that the specific implementation process can refer to Figures 3 to 9 The corresponding description in will not be repeated here.
[0131] Fig.12 A schematic diagram of a terminal device provided in an embodiment of the present application.
[0132] The present application provides a terminal device 1200, which may include: a processor 1201, a memory 1202, and a bus 1203. The processor 1201 and the memory 1202 in the terminal device 1200 may establish a communication connection through the bus 1203. It is understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the terminal device 1200. The terminal device 1200 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0133] The processor 1201 may be a processor of an architecture such as an advanced reduced instruction set computing machine (ARM), X86, or a microprocessor without interlocked piped stages (MIPS). The processor 1201 may include one or more processing units, such as an application processor (AP), a modem processor, a GPU, an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.
[0134] A memory may also be provided in the processor 1202 for storing instructions and data. In some embodiments, the memory 1202 is a cache memory. The memory may store instructions or data that the processor 1201 has just used or cyclically used. If the processor 1210 needs to use the instruction or data again, it may be directly called from the memory. Repeated access is avoided, and the waiting time of the processor 1201 is reduced, thereby improving the efficiency of the system. In one example, the memory 1202 may include a memory, and an operating system, an image file, etc. may be stored in the memory. The memory 1202 may also include an auxiliary memory or an external memory, such as a non-removable memory or a removable memory card, etc.
[0135] The internal memory may be used to store computer executable program codes, and the executable program codes include instructions. The internal memory may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc. The processor 1201 executes various functional applications and data processing of the device 1200 by running the instructions stored in the memory.
[0136] The device 1200 provided in this application can realize the above Figures 3 to 11 For any function of the terminal device in the described example, the specific implementation method can refer to the Figures 3 to 11 The corresponding description in will not be repeated here.
[0137] In some embodiments, the present application also provides a method for determining infringement, for example, by using a script to parse the DT image file to determine whether the parsed content of the image file contains version information, such as a fingerprint field.
[0138] This application obtains the version information in the main device tree image file and the overlay device tree image file before starting the operating system of the terminal device, and compares whether the version information of different image files matches. It solves a type of operating system operation failure caused by mismatch between configuration and code logic. And when the version information of the main device tree image file and the overlay device tree image file does not match, a backup overlay device tree image file that matches the version of the main device tree image file can be used to replace the original overlay device tree image file. Load the backup configuration data in time to ensure the normal operation of the system or repair system failures. It solves a type of failure to boot caused by inconsistent DT configuration versions.
[0139] Those of ordinary skill in the art should further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0140] A person skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing a processor through a program, and the program can be stored in a computer-readable storage medium, and the storage medium is a non-transitory medium, such as a random access memory, a read-only memory, a flash memory, a hard disk, a solid-state drive, a magnetic tape, a floppy disk, an optical disc, and any combination thereof.
[0141] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for verifying a device tree image version, characterized in that: The method is applied to a terminal device, and the method comprises: Obtaining a pre-stored main device tree image file and an overlay device tree image file, wherein the main device tree image file includes first version information, and the overlay device tree image file includes second version information, the first version information includes: one or more of first terminal device platform information, first terminal device product information, first terminal device code branch information, and first creation time information; the second version information includes: one or more of second terminal device platform information, second terminal device product information, second terminal device code branch information, and second creation time information; When the first version information matches the second version information, merging the main device tree image file with the overlay device tree image file, wherein when one or more groups of information among the first terminal device platform information and the second terminal device platform information, the first terminal device product information and the second terminal device product information, the first terminal device code branch information and the second terminal device code branch information, and the first terminal device code branch information and the second terminal device code branch information are the same, merging the main device tree image file with the overlay device tree image file; The operating system of the terminal device is started by using the merged main device tree image file and the overlay device tree image file.
2. The method according to claim 1, characterized in that Before obtaining the pre-stored main device tree image file and the overlay device tree image file, the method further includes: Generate image version information; Compile the image version information as the first version information into the main device tree image file; and, The image version information is compiled into the overlay device tree image file as the second version information.
3. The method according to claim 1 or 2, characterized in that The method further comprises: When the first version information does not match the second version information, obtaining a backup overlay device tree image file, wherein the backup overlay device tree image file includes third version information, and the third version information matches the first version information; Merging the main device tree image file with the backup overlay device tree image file; The operating system of the terminal device is started by using the merged main device tree image file and the backup overlay device tree image file.
4. The method according to claim 3, characterized in that Before obtaining the backup overlay device tree image file, the method further includes: Generate image version information; The image version information is compiled into the backup overlay device tree image file as the third version information.
5. The method according to claim 4, characterized in that The third version information includes: one or more of: third terminal device platform information, third terminal device product information, third terminal device code branch information, and third creation time information; The third version information matches the first version information, including: The third terminal device platform information is the same as the first terminal device platform information, the third terminal device product information is the same as the first terminal device product information, the third terminal device code branch information is the same as the first terminal device code branch information, and the third terminal device code branch information is the same as the first terminal device code branch information.
6. A terminal device for device tree image version verification, characterized in that: The terminal device comprises: a processor, coupled to the memory, and configured to read and execute instructions stored in the memory; The processor executes the instructions when it is running, so that the processor is used to obtain a pre-stored main device tree image file and an overlay device tree image file, wherein the main device tree image file includes first version information, and the overlay device tree image file includes second version information, the first version information includes: one or more of first terminal device platform information, first terminal device product information, first terminal device code branch information, and first creation time information; the second version information includes: one or more of second terminal device platform information, second terminal device product information, second terminal device code branch information, and second creation time information; When the first version information matches the second version information, the main device tree image file is merged with the overlay device tree image file, wherein when one or more groups of information among the first terminal device platform information and the second terminal device platform information, the first terminal device product information and the second terminal device product information, the first terminal device code branch information and the second terminal device code branch information, and the first terminal device code branch information and the second terminal device code branch information are the same, the main device tree image file is merged with the overlay device tree image file; and the merged main device tree image file and the overlay device tree image file are used to start the operating system of the terminal device.
7. The terminal device according to claim 6, characterized in that: The processor is further configured to: Generate image version information; Compile the image version information as the first version information into the main device tree image file; and, The image version information is compiled into the overlay device tree image file as the second version information.
8. The terminal device according to claim 7, characterized in that: The processor is further configured to: When the first version information does not match the second version information, obtaining a backup overlay device tree image file, wherein the backup overlay device tree image file includes third version information, and the third version information matches the first version information; Merging the main device tree image file with the backup overlay device tree image file; The operating system of the terminal device is started by using the merged main device tree image file and the backup overlay device tree image file.
9. The terminal device according to claim 8, characterized in that: The processor is further configured to: Generate image version information; The image version information is compiled into the backup overlay device tree image file as the third version information.
10. The terminal device according to claim 9, characterized in that: The third version information includes: one or more of: third terminal device platform information, third terminal device product information, third terminal device code branch information, and third creation time information; The processor is further configured to: The third terminal device platform information is the same as the first terminal device platform information, the third terminal device product information is the same as the first terminal device product information, the third terminal device code branch information is the same as the first terminal device code branch information, and the third terminal device code branch information is the same as the first terminal device code branch information.
11. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, characterized in that: When the instruction is executed on a terminal, the terminal is caused to execute the method according to any one of claims 1 to 5.
12. A computer device comprising instructions, which, when executed on a terminal, causes the terminal to execute the method according to any one of claims 1 to 5.