Method and device for switching user program into BL program and chip

Through the method of integrity verification in the BL data structure, the data error risk and reliability problems when switching between user programs and BL programs are solved, and higher system reliability and fault tolerance are achieved.

CN119718439APending Publication Date: 2025-03-28BEIJING TONGFANG MICROELECTRONICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411892773.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

In the prior art, when switching between a user program and a BL program, there are data error risks and data reliability problems, especially when the user program data is large, some of the BL code data may be overwritten.

Method used

By constructing a BL data structure including BL code verification data and code segment to be verified, integrity verification is performed to ensure that subsequent processes can be performed only after the verification result is passed. The method includes obtaining BL code verification data, verifying the code segment to be verified in the BL data structure, and updating the BL function status word and writing the backup BL startup data after the verification is passed.

Benefits of technology

It improves the reliability of the behavior of switching to BL programs, detects and prevents potential code tampering, ensures the integrity and correctness of BL code, reduces the risk of system failure, and improves the system's fault tolerance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718439A_ABST
    Figure CN119718439A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of chip application, and discloses a method and device for switching a user program into a BL program and a chip, and the method comprises the steps: obtaining BL code verification data based on a BL data structure; according to the BL code verification data, verifying the to-be-verified code segment in the BL data structure to obtain a verification result; under the condition that the verification result is passed, updating the BL function status word; and after the BL function status word is updated, writing the BL starting data backed up in the BL data structure into a starting address so as to restart the program to realize switching from the user program to the BL program. And the to-be-verified code segment is verified, so that the integrity and correctness of the BL code are ensured, and the system fault risk caused by code damage is reduced. Therefore, by adopting the method provided by the invention, the MCU running in the user program state can be safely and reliably modified to run in the BL state, and the reliability of the behavior of switching the user program to the BL program is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of chip application technology, for example, to a method and device for switching a user program to a BL program, and a chip. Background Art

[0002] At present, BootLoader (boot loader, BL) is an important component for booting program operation in embedded systems, responsible for loading startup tasks after the system is powered on or reset. BL allows new firmware images to be received through various interfaces (such as network, serial port, USB, etc.) and written into non-volatile memory to achieve remote or local firmware updates of devices. In some systems, BL supports the option of loading different operating system versions or applications, provides multiple boot options, and enhances the flexibility and customizability of the system. For chips that need to download and update user programs through the download program BL, when the user program needs to be updated again, the MCU (Microcontroller Unit) needs to switch back to the BL program and then download the user program data through BL.

[0003] In the related art, the startup data of BL is backed up to the user program. When it is necessary to switch back to BL, the backed-up startup data is written back to the NVM (Non-Volatile Memory) startup area, and the chip is restarted to switch the state.

[0004] In the process of implementing the embodiments of the present disclosure, it is found that there are at least the following problems in the related art:

[0005] Copying the NVM startup data and backing it up in the user program has the risk of data errors during the data exchange process. When the user program data volume is large, there is also the risk of overwriting part of the BL code data. Therefore, there are data reliability issues in the related technology.

[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0007] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0008] The embodiments of the present disclosure provide a method, an apparatus, and a chip for switching a user program to a BL program, so as to improve the reliability of the behavior of switching the user program to the BL program.

[0009] In some embodiments, a method for switching a user program to a BL program includes: obtaining BL code verification data based on a BL data structure; verifying a code segment to be verified in the BL data structure according to the BL code verification data to obtain a verification result; updating a BL function status word when the verification result passes; after the BL function status word is updated, writing the BL startup data backed up in the BL data structure to a startup address to restart the program to achieve switching from the user program to the BL program.

[0010] Optionally, the BL data structure includes: a BL startup data segment, a program download function segment, a communication interface segment, a basic function test segment, a BL startup data backup segment, a verification basic information segment and a code verification result data segment.

[0011] Optionally, obtaining BL code verification data includes: obtaining, according to a verification basic information segment in a BL data structure, a function state supported by BL, the number of code segments of BL, a starting address at which each segment code is stored, and a starting address of verification data corresponding to each segment code; determining, according to the starting address of verification data corresponding to each segment code, verification result data information of each segment code in a code verification result data segment; and using the function state supported by BL, the number of code segments of BL, the starting address at which each segment code is stored, and the verification result data information of each segment code as BL code verification data.

[0012] Optionally, the code segments to be verified in the BL data structure are verified according to the BL code verification data, including: determining the number of code segments to be verified supported by the BL according to the functional status supported by the BL and the number of code segments of the BL; obtaining data information of each code segment to be verified according to the starting address where each segment code is stored; verifying the data information of each code segment to be verified based on a preset verification method, and determining the verification result according to the verification result data information of each segment code.

[0013] Optionally, the code segment to be verified includes a BL startup data backup segment, one or more program download function segments, one or more communication interface segments, and a basic function test segment; the data information of each code segment to be verified is verified, including: verifying the BL startup data backup segment, the program download function segment, and the communication interface segment to determine whether the conditions for writing back the BL startup data are met; if the conditions for writing back the BL startup data are met, verifying the basic function test segment; if the conditions for writing back the BL startup data are not met, returning an error status word.

[0014] Optionally, when the BL startup data backup segment, at least one program download function segment, and at least one communication interface segment pass verification in any order, the condition for writing back the BL startup data is met; otherwise, the condition for writing back the BL startup data is not met.

[0015] Optionally, the verification result passing means that the basic function test section verification passes.

[0016] In some embodiments, the device for switching the user program to the BL program includes: a parsing module, configured to obtain BL code verification data based on the BL data structure; a verification module, configured to verify the code segment to be verified in the BL data structure according to the BL code verification data; an update module, configured to update the BL function status word when the code segment to be verified passes the verification; and a rewrite module, configured to write the backed-up BL startup data to the startup address after the update is completed, so as to restart the program to realize the switch from the user program to the BL program.

[0017] In some embodiments, the apparatus for switching a user program to a BL program includes a processor and a memory storing program instructions, and the processor is configured to execute the above-mentioned method for switching a user program to a BL program when running the program instructions.

[0018] In some embodiments, a chip includes: a chip body; and the device for switching a user program to a BL program as described above is installed in the chip body.

[0019] The method, device, and chip for switching a user program to a BL program provided by the embodiments of the present disclosure can achieve the following technical effects:

[0020] In the embodiment of the present disclosure, by constructing a BL data structure including BL code verification data and a code segment to be verified, according to the BL code verification data, the integrity of the code segment to be verified can be verified, ensuring that the subsequent process can be executed only after the verification result passes, thereby helping to detect and prevent potential code tampering and protect the system from unauthorized modification. By verifying the code segment to be verified, the integrity and correctness of the BL code are ensured, and the risk of system failure caused by code damage is reduced. The BL data structure includes the backup BL startup data to ensure that it can be detected and restored in time when the original startup data is damaged, thereby improving the fault tolerance of the system. Therefore, by adopting the method provided in the embodiment of the present disclosure, the MCU running in the user program state can be safely and reliably modified to run in the BL state, improving the reliability of the behavior of the user program switching to the BL program. In addition, through the automated verification and status word update mechanism, manual intervention is reduced and the management and maintenance process of the BL is simplified. Through accurate verification and status update, unnecessary code execution and resource consumption can also be reduced, and the system operation efficiency can be improved.

[0021] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:

[0023] Figure 1 is a schematic diagram of a method for switching a user program to a BL program provided by an embodiment of the present disclosure;

[0024] Figure 2 is a schematic diagram of a BL data structure provided by an embodiment of the present disclosure;

[0025] Figure 3 is a schematic diagram of another method for switching a user program to a BL program provided by an embodiment of the present disclosure;

[0026] Figure 4 is a schematic diagram of another method for switching a user program to a BL program provided by an embodiment of the present disclosure;

[0027] Figure 5 is a schematic diagram of a device for switching a user program to a BL program provided by an embodiment of the present disclosure;

[0028] Figure 6 is a schematic diagram of another device for switching a user program to a BL program provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0029] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.

[0030] The terms "first", "second", etc. in the technical solutions described in this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so as to describe the embodiments of the disclosed embodiments described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0031] Unless otherwise stated, the term "plurality" means two or more.

[0032] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0033] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.

[0034] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.

[0035] Combination Figure 1 As shown, the embodiment of the present disclosure provides a method for switching a user program to a BL program. The execution subject of the method may be a processor, and the method includes:

[0036] S101, the processor obtains BL code verification data based on the BL data structure.

[0037] S102, the processor verifies the code segment to be verified in the BL data structure according to the BL code verification data to obtain a verification result.

[0038] S103: When the verification result passes, the processor updates the BL function status word.

[0039] S104, after the BL function status word is updated, the processor writes the BL startup data backed up in the BL data structure into the startup address to restart the program to switch from the user program to the BL program.

[0040] In the embodiment of the present disclosure, by constructing a BL data structure including BL code verification data and a code segment to be verified, according to the BL code verification data, the integrity of the code segment to be verified can be verified, ensuring that the subsequent process can be executed only after the verification result passes, thereby helping to detect and prevent potential code tampering and protect the system from unauthorized modification. By verifying the code segment to be verified, the integrity and correctness of the BL code are ensured, and the risk of system failure caused by code damage is reduced. The BL data structure includes the backup BL startup data to ensure that it can be detected and restored in time when the original startup data is damaged, thereby improving the fault tolerance of the system. Therefore, by adopting the method provided in the embodiment of the present disclosure, the MCU running in the user program state can be safely and reliably modified to run in the BL state, improving the reliability of the behavior of the user program switching to the BL program. In addition, through the automated verification and status word update mechanism, manual intervention is reduced and the management and maintenance process of the BL is simplified. Through accurate verification and status update, unnecessary code execution and resource consumption can also be reduced, and the system operation efficiency can be improved.

[0041] Optionally, the user program includes an MCU running program that implements user-specific functional tasks.

[0042] Optionally, the BL program includes an MCU operating program that implements functions such as updating and downloading of MCU user programs and testing of basic chip functions.

[0043] Optionally, the storage location of the BL data structure includes non-volatile memory such as NVM, ROM (Read-Only Memory), OTP (One-Time Programmable Memory), etc.

[0044] Optionally, combined Figure 2 As shown, the BL data structure includes: a BL startup data segment, a program download function segment, a communication interface segment, a basic function test segment, a BL startup data backup segment, a verification basic information segment and a code verification result data segment.

[0045] In this embodiment, the BL data structure includes a BL startup data backup segment, a verification basic information segment, and a code verification result data segment. According to the verification basic information segment and the code verification result data segment, the integrity of the BL startup data backup segment waiting for the verification code segment in the BL data structure can be verified. Only when the verification result is verified, can the BL function status word be updated and the backup BL startup data be written, so as to realize the safe switching of the MCU from the user program to the BL program.

[0046] Optionally, the BL data structure also includes: user area data.

[0047] Combination Figure 2 As shown, taking the BL data structure stored in NVM as an example, according to the NVM starting address, the user area starting address, the basic function test segment starting address, the communication interface segment starting address, the program download function segment starting address, the code verification result data segment starting address, the verification basic information segment starting address, the BL startup data backup segment starting address and the NVM end address, the corresponding BL data structure can be found in the NVM.

[0048] Optionally, the program download function segment, the communication interface segment and the basic function test segment are code data for implementing different functions of the BL, and the functions implemented by each segment code are independent of each other.

[0049] In this embodiment, for the program download function segment, the communication interface segment and the basic function test segment, each function segment is an independent module and can be developed, tested and maintained separately without affecting other modules. When a specific function needs to be updated or repaired, only the corresponding function segment needs to be operated without changing other parts. The risk of introducing the impact on other functions due to modifying one function is reduced. Each independent function segment can be security-checked separately to ensure the security of each part. In addition, taking the program download function segment as an example, for multiple program download function segments that implement different functions, each program download function segment is also independent of each other. The communication interface segment and the basic function test segment can also be set as multiple independent function segments. For example, for the segmentation of multiple communication interfaces, deleting any interface code data does not affect the normal use of other interfaces; deleting the basic function test segment data of the chip does not affect the normal use of other segmented functions.

[0050] Optionally, the program download function segment includes a secure download function and a general download function.

[0051] In this embodiment, two different download functions improve the flexibility of the download method, so that BL can adapt to different security requirements and application scenarios. Developers can choose to use the secure download or general download function according to the specific needs of the application, or support both at the same time to provide more choices. The secure download function refers to a download method in which the user program data is ciphertext, and the ciphertext is decrypted using the secure download method and then written into the non-volatile storage. The ordinary download function refers to a download method in which the user program data is plaintext, and the data is directly written into the non-volatile storage using the ordinary download method. The secure download function provides the necessary security protection, while the general download function provides efficiency without the need for a high security level. Therefore, the secure download function and the general download function included in the program download function segment provide BL with a wide range of application adaptability and flexibility, which can adapt to various application requirements from high security requirements to rapid deployment, while ensuring that the requirements of different security levels can be met.

[0052] Optionally, the communication interface segment includes: USB (Universal Serial Bus), UART (Universal Asynchronous Receiver and Transmitter), SPI (Serial Peripheral Interface), I2C (Inter-Integrated Circuit), SWI (Single-Wire Interface), GPIO (General-Purpose Input / Output), RF (Radio Frequency Interface), etc. One or more communication interface function implementations. The codes for each communication interface implementation are stored in segments and do not affect each other.

[0053] Optionally, the BL startup data segment and the BL startup data backup segment have the same data, and the startup data includes data such as an interrupt vector table and a stack top address of the BL.

[0054] In this embodiment, based on security considerations, the data to be operated should be reduced as much as possible to implement the function of switching back to BL. Therefore, when designing the startup data of BL, only the interrupt vector table, the stack top address, etc. of BL can be included without adding additional code data. After the BL function status word is updated, the data of the BL startup data backup segment needs to be written into the startup address, so as to restart the program to switch from the user program to the BL program.

[0055] Optionally, in combination with what is shown in Table 1, the basic information segment for verification includes: BL function status word, number of code segments, starting address of each segment code, starting address of verification data corresponding to each segment code, and other information.

[0056] Table 1

[0057]

[0058] In this embodiment, the verification basic information segment includes the number of code segments of the program download function segment, the communication interface segment, and the basic function test segment, as well as the starting address of each segment code and the starting address of the verification data corresponding to each segment code. The verification basic information segment includes the starting address of each segment code. According to the starting address of the segment code, the corresponding data can be determined in the program download function segment, the communication interface segment, and the basic function test segment. For example, in combination Figure 2As shown in Table 1, according to the starting address of the BL startup data backup segment, the storage location of the BL startup data backup segment can be determined; according to the starting address of segment 1, the storage location of the basic function test segment can be determined; according to the starting addresses of segments 2 to 1+n, the storage location of the n types of communication interface segments can be determined; according to the starting addresses of segments 2+n and 3+n, the storage locations of the secure download code segment and the general download code segment in the program download function segment can be determined. Then, according to the starting address of the verification result data of each segment, the verification result data corresponding to each segment can be determined in the code verification result data segment.

[0059] Optionally, the BL function status word is used to indicate the function module information supported by the current BL. The function module information includes whether a test part is included, which types of communication interfaces, a secure download part, and a normal download part.

[0060] Optionally, as shown in Table 2, the code verification result data segment includes: the length information of the data to be verified and the verification result data information of each segmented data.

[0061] Table 2

[0062]

[0063] Optionally, the verification result data information is obtained based on a preset verification method. The preset verification method includes one or more algorithms such as CRC (Cyclic Redundancy Check), DES (Data Encryption Standard), AES (Advanced Encryption Standard), HASH (Hash algorithm), RSA (Rivest-Shamir-Adleman), etc.

[0064] Optionally, obtaining BL code verification data includes: obtaining, according to a verification basic information segment in a BL data structure, a function state supported by BL, the number of code segments of BL, a starting address at which each segment code is stored, and a starting address of verification data corresponding to each segment code; determining, according to the starting address of verification data corresponding to each segment code, verification result data information of each segment code in a code verification result data segment; and using the function state supported by BL, the number of code segments of BL, the starting address at which each segment code is stored, and the verification result data information of each segment code as BL code verification data.

[0065] In this embodiment, the functional status supported by the BL can be determined according to the BL functional status word in the verification basic information segment. In combination with Table 1, the number of code segments of the BL, the starting address where each segment code is stored, and the starting address of the verification data corresponding to each segment code can also be directly determined in the verification basic information segment. Then, according to the starting address of the verification data corresponding to each segment code, the verification result data information of each corresponding segment code can be determined according to the address information in the code verification result data segment.

[0066] Optionally, the code segments to be verified in the BL data structure are verified according to the BL code verification data, including: determining the number of code segments to be verified supported by the BL according to the functional status supported by the BL and the number of code segments of the BL; obtaining data information of each code segment to be verified according to the starting address where each segment code is stored; verifying the data information of each code segment to be verified based on a preset verification method, and determining the verification result according to the verification result data information of each segment code.

[0067] Combination Figure 3 As shown, the embodiment of the present disclosure provides another method for switching a user program to a BL program, including:

[0068] S301, the processor obtains the function status supported by the BL, the number of code segments of the BL, the starting address of each segment code and the starting address of the verification data corresponding to each segment code according to the verification basic information segment in the BL data structure.

[0069] S302, the processor determines the verification result data information of each segment code in the code verification result data segment according to the verification data start address corresponding to each segment code.

[0070] S303, the processor uses the function status supported by the BL, the number of code segments of the BL, the starting address where each segment code is stored, and the verification result data information of each segment code as BL code verification data.

[0071] S304: The processor determines the number of to-be-verified code segments supported by the BL according to the functional status supported by the BL and the number of code segments of the BL.

[0072] S305: The processor obtains data information of each code segment to be verified according to the starting address where each segment code is stored.

[0073] S306, the processor verifies the data information of each code segment to be verified based on a preset verification method, and determines the verification result according to the verification result data information of each segment code.

[0074] S307: When the verification result passes, the processor updates the BL function status word.

[0075] S308, after the BL function status word is updated, the processor writes the BL startup data backed up in the BL data structure into the startup address to restart the program to switch from the user program to the BL program.

[0076] In this embodiment, according to the BL code verification data, the code segment to be verified can be determined in the BL data structure, and then each code segment to be verified is verified based on a preset verification method, and finally the verification result is determined by referring to the verification result data information of each code segment to be verified. Among them, the preset verification method is the same as the method for obtaining the verification result data information, including: CRC, DES, AES, HASH, RSA and other one or more algorithms.

[0077] Optionally, the code segment to be verified includes a BL startup data backup segment, one or more program download function segments, one or more communication interface segments, and a basic function test segment.

[0078] In this embodiment, the key parts of the code segment BL to be verified need to be checked for integrity and security to ensure the reliability and security of BL when performing its functions. The BL startup data backup segment includes key data required for BL startup, such as interrupt vector table and stack top address. The verification of the BL startup data backup segment can ensure that BL can be correctly loaded and executed during system restart or update. The program download function segment includes a secure download function and a general download function, which are used to download user program data to a non-volatile memory. The verification of the program download function segment can ensure the security of the download process and the integrity of the data, and prevent the injection of malicious software. The communication interface segment implements the function of communicating with external devices, including USB, UART, SPI, I2C, etc. The verification of the communication interface segment can ensure that BL can safely and reliably receive and send data through these interfaces. The basic function test segment is used to perform basic function tests of the chip, such as hardware diagnosis and performance testing. The verification of the basic function test segment can ensure that the basic functions of the chip still work normally after the system is started or updated. In addition, for the program download function segment and the communication interface segment, according to different actual application situations, multiple program download function segments and communication interface segments can be verified. Therefore, taking the BL startup data backup segment, one or more program download function segments, one or more communication interface segments, and the basic function test segment as the code segments to be verified can ensure the security and reliability of the BL and improve the stability of the system operation.

[0079] Optionally, the data information of each code segment to be verified is verified, including: verifying the BL startup data backup segment, the program download function segment and the communication interface segment to determine whether the conditions for writing back the BL startup data are met; if the conditions for writing back the BL startup data are met, verifying the basic function test segment; if the conditions for writing back the BL startup data are not met, returning an error status word.

[0080] In this embodiment, the BL startup data backup segment, the program download function segment and the communication interface segment are verified to determine whether the BL has the ability to successfully download the user program, that is, whether the condition for writing back the BL startup data is met. If the condition for writing back the BL startup data is met, the basic function test segment is verified. If the condition for writing back the BL startup data is not met, the corresponding error status word is returned according to the verification situation. Among them, if the condition for writing back the BL startup data is not met, the corresponding error status word is returned according to the verification situation, including: returning the status word corresponding to the BL startup data backup segment verification error, returning the status word corresponding to all program download function segment verification errors, and returning the status word corresponding to all communication interface segment verification errors. These three situations of returning the corresponding error status word.

[0081] Optionally, when the BL startup data backup segment, at least one program download function segment, and at least one communication interface segment pass the verification in any order, the condition for writing back the BL startup data is met; otherwise, the condition for writing back the BL startup data is not met. In a specific implementation, for the BL startup data backup segment, at least one program download function segment, and at least one communication interface segment, these three types of verification are verified in any order, and six sequential verification situations can be selected, of which three sequential verification situations are as follows: First, it is possible to select to first perform the BL startup data backup segment verification, followed by at least one program download function segment verification, and then at least one communication interface segment verification; second, it is possible to select to first perform at least one program download function segment verification, followed by the BL startup data backup segment verification, and then at least one communication interface segment verification; third, it is possible to select to first perform at least one communication interface segment verification, followed by at least one program download function segment verification, and then at least one BL startup data backup segment verification. In summary, for the above three types of verification, the verification can be performed in any order, and six sequential verification conditions can be selected. If the verification is passed in any order, the condition for writing back the BL startup data is met, otherwise, the condition for writing back the BL startup data is not met.

[0082] In this embodiment, the BL startup data backup segment verification is passed, which can ensure that the backed-up BL startup data is complete and has not been tampered with. This is the basic prerequisite for performing the write-back operation. If the startup data is damaged or unreliable, the write-back operation may cause the system to fail to start normally or run in an unstable state. At least one program download function segment verification is passed, which can ensure that at least one program download function is available. This is a necessary condition for system updates and maintenance. If all download functions fail, the system will not be able to receive new user programs or firmware, and thus will not be able to perform necessary updates. At least one communication interface segment verification is passed, which can ensure that at least one communication interface is available. The communication interface is the key to the interaction between the system and the outside world. If all communication interfaces fail, the system will not be able to receive external instructions or data, nor can it send data to external devices. Therefore, only when the above conditions are met, that is, the BL startup data backup segment verification, at least one program download function segment verification, and at least one communication interface segment verification are verified in any order, can it be determined that the conditions for writing back the BL startup data are met, and then the basic function test segment is verified. If a BL startup data backup segment verification error, a verification error of all program download function segments, or a verification error of all communication interface segments occurs during the verification of the BL startup data backup segment, the program download function segment, and the communication interface segment in any order, then the corresponding error status word is returned according to the verification error situation, and the verification process is stopped to improve the verification efficiency.

[0083] Optionally, the verification result passing means that the basic function test section verification passes.

[0084] In this embodiment, when the conditions for writing back the BL startup data are met, the basic function test segment is verified. Verifying the basic function test segment is an important step to ensure that the entire system can operate normally after updating or switching back to the user program. Verification of the basic function test segment can determine that the hardware is working properly and detect potential hardware failures. When the basic function test segment is also verified and passed, the BL function status word is updated, and after the update is completed, the BL startup data backed up in the BL data structure is written to the startup address according to the BL startup data backup segment. After writing is completed, the chip program can be restarted to switch the user program to the BL program.

[0085] Combination Figure 4 As shown, the embodiment of the present disclosure provides another method for switching a user program to a BL program, including:

[0086] S401: The processor obtains BL code verification data based on the BL data structure.

[0087] S402, the processor obtains data information of each code segment to be verified according to the BL code verification data; the code segment to be verified includes a BL startup data backup segment, one or more program download function segments, one or more communication interface segments, and a basic function test segment.

[0088] S403: The processor verifies the BL startup data backup segment.

[0089] S404, the processor determines whether the BL startup data backup segment has passed the verification, if so, executes S405, if not, executes S412.

[0090] S405: The processor verifies one or more program download function segments.

[0091] S406, the processor determines whether at least one program download function segment has passed the verification, if so, executes S407, if not, executes S413.

[0092] S407: The processor verifies one or more communication interface segments.

[0093] S408, the processor determines whether at least one communication interface segment has passed the verification, if so, executes S409, if not, executes S414.

[0094] S409: The processor verifies the basic function test segment.

[0095] S410, when the basic function test section passes verification, the processor updates the BL function status word.

[0096] S411, the processor writes the BL startup data backed up in the BL data structure into the startup address to restart the program to switch from the user program to the BL program.

[0097] S412, the processor returns a status word corresponding to the BL startup data backup segment check error.

[0098] S413, the processor returns the status word corresponding to all program download function segment verification errors.

[0099] S414, the processor returns the status word corresponding to all communication interface segment check errors.

[0100] In this embodiment, the BL startup data backup segment check is performed first, followed by at least one program download function segment check, and then followed by at least one communication interface segment check. This check is one of the above six sequentially ordered check situations.

[0101] Combination Figure 5As shown, the embodiment of the present disclosure provides a device 500 for switching a user program to a BL program, including: a parsing module 501, a verification module 502, an update module 503 and a rewrite module 504. The parsing module 501 is configured to obtain BL code verification data based on the BL data structure. The verification module 502 is configured to verify the code segment to be verified in the BL data structure according to the BL code verification data. The update module 503 is configured to update the BL function status word when the code segment to be verified passes the verification. The rewrite module 504 is configured to write the backed-up BL startup data to the startup address after the update is completed, so as to restart the program to realize the switch from the user program to the BL program.

[0102] The device for switching a user program to a BL program provided by the embodiment of the present disclosure can be used as a secure write boot data module to improve the reliability of the behavior of switching the user program to the BL program.

[0103] Combination Figure 6 As shown, an embodiment of the present disclosure provides a device 600 for switching a user program to a BL program, including a processor 700 and a memory 701. Optionally, the device may also include a communication interface 702 and a bus 703. The processor 700, the communication interface 702, and the memory 701 may communicate with each other through the bus 703. The communication interface 702 may be used for information transmission. The processor 700 may call the logic instructions in the memory 701 to execute the method for switching a user program to a BL program in the above embodiment.

[0104] In addition, the logic instructions in the memory 701 described above may be implemented in the form of software functional units and when sold or used as independent products, may be stored in a computer-readable storage medium.

[0105] The memory 701 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 700 executes the function application and data processing by running the program instructions / modules stored in the memory 701, that is, the method of switching the user program to the BL program in the above embodiment is implemented.

[0106] The memory 701 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 701 may include a high-speed random access memory and may also include a non-volatile memory.

[0107] The embodiments of the present disclosure provide a chip, including: a chip body, and the above-mentioned device for switching a user program to a BL program. The device for switching a user program to a BL program is installed in the chip body. The installation relationship described here is not limited to placement inside the chip, but also includes installation connections with other components of the chip, including but not limited to physical connections, electrical connections, or signal transmission connections. It can be understood by those skilled in the art that the device for switching a user program to a BL program can be adapted to a feasible chip body, thereby realizing other feasible embodiments.

[0108] An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above method of switching a user program to a BL program.

[0109] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0110] The above description and accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the technical solutions recorded in this application. As used in the technical solutions recorded in this application, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0111] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods for each specific application to implement the described functions, but such implementations should not be considered to exceed the scope of the embodiments of the present disclosure. The technicians may clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above may refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0112] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0113] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A method for switching a user program to a BL program, characterized in that: include: Based on the BL data structure, obtain BL code verification data; According to the BL code verification data, the code segment to be verified in the BL data structure is verified to obtain the verification result; If the verification result passes, the BL function status word is updated; After the BL function status word is updated, the BL startup data backed up in the BL data structure is written to the startup address to restart the program to switch from the user program to the BL program.

2. The method according to claim 1, characterized in that The BL data structure includes: BL startup data segment, program download function segment, communication interface segment, basic function test segment, BL startup data backup segment, verification basic information segment and code verification result data segment.

3. The method according to claim 2, characterized in that Obtain BL code verification data, including: According to the verification basic information segment in the BL data structure, obtain the function status supported by the BL, the number of code segments of the BL, the starting address of each segment code storage and the starting address of the verification data corresponding to each segment code; According to the verification data starting address corresponding to each segment code, in the code verification result data segment, the verification result data information of each segment code is determined; The function status supported by BL, the number of code segments of BL, the starting address of each segment code and the verification result data information of each segment code are used as BL code verification data.

4. The method according to any one of claims 1 to 3, characterized in that: The BL code verification data includes the function status supported by the BL, the number of code segments of the BL, the starting address of each segment code storage and the verification result data information of each segment code; According to the BL code verification data, the code segment to be verified in the BL data structure is verified, including: Determine the number of code segments to be verified supported by the BL according to the functional status supported by the BL and the number of code segments of the BL; According to the starting address of each segment code, the data information of each code segment to be verified is obtained; Based on the preset verification method, the data information of each code segment to be verified is verified, and the verification result is determined according to the verification result data information of each segment code.

5. The method according to claim 4, characterized in that The code segments to be verified include a BL startup data backup segment, one or more program download function segments, one or more communication interface segments, and a basic function test segment; Verify the data information of each code segment to be verified, including: Verify the BL startup data backup segment, program download function segment, and communication interface segment to determine whether the conditions for writing back the BL startup data are met; When the conditions for writing back the BL startup data are met, the basic function test section is verified; If the conditions for writing back the BL startup data are not met, an error status word is returned.

6. The method according to claim 5, characterized in that If the BL startup data backup segment, at least one program download function segment, and at least one communication interface segment pass verification in any order, the BL startup data writing back condition is met; otherwise, the BL startup data writing back condition is not met.

7. The method according to claim 5, characterized in that The verification result is passed when the basic function test section is verified.

8. A device for switching a user program to a BL program, characterized in that: include: A parsing module is configured to obtain BL code verification data based on the BL data structure; A verification module is configured to verify the code segment to be verified in the BL data structure according to the BL code verification data; An update module is configured to update the BL function status word when the code segment to be verified passes the verification; The rewriting module is configured to write the backed-up BL startup data into the startup address after the update is completed, so as to restart the program to switch from the user program to the BL program.

9. A device for switching a user program to a BL program, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the method for switching a user program to a BL program according to any one of claims 1 to 7 when running the program instructions.

10. A chip, characterized in that: include: Chip body; The device for switching a user program to a BL program according to claim 8 or 9 is installed in the chip body.