CN117931251A - Firmware online upgrading method and device, electronic equipment, storage medium and product - Google Patents
Firmware online upgrading method and device, electronic equipment, storage medium and product Download PDFInfo
- Publication number
- CN117931251A CN117931251A CN202410131409.0A CN202410131409A CN117931251A CN 117931251 A CN117931251 A CN 117931251A CN 202410131409 A CN202410131409 A CN 202410131409A CN 117931251 A CN117931251 A CN 117931251A
- Authority
- CN
- China
- Prior art keywords
- partition
- address information
- system partition
- value
- storage area
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 47
- 238000005192 partition Methods 0.000 claims abstract description 476
- 230000008569 process Effects 0.000 claims abstract description 8
- 230000006870 function Effects 0.000 claims description 75
- 238000004590 computer program Methods 0.000 claims description 18
- 238000004364 calculation method Methods 0.000 claims description 16
- 230000004044 response Effects 0.000 claims description 8
- 239000011449 brick Substances 0.000 abstract description 2
- 238000013500 data storage Methods 0.000 description 14
- 238000013507 mapping Methods 0.000 description 10
- 238000010586 diagram Methods 0.000 description 7
- 238000007726 management method Methods 0.000 description 6
- 230000006854 communication Effects 0.000 description 5
- 238000012545 processing Methods 0.000 description 5
- 230000007246 mechanism Effects 0.000 description 4
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 3
- 238000004422 calculation algorithm Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 230000002093 peripheral effect Effects 0.000 description 2
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 1
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 1
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 1
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000013524 data verification Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000009877 rendering Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/65—Updates
- G06F8/654—Updates using techniques specially adapted for alterable solid state memories, e.g. for EEPROM or flash memories
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0238—Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
- G06F12/0246—Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Computer Security & Cryptography (AREA)
- Stored Programmes (AREA)
Abstract
Description
技术领域Technical Field
本申请涉及物联网技术领域,特别涉及一种固件在线升级方法、装置、电子设备、存储介质及产品。The present application relates to the technical field of Internet of Things, and in particular to a firmware online upgrade method, device, electronic device, storage medium and product.
背景技术Background technique
在物联网技术领域,系统由成千上万的ECU(Electronic Control Unit,电子控制单元)设备组网构成。对于ECU设备来说,在其生命周期中,通过固件在线(Firmware On-The-Air,简称为FOTA)升级机制对固件镜像文件进行升级,可以解决系统漏洞的安全问题或支持新的系统特性。ECU设备的固件镜像文件运行在FLASH上,升级的时间地点都是不确定的,甚至网络状况都有可能很差,这就对ECU设备的固件在线方法提出了很高的要求。In the field of Internet of Things technology, the system is composed of thousands of ECU (Electronic Control Unit) devices. For ECU devices, during their life cycle, the firmware image file can be upgraded through the Firmware On-The-Air (FOTA) upgrade mechanism to solve the security issues of system vulnerabilities or support new system features. The firmware image file of the ECU device runs on FLASH, and the time and location of the upgrade are uncertain, and even the network conditions may be very poor, which puts high demands on the firmware online method of the ECU device.
相关技术中,预先分配一块与系统分区A一样大小的系统分区B,将待升级的固件镜像文件写入系统分区B,将分区选择标识设置为系统分区B的标识,然后对电子设备进行重启。电子设备重启后,引导程序读取到分区选择标识为系统分区B的标识,根据系统分区B的标识,获取系统分区B的地址,进而根据系统分区B的地址,执行系统分区B内的固件镜像文件,以完成固件在线升级。In the related art, a system partition B of the same size as the system partition A is pre-allocated, the firmware image file to be upgraded is written into the system partition B, the partition selection identifier is set to the identifier of the system partition B, and then the electronic device is restarted. After the electronic device is restarted, the boot program reads the identifier of the partition selection identifier as the system partition B, obtains the address of the system partition B according to the identifier of the system partition B, and then executes the firmware image file in the system partition B according to the address of the system partition B to complete the firmware online upgrade.
然而,每次对固件镜像文件进行升级之前,需要存储该次的分区选择标识及分区选择标识对应的系统分区的地址,管理成本较高,且容易出错,一旦出错,设备将变砖。However, before each firmware image file is upgraded, the partition selection identifier and the address of the system partition corresponding to the partition selection identifier need to be stored, which has high management costs and is prone to errors. Once an error occurs, the device will become a brick.
发明内容Summary of the invention
本申请实施例提供了一种固件在线升级方法、装置、电子设备、存储介质及产品,能够降低固件在线升级时的管理成本,避免系统分区选择错误,有效防止设备变砖。所述技术方案如下:The embodiments of the present application provide a method, device, electronic device, storage medium and product for online firmware upgrade, which can reduce the management cost during online firmware upgrade, avoid system partition selection errors, and effectively prevent the device from becoming bricked. The technical solution is as follows:
第一方面,提供了一种固件在线升级方法,所述方法包括:In a first aspect, a method for online firmware upgrade is provided, the method comprising:
在执行第一系统分区的过程中,当确定第一固件镜像文件需要升级,将第二固件镜像文件写入第二系统分区,并将所述第二系统分区的第二地址信息写入第一寄存器,所述第二固件镜像文件为所述第一固件镜像文件的升级版本,所述第一系统分区和所述第二系统分区为地址信息不同的两个系统分区,所述第一寄存器用于存储第一存储区域中第一系统分区的第一地址信息所映射的实际地址信息;During the execution of the first system partition, when it is determined that the first firmware image file needs to be upgraded, the second firmware image file is written into the second system partition, and the second address information of the second system partition is written into the first register, the second firmware image file is an upgraded version of the first firmware image file, the first system partition and the second system partition are two system partitions with different address information, and the first register is used to store the actual address information mapped by the first address information of the first system partition in the first storage area;
将第二寄存器中分区交换标识配置为第一数值,并将所述分区交换标识的第一数值写入第二存储区域,所述第二寄存器用于配置分区交换相关标识的数值,所述第一数值用于指示分区交换功能已开启,所述分区交换功能是指从所述第一寄存器中读取所述第一存储区域中第一地址信息所映射的所述第二地址信息的功能;The partition exchange identifier in the second register is configured as a first value, and the first value of the partition exchange identifier is written into the second storage area, the second register is used to configure the value of the partition exchange related identifier, the first value is used to indicate that the partition exchange function is turned on, and the partition exchange function refers to a function of reading the second address information mapped by the first address information in the first storage area from the first register;
重启电子设备,并在所述电子设备重启后,查询所述第一存储区域中所述分区交换标识的数值;Restarting the electronic device, and after the electronic device is restarted, querying the value of the partition exchange identifier in the first storage area;
当查询到所述分区交换标识为第一数值,从所述第一寄存器中读取所述第一存储区域中第一地址信息所映射的所述第二地址信息;When it is found that the partition exchange identifier is a first value, the second address information mapped by the first address information in the first storage area is read from the first register;
基于所述第二地址信息,执行所述第二系统分区中的所述第二固件镜像文件。Based on the second address information, the second firmware image file in the second system partition is executed.
第二方面,提供了一种固件在线升级装置,所述装置包括:In a second aspect, a firmware online upgrade device is provided, the device comprising:
第一写入模块,用于在执行第一系统分区的过程中,当确定第一固件镜像文件需要升级,将第二固件镜像文件写入第二系统分区,所述第二固件镜像文件为所述第一固件镜像文件的升级版本,所述第一系统分区和所述第二系统分区为地址信息不同的两个系统分区;A first writing module is used for writing a second firmware image file into a second system partition when it is determined that the first firmware image file needs to be upgraded during the execution of the first system partition, wherein the second firmware image file is an upgraded version of the first firmware image file, and the first system partition and the second system partition are two system partitions with different address information;
第二写入模块,用于将所述第二系统分区的第二地址信息写入第一寄存器,所述第一寄存器用于存储第一存储区域中第一系统分区的第一地址信息所映射的实际地址信息;A second writing module, used for writing the second address information of the second system partition into a first register, where the first register is used for storing actual address information mapped to the first address information of the first system partition in the first storage area;
第一配置模块,用于将第二寄存器中分区交换标识配置为第一数值,所述第二寄存器用于配置分区交换相关标识的数值,所述第一数值用于指示分区交换功能已开启,所述分区交换功能是指从所述第一寄存器中读取所述第一存储区域中第一地址信息所映射的所述第二地址信息的功能;a first configuration module, configured to configure a partition exchange identifier in a second register to a first value, the second register being used to configure a value of a partition exchange related identifier, the first value being used to indicate that a partition exchange function has been enabled, the partition exchange function being a function of reading the second address information mapped by the first address information in the first storage area from the first register;
第三写入模块,用于将所述分区交换标识的第一数值写入第二存储区域The third writing module is used to write the first value of the partition exchange identifier into the second storage area
第一重启模块,用于重启电子设备;A first restart module, used to restart the electronic device;
查询模块,用于在所述电子设备重启后,查询所述第一存储区域中所述分区交换标识的数值;A query module, configured to query the value of the partition exchange identifier in the first storage area after the electronic device is restarted;
第一读取模块,用于当查询到所述分区交换标识为第一数值,从所述第一寄存器中读取所述第一存储区域中第一地址信息所映射的所述第二地址信息;A first reading module is configured to read, when it is queried that the partition exchange identifier is a first value, the second address information mapped to the first address information in the first storage area from the first register;
第一执行模块,用于基于所述第二地址信息,执行所述第二系统分区中的所述第二固件镜像文件。The first execution module is used to execute the second firmware image file in the second system partition based on the second address information.
第三方面,提供了一种电子设备,包括处理器以及存储器;所述存储器存储至少一条程序代码;所述至少一条程序代码用于被所述处理器调用并执行,以实现第一方面所述的固件在线升级方法。In a third aspect, an electronic device is provided, comprising a processor and a memory; the memory stores at least one program code; the at least one program code is used to be called and executed by the processor to implement the firmware online upgrade method described in the first aspect.
第四方面,提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有至少一条计算机程序,所述至少一条计算机程序被处理器执行时能够实现第一方面所述的固件在线升级方法。In a fourth aspect, a computer-readable storage medium is provided, wherein at least one computer program is stored in the computer-readable storage medium, and when the at least one computer program is executed by a processor, the firmware online upgrade method described in the first aspect can be implemented.
第五方面,提供了一种计算机程序产品,所述计算机程序产品包括计算机程序,所述计算机程序被处理器执行时能够实现第一方面所述的固件在线升级方法。In a fifth aspect, a computer program product is provided, the computer program product comprising a computer program, and when the computer program is executed by a processor, the firmware online upgrade method described in the first aspect can be implemented.
本申请实施例提供的技术方案带来的有益效果是:The beneficial effects of the technical solution provided by the embodiment of the present application are:
本申请实施例配置了两个系统分区,分别为第一系统分区和第二系统分区,虽然第一系统分区和第二系统分区的地址信息不同,但是在电子设备首次开机启动时,会将第一系统分区的第一地址信息写入第一存储区域,该第一存储区域中的第一地址信息实际上为逻辑地址信息,可根据分区交换功能是否开启,来映射不同系统分区的地址信息,进而根据所映射的系统分区的地址信息,对不同系统分区进行访问。例如,当基于第二存储区域内所存储的数据确定分区交换功能开启,则将该第一存储区域中第一地址信息隐藏,并从第一寄存器中读取该第一存储区域中第一地址信息所映射的第二地址信息;当基于第二存储区域内所存储的数据确定分区交换功能未开启,则从第一存储区域中第一地址信息。在后续对固件镜像文件升级时,不管升级版本的固件镜像文件在哪个系统分区,本申请实施例也只是存储且读取第一存储区域中的第一地址信息来访问相应的系统分区。由于在每次执行固件在线升级操作时,并不需要对不同系统分区分别进行管理,因此,降低了管理成本,同时能够避免系统分区选择错误,有效防止设备变砖。The embodiment of the present application is configured with two system partitions, namely the first system partition and the second system partition. Although the address information of the first system partition and the second system partition is different, when the electronic device is powered on for the first time, the first address information of the first system partition will be written into the first storage area. The first address information in the first storage area is actually the logical address information, and the address information of different system partitions can be mapped according to whether the partition exchange function is turned on, and then the different system partitions are accessed according to the address information of the mapped system partition. For example, when the partition exchange function is determined to be turned on based on the data stored in the second storage area, the first address information in the first storage area is hidden, and the second address information mapped by the first address information in the first storage area is read from the first register; when the partition exchange function is determined to be not turned on based on the data stored in the second storage area, the first address information is read from the first storage area. When the firmware image file is subsequently upgraded, no matter which system partition the upgraded version of the firmware image file is in, the embodiment of the present application only stores and reads the first address information in the first storage area to access the corresponding system partition. Since different system partitions do not need to be managed separately each time the firmware online upgrade operation is performed, the management cost is reduced, and the system partition selection error can be avoided at the same time, effectively preventing the device from becoming bricked.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
图1是本申请实施例提供的一种系统分区的示意图;FIG1 is a schematic diagram of a system partition provided in an embodiment of the present application;
图2是本申请实施例提供的一种固件在线升级方法的系统架构图;FIG2 is a system architecture diagram of a firmware online upgrade method provided in an embodiment of the present application;
图3是本申请实施例提供的一种固件在线升级方法的流程图;FIG3 is a flow chart of a firmware online upgrade method provided in an embodiment of the present application;
图4是本申请实施例提供的一种固件在线升级装置的结构示意图;FIG4 is a schematic diagram of the structure of a firmware online upgrade device provided in an embodiment of the present application;
图5示出了本申请一个示例性实施例提供的一种电子设备的结构框图。FIG. 5 shows a structural block diagram of an electronic device provided by an exemplary embodiment of the present application.
具体实施方式Detailed ways
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。In order to make the objectives, technical solutions and advantages of the present application more clear, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
可以理解,本申请实施例所使用的术语“每个”、“多个”及“任一”等,多个包括两个或两个以上,每个是指对应的多个中的每一个,任一是指对应的多个中的任意一个。举例来说,多个词语包括10个词语,而每个词语是指这10个词语中的每一个词语,任一词语是指10个词语中的任意一个词语。It can be understood that the terms "each", "multiple", and "any" used in the embodiments of the present application include two or more, each refers to each of the corresponding multiple, and any refers to any one of the corresponding multiple. For example, the multiple words include 10 words, and each word refers to each of the 10 words, and any word refers to any one of the 10 words.
需要说明的是,本申请所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据,并且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准,并提供有相应的操作入口,供用户选择授权或者拒绝。It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
本申请实施例提供的方法针对是嵌入式芯片(例如,ECU设备)中系统软件的固件在线升级问题。通常嵌入式芯片中系统软件的固件镜像文件存储在FLASH中。FLASH包括多个分区,参见图1,包括普通分区(Common regions)、系统分区等,系统分区可以包括系统分区A(System Partition A,即第一系统分区)、系统分区B(System Partition B,即第二系统分区)等。其中,普通分区的起始地址为地址0(Address0)、系统分区A的起始地址为地址1(Address1)、系统分区B的起始地址为地址2(Address2)。The method provided in the embodiment of the present application is aimed at the problem of online firmware upgrade of system software in embedded chips (for example, ECU devices). Usually, the firmware image file of the system software in the embedded chip is stored in FLASH. FLASH includes multiple partitions, see Figure 1, including common regions, system partitions, etc. The system partitions may include system partition A (System Partition A, i.e., the first system partition), system partition B (System Partition B, i.e., the second system partition), etc. Among them, the starting address of the common partition is address 0 (Address0), the starting address of the system partition A is address 1 (Address1), and the starting address of the system partition B is address 2 (Address2).
电子设备每次启动时,引导程序(Bootloader)会选择其中一个系统分区内的固件镜像文件执行。被选中的系统分区称为活跃分区(Active Partition),未被选中的系统分区称为非活跃分区。其中,引导程序是嵌入式系统上电后执行的第一段代码,在完成处理器和相关硬件设备初始化后,再将操作系统的镜像或固化的嵌入式应用程序装载到内存中,然后跳转到操作系统所在的内存空间,从而运行操作系统。引导程序可以初始化硬件设备、建立内存空间映射图,从而将系统的软硬件环境带到一个合适状态,以便为最终调用操作系统内核准备好正确的环境。在本申请实施例中,处理器对处于不同状态的系统分区具有不同的权限。对于活跃分区,处理器具有读的权限,对于非活跃分区,处理器具有读写权限。Each time the electronic device starts, the bootloader selects the firmware image file in one of the system partitions to execute. The selected system partition is called the active partition, and the unselected system partition is called the inactive partition. Among them, the bootloader is the first code executed after the embedded system is powered on. After the processor and related hardware devices are initialized, the operating system image or solidified embedded application is loaded into the memory, and then jumps to the memory space where the operating system is located to run the operating system. The bootloader can initialize the hardware devices and establish a memory space mapping map, so as to bring the system's hardware and software environment to a suitable state, so as to prepare the correct environment for the final call to the operating system kernel. In an embodiment of the present application, the processor has different permissions for system partitions in different states. For active partitions, the processor has read permissions, and for inactive partitions, the processor has read and write permissions.
为实现同一地址信息对不同系统分区的访问,本申请实施例提供了分区交换功能,当分区交换功能开启时,系统分区A的地址映射的实际地址为系统分区B的地址,此时处理器根据系统分区A的地址访问的并不是系统分区A,而是系统分区B;当分区交换功能关闭时,系统分区A的地址映射的实际地址依然是系统分区A,此时处理器根据系统分区A的地址访问的是系统分区A。In order to achieve access to different system partitions with the same address information, an embodiment of the present application provides a partition exchange function. When the partition exchange function is turned on, the actual address mapped by the address of system partition A is the address of system partition B. At this time, the processor accesses system partition B instead of system partition A according to the address of system partition A; when the partition exchange function is turned off, the actual address mapped by the address of system partition A is still system partition A. At this time, the processor accesses system partition A according to the address of system partition A.
然而,分区交换功能开启后,只在处理器对系统分区执行读取操作时,分区交换功能才生效,如果处理器对系统分区执行写操作,即便分区交换功能开启,分区交换功能也不生效。However, after the partition exchange function is enabled, the partition exchange function takes effect only when the processor performs a read operation on the system partition. If the processor performs a write operation on the system partition, the partition exchange function does not take effect even if the partition exchange function is enabled.
对于分区隐藏功能分别处于开启(ON)和关闭(OFF)状态,处理器分别对FLASH执行读写操作时,System Partition A和System Partition B的起始地址的情况,可参见下述表1。For the partition hiding function being in the ON state and the OFF state, respectively, when the processor performs read and write operations on the FLASH, the start addresses of System Partition A and System Partition B can be seen in the following Table 1.
表1Table 1
通过表1可以看出,当处理器对FLASH执行读取操作时,如果分区交换功能开启,则System Partition A和System Partition B的地址互换,也即是,System Partition A的起始地址由Address1变为Address2,System Partition B的起始地址由Address2变为Address1;如果分区交换功能关闭,则System Partition A和System Partition B的地址不会互换,此时System Partition A的起始地址依然为Address1,System Partition B的起始地址依然为Address2。当处理器对FLASH执行写操作时,无论分区交换功能是否开启,System Partition A和System Partition B的地址都不会互换,此时System Partition A的起始地址依然为Address1,System Partition B的起始地址依然为Address2。It can be seen from Table 1 that when the processor performs a read operation on the FLASH, if the partition exchange function is turned on, the addresses of System Partition A and System Partition B are exchanged, that is, the starting address of System Partition A changes from Address1 to Address2, and the starting address of System Partition B changes from Address2 to Address1; if the partition exchange function is turned off, the addresses of System Partition A and System Partition B will not be exchanged, and the starting address of System Partition A will still be Address1, and the starting address of System Partition B will still be Address2. When the processor performs a write operation on the FLASH, regardless of whether the partition exchange function is turned on or not, the addresses of System Partition A and System Partition B will not be exchanged, and the starting address of System Partition A will still be Address1, and the starting address of System Partition B will still be Address2.
需要说明的是,System Partition A和System Partition B的地址互换并非物理地址真的发生互换,而是Address1所映射的System Partition发生变换。Address1原本为System Partition A的起始地址,根据Address1可以访问System Partition A,但是在分区交换功能生效后,Address1映射的系统分区为System Partition B,此时根据Address1访问的是System Partition B,而不是System Partition A。It should be noted that the address swap between System Partition A and System Partition B does not mean that the physical addresses are swapped, but that the System Partition mapped by Address1 is changed. Address1 was originally the starting address of System Partition A, and System Partition A can be accessed according to Address1. However, after the partition swap function takes effect, the system partition mapped by Address1 is System Partition B. At this time, what is accessed according to Address1 is System Partition B, not System Partition A.
图2示出了本申请实施例提供的固件在线升级方法的系统架构图,参见图2,该系统包括:引导程序、处理器逻辑控制单元、分区映射数据存储单元及系统分区。FIG2 shows a system architecture diagram of a firmware online upgrade method provided in an embodiment of the present application. Referring to FIG2 , the system includes: a boot program, a processor logic control unit, a partition mapping data storage unit, and a system partition.
其中,引导程序(Bootloader)用于对系统分区内数据进行校验,对处理器逻辑控制单元进行分区交换功能的初始化操作。The bootloader is used to verify the data in the system partition and to initialize the partition exchange function of the processor logic control unit.
处理器逻辑控制单元用于配置分区交换功能相关的信息,完成系统分区内数据的访问和校验。该处理器逻辑控制单元包括多个寄存器组以及分区交换逻辑单元。分区交换逻辑单元为处理器实现分区交换的逻辑控制电路,用于根据多个寄存器组实现分区交换的逻辑功能。多个寄存器组包括分区逻辑控制寄存器组(Partition LC register,即第二寄存器)、分区逻辑地址寄存器组(Partition LA register,即第一寄存器)及分区交换上下文寄存器组(Partition swap context register,即第三寄存器)等。分区逻辑控制寄存器组包括至少一个寄存器,用于配置分区交换相关标识的数值。分区交换相关标识包括分区交换功能标识、分区签名标识等。分区逻辑地址寄存器组包括至少一个寄存器,用于存储第一存储区域中第一系统分区的第一地址信息所映射的实际地址信息。分区交换上下文寄存器组包括至少一个寄存器,可以用于用户设置配置需要交换的系统分区的地址、大小等信息,还可以用于访问分区映射数据存储单元及系统分区,对分区数据进行校验等。The processor logic control unit is used to configure information related to the partition exchange function and complete the access and verification of data in the system partition. The processor logic control unit includes multiple register groups and a partition exchange logic unit. The partition exchange logic unit is a logic control circuit for the processor to implement partition exchange, and is used to implement the logic function of partition exchange according to multiple register groups. The multiple register groups include a partition logic control register group (Partition LC register, i.e., the second register), a partition logic address register group (Partition LA register, i.e., the first register) and a partition exchange context register group (Partition swap context register, i.e., the third register), etc. The partition logic control register group includes at least one register for configuring the value of the partition exchange related identifier. The partition exchange related identifier includes a partition exchange function identifier, a partition signature identifier, etc. The partition logic address register group includes at least one register for storing the actual address information mapped by the first address information of the first system partition in the first storage area. The partition exchange context register group includes at least one register, which can be used by the user to set the address, size and other information of the system partition to be exchanged, and can also be used to access the partition mapping data storage unit and the system partition, and verify the partition data.
分区映射数据存储单元包括多个存储区域,分别为分逻辑控制数据存储区域(即第二存储区域)、分区逻辑地址数据存储区域(即第一存储区域)、分区签名数据存储区域(即第三存储区域)等。逻辑控制数据存储区域用于存储系统分区的逻辑控制数据,包括分区交换功能标识的数值、分区签名标识的数值等。分区逻辑地址数据存储区域用于存储系统分区的地址数据。分区签名数据存储区域用于存储系统分区数据的校验值。The partition mapping data storage unit includes multiple storage areas, namely, a partition logic control data storage area (i.e., the second storage area), a partition logic address data storage area (i.e., the first storage area), a partition signature data storage area (i.e., the third storage area), etc. The logic control data storage area is used to store the logic control data of the system partition, including the value of the partition exchange function identifier, the value of the partition signature identifier, etc. The partition logic address data storage area is used to store the address data of the system partition. The partition signature data storage area is used to store the check value of the system partition data.
系统分区包括系统分区A(即第一系统分区)和系统分区B(即第二系统分区)等。分区A和系统分区B用于存储系统代码数据。系统分区A和系统分区B的地址不同,其地址大小可由用户预先配置。The system partition includes system partition A (i.e., the first system partition) and system partition B (i.e., the second system partition). Partition A and system partition B are used to store system code data. The addresses of system partition A and system partition B are different, and their address sizes can be pre-configured by the user.
本申请实施例提供了一种固件在线升级方法,以具有图2所示的系统架构的电子设备执行本申请实施例为例,参见图3,本申请实施例提供的方法流程包括:The embodiment of the present application provides a method for online firmware upgrade. Taking the electronic device having the system architecture shown in FIG. 2 as an example, referring to FIG. 3 , the method flow provided by the embodiment of the present application includes:
301、在执行第一系统分区的过程中,当确定第一固件镜像文件需要升级,将第二固件镜像文件写入第二系统分区,并将第二系统分区的第二地址信息写入第一寄存器。301. During the execution of the first system partition, when it is determined that the first firmware image file needs to be upgraded, the second firmware image file is written into the second system partition, and the second address information of the second system partition is written into the first register.
其中,第二固件镜像文件和第二固件镜像文件为同一固件的不同版本,第二固件镜像文件为第一固件镜像文件的升级版本。第一系统分区和第二系统分区为FLASH的两个系统分区,可将第一系统分区作为主系统分区,将第二系统分区作为辅助系统分区。第一系统分区和第二系统分区的地址信息不同,该地址信息包括起始地址、大小等。第一系统分区和第二系统分区的地址信息不同主要是指起始地址不同。对于第一系统分区和第二系统分区的大小,可以相同,也可以不同,具体可由用户根据需求配置。在对系统分区中的系统软件进行升级时,可以采用ping-pong机制进行升级,此时系统软件的升级版本在第一系统分区和第二系统分区中交替存储,第一系统分区和第二系统分区也将交替执行。这样,第一系统分区和第二系统分区将共同存储的系统软件的不同版本。例如,系统软件有四个版本,第一系统分区可以存储系统软件的第一版本和第三版本,第二系统分区可以存储系统软件的第二版本和第四版本。第一寄存器用于存储第一存储区域中第一系统分区的第一地址信息所映射的实际地址信息。随着系统软件不断进行升级,系统软件的不同版本在第一系统分区和第二系统分区交替存储,第一寄存器中所存储的地址信息也将不断变化。Among them, the second firmware image file and the second firmware image file are different versions of the same firmware, and the second firmware image file is an upgraded version of the first firmware image file. The first system partition and the second system partition are two system partitions of FLASH, and the first system partition can be used as the main system partition, and the second system partition can be used as the auxiliary system partition. The address information of the first system partition and the second system partition is different, and the address information includes the starting address, size, etc. The difference in address information of the first system partition and the second system partition mainly refers to the difference in starting address. The size of the first system partition and the second system partition can be the same or different, and can be specifically configured by the user according to needs. When upgrading the system software in the system partition, the ping-pong mechanism can be used for upgrading. At this time, the upgraded version of the system software is alternately stored in the first system partition and the second system partition, and the first system partition and the second system partition will also be executed alternately. In this way, the first system partition and the second system partition will store different versions of the system software together. For example, there are four versions of the system software, the first system partition can store the first version and the third version of the system software, and the second system partition can store the second version and the fourth version of the system software. The first register is used to store the actual address information mapped by the first address information of the first system partition in the first storage area. As the system software is continuously upgraded, different versions of the system software are alternately stored in the first system partition and the second system partition, and the address information stored in the first register will also continuously change.
电子设备首次启动时,引导程序通过第三寄存器与处理器逻辑控制单元进行通信,并在通信过程中判断处理器逻辑控制单元的分区交换功能是否初始化,如果未进行初始化,则对分区交换功能进行初始化,分区交换功能初始化后,执行第一系统分区。When the electronic device is started for the first time, the boot program communicates with the processor logic control unit through the third register, and determines whether the partition exchange function of the processor logic control unit is initialized during the communication process. If not initialized, the partition exchange function is initialized. After the partition exchange function is initialized, the first system partition is executed.
具体地,电子设备首次启动时,对分区交换功能进行初始化,可以采用如下步骤:Specifically, when the electronic device is started for the first time, the partition exchange function is initialized, and the following steps may be adopted:
3011、电子设备首次启动时,将第一地址信息写入第一寄存器中,并将第一地址信息写入第一存储区域中。3011. When the electronic device is started for the first time, the first address information is written into the first register, and the first address information is written into the first storage area.
电子设备首次启动,可将第一系统分区的第一地址信息写入第一寄存器中,然后再通过第三寄存器将该第一地址信息写入第一存储区域中。该第一地址信息为本申请实施例执行固件在线升级操作的系统分区对外暴露的统一访问地址,在后续进行固件在线升级操作时,第一存储区域中的第一地址信不会更新。由于本申请实施例只维护一个系统分区的地址信息,因而降低了管理成本,且由于无需更新执行固件在线升级操作的系统分区的地址,因此能够避免系统分区错误,有效地防止了设备变砖。When the electronic device is started for the first time, the first address information of the first system partition can be written into the first register, and then the first address information can be written into the first storage area through the third register. The first address information is a unified access address exposed to the outside by the system partition that performs the firmware online upgrade operation in the embodiment of the present application. When the firmware online upgrade operation is performed subsequently, the first address information in the first storage area will not be updated. Since the embodiment of the present application only maintains the address information of one system partition, the management cost is reduced, and since there is no need to update the address of the system partition that performs the firmware online upgrade operation, system partition errors can be avoided, effectively preventing the device from becoming bricked.
3012、对第一系统分区的数据进行哈希计算,得到第一哈希值。3012. Perform a hash calculation on the data of the first system partition to obtain a first hash value.
采用哈希算法对第一系统分区的数据进行哈希计算,可以得到第一系统分区对应的第一哈希值。By using a hash algorithm to perform hash calculation on the data of the first system partition, a first hash value corresponding to the first system partition can be obtained.
3013、将第二寄存器中分区交换标识配置为第二数值,并将第二寄存器中分区签名标识配置为第三数值。3013. Configure the partition exchange identifier in the second register as a second value, and configure the partition signature identifier in the second register as a third value.
其中,第二数值用于指示分区交换功能已关闭,第三数值用于指示分区签名功能已开启。分区交换功能是指从第一寄存器中读取第一存储区域中第一地址信息所映射的第二地址信息的功能。分区签名功能是指将系统分区中固件镜像文件对应的哈希值写入第三存储区域的功能。The second value is used to indicate that the partition exchange function is turned off, and the third value is used to indicate that the partition signature function is turned on. The partition exchange function refers to a function of reading the second address information mapped by the first address information in the first storage area from the first register. The partition signature function refers to a function of writing the hash value corresponding to the firmware image file in the system partition into the third storage area.
3014、将分区交换标识的第二数值和分区签名标识的第三数值写入第二存储区域。3014. Write the second value of the partition exchange identifier and the third value of the partition signature identifier into the second storage area.
引导程序可以通过第三寄存器将分区交换标识的第二数值和分区签名标识的第三数值写入第二存储区域。The boot program may write the second value of the partition exchange identifier and the third value of the partition signature identifier into the second storage area through the third register.
3015、响应于分区签名标识为第三数值,将第一哈希值写入第三存储区域。3015. In response to the partition signature being identified as a third value, write the first hash value into a third storage area.
当分区签名标识为第三数值,说明分区签名功能已开启,因此,可将第一哈希值写入第三存储区域。在将第一哈希值写入第三存储区域时,可通过第三寄存器写入。When the partition signature identifier is the third value, it indicates that the partition signature function has been enabled, and therefore, the first hash value can be written into the third storage area. When the first hash value is written into the third storage area, it can be written through the third register.
当执行完上述步骤3011~3015后,完成了分区交换功能的初始化操作,从而可以根据第一存储区域中第一系统分区的第一地址信息,执行第一系统分区。After executing the above steps 3011 to 3015, the initialization operation of the partition exchange function is completed, so that the first system partition can be executed according to the first address information of the first system partition in the first storage area.
在执行第一系统分区的过程中,当检测到第一固件镜像文件对应的升级版本,即第二固件镜像文件,确定需要对第一固件镜像文件进行升级。系统的OTA程序获取第二固件镜像文件,进而将第二固件镜像文件写入到系统分区中。由于第一固件镜像文件存储在第一系统分区中,基于ping-pong升级机制,在本次进行升级时,需要将第二固件镜像文件写入第二系统分区。由于在将第二固件镜像文件写入第二系统分区之前,第一固件镜像文件为系统分区存储的最新版本的固件镜像文件,而将第二固件镜像文件写入第二系统分区之后,第二固件镜像文件为系统分区中最新版本的固件镜像文件,而第一寄存器中存储的是系统分区中最新版本的固件镜像文件所在的系统分区的地址信息,因此,在将第二固件镜像文件写入第二系统分区之后,还需要将第二系统分区的第二地址信息写入第一寄存器,从而保证第一寄存器中存储的是系统分区中最新版本的固件镜像文件所在的系统分区的地址信息。In the process of executing the first system partition, when the upgrade version corresponding to the first firmware image file, that is, the second firmware image file, is detected, it is determined that the first firmware image file needs to be upgraded. The OTA program of the system obtains the second firmware image file, and then writes the second firmware image file into the system partition. Since the first firmware image file is stored in the first system partition, based on the ping-pong upgrade mechanism, the second firmware image file needs to be written into the second system partition during this upgrade. Since before the second firmware image file is written into the second system partition, the first firmware image file is the latest version of the firmware image file stored in the system partition, and after the second firmware image file is written into the second system partition, the second firmware image file is the latest version of the firmware image file in the system partition, and the first register stores the address information of the system partition where the latest version of the firmware image file in the system partition is located, therefore, after the second firmware image file is written into the second system partition, the second address information of the second system partition also needs to be written into the first register, thereby ensuring that the first register stores the address information of the system partition where the latest version of the firmware image file in the system partition is located.
302、将第二寄存器中分区交换标识配置为第一数值,并将分区交换标识的第一数值写入第二存储区域。302. Configure the partition exchange flag in the second register to be a first value, and write the first value of the partition exchange flag into the second storage area.
其中,第一数值用于指示分区交换功能已开启。由于第一存储区域存储的是第一系统分区的第一地址信息,最新版本的第二固件镜像文件存储在第二系统分区中,而第二系统分区的地址信息为第二地址信息,并不是第一地址信息。然而,为了实现固件在线升级,需要执行第二系统分区中的第二固件镜像文件,而第一地址信息为本申请实施例执行固件在线升级操作的系统分区对外暴露的统一访问地址,为实现对第二系统分区的访问,则需要将第二寄存器中分区交换标识配置为第一数值,以开启分区交换功能,从而可以读取到第一存储区域中第一地址信息所映射的实际地址信息。Among them, the first value is used to indicate that the partition exchange function has been turned on. Since the first storage area stores the first address information of the first system partition, the latest version of the second firmware image file is stored in the second system partition, and the address information of the second system partition is the second address information, not the first address information. However, in order to realize the online upgrade of the firmware, it is necessary to execute the second firmware image file in the second system partition, and the first address information is the unified access address exposed to the outside of the system partition that performs the firmware online upgrade operation in the embodiment of the present application. In order to realize the access to the second system partition, it is necessary to configure the partition exchange identifier in the second register to the first value to turn on the partition exchange function, so that the actual address information mapped by the first address information in the first storage area can be read.
进一步地,在将第二寄存器中分区交换标识配置为第一数值后,还将分区交换标识的第一数值写入第二存储区域,从而可在执行固件在线升级操作时,能够读取到分区交换功能相关的状态数据,进而根据读取的状态数据,执行相应的操作。Furthermore, after the partition exchange identifier in the second register is configured as the first value, the first value of the partition exchange identifier is also written into the second storage area, so that when the firmware online upgrade operation is performed, the status data related to the partition exchange function can be read, and then the corresponding operation can be performed according to the read status data.
进一步地,为避免在固件在线升级操作过程中第二固件镜像文件中的数据丢失或被篡改,导致确保固件在线升级操作失败,本申请实施例在获取第二固件镜像文件之后,还将对第二系统分区中的数据进行哈希计算,得到第二哈希值,进而将第三存储区域中的第一哈希值更新为第二哈希值。该第二哈希值可作为参考值,对固件在线升级操作过程中第二系统分区中的数据进行完整性校验。Furthermore, in order to avoid data loss or tampering in the second firmware image file during the firmware online upgrade operation, which may lead to the failure of the firmware online upgrade operation, after obtaining the second firmware image file, the embodiment of the present application will also perform a hash calculation on the data in the second system partition to obtain a second hash value, and then update the first hash value in the third storage area to the second hash value. The second hash value can be used as a reference value to perform integrity verification on the data in the second system partition during the firmware online upgrade operation.
303、重启电子设备,并在电子设备重启后,查询第一存储区域中分区交换标识的数值。303: Restart the electronic device, and after the electronic device is restarted, query the value of the partition exchange identifier in the first storage area.
由于本申请实施例提供了两个系统分区,分别为第一系统分区和第二系统分区,最新版本的固件镜像文件可能位于第一系统分区,也可能位于第二系统分区,而电子设备存储的用于执行固件升级操作的系统分区的地址信息为第一地址信息,为确定出第二固件镜像文件所在的系统分区,当因第一固件镜像文件需要升级电子设备重启后,电子设备还将查询第一存储区域中分区交换标识的数值。Since the embodiment of the present application provides two system partitions, namely the first system partition and the second system partition, the latest version of the firmware image file may be located in the first system partition or in the second system partition, and the address information of the system partition stored in the electronic device for performing the firmware upgrade operation is the first address information. In order to determine the system partition where the second firmware image file is located, when the electronic device is restarted because the first firmware image file needs to be upgraded, the electronic device will also query the value of the partition exchange identifier in the first storage area.
304、当查询到分区交换标识为第一数值,从第一寄存器中读取第一存储区域中第一地址信息所映射的第二地址信息。304. When it is found that the partition exchange identifier is the first value, read the second address information mapped by the first address information in the first storage area from the first register.
当查询到分区交换标识为第一数值,确定分区交换功能已开启,且当前处理器对FLASH的操作类型为读取操作,因此,可将第一系统分区隐藏,进而基于第一地址信息访问第二系统分区。由于第一地址信息为第一系统分区的物理地址,为实现对第二系统分区的访问,则需要获取第一地址信息所映射的实际地址信息,而第一寄存器中存储有第一存储区域中第一地址信息所映射的实际地址信息,因此,可从第一寄存器中读取第一存储区域中第一地址信息所映射的第二地址信息。When the partition exchange identifier is found to be the first value, it is determined that the partition exchange function has been turned on, and the current processor's operation type on the FLASH is a read operation. Therefore, the first system partition can be hidden, and then the second system partition can be accessed based on the first address information. Since the first address information is the physical address of the first system partition, in order to access the second system partition, it is necessary to obtain the actual address information mapped by the first address information, and the first register stores the actual address information mapped by the first address information in the first storage area. Therefore, the second address information mapped by the first address information in the first storage area can be read from the first register.
305、基于第二地址信息,执行第二系统分区中的第二固件镜像文件。305. Execute the second firmware image file in the second system partition based on the second address information.
为提高固件在线升级的成功率,在执行第二系统分区中的第二固件镜像文件之前,还需要对第二系统分区中的数据进行校验。具体地,可根据第二地址信息,从第二系统分区中,读取第二系统分区的数据,采用哈希算法对第二系统分区的数据进行哈希计算,得到第三哈希值,然后从第三存储区域中,读取第二哈希值,进而将第二哈希值与第三哈希值进行比较,当第二哈希值与第三哈希值匹配,则执行第二系统分区中的第二固件镜像文件,以完成对第一固件镜像文件的升级。此处需要说明的是,两个哈希值匹配可以是两个哈希值相等,或者误差在设定的范围内。In order to improve the success rate of the online firmware upgrade, before executing the second firmware image file in the second system partition, it is also necessary to verify the data in the second system partition. Specifically, according to the second address information, the data of the second system partition can be read from the second system partition, and the data of the second system partition can be hashed using a hash algorithm to obtain a third hash value, and then the second hash value is read from the third storage area, and then the second hash value is compared with the third hash value. When the second hash value matches the third hash value, the second firmware image file in the second system partition is executed to complete the upgrade of the first firmware image file. It should be noted here that the match of two hash values can be that the two hash values are equal, or the error is within a set range.
在本申请另一个实施例中,在执行第一系统分区的过程中,当确定第一固件镜像文件不需要升级而电子设备重启,在电子设备重启后,可以执行第一系统分区中的第一固件镜像文件。In another embodiment of the present application, during the execution of the first system partition, when it is determined that the first firmware image file does not need to be upgraded and the electronic device is restarted, the first firmware image file in the first system partition can be executed after the electronic device is restarted.
进一步地,在执行第一系统分区中的第一固件镜像文件之前,电子设备还将对第一系统分区中的数据进行完整性校验。具体地,可以从第二存储区域中,读取分区交换标识的数值,响应于该分区交换标识的数值为第二数值,也即是,分区交换功能未开启,读取第一存储区域中的第一地址信息,然后根据第一地址信息,读取第一系统分区中的数据,进而采用哈希算法,对第一系统分区中的数据进行哈希计算,得到第四哈希值。然后从第三存储区域中,读取第一哈希值,并将第一哈希值与第四哈希值进行比较,当第一哈希值与第四哈希值匹配,则执行第一系统分区中的第一固件镜像文件。Furthermore, before executing the first firmware image file in the first system partition, the electronic device will also perform an integrity check on the data in the first system partition. Specifically, the value of the partition exchange identifier can be read from the second storage area, and in response to the value of the partition exchange identifier being the second value, that is, the partition exchange function is not enabled, the first address information in the first storage area is read, and then the data in the first system partition is read according to the first address information, and then a hash algorithm is used to perform a hash calculation on the data in the first system partition to obtain a fourth hash value. Then, the first hash value is read from the third storage area, and the first hash value is compared with the fourth hash value. When the first hash value matches the fourth hash value, the first firmware image file in the first system partition is executed.
进一步地,当第一哈希值与第四哈希值不匹配,则对电子设备进行错误提示,然后重启电子设备。Furthermore, when the first hash value does not match the fourth hash value, an error prompt is given to the electronic device, and then the electronic device is restarted.
为便于理解上述固件在线升级方法,下面将结合图2进行说明。To facilitate understanding of the above firmware online upgrade method, it will be described below in conjunction with FIG. 2 .
参见图2,步骤①中,电子设备首次启动后,引导程序通过分区交换上下文寄存器组与处理器逻辑控制单元进行通信,在通信过程中,判断分区交换功能是否开启,如果没有开启,则对分区交换功能进行初始化操作。具体地,将系统分区A的地址信息写入分区逻辑地址寄存器组中,并将系统分区A的地址信息写入分区映射数据存储单元的第一存储区域中,然后计算系统分区A中数据的哈希值A,并配置分区逻辑控制寄存器,将分区交换标识的数值设置为第二数值,以关闭分区交换功能,并将分区签名标识设置为第三数值,以开启分区签名功能,然后通过分区交换上下文寄存器组,将分区交换标识的第二数值和分区签名标识的第三数值写入分区映射数据存储单元的第二存储区域中,然后将哈希值A通过分区交换上下文寄存器组,写入分区映射数据存储单元的第一存储区域中。Referring to FIG. 2, in step ①, after the electronic device is started for the first time, the boot program communicates with the processor logic control unit through the partition exchange context register group. During the communication process, it is determined whether the partition exchange function is turned on. If it is not turned on, the partition exchange function is initialized. Specifically, the address information of the system partition A is written into the partition logic address register group, and the address information of the system partition A is written into the first storage area of the partition mapping data storage unit, and then the hash value A of the data in the system partition A is calculated, and the partition logic control register is configured, the value of the partition exchange identifier is set to the second value to turn off the partition exchange function, and the partition signature identifier is set to the third value to turn on the partition signature function, and then the second value of the partition exchange identifier and the third value of the partition signature identifier are written into the second storage area of the partition mapping data storage unit through the partition exchange context register group, and then the hash value A is written into the first storage area of the partition mapping data storage unit through the partition exchange context register group.
步骤②中,引导程序根据系统分区A的地址,执行系统分区A。In step ②, the boot program executes system partition A according to the address of system partition A.
步骤③中,在系统分区A执行过程中,如果电子设备需要重启,判断电子设备重启的原因是否为需要对系统分区中的固件镜像文件进行升级,如果是,执行步骤④,如果否,执行步骤⑤。In step ③, during the execution of system partition A, if the electronic device needs to be restarted, determine whether the reason for the restart of the electronic device is the need to upgrade the firmware image file in the system partition. If so, execute step ④; if not, execute step ⑤.
步骤④中,引导程序从分区映射数据存储单元的第二存储区域读取分区交换标识的数值为第二数值,并从第一存储区域中读取系统分区A的地址信息,根据系统分区A的地址信息,读取系统分区A的数据,然后计算系统分区A的数据的哈希值,如果该哈希值与第一存储区域中的哈希值A一致,则确定系统分区A的数据通过完整性校验,进而执行系统分区A,如果该哈希值与第一存储区域中的哈希值A不一致,则对电子设备进行提示错误,然后重启电子设备。In step ④, the boot program reads the value of the partition exchange identifier as the second value from the second storage area of the partition mapping data storage unit, and reads the address information of the system partition A from the first storage area. According to the address information of the system partition A, the data of the system partition A is read, and then the hash value of the data of the system partition A is calculated. If the hash value is consistent with the hash value A in the first storage area, it is determined that the data of the system partition A passes the integrity check, and then the system partition A is executed. If the hash value is inconsistent with the hash value A in the first storage area, an error prompt is given to the electronic device, and then the electronic device is restarted.
步骤⑤中,系统的OTA程序接收新的固件镜像文件,并将新的固件镜像文件写入系统分区B,然后计算系统分区B的数据的哈希值,将得到的哈希值B写入第三存储区域,并将系统分区B的地址信息写入分区逻辑地址寄存器组中。响应于分区交换功能使能,对电子设备进行重启,电子设备重启后,引导程序执行步骤4检查分区交换功能是否使能,由于分区交换功能使能,第一存储区域存储的系统分区A的地址信息映射的实际地址为系统分区B的地址信息,也即是看,处理器实际上访问的是系统分区B的分区代码数据,因此,执行的也是系统分区B的新的固件代码。In step ⑤, the system's OTA program receives a new firmware image file, writes the new firmware image file into system partition B, then calculates the hash value of the data of system partition B, writes the obtained hash value B into the third storage area, and writes the address information of system partition B into the partition logical address register group. In response to the partition exchange function being enabled, the electronic device is restarted. After the electronic device is restarted, the boot program executes step 4 to check whether the partition exchange function is enabled. Since the partition exchange function is enabled, the actual address mapped to the address information of system partition A stored in the first storage area is the address information of system partition B, that is, the processor actually accesses the partition code data of system partition B, and therefore, the new firmware code of system partition B is also executed.
采用本申请实施例提供的方法,在不进行分区数据擦除、数据拷贝等情况下,通过处理器的分区映射机制,可以基于统一地址对不同分区的执行访问,提升了系统响应时间,降低了系统软件的维护成本。另外,本申请实施例还支持对两个系统分区进行链式映射管理,引导程序通过同一地址可以访问两个系统分区中被激活的系统分区的分区代码数据,未被激活的系统分区被隐藏。在向未被激活的系统分区写入数据的时候,激活的系统分区内的分区代码数据仍然可以运行,因此,能够实现对两个系统分区上下文的切换。By adopting the method provided in the embodiment of the present application, without performing partition data erasure, data copying, etc., the partition mapping mechanism of the processor can be used to perform execution access to different partitions based on a unified address, thereby improving the system response time and reducing the maintenance cost of the system software. In addition, the embodiment of the present application also supports chain mapping management of two system partitions, and the boot program can access the partition code data of the activated system partition in the two system partitions through the same address, and the inactivated system partition is hidden. When writing data to the inactivated system partition, the partition code data in the activated system partition can still run, so the context switching of the two system partitions can be achieved.
上述所有可选技术方案,可以采用任意结合形成本申请的可选实施例,在此不再一一赘述。All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
请参考图4,其示出了本申请实施例提供了一种固件在线升级装置的结构示意图,该装置可以通过软件、硬件或者二者结合实现,成为电子设备的全部或一部分,该装置包括:Please refer to FIG. 4 , which shows a schematic diagram of the structure of a firmware online upgrade device provided in an embodiment of the present application. The device can be implemented by software, hardware, or a combination of the two, and becomes the whole or part of the electronic device. The device includes:
第一写入模块401,用于在执行第一系统分区的过程中,当确定第一固件镜像文件需要升级,将第二固件镜像文件写入第二系统分区,该第二固件镜像文件为第一固件镜像文件的升级版本,该第一系统分区和第二系统分区为地址信息不同的两个系统分区;A first writing module 401 is used for writing a second firmware image file into a second system partition when it is determined that the first firmware image file needs to be upgraded during the execution of the first system partition, wherein the second firmware image file is an upgraded version of the first firmware image file, and the first system partition and the second system partition are two system partitions with different address information;
第二写入模块402,用于将第二系统分区的第二地址信息写入第一寄存器,该第一寄存器用于存储第一存储区域中第一系统分区的第一地址信息所映射的实际地址信息;A second writing module 402, used to write the second address information of the second system partition into a first register, where the first register is used to store the actual address information mapped to the first address information of the first system partition in the first storage area;
第一配置模块403,用于将第二寄存器中分区交换标识配置为第一数值,该第二寄存器用于配置分区交换相关标识的数值,该第一数值用于指示分区交换功能已开启,该分区交换功能是指从第一寄存器中读取第一存储区域中第一地址信息所映射的第二地址信息的功能;A first configuration module 403 is used to configure the partition exchange identifier in the second register to a first value, the second register is used to configure the value of the partition exchange related identifier, the first value is used to indicate that the partition exchange function is turned on, and the partition exchange function refers to a function of reading the second address information mapped by the first address information in the first storage area from the first register;
第三写入模块404,用于将分区交换标识的第一数值写入第二存储区域The third writing module 404 is used to write the first value of the partition exchange identifier into the second storage area
第一重启模块405,用于重启电子设备;A first restart module 405, used to restart the electronic device;
查询模块406,用于在电子设备重启后,查询第一存储区域中分区交换标识的数值;A query module 406, configured to query the value of the partition exchange identifier in the first storage area after the electronic device is restarted;
第一读取模块407,用于当查询到分区交换标识为第一数值,从第一寄存器中读取第一存储区域中第一地址信息所映射的第二地址信息;A first reading module 407 is configured to read, when the partition exchange identifier is found to be a first value, second address information mapped to the first address information in the first storage area from the first register;
第一执行模块408,用于基于第二地址信息,执行第二系统分区中的第二固件镜像文件。The first execution module 408 is configured to execute the second firmware image file in the second system partition based on the second address information.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
初始化模块,用于电子设备首次启动时,对分区交换功能进行初始化;An initialization module is used to initialize the partition exchange function when the electronic device is started for the first time;
第二执行模块,用于分区交换功能初始化后,执行第一系统分区。The second execution module is used to execute the first system partition after the partition exchange function is initialized.
在本申请的另一个实施例中,初始化模块,用于电子设备首次启动时,将第一地址信息写入第一寄存器中,并将第一地址信息写入第一存储区域中;In another embodiment of the present application, the initialization module is used to write the first address information into the first register and write the first address information into the first storage area when the electronic device is started for the first time;
第一计算模块,用于对第一系统分区的数据进行哈希计算,得到第一哈希值;A first calculation module, used for performing hash calculation on the data of the first system partition to obtain a first hash value;
第二配置模块,用于将第二寄存器中分区交换标识配置为第二数值,并将第二寄存器中分区签名标识配置为第三数值,第二数值用于指示分区交换功能已关闭,第三数值用于指示分区签名功能已开启,分区签名功能是指将系统分区中固件镜像文件对应的哈希值写入第三存储区域的功能;A second configuration module, configured to configure the partition exchange identifier in the second register to a second value, and to configure the partition signature identifier in the second register to a third value, wherein the second value is used to indicate that the partition exchange function is turned off, and the third value is used to indicate that the partition signature function is turned on, and the partition signature function refers to a function of writing a hash value corresponding to a firmware image file in a system partition into a third storage area;
第四写入模块,用于将分区交换标识的第二数值和分区签名标识的第三数值写入第二存储区域;A fourth writing module, used for writing the second value of the partition exchange identifier and the third value of the partition signature identifier into the second storage area;
第五写入模块,用于响应于分区签名标识为第三数值,将第一哈希值写入第三存储区域。The fifth writing module is used to write the first hash value into the third storage area in response to the partition signature being identified as a third value.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
第二计算模块,用于对第二系统分区中的数据进行哈希计算,得到第二哈希值;A second calculation module, used for performing hash calculation on the data in the second system partition to obtain a second hash value;
更新模块,用于将第三存储区域中的第一哈希值更新为第二哈希值。An updating module is used to update the first hash value in the third storage area to a second hash value.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
第二读取模块,用于根据第二地址信息,读取第二系统分区的数据;A second reading module, used for reading data of the second system partition according to the second address information;
第三计算模块,用于对第二系统分区的数据进行哈希计算,得到第三哈希值;A third calculation module, used for performing hash calculation on the data of the second system partition to obtain a third hash value;
第三读取模块,用于从第三存储区域中,读取第二哈希值;A third reading module, used for reading a second hash value from a third storage area;
第二执行模块,用于当第二哈希值与第三哈希值匹配,则执行第二系统分区中的第二固件镜像文件。The second execution module is configured to execute the second firmware image file in the second system partition when the second hash value matches the third hash value.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
第三执行模块,用于在执行第一系统分区的过程中,当确定第一固件镜像文件不需要升级而电子设备重启,电子设备重启后,执行第一系统分区中的第一固件镜像文件。The third execution module is used to execute the first firmware image file in the first system partition when it is determined that the first firmware image file does not need to be upgraded and the electronic device is restarted during the execution of the first system partition. After the electronic device is restarted, the first firmware image file in the first system partition is executed.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
第四读取模块,用于从第二存储区域中,读取分区交换标识的数值;A fourth reading module, used for reading a value of a partition exchange identifier from the second storage area;
第五读取模块,用于响应于分区交换标识的数值为第二数值,读取第一存储区域中的第一地址信息;A fifth reading module, configured to read first address information in the first storage area in response to the value of the partition exchange identifier being the second value;
第六读取模块,用于根据第一地址信息,读取第一系统分区的数据;A sixth reading module, used for reading data of the first system partition according to the first address information;
第四计算模块,用于对第一系统分区的数据进行哈希计算,得到第四哈希值;a fourth calculation module, configured to perform hash calculation on the data of the first system partition to obtain a fourth hash value;
第七读取模块,用于从第三存储区域中,读取第一哈希值;A seventh reading module, configured to read the first hash value from the third storage area;
第三执行模块,用于当第一哈希值与第四哈希值匹配,则执行第一系统分区中的第一固件镜像文件。The third execution module is configured to execute the first firmware image file in the first system partition when the first hash value matches the fourth hash value.
在本申请的另一个实施例中,该装置还包括:In another embodiment of the present application, the device further comprises:
提示模块,用于当第一哈希值与第四哈希值不匹配,对电子设备进行错误提示;a prompt module, configured to provide an error prompt to the electronic device when the first hash value does not match the fourth hash value;
第二重启模块,用于重启电子设备。The second restart module is used to restart the electronic device.
本申请实施例配置了两个系统分区,分别为第一系统分区和第二系统分区,虽然第一系统分区和第二系统分区的地址信息不同,但是在电子设备首次开机启动时,会将第一系统分区的第一地址信息写入第一存储区域,该第一存储区域中的第一地址信息实际上为逻辑地址信息,可根据分区交换功能是否开启,来映射不同系统分区的地址信息,进而根据所映射的系统分区的地址信息,对不同系统分区进行访问。例如,当基于第二存储区域内所存储的数据确定分区交换功能开启,则将该第一存储区域中第一地址信息隐藏,并从第一寄存器中读取该第一存储区域中第一地址信息所映射的第二地址信息;当基于第二存储区域内所存储的数据确定分区交换功能未开启,则从第一存储区域中第一地址信息。在后续对固件镜像文件升级时,不管升级版本的固件镜像文件在哪个系统分区,本申请实施例也只是存储且读取第一存储区域中的第一地址信息来访问相应的系统分区。由于在每次执行固件在线升级操作时,并不需要对不同系统分区分别进行管理,因此,降低了管理成本,同时能够避免系统分区选择错误,有效防止设备变砖。The embodiment of the present application is configured with two system partitions, namely the first system partition and the second system partition. Although the address information of the first system partition and the second system partition is different, when the electronic device is powered on for the first time, the first address information of the first system partition will be written into the first storage area. The first address information in the first storage area is actually the logical address information, and the address information of different system partitions can be mapped according to whether the partition exchange function is turned on, and then the different system partitions are accessed according to the address information of the mapped system partition. For example, when the partition exchange function is determined to be turned on based on the data stored in the second storage area, the first address information in the first storage area is hidden, and the second address information mapped by the first address information in the first storage area is read from the first register; when the partition exchange function is determined to be not turned on based on the data stored in the second storage area, the first address information is read from the first storage area. When the firmware image file is subsequently upgraded, no matter which system partition the upgraded version of the firmware image file is in, the embodiment of the present application only stores and reads the first address information in the first storage area to access the corresponding system partition. Since different system partitions do not need to be managed separately each time the firmware online upgrade operation is performed, the management cost is reduced, and the system partition selection error can be avoided at the same time, effectively preventing the device from becoming bricked.
图5示出了本申请一个示例性实施例提供的一种电子设备500的结构框图。通常,电子设备500包括有:处理器501和存储器502。Fig. 5 shows a structural block diagram of an electronic device 500 provided by an exemplary embodiment of the present application. Generally, the electronic device 500 includes: a processor 501 and a memory 502.
处理器501可以采用DSP(Digital Signal Processing,数字信号处理)、FPGA(Field-Programmable Gate Array,现场可编程门阵列)、PLA(Programmable LogicArray,可编程逻辑阵列)中的至少一种硬件形式来实现。处理器501也可以包括主处理器和协处理器,主处理器是用于对在唤醒状态下的数据进行处理的处理器;协处理器是用于对在待机状态下的数据进行处理的低功耗处理器。在一些实施例中,处理器501可以在集成有GPU(Graphics Processing Unit,图像处理器),GPU用于负责显示屏所需要显示的内容的渲染和绘制。一些实施例中,处理器501还可以包括人工智能处理器,该人工智能处理器用于处理有关机器学习的计算操作。The processor 501 can be implemented in at least one of the following hardware forms: DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 501 may also include a main processor and a coprocessor, wherein the main processor is a processor for processing data in an awake state; and the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 501 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 501 may also include an artificial intelligence processor, which is used to process computing operations related to machine learning.
存储器502可以包括一个或多个计算机可读存储介质,该计算机可读存储介质可以是可以是非临时性计算机可读存储介质,例如,所述非临时性计算机可读存储介质可以是CD-ROM(Compact Disc Read-Only Memory,只读光盘)、ROM、RAM(Random AccessMemory,随机存取存储器)、磁带、软盘和光数据存储设备等。该计算机可读存储介质中存储有至少一条计算机程序,该至少一条计算机程序被执行时能够实现上述固件在线升级方法。The memory 502 may include one or more computer-readable storage media, which may be non-temporary computer-readable storage media, for example, the non-temporary computer-readable storage media may be CD-ROM (Compact Disc Read-Only Memory), ROM, RAM (Random Access Memory), magnetic tape, floppy disk and optical data storage device, etc. The computer-readable storage medium stores at least one computer program, which can implement the above-mentioned firmware online upgrade method when executed.
当然,上述电子设备必然还可以包括其他部件,例如输入/输出接口、通信组件等。输入/输出接口为处理器和外围接口模块之间提供接口,上述外围接口模块可以是输出设备、输入设备等。通信组件被配置为便于电子设备和其他设备之间有线或无线方式的通信等。Of course, the above electronic device may also include other components, such as input/output interface, communication component, etc. The input/output interface provides an interface between the processor and the peripheral interface module, and the above peripheral interface module may be an output device, an input device, etc. The communication component is configured to facilitate wired or wireless communication between the electronic device and other devices.
本领域技术人员可以理解,图5中示出的结构并不构成对电子设备500的限定,可以包括比图示更多或更少的组件,或者组合某些组件,或者采用不同的组件布置。Those skilled in the art will appreciate that the structure shown in FIG. 5 does not limit the electronic device 500 , and may include more or fewer components than shown, or combine certain components, or adopt a different component arrangement.
本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有至少一条计算机程序,所述至少一条计算机程序被处理器执行时能够实现上述固件在线升级方法。An embodiment of the present application provides a computer-readable storage medium, in which at least one computer program is stored. When the at least one computer program is executed by a processor, the above-mentioned firmware online upgrade method can be implemented.
本申请实施例提供了一种计算机程序产品,所述计算机程序产品包括计算机程序,所述计算机程序被处理器执行时能够实现上述固件在线升级方法。An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the above-mentioned firmware online upgrade method can be implemented.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, 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 application.
Claims (12)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410131409.0A CN117931251A (en) | 2024-01-30 | 2024-01-30 | Firmware online upgrading method and device, electronic equipment, storage medium and product |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410131409.0A CN117931251A (en) | 2024-01-30 | 2024-01-30 | Firmware online upgrading method and device, electronic equipment, storage medium and product |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117931251A true CN117931251A (en) | 2024-04-26 |
Family
ID=90755548
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410131409.0A Pending CN117931251A (en) | 2024-01-30 | 2024-01-30 | Firmware online upgrading method and device, electronic equipment, storage medium and product |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117931251A (en) |
-
2024
- 2024-01-30 CN CN202410131409.0A patent/CN117931251A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103365696B (en) | BIOS image file acquisition methods and device | |
US6073206A (en) | Method for flashing ESCD and variables into a ROM | |
TWI703499B (en) | Data storage device and method for sharing memory of controller thereof | |
US7694195B2 (en) | System and method for using a memory mapping function to map memory defects | |
CN111581126B (en) | SSD-based log data storage method, SSD-based log data storage device, SSD-based log data storage equipment and SSD-based log data storage medium | |
CN108062253A (en) | The communication means of a kind of kernel state and User space, device and terminal | |
CN105320553A (en) | Method and system for updating network card firmware based on domestic processor platform | |
CN110554998A (en) | hook method, device, terminal and storage medium for replacing function internal instruction | |
CN111008101B (en) | A debugging verification platform and testing method for RISC-V processor system | |
US6925522B2 (en) | Device and method capable of changing codes of micro-controller | |
US8122205B2 (en) | Structured virtual registers for embedded controller devices | |
CN112131171B (en) | The method of dynamically modifying the PCH PCIE root port where the onboard VGA is located | |
CN118760404A (en) | Method for enabling optional read-only memory function, computer device and medium | |
CN117931251A (en) | Firmware online upgrading method and device, electronic equipment, storage medium and product | |
WO2024087607A1 (en) | Flash memory management algorithm debugging method, system and device, and readable storage medium | |
CN117931404A (en) | Multi-application switching method, device, equipment and medium based on FPGA | |
US20240176887A1 (en) | Method for Running Startup Program of Electronic Device, and Electronic Device | |
TWI726524B (en) | Electronic processing devices and memory control methods thereof | |
US7380174B2 (en) | Variable writing through a fixed programming interface | |
CN113805917A (en) | Firmware updating method and device, electronic equipment and storage medium | |
CN113515405B (en) | Address management method and device | |
TWI875076B (en) | Micro-controller and method to execute on-the-air (ota) updated firmware | |
US20250045373A1 (en) | Method and system for writing authentication information | |
CN112261170B (en) | Method, system, equipment and medium for reading MAC address | |
CN118672630A (en) | Application program updating method, device, equipment and medium |
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 |