Application deployment method, boot device, single-chip microcomputer and medium
By using a boot device to erase the microcontroller's memory and protect specified statements, the security issues in the deployment process of microcontroller applications are resolved, and the proper deployment and secure startup of applications are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NATIONZ TECH INC
- Filing Date
- 2022-02-25
- Publication Date
- 2026-05-12
AI Technical Summary
The lack of software-level protection mechanisms in the deployment of applications makes microcontrollers vulnerable to being cracked.
The Boot device erases the memory partitions excluding the Boot area, downloads and deploys the application, and performs execution protection on specified statement types, specified functions and comparison operations during the process, including encrypted download and integrity verification.
This effectively prevents the application deployment process from being compromised, thus ensuring the security of the microcontroller.
Smart Images

Figure CN116702098B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of microcontrollers, and particularly to an application deployment method, a boot device, a microcontroller, and a computer-readable storage medium. Background Technology
[0002] In the Internet of Things (IoT) field, microcontroller units (MCUs) can provide effective protection for business privacy and data security through their hardware-level security mechanisms. However, their protection capabilities at the software application level are relatively weak. For example, when deploying applications, MCUs lack detection and protection mechanisms for the deployment process, which makes them vulnerable to being cracked during application deployment. Summary of the Invention
[0003] The purpose of this invention is to provide an application deployment method, a boot device, a microcontroller, and a computer-readable storage medium, which can provide targeted protection for specific statements that the boot device needs to execute during the application deployment process, thereby effectively preventing smart cards from being cracked during the application deployment process and effectively ensuring the security of smart cards.
[0004] To address the aforementioned technical problems, this invention provides an application deployment method applied to a Boot device, the method comprising:
[0005] When an application is detected not to be downloaded, the memory partitions in memory, excluding the Boot area, are erased.
[0006] When the memory erasure is completed, the application is downloaded, and when the application download is complete, the application is deployed in the memory.
[0007] When the application deployment is complete, navigate to the application to launch it;
[0008] During the memory erasure, application download, and application deployment, execution protection is provided for statements corresponding to specified statement types, specified functions, and comparison operations.
[0009] Preferably, the process of downloading the application includes:
[0010] A download key is generated using a random number, and the application is downloaded in encrypted form using the download key.
[0011] Upon receiving the application, an integrity check is performed on the application, and if the check passes, the application is deemed to have been downloaded successfully.
[0012] Preferably, before detecting that the application has not been downloaded, it also includes:
[0013] Extract the download flag from the preset flag list and invert the download flag;
[0014] Determine whether the processed download flag indicates that the application has not been downloaded;
[0015] If so, then the application is determined not to have been downloaded;
[0016] Accordingly, before jumping to the application, the following is also included:
[0017] Update the download flag to indicate that the application has been downloaded, and then perform the inversion process on the updated download flag.
[0018] Save the processed download flag to the preset flag list.
[0019] Preferably, before jumping to the application, it further includes:
[0020] Extract the sealing flag and the debugging disable flag from the preset flag list; the sealing flag is used to disable user mode, and the debugging disable flag is used to disable debugging function;
[0021] Set the sealing flag and the debugging disable flag to preset effective values and perform the inversion process, and save the processed sealing flag and debugging disable flag to the preset flag list.
[0022] Preferably, before detecting that the application has not been downloaded, it also includes:
[0023] When the microcontroller is detected to be powered on for the first time, the preset MPU partition information is read; the MPU partition information includes the location and operation permission information of all partitions in the memory;
[0024] Configure all partitions in memory using the MPU partition information.
[0025] Preferably, the memory erasure of partitions other than the Boot area in memory includes:
[0026] The memory of the partition is erased, and after erasure, it is checked whether the memory has been restored to its initial value.
[0027] If so, then confirm that the memory erasure has been completed.
[0028] Preferably, the execution protection for statements corresponding to specified statement types, specified functions, and comparison operations includes:
[0029] When the current statement is executed, determine the type of the current statement;
[0030] If the current statement is a conditional statement, then the variables and condition values in the current statement are compared to obtain a first comparison result, and the variables and condition values are inverted and then compared to obtain a second comparison result; if the first comparison result and the second comparison result are determined to be the same, the next statement is executed;
[0031] If the current statement is a loop statement, then extract the judgment condition value in the current statement, execute the current statement and record the execution round; when exiting the execution of the current statement, determine whether the judgment condition value and the execution round are the same as the corresponding first preset value; if so, execute the next statement;
[0032] If the current statement is a specified statement, then the execution is delayed according to a randomly generated waiting time, and the current statement is executed after the delay ends; and / or, when the execution of the current statement is completed, the execution is delayed according to the waiting time, and the next statement is executed after the delay ends.
[0033] If the current statement is the specified function, then the return value of the current statement is validated, and the next statement is executed after the validation is completed; the validation value used for the validation is a non-contiguous value and its length is greater than a second preset value;
[0034] If the current statement is the comparison operation, then the comparison function in the preset algorithm library is called to perform the comparison operation, and the next statement is executed after the comparison operation is completed.
[0035] The present invention also provides a boot device, comprising:
[0036] The erase module is used to erase the memory partitions other than the Boot area when it is detected that the application has not been downloaded.
[0037] The download and deployment module is used to download the application when the memory erasure is completed, and to deploy the application in the memory when the application download is completed.
[0038] The program startup module is used to jump to the application when the application deployment is completed, so as to start the application;
[0039] An execution protection module is used to perform execution protection on statements corresponding to specified statement types, specified functions, and comparison operations during the memory erasure, application download, and application deployment.
[0040] The present invention also provides a microcontroller, comprising:
[0041] Memory, used to store computer programs;
[0042] A processor for implementing the application deployment method as described above when executing the computer program.
[0043] The present invention also provides a computer-readable storage medium storing computer-executable instructions, which, when loaded and executed by a processor, implement the application deployment method described above.
[0044] This invention provides an application deployment method applied to a boot device. The method includes: when an application is detected not to be downloaded, erasing a memory partition in memory excluding the boot area; when the memory erasure is complete, downloading the application, and when the application download is complete, deploying the application in memory; when the application deployment is complete, jumping to the application to start the application; and during the memory erasure, application download, and application deployment, execution protection is provided for statements corresponding to specified statement types, specified functions, and comparison operations.
[0045] As can be seen, when the Boot device in this invention determines that the application has not been downloaded, it first erases the memory partitions other than the Boot area to prevent malicious code or other code remaining in memory from affecting the application deployment, thus ensuring that the application can be properly deployed in the microcontroller's memory. Afterward, the Boot device further downloads and deploys the application sequentially. During the memory erasure, application download, and application deployment processes, the Boot device further judges each statement to be executed and performs targeted execution protection on specific statements corresponding to specified statement types, functions, and comparison operations. This effectively prevents attackers from maliciously guiding the Boot device to execute incorrect statements during the application deployment stage, thereby preventing the microcontroller from being compromised. This effectively ensures the security of the microcontroller during the application deployment stage. This invention also provides a Boot device, a microcontroller, and a computer-readable storage medium, which have the aforementioned beneficial effects. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0047] Figure 1 A flowchart illustrating an application deployment method provided in an embodiment of the present invention;
[0048] Figure 2 This is a structural block diagram of a boot device provided in an embodiment of the present invention. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] In related technologies, microcontrollers lack detection and protection mechanisms during application deployment, making them vulnerable to being compromised during the deployment process. Therefore, this invention provides an application deployment method that provides targeted protection for specific statements executed by the boot device during application deployment, effectively preventing microcontroller compromise and ensuring its security. Please refer to [reference needed]. Figure 1 , Figure 1 This is a flowchart illustrating an application deployment method provided in an embodiment of the present invention. The method is applied to a boot device in a microcontroller, which is typically used to guide the installation and startup of a microcontroller application. The method may include:
[0051] S101. When it is detected that the application has not been downloaded, the memory partitions in memory other than the Boot area are erased.
[0052] After startup, the boot device first checks whether an application has been downloaded and deployed in memory. If it finds that the application has not been downloaded and deployed, it will automatically begin application deployment preparation, i.e., begin memory erasure. This embodiment of the invention does not limit the specific application; any application that can be deployed to the microcontroller is acceptable, and relevant microcontroller technologies can be referenced. This embodiment of the invention also does not limit the method by which the boot device detects application download status. For example, it can scan the memory to determine whether the application file exists in memory; alternatively, it can determine whether the application has been downloaded by reading a preset flag. The flag is used to record whether a task has been executed or to indicate whether a certain operation is allowed. For example, for application downloads, a download flag can be set to indicate whether the application has been downloaded. In this embodiment of the invention, to improve detection efficiency, the boot device can determine whether the application has been downloaded by reading the download flag. This embodiment of the invention does not limit the specific form of the download flag; relevant flag technologies can be referenced, and the flag can be set according to actual needs.
[0053] Furthermore, to ensure proper application deployment, Boot will erase the memory partitions other than the Boot area. This is to prevent residual code in memory from damaging application files, such as malicious code or incompletely removed legacy code. This embodiment of the invention does not limit the specific process of memory erasure; relevant memory technologies can be referenced. Of course, to ensure the effectiveness of memory erasure, a secondary check can be performed on the erase results after the erasure is complete. This secondary check step can be set according to actual application requirements.
[0054] S102. When the memory erasure is completed, the application is downloaded, and when the application download is complete, the application is deployed in memory.
[0055] After memory erasure is complete, the application download process can be executed, and the application can be deployed after the download is finished. This invention does not limit the specific process of application download; relevant microcontroller technologies can be referenced, such as setting encrypted download or setting application integrity checks. Similarly, this invention does not limit the specific process of application deployment; relevant microcontroller technologies can also be referenced.
[0056] S103. When the application deployment is complete, jump to the application to start the application.
[0057] After deployment is complete, the boot process of the boot device is essentially finished, and it can then jump to the application to start it. This embodiment of the invention does not limit the specific steps for jumping to the application; relevant microcontroller technologies can be referenced. Of course, before jumping to the application, the boot device can further perform configuration operations such as setting and backing up flags, which can be set according to actual application requirements.
[0058] S104. When performing memory erasure, application download, and application deployment, execution protection is provided for statements corresponding to specified statement types, specified functions, and comparison operations.
[0059] In this embodiment of the invention, the boot device performs execution protection on the code statements to be executed throughout the entire application deployment process. This effectively prevents attackers from maliciously guiding the boot device to execute incorrect statements during the application deployment stage, causing the boot device to malfunction and thus leading to the microcontroller being compromised. It should be noted that, for ease of explanation, this embodiment only specifically describes the memory erasure, application download, and application deployment steps in application deployment. However, in practical applications, the boot device may also need to perform other steps during application deployment, and in the process of performing these other steps, the device will also perform execution protection on the code to be executed.
[0060] Furthermore, the Boot device in this embodiment of the invention primarily performs execution protection on statements corresponding to specified statement types, specified functions, and comparison operations. It is understood that the execution protection steps for different statement types may vary. Additionally, it is understood that the statements to be executed by the Boot device may contain multiple objects requiring execution protection; for example, the statement may contain both a specified statement type and a specified function. In this case, the Boot device can combine and execute the execution protection content corresponding to these objects. This embodiment of the invention does not limit the execution order of the various execution protection steps by the Boot device. For example, it can process the corresponding execution protection steps according to the nesting order of the protected objects in the statement, or it can process these execution protection steps according to a preset priority order, which can be set according to actual application requirements.
[0061] Furthermore, the embodiments of the present invention do not limit the specific type of statement. For example, it can be a conditional statement (if statement), a loop statement, or a special statement manually specified by the user (such as important judgment, calculation, and jump statements). It is understood that before executing a statement, the boot device will determine whether the statement belongs to the above-mentioned specified statement type, and then jump to the execution protection content corresponding to each type.
[0062] This invention does not limit the protection provided for conditional statements. Since conditional statements involve conditional judgments, targeted protection can be implemented for the conditional judgment steps. Specifically, the variables and judgment condition values in the conditional statement can be compared normally to obtain a first comparison result. Simultaneously, both the variable and judgment condition values are inverted, and a second comparison is performed to obtain a second comparison result. Finally, it is determined whether the first and second comparison results are the same. If they are the same, the process proceeds to the next statement; if they are different, the process continues, and corresponding error information is output. The advantage of this double comparison is that it effectively avoids comparison errors caused by incorrect or tampered variable or judgment condition values, effectively ensuring the secure execution of conditional statements.
[0063] This invention does not limit the protection measures for loop statements. Since loop statements involve the number of execution iterations and the conditional statements within the loop structure, targeted protection can be implemented for the execution iterations and conditional statements. Specifically, the conditional values in the loop statement can be extracted, and the current statement can be executed while recording the execution iteration. When exiting the execution of the loop statement, it can be determined whether the conditional values and execution iteration are the same as the corresponding first preset values. If they are the same, the next statement is executed; if they are different, the next statement is not processed, and corresponding error information can be output. In other words, the number of iterations a loop statement should perform and the normal conditional values can be pre-recorded, thereby avoiding premature exits caused by modifications to the loop statement and effectively ensuring the safe execution of the loop statement.
[0064] The embodiments of this invention are not limited to the execution protection content of the specified statement. To increase the difficulty of malicious cracking, random delays can be made before, after, or both before and after the execution of the specified statement. Of course, the specified statement may also have other execution protection content, which can be set according to actual application needs.
[0065] Furthermore, this embodiment of the invention does not limit the specific function to a particular one, and can be set according to actual application requirements. To detect the execution status of the function, the function executed by the Boot device should have a return value, so that the execution status of the function can be determined based on the return value of the function statement. It should be noted that, to ensure the effectiveness of the detection, the return value of the function should avoid using data with a length of one bit, and should instead use longer and non-contiguous data. This embodiment of the invention does not limit the specific length of the function return value, which should be at least greater than one bit, and can be set according to actual application requirements. It is understood that the function return value should have a corresponding checksum, and the data requirement for this checksum is the same as that of the function return value, that is, it should be non-contiguous and longer data.
[0066] Furthermore, this embodiment of the invention does not limit the protection measures for the comparison operation. To ensure the safe and effective execution of the comparison operation, this embodiment can call a comparison function with a higher security level from a preset function library to perform the comparison operation. This embodiment of the invention does not limit the specific comparison function and can be set according to actual application needs.
[0067] In one possible scenario, execution protection for statements corresponding to specified statement types, specified functions, and comparison operations could include:
[0068] Step 11: When executing the current statement, determine the type of the current statement;
[0069] Step 12: If the current statement is a conditional statement, compare the variables and condition values in the current statement to obtain the first comparison result, invert the variables and condition values and then compare them to obtain the second comparison result; if the first comparison result and the second comparison result are the same, execute the next statement; if the first comparison result and the second comparison result are different, output the corresponding alarm information.
[0070] Step 13: If the current statement is a loop statement, extract the judgment condition value in the current statement, execute the current statement and record the execution round; when exiting the execution of the current statement, check whether the judgment condition value and execution round are the same as the corresponding first preset value; if yes, execute the next statement; if no, output the corresponding alarm information.
[0071] Step 14: If the current statement is a specified statement, then delay according to the randomly generated waiting time, and execute the current statement after the delay ends; and / or, when the execution of the current statement is completed, delay according to the waiting time, and execute the next statement after the delay ends.
[0072] Step 15: If the current statement is a specified function, then validate the return value of the current statement and execute the next statement after the validation is completed; the validation value used for validation is a non-contiguous value and its length is greater than the second preset value;
[0073] Step 16: If the current statement is a comparison operation, call the comparison function in the preset algorithm library to perform the comparison operation, and execute the next statement after the comparison operation is completed.
[0074] It should be noted that the embodiments of the present invention do not limit the specific values of the first preset value and the second preset value, wherein the second preset value is at least greater than 1 bit and can be set according to actual application requirements.
[0075] Based on the above embodiments, when the Boot device of the present invention determines that the application has not been downloaded, it first erases the memory partitions in the memory other than the Boot area to avoid the impact of malicious code or other code remaining in the memory on the application deployment, so as to ensure that the application can be properly deployed in the microcontroller memory. After that, the Boot device will further download and deploy the application in sequence. During the process of memory erasure, application download and application deployment, the Boot device will further determine each statement to be executed, and perform targeted execution protection on specific statements corresponding to specified statement types, specified functions and comparison operations. This can effectively prevent attackers from maliciously guiding the Boot to execute incorrect statements during the application deployment stage, which could lead to the microcontroller being cracked. This can effectively protect the security of the microcontroller during the application deployment stage.
[0076] Based on the above embodiments, to further improve the effectiveness of memory erasure, the erasure status can be detected after the erasure is completed. In one possible scenario, erasing memory partitions other than the Boot area may include:
[0077] S201. Erase the partition's memory and check if the memory has been restored to its initial value after erasure. If yes, proceed to step S202; otherwise, erase the partition again.
[0078] S202. If yes, then confirm that the memory erase is complete.
[0079] Specifically, when all the data in memory is in hexadecimal "FF", it can be determined that the partition has been completely erased.
[0080] Based on the above embodiments, to further enhance the security of application downloads and ensure the integrity and validity of the applications, encrypted download methods can be used, and integrity checks can be performed on the downloaded applications. In one possible scenario, downloading an application includes:
[0081] S301. Generate a download key using a random number, and use the download key to encrypt and download the application.
[0082] It should be noted that the embodiments of the present invention do not limit the specific steps of encrypted downloading; relevant technologies of the application can be referred to. Since the data requirements for the download key are related to the specific download method, a suitable download key can be selected based on the actual encrypted download method used, as long as the key is generated using random numbers.
[0083] S302. Upon receiving the application, perform an integrity check on the application, and determine that the application download is complete if the check passes.
[0084] It should be noted that the embodiments of the present invention do not limit the specific algorithm used for integrity verification. For example, the CRC algorithm can be used. The CRC (Cyclic Redundancy Check) algorithm is a channel coding technique that generates a short, fixed-length checksum based on data such as network data packets or computer files. It is mainly used to detect or verify errors that may occur after data transmission or storage. The present invention also does not limit the CRC checksum length; for example, it can be 16 bits, and can be set according to actual application requirements.
[0085] Based on the above embodiments, to enhance the security of flag management, important flags involved in the application deployment phase can be inverted and backed up to ensure the integrity of these flags. In one possible scenario, before detecting that the application has not been downloaded, the following may also be included:
[0086] S401. Extract the download flag from the preset flag list and invert the download flag.
[0087] In this embodiment of the invention, a preset flag list is used to store important flags involved in the application deployment phase. This embodiment does not limit the specific flags to be saved; for example, they can be download flags, blocking flags for disabling user mode, and debug disable flags for disabling debugging functions, etc., and can be selected according to actual application needs. Furthermore, the preset flag list stores each flag using an inverted backup method. Specifically, the values of the flags can be inverted and saved to the list after inversion. Correspondingly, before use, the flags in the list need to be inverted to obtain normal flag values, and then operations can be performed based on normal data. Therefore, in this step, after extracting the download flag from the preset flag list, the flag needs to be inverted to obtain the normal value of the download flag.
[0088] S402. Determine whether the processed download flag indicates that the application has not been downloaded; if yes, proceed to step 403; if no, jump to the application.
[0089] It should be noted that the embodiments of the present invention do not limit the value of the download flag to indicate that the application has not been downloaded, or the value to indicate that the application has been downloaded; the value can be set according to actual application requirements.
[0090] S403. If yes, then the application has not been downloaded.
[0091] Accordingly, before jumping to the application, the following is also included:
[0092] S501. Update the download flag to indicate that the application has been downloaded, and invert the updated download flag.
[0093] S502. Save the processed download flag to the preset flag list.
[0094] Correspondingly, to enhance the security of the microcontroller, it is also necessary to restrict its other functions, such as user mode and debugging functions. Therefore, when completing application deployment, the boot device can also set the corresponding disable flags for these two functions—the sealing flag and the debug disable flag—to the active state. Similarly, after setting the active values, these two flags need to be inverted before being saved to the preset flag list.
[0095] In one possible scenario, the jump to the application may also include:
[0096] Step 21: Extract the sealing flag and the debug disable flag from the preset flag list; the sealing flag is used to disable user mode, and the debug disable flag is used to disable the debug function.
[0097] Step 22: Set the sealing flag and debugging disable flag to preset effective values and invert them, then save the processed sealing flag and debugging disable flag to the preset flag list.
[0098] It should be noted that the embodiments of the present invention do not limit the specific value of the preset effective value, and can be set according to actual application needs. Furthermore, it is understood that other important flag bits may be involved in the application deployment stage. The state adjustment process for these flag bits is similar to the state adjustment process for the download flag bit, sealing flag bit, and modulation disable flag bit described above. In addition, the timing of the state adjustment of other important flag bits may occur at any stage of the application deployment process, and not only when the application deployment is completed. Therefore, the state adjustment steps for other important flag bits can refer to the state adjustment steps for the download flag bit, sealing flag bit, and modulation disable flag bit described above, and be set according to actual application needs.
[0099] Based on the above embodiments, to ensure that the memory locations within the microcontroller cannot access each other and to restrict external users' access to each partition, operation permission information can be configured for each partition in the microcontroller's memory. In one possible scenario, before detecting that the application has not been downloaded, the following may also be included:
[0100] S601. When the microcontroller is detected to be powered on for the first time, the preset MPU partition information is read; the MPU partition information includes the location and operation permission information of all partitions in memory;
[0101] MPU (Micro Processor Unit) represents a microprocessor. This embodiment of the invention does not limit the specific content of the MPU partition information, as long as it correctly describes the specific location of each partition in memory and its corresponding operation permission information. Related technologies for MPU partitioning can be referenced.
[0102] S601: Configure all partitions in memory using the MPU partition information.
[0103] After the partition configuration is completed, the Boot device can restrict access between partitions based on the specific configuration information.
[0104] The Boot device, microcontroller, and computer-readable storage medium provided in the embodiments of the present invention are described below. The Boot device, microcontroller, and computer-readable storage medium described below can be referred to in correspondence with the application deployment method described above.
[0105] Please refer to Figure 2 , Figure 2 This is a structural block diagram of a boot device provided in an embodiment of the present invention. The device may include:
[0106] The erase module 201 is used to erase the memory partitions other than the Boot area when it is detected that the application has not been downloaded.
[0107] The download and deployment module 202 is used to download the application when memory erasure is complete, and to deploy the application in memory when the application download is complete.
[0108] The program startup module 203 is used to jump to the application when the application deployment is completed, so that the application can start.
[0109] The execution protection module 204 is used to perform execution protection on statements corresponding to specified statement types, specified functions, and comparison operations during memory erasure, application download, and application deployment.
[0110] Preferably, the download and deployment module 202 may include:
[0111] The download submodule is used to generate a download key using a random number and to use the download key to perform encrypted download of the application.
[0112] The integrity verification submodule is used to perform integrity verification on the application when it is received, and to determine that the application download is complete when the verification passes.
[0113] Preferably, the device may further include:
[0114] The download flag extraction module is used to extract the download flag from a preset flag list and invert the download flag.
[0115] The judgment module is used to determine whether the processed download flag indicates that the application has not been downloaded; if so, it is determined that the application has not been downloaded.
[0116] Accordingly, the device may also include:
[0117] The download flag update module is used to update the download flag to indicate that the application has been downloaded, and to invert the updated download flag.
[0118] The download flag saving module is used to save the processed download flag to a preset flag list.
[0119] Preferably, the device may further include:
[0120] Other flag extraction modules are used to extract sealing flags and debug disable flags from a preset flag list; sealing flags are used to disable user mode, and debug disable flags are used to disable debugging functions.
[0121] Other flag update modules are used to set the sealing flag and debugging disable flag to preset effective values and perform inversion processing, and save the processed sealing flag and debugging disable flag to the preset flag list.
[0122] Preferably, the device may further include:
[0123] The MPU partition information extraction module is used to read the preset MPU partition information when the microcontroller is first powered on; the MPU partition information includes the location and operation permission information of all partitions in memory;
[0124] The MPU partition configuration module is used to configure all partitions in memory using the MPU partition information.
[0125] Preferably, the erasure module 201 may include:
[0126] The erase submodule is used to erase the partition in memory and check whether the memory has been restored to its initial value after erasure; if so, the memory erasure is considered complete.
[0127] Preferably, the protection module 204 may include:
[0128] The type determination submodule is used to determine the type of the current statement when execution reaches the current statement;
[0129] The first protection submodule is used to compare the variables and judgment condition values in the current statement to obtain a first comparison result if the current statement is a conditional statement, and then compare the variables and judgment condition values after inverting them to obtain a second comparison result; if the first comparison result and the second comparison result are the same, the next statement is executed.
[0130] The second protection submodule is used to extract the judgment condition value in the loop statement if the current statement is a loop statement, and execute the current statement and record the execution round; when jumping out of the execution of the current statement, it is determined whether the judgment condition value and the execution round are the same as the corresponding first preset value; if so, the next statement is executed.
[0131] The third protection submodule is used to delay the execution of the current statement according to a randomly generated waiting time if the current statement is a specified statement, and execute the current statement after the delay ends, and / or, when the execution of the current statement is completed, delay the execution according to the waiting time, and execute the next statement after the delay ends;
[0132] The fourth protection submodule is used to validate the return value of a specified function if the current statement is such that the next statement is executed after the validation is completed. The validation value used for validation is a non-contiguous value and its length is greater than the second preset value.
[0133] The fifth protection submodule is used to call the comparison function in the preset algorithm library to perform the comparison operation if the current statement is a comparison operation, and then execute the next statement after the comparison operation is completed.
[0134] This invention also provides a microcontroller, comprising:
[0135] Memory, used to store computer programs;
[0136] A processor is used to implement the steps of the application deployment method described above when executing computer programs.
[0137] Since the embodiments of the microcontroller part correspond to the embodiments of the application deployment method part, please refer to the description of the embodiments of the application deployment method part for the embodiments of the microcontroller part, and will not be repeated here.
[0138] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the application deployment method described in any of the above embodiments.
[0139] Since the embodiments of the computer-readable storage medium portion correspond to the embodiments of the application deployment method portion, the embodiments of the computer-readable storage medium portion are described in the description of the embodiments of the application deployment method portion, and will not be repeated here.
[0140] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0141] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0142] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0143] The above provides a detailed description of the application deployment method, boot device, microcontroller, and computer-readable storage medium provided by this invention. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of this invention. It should be noted that those skilled in the art can make various improvements and modifications to this invention without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this invention.
Claims
1. An application deployment method, characterized in that, Applied to a boot device, the method includes: When an application is detected not to be downloaded, the memory partitions in memory, excluding the Boot area, are erased. When the memory erasure is completed, the application is downloaded, and when the application download is complete, the application is deployed in the memory. When the application deployment is complete, navigate to the application to launch it; During the memory erasure, application download, and application deployment, execution protection is provided for statements corresponding to specified statement types, specified functions, and comparison operations. The specified statement types include conditional statements, loop statements, and specified statements; The protection logic corresponding to the conditional statement is to perform execution protection based on the variables and judgment condition values in the conditional statement; the protection logic corresponding to the loop statement is to perform execution protection based on the judgment condition in the loop statement and the execution round of the loop statement; the protection logic corresponding to the specified statement is to perform execution protection based on the randomly generated waiting time corresponding to the specified statement. The protection logic for the statement corresponding to the specified function is to perform execution protection based on the return value of the specified function; The protection logic for the statement corresponding to the comparison operation is to perform execution protection by calling the comparison function in the preset algorithm library.
2. The application deployment method according to claim 1, characterized in that, The process of downloading the application includes: A download key is generated using a random number, and the application is downloaded in encrypted form using the download key. Upon receiving the application, an integrity check is performed on the application, and if the check passes, the application is deemed to have been downloaded successfully.
3. The application deployment method according to claim 1, characterized in that, Before detecting that the application has not been downloaded, it also includes: Extract the download flag from the preset flag list and invert the download flag; Determine whether the processed download flag indicates that the application has not been downloaded; If so, then the application is determined not to have been downloaded; Accordingly, before jumping to the application, the following is also included: Update the download flag to indicate that the application has been downloaded, and then perform the inversion process on the updated download flag. Save the processed download flag to the preset flag list.
4. The application deployment method according to claim 3, characterized in that, Before jumping to the application, it also includes: Extract the sealing flag and the debugging disable flag from the preset flag list; the sealing flag is used to disable user mode, and the debugging disable flag is used to disable debugging function; Set the sealing flag and the debugging disable flag to preset effective values and perform the inversion process, then save the processed sealing flag and debugging disable flag to the preset flag list.
5. The application deployment method according to claim 1, characterized in that, Before detecting that the application has not been downloaded, it also includes: When the microcontroller is detected to be powered on for the first time, the preset MPU partition information is read; the MPU partition information includes the location and operation permission information of all partitions in the memory; Configure all partitions in memory using the MPU partition information.
6. The application deployment method according to claim 1, characterized in that, The memory erasure of partitions other than the Boot area in memory includes: The memory of the partition is erased, and after erasure, it is checked whether the memory has been restored to its initial value. If so, then confirm that the memory erasure has been completed.
7. The application deployment method according to any one of claims 1 to 6, characterized in that, The execution protection for statements corresponding to specified statement types, specified functions, and comparison operations includes: When the current statement is executed, determine the type of the current statement; If the current statement is a conditional statement, then the variables and condition values in the current statement are compared to obtain a first comparison result, and the variables and condition values are inverted and then compared to obtain a second comparison result; if the first comparison result and the second comparison result are determined to be the same, the next statement is executed; If the current statement is a loop statement, then extract the judgment condition value in the current statement, execute the current statement and record the execution round; when exiting the execution of the current statement, determine whether the judgment condition value and the execution round are the same as the corresponding first preset value; if so, execute the next statement; If the current statement is a specified statement, then the execution is delayed according to a randomly generated waiting time, and the current statement is executed after the delay ends; and / or, when the execution of the current statement is completed, the execution is delayed according to the waiting time, and the next statement is executed after the delay ends. If the current statement is the specified function, then the return value of the current statement is validated, and the next statement is executed after the validation is completed; the validation value used for the validation is a non-contiguous value and its length is greater than a second preset value; If the current statement is the comparison operation, then the comparison function in the preset algorithm library is called to perform the comparison operation, and the next statement is executed after the comparison operation is completed.
8. A boot device, characterized in that, include: The erase module is used to erase the memory partitions other than the Boot area when it is detected that the application has not been downloaded. The download and deployment module is used to download the application when the memory erasure is completed, and to deploy the application in the memory when the application download is completed. The program startup module is used to jump to the application when the application deployment is completed, so as to start the application; An execution protection module is used to perform execution protection on statements corresponding to specified statement types, specified functions, and comparison operations during the memory erasure, application download, and application deployment. The specified statement types include conditional statements, loop statements, and specified statements; the protection logic corresponding to the conditional statement is to perform execution protection based on the variables and judgment condition values in the conditional statement. The protection logic corresponding to the loop statement is to perform execution protection based on the judgment condition in the loop statement and the execution round of the loop statement; the protection logic corresponding to the specified statement is to perform execution protection based on the randomly generated waiting time corresponding to the specified statement; the protection logic corresponding to the specified function is to perform execution protection based on the return value of the specified function; and the protection logic corresponding to the comparison operation is to perform execution protection by calling the comparison function in the preset algorithm library.
9. A microcontroller, characterized in that, include: Memory, used to store computer programs; A processor for implementing the application deployment method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the application deployment method as described in any one of claims 1 to 7.