Firmware program updating method and system, storage medium and microprocessor
By dividing the memory into regions and utilizing the BootLoader program, seamless firmware updates are achieved while the device is running continuously, solving the device downtime problem caused by traditional update methods and ensuring the continuity and reliability of the device.
Patent Information
- Application Number
- CN202411075299.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-11-15
AI Technical Summary
Traditional firmware update methods require interrupting device operation, causing the device to malfunction and affecting its availability and continuity, especially for critical devices and systems that operate continuously for extended periods.
By dividing the memory into independent regions, loading the new firmware into the idle region, and switching to execute the new firmware when the old firmware is idle, the BootLoader program coordinates the upgrade process, achieving a smooth update without restarting or resetting.
It enables secure and seamless firmware updates while the equipment is running continuously, avoiding equipment downtime and ensuring the continuity and reliability of equipment operation.
Smart Images

Figure CN118963803A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic technology, and in particular to a firmware program updating method, system, storage medium and microprocessor. Background Art
[0002] In the fields of industrial control systems, IoT devices, etc., firmware programs on embedded devices usually need to be updated according to functional iterations or problem fixes. However, traditional firmware program update methods often require interrupting the normal operation of the device, restarting or resetting the device, and then loading and executing the new firmware program. This firmware update mode will cause the device to not work properly for a certain period of time, affecting the availability and continuity of the device. In particular, for some critical devices and systems that require long-term continuous operation and incur high costs if the operation is interrupted, frequent firmware updates will significantly affect their performance and reliability. Summary of the invention
[0003] The present application provides a firmware program update method, system, storage medium and microprocessor, which can dynamically and smoothly update the firmware program of a device while the device is continuously running, without restarting or resetting the device.
[0004] In a first aspect of the present application, the present application provides a firmware program update method, comprising: Acquire a new firmware program, and load the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state; Writing firmware parameters of the new firmware program into a swap area of the memory; When the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed, the execution of the new firmware program and the corresponding firmware parameters of the first area is switched, and the execution of the old firmware program of the second area is stopped.
[0005] Optionally, the memory includes a non-volatile memory and a volatile memory, the non-volatile memory includes the first area and the second area, the volatile memory includes the exchange area and a firmware program running area, and the firmware program running area is used to provide an execution environment for the firmware program in an execution state.
[0006] Optionally, the exchange area includes a first exchange sub-area and a second exchange sub-area, the firmware parameters include an interrupt vector table, global variables, and static variables, and writing the firmware parameters of the new firmware program into the exchange area of the memory includes: Writing the interrupt vector table of the new firmware program into the first exchange sub-area; The global variables and static variables of the new firmware program are written into the second exchange sub-area.
[0007] Optionally, the storage addresses of the global variables and the static variables in the second exchange sub-area are the same as the storage addresses of the global variables and the static variables of the old firmware program in the firmware program running area.
[0008] Optionally, the switching to execute the new firmware program and corresponding firmware parameters of the first area includes: Copying the interrupt vector table of the first exchange sub-area to the interrupt vector table storage location of the new firmware program running area; Copying the contents of the global variables and static variables of the second exchange sub-area to corresponding storage locations of the new firmware program running area; The stack pointer is initialized and the new firmware program is executed.
[0009] Optionally, after writing the firmware parameters of the new firmware program into the exchange area of the memory, the method further includes: Setting a first flag bit in the first area, the first flag bit being used to detect the loading process of the new firmware program; A second flag bit is set in the second area, and the second flag bit is used to detect that the interrupt of the old firmware program is in an idle state.
[0010] Optionally, the method further includes: When the interrupt of the old firmware program is in an idle state and the loading of the new firmware program is completed, disabling global interrupts; After switching to execute the new firmware program and the corresponding firmware parameters of the first area and stopping the execution of the old firmware program of the second area, the global interrupt is enabled.
[0011] In a second aspect of the present application, a firmware program update system is provided, comprising: A firmware program distribution module, used for acquiring a new firmware program and loading the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state; A firmware parameter storage module, used for writing the firmware parameters of the new firmware program into the exchange area of the memory; The firmware program update module is used for the new firmware program allocation module, which is used to switch to execute the new firmware program and corresponding firmware parameters of the first area and stop executing the old firmware program of the second area when the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed.
[0012] In a third aspect of the present application, a computer storage medium is provided, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above method steps.
[0013] In a fourth aspect of the present application, a microprocessor is provided, comprising: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0014] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: By loading the new firmware program into the first free area in the memory, and retaining the old firmware program in the execution state in the second area, and writing the firmware parameters of the new firmware program into the exchange area of the memory, the preparation work for loading the new firmware program is completed without interrupting the execution of the old firmware program. Furthermore, when the interrupt of the old firmware program is in an idle state, by switching to execute the new firmware program in the first area and its corresponding firmware parameters, and stopping the execution of the old firmware program in the second area, the switching between the new and old firmware programs is completed smoothly and quickly while the system continues to run.
[0015] Compared with the prior art, the firmware update method provided in the present application does not require restarting or resetting the device. By rationally utilizing different areas of the memory, it realizes the coexistence and parameter exchange of new and old firmware programs, and completes smooth migration by switching and executing programs in different areas, effectively avoiding the equipment shutdown problem caused by traditional firmware updates and ensuring the continuity of equipment operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a flowchart of a firmware program update method provided in an embodiment of the present application; Figure 2 It is a schematic diagram of a memory structure provided by an embodiment of the present application; Figure 3 It is a structural diagram of a firmware program update system provided by an embodiment of the present application; Figure 4 It is a schematic diagram of the structure of a microprocessor disclosed in an embodiment of the present application.
[0017] Description of the reference numerals: 400, microprocessor; 401, processor; 402, communication bus; 403, user interface; 404, network interface; 405, memory. DETAILED DESCRIPTION
[0018] In order to enable technicians in this field to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.
[0019] In the description of the embodiments of the present application, words such as "for example" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "for example" or "for example" is intended to present related concepts in a specific way.
[0020] In the description of the embodiments of the present application, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0021] This application provides a firmware program update method, referring to Figure 1 , Figure 1 A flowchart of a firmware program update method provided in an embodiment of the present application is shown in FIG. S101 to S103 are included, and the above steps are as follows: S101: Obtain a new firmware program, and load the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state.
[0022] Firmware is a type of software embedded in a hardware device. It is stored in memory and is used to control the basic functions and operations of the device. Unlike general application software, firmware is usually closely related to a specific hardware platform and is automatically loaded and run when the device is powered on.
[0023] Furthermore, the new firmware program refers to a new set of software codes used to update or upgrade the functions of the device. In the embodiment of the present application, the new firmware program can be understood as a program file received through an external communication interface that has not yet been loaded and run, which is used to replace the old firmware program running in the device, thereby updating and optimizing the device functions. The new firmware program usually includes content such as performance improvements, bug fixes, and new function additions. During the upgrade process, the new firmware program will be temporarily stored in a free area of the device memory, waiting for the right time to switch to operation to ensure the continuity and reliability of the device functions.
[0024] The firmware program update method proposed in this application mainly stores the new and old versions of the firmware program by dividing independent areas in the memory, and uses the BootLoader program to coordinate and execute the upgrade process, so as to achieve a smooth upgrade of the device to the new version of the firmware program without stopping or interrupting. Among them, the BootLoader program is a special firmware program that is responsible for automatically loading and starting the main program from the memory after the system is powered on or reset. BootLoader is usually independent of the main program firmware and runs in a dedicated code area.
[0025] Specifically, the system needs to establish a data connection with a host device (such as a host computer, server, etc.) through an existing communication interface (such as SCI / UART serial port or CAN bus, etc.). After the connection is established, the host can start transmitting the new version of the firmware program file to the system in the form of a data stream.
[0026] When the system receives the new firmware program data, it needs to store it in real time in the inactive application area of the pre-divided memory, that is, the first area. It is called the inactive area because the old firmware program code currently running in the system is isolated and stored in another independent second area.
[0027] It is worth noting that the firmware program data reception and storage process cannot interrupt or affect the system's currently executing functions, so it must be run in the background in a concurrent manner. In other words, the system needs to perform the original control task while receiving and storing the transmitted new firmware program data.
[0028] This concurrent execution process will significantly increase the complexity and real-time performance requirements of the system, and put great pressure on hardware resources. At the same time, due to the bandwidth limitation of the communication interface, the transmission process of the firmware program file is usually slow, so the entire receiving and storing process will last for a certain period of time, during which the system needs to ensure the normal operation of both tasks under limited resources.
[0029] Based on the above embodiment, as an optional embodiment, please refer to Figure 2, Figure 2 A schematic diagram of a memory structure is provided for an embodiment of the present application. In the embodiment of the present application, the memory can be understood as consisting of two parts: a non-volatile memory and a volatile memory, which are used for different functions respectively.
[0030] For example, non-volatile memory can generally be Flash, EEPROM, EPROM, disk, etc. Their characteristic is that they can retain stored data and program code after power failure. Volatile memory generally refers to RAM, registers, etc. They can read and write data quickly when powered on, but the stored content will be lost after power failure.
[0031] The non-volatile memory is used to permanently store the firmware program code. It is divided into two areas: the first area is used to store the received new version of the firmware program, and the second area is used to store the old version of the firmware program currently running. This division ensures the isolation of the new and old firmware programs and avoids mutual overwriting and conflict.
[0032] Among them, the first area refers to a free storage space reserved in the memory, which can be understood as an independent area divided out in the non-volatile memory in the embodiment of the present application, and is used to store the received new version firmware program code.
[0033] Correspondingly, the second area refers to a storage area in the memory for storing the firmware program code currently being executed and running. In the embodiment of the present application, the second area can be understood as another independent area divided out of the non-volatile memory for storing the old firmware program code currently being run and executed by the device.
[0034] The first area and the second area are physically isolated and independent of each other, avoiding the risk of new and old firmware programs overwriting each other. Through this division method, when a new firmware program is transmitted through an external communication interface, the system can first store it in the first area without affecting the normal operation of the old program in the second area.
[0035] When the new firmware program is received through the external interface and stored in the first area, the device will switch to the new firmware at an appropriate time, and the original firmware code in the second area can be overwritten or erased. Therefore, the second area is only a temporary running area, and its size needs to be reserved according to the actual size of the current firmware version.
[0036] By isolating the currently running firmware program in the second area, the reception and storage of the new firmware program will not affect or damage the running firmware, effectively avoiding various anomalies and risks caused by improper loading of the new firmware. This division method lays the foundation for a smooth transition to the new firmware version and seamless upgrade.
[0037] It is worth noting that the size of the first area needs to be reserved according to the size of the actual new firmware program, and a certain amount of storage space redundancy should be appropriately reserved so as to be able to store the code added in future versions. At the same time, the first area is used as a temporary storage area. After the firmware upgrade is successfully switched to the new firmware, its storage content loses its function and can be overwritten to receive the next version of the upgraded firmware.
[0038] The volatile memory is mainly used to provide an execution environment for the currently running firmware program. It includes the firmware program running area, which is used to store the code, data, and stack during runtime; it also includes a special exchange area, which is used to temporarily store the interrupt vector table, global variables, static variables and other parameters of the new firmware program during firmware upgrades.
[0039] Among them, the exchange area refers to a memory area divided out in the volatile memory, which can be understood as a special data buffer in the embodiment of the present application, used to temporarily store and exchange some key program data and parameters during the firmware program upgrade and switching process, such as the interrupt vector table, global variables, static variables, etc. of the new and old firmware programs.
[0040] The swap area acts as a buffer zone for data exchange, facilitating a smooth transition between the old and new firmware programs during the upgrade process. By pre-copying the key parameters of the new firmware program to the swap area, the impact of the switching process on system operation can be minimized, achieving instant and seamless firmware upgrades.
[0041] At the same time, the introduction of the exchange area also simplifies the switching process between the old and new firmware programs, avoiding tedious data migration and environment reconstruction, thereby significantly improving the upgrade efficiency and success rate. Once the exchange of key data is completed, the system can safely switch program execution to the new firmware code and complete the upgrade at the lowest cost.
[0042] Among them, the firmware program running area refers to a memory area divided out in the volatile memory. In the embodiment of the present application, it can be understood as an exclusive memory space for executing the current firmware program code, for loading and running the firmware program's instruction sequence, operating data structure, and dynamically allocated stack, etc.
[0043] The firmware program running area is the core area where the system performs key functions. After the system starts or the firmware is switched, the currently used firmware program code will be copied from the non-volatile memory and loaded into this area and begin to execute. All control tasks of the system are performed in this area.
[0044] During the firmware upgrade process, the old and new versions of the firmware will occupy the running area at different times. At the beginning of the upgrade, the old version of the firmware will be running in this area to control the current system functions; after the upgrade is completed, the area will switch to running the new version of the firmware to update and expand the system functions and achieve a smooth upgrade of the firmware program.
[0045] Through the above memory division method, the new and old firmware programs can be safely and independently stored, and the operating parameters of the new firmware can be prepared in advance through the exchange area. Therefore, during the system operation, the firmware can be upgraded and switched seamlessly safely and smoothly, avoiding system interruptions or abnormalities caused by the upgrade, thereby maximizing the continuity, reliability and availability of the system.
[0046] S102: Writing firmware parameters of the new firmware program into the swap area of the memory.
[0047] Specifically, before actually switching to execute the new firmware code, the environment and data required for the new firmware program to run need to be prepared in advance to minimize the impact of the switching process on the system operation. Therefore, the system needs to pre-write some key firmware parameters of the new firmware program into the swap area of the memory to achieve smooth upgrade switching of the firmware program.
[0048] Specifically, the system will first read the received new firmware program file from the first area of the non-volatile memory and extract some important firmware parameters from it. The system will write the extracted firmware parameters to the exchange area of the volatile memory according to a predetermined format and address. The exchange area acts as a temporary buffer for storing and exchanging key data of the new and old firmware programs. By writing the parameters of the new firmware into the exchange area in advance, it is possible to prepare for subsequent firmware switching.
[0049] During the writing process, the system needs to strictly follow the address mapping relationship of the new firmware program and copy each parameter to the specified location in the swap area. The above location is usually pre-calculated based on the link configuration of the new firmware to ensure the correctness and consistency of the data.
[0050] There are several significant effects and advantages of writing to the swap area in advance. It simplifies the firmware program switching process, avoids tedious data migration and environment reconstruction, and significantly improves the upgrade efficiency and success rate. Secondly, by pre-writing key data to the swap area, the impact of the switching process on the real-time performance of the system can be minimized, ensuring a smooth and transparent upgrade process. Finally, even in the event of an upgrade failure or abnormality, the system can quickly recover to the operating state of the original firmware, thereby improving the system's fault tolerance and reliability.
[0051] Based on the above embodiment, as an optional embodiment, Figure 2 As shown, the exchange area includes a first exchange sub-area and a second exchange sub-area, and the firmware parameters include an interrupt vector table, global variables and static variables. In S102: the step of writing the firmware parameters of the new firmware program into the exchange area of the memory can also specifically include the following steps: writing the interrupt vector table of the new firmware program into the first exchange sub-area; writing the global variables and static variables of the new firmware program into the second exchange sub-area.
[0052] The first exchange sub-area and the second exchange sub-area refer to two independent sub-areas of the exchange area of the memory that are further divided. In the embodiment of the present application, it can be understood as two dedicated memory areas pre-divided in the volatile memory, which are part of the exchange area and are used to store and exchange different types of key operating parameters of the new and old firmware programs during the firmware upgrade process.
[0053] Among them, the first exchange sub-area is specifically used to store the interrupt vector table data of the new firmware program. The interrupt vector table records the address mapping relationship of all interrupt entry points in the system, which is crucial for the real-time response and normal operation of the firmware program. Storing it separately in the first exchange sub-area can ensure the integrity and correctness of the interrupt vector table data, and support efficient and fast access, preparing for firmware startup.
[0054] The second swap sub-area is used to store the global variables and static variable data of the new firmware program. Global variables and static variables contain all the data states required for the firmware program to run, and are the core data basis for program execution. Storing them in the second swap sub-area can support progressive loading and incremental updates, ensuring the continuity and consistency of the above variable data during firmware execution.
[0055] Through such a partitioning mechanism, different types of firmware parameters are reasonably isolated and organized, which simplifies the data loading process, improves access efficiency, reduces mutual interference, reduces waste of storage space, and also enhances the fault tolerance and reliability of the firmware upgrade process.
[0056] Based on the above embodiment, as an optional embodiment, the storage addresses of the global variables and static variables in the second exchange sub-area are the same as the storage addresses of the global variables and static variables of the old firmware program in the firmware program running area.
[0057] Specifically, when the system writes the global variables and static variables of the new firmware program into the second exchange sub-area, it sets their storage addresses to be consistent with the storage addresses of the corresponding variables in the old firmware program in the firmware program running area. This variable address alignment design is mainly to maximize the data continuity of global variables and static variables when the firmware is switched, and reduce the impact of the switching process on the system running state.
[0058] In order to implement this design, developers need to refer to the variable definition and memory layout of the old firmware when writing the new firmware program to ensure that the global variables and static variables of the new and old firmware match in type, quantity and order. When the system executes S102 to write the variables of the new firmware into the second exchange sub-area, it will strictly follow the variable storage address mapping relationship of the old firmware and automatically copy the data of each new variable to the corresponding target address location through a link script or mapping table.
[0059] After the above precise address alignment, the memory layout of the new firmware's global variables and static variables in the second swap sub-area is consistent with the layout of the old firmware in the program running area. When the firmware is switched later, the system can quickly replace the old variable data with the new variable data through simple data exchange or pointer remapping without large-scale data movement or relocation.
[0060] The above variable address alignment design simplifies the firmware switching process, improves switching efficiency, and minimizes system interruption time. Secondly, it maintains the continuity of variable data, enhances system stability, and avoids the risk of data loss or inconsistency. Furthermore, it reduces the resource overhead of the switching process, saves system resources, and does not require additional memory space for data migration and reorganization. Finally, it improves the compatibility and reliability of firmware upgrades. As long as the variable definitions of the new and old firmware match, the upgrade process can proceed smoothly without introducing new errors or exceptions.
[0061] S103: When the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed, switch to execute the new firmware program and the corresponding firmware parameters of the first area, and stop executing the old firmware program of the second area.
[0062] The idle state refers to a temporary idle working state in which the system or program has no critical tasks or interrupt service routines being executed at a specific moment. In the embodiment of the present application, it can be understood that during the execution of the old firmware program, a short time window appears, during which no interrupt service routine needs to be responded to and processed, and no critical control flow or task function is running, and system resources are temporarily idle.
[0063] The idle state is selected as the switching point mainly to achieve safe and seamless firmware upgrade switching. If the firmware is switched when responding to an interrupt or executing a critical task, the interrupt vector table and critical data may be destroyed, and the task process may be interrupted, resulting in serious consequences such as abnormalities, data confusion or system crashes. The idle state can avoid the above risks, ensure the atomicity and integrity of the switching operation, and ensure the continuity of data status and task execution.
[0064] At the same time, in the idle state, system resources are relatively idle, which can free up enough time and memory space for switching operations, thereby reducing the resource overhead and impact of switching on the system. In addition, since the idle state is an unpredictable moment in the program running process, by capturing this opportunity to switch, the system can be upgraded anytime and anywhere to meet special needs such as emergency maintenance.
[0065] Based on the above embodiment, as an optional embodiment, the present application also provides a method based on time window analysis. The method realizes accurate identification and utilization of the system idle time window through three main steps: historical data collection, pattern analysis, and prediction and scheduling, so as to perform the firmware switching operation at the optimal time. Specifically, the following steps are included: S201: Continuously collect key performance indicator data during the operation process through the system's built-in data acquisition module.
[0066] Specifically, the system first collects the task execution time. By recording the start time, end time, and execution time of each task, the system can fully grasp the task scheduling and processing capacity. The above data not only reflects the real-time performance of the system, but also provides an important basis for identifying potential idle time windows. For example, if the task execution frequency is low or the execution time is short in certain time periods, it may mean that the system is in a relatively idle state and is suitable for firmware update operations.
[0067] At the same time, the system also regularly collects load indicators such as CPU usage, memory usage, and I / O bandwidth. The above indicators directly reflect the utilization of system resources and are the key basis for judging the system load status. In order to obtain sufficiently fine-grained data, the collection frequency can be set to once per second. High-frequency data collection can capture short-term load fluctuations and help to more accurately identify low-load periods of the system. For example, if multiple consecutive sampling points show that the CPU usage is less than 20%, the memory usage is less than 30%, and the I / O bandwidth is less than 15%, it may indicate that the system is in a low-load state and is suitable for performing firmware update tasks.
[0068] In addition, the system also records the triggering time, type, and duration of the interrupt. The interrupt frequency data reflects the real-time response characteristics of the system and is an important indicator for determining whether the system is in an idle state. If the interrupt frequency is low for a period of time, it may mean that the system has fewer external requests and is in a relatively idle state. In this case, executing the firmware update operation has less impact on the real-time performance of the system, which is more conducive to ensuring the stability and reliability of the update process.
[0069] In order to effectively manage and utilize the collected data, the system uses a standardized data format and stores it in a relational database (such as MySQL) or a time series database (such as InfluxDB). The data structure includes fields such as timestamp, task ID, load value, interrupt type, etc. This structured storage method not only facilitates subsequent data analysis and processing, but also supports efficient data query and retrieval. For example, the system can quickly filter out time periods in the past week when the CPU usage rate was less than 20%, providing a basis for finding the right time to update the firmware.
[0070] Through the above comprehensive and detailed data collection process, the system can accumulate rich historical operation data. The above data not only reflects the operating characteristics of the system under different time periods and different load conditions, but also provides a reliable data basis for subsequent pattern analysis. Based on the above historical data, the system can identify periodic low-load patterns and predict possible idle time windows in the future, so as to select the optimal execution time for firmware updates. For example, by analyzing historical data, the system may find that 2 to 4 a.m. every day is the time period with the lowest load, and this time period can be set as the preferred time for firmware updates.
[0071] In addition, the above historical data can also be used to evaluate the impact of firmware updates. By comparing system performance data before and after the update, potential performance degradation or anomalies can be quickly discovered and repair measures can be taken in a timely manner. For example, if the CPU usage after the firmware update is found to be significantly higher than the level before the update, it may mean that the new firmware has performance issues and needs to be further optimized or rolled back to the previous version.
[0072] S202: Identify low-load periods or idle periods of the system by analyzing the collected historical data.
[0073] Specifically, the system first preprocesses the collected historical data. Because the original data may contain outliers and noise, the above data may cause deviations in subsequent analysis. By using statistical methods such as median filtering or moving average techniques, the system can effectively filter out the above abnormal data to ensure the accuracy of subsequent analysis. After data cleaning, the system aggregates the data according to the predefined time window to obtain indicators such as average load and interruption frequency in each time window.
[0074] Subsequently, the system conducts a logical strategy analysis, the core of which is to set reasonable load thresholds and interruption frequency thresholds. The setting of the above thresholds directly affects the system's judgment criteria for idle periods. For example, the system can set the low load threshold to CPU usage below 20%, memory usage below 30%, and I / O bandwidth below 15%; and set the low interruption frequency threshold to less than 5 interruptions per unit time. The selection of the above thresholds needs to be weighed against the performance characteristics of the system and business needs. Setting it too high may miss potential update opportunities, while setting it too low may cause updates to be performed while the system is still busy, affecting normal business.
[0075] Based on the set threshold, the system performs pattern recognition. It mainly includes two aspects: low-load period recognition and idle period recognition. Low-load period recognition focuses on system resource utilization. When indicators such as CPU, memory, and I / O are all lower than the set threshold, it is considered a low-load state. Idle period recognition focuses more on the external interaction of the system. When the interrupt frequency is low and fewer tasks are executed, it is considered an idle state. This dual recognition mechanism can more comprehensively evaluate the system status and avoid the judgment bias that may be caused by a single indicator.
[0076] In order to improve the accuracy and stability of identification, the system also defines specific judgment rules. The low load rule requires that the system load is lower than the set threshold for N consecutive time windows; the idle period rule requires that the system interruption frequency is lower than the set threshold for N consecutive time windows. This continuity requirement can effectively avoid the impact of instantaneous fluctuations on judgment, ensuring that the identified time period has sufficient continuity and is suitable for firmware update operations.
[0077] S203: Predict and intelligently schedule the system operation mode to determine the optimal execution time of the firmware switching task.
[0078] Specifically, the system first performs a logical prediction operation. The core of this step is to identify periodic patterns in historical data, such as low load characteristics at specific times of the day. By performing time series analysis on a large amount of historical data, the system can find patterns such as "the system load is lowest between 2 and 4 a.m. every day" or "the interruption frequency is significantly reduced after 10 p.m. every Sunday." The identification of such periodic patterns is crucial for accurately predicting future system states. For example, if the system finds that a low load state lasting more than one hour has occurred around 3 a.m. every day for the past 30 days, it can be reasonably inferred that this time period in the future is also likely to be a low load period for the system. Based on the periodic patterns identified above, the system further performs window prediction, that is, predicting low load windows and idle windows that may appear in the future. This prediction not only considers historical patterns, but also combines the current system state and recent trends to improve the accuracy of the prediction. For example, if the system detects that the load in the early morning has an upward trend recently, it will adjust the prediction results accordingly, and may move the predicted low load window back or shorten its duration.
[0079] Based on the prediction results, the system formulates corresponding scheduling strategies. This includes dynamic scheduling and pre-scheduling. Dynamic scheduling is a real-time response mechanism. The system dynamically adjusts the execution time of the firmware switching task based on real-time monitoring and prediction results. For example, if the firmware switching task originally planned to be executed at 3 a.m. detects an abnormal increase in load when approaching the execution time, the dynamic scheduling mechanism will immediately postpone the task execution time and wait for the next suitable time window. This flexible scheduling method can effectively respond to real-time changes in system load and avoid firmware switching at inappropriate times to the greatest extent. At the same time, the system also adopts a pre-scheduling strategy to formulate a firmware switching plan in advance based on the prediction results. For example, if the prediction shows that from 10 p.m. to 4 a.m. next Sunday is a long low-load window, the system will schedule the firmware switching task in this time period in advance. This pre-scheduling can not only make full use of system resources, but also reserve enough time buffer for the switching operation to deal with possible unexpected situations.
[0080] In the specific scheduling implementation process, the system first manages the task queue. The firmware switching task is added to the system task queue and is assigned an appropriate execution priority. The setting of this priority needs to weigh the urgency of the firmware update and the current load status of the system. For example, if it is an urgent update to fix a major security vulnerability, it may be given a higher priority; while a general function optimization update may be given a lower priority. When the system detects the arrival of the predicted idle time window, it triggers the execution of the firmware switching task. This triggering process is automatic and does not require human intervention, which greatly improves the automation and response speed of the system.
[0081] In order to continuously optimize the firmware update strategy, the system will record the execution of each firmware switch in detail, including information such as execution time, time consumption and results. The above switch log is not only an important system operation record, but also a valuable basis for subsequent analysis and optimization. By analyzing the above logs, the system can evaluate the effectiveness of the current prediction and scheduling strategy, and find possible problems and optimization space. For example, if it is found that a certain predicted low-load window often experiences load surges, resulting in frequent interruptions of the switching operation, the system can adjust the prediction algorithm or increase the safety margin to improve the accuracy of the prediction and the success rate of the switch.
[0082] Through the above prediction and scheduling mechanism, the system can perform firmware switching operations in the most appropriate time window, significantly reducing the impact on normal business. For example, under the traditional fixed-time update strategy, updates may be unexpectedly performed during business peaks, resulting in system performance degradation or service interruption. After adopting this method, the system can intelligently avoid the above high-load periods and choose to perform updates during real idle time, thereby maximizing business continuity and system stability.
[0083] Based on the above embodiment, as another optional embodiment, the idle state and the new firmware program update completion state can be captured by setting a flag. Specifically, a first flag can be set in the first area, and the first flag is used to detect the loading process of the new firmware program; and a second flag can be set in the second area, and the second flag is used to detect that the interrupt of the old firmware program is in an idle state.
[0084] Specifically, the system sets a first flag in the first area of the non-volatile memory to detect and record the loading progress of the new firmware program in real time. When the system starts to receive the new firmware program data through the communication interface and write it into the first area, the first flag is set to the "loading" state. As the new firmware data is continuously written, the first flag is continuously updated to reflect the current loading progress. Once the new firmware program data is completely received and stored, the first flag is set to the "load completed" state, indicating that the new firmware is ready and can be switched.
[0085] At the same time, the system will also set another second flag bit in the second area of the non-volatile memory to detect and record the interrupt status of the old firmware program currently running in real time. During the running of the old firmware program, if no interrupt service program is being executed, the second flag bit will be set to the "interrupt idle" state; conversely, if an interrupt is being responded to and processed, the second flag bit will be set to the "interrupt busy" state. By monitoring the state changes of the second flag bit in real time, the system can dynamically capture the idle time of the old firmware program.
[0086] Based on the cooperation of the above two flags, the best time to switch firmware can be accurately determined. That is, only when the first flag is in the "load complete" state and the second flag is in the "interrupt idle" state, the system will trigger the firmware switching operation, copy the running parameters of the new firmware program from the memory exchange area to the program running area, and redirect the program counter to jump to the entry address of the new firmware to complete the seamless switching of the new and old firmware. At the same time, the system will stop the execution of the old firmware program to release the system resources it occupies.
[0087] The main purpose of introducing the flag mechanism is to achieve precise control and intelligent scheduling of the firmware switching timing. Through real-time detection and recording of the flag, the system can dynamically perceive the loading progress of the new firmware and the interruption status of the old firmware, so as to adaptively select the most appropriate firmware switching timing, minimize the impact of the switching operation on the real-time performance of the system, and improve the switching success rate.
[0088] In addition, the setting of the flag bit also enhances the fault tolerance and reliability of the system. Even if there is an abnormal interruption or data loss during the new firmware loading process, the system can judge the current loading progress through the status of the flag bit and take corresponding recovery measures, avoiding system crash or data damage caused by blind switching.
[0089] Based on the above embodiment, as an optional embodiment, in S103: switching to execute the new firmware program and the corresponding firmware parameters in the first area and stopping the execution of the old firmware program in the second area may further include the following steps: The interrupt vector table of the first exchange sub-area is copied to the interrupt vector table storage position of the new firmware program running area, the contents of the global variables and static variables of the second exchange sub-area are copied to the corresponding storage positions of the new firmware program running area, the stack pointer is initialized, and the new firmware program is executed.
[0090] Specifically, before executing the switch, the key operating parameters of the new firmware, such as the interrupt vector table, global variables, and static variables, are temporarily stored in the swap area reserved in the volatile memory. When the switch time comes, the system first copies the interrupt vector table of the new firmware stored in the first swap sub-area to the interrupt vector table storage location of the new firmware program running area. This ensures that the new firmware can use the correct interrupt entry address after startup to respond to and handle various interrupt events.
[0091] Subsequently, the system reads the global variables and static variables of the new firmware from the second exchange sub-area and copies their contents to the corresponding storage locations in the firmware program running area. The above variables carry the key data and status information of the program. Restoring them can ensure that the new firmware can smoothly and continuously execute subsequent functions and tasks based on the running results of the old firmware, achieving seamless switching.
[0092] After completing the copying of key parameters, the system will initialize the stack pointer to point to the stack start address of the new firmware. This provides an independent stack space for the operation of the new firmware, avoiding abnormal risks such as stack overflow and data overwrite. At this point, the new firmware has complete operating conditions, and the system will jump to the entry address of the new firmware and start executing the new version of the program code.
[0093] Through the above steps, the key data accumulated in the old firmware program can be smoothly transferred to the new firmware program, and the startup environment of the new firmware program has also been carefully configured and initialized, thus achieving seamless switching and upgrading of the firmware version. This switching mechanism cleverly avoids risks such as data loss and environmental loss, ensures the continuity of system functions and business processes, and greatly improves the security and reliability of firmware program updates.
[0094] Based on the above embodiment, as an optional embodiment, when the interrupt of the old firmware program is in an idle state and the new firmware program is loaded, the global interrupt is disabled; after switching to execute the new firmware program and the corresponding firmware parameters of the first area and stopping the execution of the old firmware program in the second area, the global interrupt is enabled.
[0095] Specifically, in the process of firmware switching and upgrading, in order to further ensure the atomicity and security of the switching operation, the embodiment of the present application also provides an optimized implementation scheme, that is, to protect the switching process by controlling the global interrupt at the key node. When the system detects that the switching condition is met, that is, the interrupt of the old firmware program is in an idle state and the new firmware program has been fully loaded, the system will first perform a global interrupt disabling operation.
[0096] By turning off all interrupt responses at the processor level, including internal and external interrupt sources, a safe atomic operation environment is created. After the global interrupt is disabled, any new interrupt request will be masked, and the processor will focus on the firmware switching task currently being executed to ensure that it will not be accidentally interrupted.
[0097] Furthermore, in an environment without interruption, the system performs the actual firmware program and parameter switching operation, that is, stops executing the old firmware program in the second area of the memory, starts executing the new firmware program in the first area, and synchronously switches to the parameter set corresponding to the new firmware. Since the global interrupt is disabled at this time, the switching operation can be executed continuously without interruption, and no interrupt processing will be inserted in the middle, ensuring the integrity and consistency of the switching process.
[0098] When the switch between the old and new firmware is completed, the system will immediately execute the global interrupt enable operation to restore the processor's interrupt response capability to normal. At this point, the upgraded new firmware program begins to execute continuously under the correct parameter environment, and can respond to interrupt requests in a timely manner and enter normal working state. The entire switching process was completed smoothly under safe and controllable conditions, avoiding data inconsistency problems that may be caused by the interleaving of interrupts and program execution.
[0099] Reference Figure 3 , the present application also provides a firmware program update system, including: A firmware program distribution module, used for acquiring a new firmware program and loading the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state; A firmware parameter storage module, used for writing the firmware parameters of the new firmware program into the exchange area of the memory; The firmware program update module is used for the new firmware program allocation module, which is used to switch to execute the new firmware program and corresponding firmware parameters of the first area and stop executing the old firmware program of the second area when the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed.
[0100] Based on the above embodiments, as an optional embodiment, the memory includes a non-volatile memory and a volatile memory, the non-volatile memory includes the first area and the second area, the volatile memory includes the exchange area and the firmware program running area, and the firmware program running area is used to provide an execution environment for the firmware program in the execution state.
[0101] Based on the above embodiment, as an optional embodiment, the exchange area includes a first exchange sub-area and a second exchange sub-area, the firmware parameters include an interrupt vector table, global variables and static variables, and the firmware parameter storage module is also used to write the interrupt vector table of the new firmware program into the first exchange sub-area; and write the global variables and static variables of the new firmware program into the second exchange sub-area.
[0102] Based on the above embodiment, as an optional embodiment, the storage addresses of the global variables and static variables in the second exchange sub-area are the same as the storage addresses of the global variables and static variables of the old firmware program in the firmware program running area.
[0103] Based on the above embodiment, as an optional embodiment, the firmware program update module is also used to copy the interrupt vector table of the first exchange sub-area to the interrupt vector table storage location of the new firmware program running area; copy the contents of the global variables and static variables of the second exchange sub-area to the corresponding storage locations of the new firmware program running area; initialize the stack pointer, and execute the new firmware program.
[0104] Based on the above embodiment, as an optional embodiment, the firmware program update module is also used to set a first flag bit in the first area, and the first flag bit is used to detect the loading process of the new firmware program; set a second flag bit in the second area, and the second flag bit is used to detect that the interrupt of the old firmware program is in an idle state.
[0105] Based on the above embodiment, as an optional embodiment, the firmware program update module is also used to disable the global interrupt when the interrupt of the old firmware program is in an idle state and the new firmware program is loaded; after switching to execute the new firmware program and the corresponding firmware parameters of the first area and stopping the execution of the old firmware program in the second area, the global interrupt is enabled.
[0106] It should be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0107] An embodiment of the present application also provides a computer storage medium, which can store multiple instructions. The instructions are suitable for being loaded by a processor and executing the firmware program update method of the above embodiment. The specific execution process can refer to the specific description of the embodiment shown, which will not be repeated here.
[0108] The present application also discloses a microprocessor. Figure 4 , Figure 4 The microprocessor 400 may include: at least one processor 401 , at least one network interface 404 , a user interface 403 , a memory 405 , and at least one communication bus 402 .
[0109] The communication bus 402 is used to realize the connection and communication between the above components.
[0110] The user interface 403 may include a display interface and a camera interface. Optionally, the user interface 403 may also include a standard wired interface and a wireless interface.
[0111] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0112] Among them, the processor 401 may include one or more processing cores. The processor 401 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 405, and calling data stored in the memory 405. Optionally, the processor 401 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 401 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface diagrams and applications, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 401, and it can be implemented separately through a chip.
[0113] Among them, the memory 405 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 405 includes a non-transitory computer-readable storage medium. The memory 405 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 405 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 405 may optionally also be at least one storage device located away from the aforementioned processor 401. Refer to Figure 4 , the memory 405 as a computer storage medium may include an operating system, a network communication module, a user interface module and an application program of a firmware program updating method.
[0114] exist Figure 4 In the microprocessor 400 shown, the user interface 403 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 401 can be used to call an application program storing a firmware program update method in the memory 405, and when executed by one or more processors 401, the microprocessor 400 executes one or more of the methods described in the above embodiments. It should be noted that for the aforementioned method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.
[0115] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0116] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0117] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0118] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0119] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.
[0120] The above is only an exemplary embodiment of the present disclosure and cannot be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification and the truth of practice, those skilled in the art will easily think of other embodiments of the present disclosure.
[0121] This application is intended to cover any variation, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art that are not described in the present disclosure. The description and examples are to be regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. A firmware program update method, It is characterized in that include: Acquire a new firmware program, and load the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state; Writing firmware parameters of the new firmware program into a swap area of the memory; When the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed, the execution of the new firmware program and the corresponding firmware parameters of the first area is switched, and the execution of the old firmware program of the second area is stopped.
2. The firmware program updating method according to claim 1, It is characterized in that The memory includes a non-volatile memory and a volatile memory, the non-volatile memory includes the first area and the second area, the volatile memory includes the exchange area and a firmware program running area, and the firmware program running area is used to provide an execution environment for the firmware program in the execution state.
3. The firmware program updating method according to claim 2, It is characterized in that The exchange area includes a first exchange sub-area and a second exchange sub-area, the firmware parameters include an interrupt vector table, global variables and static variables, and writing the firmware parameters of the new firmware program into the exchange area of the memory includes: Writing the interrupt vector table of the new firmware program into the first exchange sub-area; The global variables and static variables of the new firmware program are written into the second exchange sub-area.
4. The firmware program updating method according to claim 3, It is characterized in that The storage addresses of the global variables and the static variables in the second exchange sub-area are the same as the storage addresses of the global variables and the static variables of the old firmware program in the firmware program running area.
5. The firmware program updating method according to claim 3, It is characterized in that The switching to execute the new firmware program and corresponding firmware parameters of the first area includes: Copying the interrupt vector table of the first exchange sub-area to the interrupt vector table storage location of the new firmware program running area; Copying the contents of the global variables and static variables of the second exchange sub-area to corresponding storage locations of the new firmware program running area; The stack pointer is initialized and the new firmware program is executed.
6. The firmware program updating method according to claim 1, It is characterized in that After writing the firmware parameters of the new firmware program into the exchange area of the memory, the method further includes: Setting a first flag bit in the first area, the first flag bit being used to detect the loading process of the new firmware program; A second flag bit is set in the second area, and the second flag bit is used to detect that the interrupt of the old firmware program is in an idle state.
7. The firmware program updating method according to claim 1, It is characterized in that The method further comprises: When the interrupt of the old firmware program is in an idle state and the loading of the new firmware program is completed, disabling global interrupts; After switching to execute the new firmware program and the corresponding firmware parameters of the first area and stopping the execution of the old firmware program of the second area, the global interrupt is enabled.
8. A firmware program update system, It is characterized in that include: A firmware program distribution module, used for acquiring a new firmware program and loading the new firmware program into a free first area in a memory, wherein the memory also stores a second area of an old firmware program in an execution state; A firmware parameter storage module, used for writing the firmware parameters of the new firmware program into the exchange area of the memory; The firmware program update module is used for the new firmware program allocation module, which is used to switch to execute the new firmware program and corresponding firmware parameters of the first area and stop executing the old firmware program of the second area when the interrupt of the old firmware program is in an idle state and the update of the new firmware program is completed.
9. A microprocessor, It is characterized in that It includes a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the microprocessor executes the method according to any one of claims 1 to 7.
10. A computer storage medium, It is characterized in that The computer storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is performed.
Citation Information
Patent Citations
Remote dynamic upgrading method and method for embedded software of power system
CN108196873A
Firmware updating method and device, earphone and computer readable storage medium
CN111045714A
Firmware upgrading method and device, chip, storage medium and wireless earphone
CN116243954A
Firmware real-time updating method and system of non-reset control chip and storage medium
CN117573175A
Firmware updating device
JP2000242503A
Cited By
Inverter parallel operation system and upgrading method thereof
CN120994228A
Inverter parallel system and upgrading method thereof
CN120994228B
