Firmware upgrading method and device, electronic equipment and computer readable storage medium
By dividing two firmware partitions in electronic devices that do not have A/B Swap functions, using backup partitions to perform sensorless upgrades and switch partition attributes, the problem of high firmware upgrade costs in the existing technology is solved, and sensorless upgrades are achieved Keep the device available.
Patent Information
- Application Number
- CN202411231108.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-02-14
AI Technical Summary
The prior art is difficult to realize the sensingless upgrade of firmware for electronic devices that do not have the A/B Swap function without increasing production costs.
By dividing two firmware partitions in the memory of the electronic device, obtaining the firmware upgrade package, identifying the running partition and the backup partition, using the backup partition for invisible upgrade, and switching partition properties to complete the entire firmware upgrade process.
It realizes sensorless upgrades for electronic devices that do not have A/B Swap functions without increasing production costs, keeping the equipment available, and is suitable for a wide range of electronic devices.
Smart Images

Figure CN119440569A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer technology, and in particular to a firmware upgrade method, device, electronic device, computer-readable storage medium, and computer program product. Background Art
[0002] Firmware refers to the "driver" stored inside an electronic device, which is used to perform the most basic and low-level work in the electronic device, such as providing basic input and output functions, managing the hardware resources of the electronic device, etc. Firmware may also contain the code of the operating system or a specific application. At present, firmware is widely used in various fields. For example, in the automotive field, the microcontroller (MCU) as the core of the automotive electronic control unit (ECU) system needs to rely on firmware to drive it.
[0003] In order to solve the problem of electronic devices being unavailable during firmware upgrades, the solutions provided by related technologies usually implement an A / B Swap function in electronic devices. In the A / B Swap function, the same firmware can run in two partitions, A and B. In this way, the firmware can be upgraded seamlessly through backup. However, due to resource and technical limitations, many electronic devices do not have the A / B Swap function. Summary of the invention
[0004] The present application provides a firmware upgrade method, device, electronic device, computer-readable storage medium and computer program product, which can realize seamless firmware upgrade without increasing production costs.
[0005] The technical solution of this application is implemented as follows:
[0006] The present application provides a firmware upgrade method, which is applied to an electronic device, wherein a memory of the electronic device includes two firmware partitions; the method includes:
[0007] Obtain a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to the two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition;
[0008] Identify, from the two firmware partitions, a first partition whose partition attribute is a running partition and a second partition whose partition attribute is a backup partition;
[0009] Determine the upgrade firmware corresponding to the second partition from the firmware upgrade package, and upgrade the second partition according to the upgrade firmware corresponding to the second partition;
[0010] Switching the partition attribute of the first partition with the partition attribute of the second partition;
[0011] Determine the upgrade firmware corresponding to the first partition from the firmware upgrade package, and perform upgrade processing on the first partition according to the upgrade firmware corresponding to the first partition.
[0012] The present application provides a firmware upgrade device, which is applied to an electronic device, wherein a memory of the electronic device includes two firmware partitions; the device includes:
[0013] An acquisition module, used to acquire a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to the two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition;
[0014] an identification module, used to identify, from the two firmware partitions, a first partition whose partition attribute is a running partition and a second partition whose partition attribute is a backup partition;
[0015] An upgrade module, used to determine the upgrade firmware corresponding to the second partition from the firmware upgrade package, and perform upgrade processing on the second partition according to the upgrade firmware corresponding to the second partition;
[0016] A switching module, used for switching the partition attribute of the first partition with the partition attribute of the second partition;
[0017] The upgrade module is further used to determine the upgrade firmware corresponding to the first partition from the firmware upgrade package, and perform upgrade processing on the first partition according to the upgrade firmware corresponding to the first partition.
[0018] The present application provides an electronic device, including:
[0019] A memory for storing executable instructions;
[0020] The processor is used to implement the firmware upgrade method provided in the present application when executing the executable instructions stored in the memory.
[0021] The present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute and implement the firmware upgrade method provided by the present application.
[0022] The present application provides a computer program product, which includes executable instructions for causing a processor to execute and implement the firmware upgrade method provided by the present application.
[0023] This application has the following beneficial effects:
[0024] The present application obtains a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition; the first partition whose partition attribute is a running partition and the second partition whose partition attribute is a backup partition are identified from the two firmware partitions; the upgrade firmware corresponding to the second partition is determined from the firmware upgrade package, and the second partition is upgraded according to the upgrade firmware corresponding to the second partition; the partition attributes of the first partition and the partition attributes of the second partition are switched; the upgrade firmware corresponding to the first partition is determined from the firmware upgrade package, and the first partition is upgraded according to the upgrade firmware corresponding to the first partition. In this way, the firmware can be upgraded seamlessly through the backup mechanism, and the electronic device can still be kept available during the upgrade process; at the same time, only the upgrade firmware corresponding to the two firmware partitions needs to be prepared, which can be applicable to electronic devices that do not have the A / B Swap function, and will not increase the design and production costs of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] 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 those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0026] Figure 1 It is a schematic diagram of the architecture of the firmware upgrade system provided in an embodiment of the present application;
[0027] Figure 2 is a structural diagram of a microcontroller provided in an embodiment of the present application;
[0028] Figure 3A It is a first flow chart of the firmware upgrade method provided in an embodiment of the present application;
[0029] Figure 3B It is a second flow chart of the firmware upgrade method provided in an embodiment of the present application;
[0030] Figure 4 3 is a schematic diagram of a third process of the firmware upgrade method provided in an embodiment of the present application;
[0031] Figure 5 It is a schematic diagram of the partition address provided in the embodiment of the present application;
[0032] Figure 6 It is a flowchart of code compilation and code linking provided by an embodiment of the present application;
[0033] Figure 7This is a flowchart of a successful upgrade provided by an embodiment of the present application;
[0034] Figure 8 It is a flowchart of an upgrade failure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0036] In the following description, reference is made to "some embodiments", which describes a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, reference is made to the term "multiple" to mean at least two.
[0037] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0038] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0039] The embodiments of the present application provide a firmware upgrade method, device, electronic device, computer-readable storage medium, and computer program product, which can realize the seamless upgrade of firmware without increasing production costs. The following describes an exemplary application of the electronic device provided by the embodiments of the present application. The electronic device provided by the embodiments of the present application can be implemented as various types of terminal devices, such as chip-level terminal devices.
[0040] See also Figure 1 , Figure 1 It is an architectural diagram of the firmware upgrade system 100 provided in an embodiment of the present application, and is illustrated by taking the electronic device as a microcontroller 400 in a vehicle 300 as an example, wherein the vehicle 300 is connected to the server 200 via a network 500, wherein the network 500 may be a wide area network or a local area network, or a combination of the two.
[0041] In some embodiments, the memory of the microcontroller 400 includes two firmware partitions, wherein each firmware partition is used to store firmware. The developer can upload the upgrade firmware corresponding to the two firmware partitions to the server 200 in the form of a firmware upgrade package. The microcontroller 400 queries the server 200 regularly or under specific trigger conditions whether there is an upgrade firmware. For example, the microcontroller 400 initiates a query request to the server 200 according to the version number of the firmware stored in the firmware partition, and receives a response from the server 200 whether there is a new version of the upgrade firmware available. When the microcontroller 400 finds that the server 200 stores the upgrade firmware, it obtains the firmware upgrade package from the server 200. The microcontroller 400 identifies the first partition whose partition attribute is the running partition and the second partition whose partition attribute is the backup partition from the two firmware partitions; determines the upgrade firmware corresponding to the second partition from the firmware upgrade package, and upgrades the second partition according to the upgrade firmware corresponding to the second partition; switches the partition attribute of the first partition with the partition attribute of the second partition; determines the upgrade firmware corresponding to the first partition from the firmware upgrade package, and upgrades the first partition according to the upgrade firmware corresponding to the first partition. Through the above method, the microcontroller 400 can still be kept available during the firmware upgrade process, that is, the normal operation of the microcontroller 400 will not be affected; at the same time, the microcontroller 400 is not required to have an A / B Swap function, and the application range is wide.
[0042] It is worth mentioning that Figure 1 The Over The Air (OTA) upgrade method is taken as an example for explanation, but this does not constitute a limitation on the embodiments of the present application, that is, the microcontroller 400 can obtain the firmware upgrade package through other methods, such as through wired communication (such as firmware transmission through a USB flash drive connection).
[0043] In some embodiments, the electronic device can implement the firmware upgrade method provided in the embodiments of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, Application), that is, a program that needs to be installed in the operating system to run; it can also be a small program, that is, a program that can be run only by downloading it to a browser environment; it can also be a small program that can be embedded in any APP, and the small program can be controlled to run or closed by the user. In short, the above-mentioned computer program can be any form of application, module or plug-in.
[0044] The electronic device provided in the embodiment of the present application is Figure 1 The microcontroller 400 shown is used as an example. Figure 2 , Figure 2 is a schematic diagram of the structure of the microcontroller 400 provided in an embodiment of the present application, Figure 2 The microcontroller 400 shown includes: at least one processor 410, a memory 450 and at least one network interface 420. The various components in the microcontroller 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not described in detail. Figure 2 Various buses are labeled as bus system 440 .
[0045] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0046] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0047] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0048] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0049] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0050] A network communication module 452, used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0051] In some embodiments, the firmware upgrade device provided in the embodiments of the present application can be implemented in a software manner. Figure 2 The firmware upgrade device 455 stored in the memory 450 is shown, which can be software in the form of a program and a plug-in, etc., and includes the following software modules: an acquisition module 4551, an identification module 4552, an upgrade module 4553, and a switching module 4554. These modules are logical, and therefore can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0052] The firmware upgrade method provided in the embodiment of the present application will be described in conjunction with the exemplary application and implementation of the electronic device provided in the embodiment of the present application.
[0053] See also Figure 3A , Figure 3A is a flowchart of a firmware upgrade method provided in an embodiment of the present application. The firmware upgrade method provided in an embodiment of the present application can be implemented by an electronic device, such as a terminal device, and combined with Figure 3A The steps shown are explained.
[0054] In step 101, a firmware upgrade package is obtained; wherein the firmware upgrade package includes upgrade firmware corresponding to two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition.
[0055] Here, the memory of the electronic device is divided into two firmware partitions, each of which is used to store firmware.
[0056] During the firmware upgrade process, first, a firmware upgrade package is obtained, wherein the firmware upgrade package includes upgrade firmware corresponding to two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition. It is worth noting that the link address of the link file of the upgrade firmware is used to define the address at which the upgrade firmware should be loaded (run), and for the upgrade firmware corresponding to each firmware partition, since the link address of the link file of the upgrade firmware points to the address of the firmware partition, the upgrade firmware can only be run in the firmware partition, and cannot be run in other firmware partitions.
[0057] It is worth noting that for each firmware partition, the version number of the corresponding upgrade firmware is higher than the version number of the firmware stored in the firmware partition. In addition, the upgrade firmware corresponding to the two firmware partitions are usually released uniformly, so the upgrade firmware corresponding to the two firmware partitions usually have the same version number.
[0058] In some embodiments, the two firmware partitions are of the same size. Firmware partitions of the same size can make firmware management easier; when planning storage space, it is easier to determine the size of each firmware partition according to needs, thereby helping to optimize the use of storage space and avoid storage space waste.
[0059] In some embodiments, the upgrade firmware corresponding to any firmware partition is obtained by compiling the upgrade firmware code and linking the code compilation result according to the target link file; wherein the link address of the target link file points to the address of any firmware partition.
[0060] Here, the firmware development process is described. Taking the second partition as an example, based on the developed upgrade firmware code, the upgrade firmware code is first compiled, and then the code compilation result is linked according to the target link file to obtain the upgrade firmware corresponding to the second partition, wherein the link address of the target link file points to the address of the second partition (referring to the address of the second partition in the memory). In this way, it is ensured that the upgrade firmware corresponding to each firmware partition only supports running in the firmware partition.
[0061] In step 102, a first partition whose partition attribute is a running partition and a second partition whose partition attribute is a backup partition are identified from two firmware partitions.
[0062] Here, the first partition whose current partition attribute is a running partition and the second partition whose partition attribute is a backup partition are identified, that is, the first partition is currently running, while the second partition is currently not running.
[0063] In step 103, the upgrade firmware corresponding to the second partition is determined from the firmware upgrade package, and the second partition is upgraded according to the upgrade firmware corresponding to the second partition.
[0064] Here, the upgrade firmware corresponding to the second partition is determined from the firmware upgrade package, and the second partition is upgraded according to the upgrade firmware corresponding to the second partition, for example, the firmware stored in the second partition is overwritten according to the upgrade firmware corresponding to the second partition. Since the partition attribute of the second partition is a backup partition, the upgrade process of the second partition will not affect the normal operation of the electronic device, and an imperceptible firmware upgrade can be achieved.
[0065] In step 104, the partition attributes of the first partition and the partition attributes of the second partition are switched.
[0066] Here, the partition attributes of the first partition and the partition attributes of the second partition are switched, that is, the partition attributes of the first partition are updated from the running partition to the backup partition, and the partition attributes of the second partition are updated from the backup partition to the running partition.
[0067] In some embodiments, the above-mentioned switching of the partition attributes of the first partition and the partition attributes of the second partition can be achieved in the following manner: when the second partition is upgraded successfully, the partition attributes of the first partition and the partition attributes of the second partition are switched; after the second partition is upgraded according to the upgraded firmware corresponding to the second partition, the firmware upgrade method also includes: when the upgrade of the second partition fails, the partition attributes of the first partition and the partition attributes of the second partition are kept unchanged, and an upgrade error message is output.
[0068] Here, when the second partition is upgraded successfully, the partition attributes of the first partition and the partition attributes of the second partition are switched so as to upgrade the first partition; when the second partition upgrade fails, the second partition still stores the unupgraded firmware (or the firmware of an unknown version). At this time, the partition attributes of the first partition and the partition attributes of the second partition are kept unchanged to ensure the stability of the firmware operation, and the upgrade error information is output at the same time. For example, the electronic device can display the upgrade error information, or send the upgrade error information to other electronic devices for display (for example, the vehicle's MCU sends the upgrade error information to the vehicle system for display). By outputting the upgrade error information, relevant users can quickly understand the reasons for the upgrade failure, so as to take appropriate measures to solve the problem, such as taking manual upgrade measures, which is crucial for troubleshooting and subsequent maintenance.
[0069] In some embodiments, after the second partition is upgraded according to the upgrade firmware corresponding to the second partition, the firmware upgrade method also includes: when the upgrade of the second partition fails, re-upgrading the second partition according to the upgrade firmware corresponding to the second partition; when the number of upgrade failures of the second partition reaches a threshold number, keeping the partition attributes of the first partition and the partition attributes of the second partition unchanged, and outputting an upgrade error message.
[0070] Here, when the upgrade of the second partition fails, the second partition is upgraded again according to the upgrade firmware corresponding to the second partition until the number of upgrade failures of the second partition reaches the number threshold, where the number threshold can be set according to the needs of the actual application scenario, such as 3 times. When the number of upgrade failures of the second partition reaches the number threshold, the partition attributes of the first partition and the partition attributes of the second partition are kept unchanged, and the upgrade error information is output.
[0071] The above method implements a retry mechanism, which can automatically retry the upgrade process when encountering temporary errors or interruptions, thereby improving the success rate of the upgrade; when the number of upgrade failures reaches a threshold, further upgrade attempts are stopped and the partition properties of the current firmware partitions are maintained unchanged. In this way, excessive consumption of computing resources or potential instability caused by infinite retries can be avoided, ensuring the stable operation of the electronic device.
[0072] In some embodiments, after the second partition is upgraded according to the upgraded firmware corresponding to the second partition, the firmware upgrade method also includes: determining the version number of the firmware stored in the second partition; when the version number of the firmware stored in the second partition is the same as the version number of the upgraded firmware corresponding to the second partition, determining that the upgrade of the second partition is successful; when the version number of the firmware stored in the second partition is different from the version number of the upgraded firmware corresponding to the second partition, determining that the upgrade of the second partition has failed.
[0073] Here, after the second partition is upgraded according to the upgrade firmware corresponding to the second partition, since the version number of the upgrade firmware corresponding to the second partition is known, the version number of the firmware stored in the second partition can be determined, and the version number of the firmware stored in the second partition is compared with the version number of the upgrade firmware corresponding to the second partition. When the version number of the firmware stored in the second partition is the same as the version number of the upgrade firmware corresponding to the second partition, it proves that the second partition stores the upgrade firmware, so it is determined that the second partition has been successfully upgraded; when the version number of the firmware stored in the second partition is different from the version number of the upgrade firmware corresponding to the second partition, it proves that the second partition does not store the upgrade firmware, so it is determined that the upgrade of the second partition has failed. The above method can accurately and easily verify whether the second partition has been successfully upgraded by comparing the version numbers.
[0074] In step 105, the upgrade firmware corresponding to the first partition is determined from the firmware upgrade package, and the first partition is upgraded according to the upgrade firmware corresponding to the first partition.
[0075] Here, the upgrade firmware corresponding to the first partition is determined from the firmware upgrade package, and the first partition is upgraded according to the upgrade firmware corresponding to the first partition. At this time, the partition attribute of the first partition is a backup partition. Therefore, the upgrade process of the first partition will not affect the normal operation of the electronic device, and an imperceptible firmware upgrade can be achieved. Through the above method, the consistency of the firmware versions of the first partition and the second partition can be guaranteed, and a comprehensive firmware upgrade can be achieved; if there is a problem with the upgrade firmware in the second partition or the second partition itself fails, the upgrade firmware in the first partition can be run to improve fault tolerance.
[0076] It is worth noting that after the first partition is upgraded according to the upgraded firmware corresponding to the first partition, since both the first partition and the second partition store the upgraded firmware, there is no need to switch the partition attributes of the first partition with the partition attributes of the second partition, thereby avoiding unnecessary waste of resources caused by frequent switching of partition attributes.
[0077] In some embodiments, after the first partition is upgraded according to the upgrade firmware corresponding to the first partition, the firmware upgrade method further includes: when the upgrade of the first partition fails, outputting upgrade error information.
[0078] In some embodiments, after the first partition is upgraded according to the upgrade firmware corresponding to the first partition, the firmware upgrade method also includes: when the upgrade of the first partition fails, re-upgrading the first partition according to the upgrade firmware corresponding to the first partition; when the number of upgrade failures of the first partition reaches a threshold number, outputting an upgrade error message.
[0079] In some embodiments, after the first partition is upgraded according to the upgraded firmware corresponding to the first partition, the firmware upgrade method also includes: determining the version number of the firmware stored in the first partition; when the version number of the firmware stored in the first partition is the same as the version number of the upgraded firmware corresponding to the first partition, determining that the first partition upgrade is successful; when the version number of the firmware stored in the first partition is different from the version number of the upgraded firmware corresponding to the first partition, determining that the first partition upgrade has failed.
[0080] In some embodiments, before obtaining the firmware upgrade package, the firmware upgrade method also includes: initiating a query request to the server according to the version numbers of the firmware stored in the two firmware partitions; the above-mentioned acquisition of the firmware upgrade package can be achieved in the following way: when it is queried that the server stores an upgrade firmware with a higher version number, the firmware upgrade package is obtained from the server.
[0081] Here, the electronic device is taken as a terminal device, and the OTA upgrade method is used as an example for explanation. The terminal device can query the server whether there is an upgrade firmware regularly or under specific trigger conditions. For example, the terminal device initiates a query request to the server based on the version number of the firmware stored in the firmware partition (the version numbers of the firmware stored in the two firmware partitions are usually the same), and receives a response from the server whether there is a new version of the upgrade firmware available. When the terminal device receives a response from the server that a new version of the upgrade firmware is available (that is, the terminal device queries the upgrade firmware release), the terminal device obtains a firmware upgrade package from the server (including the upgrade firmware corresponding to the two firmware partitions, respectively) for upgrading the two firmware partitions. In the above manner, the terminal device can obtain all required upgrade firmware at one time, which helps to reduce the communication overhead between the terminal device and the server.
[0082] like Figure 3AAs shown, the embodiment of the present application obtains a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition; the first partition whose partition attribute is a running partition and the second partition whose partition attribute is a backup partition are identified from the two firmware partitions; the upgrade firmware corresponding to the second partition is determined from the firmware upgrade package, and the second partition is upgraded according to the upgrade firmware corresponding to the second partition; the partition attributes of the first partition and the partition attributes of the second partition are switched; the upgrade firmware corresponding to the first partition is determined from the firmware upgrade package, and the first partition is upgraded according to the upgrade firmware corresponding to the first partition. In this way, the firmware can be upgraded seamlessly through the backup mechanism, and the electronic device can still be kept available during the upgrade process; at the same time, only the upgrade firmware corresponding to the two firmware partitions needs to be prepared, which can be applied to electronic devices that do not have the A / B Swap function, and will not increase the design and production costs of the electronic device.
[0083] In some embodiments, see Figure 3B , Figure 3B is a flowchart of a firmware upgrade method provided in an embodiment of the present application. Figure 3A The illustrated step 104 may be updated to step 201 .
[0084] In step 201, the partition attributes of the first partition and the partition attributes of the second partition are switched by the re-running boot loader.
[0085] Here, in addition to being divided into two firmware partitions, the memory of the electronic device is also divided into a boot loader (BootLoader) partition. The boot loader partition is used to store the boot loader program. The boot loader program is usually the first section of code executed by the electronic device after power-on, and is used to implement functions such as hardware initialization and operating system loading. In an embodiment of the present application, the boot loader program is used to run the firmware in the running partition.
[0086] After the second partition is upgraded according to the upgraded firmware corresponding to the second partition, the boot loader can be re-run immediately, or, considering that the firmware in the first partition has been run, no operation can be performed temporarily, waiting for the boot loader to be re-run (i.e., waiting for the electronic device to be restarted) to ensure the stability of the operation of the electronic device. When the boot loader is re-run, the partition attributes of the first partition and the partition attributes of the second partition are switched by the re-running boot loader.
[0087] exist Figure 3B In the embodiment, step 202 may be further executed after step 201, in which the upgraded firmware in the second partition is run by the re-running boot loader.
[0088] Here, the partition attribute of the second partition is a running partition. In addition to being used to switch the partition attributes of the first partition with the partition attributes of the second partition, the re-running boot loader is also used to run the upgraded firmware in the second partition to achieve normal operation of the electronic device.
[0089] like Figure 3B As shown, when the boot loader is re-run, the embodiment of the present application switches the partition attributes of the first partition with the partition attributes of the second partition through the re-running boot loader, so as to upgrade the first partition; at the same time, the upgraded firmware in the second partition is run through the re-running boot loader to realize the normal operation of the electronic device. In summary, the embodiment of the present application can switch the running firmware from the non-upgraded firmware to the upgraded firmware without the user's perception.
[0090] The following will describe an exemplary application of the embodiment of the present application in a practical application scenario. For ease of understanding, the electronic device is described by taking the MCU in a vehicle as an example.
[0091] As the core component of the vehicle ECU system, the demand for firmware upgrades is increasing. In the solutions provided by related technologies, to achieve seamless firmware upgrades in MCU, the internal memory Program Flash (hereinafter referred to as PFLASH) of the MCU is often required to have the A / B Swap function. However, due to resource and technical limitations, most low-cost MCUs do not have the A / B Swap function and cannot achieve seamless firmware upgrades.
[0092] In view of this, the embodiment of the present application provides a firmware upgrade method, which enables an MCU that does not have the A / B Swap function to achieve a firmware upgrade without a sense of touch. As an example, the embodiment of the present application provides the following Figure 4 The firmware upgrade method shown in the figure is a flowchart, which combines Figure 4 , explained in step form.
[0093] Step 1) PFLASH partition: Divide the PFLASH inside the MCU into a BootLoader partition and two APP_A / APP_B partitions of equal size. The APP_A / APP_B partitions are parallel partitions, such as Figure 5 As shown, the address of the APP_A partition is 0x00040000~0x0011FFFF, and the address of the APP_B partition is 0x00120000~0x001FFFFF.
[0094] Step 2) Compile and process: Figure 6As shown, for the latest version of the upgrade firmware code, the upgrade firmware code is first compiled, and then the code is linked according to the dual link file to obtain A_PACK and B_PACK respectively. A_PACK represents the upgrade firmware corresponding to the APP_A partition, and B_PACK represents the upgrade firmware corresponding to the APP_B partition. Among them, the link address of the link file LD_A corresponding to A_PACK points to the address of the APP_A partition, that is, A_PACK can only run in the APP_A partition; the link address of the link file LD_B corresponding to B_PACK points to the address of the APP_B partition, that is, B_PACK can only run in the APP_B partition. When releasing the upgrade firmware, A_PACK and B_PACK are released at the same time.
[0095] Step 3) Partition upgrade: When the MCU triggers an upgrade, it first identifies the current backup partition of the MCU (APP_A partition / APP_B partition), and upgrades the backup partition according to the upgrade firmware (A_PACK / B_PACK) corresponding to the backup partition, that is, the firmware originally stored in the backup partition is overwritten according to the upgrade firmware corresponding to the backup partition. Figure 7 In the figure, taking the backup partition as the APP_B partition as an example, the firmware B_PACK V1.0 originally stored in the APP_B partition and the upgraded firmware B_PACK V1.1 corresponding to the APP_B partition are shown.
[0096] Step 4) Partition switching: After the backup partition is successfully upgraded, the MCU is reset and the BootLoader program is executed. The original backup partition is switched to the running partition through the BootLoader program, and the original running partition is switched to the backup partition, and the upgraded firmware in the new running partition is run. Figure 7 shown.
[0097] If the backup partition upgrade fails, the running partition and the backup partition remain unchanged, and the corresponding error code (corresponding to the upgrade error information above) is reported. Figure 8 As shown, Figure 8 The firmware version stored in the APP_B partition is unknown, for example, it may be B_PACK V1.0.
[0098] Step 5) Partition upgrade: After the backup partition is successfully upgraded and the partition is successfully switched, the new backup partition is upgraded according to the upgrade firmware corresponding to the new backup partition. Figure 7 As shown, the new backup partition is the APP_A partition, and the upgrade firmware corresponding to the new backup partition is A_PACK V1.1.
[0099] The embodiments of the present application can at least achieve the following technical effects:
[0100] 1) After compilation, use the dual link file (LD_A / LD_B) to generate two upgrade firmware (A_PACK / B_PACK), corresponding to two firmware partitions (APP_A / APP_B) respectively, to realize the parallel partitioning function.
[0101] 2) Based on parallel partitioning, the backup partition can be upgraded without interrupting the operation of other functions of the APP (referring to the APP running based on firmware in the MCU), realizing a seamless upgrade function.
[0102] The following is a description of an exemplary structure of the firmware upgrade device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, Figure 2 As shown, the software modules stored in the firmware upgrade device 455 of the memory 450 may include: an acquisition module 4551, used to acquire a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition; an identification module 4552, used to identify the first partition whose partition attribute is a running partition and the second partition whose partition attribute is a backup partition from the two firmware partitions; an upgrade module 4553, used to determine the upgrade firmware corresponding to the second partition from the firmware upgrade package, and upgrade the second partition according to the upgrade firmware corresponding to the second partition; a switching module 4554, used to switch the partition attributes of the first partition with the partition attributes of the second partition; the upgrade module 4553 is also used to determine the upgrade firmware corresponding to the first partition from the firmware upgrade package, and upgrade the first partition according to the upgrade firmware corresponding to the first partition.
[0103] In some embodiments, the memory of the electronic device also includes a boot loader partition, which is used to store a boot loader program; the switching module 4554 is also used to: switch the partition attributes of the first partition with the partition attributes of the second partition by re-running the boot loader program; the firmware upgrade device 455 also includes a running module, which is used to: run the upgraded firmware in the second partition by re-running the boot loader program.
[0104] In some embodiments, the switching module 4554 is also used to: when the second partition is upgraded successfully, switch the partition attributes of the first partition with the partition attributes of the second partition; the firmware upgrade device 455 also includes an error module, which is used to: when the second partition upgrade fails, keep the partition attributes of the first partition and the partition attributes of the second partition unchanged, and output upgrade error information.
[0105] In some embodiments, the upgrade module 4553 is also used to: determine the version number of the firmware stored in the second partition; when the version number of the firmware stored in the second partition is the same as the version number of the upgrade firmware corresponding to the second partition, determine that the upgrade of the second partition is successful; when the version number of the firmware stored in the second partition is different from the version number of the upgrade firmware corresponding to the second partition, determine that the upgrade of the second partition has failed.
[0106] In some embodiments, the acquisition module 4551 is further used to: initiate a query request to the server according to the version numbers of the firmware stored in the two firmware partitions; and when it is found that the server stores an upgraded firmware with a higher version number, obtain a firmware upgrade package from the server.
[0107] In some embodiments, the upgrade firmware corresponding to any firmware partition is obtained by compiling the upgrade firmware code and linking the code compilation result according to the target link file; wherein the link address of the target link file points to the address of any firmware partition.
[0108] The embodiment of the present application provides a computer program product or a computer program, which includes executable instructions stored in a computer-readable storage medium. The processor of the electronic device reads the executable instructions from the computer-readable storage medium, and the processor executes the executable instructions, so that the electronic device executes the firmware upgrade method described in the embodiment of the present application.
[0109] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the firmware upgrade method provided in the embodiment of the present application.
[0110] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.
[0111] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0112] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0113] As an example, the executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0114] The above are only embodiments of the present application and are not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A firmware upgrade method, characterized in that: Applied to an electronic device, the memory of the electronic device includes two firmware partitions; the method includes: Obtain a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to the two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition; Identify, from the two firmware partitions, a first partition whose partition attribute is a running partition and a second partition whose partition attribute is a backup partition; Determine the upgrade firmware corresponding to the second partition from the firmware upgrade package, and upgrade the second partition according to the upgrade firmware corresponding to the second partition; Switching the partition attribute of the first partition with the partition attribute of the second partition; Determine the upgrade firmware corresponding to the first partition from the firmware upgrade package, and perform upgrade processing on the first partition according to the upgrade firmware corresponding to the first partition.
2. The method according to claim 1, characterized in that The memory of the electronic device further includes a boot loading partition, and the boot loading partition is used to store a boot loading program; the switching process of the partition attribute of the first partition and the partition attribute of the second partition includes: Switching the partition attribute of the first partition with the partition attribute of the second partition by re-running the boot loader; After switching the partition attribute of the first partition with the partition attribute of the second partition, the method further includes: The upgraded firmware in the second partition is run by the re-running boot loader.
3. The method according to claim 1, characterized in that The switching process of the partition attribute of the first partition and the partition attribute of the second partition includes: When the second partition is successfully upgraded, switching the partition attributes of the first partition with the partition attributes of the second partition; After the second partition is upgraded according to the upgrade firmware corresponding to the second partition, the method further includes: When the upgrade of the second partition fails, the partition attributes of the first partition and the partition attributes of the second partition are kept unchanged, and upgrade error information is output.
4. The method according to claim 3, characterized in that After the second partition is upgraded according to the upgrade firmware corresponding to the second partition, the method further includes: Determine a version number of the firmware stored in the second partition; When the version number of the firmware stored in the second partition is the same as the version number of the upgraded firmware corresponding to the second partition, determining that the second partition is upgraded successfully; When the version number of the firmware stored in the second partition is different from the version number of the upgrade firmware corresponding to the second partition, it is determined that the upgrade of the second partition fails.
5. The method according to claim 1, characterized in that Before obtaining the firmware upgrade package, the method further includes: Initiate a query request to the server according to the version numbers of the firmware stored in the two firmware partitions; The step of obtaining the firmware upgrade package includes: When it is found that the server stores upgraded firmware with a higher version number, the firmware upgrade package is obtained from the server.
6. The method according to claim 1, characterized in that The upgrade firmware corresponding to any firmware partition is obtained by compiling the upgrade firmware code and linking the code compilation result according to the target link file; wherein the link address of the target link file points to the address of the any firmware partition.
7. A firmware upgrade device, characterized in that: Applied to an electronic device, the memory of the electronic device includes two firmware partitions; the device includes: An acquisition module, used to acquire a firmware upgrade package; wherein the firmware upgrade package includes upgrade firmware corresponding to the two firmware partitions respectively, and the link address of the link file of the upgrade firmware corresponding to each firmware partition points to the address of the firmware partition; an identification module, used to identify, from the two firmware partitions, a first partition whose partition attribute is a running partition and a second partition whose partition attribute is a backup partition; An upgrade module, used to determine the upgrade firmware corresponding to the second partition from the firmware upgrade package, and perform upgrade processing on the second partition according to the upgrade firmware corresponding to the second partition; A switching module, used for switching the partition attribute of the first partition with the partition attribute of the second partition; The upgrade module is further used to determine the upgrade firmware corresponding to the first partition from the firmware upgrade package, and perform upgrade processing on the first partition according to the upgrade firmware corresponding to the first partition.
8. An electronic device, characterized in that: include: A memory for storing executable instructions; A processor, configured to implement the method according to any one of claims 1 to 6 when executing the executable instructions stored in the memory.
9. A computer-readable storage medium, characterized in that: Executable instructions are stored, and when executed by a processor, the method described in any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that The method comprises executable instructions for implementing the method according to any one of claims 1 to 6 when executed by a processor.
Citation Information
Cited By
Firmware management method and device, equipment, storage medium and program product
CN120780296A