[go: up one dir, main page]

WO2020062887A1 - Firmware upgrading method and system based on flash micro-controller, and flash micro-controller - Google Patents

Firmware upgrading method and system based on flash micro-controller, and flash micro-controller Download PDF

Info

Publication number
WO2020062887A1
WO2020062887A1 PCT/CN2019/086802 CN2019086802W WO2020062887A1 WO 2020062887 A1 WO2020062887 A1 WO 2020062887A1 CN 2019086802 W CN2019086802 W CN 2019086802W WO 2020062887 A1 WO2020062887 A1 WO 2020062887A1
Authority
WO
WIPO (PCT)
Prior art keywords
upgrade
flash memory
specific
flash
page
Prior art date
Application number
PCT/CN2019/086802
Other languages
French (fr)
Chinese (zh)
Inventor
林云胜
王树东
Original Assignee
深圳市慧嘉智科技有限公司
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 深圳市慧嘉智科技有限公司 filed Critical 深圳市慧嘉智科技有限公司
Publication of WO2020062887A1 publication Critical patent/WO2020062887A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/654Updates using techniques specially adapted for alterable solid state memories, e.g. for EEPROM or flash memories

Definitions

  • the present invention relates to the technical field of firmware upgrading, and in particular, to a method and system for upgrading firmware based on a flash microcontroller, and a flash microcontroller.
  • the firmware written in the original product may not meet the needs of the current product upgrade. For example, when a user upgrades a USB device, forcing an unexpected situation such as unplugging or powering off the USB device, the upgrade will fail, which will cause the entire device firmware to become unusable. This means that the product's safety and stability functions are poor, which also increases the production cost of the product.
  • the prior art urgently needs a technology that can continue to upgrade normally without damaging the hardware in the scenario where the USB device is arbitrarily plugged or inserted or other interrupted upgrade operations are performed.
  • Embodiments of the present invention provide a flash microcontroller-based firmware upgrade method and system, and a flash microcontroller, which are used to solve various unexpected situations that a USB device cannot normally upgrade during the firmware upgrade process, causing firmware damage and The product cannot be used normally.
  • a first aspect of the present invention provides a firmware upgrade method based on a flash memory microcontroller.
  • the flash memory microcontroller includes a processor and a flash memory.
  • the flash memory stores an application program and a boot upgrade program.
  • the boot upgrade program is used for Starting or upgrading the application program; the method comprises: running the boot upgrade program after the flash microcontroller is powered on to determine whether an upgrade instruction is received; if the upgrade instruction is not received, further determining the Whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or a specific code is not stored in the specific address of the flash memory, the application program is upgraded, and the specific address of the flash memory is to be updated when the upgrade is about to be completed Write specific code.
  • the method further includes: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, starting the application program.
  • the application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed, including: communicating with a host computer through a USB port to obtain the application program ’s Update data; in pages, erase application programs stored in the flash memory page by page and write the update data.
  • the above-mentioned upgrade is about to be completed, which means that only the last page, that is, the specific page has not been written with the update data, and the other pages have been written with the update data.
  • erasing an application program stored in the flash memory and writing update data page by page includes: executing an erase command to erase the original data of the current page; executing a write command to write on the current page Enter the update data; execute the verification command, read the update data written in the current page, calculate the verification code, and send the verification code to the upper computer so that the upper computer can verify the verification code. If the verification fails, The user will be prompted to upgrade again.
  • a second aspect of the present invention provides a flash memory microcontroller, including a flash memory and a processor.
  • the flash memory stores an application program and a boot upgrade program.
  • the processor runs the flash memory. Guide the upgrade program and perform the following steps: determine whether an upgrade instruction is received; if the upgrade instruction is not received, further determine whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or a If the specific address does not store the specific code, the application is upgraded, and when the upgrade is about to be completed, the specific code is written in the specific address of the flash memory.
  • the processor further executes the following steps: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, the application program is started.
  • the boot upgrade program is specifically stored in a few pages of memory area including a processor reset address for implementing an online programming ISP function, and the size of the memory area can be dynamically adjusted according to processor performance, or
  • the storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on.
  • a third aspect of the present invention provides a USB-based firmware upgrade system, including: a flash memory microcontroller and a host computer, wherein the flash microcontroller communicates with the host computer through a USB port; the flash microcontroller includes a processor and Flash memory, which stores an application program and a boot upgrade program, the boot upgrade program is used to start or upgrade the application program; the flash microcontroller is used to: run the boot upgrade program after power-on to determine whether Receive the entry upgrade instruction; if no entry upgrade instruction is received, further determine whether a specific code is stored in the specific address of the flash memory; if receive the upgrade instruction or the specific address of the flash memory does not store a specific code, The application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed; the host computer is used to transmit the update data of the application program to the flash microcontroller, and according to the upgrade steps A control instruction is issued to control the boot upgrade program to upgrade the application program.
  • a fourth aspect of the present invention provides a firmware upgrade device, which is deployed in a flash microcontroller.
  • the flash microcontroller includes a flash memory and a processor, the flash memory stores an application program, and the device includes a judgment module. After the flash microcontroller is powered on, it is judged whether an upgrade instruction is received; if the upgrade instruction is not received, it is further judged whether a specific code is stored in a specific address of the flash memory; a processing module is used to When the upgrade instruction or the specific address of the flash memory does not store specific code, the application program is upgraded, and when the upgrade is about to be completed, the specific code is written in the specific address of the flash memory.
  • the integrity of the upgrade is indicated by checking during the upgrade process, and the integrity of the application is verified by storing specific code in the specific address of the flash memory. Even if the upgrade fails due to unexpected conditions such as power failure, plugging, etc. during the upgrade process, power on again Later, due to the inability to detect specific data, the application is incomplete, and the incomplete application will not be started. Instead, it will enter the upgrade process and continue to complete the upgrade to ensure the integrity of the application firmware in the flash microcontroller. It can be seen that the solution of the invention improves the stability of the upgrade, can effectively avoid the problem that the normal use cannot be restored after the upgrade is interrupted, and improves the safety, stability and practicability of the product.
  • FIG. 1 is a schematic flowchart of a firmware upgrade method according to an embodiment of the present invention
  • FIG. 2 is a flowchart of implementing firmware upgrade in an application scenario embodiment of the present invention
  • FIG. 3 is a schematic structural diagram of a flash memory microcontroller according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a firmware upgrade device according to an embodiment of the present invention.
  • an embodiment of the present invention provides a firmware upgrade method based on a flash microcontroller.
  • This method can be used to upgrade firmware in a USB device such as a flash microcontroller.
  • the flash microcontroller includes a processor and a flash memory.
  • the flash memory stores firmware such as an application program and a boot upgrade program, and the boot upgrade program is used to start or upgrade the application program.
  • the method may include:
  • step S1 After the flash microcontroller is powered on, run the boot upgrade program to determine whether an upgrade instruction is received; if yes, go to step S3; if not, go to step S2;
  • step S2 It is further determined whether a specific code is stored in a specific address of the flash memory; if not, proceed to step S3; if yes, proceed to step S4;
  • upgrading the application and writing specific code at a specific address of the flash memory when the upgrade is about to be completed may include: communicating with a host computer through a USB port to obtain update data of the application; The application program stored in the flash memory is erased page by page and written with updated data.
  • the step of erasing the application program stored in the flash memory and writing updated data page by page may specifically include: executing an erase command to erase the original data of the current page; executing a write command to write in the current page Update data; execute the check command, read the updated data written in the current page, calculate the check code, and send the check code to the host computer so that the host computer can verify the check code.
  • the upper computer passes the verification, it transmits the updated data of the next page to the flash microcontroller, and the flash microcontroller performs the erase and write operations on the next page, and so on, until the data of all pages is rewritten. Complete all upgrades.
  • the specific code of a specific page is used to indicate the integrity of the firmware upgrade. Once it is erased or deleted, it means that the application is no longer complete and needs to be upgraded. In this way, once the upgrade process is interrupted unexpectedly, you can determine whether the current application is incomplete by detecting whether it contains specific data after the power is turned on again, and you need to upgrade without jumping to the code area of the application and starting the incomplete application. , Throwing various errors. Only when the entire application is upgraded, a specific address will be written into a specific code. When the specific code is detected after power-on, it means that the current application is complete and can be started. As a result, the upgrade efficiency is improved, the problem that normal use cannot be resumed after the upgrade is interrupted can be effectively avoided, and the safety, stability and practicability of the product are improved.
  • a Flash microcontroller unit MCU
  • APP application program
  • the upgrade program is used to guide the upgrade program to cooperate with the software of the host computer such as APP to upgrade or update the application program.
  • the host computer is, for example, a personal computer (PC) or a server.
  • the boot upgrade program is, for example, a boot loader program.
  • the overall implementation process includes: placing the user code of the application to be upgraded into the host computer software.
  • the boot code in the upgrade boot program is first run to select the mode, that is, to determine whether to enter Upgrade, if not enter the upgrade, execute the normal application program, otherwise execute the upgrade code in the upgrade boot program.
  • the MCU communicates with the host computer software through the USB port, so that the user code in the host computer software is transmitted to the MCU, the MCU writes to Flash, and sends the check code to the host computer software as judged by the host computer APP The check code is correct, so it is executed page by page.
  • the boot code can be placed in this area.
  • the storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on.
  • the judgment condition is usually determined by the actual situation, and it is generally whether or not an upgrade instruction is received. For example, if a keystroke instruction is detected to indicate that the upgrade is to be entered.
  • USB upgrade-MCU part USB upgrade-MCU part.
  • the host computer and MCU implement data exchange through the USB port.
  • the data needs to be encrypted and verified.
  • the user code is upgraded in units of pages, that is, to erase a page and write a Page, check one page, and after confirming that it is correct, proceed to the next page.
  • This process can be implemented with the "set port” and “getreport” commands of USB.
  • the following protocol can be defined:
  • getreport [1] refers to the first byte of data received by the get command.
  • the APP part is written in C ++, and the process is similar to the above process. The difference is that the APP communicates with the MCU as the initiator of the command and controls the MCU to perform the upgrade process.
  • a specific data such as 32 bits, is written in advance at a fixed address / specific address in the flash area of the user code, and the data is used to indicate the completeness of the upgrade, or the integrity of the application. For example, it can be written during the last upgrade.
  • the APP needs to do the corresponding processing. After entering the upgrade, the APP should first erase the page so that the specific data is erased; if the data is erased, it means that the user code is incomplete.
  • the APP erases page by page and writes page by page;
  • Processing is needed in the boot code of the MCU's boot upgrade program. It is judged that if the specific data does not exist, it can only enter the upgrade and cannot jump to the user code area.
  • the application is wrong or incomplete, which will cause an unpredictable error in the application. If there is no such limitation, that is, the data is incomplete, it can only be upgraded and cannot enter the application; users will mistake it as an application problem, because the incomplete data may have most of the functions, and it will not be manually upgraded again. An error occurs.
  • an embodiment of the present invention provides a flash memory microcontroller 30 including a flash memory 31 and a processor 32.
  • the flash memory 31 stores an application program 33 and a boot upgrade program 34.
  • the processor 32 runs the boot upgrade program and performs the following steps:
  • the processor 32 further executes the following step: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, the application program is started.
  • the boot upgrade program is specifically stored in a page memory area containing a processor reset address for implementing the ISP function, and the size of the memory area can be dynamically adjusted according to the performance of the processor.
  • the storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on, that is, the storage space of the boot upgrade program is located before the storage space of the application program.
  • a firmware upgrade device 40 is further provided, which is deployed in a flash memory microcontroller.
  • the flash microcontroller includes a flash memory and a processor, and the flash memory stores an application program.
  • the device 40 includes:
  • a judging module 41 is configured to determine whether an upgrade instruction is received after the flash microcontroller is powered on; if the upgrade instruction is not received, further determine whether a specific code is stored in a specific address of the flash memory;
  • the processing module 42 is configured to upgrade the application program if an upgrade instruction is received or the specific address of the flash memory does not store the specific code, and write the specific code at the specific address of the flash memory when the upgrade is about to be completed. .
  • An embodiment of the present invention further provides a USB-based firmware upgrade system, including: a flash memory microcontroller and a host computer, wherein the flash microcontroller communicates with the host computer through a USB port;
  • the flash memory microcontroller includes a processor and a flash memory.
  • the flash memory stores an application program and a boot upgrade program.
  • the boot upgrade program is used to start or upgrade the application program.
  • the flash microcontroller is used to: After power-on, the boot upgrade program is run to determine whether an upgrade instruction is received. If the upgrade instruction is not received, it is further determined whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or the flash memory is received The specific address does not store the specific code, then upgrade the application, and write the specific code at the specific address of the flash memory when the upgrade is about to be completed;
  • the host computer is configured to transmit the update data of the application program to the flash microcontroller, and issue a control instruction according to the upgrade step to control the boot upgrade program to upgrade the application program.
  • the embodiments of the present invention provide a firmware upgrade method based on a flash microcontroller, a firmware upgrade device, a flash microcontroller, and a USB-based firmware upgrade system.
  • Effect The specificity of the code is stored in the specific address of the flash memory to indicate the integrity of the upgrade. Even if the upgrade fails due to unexpected conditions such as power failure, plugging, etc., the specific data will not be detected after the power is turned on again, and it will not start Incomplete applications will instead enter the upgrade process and continue to complete the upgrade to ensure the integrity of the application firmware in the flash microcontroller. It can be seen that the solution of the present invention improves the upgrade efficiency, can effectively avoid the problem that normal use cannot be restored after the upgrade is interrupted, and improves the safety, stability and practicability of the product.

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

A firmware upgrading method and system based on a flash micro-controller (30), and the flash micro-controller (30). The method comprises: after the flash micro-controller (30) is powered on, running a bootstrap upgrade program (34), and determining whether an instruction for entering an upgrade is received; if an instruction for entering an upgrade is not received, further determining whether a specific code is stored in a specific address of a flash memory (31); and if an instruction for entering an upgrade is received or the specific code is not stored in the specific address of the flash memory (31), upgrading an application program (33), and when the upgrade is about to be completed, writing the specific code into the specific address of the flash memory (31). The upgrade integrity is indicated by means of storing a specific code in a specific address of the flash memory (31); therefore, if the upgrade fails due to something unexpected, it can be ensured that an upgrade process is entered after powering on again so as to continuously complete the upgrade. The problem of it not being possible to restore normal use after an upgrade is interrupted can be effectively avoided, thereby improving the security, stability and practicability of a product.

Description

基于闪存微控制器的固件升级方法和系统及闪存微控制器Firmware upgrading method and system based on flash microcontroller and flash microcontroller 技术领域Technical field
本发明涉及固件升级技术领域,具体涉及一种基于闪存微控制器的固件升级方法和系统及闪存微控制器。The present invention relates to the technical field of firmware upgrading, and in particular, to a method and system for upgrading firmware based on a flash microcontroller, and a flash microcontroller.
背景技术Background technique
随着用户需求的增加,为了增加已出货产品的竞争力和降低产品生产成本等原因,需要对原有产品开放更多的资源给用户,允许用户将原有产品升级。不过,烧写在原有产品中的固件可能满足不了现阶段产品升级的需求。比如:用户在对USB设备进行升级的时候,强制对USB设备进行拔插或断电等意外情况,会造成升级失败,从而会导致整个设备固件受损而无法使用。这就意味着产品的安全性和稳定性功能很差,从而也增加了产品的生产成本。With the increase of user demand, in order to increase the competitiveness of the shipped products and reduce the production cost of the product, it is necessary to open more resources to the original product to the user, allowing the user to upgrade the original product. However, the firmware written in the original product may not meet the needs of the current product upgrade. For example, when a user upgrades a USB device, forcing an unexpected situation such as unplugging or powering off the USB device, the upgrade will fail, which will cause the entire device firmware to become unusable. This means that the product's safety and stability functions are poor, which also increases the production cost of the product.
现有技术急需一种对USB设备进行任意拔插或其他中断升级操作的场景下,仍能在硬件不受损的前提下继续正常升级的技术。The prior art urgently needs a technology that can continue to upgrade normally without damaging the hardware in the scenario where the USB device is arbitrarily plugged or inserted or other interrupted upgrade operations are performed.
发明内容Summary of the Invention
本发明实施例提供一种基于闪存微控制器的固件升级方法和系统及闪存微控制器,用于解决USB设备在固件升级过程中遇到无法正常升级的各种意外情况,导致固件受损和产品不能正常使用的问题。Embodiments of the present invention provide a flash microcontroller-based firmware upgrade method and system, and a flash microcontroller, which are used to solve various unexpected situations that a USB device cannot normally upgrade during the firmware upgrade process, causing firmware damage and The product cannot be used normally.
本发明第一方面提供一种基于闪存微控制器的固件升级方法,所述闪存微控制器包括处理器和闪存,所述闪存中存储有应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序;所述方法包括:所述闪存微控制器上电后运行所述引导升级程序,判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。A first aspect of the present invention provides a firmware upgrade method based on a flash memory microcontroller. The flash memory microcontroller includes a processor and a flash memory. The flash memory stores an application program and a boot upgrade program. The boot upgrade program is used for Starting or upgrading the application program; the method comprises: running the boot upgrade program after the flash microcontroller is powered on to determine whether an upgrade instruction is received; if the upgrade instruction is not received, further determining the Whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or a specific code is not stored in the specific address of the flash memory, the application program is upgraded, and the specific address of the flash memory is to be updated when the upgrade is about to be completed Write specific code.
一种可能的实现方式中,所述方法还包括:若没有收到进入升级指令且所述闪存的特定地址中存储有特定代码,则启动所述应用程序。In a possible implementation manner, the method further includes: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, starting the application program.
一种可能的实现方式中,对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码,包括:通过USB端口与上位机通信,获 取所述应用程序的更新数据;以页为单位,逐页擦除所述闪存中存储的应用程序并写入更新数据。In a possible implementation manner, the application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed, including: communicating with a host computer through a USB port to obtain the application program ’s Update data; in pages, erase application programs stored in the flash memory page by page and write the update data.
一种可能的实现方式中,在逐页擦除所述闪存中存储的应用程序并写入更新数据的步骤中,首先擦除包含所述特定代码的特定页,然后逐页改写其它页,最后写所述特定页,并在写所述特定页时将特定代码写入特定地址。In a possible implementation manner, in a step of erasing an application program stored in the flash memory and writing update data page by page, first erase a specific page containing the specific code, and then rewrite other pages page by page, and finally Write the specific page, and write a specific code to a specific address when the specific page is written.
前文所说的升级即将完成,是指仅余最后一页即特定页尚未写入更新数据,其它页都已写入更新数据。The above-mentioned upgrade is about to be completed, which means that only the last page, that is, the specific page has not been written with the update data, and the other pages have been written with the update data.
一种可能的实现方式中,逐页擦除所述闪存中存储的应用程序并写入更新数据包括:执行擦除命令,将当前页的原始数据擦除;执行写入命令,在当前页写入更新数据;执行校验命令,读取当前页写入的更新数据,计算出校验码,将校验码发送给上位机,以便上位机对所述校验码进行验证,若验证失败,会提示用户重新升级。In a possible implementation manner, erasing an application program stored in the flash memory and writing update data page by page includes: executing an erase command to erase the original data of the current page; executing a write command to write on the current page Enter the update data; execute the verification command, read the update data written in the current page, calculate the verification code, and send the verification code to the upper computer so that the upper computer can verify the verification code. If the verification fails, The user will be prompted to upgrade again.
本发明第二方面提供一种闪存微控制器,包括闪存和处理器,所述闪存中存储有应用程序和引导升级程序,当所述闪存微控制器上电后,所述处理器运行所述引导升级程序,执行以下步骤:判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。A second aspect of the present invention provides a flash memory microcontroller, including a flash memory and a processor. The flash memory stores an application program and a boot upgrade program. When the flash microcontroller is powered on, the processor runs the flash memory. Guide the upgrade program and perform the following steps: determine whether an upgrade instruction is received; if the upgrade instruction is not received, further determine whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or a If the specific address does not store the specific code, the application is upgraded, and when the upgrade is about to be completed, the specific code is written in the specific address of the flash memory.
一种可能的实现方式中,所述处理器还执行以下步骤:若没有收到进入升级指令且所述闪存的特定地址中存储有特定代码,则启动所述应用程序。In a possible implementation manner, the processor further executes the following steps: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, the application program is started.
一种可能的实现方式中,所述引导升级程序具体存储在用于实现在线编程ISP功能的、含处理器复位地址的几页内存区域,该内存区域的大小根据处理器性能可动态调节,或者,所述引导升级程序的存储空间为闪存微控制器上电后的默认执行空间。In a possible implementation manner, the boot upgrade program is specifically stored in a few pages of memory area including a processor reset address for implementing an online programming ISP function, and the size of the memory area can be dynamically adjusted according to processor performance, or The storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on.
本发明第三方面提供一种基于USB的固件升级系统,包括:闪存微控制器和上位机,所述闪存微控制器通过USB端口与上位机通信;所述闪存微控制器,包括处理器和闪存,所述闪存中存储有应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序;所述闪存微控制器用于:上电后运行所述引导升级程序,判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或 者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码;所述上位机,用于向所述闪存微控制器传送所述应用程序的更新数据,根据升级步骤发出控制指令,控制所述引导升级程序对所述应用程序进行升级。A third aspect of the present invention provides a USB-based firmware upgrade system, including: a flash memory microcontroller and a host computer, wherein the flash microcontroller communicates with the host computer through a USB port; the flash microcontroller includes a processor and Flash memory, which stores an application program and a boot upgrade program, the boot upgrade program is used to start or upgrade the application program; the flash microcontroller is used to: run the boot upgrade program after power-on to determine whether Receive the entry upgrade instruction; if no entry upgrade instruction is received, further determine whether a specific code is stored in the specific address of the flash memory; if receive the upgrade instruction or the specific address of the flash memory does not store a specific code, The application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed; the host computer is used to transmit the update data of the application program to the flash microcontroller, and according to the upgrade steps A control instruction is issued to control the boot upgrade program to upgrade the application program.
本发明第四方面提供一种固件升级装置,部署于闪存微控制器中,所述闪存微控制器包括闪存和处理器,所述闪存中存储有应用程序,所述装置包括:判断模块,用于所述闪存微控制器上电后判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;处理模块,用于若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。A fourth aspect of the present invention provides a firmware upgrade device, which is deployed in a flash microcontroller. The flash microcontroller includes a flash memory and a processor, the flash memory stores an application program, and the device includes a judgment module. After the flash microcontroller is powered on, it is judged whether an upgrade instruction is received; if the upgrade instruction is not received, it is further judged whether a specific code is stored in a specific address of the flash memory; a processing module is used to When the upgrade instruction or the specific address of the flash memory does not store specific code, the application program is upgraded, and when the upgrade is about to be completed, the specific code is written in the specific address of the flash memory.
从以上技术方案可以看出,本发明实施例具有以下优点:It can be seen from the above technical solutions that the embodiments of the present invention have the following advantages:
通过升级过程中校验来指示升级的完整性,通过闪存的特定地址存储特定代码来验证应用程序的完整性,即便升级过程中因断电、插拔等意外情况导致升级失败,则重新上电后由于检测不到特定数据从而得知应用程序不完整,也不会启动不完整的应用程序,而是会进入升级过程,继续完成升级,确保闪存微控制器中的应用程序固件的完整性。可见,本发明方案提高了升级稳定性,可有效避免升级中断后无法恢复正常使用的问题,提升了产品的安全性、稳定性和实用性。The integrity of the upgrade is indicated by checking during the upgrade process, and the integrity of the application is verified by storing specific code in the specific address of the flash memory. Even if the upgrade fails due to unexpected conditions such as power failure, plugging, etc. during the upgrade process, power on again Later, due to the inability to detect specific data, the application is incomplete, and the incomplete application will not be started. Instead, it will enter the upgrade process and continue to complete the upgrade to ensure the integrity of the application firmware in the flash microcontroller. It can be seen that the solution of the invention improves the stability of the upgrade, can effectively avoid the problem that the normal use cannot be restored after the upgrade is interrupted, and improves the safety, stability and practicability of the product.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本发明实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to explain the technical solutions of the embodiments of the present invention more clearly, the drawings used in the description of the embodiments are briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. Those skilled in the art can also obtain other drawings according to these drawings without paying creative labor.
图1是本发明的一个实施例提供的一种固件升级方法的流程示意图;FIG. 1 is a schematic flowchart of a firmware upgrade method according to an embodiment of the present invention; FIG.
图2是本发明的一个应用场景实施例中固件升级的实现流程图;FIG. 2 is a flowchart of implementing firmware upgrade in an application scenario embodiment of the present invention; FIG.
图3是本发明的一个实施例提供的一种闪存微控制器的结构示意图;3 is a schematic structural diagram of a flash memory microcontroller according to an embodiment of the present invention;
图4是本发明的一个实施例提供的一种固件升级装置的结构示意图。FIG. 4 is a schematic structural diagram of a firmware upgrade device according to an embodiment of the present invention.
具体实施方式detailed description
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分的实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only The embodiments are part of the present invention, but not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by a person of ordinary skill in the art without creative efforts should fall within the protection scope of the present invention.
本发明的说明书和权利要求书及上述附图中的术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "including" and "having" and any variations thereof in the description and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device containing a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes Other steps or units inherent to these processes, methods, products or equipment.
下面通过具体实施例,分别进行详细的说明。Detailed descriptions are respectively provided below through specific embodiments.
请参考图1,本发明的一个实施例,提供一种基于闪存微控制器的固件升级方法。该方法可用于升级闪存(Flash)微控制器等USB设备中的固件。所述闪存微控制器包括处理器和闪存,所述闪存中存储有固件如应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序。所述方法可包括:Please refer to FIG. 1, an embodiment of the present invention provides a firmware upgrade method based on a flash microcontroller. This method can be used to upgrade firmware in a USB device such as a flash microcontroller. The flash microcontroller includes a processor and a flash memory. The flash memory stores firmware such as an application program and a boot upgrade program, and the boot upgrade program is used to start or upgrade the application program. The method may include:
S1、闪存微控制器上电后运行引导升级程序,判断是否收到进入升级指令;若是,进入步骤S3;若否,进入步骤S2;S1. After the flash microcontroller is powered on, run the boot upgrade program to determine whether an upgrade instruction is received; if yes, go to step S3; if not, go to step S2;
S2、进一步判断闪存的特定地址是否存储有特定代码;若否,进入步骤S3;若是,进入步骤S4;S2. It is further determined whether a specific code is stored in a specific address of the flash memory; if not, proceed to step S3; if yes, proceed to step S4;
S3、对应用程序进行升级,并于升级即将完成时在闪存的特定地址写入特定代码;S3. Upgrade the application program and write specific code at a specific address in the flash memory when the upgrade is about to be completed;
S4、启动应用程序。S4. Start the application.
可选的,对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码,可包括:通过USB端口与上位机通信,获取所述应用程序的更新数据;以页为单位,逐页擦除所述闪存中存储的应用程序并写入更新数据。Optionally, upgrading the application and writing specific code at a specific address of the flash memory when the upgrade is about to be completed may include: communicating with a host computer through a USB port to obtain update data of the application; The application program stored in the flash memory is erased page by page and written with updated data.
其中,逐页擦除所述闪存中存储的应用程序并写入更新数据的步骤,具体可包括:执行擦除命令,将当前页的原始数据擦除;执行写入命令,在当前页写入更新数据;执行校验命令,读取当前页写入的更新数据,计算出校验码,将校验码发送给上位机,以便上位机对所述校验码进行验证。上位机验证通过 后,传送下一页的更新数据给闪存微控制器,以闪存微控制器对下一页执行擦除和写入的操作,以此类推,直到所有页的数据都被改写,完成全部升级。The step of erasing the application program stored in the flash memory and writing updated data page by page may specifically include: executing an erase command to erase the original data of the current page; executing a write command to write in the current page Update data; execute the check command, read the updated data written in the current page, calculate the check code, and send the check code to the host computer so that the host computer can verify the check code. After the upper computer passes the verification, it transmits the updated data of the next page to the flash microcontroller, and the flash microcontroller performs the erase and write operations on the next page, and so on, until the data of all pages is rewritten. Complete all upgrades.
特别的,在逐页擦除所述闪存中存储的应用程序并写入更新数据的步骤中,首先擦除包含所述特定代码的特定页,然后逐页改写其它页,最后写所述特定页,并在写所述特定页时将特定代码写入特定地址。In particular, in a step of erasing an application program stored in the flash memory and writing update data page by page, first erase a specific page containing the specific code, then rewrite other pages page by page, and finally write the specific page And write a specific code to a specific address when writing the specific page.
特定页的特定代码用于指示固件升级完整性,一旦被擦除或者说删除,意味着应用程序不再完整需要升级。这样,一旦升级过程因意外中断,则重新上电后可通过检测是否包含特定数据来判断当前应用程序不完整,需要升级,而不会跳转到应用程序的代码区,启动不完整的应用程序,引发各种错误。唯有整个应用程序完成升级,特定地址才会被写入特定代码,后续上电后检测到该特定代码,就意味着当前的应用程序是完整的,是可以启动的。从而,提高了升级效率,可有效避免升级中断后无法恢复正常使用的问题,提升了产品的安全性、稳定性和实用性。The specific code of a specific page is used to indicate the integrity of the firmware upgrade. Once it is erased or deleted, it means that the application is no longer complete and needs to be upgraded. In this way, once the upgrade process is interrupted unexpectedly, you can determine whether the current application is incomplete by detecting whether it contains specific data after the power is turned on again, and you need to upgrade without jumping to the code area of the application and starting the incomplete application. , Throwing various errors. Only when the entire application is upgraded, a specific address will be written into a specific code. When the specific code is detected after power-on, it means that the current application is complete and can be started. As a result, the upgrade efficiency is improved, the problem that normal use cannot be resumed after the upgrade is interrupted can be effectively avoided, and the safety, stability and practicability of the product are improved.
下面,结合具体的应用场景实施例,对本发明方法做进一步详细的描述:The method of the present invention is described in further detail below in combination with specific application scenario embodiments:
本实施例在Flash微控制器(MicrocontrollerUnit,MCU)中烧录两部分固件或者说程序,一部分为引导升级程序,一部分为应用程序(APP),在应用程序出现问题需要升级的时候,切换到引导升级程序,由引导升级程序配合上位机的软件如APP对应用程序进行升级或者说更新。上位机例如是个人计算机(PC)或者服务器等。引导升级程序例如是启动装载(BootLoader)程序。In this embodiment, two parts of firmware or program are programmed in a Flash microcontroller unit (Microcontroller Unit, MCU), one is a boot upgrade program, and the other is an application program (APP). When an application problem occurs and needs to be upgraded, switch to the boot. The upgrade program is used to guide the upgrade program to cooperate with the software of the host computer such as APP to upgrade or update the application program. The host computer is, for example, a personal computer (PC) or a server. The boot upgrade program is, for example, a boot loader program.
如图2所示,总的实现流程包括:把需要升级的应用程序的用户代码放到上位机软件中,MCU上电后首先运行升级引导程序中的引导代码,进行模式选择,即判断是否进入升级,如果不进入升级,则执行正常的应用程序,否则执行升级引导程序中的升级代码。在升级代码中,MCU通过USB端口实现与上位机软件的通信,从而把上位机软件中的用户代码传送到MCU,MCU写入Flash,并把校验码发送给上位机软件如上位机APP判断校验码的对错,如此逐页执行。As shown in Figure 2, the overall implementation process includes: placing the user code of the application to be upgraded into the host computer software. After the MCU is powered on, the boot code in the upgrade boot program is first run to select the mode, that is, to determine whether to enter Upgrade, if not enter the upgrade, execute the normal application program, otherwise execute the upgrade code in the upgrade boot program. In the upgrade code, the MCU communicates with the host computer software through the USB port, so that the user code in the host computer software is transmitted to the MCU, the MCU writes to Flash, and sends the check code to the host computer software as judged by the host computer APP The check code is correct, so it is executed page by page.
具体实现过程分如下几部分:The specific implementation process is divided into the following parts:
1、用户代码和引导代码的内存配置。1. Memory configuration for user code and boot code.
对于某些MCU而言,有专门为实现ISP(In-System Programming,线上编程)功能的内存区域,则把引导代码放到该区域即可。For some MCUs, there is a memory area specifically for implementing the ISP (In-System Programming) function, and the boot code can be placed in this area.
对于没有ISP功能的MCU,则需要为引导代码配置Flash空间,如引导代码需 4K空间,则引导代码放入Flash的前4K空间,用户代码放到从第4K开始的空间。或者说,所述引导升级程序的存储空间为闪存微控制器上电后的默认执行空间。For MCU without ISP function, you need to configure the flash space for the boot code. If the boot code requires 4K space, the boot code is placed in the first 4K space of the Flash, and the user code is placed in the space starting from the 4K. In other words, the storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on.
2、引导代码的跳转选择。2. Jump selection of boot code.
对于引导代码而言,其功能只有一个,就是判断是否进入升级,如果不进入升级,则程序要跳转到用户代码区,否则,执行升级代码,进入升级过程。As far as the boot code is concerned, there is only one function, which is to determine whether to enter the upgrade. If it does not enter the upgrade, the program must jump to the user code area, otherwise, execute the upgrade code and enter the upgrade process.
其判断条件通常由实际情况而定,一般为是否收到进入升级指令,例如检测到某个按键指令表示要进入升级。The judgment condition is usually determined by the actual situation, and it is generally whether or not an upgrade instruction is received. For example, if a keystroke instruction is detected to indicate that the upgrade is to be entered.
如上述,对于有专门ISP内存区域的MCU,如果要进入用户代码区域,需要设置从用户代码启动,然后发出MCU复位指令即可。As mentioned above, for an MCU with a dedicated ISP memory area, if you want to enter the user code area, you need to set to start from the user code, and then issue an MCU reset instruction.
对于没有ISP功能的MCU,则需要设置手动的跳转指令,如函数指针,其地址设定为用户代码区。For MCUs without ISP function, you need to set manual jump instructions, such as function pointer, whose address is set to the user code area.
3、USB升级——MCU部分。3, USB upgrade-MCU part.
上位机和MCU通过USB端口实现数据交换,为了保证数据的完整性和保密性,需要对数据进行加密和校验,用户代码的升级是以页为单位进行,即擦除一页,写入一页,校验一页,确认无误后,再进行下一页。The host computer and MCU implement data exchange through the USB port. In order to ensure the integrity and confidentiality of the data, the data needs to be encrypted and verified. The user code is upgraded in units of pages, that is, to erase a page and write a Page, check one page, and after confirming that it is correct, proceed to the next page.
该过程可通过usb的“set report”和“getreport”命令实现,为了保证该过程有序进行,可以定义如下协议:This process can be implemented with the "set port" and "getreport" commands of USB. In order to ensure the orderly progress of the process, the following protocol can be defined:
(1)get report[1]=0xE1,MCU返回版本号等信息。(1) get report [1] = 0xE1, MCU returns information such as version number.
(2)get report[1]=0xE2,保留命令。(2) get report [1] = 0xE2, reserve the command.
(3)get report[1]=0xE3,MCU执行擦除命令。(3) get report [1] = 0xE3, the MCU executes the erase command.
(4)get report[1]=0xE4,MCU解码数据,并写入Flash。(4) get report [1] = 0xE4, the MCU decodes the data and writes it to Flash.
(5)get report[1]=0xE5,MCU读取指定页的内容并计算出校验码,返回给上位机APP。(5) get report [1] = 0xE5, the MCU reads the content of the specified page and calculates the check code, and returns it to the upper computer APP.
(6)get report[1]=0xE6,升级完成。(6) get report [1] = 0xE6, the upgrade is completed.
其中,getreport[1]指get report命令收到数据的第1个字节。Among them, getreport [1] refers to the first byte of data received by the get command.
4、USB升级——APP部分。4, USB upgrade-APP part.
APP部分通过C++编写,其过程与上述过程类似。区别在于APP是作为命令的发起者与MCU沟通,控制MCU执行升级过程。The APP part is written in C ++, and the process is similar to the above process. The difference is that the APP communicates with the MCU as the initiator of the command and controls the MCU to perform the upgrade process.
5、USB升级稳定性。5. USB upgrade stability.
USB升级过程中会出现这样一个问题,如果还未升级完成,用户不小心断 开USB连接或USB连接出错,导致写进Flash的用户代码是残缺的,该情况会导致意想不到的后果。Such a problem occurs during the USB upgrade process. If the user has not accidentally disconnected the USB connection or the USB connection error has occurred before the upgrade is completed, the user code written into Flash is incomplete, which may lead to unexpected results.
该种情况解决如下:This situation is resolved as follows:
预先在用户代码Flash区域的固定地址/特定地址写入一个例如32位的特定数据,该数据用以指示升级完整,或者说应用程序的完整性。例如,可以在上一次升级时写入。A specific data, such as 32 bits, is written in advance at a fixed address / specific address in the flash area of the user code, and the data is used to indicate the completeness of the upgrade, or the integrity of the application. For example, it can be written during the last upgrade.
在APP端需做相应处理,进入升级后,APP应首先擦除该页,使得该特定数据被擦除;该数据被擦掉,则表示用户代码是不完整的。The APP needs to do the corresponding processing. After entering the upgrade, the APP should first erase the page so that the specific data is erased; if the data is erased, it means that the user code is incomplete.
接下来,对于特定页以外的其它页,APP逐页擦除,逐页写入;Next, for pages other than the specific page, the APP erases page by page and writes page by page;
等其它所有页都写完后,最后写入该页的代码,包括将特定代码写入。特定代码的写入,表示升级完成,应用程序已经是完整的。After all other pages have been written, the code for that page is finally written, including writing specific code. The writing of specific code indicates that the upgrade is complete and the application is complete.
在MCU的引导升级程序的引导代码中需做处理,判断如果该特定数据不存在则只能进入升级,不能跳到用户代码区。Processing is needed in the boot code of the MCU's boot upgrade program. It is judged that if the specific data does not exist, it can only enter the upgrade and cannot jump to the user code area.
这样,即便升级过程中因断电等原因导致升级失败,则重新上电后由于检测不到32位特定数据,则只能进入升级,即可继续完成升级;而不能启动不完整的应用程序,避免导致意想不到的后果。In this way, even if the upgrade fails due to a power outage during the upgrade process, since the 32-bit specific data cannot be detected after the power is turned on again, you can only enter the upgrade and continue to complete the upgrade; you cannot start incomplete applications, Avoid causing unintended consequences.
因为,如果升级失败,则应用程序是错误或者是不完整的,这将会导致应用程序发生不可预估的错误。如果没有上述限制,即,数据不完整则只能升级不能进入应用程序;用户会误以为是应用程序的问题,因为数据不完整可能会有大部分功能,而不会再次手动升级,则后续使用时就会发生错误。Because if the upgrade fails, the application is wrong or incomplete, which will cause an unpredictable error in the application. If there is no such limitation, that is, the data is incomplete, it can only be upgraded and cannot enter the application; users will mistake it as an application problem, because the incomplete data may have most of the functions, and it will not be manually upgraded again. An error occurs.
以上,对本发明提供的方法进行了说明。The method provided by the present invention has been described above.
为便于实施本发明,下面还提供相应的装置/系统。To facilitate the implementation of the present invention, corresponding devices / systems are also provided below.
请参考图3,本发明的一个实施例,提供一种闪存微控制器30,包括闪存31和处理器32,所述闪存31中存储有应用程序33和引导升级程序34,当所述闪存微控制器30上电后,所述处理器32运行所述引导升级程序,执行以下步骤:Referring to FIG. 3, an embodiment of the present invention provides a flash memory microcontroller 30 including a flash memory 31 and a processor 32. The flash memory 31 stores an application program 33 and a boot upgrade program 34. After the controller 30 is powered on, the processor 32 runs the boot upgrade program and performs the following steps:
判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。Determine whether an upgrade instruction is received; if no upgrade instruction is received, further determine whether a specific code is stored in a specific address of the flash memory; if a specific code is stored in a specific address of the flash memory, The application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed.
可选的,所述处理器32还执行以下步骤:若没有收到进入升级指令且所述 闪存的特定地址中存储有特定代码,则启动所述应用程序。Optionally, the processor 32 further executes the following step: if the upgrade instruction is not received and a specific code is stored in a specific address of the flash memory, the application program is started.
可选的,所述引导升级程序具体存储在用于实现ISP功能的、的含处理器复位地址的几页内存区域,该内存区域的大小根据处理器性能可动态调节。Optionally, the boot upgrade program is specifically stored in a page memory area containing a processor reset address for implementing the ISP function, and the size of the memory area can be dynamically adjusted according to the performance of the processor.
可选的,所述引导升级程序的存储空间为闪存微控制器上电后的默认执行空间,即,所述引导升级程序的存储空间位于所述应用程序的存储空间之前。Optionally, the storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on, that is, the storage space of the boot upgrade program is located before the storage space of the application program.
请参考图4,本发明的一个实施例,还提供一种固件升级装置40,部署于闪存微控制器中,所述闪存微控制器包括闪存和处理器,所述闪存中存储有应用程序,所述装置40包括:Please refer to FIG. 4. According to an embodiment of the present invention, a firmware upgrade device 40 is further provided, which is deployed in a flash memory microcontroller. The flash microcontroller includes a flash memory and a processor, and the flash memory stores an application program. The device 40 includes:
判断模块41,用于所述闪存微控制器上电后判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;A judging module 41 is configured to determine whether an upgrade instruction is received after the flash microcontroller is powered on; if the upgrade instruction is not received, further determine whether a specific code is stored in a specific address of the flash memory;
处理模块42,用于若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。The processing module 42 is configured to upgrade the application program if an upgrade instruction is received or the specific address of the flash memory does not store the specific code, and write the specific code at the specific address of the flash memory when the upgrade is about to be completed. .
本发明的一个实施例,还提供一种基于USB的固件升级系统,包括:闪存微控制器和上位机,所述闪存微控制器通过USB端口与上位机通信;An embodiment of the present invention further provides a USB-based firmware upgrade system, including: a flash memory microcontroller and a host computer, wherein the flash microcontroller communicates with the host computer through a USB port;
所述闪存微控制器,包括处理器和闪存,所述闪存中存储有应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序;所述闪存微控制器用于:上电后运行所述引导升级程序,判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码;The flash memory microcontroller includes a processor and a flash memory. The flash memory stores an application program and a boot upgrade program. The boot upgrade program is used to start or upgrade the application program. The flash microcontroller is used to: After power-on, the boot upgrade program is run to determine whether an upgrade instruction is received. If the upgrade instruction is not received, it is further determined whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or the flash memory is received The specific address does not store the specific code, then upgrade the application, and write the specific code at the specific address of the flash memory when the upgrade is about to be completed;
所述上位机,用于向所述闪存微控制器传送所述应用程序的更新数据,根据升级步骤发出控制指令,控制所述引导升级程序对所述应用程序进行升级。The host computer is configured to transmit the update data of the application program to the flash microcontroller, and issue a control instruction according to the upgrade step to control the boot upgrade program to upgrade the application program.
本发明实施例提供了一种基于闪存微控制器的固件升级方法、一种固件升级装置、一种闪存微控制器和一种基于USB的固件升级系统,通过采用上述技术方案,取得了以下技术效果:通过在闪存的特定地址存储特定代码来指示升级完整性,即便升级过程中因断电、插拔等意外情况导致升级失败,则重新上电后由于检测不到特定数据,也不会启动不完整的应用程序,而是会进入升级过程,继续完成升级,确保闪存微控制器中的应用程序固件的完整性。可见, 本发明方案提高了升级效率,可有效避免升级中断后无法恢复正常使用的问题,提升了产品的安全性、稳定性和实用性。The embodiments of the present invention provide a firmware upgrade method based on a flash microcontroller, a firmware upgrade device, a flash microcontroller, and a USB-based firmware upgrade system. By adopting the above technical solution, the following technologies are obtained: Effect: The specificity of the code is stored in the specific address of the flash memory to indicate the integrity of the upgrade. Even if the upgrade fails due to unexpected conditions such as power failure, plugging, etc., the specific data will not be detected after the power is turned on again, and it will not start Incomplete applications will instead enter the upgrade process and continue to complete the upgrade to ensure the integrity of the application firmware in the flash microcontroller. It can be seen that the solution of the present invention improves the upgrade efficiency, can effectively avoid the problem that normal use cannot be restored after the upgrade is interrupted, and improves the safety, stability and practicability of the product.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详细描述的部分,可以参见其它实施例的相关描述。In the above embodiments, the description of each embodiment has its own emphasis. For a part that is not described in detail in one embodiment, reference may be made to related descriptions in other embodiments.
上述实施例仅用以说明本发明的技术方案,而非对其限制;本领域的普通技术人员应当理解:其依然可以对上述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。The above embodiments are only used to illustrate the technical solutions of the present invention, rather than limiting them. Those of ordinary skill in the art should understand that they can still modify the technical solutions described in the above embodiments, or modify some of the technical features. Equivalent replacements are made; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (10)

  1. 一种基于闪存微控制器的固件升级方法,其特征在于,所述闪存微控制器包括处理器和闪存,所述闪存中存储有应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序;所述方法包括:A firmware upgrade method based on a flash microcontroller, characterized in that the flash microcontroller includes a processor and a flash memory, the flash memory stores an application program and a boot upgrade program, and the boot upgrade program is used to start or Upgrading the application; the method includes:
    所述闪存微控制器上电后运行所述引导升级程序,判断是否收到进入升级指令;After the flash microcontroller is powered on, run the boot upgrade program to determine whether an upgrade instruction is received;
    若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;If no entry upgrade instruction is received, further determining whether a specific code is stored in a specific address of the flash memory;
    若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。If an upgrade instruction is received or a specific address of the flash memory does not store a specific code, the application program is upgraded, and the specific code is written in a specific address of the flash memory when the upgrade is about to be completed.
  2. 根据权利要求1所述的方法,其特征在于,还包括:The method according to claim 1, further comprising:
    若没有收到进入升级指令且所述闪存的特定地址中存储有特定代码,则启动所述应用程序。If no upgrade instruction is received and a specific code is stored in a specific address of the flash memory, the application program is started.
  3. 根据权利要求2所述的方法,其特征在于,对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码,包括:The method according to claim 2, wherein upgrading the application program, and writing specific code at a specific address of the flash memory when the upgrade is about to be completed, comprises:
    通过USB端口与上位机通信,获取所述应用程序的更新数据;Communicate with a host computer through a USB port to obtain update data of the application program;
    以页为单位,逐页擦除所述闪存中存储的应用程序并写入更新数据。The application program stored in the flash memory is erased page by page and written with updated data.
  4. 根据权利要求3所述的方法,其特征在于,The method according to claim 3, wherein:
    在逐页擦除所述闪存中存储的应用程序并写入更新数据的步骤中,首先擦除包含所述特定代码的特定页,然后逐页改写其它页,最后写所述特定页,并在写所述特定页时将特定代码写入特定地址。In the step of erasing the application program stored in the flash memory page by page and writing update data, first erase a specific page containing the specific code, then rewrite other pages page by page, and finally write the specific page, and then A specific code is written to a specific address when the specific page is written.
  5. 根据权利要求3所述的方法,其特征在于,逐页擦除所述闪存中存储的应用程序并写入更新数据包括:The method according to claim 3, wherein erasing the application program stored in the flash memory page by page and writing the update data comprises:
    执行擦除命令,将当前页的原始数据擦除;Execute the erase command to erase the original data of the current page;
    执行写入命令,在当前页写入更新数据;Execute a write command to write updated data on the current page;
    执行校验命令,读取当前页写入的更新数据,计算出校验码,将校验码发送给上位机,以便上位机对所述校验码进行验证。Execute the check command to read the updated data written in the current page, calculate the check code, and send the check code to the host computer so that the host computer can verify the check code.
  6. 一种闪存微控制器,其特征在于,包括闪存和处理器,所述闪存中存储有应用程序和引导升级程序,当所述闪存微控制器上电后,所述处理器运行所述引导升级程序,执行以下步骤:A flash microcontroller includes a flash memory and a processor. The flash memory stores an application program and a boot upgrade program. When the flash microcontroller is powered on, the processor runs the boot upgrade. Procedure to perform the following steps:
    判断是否收到进入升级指令;Determine whether to receive the upgrade instruction;
    若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;If no entry upgrade instruction is received, further determining whether a specific code is stored in a specific address of the flash memory;
    若收到进入升级指令,或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码。If an upgrade instruction is received, or a specific address of the flash memory does not store a specific code, the application program is upgraded, and a specific code is written in a specific address of the flash memory when the upgrade is about to be completed.
  7. 根据权利要求6所述的闪存微控制器,其特征在于,所述处理器还执行以下步骤:The flash memory microcontroller according to claim 6, wherein the processor further performs the following steps:
    若没有收到进入升级指令且所述闪存的特定地址中存储有特定代码,则启动所述应用程序。If no upgrade instruction is received and a specific code is stored in a specific address of the flash memory, the application program is started.
  8. 根据权利要求6所述的闪存微控制器,其特征在于,The flash memory microcontroller according to claim 6, wherein:
    所述引导升级程序具体存储在用于实现在线编程的含处理器复位地址的几页内存区域,该内存区域的大小根据处理器性能可动态调节。The boot upgrade program is specifically stored in a few pages of memory area including a processor reset address for implementing online programming, and the size of the memory area can be dynamically adjusted according to the performance of the processor.
  9. 根据权利要求6所述的闪存微控制器,其特征在于,The flash memory microcontroller according to claim 6, wherein:
    所述引导升级程序的存储空间为闪存微控制器上电后的默认执行空间。The storage space of the boot upgrade program is a default execution space after the flash microcontroller is powered on.
  10. 一种基于USB的固件升级系统,其特征在于,包括:A USB-based firmware upgrade system, comprising:
    闪存微控制器和上位机,所述闪存微控制器通过USB端口与上位机通信;A flash microcontroller and a host computer, the flash microcontroller communicates with the host computer through a USB port;
    所述闪存微控制器,包括处理器和闪存,所述闪存中存储有应用程序和引导升级程序,所述引导升级程序用于启动或升级所述应用程序;所述闪存微控制器用于:上电后运行所述引导升级程序,判断是否收到进入升级指令;若没有收到进入升级指令,则进一步判断所述闪存的特定地址是否存储有特定代码;若收到进入升级指令或者所述闪存的特定地址没有存储特定代码,则对所述应用程序进行升级,并于升级即将完成时在所述闪存的特定地址写入特定代码;The flash memory microcontroller includes a processor and a flash memory. The flash memory stores an application program and a boot upgrade program. The boot upgrade program is used to start or upgrade the application program. The flash microcontroller is used to: After power-on, the boot upgrade program is run to determine whether an upgrade instruction is received. If the upgrade instruction is not received, it is further determined whether a specific code is stored in a specific address of the flash memory; if an upgrade instruction is received or the flash memory is received The specific address does not store the specific code, then upgrade the application, and write the specific code at the specific address of the flash memory when the upgrade is about to be completed;
    所述上位机,用于向所述闪存微控制器传送所述应用程序的更新数据,根据升级步骤发出控制指令,控制所述引导升级程序对所述应用程序进行升级。The host computer is configured to transmit the update data of the application program to the flash microcontroller, and issue a control instruction according to the upgrade step to control the boot upgrade program to upgrade the application program.
PCT/CN2019/086802 2018-09-26 2019-05-14 Firmware upgrading method and system based on flash micro-controller, and flash micro-controller WO2020062887A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201811123798.3A CN109284117A (en) 2018-09-26 2018-09-26 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller
CN201811123798.3 2018-09-26

Publications (1)

Publication Number Publication Date
WO2020062887A1 true WO2020062887A1 (en) 2020-04-02

Family

ID=65182259

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/086802 WO2020062887A1 (en) 2018-09-26 2019-05-14 Firmware upgrading method and system based on flash micro-controller, and flash micro-controller

Country Status (2)

Country Link
CN (1) CN109284117A (en)
WO (1) WO2020062887A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111338681A (en) * 2020-04-13 2020-06-26 猫岐智能科技(上海)有限公司 Firmware upgrading method and system for equipment

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109284117A (en) * 2018-09-26 2019-01-29 深圳市慧嘉智科技有限公司 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller
CN111857785B (en) * 2019-04-29 2023-06-09 深圳市优必选科技有限公司 MCU starting method and device and terminal equipment
CN110399155A (en) * 2019-07-26 2019-11-01 山东汘沄智能科技有限公司 A kind of batch device firmware upgrade method that backstage is online
CN111338667B (en) * 2020-02-10 2023-08-01 浙江大华技术股份有限公司 Application program APP upgrading method and device
CN113918082B (en) * 2020-07-08 2024-03-08 慧荣科技股份有限公司 Computer readable storage medium, method and apparatus for configuring reliable command
CN112148338B (en) 2020-09-16 2022-06-03 北京算能科技有限公司 Power management circuit, chip, upgrading method of power management circuit and chip and server
CN113848853A (en) * 2021-09-27 2021-12-28 一飞智控(天津)科技有限公司 Flight controller upgrading flow processing method, system, terminal, medium and application
CN114721685A (en) * 2022-04-13 2022-07-08 北京英创汇智科技有限公司 Program upgrading method for redundant controller
CN114860279B (en) * 2022-04-22 2023-03-14 珠海海奇半导体有限公司 Rapid empty-chip upgrading method
CN115437674B (en) * 2022-09-28 2024-04-30 杭州华塑科技股份有限公司 Firmware upgrading method, device, medium and electronic equipment
CN117707567A (en) * 2023-11-06 2024-03-15 上海联适导航技术股份有限公司 Method for identifying integrity of mcu firmware

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105677388A (en) * 2015-12-31 2016-06-15 清华大学苏州汽车研究院(吴江) Firmware updating method for motor controller of electric vehicle
CN105786510A (en) * 2016-02-29 2016-07-20 深圳市美贝壳科技有限公司 Upgrading and partitioning system and security upgrading method for single-chip microcomputer
CN106909352A (en) * 2015-12-22 2017-06-30 北京谊安医疗系统股份有限公司 A kind of firmware upgrade method of embedded device
CN107861745A (en) * 2017-11-30 2018-03-30 厦门科华恒盛股份有限公司 A kind of application program online upgrading method, apparatus, equipment and storage medium
CN109284117A (en) * 2018-09-26 2019-01-29 深圳市慧嘉智科技有限公司 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
SE525945C2 (en) * 2002-01-09 2005-05-31 Atlas Copco Rock Drills Ab Program code exchange method for computerized drilling rig, stores original code for possible use if new code is found to contain errors
CN103294511A (en) * 2013-05-31 2013-09-11 哈尔滨工业大学 Bootloader software updating method based on CAN (controller area network) bus
CN103336701B (en) * 2013-06-20 2016-08-24 深圳麦克维尔空调有限公司 Intelligent guiding upgrade method
CN103761125A (en) * 2014-01-06 2014-04-30 凯迈(洛阳)电子有限公司 Application system and method for upgrading programs
CN103744712A (en) * 2014-01-28 2014-04-23 北京经纬恒润科技有限公司 Method and device for updating application program
CN103942080B (en) * 2014-05-16 2016-08-24 国网山东省电力公司青岛供电公司 Electronic device information transmission method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106909352A (en) * 2015-12-22 2017-06-30 北京谊安医疗系统股份有限公司 A kind of firmware upgrade method of embedded device
CN105677388A (en) * 2015-12-31 2016-06-15 清华大学苏州汽车研究院(吴江) Firmware updating method for motor controller of electric vehicle
CN105786510A (en) * 2016-02-29 2016-07-20 深圳市美贝壳科技有限公司 Upgrading and partitioning system and security upgrading method for single-chip microcomputer
CN107861745A (en) * 2017-11-30 2018-03-30 厦门科华恒盛股份有限公司 A kind of application program online upgrading method, apparatus, equipment and storage medium
CN109284117A (en) * 2018-09-26 2019-01-29 深圳市慧嘉智科技有限公司 Firmware upgrade method and system and flash memory microcontroller based on flash memory microcontroller

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111338681A (en) * 2020-04-13 2020-06-26 猫岐智能科技(上海)有限公司 Firmware upgrading method and system for equipment

Also Published As

Publication number Publication date
CN109284117A (en) 2019-01-29

Similar Documents

Publication Publication Date Title
WO2020062887A1 (en) Firmware upgrading method and system based on flash micro-controller, and flash micro-controller
JP5575338B2 (en) Information processing apparatus, information processing method, and computer program
TWI515660B (en) Firmware variable update method
US8601255B2 (en) Approaches for updating bios
JP5889933B2 (en) Method for preventing malfunction of computer, computer program, and computer
JP6054908B2 (en) Method for repairing variable sets, computer program and computer
CN104407878B (en) C6000 digital signal processor online upgrading methods
CN101807152B (en) Basic output and input system for self verification of selection read only memory and verification method thereof
CN114265603A (en) System upgrade method, device and electronic device based on asymmetric partition
US7428635B2 (en) Method of writing non-volatile memory that avoids corrupting the vital initialization code
CN110457058A (en) Control node online upgrade method, device, host computer, system and electronic equipment
US20080098388A1 (en) Safe Flashing
CN1323361C (en) Processor system and method using multi memory of start-up procedure
JP2013156799A (en) Method for updating system firmware and computer
CN110825421A (en) Firmware upgrading method and system and readable storage medium
CN113918199B (en) Updating method of bottom firmware program, storage medium and electronic equipment
TWI556172B (en) Computer and booting method thereof
CN114625389A (en) Embedded equipment upgrading method, embedded equipment and storage device
TW201801093A (en) Data storage device and operating method
TWI467484B (en) Bios for self-verifying option rom and the verifying method thereof
JP2007207089A (en) External storage controller and program
TWI446351B (en) Data writing method and computer system
TWI839278B (en) Method for performing firmware update in electronic device and micro-control unit equipped with firmware update function
CN102262598B (en) Memory system capable of improving write protection and related method
CN102270160B (en) Data writing method and computer system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19865084

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19865084

Country of ref document: EP

Kind code of ref document: A1