Method for updating bootstrap program of single-chip microcomputer

By using code synthesis tools in the microcontroller to splice the application executable files and boot program code, and adding a boot program startup area in the memory, the problem of capacity limitation, compilation limitation and power failure during the microcontroller boot program update process is solved, and stable boot program update is achieved.

CN119938097APending Publication Date: 2025-05-06DELTA ELECTRONICS INC(CN)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510009116.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-03
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The boot program update process of the microcontroller is subject to the limitation of the random access memory capacity, the size of the compiler's static array, and the boot program damage caused by power outage during the update process.

Method used

It provides an operator with code synthesis tools. Through the code synthesis tool, the special application executable file and the mapped boot program code are spliced ​​into the application executable file, downloaded to the microcontroller, and a boot program startup area is added to the microcontroller's memory to determine whether the code to run the boot program or the code of the application.

Benefits of technology

Overcoming the issue where the update process may be limited by the random access memory capacity and the possibility that the compiler cannot successfully generate application execution files due to the size of the static array, and solving the problem of boot program corruption caused by power failure during the update boot program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938097A_ABST
    Figure CN119938097A_ABST
Patent Text Reader

Abstract

The invention provides a bootstrap program updating method of a single-chip microcomputer. An arithmetic unit with a code synthesis tool is provided, the code synthesis tool can splice a special application program executable file and the mapped boot program code to form an application program executable file, and the application program executable file can be downloaded to the single-chip microcomputer to be directly used by the single-chip microcomputer. Therefore, the problems that the updating process is possibly limited by the capacity of the random access memory and cannot load complete data, and the application program execution file cannot be successfully generated possibly due to the limitation of a compiling program on the size of the static array are solved. Meanwhile, a bootstrap program starting area is newly added in the memory of the single chip microcomputer and used for judging whether codes of a bootstrap program or codes of an application program need to be operated, so that the problem that the bootstrap program is damaged due to power failure in the bootstrap program updating process is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of single-chip microcomputers, and in particular to a boot program updating method for a single-chip microcomputer. Background Art

[0002] The MCU is a highly integrated embedded processor. In the MCU system, there are some technical problems in the process of updating the bootloader. The causes of these problems are mainly related to hardware resource limitations and risks in the operation process. If these problems are not properly resolved, it may cause the device to fail to operate normally or even fail completely. The above technical problems are briefly described as follows.

[0003] First, the limited capacity of the random access memory (RAM) of the MCU makes it difficult to implement the traditional bootloader update method. The traditional method usually converts the update code of the bootloader into a static array, embeds it into the application, and then writes this data to the flash memory (Flash) through the application. However, this method requires that the complete bootloader data be loaded into the random access memory during system execution. If the size of the bootloader file exceeds the available space in the random access memory, the loading or operation of the data will not be completed. In other words, the capacity limitation of the random access memory will cause the update process to fail and the bootloader upgrade cannot be completed.

[0004] Secondly, the compiler's limitation on the size of static arrays can also affect the bootloader update. In the traditional method, the bootloader update code is converted into a static array and compiled together with the application code to generate the application's executable file. However, some compilers have clear limitations on the size of static arrays. Arrays that exceed this limit cannot be compiled, resulting in failure to generate the final application executable file. Even if the microcontroller's flash memory capacity is sufficient, the compiler may still be unable to complete code generation due to the large static array, thus affecting the bootloader update process.

[0005] Finally, during the update process of the boot program, if an unexpected power outage occurs, the boot program data may be incomplete. The boot program is usually stored in flash memory, and its data erasure and writing process needs to be fully executed. If a power outage occurs during the update process, the flash memory may only complete partial erasure or partial writing, resulting in incomplete boot program code. The boot program is the core module for system startup. If the code is damaged, the system will not be able to start, resulting in the device being unusable (commonly known as "bricked"). In this case, the device must be disassembled and the boot program code must be directly rewritten using a dedicated hardware burning tool. This repair method is cumbersome and costly, causing great trouble to users and maintenance personnel. Due to the limited hardware resources of the microcontroller, especially the capacity of the random access memory is usually only between a few KB and tens of KB, which poses certain challenges for storing large-scale data or performing complex tasks. Especially when it comes to boot program updates, the limited nature of random access memory will be particularly prominent.

[0006] In summary, the bootloader update process may be unable to load complete data due to the capacity limit of random access memory, or the compiler may be unable to successfully generate the application executable file due to the static array size limit. In addition, if the power is cut off during the update process, the bootloader may be damaged, which may cause the device to lose its function.

[0007] In view of this, it is necessary to develop a boot program update method for a single chip microcomputer to solve the problems and deficiencies faced by the prior art. Summary of the invention

[0008] The purpose of this case is to provide a method for updating the boot program of a single-chip microcomputer. An operator with a code synthesis tool is provided. The code synthesis tool can splice a special application executable file and the mapped boot program code to form an application executable file. The application executable file can be downloaded to the single-chip microcomputer for direct use by the single-chip microcomputer, thereby overcoming the problem that the update process may be limited by the capacity of the random access memory and cannot load complete data, and the problem that the application executable file may not be successfully generated due to the limitation of the compiler on the size of the static array. At the same time, a new boot program startup area is added to the memory of the single-chip microcomputer to determine whether to run the boot program code or the application code, so as to solve the problem of boot program damage caused by power failure during the boot program update process.

[0009] To achieve the aforementioned purpose, the present case provides a boot program update method for a single-chip microcomputer, which includes the following steps: providing an operator, wherein the operator has a code synthesis tool; providing the latest boot program code, and the code synthesis tool maps the first address where the boot program code is located to the second address of the application code area; calculating the first verification value of the mapped boot program code; splicing a special application executable file and the mapped boot program code through the code synthesis tool to form an application executable file; and downloading the application executable file to the single-chip microcomputer.

[0010] To achieve the above-mentioned purpose, the present invention provides a method for updating the boot program of a single-chip microcomputer, which comprises the following steps: (1) providing an arithmetic unit, the arithmetic unit having a code synthesis tool; (2) providing a single-chip microcomputer, the single-chip microcomputer comprising a memory, the memory comprising a boot program startup area, a boot program code area, an application program code area and an application program valid flag area; (3) providing the latest boot program code, the code synthesis tool mapping the first address where the boot program code is located to the second address of the application program code area; (4) calculating the first verification value of the mapped boot program code; (5) splicing the special application executable file and the mapped boot program code through the code synthesis tool to form an application executable file; (6) downloading the application executable file and the first verification value to the application program code area; (7) initializing the single-chip microcomputer; (8) calculating the first verification value of the code in the boot program code area Second verification value, and set the application valid flag area to valid; (9) determine whether the first verification value is equal to the second verification value, when the determination result is consistent, execute step (14), when the determination result is not consistent, execute step (10); (10) erase the code in the boot program code area; (11) write the update code in the application executable file into the boot program code area; (12) calculate the second verification value of the current boot program code area; (13) determine whether the first verification value is equal to the second verification value, when the determination result is consistent, execute step (14), when the determination result is not consistent, execute step (10); (14) determine whether the application valid flag area is valid, when the determination result is consistent, execute step (15), when the determination result is not consistent, execute step (16); (15) set the application valid flag area to invalid; and (16) perform reset.

[0011] The beneficial effect of this case is that the embodiment of this case provides a method for updating the boot program of a single chip microcomputer. The method of this case can be applied to a power supply device, such as a vehicle charger, to ensure that the boot program update can be implemented and executed, and the process is simple, the cost is low and it is easy to implement. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The following detailed description of the present invention and the schematic diagrams of the embodiments are intended to enable those skilled in the art to more fully understand the above contents, and are not intended to limit the present invention.

[0013] Figure 1 This is a schematic diagram of the architecture of the application executable file generated by the code synthesis tool in this case.

[0014] Figure 2 This is a schematic diagram of the memory architecture of the microcontroller in this case.

[0015] Figure 3A , Figure 3B The flowchart of the boot program update method of the single chip microcomputer in this case.

[0016] Figure 4 This is the workflow diagram of the boot program startup area in this case.

[0017] The reference numerals are described as follows:

[0018] S1~S18: Process steps of the boot program update method of the single chip microcomputer in this case

[0019] 1: Calculator

[0020] 100: Code Synthesis Tools

[0021] 2: Single chip microcomputer

[0022] 21: Memory

[0023] 22: Clock unit

[0024] 23: General purpose input and output unit

[0025] V1: First verification value

[0026] V2: Second verification value

[0027] F1: Bootloader startup area

[0028] F2: Bootloader code area

[0029] F3: Application code area

[0030] F4: Application valid mark area

[0031] D1: Bootloader code

[0032] D2: Special application executable files

[0033] D3: Application executable file DETAILED DESCRIPTION

[0034] Some typical embodiments that embody the features and advantages of the present invention will be described in detail in the following description. It should be understood that the present invention can be varied in various ways without departing from the scope of the present invention, and the description and drawings are essentially for illustrative purposes rather than for limiting the present invention.

[0035] Figure 1 This is a schematic diagram of the architecture of the application executable file generated by the code synthesis tool in this case. Figure 2 The schematic diagram of the memory architecture of the single-chip microcomputer in this case is shown in FIG. In this case, an application executable file is formed by a code synthesis tool to be applied to the boot program update of the single-chip microcomputer, which includes the following contents.

[0036] First, a computing unit 1 is provided, wherein the computing unit 1 has a code synthesis tool 100. The computing unit 1 is an external computing device.

[0037] Next, the latest boot program code D1 is provided, and the code synthesis tool 100 maps the first address where the boot program code D1 is located to the second address of the application code area F3. In other words, the first address in the operator 1 where the latest boot program code D1 is located is mapped to the second address of the application code area F3 in the single-chip microcomputer 2, so as to realize the flexible allocation of hardware resources, so that the single-chip microcomputer 2 is capable of processing a larger boot program code D1.

[0038] Next, the first verification value V1 of the mapped boot code D1 is calculated. In some embodiments, the first verification value V1 may be a hash value, wherein the hash value is used to perform security verification on the boot code D1 to ensure that the data of the boot code D1 has not been tampered with.

[0039] Next, the special application executable file D2 and the mapped boot program code D1 are spliced ​​by the code synthesis tool 100 to form the application executable file D3. That is, the application executable file D3 is generated by the code synthesis tool 100 in the computing unit 1.

[0040] Next, the application executable file D3 is downloaded to the single chip microcomputer 2. The application executable file D3 can be stored in the application code area F3 of the single chip microcomputer 2. In this embodiment, the single chip microcomputer 2 is installed in a power supply device, such as a vehicle charger.

[0041] In summary, the code synthesis tool 100 can be used to splice the special application executable file D2 and the mapped boot program code D1 into an application executable file D3 in the computing unit 1, and then downloaded from the computing unit 1 to the application code area F3 of the microcontroller 2, thereby overcoming the problem that the update process is limited by the capacity of the random access memory and cannot load complete data, and the problem that the application executable file cannot be successfully generated due to the compiler's limitation on the size of the static array.

[0042] Please refer to Figure 2 The single chip computer 2 includes a memory 21, and the memory 21 includes a boot program startup area F1, a boot program code area F2, an application program code area F3, and an application program valid flag area F4.

[0043] In this case, a boot program startup area F1 is newly added. Since the memory 21 resources reserved for the application code area F3 are relatively sufficient, the boot program startup area F1 occupies part of the application code area F3. Since the resources consumed by the boot program startup area F1 are very small, setting the boot program startup area F1 will not have much impact on the resources of the application code area F3. The boot program startup area F1 is used to determine whether the boot program code or the application code is to be run. The boot program code area F2 is used to store most of the boot program code. The application code area F3 is used to store the application code. The application valid flag area F4 is used to confirm whether the current application code is valid. In detail, after downloading the new application code through the boot program, by calculating the hash value of the application code, it can be determined whether the code in the current application code area F3 is valid. If the downloaded application code is complete and valid, a string of specific numbers will be written to the application valid flag area F4 to detect whether the code in the application code area F3 is to be run after the microcontroller 2 is started.

[0044] In the present embodiment, the memory 21 is a flash memory, and the boot program startup block area F1 is a non-erasable area, and the boot program code area F2 and the application code area F3 are erasable areas. Therefore, when the single-chip computer 2 updates the boot program, the code in the boot program code area F2 or the application code area F3 is valid, and the code in the boot program code area F2 or the application code area F3 can be selected for execution through the code in the boot program startup block area F1. Therefore, if a power outage or the like occurs during the process of updating the boot program, resulting in the failure to update the code in the boot program code area F2, it can be re-updated through the operation of the boot program startup block area F1, without making the entire boot program code completely unable to run, thereby making the system unable to start and causing the device to be unusable. In addition, the design of the boot program startup block area F1 takes up very little resources of the memory 21, preferably less than 10Kb, so it will not cause resource shortages for the single-chip computer 2.

[0045] Figure 3A , 3B Flow chart of the boot program update method of the single chip microcomputer in this case. In this embodiment, an application executable file D3 is synthesized by the code synthesis tool 100 and downloaded to the application code area F3, and then the boot program code area F2 is updated by the update code in the application executable file D3 in the application code area F3. The boot program update method of the single chip microcomputer in this case includes the following steps.

[0046] First, in step S1 , a computing unit 1 is provided, wherein the computing unit 1 has a code synthesis tool 100 .

[0047] Next, in step S2 , a single chip microcomputer 2 is provided, wherein the single chip microcomputer 2 comprises a memory 21 , and the memory 21 comprises a boot program startup area F1 , a boot program code area F2 , an application program code area F3 and an application program valid flag area F4 .

[0048] Next, in step S3 , the latest boot code D1 is provided, and the code synthesis tool 100 maps the first address where the boot code D1 is located to the second address of the application code region F3 .

[0049] Next, in step S4, a first verification value V1 of the mapped boot code D1 is calculated. In this embodiment, the first verification value V1 is calculated by the code synthesis tool 100. In some embodiments, the first verification value V1 may be a hash value, wherein the hash value is used to perform a security check on the boot code D1 to ensure that the data of the boot code D1 has not been tampered with.

[0050] Next, in step S5, the special application executable file D2 and the mapped boot program code D1 are spliced ​​by the code synthesis tool 100 to form an application executable file D3. In this embodiment, the special application executable file D2 is a program designed to complete the update boot program, and the special application executable file D2 can be directly run in the single chip 2.

[0051] Next, in step S6 , the application executable file D3 and the first verification value V1 are downloaded to the application code area F3 .

[0052] Next, in step S7, the single-chip microcomputer 2 is initialized. In this embodiment, the single-chip microcomputer 2 includes a clock unit 22 and a universal input and output unit 23, wherein the clock unit 22, the universal input and output unit 23, and the flash memory 21 are initialized in sequence. In this embodiment, the clock unit 22 is used to provide a stable clock signal for the entire single-chip microcomputer system to synchronize the operation of various hardware modules in the single-chip microcomputer 2. The universal input and output unit is used to enable the single-chip microcomputer 2 to interact with external devices to process the input and output of digital signals to the single-chip microcomputer 2.

[0053] Next, in step S8 , the second verification value V2 of the code in the boot program code area F2 is calculated, and the application valid flag area F4 is set to be valid. In some embodiments, the first verification value V1 and the second verification value V2 are both hash values, and the first verification value V1 and the second verification value V2 are calculated by the code synthesis tool 100 .

[0054] Next, in step S9, it is determined whether the first verification value V1 is equal to the second verification value V2. When the determination result is yes, step S14 is executed. When the determination result is no, step S10 is executed. In this embodiment, the first verification value V1 is the mapped boot program code D1 for updating, and the second verification value V2 is the code in the existing boot program code area F2. When the first verification value V1 is equal to the second verification value V2, it means that the code in the current boot program code area F2 is the latest; if the first verification value V1 is not equal to the second verification value V2, it means that the current code in the boot program code area F2 needs to be updated. In this embodiment, the determination step is executed by the code in the boot program startup block area F1 of the single-chip computer 2.

[0055] Next, in step S10 , the code in the boot code area F2 is erased, so that there is no executable code in the boot code area F2 .

[0056] Next, in step S11, the update code in the application executable file D3 is written into the boot program code area F2. Specifically, the update code in the application executable file D3 in the application code area F3 is written into the boot program code area F2. This step uses the read and write functions of the flash memory to copy data to different areas in the flash memory.

[0057] Next, in step S12 , a second verification value V2 of the current boot code region F2 is calculated.

[0058] Next, in step S13, it is determined whether the first verification value V1 is equal to the second verification value V2. When the determination result is yes, step S14 is executed, and when the determination result is no, step S10 is executed. When the first verification value V1 is equal to the second verification value V2, it indicates that the code currently in the boot program code area F2 has been successfully updated to the latest version; if the first verification value V1 is not equal to the second verification value V2, it indicates that there is a problem in the update process, for example, there may be a problem in erasing the old code in the boot program code area F2 or writing the new code.

[0059] Next, in step S14, it is determined whether the application valid flag area F4 is valid. If the determination result is yes, step S15 is executed, and if the determination result is no, step S16 is executed. In this embodiment, the determination step is executed by the code of the boot program startup block area F1 of the single chip 2.

[0060] Next, in step S15, the application valid flag area F4 is set to be invalid.

[0061] Next, in step S16, a reset is performed, that is, the single chip computer 2 is restarted to ensure that the system starts running again.

[0062] Figure 4 The flowchart of the boot program startup area of ​​this case is as follows. When the single chip microcomputer 2 is started, or after resetting (step S16), the code in the boot program code area F2 or the application code area F3 to be executed is selected through the boot program startup block area F1. The detailed steps are as follows.

[0063] First, in step S17, the single-chip microcomputer 2 provides a clock unit 22, an interrupt vector table, and initializes the clock unit 22 to ensure that the single-chip microcomputer 2 can operate normally. In some embodiments, the address of the interrupt vector table of the single-chip microcomputer 2 is not fixed, and the interrupt vector table does not need to be initialized. In some embodiments, the address of the interrupt vector table of the single-chip microcomputer 2 is fixed, and the interrupt vector table needs to be initialized. The interrupt vector table is used to store the entry address of the interrupt processing program, so that when an interrupt occurs in the system, the address of the corresponding interrupt service program is searched through the interrupt vector table and jumped to execute. The interrupt vector table is structured in a way of a function pointer array to execute different interrupt responses for the same interrupt source.

[0064] Next, in step S18, it is determined whether the application valid flag area F4 is valid or whether an update request is received. When the application valid flag area F4 is valid and no update request is received, the code in the application code area F3 is executed. That is to say, the code in the application code area F3 is an executable application code, not the code of the application executable file D3. When the application valid flag area F4 is invalid or an update request is received, the code in the boot program code area F2 is executed. There are two possibilities in this situation. First, if the application valid flag area F4 is invalid, it means that the code in the boot program code area F2 is the latest version of the code. At this time, the code in the application code area F3 may be incomplete or the code of the application executable file D3 previously used to update the boot program. Therefore, by running the latest code in the boot program code area F2, the complete and correct application code can be downloaded back, and the application valid flag area F4 is marked as valid. Second, if an update request is received, the code in the boot program code area F2 is executed to update the boot program, that is, continue to execute from the aforementioned step S6.

[0065] In summary, this case provides a method for updating the boot program of a single-chip microcomputer. An operator with a code synthesis tool is provided. The code synthesis tool can splice a special application executable file and the mapped boot program code to form an application executable file. The application executable file can be downloaded to the single-chip microcomputer for direct use by the single-chip microcomputer, thereby overcoming the problem that the update process may be limited by the capacity of the random access memory and cannot load complete data, and the problem that the application executable file may not be successfully generated due to the limitation of the compiler on the size of the static array. At the same time, a new boot program startup area is added to the memory of the single-chip microcomputer to determine whether to run the boot program code or the application code, so as to solve the problem of boot program damage caused by power failure during the boot program update process.

[0066] This application may be modified in various ways by those skilled in the art, but all modifications are within the scope of the claims of this application.

Claims

1. A method for updating a boot program of a single chip microcomputer, characterized in that: include: Providing an operator, the operator having a code synthesis tool; Providing a latest boot program code, the code synthesis tool maps a first address where the boot program code is located to a second address in an application code area; Calculating a first verification value of the mapped boot program code; splicing a special application executable file and the mapped boot program code through the code synthesis tool to form an application executable file; and Download the application executable file to a single-chip microcomputer. 2 . The boot program updating method of a single chip microcomputer according to claim 1 , wherein the first verification value is a hash value.

3. The boot program updating method of a single chip microcomputer according to claim 1, wherein the single chip microcomputer is installed in a power supply device.

4. A method for updating a boot program of a single chip microcomputer, characterized in that: Contains steps: S1: providing an operator, wherein the operator has a code synthesis tool; S2: providing a single chip microcomputer, the single chip microcomputer comprising a memory, the memory comprising a boot program startup area, a boot program code area, an application code area and an application valid flag area; S3: providing a latest boot program code, and the code synthesis tool mapping a first address where the boot program code is located to a second address of the application code area; S4: Calculate a first verification value of the mapped boot program code; S5: splicing a special application executable file and the mapped boot program code through the code synthesis tool to form an application executable file; S6: Downloading the application executable file and the first verification value to the application code area; S7: Initialize the microcontroller; S8: Calculate a second verification value of a code in the boot program code area, and set the application valid flag area to be valid; S9: Determine whether the first verification value is equal to the second verification value. If the determination result is yes, execute step S14. If the determination result is no, execute step S10. S10: Erasing the code in the boot program code area; S11: writing an update code in the executable file of the application into the boot program code area; S12: Calculate the second verification value of the current boot program code area; S13: Determine whether the first verification value is equal to the second verification value. If the determination result is yes, execute step S14. If the determination result is no, execute step S10. S14: Determine whether the valid flag area of ​​the application is valid. If the determination result is yes, execute step S15. If the determination result is no, execute step S16. S15: Setting the application valid flag area to invalid; and S16: Execute reset. 5 . The boot program updating method of a single chip microcomputer according to claim 4 , wherein the first verification value and the second verification value are both a hash value. 6 . The boot program updating method of a single chip microcomputer according to claim 4 , wherein the single chip microcomputer is installed in a power supply device.

7. The boot program updating method of the single chip microcomputer according to claim 4, wherein the boot program startup block area is a non-erasable area, and the boot program code area and the application code area are erasable areas.

8. The boot program updating method of the single chip microcomputer according to claim 4, wherein in step S6, the application executable file and the first verification value are downloaded to the application code area of ​​the single chip microcomputer through a code in the boot program startup block area.

9. The boot program updating method of a single chip microcomputer according to claim 4, wherein the memory is a flash memory.

10. The boot program updating method of a single chip microcomputer according to claim 9, wherein in step S7, the single chip microcomputer comprises a clock unit and a general purpose input and output unit, wherein the clock unit, the general purpose input and output unit, and the flash memory are initialized in sequence.

11. The boot program updating method of a single chip microcomputer according to claim 4, wherein after the step S16 or the single chip microcomputer is started, the method further comprises the steps of: S17: The single chip microcomputer provides a clock unit, an interrupt vector table, and initializes the clock unit; and S18: Determine whether the valid flag area of ​​the application is valid or whether an update request is received; when the valid flag area of ​​the application is valid and the update request is not received, execute a code in the code area of ​​the application; when the valid flag area of ​​the application is invalid or the update request is received, execute the code in the boot program code area. 12 . The boot program updating method of a single chip microcomputer according to claim 11 , wherein an address of the interrupt vector table is a fixed address, and in step S17 , the interrupt vector table is initialized.