Firmware upgrading method and device, first equipment and computer readable storage medium
By using the upgrade module and single-wire interface in a single-wire half-duplex UART device to parse and write firmware upgrade messages, the convenience of firmware upgrade problem of single-wire half-duplex UART device is solved, and efficient firmware upgrade without additional hardware is achieved.
Patent Information
- Application Number
- CN202510455097.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-06-20
AI Technical Summary
The prior art is difficult to easily upgrade the firmware of single-line half-duplex UART devices, especially without relying on additional hardware.
Receive messages from the second device through a single-line interface, parse the message content, determine the message type, and in the case of firmware upgrade messages, write the upgrade data to the firmware storage area through the upgrade module, while ensuring that the upgrade module has control permissions of the firmware storage area.
It realizes convenient upgrade of firmware to single-line interface devices without additional hardware, improving the success rate of firmware upgrades and the continuous online service of the device.
Smart Images

Figure CN120179270A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a firmware upgrade method, apparatus, first device, and computer-readable storage medium. Background Art
[0002] The Universal Asynchronous Receiver / Transmitter (UART) is a protocol widely used in full-duplex communication. It realizes bidirectional data transmission through two lines (one for sending and one for receiving). However, with the rising cost of chip manufacturing and the limitation of space occupation, the single-wire half-duplex UART protocol has gradually become an alternative solution. Through the design of hardware circuits, the single-wire half-duplex UART protocol multiplexes the sending end and the receiving end of the UART protocol on the same physical line, and uses firmware to control tri-state gates or switch circuits to implement the switching of the sending and receiving modes. The single-wire half-duplex UART interface is not connected to the UART serial port of the Micro controller Unit (MCU) itself, but serves as an interface for protocol communication. The single-wire half-duplex UART interface has been widely used in devices with limited space or simplified interfaces, such as fast charging interface chips, micro sensors, wearable devices, etc.
[0003] Currently, the mainstream firmware upgrade solutions include: using a dedicated hardware interface for firmware upgrade. This method requires additional configuration of a dedicated hardware interface on the device, which is contrary to the hardware constraints of single-wire half-duplex UART devices. Or, forcing the device into the firmware upgrade mode through a physical button. This method also requires the configuration of an additional physical button and manual intervention, making the operation inconvenient. Therefore, how to conveniently upgrade the firmware of single-wire half-duplex UART devices is a technical problem that needs to be solved urgently. Summary of the Invention
[0004] This application discloses a firmware upgrade method, apparatus, first device, and computer-readable storage medium, which can conveniently upgrade the firmware of single-wire interface devices without relying on additional hardware.
[0005] In a first aspect, an embodiment of the present application provides a firmware upgrade method, which can be applied to a first device or a device (such as a chip or a processor, etc., which is a device inside the first device) that matches the first device. The first device at least includes a single-wire interface, an upgrade module, and a firmware storage area. Among them, the method includes: receiving a first message from a second device through the single-wire interface; parsing the first message to obtain first parsing content; based on the first parsing content, determining the message type of the first message, and the message type includes a communication message and a firmware upgrade message; when the message type of the first message is a firmware upgrade message and the control right of the firmware storage area belongs to the upgrade module, writing the first upgrade data in the first parsing content into the firmware storage area through the upgrade module.
[0006] In this technical solution, before writing the first upgrade data into the firmware storage area, the upgrade module first confirms that the control right of the firmware storage area belongs to the upgrade module, which is beneficial to ensuring that the upgrade module can successfully write the first upgrade data into the firmware storage area subsequently. It can be seen that by implementing the embodiment of the present application, it is possible to conveniently upgrade the firmware of the single-wire interface device without relying on additional hardware.
[0007] Combined with the first aspect, in a possible implementation manner, the first device further includes a first control module, and the first control module at least includes an MCU; the method further includes: when the message type of the first message is a firmware upgrade message, stopping authorizing the control right of the firmware storage area to the first control module; authorizing the control right of the firmware storage area to the upgrade module.
[0008] In this technical solution, by stopping authorizing the control right of the firmware storage area to the first control module and authorizing the control right of the firmware storage area to the upgrade module, on the one hand, it is beneficial to ensuring that the upgrade module can successfully write the first upgrade data into the firmware storage area subsequently. On the other hand, it can avoid the first control module or the MCU from operating on the firmware storage area during the firmware upgrade process, thereby avoiding interference with the firmware upgrade, which is beneficial to improving the success rate of the firmware upgrade.
[0009] Combined with the first aspect, in a possible implementation manner, the method further includes: when the message type of the first message is a firmware upgrade message, controlling the MCU to enter a low-power state.
[0010] In this technical solution, after the MCU enters the low-power state, the MCU will not operate on the firmware storage area. In this way, on the one hand, it can avoid the MCU from operating on the firmware storage area during the firmware upgrade process, thereby avoiding interference with the firmware upgrade, which is beneficial to improving the success rate of the firmware upgrade. On the other hand, controlling the MCU to enter the low-power state can reduce the power consumption of the first device as much as possible to extend the battery life or reduce energy consumption.
[0011] In combination with the first aspect, in a possible implementation, the method further includes: masking an interrupt when the message type of the first message is a firmware upgrade message.
[0012] In this technical solution, it can be ensured that the MCU will not be awakened by an interrupt, thereby avoiding the MCU operating on the firmware storage area during the firmware upgrade process, and thus avoiding interference with the firmware upgrade, which is conducive to improving the success rate of the firmware upgrade.
[0013] In combination with the first aspect, in a possible implementation, the second parsing content obtained by parsing the firmware upgrade message includes multiple frames, and each frame in the multiple frames includes a start bit, a data bit, a check bit, and an end bit; the multiple frames include a header frame and a check frame, and also include a first content frame or multiple second content frames; wherein, the data bit of the header frame includes the message header of the firmware upgrade message; the data bit of the check frame includes the check field of the firmware upgrade message; the data bit of the first content frame includes a response command.
[0014] The multiple second content frames include a command frame, an address frame, a data length frame, and at least one data frame; wherein, the data bit of the command frame includes a write command or a read command; when the data bit of the command frame includes a write command, the data bit of the at least one data frame includes the upgrade data in the second parsing content, the data bit of the address frame includes the starting address where the upgrade data in the second parsing content is written to the firmware storage area, and the data bit of the data length frame includes the data length of the upgrade data in the second parsing content; when the data bit of the command frame includes a read command, the data bit of the address frame includes the starting address of the firmware data to be read from the firmware storage area, and the data bit of the data length frame includes the data length of the firmware data.
[0015] In combination with the first aspect, in a possible implementation, the data bit of one data frame in the at least one data frame occupies at least one byte.
[0016] In combination with the first aspect, in a possible implementation, the method further includes: determining the address range corresponding to the first upgrade data in the first parsing content based on the starting address included in the data bit of the address frame in the first parsing content and the data length included in the data bit of the data length frame in the first parsing content; writing the first upgrade data in the first parsing content into the firmware storage area through an upgrade module, including: writing the first upgrade data into the address range in the firmware storage area through the upgrade module.
[0017] In this technical solution, even if only the starting address is provided, the complete address range where the first upgrade data is written can be obtained by incrementing the address, which can support continuous writing of multi-byte upgrade data.
[0018] In combination with the first aspect, in a possible implementation, the method further includes: when a second condition is satisfied, stopping authorizing the control right of the firmware storage area to the upgrade module; wherein, the second condition includes: the firmware upgrade is completed, or, a preset preemption signal is received; authorizing the control right of the firmware storage area to the first control module.
[0019] In this technical solution, after the firmware upgrade is completed, the control right of the firmware storage area is re-authorized to the first control module to facilitate re-entering the normal communication mode. Or, in the case of high-priority services or emergency services, the first device can pause the firmware upgrade process and give priority to processing high-priority services or emergency services by stopping authorizing the control right of the firmware storage area to the upgrade module and re-authorizing the control right of the firmware storage area to the first control module. In other words, it can support the processing of other services inserted during the firmware upgrade process, which can better handle emergencies and is beneficial to improving the intelligence of the system.
[0020] In combination with the first aspect, in a possible implementation, the preset preemption signal is used to indicate the existence of an emergency service, and the first upgrade data in the first parsed content corresponds to a new firmware version; after authorizing the control right of the firmware storage area to the first control module, the method further includes: reading the firmware corresponding to the old firmware version in the firmware storage area through the MCU and processing the emergency service.
[0021] In combination with the first aspect, in a possible implementation, the first device further includes a communication module, and the method further includes: when the message type of the first message is a communication message, processing the first parsed content through the communication module.
[0022] In this technical solution, the single-wire interface can realize dynamic time-division multiplexing of the normal communication function and the firmware upgrade function, so that the firmware upgrade can be completed without interrupting the normal service communication, which is beneficial to improving the continuity of the online service of the first device.
[0023] In combination with the first aspect, in a possible implementation, the parsed content obtained by parsing the firmware upgrade message includes a digital signature; when the message type of the first message is a firmware upgrade message, stopping authorizing the control right of the firmware storage area to the first control module includes: when the message type of the first message is a firmware upgrade message, verifying the digital signature in the first parsed content; when the digital signature in the first parsed content is verified, stopping authorizing the control right of the firmware storage area to the first control module.
[0024] In this technical solution, by carrying a digital signature in the firmware upgrade message, it is beneficial to avoid accidentally triggering the first device to enter the firmware upgrade mode and prevent illegal injection of firmware.
[0025] In a second aspect, an embodiment of the present application provides a firmware upgrade device, which includes a unit for implementing the method described in the first aspect.
[0026] In a third aspect, an embodiment of the present application provides a first device, which at least includes a single-wire interface, a parsing module, a communication module, a second control module, an upgrade module, and a firmware storage area; wherein,
[0027] The single-wire interface is used to receive a first message from a second device;
[0028] The parsing module is used to parse the first message to obtain first parsing content; based on the first parsing content, determine the message type of the first message, and the message type includes a communication message and a firmware upgrade message; when the message type of the first message is a firmware upgrade message, send the first parsing content to the communication module;
[0029] The communication module is used to verify the digital signature in the first parsing content, and when the digital signature in the first parsing content is verified successfully, send a first indication to the second control module, and the first indication is used to indicate that the digital signature is verified successfully;
[0030] The second control module is used to, in response to the first indication, when the control right of the firmware storage area belongs to the upgrade module, send a second indication to the parsing module, and the second indication is used to indicate that the parsing module sends the first upgrade data in the first parsing content to the upgrade module;
[0031] The parsing module is further used to, in response to the second indication, send the first upgrade data to the upgrade module;
[0032] The upgrade module is used to write the first upgrade data into the firmware storage area.
[0033] In combination with the third aspect, in a possible implementation manner, the first device further includes a first control module, and the first control module at least includes an MCU; the second control module is used to, in response to the first indication, send a third indication to the first control module and send a fourth indication to the upgrade module; wherein, the third indication is used to indicate to stop authorizing the control right of the firmware storage area to the first control module, and the fourth indication is used to indicate to authorize the control right of the firmware storage area to the upgrade module.
[0034] In a fourth aspect, an embodiment of the present application provides another first device, which includes a single-wire interface, a memory, and at least one processor; wherein, the at least one memory is used to store a computer program or instruction, and the at least one processor is used to call the computer program or instruction from the at least one memory and run the computer program or instruction to execute the method described in the first aspect.
[0035] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program or computer instructions, and when the computer program or computer instructions are executed, the processor is caused to execute the method described in the first aspect.
[0036] In a sixth aspect, an embodiment of the present application provides a computer program product including a computer program or instructions, and when the computer program or instructions run on an electronic device (such as the first device), the electronic device is caused to execute the method described in the first aspect. Description of the Drawings
[0037] Figure 1 is a schematic diagram of an application scenario applicable to an embodiment of the present application;
[0038] Figure 2a is a schematic flowchart of a firmware upgrade method provided by an embodiment of the present application;
[0039] Figure 2b is a schematic diagram of relevant processing performed by each module in the first device after the first device receives a first message in an embodiment of the present application;
[0040] Figure 3 is a schematic diagram of the frame structure of each frame in the second parsed content provided by an embodiment of the present application;
[0041] Figure 4 is a schematic diagram of the frame types included in the second parsed content provided by an embodiment of the present application;
[0042] Figure 5 is a schematic diagram of the specific structure of each frame in the first parsed content provided by an embodiment of the present application;
[0043] Figure 6 is a schematic diagram of relevant processing performed by each module in the first device when the firmware upgrade ends in an embodiment of the present application;
[0044] Figure 7 is a schematic diagram of relevant processing performed by each module in the first device when a preset preemption signal is received in an embodiment of the present application;
[0045] Figure 8 is a schematic diagram of the state transition process of a data parsing state machine provided by an embodiment of the present application;
[0046] Figure 9 is a schematic diagram of the state transition process of an upgrade protocol state machine provided by an embodiment of the present application;
[0047] Figure 10It is a schematic structural diagram of a firmware upgrade device provided by an embodiment of the present application;
[0048] Figure 11 It is a schematic structural diagram of a first device provided by an embodiment of the present application. Specific embodiments
[0049] In the embodiments of the present application, terms such as "first" and "second" are used to distinguish different objects, rather than to describe a specific order. "At least one" in the embodiments of the present application refers to one or more, and multiple refers to two or more. "And / or" in the embodiments of the present application describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent the following three situations: A exists alone, A and B exist simultaneously, and B exists alone. Among them, A and B can be singular or plural.
[0050] "At least one (item)" or similar expressions in the embodiments of the present application refer to any combination of these items, including any combination of single item (item) or multiple items (items). For example, at least one (item) of a, b, or c can represent the following seven situations: a, b, c, a and b, a and c, b and c, a, b, and c. Among them, each of a, b, and c can be an element or a set containing one or more elements.
[0051] In the embodiments of the present application, "indicating" can include direct indication and indirect indication, and can also include explicit indication and implicit indication. Assuming that the information to be indicated is called the to-be-indicated information, in the specific implementation process, there are many ways to indicate the to-be-indicated information. For example, the to-be-indicated information can be directly indicated, such as indicating the to-be-indicated information itself or the index of the to-be-indicated information, etc. For another example, the to-be-indicated information can also be indirectly indicated by indicating other information, and there is an association relationship between the indicated other information and the to-be-indicated information. For another example, only a part of the to-be-indicated information can be indicated, while the other parts of the to-be-indicated information are known or pre-agreed.
[0052] Please refer to Figure 1 , Figure 1 It is a schematic diagram of an application scenario applicable to the embodiments of the present application. This application scenario may include, but is not limited to, a first device 10 and a second device 11.
[0053] Among them, the first device 10 refers to a single-wire interface device. The first device 10 can be connected to an external device through a single-wire interface and communicate with it. Among them, the external device can be Figure 1 the second device 11 shown.
[0054] The first device 10 may include, but is not limited to, the following components: a single-wire interface 101, a single-wire protocol system 102, a firmware storage area 103, and a first control module 104. Optionally, the first device 10 may further include a second control module 105. The second control module may also be referred to as a system control module, a general control module, a system controller, a general controller, or other names, which are not limited in the embodiments of the present application.
[0055] Optionally, the single-wire protocol system 102 may include an upgrade module 1021. Optionally, the single-wire protocol system 102 may further include a parsing module 1022 and a communication module 1023. Optionally, the first control module 104 may include an MCU 1041 or other components having control authority over the firmware storage area 103, which are not limited in the embodiments of the present application.
[0056] Figure 1 In the figure, the modules shown by the dashed lines are optional modules. That is to say, the first device may include Figure 1 the optional modules shown, or may not include Figure 1 the optional modules shown.
[0057] Figure 1 In the figure, the solid arrows indicate the information transmission directions that may be involved in the firmware upgrade mode, and the dashed arrows indicate the information transmission directions that may be involved in the normal communication mode. The normal communication mode may also be referred to as a non-firmware upgrade mode. For example, in the normal communication mode, the MCU 1041 may read MCU instructions such as startup codes from the firmware storage area 103. This process involves the transmission of MCU instructions from the firmware storage area 103 to the MCU 1041, such as Figure 1 the dashed arrow from the firmware storage area 103 pointing to the MCU 1041 shown. Another example is that in the firmware upgrade mode, the single-wire protocol system 101 may perform data and instruction interactions with the firmware storage area 103 through the upgrade module 1021 to complete the firmware upgrade.
[0058] The single-wire interface 101 in the embodiments of the present application may include, but is not limited to: a single-wire UART interface, a single-wire Serial Peripheral Interface (SPI), a single-wire Controller Area Network (CAN) interface, a single-wire Local Interconnect Network (LIN) interface, or other single-wire interfaces. The single-wire interface may also be referred to as a single-wire half-duplex interface. For example, the single-wire UART interface may also be referred to as a single-wire half-duplex UART interface.
[0059] The single-wire protocol refers to the rules and standards for data communication on a single wire. The single-wire protocol system 102 is used to achieve the effective transmission of data on a single wire through the single-wire protocol. The single-wire protocol in the embodiments of the present application may include, but is not limited to: single-wire UART protocol, single-wire LIN protocol, or other single-wire protocols. The single-wire protocol can also be referred to as a single-wire half-duplex protocol. For example, the single-wire UART protocol can also be referred to as a single-wire half-duplex UART protocol.
[0060] The first control module 104 refers to a component that has control authority over the firmware storage area 103. For example, the first control module 104 may include an MCU 1041. The MCU 1041, also known as a Single Chip Microcomputer or a microcontroller, is a computer-on-a-chip that integrates the frequency and specifications of a Central Process Unit (CPU) with peripherals such as memory, counters, Universal Serial Bus (USB), analog-to-digital conversion, UART, and PLC to provide different combinations of control for different applications.
[0061] The firmware storage area 103 refers to the storage space for saving firmware. For example, the firmware storage area 103 can be the storage space of a non-volatile memory, and the non-volatile memory may include, but is not limited to: flash memory, Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM).
[0062] Firmware may include program code written for specific hardware components. Optionally, firmware may also include configuration parameters, user settings, and other important data. Firmware is responsible for low-level hardware operations such as initializing hardware components, data transmission, power management, and other underlying functions.
[0063] The firmware mentioned in the embodiments of the present application can be the firmware of the MCU 1041 or the firmware of other hardware components. Taking the example that the firmware storage area 103 stores the firmware of the MCU 1041, when the first device 10 starts up, the MCU 1041 can read MCU instructions such as startup codes from the firmware storage area 103 to initialize the hardware and load the operating system or the main application program.
[0064] The embodiments of the present application do not limit the forms of the first device 10 and the second device 11. For example, the form of the first device 10 may include but is not limited to: charger, single-wire temperature sensor, smart lock, keyboard, mouse, wearable device, etc. The form of the second device 11 may include but is not limited to: mobile phone, tablet computer, desktop computer, laptop computer, all-in-one computer or other terminal devices.
[0065] It can be understood that the application scenarios described in the embodiments of the present application are for more clearly explaining the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those skilled in the art know that with the evolution of technology and the emergence of new business scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
[0066] The firmware upgrade method proposed in the embodiments of the present application is described below. This firmware upgrade method can be executed by the first device and the second device, or by a device matching the first device (such as a chip or a processor, etc., a device placed inside the first device), and a device matching the second device (such as a chip or a processor, etc., a device placed inside the second device). The embodiments of the present application are described by taking the firmware upgrade method being executed by the first device and the second device as an example. Among them, the first device can be Figure 1 the first device 10 shown, and the second device 11 can be Figure 1 the second device 11 shown. For specific details, please refer to Figure 1 the description of the application scenario shown. Details are not described herein again. Among them, the first device at least includes a single-wire interface, an upgrade module, and a firmware storage area. The first device is connected to the second device through the single-wire interface and communicates with it.
[0067] Please refer to Figure 2a , Figure 2a which is a schematic flowchart of a firmware upgrade method provided by the embodiments of the present application. As Figure 2a shown, this firmware upgrade method may include but is not limited to the following steps.
[0068] S201: The first device receives a first message from the second device through the single-wire interface.
[0069] In the embodiments of the present application, the first device can interact with the second device through the single-wire interface. For example, the second device can send normal service messages to the first device through the single-wire interface.
[0070] Optionally, taking a normal service message including a version query instruction as an example, after receiving the normal service message, the first device can extract and execute the version query instruction, that is, query the version number of the current firmware of the first device, and then send a first response message to the second device. The first response message can indicate the version number of the current firmware of the first device. After receiving the first response message, the second device can compare the version number indicated by the first response message (hereinafter referred to as the second version number) with the first version number of the firmware. If the version numbers are different, the second device can initiate a firmware upgrade process for the first device.
[0071] Among them, the first version number is the version number expected by the second device. For example, the first version number can be the latest version number of the firmware. In this case, the second device expects to upgrade the firmware of the first device to the latest version. Another example is that the first version number can be the version number of any version of the firmware. In this case, the second device expects to upgrade the firmware of the first device to the expected version number. It can be understood that the expected version number may not be the latest version number.
[0072] Among them, the first message can be any message carrying upgrade data, and the upgrade data is used to upgrade the firmware of the first device. The version number of the firmware corresponding to the upgrade data is the first version number. Or, the first message can be a normal communication message sent by the second device to the first device, and the normal communication message is not used for upgrading the firmware of the first device.
[0073] Optionally, taking the first message as any message carrying upgrade data as an example, the upgrade data carried in the first message can be all or part of the data of the firmware corresponding to the first version number. Or, the upgrade data carried in the first message can be all or part of the differential data, and the differential data includes the differential part between the firmware corresponding to the first version number and the firmware corresponding to the second version number. In other words, the second device can upgrade the firmware of the first device by means of full update or incremental update.
[0074] In a possible implementation manner, before the second device sends a message (such as the first message) carrying upgrade data to the first device, it can also send an upgrade request to the first device. After receiving the upgrade request, the first device can prepare for firmware upgrade so that it can upgrade faster after receiving the upgrade data subsequently.
[0075] In a possible implementation manner, after the first device completes the firmware upgrade preparation, it can send a second response message to the second device through a single-wire interface. The second response message can indicate that the first device has completed the firmware upgrade preparation. After receiving the second response message, the second device can start sending upgrade data to the first device, that is, it can start sending the first message to the first device.
[0076] S202: Parse the first message to obtain the first parsed content.
[0077] In a possible implementation, the first device can parse the message received by the parsing module (such as the first message).
[0078] Taking the first message, which is transmitted on a single-wire interface following the single-wire UART protocol, as an example, the parsing module can parse the first message based on the single-wire UART protocol to obtain the parsed content of the first message (hereinafter referred to as the first parsed content).
[0079] S203: Based on the first parsed content, determine the message type of the first message. The message types include communication messages and firmware upgrade messages.
[0080] In a possible implementation, the first device can determine the message type of the first message through the parsing module.
[0081] Optionally, when the message type of the first message is a firmware upgrade message, the first parsed content can at least include first upgrade data. The first upgrade data can be all or part of the data of the firmware corresponding to the first version number, or the first upgrade data can be all or part of the differential data, where the differential data includes the differential part between the firmware corresponding to the first version number and the firmware corresponding to the second version number.
[0082] Optionally, when the message type of the first message is a firmware upgrade message, the parsing module can at least send the first upgrade data in the first parsed content to the upgrade module, and the upgrade module performs firmware upgrade based on the first upgrade data.
[0083] Optionally, when the message type of the first message is a communication message, the parsing module can send the first parsed content or the data content in the first parsed content to the communication module, and the communication module processes the received content. For example, the communication module can forward the received content to the MCU, or forward some of the received content to the MCU.
[0084] Optionally, when the message type of the first message is a communication message, the parsing module can store the first parsed content or the data content in the first parsed content in the register of the communication module. When the message type of the first message is a firmware upgrade message, the parsing module can store the first parsed content or the data content in the first parsed content in the register of the upgrade module.
[0085] It can be seen that in this way, the single-wire interface can achieve dynamic time-division multiplexing of the normal communication function and the firmware upgrade function. Specifically, the physical layer multiplexing of the firmware upgrade protocol and the communication protocol can be implemented within the single-wire interface, so that there is no need to switch to an independent debugging interface or expand the hardware circuit, and the firmware upgrade can be completed without interrupting the normal service communication, which is beneficial to improving the continuity of the online service of the first device.
[0086] It should be noted that the packet structure of the data packet of the message type of communication message can be determined based on the single-wire protocol followed on the single-wire interface. Different single-wire protocols may adopt different packet structures.
[0087] S204: When the message type of the first message is a firmware upgrade message and the control right of the firmware storage area belongs to the upgrade module, the first upgrade data in the first parsing content is written into the firmware storage area by the upgrade module.
[0088] In a possible implementation manner, after receiving the first upgrade data, if the control right of the firmware storage area belongs to the upgrade module, the upgrade module may send an erase instruction to the firmware storage area, and the firmware storage area executes the erase instruction to erase the data stored in the firmware storage area, that is, erase the data of the firmware corresponding to the second version number. After the firmware storage area finishes erasing, the upgrade module may send a write instruction to the firmware storage area, and the firmware storage area executes the write instruction to write the first upgrade data into the firmware storage area. The first device executes S202 - S204 for all received firmware upgrade messages, and can write all the data or all the differential data of the firmware corresponding to the first version number into the firmware storage area, thereby completing the firmware upgrade.
[0089] Before writing the first upgrade data into the firmware storage area, the upgrade module first confirms that the control right of the firmware storage area belongs to the upgrade module, which is beneficial to ensuring that the upgrade module can smoothly write the first upgrade data into the firmware storage area in the future. It can be seen that by implementing the embodiments of the present application, the firmware of the single-wire interface device can be conveniently upgraded without relying on additional hardware.
[0090] In a possible implementation manner, the meaning that the control right of the firmware storage area belongs to the upgrade module is that the control right of the firmware storage area is uniquely owned by the upgrade module. In other words, except for the upgrade module, other modules do not have the control right over the firmware storage area. Optionally, the control right of the firmware storage area may include, but is not limited to, read permission, write permission, erase permission, access permission, etc.
[0091] In a possible implementation, the parsed content obtained by parsing the firmware upgrade message (hereinafter referred to as the second parsed content) may include a digital signature. That is to say, in addition to including the first upgrade data, the first parsed content may also include a digital signature. When the message type of the first message is a firmware upgrade message, the first device may verify the digital signature in the first parsed content. When the digital signature in the first parsed content is verified successfully, S204 is executed. The first device may verify the digital signature in the first parsed content based on the public key. Optionally, the public key may be obtained by the first device itself or stored in advance. Alternatively, in addition to including the first upgrade data and the digital signature, the first parsed content may also include the public key. Optionally, when the first device determines that the message type of the first message is a firmware upgrade message through the parsing module, it may send the first parsed content to the communication module, and the communication module is used to verify the digital signature in the first parsed content. By carrying a digital signature in the firmware upgrade message, it is beneficial to avoid accidentally triggering the first device to enter the firmware upgrade mode and prevent illegal firmware injection.
[0092] Optionally, when the digital signature in the first parsed content is verified to fail, the first device may discard the first parsed content. Optionally, when the digital signature in the first parsed content is verified to fail, the first device may send a negative acknowledgment (NACK) to the second device. Optionally, when the digital signature in the first parsed content is verified to fail, the first device may not enter the firmware upgrade mode (or exit the firmware upgrade mode) and resume the normal communication mode.
[0093] Optionally, when the digital signature in the first parsed content is verified to succeed, the first device may send an affirmative acknowledgment ACK to the second device so that the second device can continue to send the remaining upgrade data. Optionally, the second device may transmit the upgrade data of the new firmware in batches and continue to send the remaining upgrade data after receiving the ACK feedback from the first device, which is beneficial to reducing the link idle waiting time.
[0094] In a possible implementation, the first device may further include a first control module, and the first control module at least includes an MCU. In the normal communication mode, the control authority of the firmware storage area may belong to the first control module or belong to the MCU.
[0095] In a possible implementation, before S204, the first device may further execute S205 and S206. Among them, S205 and S206 are optional steps. That is to say, the first device may execute S205 and S206, or may not execute S205 and S206. Figure 2a The optional steps are indicated by dotted lines.
[0096] S205: When the message type of the first message is a firmware upgrade message, stop authorizing the control right of the firmware storage area to the first control module.
[0097] In a possible implementation, when the message type of the first message is a firmware upgrade message, the first device can verify the digital signature in the first parsed content; when the digital signature in the first parsed content is verified successfully, stop authorizing the control right of the firmware storage area to the first control module.
[0098] In a possible implementation, the first device may further include a second control module. When the communication module verifies the digital signature in the first parsed content successfully, the communication module can send a first indication to the second control module, and the first indication can be used to indicate that the digital signature is verified successfully. In response to the first indication, the second control module can stop authorizing the control right of the firmware storage area to the first control module. Optionally, the specific implementation for the second control module to stop authorizing the control right of the firmware storage area to the first control module may be: the second control module sends a third indication to the first control module, and the third indication is used to indicate to stop authorizing the control right of the firmware storage area to the first control module.
[0099] S206: Authorize the control right of the firmware storage area to the upgrade module.
[0100] In the embodiments of the present application, after the first device stops authorizing the control right of the firmware storage area to the first control module and authorizes the control right of the firmware storage area to the upgrade module, it can indicate that the preparation work for firmware upgrade is completed, and then it can start writing upgrade data to the firmware storage area.
[0101] In a possible implementation, after the second control module executes S205 in response to the first indication, it can execute S206. Optionally, the specific implementation for the second control module to execute S206 may be: the second control module sends a fourth indication to the upgrade module, and the fourth indication is used to indicate to authorize the control right of the firmware storage area to the upgrade module. Optionally, after executing S206, the second control module can send a second indication to the parsing module, and the second indication is used to indicate that the parsing module sends the first upgrade data in the first parsed content to the upgrade module. In response to the second indication, the parsing module can send the first upgrade data to the upgrade module, so that the upgrade module can write the first upgrade data to the firmware storage area.
[0102] Exemplarily, after the first device receives the first message through the single-wire interface, the schematic diagram of the relevant processing of each module in the first device can be as Figure 2b shown. Figure 2bAmong them, the messages exchanged between the modules can be seen in the previous description and will not be elaborated here.
[0103] In the embodiment of the present application, by stopping authorizing the control right of the firmware storage area to the first control module and authorizing the control right of the firmware storage area to the upgrade module, on the one hand, it is beneficial to ensure that the upgrade module can successfully write the first upgrade data into the firmware storage area subsequently. On the other hand, it can avoid the first control module or the MCU from operating on the firmware storage area during the firmware upgrade process, thereby avoiding interference with the firmware upgrade, which is conducive to improving the success rate of the firmware upgrade.
[0104] In a possible implementation manner, when the message type of the first message is a firmware upgrade message, the first device can control the MCU to enter the low-power state. After the MCU enters the low-power state, the MCU will not operate on the firmware storage area. In this way, on the one hand, it can avoid the MCU from operating on the firmware storage area during the firmware upgrade process, thereby avoiding interference with the firmware upgrade, which is conducive to improving the success rate of the firmware upgrade. On the other hand, controlling the MCU to enter the low-power state can reduce the power consumption of the first device as much as possible to extend the battery life or reduce energy consumption. The embodiment of the present application does not limit the implementation form of the MCU low-power state. For example, the implementation form of the MCU low-power state can be but not limited to: sleep state (such as STOP state, STANDBY state, etc.), dormancy state, etc.
[0105] Optionally, the first device can control the MCU to enter the low-power state through the second control module. For example, the second control module sends a low-power indication to the MCU, and the MCU enters the low-power state in response to the low-power indication. Optionally, in addition to indicating that the MCU enters the low-power state, the low-power indication can also indicate to stop authorizing the control right of the firmware storage area to the MCU.
[0106] Optionally, before the MCU enters the sleep state, the first device can start the watchdog to prevent the first device from failing due to reasons such as firmware upgrade errors or firmware upgrade timeouts. The watchdog is a hardware timing device used to monitor the running state of the single-chip microcomputer program. After the watchdog is started, it starts to count down. If the program runs normally, the CPU will regularly issue instructions to reset the watchdog timer and start counting down again. If the program runs abnormally or enters an infinite loop and does not reset the watchdog timer within the set time, the counter will reach 0. At this time, the watchdog will trigger a system reset to make the system resume normal operation.
[0107] In a possible implementation, when the message type of the first message is the firmware upgrade message, the first device can mask interrupts, and the masked interrupts can include hardware interrupts and / or software interrupts. In this way, it can be ensured that the MCU will not be awakened by interrupts, and further, it can be avoided that the MCU operates on the firmware storage area during the firmware upgrade process, so as to avoid interfering with the firmware upgrade, which is beneficial to improving the success rate of the firmware upgrade.
[0108] In the embodiment of the present application, after the first device receives the first message through the single-wire interface, if it is recognized that the message type of the first message is the firmware upgrade message, before the upgrade module writes the first upgrade data into the firmware storage area, it first confirms that the control right of the firmware storage area belongs to the upgrade module, which is beneficial to ensuring that the upgrade module can smoothly write the first upgrade data into the firmware storage area subsequently. It can be seen that by implementing the embodiment of the present application, it is possible to conveniently upgrade the firmware of the single-wire interface device without relying on additional hardware. For example, without physically contacting the device or reserving a dedicated debugging interface, the firmware upgrade can be completed through the communication link, which is especially suitable for Internet of Things terminals that are difficult to maintain after deployment. Moreover, the external device can automatically trigger the version detection and upgrade process, reducing the need for manual intervention and lowering the operation and maintenance complexity.
[0109] In addition, by stopping authorizing the control right of the firmware storage area to the first control module and authorizing the control right of the firmware storage area to the upgrade module, on the one hand, it is beneficial to ensuring that the upgrade module can smoothly write the first upgrade data into the firmware storage area subsequently, and on the other hand, it can be avoided that the first control module or the MCU operates on the firmware storage area during the firmware upgrade process, so as to avoid interfering with the firmware upgrade, which is beneficial to improving the success rate of the firmware upgrade.
[0110] Taking the first device as a charger and the second device as a mobile phone as an example, when the user detects that the charger firmware version is too old through the mobile phone, the user can send firmware upgrade data through the single-wire UART link of the Type-C interface. The charger can complete the firmware update while maintaining normal fast charging protocol communication, and there is no power-off or plugging operation throughout the process. After the firmware upgrade is completed, the LED indicator of the charger flashes, and / or the mobile phone can display a prompt message indicating that the firmware upgrade is completed, so as to prompt the user that the firmware upgrade is completed.
[0111] In a possible implementation, the parsing content obtained by parsing the firmware upgrade message (hereinafter referred to as the second parsing content) may include multiple frames (hereinafter referred to as N frames, where N is an integer greater than or equal to 2). Each frame in the N frames includes a start bit, a data bit, a check bit, and an end bit. The frame structure schematic diagram of each frame in the second parsing content can be as Figure 3 shown.
[0112] The start bit can indicate the start of a frame in a second parsed content. The data bits can be used to carry the data actually required to be transmitted in a frame in the second parsed content (i.e., firmware upgrade data). The check bit can be used for error detection. The end bit can indicate the end of a frame in the second parsed content.
[0113] Optionally, the number of bits occupied by the data bits can be greater than the sum of the number of bits occupied by the start bit, the check bit, and the end bit. In this way, the proportion of the control field can be reduced, and the effective data throughput rate can be increased, which is conducive to improving the firmware upgrade efficiency. It should be noted that the embodiments of the present application do not limit the number of bits occupied by each field in each frame of the second parsed content. Figure 3 As shown, the start bit, the data bits, the check bit, and the end bit respectively occupy 1 bit, 8 bits, 1 bit, and 1 bit for illustrative purposes, and do not constitute a limitation on the embodiments of the present application. For example, in other possible implementation manners, the data bits can occupy 8 bits, 16 bits, 24 bits, or more bits. Correspondingly, the data bits in a frame of the second parsed content can actually transmit 1 byte, 2 bytes, 3 bytes, or more bytes of data.
[0114] It can be understood that when the message type of the first message belongs to the firmware upgrade message, the parsed content (i.e., the first parsed content) obtained by parsing the first message also includes multiple frames, and the frame structure of each frame is as Figure 3 shown. For the relevant content of each frame in the first parsed content, reference can be made to the detailed description of each frame in the second parsed content, and details will not be repeated.
[0115] In a possible implementation manner, the N frames can include different types of frames. For example, the N frames can include a header frame and a check frame, and can also include a first content frame or multiple second content frames.
[0116] Among them, the data bits of the header frame can include the message header of the firmware upgrade message. For example, when the message type of the first message belongs to the firmware upgrade message, the data bits of the header frame in the parsed content (i.e., the first parsed content) obtained by parsing the first message include the message header of the first message. In one implementation manner, the first device can determine whether the received message belongs to the firmware upgrade message based on the information carried by the data bits in the header frame of the received message. Exemplarily, taking the data bits of the header frame of the firmware upgrade message carrying the hexadecimal number AA (i.e., 0xAA) as an example, assuming that the information carried by the data bits in the header frame of the message (such as the first message) received by the first device is the hexadecimal number AA, then it can be determined that the first message belongs to the firmware upgrade message. If the information carried by the data bits in the header frame of the message (such as the first message) received by the first device is not the hexadecimal number AA, then it can be determined that the first message does not belong to the firmware upgrade message.
[0117] The data bits of the verification frame may include a verification field of the firmware upgrade message. The embodiments of the present application do not limit the specific form of the verification field. For example, the verification field may be a Cyclic Redundancy Check (CRC) code. For example, when the message type of the first message belongs to the firmware upgrade message, the data bits of the verification frame in the first parsing content include the CRC code of the first message. Optionally,
[0118] The data bits of the first content frame may include a response command. The response command may include other messages (such as commands or instructions, etc.) except for the upgrade data during the firmware upgrade process. These messages may include interaction messages between different modules inside the first device, and / or interaction messages between the first device and the second device. For example, the response command may include the aforementioned indication messages (such as the first indication, the second indication, etc.), and may also include a firmware upgrade success message, an upgrade failure message, a second response message (used to indicate that the first device has completed the firmware upgrade preparation), etc. sent by the first device to the second device.
[0119] The multiple second content frames may include a command frame, an address frame, a data length frame, and at least one data frame (hereinafter denoted as M data frames, where M is a positive integer).
[0120] Among them, the data bits of the command frame include a write command or a read command. When the data bits of the command frame are a write command, it means that data of the firmware corresponding to the first version number (i.e., the new firmware) needs to be written into the firmware storage area. When the data bits of the command frame are a read command, it means that firmware data of the firmware corresponding to the second version number (i.e., the old firmware) needs to be read from the firmware storage area. Optionally, the write command may be represented by the hexadecimal number b2 (i.e., 0xb2), and the read command may be represented by the hexadecimal number b1 (i.e., 0xb1).
[0121] When the data bits of the command frame include a write command, the data bits of the M data frames include the upgrade data in the second parsing content, the data bits of the address frame include the starting address where the upgrade data in the second parsing content is written into the firmware storage area, and the data bits of the data length frame include the data length of the upgrade data in the second parsing content. The schematic diagram of the frame types included in the second parsing content may be as Figure 4 shown.
[0122] When the message type of the first message belongs to the firmware upgrade message and the data bits of the command frame in the first parsing content include a write command, the data bits of the address frame include the starting address where the upgrade data (i.e., the first upgrade data) in the first parsing content is written into the firmware storage area, the data bits of the data length frame include the data length of the first upgrade data, and the data bits of the M data frames include the first upgrade data. That is to say, the first upgrade data is jointly carried by the data bits of the M data frames.
[0123] Assume that the information carried by the data bits of the header frame in the first parsed content is the hexadecimal number AA (i.e., 0xAA), the data bits of the command frame in the first parsed content include a write command, and the write command can be represented by the hexadecimal number b2 (i.e., 0xb2), and M = 2. The first upgrade data is written to the starting address a of the firmware storage area, and the data length of the first upgrade data is 2 bytes. In this case, the specific structure diagram of each frame in the first parsed content can be as Figure 5 shown. As Figure 5 shown, the first upgrade data occupies 2 bytes. Among them, the data bits of the first data frame are used to carry the first 8 bits of data (i.e., the first 1-byte data) in the first upgrade data, and the data bits of the second data frame are used to carry the last 8 bits of data (i.e., the last 1-byte data) in the first upgrade data. Among them, the first bit of data in the first upgrade data is written to address a.
[0124] In the case where the data bits of the command frame include a read command, the data bits of the address frame include the starting address of the firmware data to be read from the firmware storage area, and the data bits of the data length frame include the data length of the firmware data.
[0125] In a possible implementation, the number of address frames and data length frames in the multiple second content frames can be one or more, and the address frames and the data length frames are in one-to-one correspondence. Taking the multiple second content frames including 2 address frames and 2 data length frames and also including a write command frame as an example, assume that the starting addresses provided by the 2 address frames are starting address a and starting address b respectively, and the data lengths provided by the 2 data length frames are 2 bytes and 1 byte respectively. Among them, starting address a corresponds to a bytes, and starting address b corresponds to 1 byte. In this case, the first device can write 2-byte upgrade data starting from starting address a and write 1-byte upgrade data starting from starting address b. In this way, upgrade data can be written in a non-continuous address space, which is beneficial to improving the storage space utilization rate.
[0126] In a possible implementation, the data bits of one data frame among the M data frames occupy at least one byte. The data bits of one data frame among the M data frames occupying one byte means that the data bits of one data frame among the M data frames can carry one byte of upgrade data. Similarly, the data bits of one data frame among the M data frames occupying 2 bytes means that the data bits of one data frame among the M data frames can carry 2 bytes of upgrade data.
[0127] In this way, when the message to which the M data frames belong carries a write command, continuous writing of multi-byte upgrade data can be supported. When the message to which the M data frames belong carries a read command, multi-byte firmware data can be supported to be read from the firmware storage area and the multi-byte firmware data can be sent to the second device. This is beneficial to improving the overall efficiency of firmware upgrade. It should be noted that in a possible implementation manner, during the firmware upgrade process, in addition to writing new data to the firmware storage area of the first device, it may also involve first reading the firmware data of the old firmware from the firmware storage area of the first device and sending the read firmware data to the second device. Based on the read firmware data, the second device further determines the new data that needs to be written to the firmware storage area of the first device.
[0128] In a possible implementation manner, the first device may determine the address range corresponding to the first upgrade data in the first parsing content based on the starting address included in the data bits of the address frame in the first parsing content and the data length included in the data bits of the data length frame in the first parsing content; and write the first upgrade data into the address range in the firmware storage area through the upgrade module. Optionally, taking the address difference between two adjacent storage units in the firmware storage area as 1 as an example, the first address in the address range corresponding to the first upgrade data is the starting address included in the data bits of the address frame, and the last address in the address range corresponding to the first upgrade data is the difference between the first address and 1, where the first address is the sum of the starting address and the data length. In this way, even if only the starting address is provided, the complete address range into which the first upgrade data is written can be obtained by incrementing the address, so that continuous writing of multi-byte upgrade data can be supported.
[0129] Exemplarily, taking Figure 5 as an example, assuming that the last address in the address range corresponding to the first upgrade data is the difference between the first address and 1, the data of the 1st bit in the first upgrade data is written to address a, the data of the 2nd bit in the first upgrade data is written to the 1st address after address a (i.e., address a + 1), the data of the 3rd bit in the first upgrade data is written to the 2nd address after address a (i.e., address a + 2), and so on, the data of the 16th bit in the first upgrade data is written to the 15th address after address a (i.e., address a + 15).
[0130] In a possible implementation manner, the first device may determine the address range required to be read by the read instruction based on the starting address of the firmware data to be read from the firmware storage area and the data length of the firmware data to be read. The method can refer to the address increment method of the address range of the write instruction and will not be elaborated here.
[0131] It can be seen that the frame format design of the above firmware upgrade message has simple and efficient logic and strong flexibility. The number of different types of frames can be adjusted according to actual requirements, so as to adapt to more application scenarios. On the other hand, this design is transparently extensible, can be compatible with different single-wire interface protocols, can avoid conflicts with privately designed single-wire interface protocols, and can adapt to a variety of device scenarios.
[0132] In a possible implementation, when the second condition is met, the first device can stop authorizing the control right of the firmware storage area to the upgrade module and authorize the control right of the firmware storage area to the first control module. The second condition includes: the firmware upgrade is completed, or a preset preemption signal is received. The preset preemption signal can be used to indicate that there is a service with a priority higher than that of the firmware upgrade task, or to indicate that there is an emergency service.
[0133] In this way, after the firmware upgrade is completed, the control right of the firmware storage area is re-authorized to the first control module to facilitate re-entering the normal communication mode. Or, in the case of high-priority services or emergency services, the first device can suspend the firmware upgrade process and give priority to processing high-priority services or emergency services by stopping authorizing the control right of the firmware storage area to the upgrade module and re-authorizing the control right of the firmware storage area to the first control module. In other words, it can support the processing of other services inserted during the firmware upgrade process, which can better handle emergencies and is conducive to improving the intelligence of the system.
[0134] Exemplarily, in the case where the firmware upgrade is completed, the schematic diagram of the relevant processing of each module in the first device can be as Figure 6 shown. Figure 6 In, the upgrade module can notify the second control module that the firmware upgrade is completed. The second control module can send a fifth indication to the upgrade module and a sixth indication to the first control module. The fifth indication is used to indicate stopping authorizing the control right of the firmware storage area to the upgrade module, and the sixth indication is used to indicate authorizing the control right of the firmware storage area to the first control module. Furthermore, the MCU in the first control module can be restarted and read the MCU instructions of the new firmware from the firmware storage area, that is, start from the new firmware. Then, the second control module can send a seventh indication to the parsing module. The seventh indication is used to indicate that the parsing module stops sending data to the upgrade module. In this case, after the first device receives the second message through the single-wire interface, the second message can be parsed by the parsing module, and the parsed content can be sent to the communication module for processing instead of being sent to the upgrade module for processing. Through Figure 6 the process shown, it can be seen that after exiting the firmware upgrade module, the normal communication mode can be re-entered.
[0135] Exemplarily, in the case of receiving a preset preemption signal, a schematic diagram of the relevant processing of each module in the first device can be as Figure 7 shown. Figure 7 In Figure 7 , after the second control module receives the preset preemption signal, the second control module may send a fifth instruction to the upgrade module and send a sixth instruction to the first control module. The fifth instruction is used to instruct to stop authorizing the control right of the firmware storage area to the upgrade module, and the sixth instruction is used to instruct to authorize the control right of the firmware storage area to the first control module. Furthermore, the MCU in the first control module can read the MCU instructions of the old firmware from the firmware storage area to process emergency services. Then, the second control module may send a seventh instruction to the parsing module, and the seventh instruction is used to instruct the parsing module to stop sending data to the upgrade module.
[0136] Optionally, as Figure 7 shown, the MCU may also request the communication module to send a status message, and the status message is used to indicate the processing status of the emergency service. In response to this request, the communication module may request the parsing module to send a status message. Further, the parsing module sends the status message to the second device through a single-wire interface. In this way, the second device can know the processing status of the emergency service. Through Figure 7 the process shown in Figure 7 , it can be seen that by implementing the embodiments of the present application, it is possible to support the processing of emergency services inserted during the firmware upgrade process, which can better handle emergencies and is beneficial to improving the intelligence of the system.
[0137] In a possible implementation manner, when the second condition is met, the first device may wake up the MCU to process high-priority services or emergency services. Optionally, the sixth instruction may also be used to wake up the MCU.
[0138] In a possible implementation manner, the first upgrade data in the first parsing content corresponds to a new firmware version (i.e., the first version number). After the first device authorizes the control right of the firmware storage area to the first control module, the firmware corresponding to the old firmware version (i.e., the second version number) in the firmware storage area can be read through the MCU to process emergency services. In other words, in the case of the existence of emergency services, if the firmware upgrade has not been completed, the first device can actively roll back to the old firmware version, and the MCU runs with the old firmware version to process emergency services.
[0139] Optionally, the high-priority service or emergency service may be generated inside the first device. For example, system overvoltage protection, overcurrent protection, overtemperature protection, etc. Or, the high-priority service or emergency service may be generated outside the first device, such as generated by the second device. The embodiments of the present application do not limit the generation reasons of the high-priority service or emergency service.
[0140] In a possible implementation, the parsing module can be implemented as a state machine, such as a data parsing state machine; the communication module can be implemented as a state machine, such as a communication protocol state machine; the upgrade module can be implemented as a state machine, such as an upgrade protocol state machine.
[0141] Among them, the data parsing state machine can be used to parse the messages received by the single-wire interface, and based on the parsing results, distinguish whether the received messages belong to firmware upgrade messages or communication messages. And based on the discrimination results, further forward some or all of the data in the parsing results to the corresponding logic for processing. If the received message belongs to a firmware upgrade message, some or all of the data in the parsing results can be further forwarded to the upgrade data packet parsing logic for processing. For example, the upgrade data packet parsing logic can be used to forward the command frame, address frame, data length frame, and M data frames in the first parsing content to the upgrade protocol state machine for processing based on the frame structure of the firmware upgrade message. If the received message belongs to a communication message, some or all of the data in the parsing results can be further forwarded to the communication data packet parsing logic for processing. For example, the communication data packet parsing logic can be used to forward the required data to the communication protocol state machine for processing based on the frame structure of the communication message. It can be seen that in this way, the time-sharing multiplexing of the communication protocol state machine and the upgrade protocol state machine can be achieved.
[0142] In a possible implementation, the schematic diagram of the state transition process of the data parsing state machine can be as Figure 8 shown. Figure 8 In, the circles represent the states of the data parsing state machine, and the arrows between different states represent the state transition process, as well as the events or conditions that trigger the state transition. As Figure 8 shown, when a message is received (such as called message a, and message a can be, for example, the first message), the data parsing state machine transitions from the idle state to the message processing state. When in the message processing state, the data parsing state machine can parse the received message a, and after parsing, it can perform a CRC check on message a. If the CRC check fails, it means that message a is incorrect. At this time, the data parsing state machine transitions from the message processing state to the idle state. If the CRC check is successful, the data parsing state machine can distinguish the message type of message a. If message a belongs to a communication message, it means that the first device does not need to enter the upgrade mode, that is, the first device enters the non-upgrade mode. At this time, the data parsing state machine can transition from the message processing state to the communication message parsing logic state. If message a belongs to a firmware upgrade message, it means that the first device needs to enter the upgrade mode. At this time, the data parsing state machine can transition from the message processing state to the firmware upgrade message parsing logic state.
[0143] Optionally, when the CRC check of message a by the data parsing state machine is successful, the data parsing state machine can send an ACK to the second device through the single-wire interface. Optionally, when the CRC check of message a by the data parsing state machine fails, the data parsing state machine can send a NACK to the second device through the single-wire interface.
[0144] In a possible implementation, the upgrade protocol state machine can be used to send read instructions or write instructions to the firmware storage area according to the command type in the firmware upgrade message. Optionally, the upgrade protocol state machine can also be used to provide real-time feedback to other modules on various data and status during the firmware upgrade process. Further, other modules can send feedback messages to the second device.
[0145] In a possible implementation, the schematic diagram of the state transition process of the upgrade protocol state machine can be as Figure 9 shown. Figure 9 In the figure, the circles represent the states of the upgrade protocol state machine, and the arrows between different states represent the state transition process, as well as the events or conditions that trigger the state transition.
[0146] As Figure 9As shown, when receiving the fourth indication from the second control module, the upgrade protocol state machine transfers from the idle state to the firmware upgrade preparation state. In the firmware upgrade preparation state, if the upgrade protocol state machine determines that the firmware upgrade message carries a write instruction, the upgrade protocol state machine transfers from the firmware upgrade preparation state to the firmware writing state. After writing the upgrade data in the firmware upgrade message to the target address in the firmware storage area, the upgrade protocol state machine transfers from the firmware writing state to the write verification state. In the write verification state, the upgrade protocol state machine requests to read the data at the target address. At this time, the upgrade protocol state machine transfers from the write verification state to the firmware reading state. After obtaining the data read from the target address, the upgrade protocol state machine transfers from the firmware reading state to the write verification state. In the write verification state, the upgrade protocol state machine compares the upgrade data with the data read from the target address to obtain a verification result, and after transmitting the verification result to the parsing module, the upgrade protocol state machine transfers from the write verification state to the idle state. After the upgrade protocol state machine writes the upgrade data to the target address, it performs a read-back, and then verifies whether the read-back data is the same as the previously written upgrade data, which helps to ensure that the upgrade data is correctly written to the firmware storage area and improves the success rate of firmware upgrade. Optionally, the parsing module can send the verification result to the second device so that the second device can know whether the upgrade data is correctly written to the firmware storage area. Optionally, in the case where the upgrade data is not correctly written to the firmware storage area, the second device can re-send the upgrade data to the first device. Among them, the verified read-back data can include verifying whether the read-back firmware version number is the firmware version number corresponding to the previously written upgrade data (i.e., the first version number).
[0147] As Figure 9 shown, if the upgrade protocol state machine determines that the firmware upgrade message carries a read instruction, the upgrade protocol state machine transfers from the firmware upgrade preparation state to the firmware reading state. After reading the data indicated by the read instruction from the firmware storage area, the upgrade protocol state machine transmits the read data to the parsing module and then transfers from the firmware reading state to the idle state. Optionally, the parsing module can send the read data to the second device.
[0148] Optionally, when the upgrade protocol state machine verifies that the read-back data is the same as the previously written upgrade data, the upgrade protocol state machine can request the parsing module to send an upgrade success notification. The parsing module can further send an upgrade success notification to the second device through a single-wire interface so that the second device can know that the first device has successfully completed the firmware upgrade.
[0149] Please refer to Figure 10 , Figure 10 which Figure 10As shown in the figure, the firmware upgrade device 100 includes a communication unit 1001 and a processing unit 1002. The firmware upgrade device 100 can execute the relevant steps of the first device in the foregoing method embodiments.
[0150] The communication unit 1001 is configured to receive a first message from a second device through a single-wire interface;
[0151] The processing unit 1002 is configured to parse the first message to obtain first parsed content; based on the first parsed content, determine the message type of the first message, where the message type includes a communication message and a firmware upgrade message; when the message type of the first message is a firmware upgrade message and the control right of the firmware storage area belongs to the upgrade module, write the first upgrade data in the first parsed content into the firmware storage area through the upgrade module.
[0152] Specifically, in this case, the operations performed by the communication unit 1001 and the processing unit 1002 can refer to the introduction of the first device in the corresponding embodiment of FIG. 2- Figure 9 For details, reference can be made to the description of the first device in the corresponding embodiment, which will not be elaborated here.
[0153] Please refer to Figure 11 , Figure 11 , which is a schematic structural diagram of a first device 110 provided by an embodiment of the present application. It can be used to implement the functions of the first device in the foregoing method embodiments. The first device 110 may include a single-wire interface 1101, at least one memory 1102, and at least one processor 1103. Optionally, the first device 110 may further include an MCU 1104. Among them, the single-wire interface 1101, at least one memory 1102, at least one processor 1103, and MCU 1104 may be connected through a bus 1105 or other means. The bus is shown in Figure 11 in thick lines, and the connection manners between other components are only for illustrative purposes and are not limited thereto. The bus may be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 11 only one thick line is shown in, but it does not mean that there is only one bus or one type of bus.
[0154] The coupling in the embodiments of the present application is an indirect coupling or communication connection between devices, units, or modules, which may be electrical, mechanical, or other forms, and is used for information interaction between devices, units, or modules. In the embodiments of the present application, the specific connection medium between the single-wire interface 1101, at least one memory 1102, at least one processor 1103, and MCU 1104 is not limited.
[0155] At least one memory 1102 can be used for the functions in the above firmware storage area. At least one memory 1102 can include a read-only memory and a random access memory, and provide instructions and data to at least one processor 1103. A part of at least one memory 1102 may further include a non-volatile random access memory.
[0156] At least one processor 1103 can be a central processing unit (CPU), and at least one processor 1103 can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor. Optionally, at least one processor 1103 can also be any conventional processor, etc.
[0157] In one example, when the electronic device adopts Figure 11 the form shown, Figure 11 at least one processor 1103 in
[0158] In an alternative embodiment, at least one memory 1102 is used to store computer programs or instructions; at least one processor 1103 is used to call the computer programs or instructions stored in at least one memory 1102 for performing the steps executed by the first device in the corresponding embodiments of FIGS. 2 - Figure 9 corresponding embodiments.
[0159] Specifically, Figure 10 the functions / implementation processes of the communication unit 1001 and the processing unit 1002 in Figure 11 can all be implemented by at least one processor 1103 in Figure 10 calling the computer programs or instructions stored in at least one memory 1102. Or, Figure 11 the function / implementation process of the processing unit 1002 in Figure 10 can be implemented by at least one processor 1103 in Figure 11 calling the computer programs or instructions stored in at least one memory 1102, and the function / implementation process of the communication unit 1001 in
[0160] Specifically, Figure 1The functions / implementation processes of the single-wire interface 101, upgrade module 1021, parsing module 1022, communication module 1023, first control module 104, second control module 105, and firmware storage area 103 in Figure 11 can all be implemented by at least one processor 1103 in Figure 1 invoking computer programs or instructions stored in at least one memory 1102. Or, Figure 11 the functions / implementation processes of the upgrade module 1021, parsing module 1022, communication module 1023, first control module 104, second control module 105, and firmware storage area 103 in Figure 1 can be implemented by at least one processor 1103 in Figure 11 invoking computer programs or instructions stored in at least one memory 1102. Figure 1 The function / implementation process of the single-wire interface 101 in Figure 11 can be implemented by the single-wire interface 1101 in
[0161] In the embodiments of the present application, the method provided in the embodiments of the present application can be implemented by running a computer program (including program code) capable of executing the steps involved in the above method on a general computing device such as a computer including processing elements and storage elements such as a CPU, a random access storage medium (Random Access Memory, RAM), and a read-only storage medium (Read-Only Memory, ROM). The computer program can be recorded on a computer-readable recording medium, loaded into the first device through the computer-readable recording medium, and run therein.
[0162] Based on the same inventive concept, the principle of solving problems and the beneficial effects of the first device 110 provided in the embodiments of the present application are similar to the principle of solving problems and the beneficial effects of the first device in the method embodiments of the present application. For the principle and beneficial effects of the method implementation, reference can be made, and for the sake of brevity of description, they will not be elaborated here.
[0163] The embodiments of the present application further provide a computer-readable storage medium, in which computer programs or computer instructions are stored, and the computer programs or computer instructions are suitable for being loaded and executed by a processor to execute the method provided in the above method embodiments.
[0164] The embodiments of the present application further provide a computer program product including computer programs or instructions. When the computer programs or instructions run on an electronic device (such as the first device), the electronic device is caused to execute the method provided in the above method embodiments.
[0165] Regarding each device and product described in the above embodiments, each module / unit included therein can be a software module / unit, a hardware module / unit, or can be partly a software module / unit and partly a hardware module / unit. For example, for each device and product applied to or integrated into a chip, each module / unit included therein can be implemented in a hardware manner such as a circuit, or at least part of the modules / units can be implemented in a software program manner, and the software program runs on a processor integrated inside the chip, and the remaining (if any) part of the modules / units can be implemented in a hardware manner such as a circuit; for each device and product applied to or integrated into a chip module, each module / unit included therein can be implemented in a hardware manner such as a circuit, and different modules / units can be located in the same component (such as a chip, a circuit module, etc.) or different components of the chip module, or at least part of the modules / units can be implemented in a software program manner, and the software program runs on a processor integrated inside the chip module, and the remaining (if any) part of the modules / units can be implemented in a hardware manner such as a circuit; for each device and product applied to or integrated into an electronic device (such as the first device), each module / unit included therein can be implemented in a hardware manner such as a circuit, and different modules / units can be located in the same component (such as a chip, a circuit module, etc.) or different components inside the electronic device (such as the first device), or at least part of the modules / units can be implemented in a software program manner, and the software program runs on a processor integrated inside the electronic device (such as the first device), and the remaining (if any) part of the modules / units can be implemented in a hardware manner such as a circuit.
[0166] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described action sequence, because according to this application, some steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0167] In the above embodiments, the descriptions of each embodiment have their own focuses, and any multiple embodiments can be combined for use. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0168] The steps in the method embodiments of this application can be adjusted, combined, and deleted according to actual needs.
[0169] The modules in the device embodiments of this application can be combined, divided, and deleted according to actual needs.
[0170] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by program instructions and related hardware, and the program instructions can be stored in a computer-readable storage medium, which can include: flash drives, ROM, RAM, magnetic disks or optical discs, etc.
[0171] What has been disclosed above is only one embodiment of the present application, and it is only a part of the embodiments of the present application, and it cannot be used to limit the scope of rights of the present application.
Claims
1. A firmware upgrade method, characterized in that: Applied to a first device, the first device at least includes a single-line interface, an upgrade module, and a firmware storage area; the method includes: receiving a first message from a second device via the single-wire interface; Parsing the first message to obtain first parsed content; Based on the first parsed content, determine a message type of the first message, where the message type includes a communication message and a firmware upgrade message; When the message type of the first message is the firmware upgrade message and the control authority of the firmware storage area belongs to the upgrade module, the first upgrade data in the first parsed content is written into the firmware storage area through the upgrade module.
2. The method according to claim 1, characterized in that The first device further includes a first control module, which includes at least a micro control unit MCU; The method further comprises: When the message type of the first message is the firmware upgrade message, stop authorizing the control authority of the firmware storage area to the first control module; The control authority of the firmware storage area is authorized to the upgrade module.
3. The method according to claim 1, characterized in that: The method further comprises: In a case where the message type of the first message is the firmware upgrade message, the MCU is controlled to enter a low power consumption state.
4. The method according to claim 3, characterized in that The method further comprises: In a case where the message type of the first message is the firmware upgrade message, interruption is masked.
5. The method according to claim 1, characterized in that: The second parsed content obtained by parsing the firmware upgrade message includes a plurality of frames, each of the plurality of frames including a start bit, a data bit, a check bit, and an end bit; The multiple frames include a header frame and a check frame, and also include a first content frame or multiple second content frames; wherein, The data bit of the header frame includes a message header of the firmware upgrade message; The data bits of the check frame include a check field of the firmware upgrade message; The data bits of the first content frame include a response command; The plurality of second content frames include a command frame, an address frame, a data length frame, and at least one data frame; wherein, The data bits of the command frame include a write command or a read command; In the case where the data bits of the command frame include a write command, the data bits of the at least one data frame include the upgrade data in the second parsed content, the data bits of the address frame include the first address of the firmware storage area where the upgrade data in the second parsed content is written, and the data bits of the data length frame include the data length of the upgrade data in the second parsed content; In the case where the data bits of the command frame include a read command, the data bits of the address frame include the first address of the firmware data to be read from the firmware storage area, and the data bits of the data length frame include the data length of the firmware data.
6. The method according to claim 5, characterized in that The data bits of one data frame in the at least one data frame occupy at least one byte.
7. The method according to claim 6, characterized in that The method further comprises: Determine an address range corresponding to the first upgrade data in the first parsed content based on a first address included in a data bit of an address frame in the first parsed content and a data length included in a data bit of a data length frame in the first parsed content; The step of writing the first upgrade data in the first parsed content into the firmware storage area through the upgrade module includes: The first upgrade data is written into the address range in the firmware storage area through the upgrade module.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: If the second condition is met, stop authorizing the control authority of the firmware storage area to the upgrade module; wherein the second condition includes: the firmware upgrade is completed, or a preset preemption signal is received; Authorize the control authority of the firmware storage area to the first control module.
9. The method according to claim 8, characterized in that The preset preemption signal is used to indicate the existence of an emergency service, and the first upgrade data in the first parsed content corresponds to a new firmware version; After authorizing the control authority of the firmware storage area to the first control module, the method further includes: The firmware corresponding to the old firmware version in the firmware storage area is read by the MCU, and the emergency service is processed.
10. The method according to any one of claims 1 to 7, characterized in that: The first device further includes a communication module, and the method further includes: In a case where the message type of the first message is the communication message, the first parsed content is processed by the communication module.
11. The method according to any one of claims 1 to 7, characterized in that: Parsing the firmware upgrade message to obtain parsed content including a digital signature; When the message type of the first message is the firmware upgrade message, stopping authorizing the control authority of the firmware storage area to the first control module includes: In a case where the message type of the first message is the firmware upgrade message, verifying the digital signature in the first parsed content; When the digital signature in the first parsed content is verified to be successful, stop authorizing the control authority of the firmware storage area to the first control module.
12. A firmware upgrade device, characterized in that: The method comprises means for executing the method as claimed in any one of claims 1 to 11.
13. A first device, characterized in that: At least includes a single-line interface, a parsing module, a communication module, a second control module, an upgrade module, and a firmware storage area; wherein, The single-wire interface is used to receive a first message from a second device; The parsing module is used to parse the first message to obtain a first parsed content; based on the first parsed content, determine the message type of the first message, the message type including a communication message and a firmware upgrade message; when the message type of the first message is the firmware upgrade message, send the first parsed content to the communication module; The communication module is configured to verify the digital signature in the first parsed content, and send a first indication to the second control module when the digital signature in the first parsed content is verified successfully, wherein the first indication is used to indicate that the digital signature is verified successfully; the second control module is configured to, in response to the first instruction, send a second instruction to the parsing module when the control authority of the firmware storage area belongs to the upgrade module, wherein the second instruction is used to instruct the parsing module to send the first upgrade data in the first parsed content to the upgrade module; The parsing module is further configured to send the first upgrade data to the upgrade module in response to the second indication; The upgrade module is used to write the first upgrade data into the firmware storage area.
14. The first device according to claim 13, characterized in that The first device further includes a first control module, which includes at least a micro control unit MCU; The second control module is used to send a third instruction to the first control module and a fourth instruction to the upgrade module in response to the first instruction; wherein the third instruction is used to instruct to stop authorizing the control authority of the firmware storage area to the first control module, and the fourth instruction is used to instruct to authorize the control authority of the firmware storage area to the upgrade module.
15. A first device, characterized in that: It comprises a single-line interface, at least one memory and at least one processor; wherein the at least one memory is used to store computer programs or instructions, and the at least one processor is used to call the computer program or instructions from the at least one memory and run the computer program or instructions to execute the method as described in any one of claims 1-11.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program or a computer instruction. When the computer program or the computer instruction is executed by a processor, the method according to any one of claims 1 to 11 is executed.
Citation Information
Cited By
Method and device for upgrading control module of special transformer terminal and medium
CN120935151A
A method, device and medium for upgrading a control module of a smart terminal
CN120935151B
