CN116560689A - Firmware upgrading method, device, chip, electronic equipment and storage medium - Google Patents

Firmware upgrading method, device, chip, electronic equipment and storage medium Download PDF

Info

Publication number
CN116560689A
CN116560689A CN202310499508.XA CN202310499508A CN116560689A CN 116560689 A CN116560689 A CN 116560689A CN 202310499508 A CN202310499508 A CN 202310499508A CN 116560689 A CN116560689 A CN 116560689A
Authority
CN
China
Prior art keywords
firmware
memory
chip
upgrading
upgrade
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310499508.XA
Other languages
Chinese (zh)
Inventor
韦康
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hefei Chipsea Electronics Technology Co Ltd
Original Assignee
Hefei Chipsea Electronics Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hefei Chipsea Electronics Technology Co Ltd filed Critical Hefei Chipsea Electronics Technology Co Ltd
Priority to CN202310499508.XA priority Critical patent/CN116560689A/en
Publication of CN116560689A publication Critical patent/CN116560689A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application relates to the technical field of electronics and discloses a firmware upgrading method which is used for upgrading firmware in a memory in a chip, wherein the chip comprises a single-wire port, and the chip establishes single-wire wired connection with external equipment through the single-wire port; the method comprises the following steps: in the process of running a boot loader in a memory, if the firmware in the memory is detected to need to be upgraded, starting the transmission enabling of a single-wire port, and transmitting an upgrade data acquisition request to external equipment; after sending the upgrade data acquisition request, receiving an upgrade data packet returned by the external equipment in response to the upgrade data acquisition request through a single-wire port; and upgrading the firmware in the memory according to the upgrading data packet. The method and the device can upgrade the chip in the firmware under the condition that the chip and the external equipment perform wired communication by using a single data line.

Description

Firmware upgrading method, device, chip, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of electronic technologies, and in particular, to a firmware upgrade method, apparatus, chip, electronic device, and storage medium.
Background
In the related art, if firmware in a chip (for example, a single chip microcomputer) is to be upgraded, the chip is required to be connected with an external device through at least two data lines, in practice, there may be a case that the chip only reserves one port for being connected with the external device, and according to the firmware upgrading mode of the related art, the firmware cannot be upgraded under the condition that the chip is connected with the external device through a single data line.
Disclosure of Invention
In view of the above problems, an embodiment of the present application proposes a firmware upgrading method, device, chip, electronic device and storage medium, so as to solve the problem that in the related art, firmware cannot be upgraded under the condition that the chip and external device are connected through a single data line.
According to an aspect of the embodiments of the present application, there is provided a firmware upgrade method for upgrading firmware in a memory in a chip, where the chip includes a single-wire port, and the chip establishes a single-wire wired connection with an external device through the single-wire port; the method comprises the following steps: in the process of running the boot loader in the memory, if the firmware in the memory is detected to need to be upgraded, starting the transmission enabling of the single-wire port, and transmitting an upgrade data acquisition request to the external equipment; after the upgrade data acquisition request is sent, an upgrade data packet returned by the external equipment in response to the upgrade data acquisition request is received through the single-wire port; and upgrading the firmware in the memory according to the upgrading data packet.
According to an aspect of the embodiments of the present application, there is provided a firmware upgrade apparatus for upgrading firmware in a memory in a chip, the chip including a single-wire port through which the chip establishes a single-wire wired connection with an external device; the device comprises: the sending module is used for starting the sending enabling of the single-wire port and sending an upgrade data acquisition request to the external equipment if the firmware in the memory is detected to need to be upgraded in the process of running the starting loading program in the memory; the receiving module is used for receiving an upgrade data packet returned by the external equipment in response to the upgrade data acquisition request through the single-wire port after the upgrade data acquisition request is sent; and the upgrading module is used for upgrading the firmware in the memory according to the upgrading data packet.
In some embodiments, an application storage area and a backup storage area are arranged in the memory, and the firmware is stored in the application storage area; in this embodiment, the upgrade module includes:
the verification unit is used for carrying out data verification on the upgrading data packet;
the storage unit is used for storing the upgrade data in the upgrade data packet to the backup storage area if the upgrade data packet passes the verification;
And the writing unit is used for writing the upgrade data in the backup storage area into the application storage area to upgrade the firmware in the application storage area if all the upgrade data packets corresponding to the firmware upgrade data of the firmware are received and all the upgrade data packets pass verification.
In some embodiments, the firmware upgrade apparatus further comprises:
the accumulation module is used for accumulating the error times of the upgrade data packet which is not checked;
and the prompt information generation module is used for sending upgrade failure prompt information to the external equipment if the accumulated error times reach the time threshold.
In some embodiments, the firmware upgrade apparatus further comprises:
the validity verification module is used for verifying the validity of the firmware in the memory if the firmware in the memory is determined to be required to be operated in the process of operating the boot loader in the memory;
and the firmware running module is used for running the firmware if the firmware in the memory is determined to be valid.
In some embodiments, the firmware is stored in an application storage area in the memory; in this embodiment, the validity verification module includes:
an acquiring unit, configured to acquire a first address of the application storage area, and acquire a second address in the application storage area;
And the effective determining unit is used for determining that the firmware in the application storage area is effective if the data pointed by the first address of the application storage area is positioned in the random access memory in the processor and the data pointed by the second address in the application storage area is positioned in the memory.
In some embodiments, the memory stores a status identifier, and if the status identifier is a first status identifier, it is determined that firmware in the memory needs to be upgraded; and if the state identifier is a second state identifier, determining that the firmware in the memory needs to be operated.
In some embodiments, the firmware upgrade apparatus further comprises: and the state identifier updating module is used for updating the state identifier stored in the memory into the first state identifier if a firmware updating command is received in the process of running the firmware.
In some embodiments, the firmware upgrade apparatus further comprises:
the address mapping modification module is used for modifying the address mapping corresponding to the memory so as to map the address where the boot loader is located in the memory to a specified memory address, and a processor in the chip starts to execute from the specified memory address after power-on or reset;
And the operation module is used for operating the starting loader based on the address mapping corresponding to the modified memory.
In some embodiments, the firmware upgrade apparatus further comprises:
the firmware upgrading request sending module is used for starting the sending enabling of the single-wire port and sending a firmware upgrading request to the external equipment if the state identifier stored in the memory is other state identifiers except the first state identifier and the second state identifier in the process of running the starting loading program in the memory;
the enabling switching module is used for closing the sending enabling of the single-wire port and opening the receiving enabling of the single-wire port after the firmware upgrading request is sent;
and if a request response packet returned by the external device in response to the firmware upgrading request is received after the receiving enabling of the single-wire port is opened, executing the steps of starting the sending enabling of the single-wire port and sending an upgrading data obtaining request to the external device.
According to one aspect of the embodiment of the application, a chip is provided, the chip comprises a memory and a single-wire port, the chip establishes a single-wire wired connection with an external device through the single-wire port, and the chip upgrades the firmware in the memory according to the firmware upgrading method.
According to an aspect of the embodiments of the present application, there is provided an electronic device including a chip as above.
According to an aspect of the embodiments of the present application, there is provided a computer-readable storage medium having stored thereon computer-readable instructions which, when executed by a processor, implement a firmware upgrade method as described above.
According to one aspect of embodiments of the present application, there is provided a computer program product comprising computer instructions which, when executed by a processor, implement a firmware upgrade method as above.
In the method, the boot loader in the memory of the chip is utilized to realize the jump from the operation of the boot loader to the upgrading of the firmware, namely, in the process of operating the boot loader, under the condition that the state identifier read in the memory is a first state identifier indicating that the firmware needs to be upgraded, the firmware upgrading data of the firmware is requested to the external device by utilizing the wired connection of a single wire between the chip and the external device so as to upgrade the firmware in the chip. In addition, in the process of interaction by utilizing the wired connection of the single wire between the chip and the external equipment, only one of the transmission enabling and the receiving enabling of the single wire port in the chip is available at the same time, so that the chip is ensured to either receive data or transmit data at the same time, and the situation that the data is transmitted and received is avoided, so that the problem of data collision in the interaction process of the chip and the external equipment can be effectively avoided, and the accuracy of an upgrade data packet received by the chip is further ensured. By adopting the scheme, the problem that firmware in a chip cannot be upgraded under the condition of single data line in the related technology can be effectively solved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application. It is apparent that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art.
Fig. 1 is a schematic diagram of an application scenario of the present application according to an embodiment of the present application.
FIG. 2 is a flow chart illustrating a firmware upgrade method according to one embodiment of the present application.
Fig. 3 is a schematic diagram illustrating region division of a memory according to an embodiment of the present application.
Fig. 4 is a flow chart of step 230 in the corresponding embodiment of fig. 2 in one embodiment.
FIG. 5 is a flow chart illustrating a firmware upgrade method according to an embodiment of the present application.
FIG. 6 is a block diagram illustrating a firmware upgrade apparatus according to one embodiment of the present application.
Fig. 7 shows a schematic structural diagram of an electronic device suitable for use in implementing embodiments of the present application.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. However, the exemplary embodiments may be embodied in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art.
The flow diagrams depicted in the figures are exemplary only, and do not necessarily include all of the elements and operations/steps, nor must they be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the order of actual execution may be changed according to actual situations.
It should be noted that: references herein to "a plurality" means two or more. "and/or" describes an association relationship of an association object, meaning that there may be three relationships, e.g., a and/or B may represent: a exists alone, A and B exist together, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.
Fig. 1 is a schematic diagram of an application scenario of the present application, as shown in fig. 1, where the application scenario includes a chip 110 and an external device 120, and a single-wire port 111 is disposed on the chip 110, one end of a data line 130 may be connected to the single-wire port 111, and the other end of the data line 130 may be connected to the external device 120, so as to establish a single-wire wired connection between the chip 110 and the external device 120, and based on the wired connection, firmware in the chip 110 is upgraded according to a method of the present application.
The chip may be a chip in an electronic device such as a keyboard, a mouse, a wearable device, a weighing scale, a charger, etc., and the chip may be a single chip microcomputer, a microcontroller, a microprocessor, etc., which is not limited herein. The external device 120 may be a host computer of the chip 110 that may provide firmware upgrade data for firmware in the chip, it being understood that a corresponding single wire port is provided on the external device 120 for the data line 130 to access.
Fig. 2 is a flow chart of a firmware upgrade method, shown according to one embodiment of the present application, that may be performed by a chip, or by an electronic device comprising a chip, for upgrading firmware in a memory in the chip, the chip further comprising a single wire port, which may be a port communicating according to a 1-wire protocol, through which the chip establishes a single wire wired connection with an external device. The chip may be a single chip microcomputer, a microcontroller (Micro controller Unit, MCU), a microprocessor chip, etc., and is not particularly limited herein. Firmware refers to a program that acts as the most basic, bottommost work in the electronic device. Referring to fig. 2, the method at least includes steps 210 to 230, and is described in detail as follows:
Step 210, in the process of running the boot loader in the memory, if it is detected that the firmware in the memory needs to be upgraded, starting the transmission enabling of the single-wire port, and transmitting an upgrade data acquisition request to the external device.
The memory in the chip may be an erasable read-only memory, such as a FLASH memory (FLASH), which may store firmware. In the application, a Boot Loader (Boot Loader) is also stored in the memory, and the Boot Loader is a section of program in the electronic device (chip) for starting the kernel of the operating system, in other words, the Boot Loader is a first section of code executed after the embedded operating system in the electronic device is powered on, after the initialization of the CPU and the hardware is completed, the operating system image or the solidified embedded application program is loaded into the memory and then jumps to the space where the operating system is located, and the operating system is started to run; the boot loader is a program that is solidified in memory for execution before the firmware (embedded application) is run.
In the memory, the firmware and the boot loader are stored in a partition, and fig. 3 is a schematic view of partitioning a memory according to an embodiment of the present application, and as shown in fig. 3, a storage area of the memory includes: a first storage area 310, an application storage area 320, a backup storage area 330, and a second storage area 340. Wherein the first storage area 310 is used for storing a boot loader, and the application storage area 320 is used for storing firmware; backup storage 330 may be used to store user data for an application; the second storage area 340 is used for storing a status identifier, and it may be determined that firmware in the memory needs to be upgraded by the status identifier stored in the second storage area 340, for example, if the status identifier stored in the second storage area 340 is read as the first status identifier, it is determined that firmware in the memory needs to be upgraded. In some embodiments, the storage areas may be sequentially divided in order. For example, in FIG. 3, the first memory area 310 has a head address of 0x8000000 and the application memory area 320 has a head address of 0x8000c00; the head address of the backup storage area 330 is 0x8008400; the first address of the second memory area 340 is 0x800fc00. In fig. 3, the address range of the first memory area 310 is contiguous with the address range of the application memory area 320, the address range of the application memory area 320 is contiguous with the address range of the backup memory area 330, and the address range of the backup memory area 330 and the address range of the second memory area 340 are contiguous. Based on the partition diagram shown in fig. 3, the status identifier may be read from the second storage area according to the address of the second storage area 340, so as to determine whether the read status identifier is the first status identifier, so as to determine whether the firmware in the memory needs to be upgraded.
The chip is connected with the external device through the single-wire port on the chip, that is, one end of the data wire is connected with the single-wire port on the chip, the other end of the data wire is connected with the external device, and the chip and the external device are connected through a data wire.
Since a wired connection of a single wire is established between the chip and the external device through one data line, the single data line needs to take on the task of data transmission from the chip to the external device and from the external device to the chip, in practice, if data (or signals) are transmitted from the chip to the external device and data from the external device are received by the chip while being performed on one data line, data collision between the chip and the external device is easily caused. Therefore, in this application, to avoid this problem, before the chip sends the upgrade data acquisition request, the transmission enable of the single-wire port is turned on, and at this time, the reception enable of the single-wire port is kept off, so that the single-wire port on the chip can only perform signal/data transmission, but cannot perform signal/data reception; and then, based on the transmission enabling of the opened single-wire port, transmitting an upgrade data acquisition request to the external equipment. The upgrade data acquisition request is for requesting to acquire upgrade data of the firmware, and it is understood that the upgrade data acquisition request includes a firmware identification of the firmware to be upgraded.
Step 220, after the upgrade data acquisition request is sent, receiving, through the single-wire port, an upgrade data packet returned by the external device in response to the upgrade data acquisition request.
Before receiving the upgrade data packet, correspondingly closing the transmission enabling of the single-wire port on the chip, and opening the receiving enabling of the single-wire port.
In some embodiments, after a time period for sending the upgrade data acquisition request from the chip reaches a first time period, that is, after the transmission enabling of the single-wire port of the chip is started, if the time period for keeping the single-wire port in the on state reaches the first time period, the transmission enabling of the single-wire port is closed, and the receiving enabling of the single-wire port is opened, so as to receive an upgrade data packet returned by the external device in response to the upgrade data acquisition request. The first duration may be set according to actual needs, for example, the first duration may be 50ms, 60ms, or the like, which is not specifically limited herein.
It is understood that, in the case of turning off the transmission enable of the single-wire port and turning on the reception enable of the single-wire port, only data transmission (or signal transmission) from the external device to the chip can be realized between the chip and the external device, and data transmission (or signal transmission) from the chip to the external device cannot be realized. Therefore, the data collision caused by the fact that the chip sends signals/data to the external equipment based on the same data line in the process of receiving the upgrade data packet can be avoided, the situation that the upgrade data packet is lost is avoided, and the accuracy of the upgrade data packet received by the chip is guaranteed.
The data in the upgrade data packet is the data in the firmware upgrade data corresponding to the firmware. In a specific embodiment, since the data size of the firmware upgrade data corresponding to the firmware is large, the external device generally segments the firmware upgrade data to transmit the firmware upgrade data in multiple times. Thus, the upgrade data packet transmitted to the chip by the external device each time includes part of the data in the firmware upgrade data (for convenience of distinction, the data in the upgrade data packet is referred to as upgrade data). Under the condition that the external equipment transmits the firmware upgrading data for multiple times, each upgrading data packet comprises a data segmentation serial number corresponding to the data, so that after the chip receives all the upgrading data packets, the data in the upgrading data packets are combined according to the corresponding data segmentation serial numbers, and the firmware upgrading data corresponding to the firmware is obtained.
And step 230, upgrading the firmware in the memory according to the upgrade data packet.
After receiving the upgrade data packet, the chip can correspondingly acquire firmware upgrade data corresponding to the firmware from the upgrade data packet, and then write the firmware upgrade data corresponding to the firmware into the memory to replace the firmware stored before the memory, thereby realizing the upgrade of the firmware.
As described above, the memory is provided with the application memory area and the backup memory area, and the firmware is stored in the application memory area; in this case, as shown in fig. 4, step 230 includes the following steps 410-430, which are described in detail below:
and step 410, performing data verification on the upgrade data packet.
The upgrade data packet includes a check value, which is a value obtained by the sender (in this application, the external device) calculating the original data (i.e., the upgrade data to be transmitted) through a check algorithm. After receiving the upgrade data packet, the chip calculates the upgrade data in the upgrade data packet by adopting the same verification algorithm, and if the calculation result is consistent with the verification value in the upgrade data packet, the data verification is correct, namely the upgrade data packet passes the verification; if the calculation result is inconsistent with the check value in the upgrade data packet, an error occurs in the transmission process, namely the upgrade data packet is not checked. In a specific embodiment, the checking algorithm may be CRC (Cyclic Redundancy Check, cyclic redundancy check code), parity check, BCC (Block Check Character, information group check code), and the like, which are not specifically limited herein.
Step 420, if the upgrade data packet passes the verification, storing the upgrade data in the upgrade data packet into the backup storage area.
If the upgrade data packet passes the test, the data in the upgrade data packet is accurate, and therefore, the upgrade data in the upgrade data packet is temporarily stored in the backup storage area. And processing the subsequently received upgrade data packet according to the same processing procedure.
Step 430, if all the upgrade data packets corresponding to the firmware upgrade data of the firmware are received and all the upgrade data packets pass the verification, writing the upgrade data in the backup storage area into the application storage area to upgrade the firmware in the application storage area.
Under the condition that all the upgrade data packets corresponding to the firmware upgrade data of the firmware are received and all the upgrade data packets pass verification, the upgrade data in all the upgrade data packets are written into the backup storage area, and the upgrade data in all the upgrade data packets are combined according to the corresponding sequence to obtain the firmware upgrade data, so that all the upgrade data stored in the backup storage area are written into the application storage area, namely the firmware upgrade data are written into the application storage area, and the firmware stored in the application storage area is replaced correspondingly, so that the firmware is upgraded.
In this embodiment, since the external device transmits the firmware upgrade data corresponding to the firmware for multiple times, and the chip directly writes the upgrade data in the upgrade data packet into the application storage area instead of directly writing the upgrade data in the upgrade data packet into the backup storage area after receiving the upgrade data packet from the external device and checking the upgrade data packet, after all the upgrade data packets are received and checked, writing all the upgrade data into the application storage area from the backup storage area, so that the situation that the data written into the application storage area is incomplete due to the fact that part of the upgrade data packet is not checked or part of the upgrade data packet is not received in the middle can be avoided, and further the firmware upgrade fails can be avoided, and the situation that the data writing into the application storage area is performed for multiple times can also be avoided.
In some embodiments, after step 410, the method further comprises: accumulating error times of the upgrade data packet which is not checked; and if the accumulated error times reach the time threshold, sending upgrade failure prompt information to the external equipment.
That is, if one upgrade data packet is not checked, the number of errors is added up by 1, so that the number of errors is the number of upgrade data packets that are checked to be failed. The frequency threshold may be set according to actual needs, for example, the frequency threshold is 8, 9, 10, 15, etc. And under the condition that the accumulated number of errors reaches the number threshold, more upgrade data packets indicating errors are displayed, so that if the upgrade data packets are continuously received, the number of the retransmission upgrade data packets is more, and the time required for upgrading the firmware is longer.
Therefore, in this embodiment, when the accumulated number of errors reaches the threshold number of times, the transmission enable of the single-wire port of the chip may be turned on, the reception enable of the single-wire port of the chip may be turned off, and the upgrade failure prompt information may be sent to the external device, so that the external device may stop sending the upgrade data packet to the chip continuously in response to the upgrade failure prompt information.
In some embodiments, the method further includes the following steps A1 and A2, described in detail below:
and step A1, in the process of running the boot loader in the memory, if the firmware in the memory is determined to be required to be run, verifying the validity of the firmware in the memory.
In the case where a second storage area for storing the status identifier is provided in the memory, the status identifier may be read from the second storage area, and it may be determined whether or not the firmware in the memory needs to be executed based on the read status identifier. Specifically, the second state identifier may indicate that firmware in the memory needs to be executed, and if the state identifier read from the second storage area is the second state identifier, it is determined that firmware in the memory needs to be executed.
In some embodiments, the firmware is stored in an application storage area in the memory; the step of verifying the validity of the firmware in the memory comprises: acquiring a first address of the application storage area and acquiring a second address in the application storage area; and if the data pointed by the first address of the application storage area is positioned in a random access memory in the processor and the data pointed by the second address of the application storage area is positioned in the memory, determining that the firmware in the application storage area is valid.
In the case that the memory is a flash memory, in the process of judging the validity of the firmware, correspondingly judging whether the data pointed by the second address in the application storage area is located in the flash memory or not.
In general, the content pointed to by the first address in the application storage area is the stack top pointer, so the data pointed to by the first address in the application storage area is the data pointed to by the stack top pointer.
If at least one of the random access memory in the processor, to which the data pointed to by the first address of the application memory area is located, and the memory to which the data pointed to by the second address in the application memory area is located is not satisfied, it is determined that the firmware in the application memory area is invalid.
And step A2, if the firmware in the memory is determined to be valid, operating the firmware.
In some embodiments, in the case where the chip is a Cortex-M0 chip, before running the firmware, the interrupt vector table in the application memory area is loaded into the RAM of the chip, the memory mapping is modified, the SRAM area is mapped to a specified zero address (the specified zero address is the base address of the firmware load address), and then the firmware in the application memory area can be executed in correspondence with the jump.
In some embodiments, the method further comprises: and in the process of running the firmware, if a firmware update command is received, updating the state identifier stored in the memory into the first state identifier.
The firmware update command may be sent by the external device to the chip. The firmware update command is used for indicating that the firmware has a new version, so that the state identifier stored in the memory is updated to the first state identifier according to the firmware update command, and the firmware in the memory is conveniently updated based on the first state identifier.
In some embodiments, after the updating the state identifier stored in the memory to the first state identifier if the firmware update command is received during the running process of the firmware, the method further includes the following step B1 and step B2, which are described in detail below:
and B1, modifying the address mapping corresponding to the memory to map the address where the boot loader is located in the memory to a specified memory address, and executing the processor in the chip from the specified memory address after power-on or reset. The specified memory address may be a 0x0 address.
And step B2, running the starting loader based on the address mapping corresponding to the modified memory. After modifying the address mapping corresponding to the memory, the process may then jump to run the boot loader.
In some embodiments, the method further comprises the following steps C1-C3, described in detail below:
and step C1, in the process of running the boot loader in the memory, if the state identifier stored in the memory is other state identifiers except the first state identifier and the second state identifier, starting the transmission enabling of the single-wire port, and transmitting a firmware upgrading request to the external equipment.
Similarly, in the case where the transmission enable of the single-wire port is turned on, the reception enable of the single-wire port is turned off, thereby ensuring that the single-wire port can only transmit data and cannot receive data at the same time.
And step C2, after the firmware upgrading request is sent, closing the sending enabling of the single-wire port, and opening the receiving enabling of the single-wire port.
And step C3, if a request response packet returned by the external device in response to the firmware upgrading request is received after the receiving enabling of the single-wire port is opened, executing the steps of opening the sending enabling of the single-wire port and sending an upgrading data obtaining request to the external device.
The request response packet returned by the external device in response to the firmware upgrade request is used to indicate that firmware upgrade data corresponding to firmware exists currently, so that based on the request response packet, the chip can determine that firmware upgrade data which can be downloaded to firmware currently is available, that is, return to step 210, and upgrade the firmware according to the process of steps 210-230.
In the method, the boot loader in the memory of the chip is utilized to realize the jump from the operation of the boot loader to the upgrading of the firmware, namely, in the process of operating the boot loader, under the condition that the state identifier read in the memory is a first state identifier indicating that the firmware needs to be upgraded, the firmware upgrading data of the firmware is requested to the external device by utilizing the wired connection of a single wire between the chip and the external device so as to upgrade the firmware in the chip. In addition, in the process of interaction by utilizing the wired connection of the single wire between the chip and the external equipment, only one of the transmission enabling and the receiving enabling of the single wire port in the chip is available at the same time, so that the chip is ensured to either receive data or transmit data at the same time, and the situation that the data is transmitted and received is avoided, so that the problem of data collision in the interaction process of the chip and the external equipment can be effectively avoided, and the accuracy of an upgrade data packet received by the chip is further ensured. By adopting the scheme, the problem that firmware in a chip cannot be upgraded under the condition of single data line in the related technology can be effectively solved.
FIG. 5 is a flow chart of a firmware upgrade method according to an embodiment of the present application, as shown in FIG. 5, including:
step 501, hardware initialization (set single line mode). After running a Boot Loader (Boot Loader), hardware initialization may be performed.
Step 502, reading a state identifier in a second storage area; if the status identifier is the first status identifier, step 503 is executed; if the status identifier is the second status identifier, executing step 513; if the status identifier is other than the first status identifier and the second status identifier, step 515 is performed. The first state identifier and the second state identifier may be set according to actual needs, for example, may be set, where the first state identifier is 0x5566, and the second state identifier is 0x1144.
Step 503, send an upgrade data acquisition request using a 1-wire line. In step 503, after the chip establishes a wired connection with the external device through the 1-wire (i.e., a single data line), the chip is triggered to open the transmission enable of the single-wire port on the chip, and close the reception enable of the single-wire port, so that only the chip can send an upgrade data acquisition request to the external device at the same time.
Step 504, waiting a first duration; the first duration may be 50ms; that is, after the transmission enable of the on-chip single-wire port is turned on, the transmission enable of the single-wire port is turned off after the duration of keeping the transmission enable on reaches the first duration, and the reception enable of the single-wire port is turned on to receive data from the external device. In some embodiments, the chip is not allowed to retransmit data during the wait period (i.e., within 50ms after the transmit enable is turned on) to avoid data collisions in the data lines.
And 505, receiving an upgrade data packet returned by the external equipment by using a 1-wire line. After the reception enable of the single-wire port on the chip is turned on, the chip can correspondingly receive data (i.e., an upgrade data packet in this step) from the external device.
Step 506, checking whether the data in the upgrade data packet is correct; if so, executing step 507; if not, go to step 510.
And step 507, storing the upgrade data in the upgrade data packet to the application backup area.
Step 508, whether the upgrade data packet is received entirely; if it is determined to be received in its entirety, step 509 is performed; if it is determined that all of the signals have not been received, the process returns to step 503.
Step 509, writing firmware upgrade data from the backup storage area to the application storage area. Thus, the firmware in the application storage area is upgraded.
In step 510, the number of errors is accumulated.
Step 511, whether the error number reaches the number threshold; if so, go to step 512; if not, go back to step 503.
Step 512, sending upgrade failure prompt information by using a 1-wire line; thereafter, step 513 is performed. Similarly, in step 512, the transmission enable of the on-chip single-wire port is correspondingly turned on, and the reception enable of the single-wire port is turned off, so as to send the upgrade failure prompt information to the external device.
Step 513, verifying the validity of the firmware in the application storage area; if the verification determines that the firmware is valid and the chip is Cortex-M0, step 514 is executed; if the verification determines that the firmware is invalid, step 515 is performed.
Step 514 includes: 1. copying the interrupt vector table in the application memory area into RAM (Random Access Memory ); 2. modifying a Memory map, and mapping an SRAM (Static Random-Access Memory) to 0x0; 3. jump to firmware in the application store.
Step 515, send firmware upgrade request using 1-wire. Similarly, in step 515, the on-chip single-wire port transmission enable is turned on, and the single-wire port reception enable is turned off, so as to transmit a firmware upgrade request to the external device.
Step 516, waiting a first duration; for example, the first duration may be 50ms.
Step 517, whether a request response packet is received; if it is determined that the request response packet is received, step 503 is executed; if it is determined that the request reply packet has not been received, execution returns to step 515.
Based on the embodiment of fig. 5, the interaction between the chip and the external device is realized by using a 1-wire single data line, and the upgrading of the firmware in the chip is realized. In addition, in the process of realizing interaction between the chip and the external device based on the data line, the transmitting enabling and the receiving enabling of the port are triggered, so that data transmission in only one direction is allowed at the same time (for example, when the chip needs to transmit data, the transmitting enabling of the single-wire port of the chip is opened, the receiving enabling of the single-wire port is closed, and when the chip needs to receive data, the receiving enabling of the single-wire port is opened, the transmitting enabling of the single-wire port is closed), and therefore the problem that data collision is caused by data interaction in two directions at the same time in the process of utilizing the single data line can be avoided. In addition, in the application, the boot loader is stored in the memory, so that the firmware in the application storage area can be upgraded according to the read state identification in the process of running the boot loader, and the firmware in the application storage area can be upgraded under the condition that the chip and the external equipment interact through a single data line.
The following describes apparatus embodiments of the present application that may be used to perform the methods of the above-described embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments described above in the present application.
FIG. 6 is a block diagram of a firmware upgrade apparatus for upgrading firmware in a memory in a chip, the chip including a single wire port through which the chip establishes a single wire wired connection with an external device, according to an embodiment of the present application; as shown in fig. 6, the firmware upgrade apparatus includes:
a sending module 610, configured to, in a process of running a boot loader in the memory, if it is detected that firmware in the memory needs to be upgraded, start a sending enable of the single-wire port, and send an upgrade data acquisition request to the external device;
a receiving module 620, configured to receive, through the single-wire port, an upgrade data packet returned by the external device in response to the upgrade data acquisition request after sending the upgrade data acquisition request;
and the upgrade module 630 is configured to upgrade the firmware in the memory according to the upgrade data packet.
In some embodiments, an application storage area and a backup storage area are arranged in the memory, and the firmware is stored in the application storage area; in this embodiment, the upgrade module 630 includes:
the verification unit is used for carrying out data verification on the upgrading data packet;
the storage unit is used for storing the upgrade data in the upgrade data packet to the backup storage area if the upgrade data packet passes the verification;
and the writing unit is used for writing the upgrade data in the backup storage area into the application storage area to upgrade the firmware in the application storage area if all the upgrade data packets corresponding to the firmware upgrade data of the firmware are received and all the upgrade data packets pass verification.
In some embodiments, the firmware upgrade apparatus further comprises:
the accumulation module is used for accumulating the error times of the upgrade data packet which is not checked;
and the prompt information generation module is used for sending upgrade failure prompt information to the external equipment if the accumulated error times reach the time threshold.
In some embodiments, the firmware upgrade apparatus further comprises:
the validity verification module is used for verifying the validity of the firmware in the memory if the firmware in the memory is determined to be required to be operated in the process of operating the boot loader in the memory;
And the firmware running module is used for running the firmware if the firmware in the memory is determined to be valid.
In some embodiments, the firmware is stored in an application storage area in the memory; in this embodiment, the validity verification module includes:
an acquiring unit, configured to acquire a first address of the application storage area, and acquire a second address in the application storage area;
and the effective determining unit is used for determining that the firmware in the application storage area is effective if the data pointed by the first address of the application storage area is positioned in the random access memory in the processor and the data pointed by the second address in the application storage area is positioned in the memory.
In some embodiments, the memory stores a status identifier, and if the status identifier is a first status identifier, it is determined that firmware in the memory needs to be upgraded; and if the state identifier is a second state identifier, determining that the firmware in the memory needs to be operated.
In some embodiments, the firmware upgrade apparatus further comprises: and the state identifier updating module is used for updating the state identifier stored in the memory into the first state identifier if a firmware updating command is received in the process of running the firmware.
In some embodiments, the firmware upgrade apparatus further comprises:
the address mapping modification module is used for modifying the address mapping corresponding to the memory so as to map the address where the boot loader is located in the memory to a specified memory address, and a processor in the chip starts to execute from the specified memory address after power-on or reset;
and the operation module is used for operating the starting loader based on the address mapping corresponding to the modified memory.
In some embodiments, the firmware upgrade apparatus further comprises:
the firmware upgrading request sending module is used for starting the sending enabling of the single-wire port and sending a firmware upgrading request to the external equipment if the state identifier stored in the memory is other state identifiers except the first state identifier and the second state identifier in the process of running the starting loading program in the memory;
the enabling switching module is used for closing the sending enabling of the single-wire port and opening the receiving enabling of the single-wire port after the firmware upgrading request is sent;
and if a request response packet returned by the external device in response to the firmware upgrading request is received after the receiving enabling of the single-wire port is opened, executing the steps of starting the sending enabling of the single-wire port and sending an upgrading data obtaining request to the external device.
The application also provides a chip, the chip comprises a memory and a single-wire port, the chip establishes a single-wire wired connection with external equipment through the single-wire port, and the chip upgrades the firmware in the memory according to the firmware upgrading method. The chip may be a single chip microcomputer, a microcontroller, a microprocessor, etc., and is not particularly limited herein.
Fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 7, the electronic device includes a processor 710 and a memory 720 coupled to the processor 710. The memory 720 stores program instructions for implementing the firmware upgrade method of any of the above embodiments. Processor 710 is configured to execute program instructions stored in memory 720 to implement firmware upgrades. The processor 710 may also be referred to as a CPU (Central Processing Unit ). Processor 710 may be an integrated circuit chip with signal processing capabilities. Processor 710 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The electronic device of the embodiment of the application may be, but is not limited to, a body weight scale, a body fat scale, a nutritional scale, an infrared electronic thermometer, a pulse oximeter, a body composition analyzer, a mobile power supply, a quick charger, a vehicle-mounted charger, an adapter, a display, a USB (Universal Serial Bus ) docking station, a stylus, a real wireless headset, a car center control screen, a car, an intelligent wearable device, a mobile terminal, an intelligent home device, a keyboard, a mouse, and the like. The intelligent wearing equipment comprises, but is not limited to, an intelligent watch, an intelligent bracelet and a cervical vertebra massage instrument. Mobile terminals include, but are not limited to, smartphones, notebook computers, tablet computers, POS (point of sales terminal, point of sale terminal) machines. The intelligent household equipment comprises, but is not limited to, an intelligent socket, an intelligent electric cooker, an intelligent sweeper and an intelligent lamp.
According to an aspect of the embodiments of the present application, there is provided a computer readable storage medium having stored thereon computer readable instructions which, when executed by a processor, implement a firmware upgrade method as in any of the method embodiments above.
It should be noted that, the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium may be, for example, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-Only Memory (ROM), an erasable programmable read-Only Memory (Erasable Programmable Read Only Memory, EPROM), flash Memory, an optical fiber, a portable compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one aspect of embodiments of the present application, there is provided a computer program product comprising computer instructions which, when executed by a processor, implement a firmware upgrade method as in any of the method embodiments above.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. Where each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It should be noted that although in the above detailed description several modules or units of a device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functions of two or more modules or units described above may be embodied in one module or unit, in accordance with embodiments of the present application. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the application pertains.
It is to be understood that the present application is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (13)

1. The firmware upgrading method is characterized by being used for upgrading firmware in a memory in a chip, wherein the chip comprises a single-wire port, and the chip establishes a single-wire wired connection with an external device through the single-wire port; the method comprises the following steps:
in the process of running the boot loader in the memory, if the firmware in the memory is detected to need to be upgraded, starting the transmission enabling of the single-wire port, and transmitting an upgrade data acquisition request to the external equipment;
after the upgrade data acquisition request is sent, an upgrade data packet returned by the external equipment in response to the upgrade data acquisition request is received through the single-wire port;
and upgrading the firmware in the memory according to the upgrading data packet.
2. The method of claim 1, wherein an application storage area and a backup storage area are provided in the memory, and the firmware is stored in the application storage area;
the upgrading the firmware in the memory according to the upgrade data packet includes:
performing data verification on the upgrading data packet;
if the upgrade data packet passes the verification, storing upgrade data in the upgrade data packet into the backup storage area;
If all the upgrade data packets corresponding to the firmware upgrade data of the firmware are received and all the upgrade data packets pass verification, the upgrade data in the backup storage area is written into the application storage area so as to upgrade the firmware in the application storage area.
3. The method of claim 2, wherein after the data verification of the upgrade data packet, the method further comprises:
accumulating error times of the upgrade data packet which is not checked;
and if the accumulated error times reach the time threshold, sending upgrade failure prompt information to the external equipment.
4. The method according to claim 1, wherein the method further comprises:
during the process of running the boot loader in the memory, if the firmware in the memory is determined to be required to be run, verifying the validity of the firmware in the memory;
and if the firmware in the memory is determined to be valid, running the firmware.
5. The method of claim 4, wherein the firmware is stored in an application storage area in the memory;
the verifying the validity of the firmware in the memory includes:
Acquiring a first address of the application storage area and acquiring a second address in the application storage area;
and if the data pointed by the first address of the application storage area is positioned in a random access memory in the processor and the data pointed by the second address of the application storage area is positioned in the memory, determining that the firmware in the application storage area is valid.
6. The method of claim 4 or 5, wherein the memory stores a status identifier, and if the status identifier is a first status identifier, determining that firmware in the memory needs to be upgraded; and if the state identifier is a second state identifier, determining that the firmware in the memory needs to be operated.
7. The method of claim 6, wherein the method further comprises:
and in the process of running the firmware, if a firmware update command is received, updating the state identifier stored in the memory into the first state identifier.
8. The method of claim 7, wherein during the running of the firmware, after updating the state identifier stored in the memory to the first state identifier if a firmware update command is received, the method further comprises:
Modifying the address mapping corresponding to the memory to map the address where the boot loader is located in the memory to a specified memory address, and executing the processor in the chip from the specified memory address after powering on or resetting;
and operating the starting loader based on the address mapping corresponding to the modified memory.
9. The method of claim 6, wherein the method further comprises:
in the process of running the boot loader in the memory, if the state identifier stored in the memory is other state identifiers except the first state identifier and the second state identifier, starting the transmission enabling of the single-wire port, and transmitting a firmware upgrading request to the external equipment;
after the firmware upgrading request is sent, closing the sending enabling of the single-wire port, and opening the receiving enabling of the single-wire port;
and if a request response packet returned by the external device in response to the firmware upgrading request is received after the receiving enabling of the single-wire port is opened, executing the steps of starting the sending enabling of the single-wire port and sending an upgrading data obtaining request to the external device.
10. The firmware upgrading device is characterized by being used for upgrading firmware in a memory in a chip, wherein the chip comprises a single-wire port, and the chip establishes a single-wire wired connection with an external device through the single-wire port; the device comprises:
the sending module is used for starting the sending enabling of the single-wire port and sending an upgrade data acquisition request to the external equipment if the firmware in the memory is detected to need to be upgraded in the process of running the starting loading program in the memory;
the receiving module is used for receiving an upgrade data packet returned by the external equipment in response to the upgrade data acquisition request through the single-wire port after the upgrade data acquisition request is sent;
and the upgrading module is used for upgrading the firmware in the memory according to the upgrading data packet.
11. A chip comprising a memory and a single wire port, the chip establishing a single wire wired connection with an external device through the single wire port, the chip upgrading firmware in the memory according to the method of any one of claims 1 to 9.
12. An electronic device comprising the chip of claim 10.
13. A computer readable storage medium having computer readable instructions stored thereon, which when executed by a processor, implement the method of any of claims 1 to 9.
CN202310499508.XA 2023-05-04 2023-05-04 Firmware upgrading method, device, chip, electronic equipment and storage medium Pending CN116560689A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310499508.XA CN116560689A (en) 2023-05-04 2023-05-04 Firmware upgrading method, device, chip, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310499508.XA CN116560689A (en) 2023-05-04 2023-05-04 Firmware upgrading method, device, chip, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116560689A true CN116560689A (en) 2023-08-08

Family

ID=87501208

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310499508.XA Pending CN116560689A (en) 2023-05-04 2023-05-04 Firmware upgrading method, device, chip, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116560689A (en)

Similar Documents

Publication Publication Date Title
CN110134415A (en) A kind of controller and its method for upgrading software and device
CN104040519B (en) HID I2The host computer side of C data bus is implemented
CN102541469B (en) Method, equipment and system for protecting data in firmware storage system
US11435985B2 (en) Electronic device and operation method thereof
CN109388345B (en) Data reading method of memory, display device and computer readable storage medium
CN111813428A (en) Method and device for upgrading terminal firmware, electronic equipment and storage medium
CN114003538B (en) Identification method of intelligent network card and intelligent network card
CN107861832B (en) Data verification method and device and readable storage medium
EP2798428B1 (en) Apparatus and method for managing operation of a mobile device
US11507718B1 (en) Chip verification system and verification method therefor
CN112379932A (en) Boot method and Boot device of electronic equipment and electronic equipment
CN103842966A (en) Electronic device
US7814254B2 (en) Mode setting method and system in hot plug of PCI device
CN109002305A (en) A kind of update method and its system of device program
CN107332589B (en) Firmware upgrading device based on bluetooth
KR20160120105A (en) Electronic device and method for processing in the electronic device
CN113360161A (en) Resource upgrading method and related product
CN116560689A (en) Firmware upgrading method, device, chip, electronic equipment and storage medium
US20150168934A1 (en) Electronic device and method for loading program code thereof
CN115576484A (en) Data reading and writing method and device, electronic equipment and storage medium
CN111061603B (en) Motherboard capable of recording self-checking data, computer and recording method of self-checking data
CN212181459U (en) FPGA upgrading system
JP2003122594A (en) Semiconductor device and evaluation tool
CN113010114A (en) Data processing method and device, computer equipment and storage medium
TWI228219B (en) Method for recording test procedure

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination