An online upgrade method suitable for MPU microprocessor
By setting specific mapping diagrams and steps in the Flash memory of the MPU microprocessor, the problem that IAP technology cannot be applied to the MPU microprocessor is solved, online upgrades are achieved, the update process is simplified, and the application stability is improved.
Patent Information
- Application Number
- CN202411855301.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-17
AI Technical Summary
The existing IAP technology cannot be applied to MPU microprocessors to achieve online upgrades.
By setting a specific mapping diagram in the Flash memory of the MPU microprocessor, including the first boot area, the second boot area, the boot program area, the third boot area, the application area and the upgrade program area, and performing online upgrades according to specific steps, including reading boot parameters, storing the encrypted firmware to be upgraded, decrypting and overwriting new applications.
The online upgrade of the MPU microprocessor is realized, which simplifies the program update process, reduces development costs and cycles, and ensures the stability of the updated application.
Smart Images

Figure CN119336370B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software upgrade, and in particular to an online upgrade method applicable to an MPU microprocessor. Background Art
[0002] As an online upgrade technology, IAP (In Application Programming) technology can upgrade the firmware without re-burning the chip. Therefore, it is of great significance in the process of program vulnerability modification and program update.
[0003] IAP technology works by mapping the Flash memory into two banks. While the user program in one bank is running, the other bank can be reprogrammed, and the reprogrammed user program is then transferred from one bank to the other. IAP technology requires using the user's own program code to write the updated user program to the Flash memory via an external interface. Then, through Flash memory read and write operations, the new application overwrites the original application, and the system restarts from the new application entry point.
[0004] However, existing IAP technology is almost exclusively used on MCU (Micro Control Unit) platforms, with little application on MPU (Micro Processor Unit) platforms. This is because MCU chips normally boot from main flash memory. In this mode, system memory is mapped to the boot space, allowing the user boot program and application stored in the main flash memory to be automatically loaded into the chip's boot space. However, on MPU (Micro Processor Unit) platforms, application storage is typically external flash memory. When an MPU chip boots from external flash memory, the chip's core processor copies the application to the chip's boot space based on the system secondary boot program pointed to by the boot parameter at the flash memory's first address. Furthermore, because the system secondary boot program can only copy a limited number of application segments, it must copy the application multiple times, segment by segment. To ensure that each segment is placed at the designated address for optimal application operation, the system secondary boot program's logic becomes extremely complex. Adding a user boot program for in-circuit programming to implement IAP functionality would require the system secondary boot program to simultaneously copy both the user boot program and application to the chip's boot space. This will not only further increase the complexity of the system's secondary boot program, but also pose a risk of updated applications not running properly. Summary of the Invention
[0005] The purpose of the present invention is to provide an online upgrade method suitable for an MPU microprocessor, so as to solve the technical problem that the existing IAP technology cannot be applied to the MPU microprocessor to realize online upgrade.
[0006] To achieve the above objectives, the present invention proposes the following technical solutions:
[0007] In a first aspect, the present technical solution provides an online upgrade method applicable to an MPU microprocessor, comprising:
[0008] The mapping map of the MPU program in the external Flash memory connected to the MPU program is set as follows: starting from the first position, the mapping areas are as follows: a first boot area, a second boot area, a boot program area, a third boot area, an application area, and an upgrade program area; wherein the first boot area is used to store boot parameters of the application and boot parameters of the boot program; the second boot area is used to store boot parameters of the boot program, and the third boot area is used to store boot parameters of the application;
[0009] And includes the following steps:
[0010] The MPU microprocessor is powered on to trigger reading of the boot parameters of the application stored in the first boot area, and then points to the application area to load the application in the application into the MPU microprocessor for execution;
[0011] triggering storage of the encrypted firmware to be upgraded in the upgrade program area based on an upgrade instruction obtained by the application during operation;
[0012] After the application area receives the encrypted firmware to be upgraded, the MPU microprocessor automatically restarts and triggers the copying of boot parameters of the boot program from the second boot area to the first address of the first boot area;
[0013] Instructing the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application based on the boot program boot parameter stored at the first address of the first boot area;
[0014] After the old application in the application area is overwritten with the new application, the boot parameters of the application are copied from the third boot area and overwritten to the first address of the first boot area;
[0015] The MPU microprocessor is reset to reload the new application program therein for execution.
[0016] Furthermore, the method triggers the storage of the encrypted firmware to be upgraded before the upgrade program area based on the upgrade instruction obtained by the application during operation, including:
[0017] Sequentially grouping the original firmware to be upgraded according to a preset number of bytes to obtain a plurality of groups of sub-firmware;
[0018] When it is determined that the number of bytes of the last group of sub-firmware is not equal to the preset number of bytes, obtaining a byte difference between the number of bytes of the last group of sub-firmware and the preset number of bytes;
[0019] Starting from the first free bit of the last group of sub-firmware, fill the last group of sub-firmware with invalid data equal to the byte difference so that the final number of bytes is equal to the preset number of bytes; wherein each invalid data filled is equal to the byte difference;
[0020] All group sub-firmwares are encrypted based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
[0021] Furthermore, the boot parameter of the boot program stored based on the first address of the first boot area instructs the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application program; including:
[0022] decrypting each set of encrypted sub-firmware to obtain corresponding each set of decrypted sub-firmware;
[0023] When determining that the last bit in the last set of decryption sub-firmware is digital data, confirming that the last set of decryption sub-firmware is filled with invalid data;
[0024] Deleting the same number of characters corresponding to the digital data from the last digit of the last group of decryption sub-firmware;
[0025] The remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that has been subjected to invalid data deletion are sequentially spliced together to obtain the new application program.
[0026] Furthermore, the application area receives the encrypted firmware to be upgraded; including:
[0027] After determining that a group of encrypted sub-firmware is successfully received, triggering the reception of the next group of encrypted sub-firmware that is sequentially adjacent to it; otherwise, terminating the reception and sending an alarm feedback to the host computer; wherein the alarm feedback includes the number of groups corresponding to the abnormally received encrypted sub-firmware;
[0028] Repeat the previous step until all group-encrypted sub-firmware are obtained.
[0029] Further, including:
[0030] An abnormality occurs in the MPU microprocessor and / or the Flash memory;
[0031] When it is determined that the encrypted firmware to be upgraded is being received in the application area, the receiving process is terminated, and the receiving of the encrypted firmware to be upgraded is restarted based on the receiving instruction of the host computer;
[0032] When it is determined that the encrypted firmware to be upgraded is decrypted in the boot program area, or the old application is overwritten with the new application, the upgrade process is continued after restarting by decrypting the encrypted firmware to be upgraded, or by overwriting the old application with the new application.
[0033] In a second aspect, the present technical solution provides an online upgrade system for an MPU microprocessor, comprising:
[0034] The mapping map of the MPU program in the external Flash memory connected to the MPU program is set as follows: starting from the first position, the mapping areas are as follows: a first boot area, a second boot area, a boot program area, a third boot area, an application area, and an upgrade program area; wherein the first boot area is used to store boot parameters of the application and boot parameters of the boot program; the second boot area is used to store boot parameters of the boot program, and the third boot area is used to store boot parameters of the application;
[0035] And includes the following modules:
[0036] An application running module, used for triggering, when the MPU microprocessor is powered on, to read the boot parameters of the application stored in the first boot area, and then pointing to the application area to load the application in it into the MPU microprocessor for execution;
[0037] A first storage module is configured to trigger the storage of the encrypted firmware to be upgraded to the upgrade program area based on an upgrade instruction obtained by the application during operation;
[0038] A second storage module is configured to automatically restart the MPU microprocessor after the application area receives the encrypted firmware to be upgraded, and trigger the copying of boot parameters of the boot program from the second boot area to the first address of the first boot area;
[0039] a third storage module, for directing the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application program based on the boot program boot parameter stored at the first address of the first boot program area;
[0040] a fourth storage module, which, after overwriting the old application in the application area with the new application, triggers the copying of the boot parameters of the application from the third boot area and overwrites the boot parameters to the first address of the first boot area;
[0041] The reset operation module is used to reset the MPU microprocessor to reload the new application program into it for operation.
[0042] Further, including:
[0043] A grouping module, used for sequentially grouping the original firmware to be upgraded according to a preset number of bytes to obtain several groups of sub-firmware;
[0044] a calculation module, configured to obtain a byte difference between the byte number of the last group of sub-firmware and the preset byte number when determining that the byte number of the last group of sub-firmware is not equal to the preset byte number;
[0045] a filling module, configured to fill, starting from the first vacant bit of the last group of sub-firmware, invalid data equal to the byte number difference in the last group of sub-firmware so that the final number of bytes thereof is equal to the preset number of bytes; wherein each invalid data filled is equal to the byte number difference;
[0046] The encryption module is used to encrypt all group sub-firmware based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
[0047] Furthermore, the third storage module includes:
[0048] a decryption unit, configured to decrypt each group of encrypted sub-firmware to obtain the corresponding group of decrypted sub-firmware;
[0049] a judging unit, configured to, when judging that the last bit in the last set of decryption sub-firmware is digital data, confirm that the last set of decryption sub-firmware is filled with invalid data;
[0050] a deleting unit, configured to delete, starting from the last digit of the last group of decryption sub-firmware, a number of characters corresponding to the digital data;
[0051] The splicing unit is used to sequentially splice the remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that has been subjected to invalid data deletion to obtain the new application program.
[0052] In a third aspect, the present technical solution provides an electronic device comprising at least one processor, wherein the processor is coupled to a memory, wherein a computer program is stored in the memory, and wherein the computer program is configured to execute the method described when executed by the processor.
[0053] In a fourth aspect, the present technical solution provides a computer-readable storage medium having a computer program stored thereon, which implements the described method when the computer program is executed by a computer.
[0054] Beneficial effects:
[0055] It can be seen from the above technical solutions that the technical solution of the present invention provides an online upgrade method suitable for MPU microprocessors to solve the technical defect that the existing IAP technology cannot be applied to MPU microprocessors to realize online upgrades, so that the MPU microprocessor can also realize online program updates simply and efficiently.
[0056] Specifically, this technical solution pre-maps the corresponding Flash memory as follows: starting from the first position, it includes the following mapping areas in sequence: the first boot area, the second boot area, the boot program area, the third boot area, the application area, and the upgrade program area; wherein the first boot area is used to store the application's boot parameters and the boot program's boot parameters; the second boot area is used to store the boot program's boot parameters, and the third boot area is used to store the application's boot parameters. Based on the Flash mapping map, the following steps are performed: First, the MPU microprocessor is powered on to trigger the reading of the application's boot parameters stored in the first boot area, and then points to the application area to load the application within it into the MPU microprocessor for execution. Second, based on the upgrade instructions obtained by the application during operation, the encrypted firmware to be upgraded is triggered to be stored in the upgrade program area. After receiving the encrypted firmware to be upgraded, the application area triggers the copying of the boot program's boot parameters from the second boot area to the first address of the first boot area. Then, based on the boot parameters of the boot program stored at the first address of the first boot area, the boot program area is instructed to decrypt the encrypted firmware to be upgraded to obtain a new application. After the new application is used to overwrite the old application in the application area, the boot parameters of the application are copied from the third boot area and overwritten to the first address of the first boot area. Finally, the MPU microprocessor is reset to reload the new application into it for execution.
[0057] In specific implementations, since this technical solution provides separate boot areas for storing boot parameters for both the application and the boot program, the boot area can be used to guide the corresponding online update steps. Furthermore, during the update process, updating the boot parameters stored at the first address within the first boot area indicates the update progress and triggers the jump of the update steps between the program storage area and the boot storage area. This allows for fast, reliable, and flexible online program upgrades or vulnerability fixes based on IAP technology, even without the need to load the boot program and application simultaneously.
[0058] It should be appreciated that all combinations of the foregoing concepts, as well as additional concepts described in greater detail below, to the extent such concepts are not mutually inconsistent, can be considered to be part of the inventive subject matter of this disclosure.
[0059] The foregoing and other aspects, embodiments, and features of the present invention will be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as features and / or beneficial effects of the exemplary embodiments, will become apparent from the following description or through practice of specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] The accompanying drawings are not intended to be drawn to scale. In the drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For the sake of clarity, not every component is labeled in every figure. Embodiments of various aspects of the present invention will now be described by way of example and with reference to the accompanying drawings, in which:
[0061] Figure 1 This is a mapping diagram of the MPU program on the Flash memory in this embodiment;
[0062] Figure 2 This is a flow chart of the online upgrade method applicable to the MPU microprocessor described in this embodiment;
[0063] Figure 3 A flowchart for encrypting the original firmware to be upgraded;
[0064] Figure 4 A flowchart of handling abnormalities in receiving encrypted firmware to be upgraded;
[0065] Figure 5 A flowchart for decrypting the encrypted firmware to be upgraded;
[0066] Figure 6 This is a flowchart for handling exceptions during an online upgrade.
[0067] Figure 7 This is a structural block diagram of the online upgrade system applicable to the MPU microprocessor described in this embodiment;
[0068] Figure 8 This is a structural block diagram of the electronic device described in this embodiment. DETAILED DESCRIPTION
[0069] In order to make the purpose, 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 in conjunction with the drawings of the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the described embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be the common meanings understood by people with ordinary skills in the field to which the present invention belongs.
[0070] The terms "first", "second" and similar words used in the specification and claims of this application do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular forms of "a", "an" or "the" and similar words do not indicate a quantitative limitation, but rather indicate the presence of at least one. Words such as "include" or "comprise" mean that the elements or objects preceding "include" or "comprises" cover the features, wholes, steps, operations, elements and / or components listed after "include" or "comprises", and do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0071] IAP (In Application Programming) technology, as an online upgrade technology, is of great significance in program vulnerability modification and program updates because it can upgrade firmware without re-burning the chip. However, it is mostly used in MCU processors and has not been applied to MPU microprocessors. The reason is that the Flash memory of the MPU microprocessor is external, and the chip core cannot directly read data from the Flash memory when executing instructions. Therefore, compared with the MCU, the MPU chip has an additional operation when powered on: loading the application program into the chip's internal RAM (Random Access Memory). Given this problem, the operation of simultaneously loading the user boot program and the application program into the MPU microprocessor's RAM is very complicated. Therefore, IAP technology is not currently widely used in MPU microprocessors. Based on this, the present embodiment aims to provide an online upgrade method suitable for MPU microprocessors to solve the above technical problems.
[0072] The following is a detailed introduction to the online upgrade method applicable to the MPU microprocessor described in this embodiment with reference to the accompanying drawings.
[0073] When the MCU microprocessor is upgraded online using IAP technology, the corresponding internal Flash memory is mapped as follows: starting from the top, it is divided into the bootloader area, the application area, and the upgrade program area. In practice, after powering on, the MCU program first enters the user bootloader. At this point, a flag is read to determine whether an upgrade is in progress. If not, the program jumps directly to the application program. If an online upgrade is in progress, a decryption upgrade is performed, and the new application corresponding to the decrypted upgraded firmware overwrites the old application program.
[0074] However, the MPU microprocessor is affected by the external plug-in form of Flash memory and cannot load the boot program and application program at the same time. Based on this, this technical solution designs a new IAP online upgrade solution suitable for MPU microprocessors.
[0075] In order to implement this solution, the corresponding Flash memory is mapped as follows. Figure 1 As shown, the mapping diagram of the MPU program in the external Flash memory connected to the communication connection is set as follows: starting from the first position, it includes the following mapping areas in sequence: the first boot area, the second boot area, the boot program area, the third boot area, the application area and the upgrade program area. Among them, the first boot area is used to store the boot parameters of the application and the boot parameters of the boot program. By default, the first address of the first boot area stores the boot parameters of the application. The second boot area is used to store the boot parameters of the boot program. The third boot area is used to store the boot parameters of the application. The boot program area is used to decrypt the firmware to be upgraded and overwrite the old application with the new application. The application area is used to receive the encrypted firmware to be upgraded. The upgrade program area is used to store the encrypted firmware to be upgraded, and the application receives and programs it through its own program in this area.
[0076] At this time, based on Figure 1 The Flash memory map shown in the figure is combined with Figure 2 As shown, perform the following steps to implement the method described in this embodiment:
[0077] Step S102: The MPU microprocessor is powered on to trigger reading of the boot parameters of the application stored in the first boot area, and then points to the application area to load the application in it into the MPU microprocessor for execution.
[0078] This step is the default operation after the MPU microprocessor is powered on. That is, the default is to point to the application and copy it to the startup space of the MPU microprocessor for execution. If no upgrade instruction is received, the application will continue to execute. If an upgrade instruction is received, continue with the following steps:
[0079] Step S104: triggering the storage of the encrypted firmware to be upgraded in the upgrade program area based on the upgrade instruction obtained during the operation of the application.
[0080] In this step, the upgrade instruction is issued by the host computer. Figure 3 As shown, encrypt the original firmware to be upgraded through the following steps:
[0081] Step S10402: The original firmware to be upgraded is grouped sequentially according to a preset number of bytes to obtain several groups of sub-firmware.
[0082] Step S10404: When it is determined that the number of bytes of the last group of sub-firmware is not equal to the preset number of bytes, a byte difference between the number of bytes of the last group of sub-firmware and the preset number of bytes is obtained.
[0083] Step S10406: Starting from the first free bit of the last group of sub-firmware, fill the last group of sub-firmware with invalid data equal to the byte difference so that the final byte number is equal to the preset byte number.
[0084] Among them, each invalid data filled is the byte number difference.
[0085] As another implementation, starting from a preset starting number, the number of byte differences can be sequentially padded to the end of the last group of sub-firmware, so that the final number of bytes equals the preset number of bytes. In a specific implementation, for ease of processing, the number "1" is used as the preset starting number and "1" is used as the arithmetic difference term. For example, if the byte difference is 8, then "1, 2, 3, 4, 5, 6, 7, 8" are sequentially padded as invalid data.
[0086] Step S10408: Encrypt all group sub-firmwares based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
[0087] At this point, based on steps S10402 to S10408, the character length restriction of the AES encryption algorithm can be broken. To improve efficiency, it is possible to directly determine whether all bytes are multiples of 1008. If the last group of bytes is not a multiple of 1008, it is further grouped into 16-byte units and the invalid data padding method described above is adopted.
[0088] Step S106: After the application area receives the encrypted firmware to be upgraded, the MPU microprocessor automatically restarts and triggers the copying of boot parameters of the boot program from the second boot area to the first address of the first boot area.
[0089] Considering the possible abnormalities in the process of receiving the encrypted firmware to be upgraded, as a specific implementation method, Figure 4 As shown, including:
[0090] Step S10602: After determining that a group of encrypted sub-firmware is received successfully, trigger the reception of the next group of encrypted sub-firmware that is adjacent to it in sequence; otherwise, terminate the reception and send an alarm feedback to the host computer.
[0091] The alarm feedback includes the number of groups corresponding to the abnormal encryption sub-firmware.
[0092] Step S10604: Execute the previous step in a loop until all group encrypted sub-firmware are obtained.
[0093] At this time, the reliability of all sub-packet receiving processes will be improved through step-by-step verification of each packet, and when an abnormality is received, it will be convenient for technicians to quickly lock the abnormal data packet and perform corresponding vulnerability repairs.
[0094] Step S108: Based on the boot parameter of the boot program stored at the first address of the first boot area, the boot program area is directed to decrypt the encrypted firmware to be upgraded to obtain a new application program.
[0095] Specifically, based on steps S10402 to S10408, combined with Figure 5 As shown, the process of decrypting the encrypted firmware to be upgraded is as follows:
[0096] Step S10802: decrypt each group of encrypted sub-firmware to obtain corresponding groups of decrypted sub-firmware.
[0097] Step S10804: When it is determined that the last bit in the last set of decryption sub-firmware is digital data, confirm that the last set of decryption sub-firmware is filled with invalid data.
[0098] As above, when the filling is invalid data in the form of an arithmetic progression, step S10804 corresponds to: obtaining the last digit of the last set of decryption sub-firmware, and obtaining the difference in the number of bytes filled based on the preset starting number and the arithmetic progression.
[0099] Step S10806: Starting from the last digit of the last group of decryption sub-firmware, delete the same number of characters corresponding to the digital data.
[0100] Similarly, when the null data is filled with invalid data in the form of an arithmetic progression, step S10806 corresponds to deleting characters equal to the byte difference starting from the last digit of the last decryption sub-firmware. For example, if the preset starting number is 1, the arithmetic progression is 1, and the last digit of the obtained digital data is 8, the byte difference to be filled is 8, and 8 bits of invalid data are deleted starting from the last digit.
[0101] Step S10808: Sequentially splice the remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that has been subjected to invalid data deletion to obtain the new application program.
[0102] At this point, based on steps S10802 to S10808, the number of invalid data bits can be quickly identified and removed through the tail data. Similarly, to improve efficiency, it is possible to directly determine whether all bytes are multiples of 1024, and if the last group of bytes is not a multiple of 1024, continue to read them in groups of 16 bytes.
[0103] Step S110: After the old application in the application area is overwritten with the new application, the boot parameters of the application are copied from the third boot area and overwritten to the first address of the first boot area.
[0104] Step S112: Reset the MPU microprocessor to reload the new application program into it for execution.
[0105] Furthermore, considering that the upgrade process also includes other possible exceptions in addition to the firmware to be upgraded receiving exception, as a specific implementation method, combined with Figure 6 As shown, it also includes:
[0106] Step S202: An abnormality occurs in the MPU microprocessor and / or the Flash memory.
[0107] Step S204: When it is determined that the encrypted firmware to be upgraded is being received in the application area, the receiving process is terminated, and the receiving of the encrypted firmware to be upgraded is restarted based on the instruction of the host computer.
[0108] Step S206: When it is determined that the encrypted firmware to be upgraded is decrypted in the boot program area or the new application is used to overwrite the old application, the upgrade process is continued after restarting from the decryption of the encrypted firmware to be upgraded or the overwriting of the old application with the new application.
[0109] At this time, based on steps S202 to S206, the exceptions in different upgrade processes are handled differently. On the one hand, it ensures the smooth progress of the upgrade. On the other hand, it avoids the problem of entering an infinite loop when an exception occurs in the boot program area, and the power is cut off when the old application is half overwritten, and the problem of being unable to recover after powering on is avoided.
[0110] From the above, it can be seen that this embodiment designs a new online upgrade method based on IAP technology based on the principle that the system secondary boot program that comes with the MPU will choose to execute different programs according to the boot parameters of the Flash memory, thereby realizing the applicability of IAP technology on the MPU microprocessor. This embodiment not only has the advantages of simpler and more flexible programs, low development costs, and short cycles, but also has the characteristics of more stable updated applications. At the same time, in the original firmware encryption process to be upgraded, the limitation of the number of bytes of the AES encryption algorithm is solved by filling invalid data with frames that do not exceed a fixed length, and the value of the invalid data happens to be the number of invalid data filled in each frame of data; thus, the information security of the program is ensured.
[0111] The above program can be executed in a processor or stored in a memory (also known as a computer-readable storage medium). Computer-readable media includes permanent and non-permanent, removable and non-removable media, and can be implemented using any method or technology to store information. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. As defined in this embodiment, computer-readable media does not include temporary computer-readable media, such as modulated data signals and carrier waves.
[0112] These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps of the functions specified in one or more blocks can be implemented by different modules corresponding to different steps.
[0113] Correspondingly, this embodiment also provides an online upgrade system for MPU microprocessors, which is built based on the method. Figure 7 As shown, the system includes the following functional modules:
[0114] The application running module is used for powering on the MPU microprocessor to trigger reading the boot parameters of the application stored in the first boot area, and then pointing to the application area to load the application in it into the MPU microprocessor for execution.
[0115] The first storage module is used to trigger the storage of the encrypted firmware to be upgraded to the upgrade program area based on the upgrade instruction obtained by the application during operation.
[0116] The second storage module is used for automatically restarting the MPU microprocessor after the application area receives the encrypted firmware to be upgraded, and triggering the copying of the boot parameters of the boot program from the second boot area to the first address of the first boot area.
[0117] The third storage module directs the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application program based on the boot program boot parameter stored at the first address of the first boot area.
[0118] The fourth storage module, after overwriting the old application in the application area with the new application, triggers the copying of the boot parameters of the application from the third boot area and overwrites the boot parameters to the first address of the first boot area.
[0119] The reset operation module is used to reset the MPU microprocessor to reload the new application program into it for operation.
[0120] Since the system is built based on the method, what has been described above will not be repeated here.
[0121] For example, the system further includes:
[0122] The grouping module is used to group the firmware to be upgraded in sequence according to a preset number of bytes to obtain several groups of sub-firmware.
[0123] The calculation module is configured to obtain a byte difference between the byte number of the last group of sub-firmware and the preset byte number when determining that the byte number of the last group of sub-firmware is not equal to the preset byte number.
[0124] A filling module is used to fill the last group of sub-firmware with invalid data of the byte number difference starting from the first empty bit of the last group of sub-firmware so that the final number of bytes is equal to the preset number of bytes; wherein each invalid data filled is the byte number difference.
[0125] The encryption module is used to encrypt all group sub-firmware based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
[0126] For another example, the third storage module includes:
[0127] The decryption unit is configured to decrypt all group-encrypted sub-firmware to obtain all group-decrypted sub-firmware.
[0128] The judging unit is configured to, when judging that the last bit of the last set of decryption sub-firmware is digital data, confirm that the last set of decryption sub-firmware is filled with invalid data.
[0129] The deleting unit is used to delete the same number of characters corresponding to the digital data starting from the last bit of the last group of decryption sub-firmware.
[0130] The splicing unit is used to sequentially splice the remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that has been subjected to invalid data deletion to obtain the new application program.
[0131] Combine Figure 8 As shown, this embodiment further provides an electronic device, including at least one processor, wherein the processor is coupled to a memory, wherein a computer program is stored in the memory, and the computer program is configured to execute the method when executed by the processor.
[0132] Similarly, this embodiment further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a computer, the method described above is implemented.
[0133] Since the system, electronic device and computer-readable storage medium are all used to implement the method, or are built based on the method, in actual application, they also have the technical advantages of a simpler and more flexible program update process, a more stable updated program, and correspondingly lower development costs and a shorter cycle.
[0134] While the present invention has been disclosed above with reference to preferred embodiments, this is not intended to limit the present invention. Persons skilled in the art will readily appreciate that various modifications and variations can be made without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be determined by the claims.
Claims
1. An online upgrade method applicable to an MPU microprocessor, characterized in that: include: The mapping diagram of the MPU program in the external Flash memory connected to the MPU program is set as follows: starting from the first position, the mapping areas are sequentially included: the first boot area, the second boot area, the boot program area, the third boot area, the application area and the upgrade program area; wherein the first boot area is used to store the boot parameters of the application and the boot parameters of the boot program; the second boot area is used to store the boot parameters of the boot program, and the third boot area is used to store the boot parameters of the application; wherein, during the update process, the update progress prompt is performed based on the update of the boot parameters stored in the first address in the first boot area, and the update step is triggered to jump in each program storage area and each boot storage area; And includes the following steps: The MPU microprocessor is powered on to trigger reading of the boot parameters of the application stored in the first boot area, and then points to the application area to load the application in it into the MPU microprocessor for execution; Based on the upgrade instruction obtained by the application program during operation, the encrypted firmware to be upgraded is stored in the upgrade program area; After the application area receives the encrypted firmware to be upgraded, the MPU microprocessor automatically restarts and triggers the copying of boot parameters of the boot program from the second boot area to the first address of the first boot area; Based on the boot parameter of the boot program stored at the first address of the first boot area, the boot program area is directed to decrypt the encrypted firmware to be upgraded to obtain a new application program; After overwriting the old application in the application area with the new application, triggering the boot parameter of copying the application from the third boot area and overwriting it to the first address of the first boot area; Resetting the MPU microprocessor to reload the new application program into it for execution; If an exception occurs during the upgrade process, the following steps are also included: An abnormality occurs in the MPU microprocessor and / or the Flash memory; When it is determined that the encrypted firmware to be upgraded is being received in the application area, the receiving is terminated, and the receiving of the encrypted firmware to be upgraded is restarted based on the receiving instruction of the host computer; When it is determined that the encrypted firmware to be upgraded is decrypted in the boot program area, or the new application is used to overwrite the old application, the upgrade process is continued after restarting from the decryption of the encrypted firmware to be upgraded, or the new application is used to overwrite the old application.
2. The online upgrade method applicable to the MPU microprocessor according to claim 1, characterized in that: The method triggers the storage of the encrypted firmware to be upgraded to the upgrade program area based on the upgrade instruction obtained during the operation of the application program; comprising: Sequentially grouping the original firmware to be upgraded according to a preset number of bytes to obtain a plurality of groups of sub-firmware; When it is determined that the number of bytes of the last group of sub-firmware is not equal to the preset number of bytes, obtaining a byte difference between the number of bytes of the last group of sub-firmware and the preset number of bytes; Starting from the first free bit of the last group of sub-firmware, fill the last group of sub-firmware with invalid data equal to the byte number difference so that the final number of bytes is equal to the preset number of bytes; wherein each of the invalid data filled is the byte number difference; All group sub-firmware are encrypted based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
3. The online upgrade method applicable to the MPU microprocessor according to claim 2, characterized in that: The boot parameter of the boot program stored based on the first address of the first boot area instructs the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application program; including: decrypting each group of encrypted sub-firmware to obtain corresponding groups of decrypted sub-firmware; When determining that the last bit in the last set of decryption sub-firmware is digital data, confirming that the last set of decryption sub-firmware is filled with invalid data; From the last digit of the last group of decryption sub-firmware, delete the same number of characters corresponding to the digital data; The remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that has been invalid data deleted are sequentially spliced to obtain the new application.
4. The online upgrade method applicable to the MPU microprocessor according to claim 2, characterized in that: The application area receives the encrypted firmware to be upgraded; including: After determining that a group of encrypted sub-firmware is received successfully, triggering the reception of the next group of encrypted sub-firmware that is sequentially adjacent to it; otherwise, terminating the reception and sending an alarm feedback to the host computer; wherein the alarm feedback includes the number of groups corresponding to the abnormally received encrypted sub-firmware; The previous step is repeated until all group-encrypted sub-firmware are obtained.
5. An online upgrade system suitable for an MPU microprocessor, characterized in that: include: The mapping diagram of the MPU program in the external Flash memory connected to the MPU program is set as follows: starting from the first position, the mapping areas are sequentially included: the first boot area, the second boot area, the boot program area, the third boot area, the application area and the upgrade program area; wherein the first boot area is used to store the boot parameters of the application and the boot parameters of the boot program; the second boot area is used to store the boot parameters of the boot program, and the third boot area is used to store the boot parameters of the application; wherein, during the update process, the update progress prompt is performed based on the update of the boot parameters stored in the first address in the first boot area, and the update step is triggered to jump in each program storage area and each boot storage area; And includes the following modules: An application running module, used for powering on the MPU microprocessor to trigger reading the boot parameters of the application stored in the first boot area, and then pointing to the application area to load the application in it into the MPU microprocessor for running; A first storage module, used for triggering the storage of the encrypted firmware to be upgraded to the upgrade program area based on the upgrade instruction obtained by the application during operation; A second storage module is used for automatically restarting the MPU microprocessor after the application area receives the encrypted firmware to be upgraded, and triggering the boot parameters of the boot program to be copied from the second boot area to the first address of the first boot area; A third storage module, based on the boot parameter of the boot program stored at the first address of the first boot area, directs the boot program area to decrypt the encrypted firmware to be upgraded to obtain a new application program; A fourth storage module, after overwriting the old application in the application area with the new application, triggers the boot parameter of copying the application from the third boot area and overwriting it to the first address of the first boot area; A reset operation module, used for resetting the MPU microprocessor to reload the new application program therein for operation; If an exception occurs during the upgrade process, the following steps are also included: An abnormality occurs in the MPU microprocessor and / or the Flash memory; When it is determined that the encrypted firmware to be upgraded is being received in the application area, the receiving is terminated, and the receiving of the encrypted firmware to be upgraded is restarted based on the receiving instruction of the host computer; When it is determined that the encrypted firmware to be upgraded is decrypted in the boot program area, or the new application is used to overwrite the old application, the upgrade process is continued after restarting from the decryption of the encrypted firmware to be upgraded, or the new application is used to overwrite the old application.
6. The online upgrade system suitable for MPU microprocessor according to claim 5, characterized in that: include: A grouping module, used for grouping the original firmware to be upgraded in sequence according to a preset number of bytes to obtain several groups of sub-firmware; A calculation module, configured to obtain a byte difference between the byte number of the last group of sub-firmware and the preset byte number when determining that the byte number of the last group of sub-firmware is not equal to the preset byte number; A filling module, used for filling the last group of sub-firmware with invalid data of the byte number difference starting from the first free bit of the last group of sub-firmware so that the final number of bytes is equal to the preset number of bytes; wherein each of the invalid data filled is the byte number difference; The encryption module is used to encrypt all group sub-firmware based on the AES encryption algorithm to serve as the encrypted firmware to be upgraded.
7. The online upgrade system suitable for an MPU microprocessor according to claim 6, characterized in that: The third storage module includes: A decryption unit, used for decrypting each group of encrypted sub-firmware to obtain each corresponding group of decrypted sub-firmware; a judging unit, configured to judge that when the last bit in the last set of decryption sub-firmware is digital data, confirm that the last set of decryption sub-firmware is filled with invalid data; a deleting unit, used for deleting a number of characters corresponding to the digital data starting from the last digit of the last group of decryption sub-firmware; The splicing unit is used to sequentially splice the remaining groups of decryption sub-firmware and the last group of decryption sub-firmware that deletes invalid data to obtain the new application program.
8. An electronic device, characterized in that: The method comprises at least one processor, wherein the processor is coupled to a memory, wherein a computer program is stored in the memory, and wherein the computer program is configured to execute the method according to any one of claims 1 to 4 when executed by the processor.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Program upgrading method and system, application system, and storage medium
CN109358883A