Firmware switching method, device, equipment and storage medium

By performing integrity checksum memory mapping after receiving the firmware upgrade command, the problem of low firmware switching efficiency is solved, and an efficient firmware switching process is realized, avoiding repeated loading of the boot program and resource initialization, ensuring business continuity.

CN120276790BActive Publication Date: 2025-08-26INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510756908.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-06
Publication Date
2025-08-26
Estimated Expiration
2045-06-06

AI Technical Summary

Technical Problem

The firmware switching efficiency in the prior art is inefficient because it is necessary to switch to the boot program for secondary loading and resource repetitive initialization, resulting in additional overhead.

Method used

After receiving the firmware upgrade command, the integrity of the target firmware is checked and saved to the memory preset address, stop processing the pending commands in the command queue, and remap the firmware start address through the memory management unit after the processing is completed, and jump directly to the execution of the target firmware to avoid the boot program loading.

Benefits of technology

Saves time for boot loading and resource initialization, improves firmware switching efficiency, and ensures business continuity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120276790B_ABST
    Figure CN120276790B_ABST
Patent Text Reader

Abstract

The present application discloses a firmware switching method, apparatus, device and storage medium, which relate to the field of computer technology. When an upgrade command is received from an operation and maintenance end, the target firmware is firstly checked for integrity to ensure that the target firmware to be upgraded is legal and then stored in a preset memory address. After the execution of the pending commands taken out from the command queue is completed, the firmware start address is remapped through the memory management unit, so that the business execution of the target device jumps directly to the execution of the target firmware without switching to a boot program, thus saving the time of secondary loading of the firmware and booting from the boot loader.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a firmware switching method, apparatus, device, and storage medium. Background Art

[0002] The number of enterprise-class SSDs running in customer production environments is far higher than the number running in the manufacturer's test environment. Therefore, some rare issues cannot be detected in test environments and instead appear in user scenarios. After engineers have located the issue and fixed it by modifying the firmware, they need to send the fixed firmware to the customer for firmware upgrade to prevent other users from experiencing the same issue.

[0003] In the related art, after the new firmware is written into the memory, it is necessary to switch to the boot program to reload the new firmware and reinitialize the hardware resources and data to process read and write commands. This upgrade method will increase the additional overhead caused by the secondary loading of the boot program and repeated initialization of resources, reducing the efficiency of firmware switching. Summary of the Invention

[0004] The present application provides a firmware switching method, apparatus, device and storage medium to at least solve the problem of low firmware switching efficiency in the related art.

[0005] The present application provides a firmware switching method, comprising: receiving a firmware upgrade command for a target device, obtaining target firmware according to the firmware upgrade command; verifying the target firmware, and saving the target firmware to a preset physical address in a memory after the verification passes; stopping processing of each pending command in a command queue, and continuing to process the stock pending commands that have been taken out of the command queue; after completing processing of the stock pending commands, deleting each currently running application layer task; configuring the firmware start address of the target device to a preset physical address in the memory through a memory management unit, and obtaining a mapping relationship between the firmware start address and the preset physical address in the memory; initializing the target firmware according to the mapping relationship, and resuming execution of each application layer task.

[0006] The present application also provides a firmware switching device, comprising:

[0007] The target firmware acquisition module is used to receive a firmware upgrade command for a target device and acquire the target firmware according to the firmware upgrade command.

[0008] The target firmware verification module is used to verify the target firmware and save the target firmware to a preset physical address in the memory after the verification passes.

[0009] The pending command execution module is used to stop processing each pending command in the command queue and continue processing the stock pending commands that have been taken out of the command queue.

[0010] The application layer task deletion module is used to delete the currently running application layer tasks after the existing pending commands are processed.

[0011] The firmware start address configuration module is used to configure the firmware start address of the target device as the preset physical address of the memory through the memory management unit, and obtain a mapping relationship between the firmware start address and the preset physical address of the memory.

[0012] The application layer task recovery module is used to initialize the target firmware according to the mapping relationship and resume running each application layer task.

[0013] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned firmware switching methods when executing the computer program.

[0014] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned firmware switching methods are implemented.

[0015] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned firmware switching methods when executed by a processor.

[0016] The firmware switching method, apparatus, device and storage medium of the present application, upon receiving an upgrade command from the operation and maintenance end, first performs an integrity check on the target firmware to ensure that the target firmware to be upgraded is legal and then stores it in a preset memory address. After the execution of the pending commands taken out from the command queue is completed, the firmware starting address is remapped through the memory management unit, so that the business execution of the target device jumps directly to the execution of the target firmware without switching to the boot program, saving the time for secondary loading of the firmware and booting from the boot loader. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0018] Figure 1 A schematic diagram of memory distribution provided in an embodiment of the present application;

[0019] Figure 2 A flowchart of a firmware switching method provided in an embodiment of the present application;

[0020] Figure 3A schematic diagram of the structure of a firmware switching device provided in an embodiment of the present application;

[0021] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments of this application, all other embodiments obtained by ordinary technicians in this field without making any creative work are within the scope of protection of this application.

[0023] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.

[0024] In order to clearly understand the technical solution of the present application, the solution of the prior art is first introduced in detail. The number of enterprise-level solid-state drives running in the customer's production environment is much higher than the number of runs in the manufacturer's test environment, so some low-probability problems cannot be tested in the test environment, but appear in the user scenario. After the engineer completes the problem location and fixes the problem by modifying the firmware, in order to avoid other users from having the same problem, the repaired firmware needs to be sent to the customer for firmware switching. In the related art, after the new firmware is written to the memory, it is necessary to switch to the boot program and reload the new firmware by the boot program, and reinitialize the hardware resources and data to process read and write commands. This upgrade method will increase the additional overhead caused by the secondary loading of the boot program and the repeated initialization of resources, reducing the efficiency of firmware switching.

[0025] In order to solve the above technical problems, the inventors thought that after receiving the upgrade command from the operation and maintenance end, the target firmware is first checked for integrity to ensure that the target firmware to be upgraded is legal and then stored in the preset address of the memory. After the execution of the pending commands taken out from the command queue is completed, the firmware starting address is remapped through the memory management unit, so that the business execution of the target device jumps directly to the execution of the target firmware without switching to the boot program, saving the time for secondary loading of firmware and booting from the boot loader.

[0026] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0027] During the target firmware design phase, application-layer code is separated from underlying driver code and system service code based on functional hierarchy and runtime privileges. The compilation toolchain maps these different components to independent physical address spaces, isolating business logic from hardware operations. Application-layer code stores business logic and algorithms; system service code provides task scheduling services; and underlying driver code provides hardware interfaces and interrupt handling services.

[0028] Figure 1 This is a memory distribution diagram provided in the embodiment of this application. Figure 1 As shown, the entire memory space is designed with data partitions to separate global variables and shared data. Area 1 stores executable code 1 and global variable 1 required by executable code 1. Area 1 can be a real-time operating system area, storing executable code and global variables used to call the real-time operating system. The original firmware area stores business executable code 2 and global variable 2 that run based on the original firmware. The target firmware area stores business executable code 3 and global variable 3 that run based on the target firmware. The original firmware / target firmware area stores firmware shared data, where firmware shared data refers to data that can continue to be accessed and can ensure consistency after the original firmware and target firmware are switched. The application layer executable code is used to implement specific business logic and algorithms based on firmware. Global variables are used for global data storage of the application layer executable code of the firmware. The shared data area stores data that needs to be accessed by both the old and new firmware and data consistency must be ensured when switching between the two.

[0029] Figure 2 Schematic diagram of the process of the firmware switching method provided in the embodiment of the present application. Figure 2 As shown, an embodiment of the present application provides a firmware switching method. The execution subject of the method can be a processor of any electronic device (i.e., a target device) that needs to perform firmware switching, or a device with similar functions. The embodiment of the present application does not make specific restrictions, and the method is described in detail as follows:

[0030] S201: Receive a firmware upgrade command for a target device, and obtain target firmware according to the firmware upgrade command.

[0031] Specifically, when the processor of the target device receives a firmware upgrade command issued by the operation and maintenance end for the target device, the command carries the acquisition path of the target firmware. According to the acquisition command, the target firmware is downloaded from the specified storage location to a specific memory location through a specific communication protocol or interface.

[0032] S202: Verify the target firmware, and save the target firmware to a preset physical address in the memory after the verification passes.

[0033] Specifically, after acquiring the target firmware, the processor of the target device will perform integrity and legality checks on the target firmware. If the checks pass, the target firmware will be saved in the memory at a pre-set physical address, where the pre-set physical address is a storage space reserved specifically for the target firmware.

[0034] Specifically, the process of verifying the target firmware includes:

[0035] Sa1: Obtain the version number, first verification information, and digital signature from the target firmware.

[0036] Among them, the first verification information is used to verify data integrity and can be a hash value or a cyclic redundancy check code; the version number is used to determine the newness of the firmware; and the digital signature is used to confirm the legitimacy of the firmware source.

[0037] Specifically, metadata for verification is parsed and extracted from a specific area or header of the target firmware file, including a version number, first verification information, and a digital signature.

[0038] Sa2: Obtain binary data of the target firmware and calculate second verification information of the binary data using a preset algorithm.

[0039] Specifically, the complete binary data content of the target firmware is read, and a preset hash algorithm is used to perform a message digest calculation on the binary data to generate the second verification information.

[0040] Sa3: Compare the first verification information and the second verification information to see if they are consistent.

[0041] Specifically, the first verification information extracted from the target firmware is compared bit by bit with the second verification information calculated in real time. If the two are completely consistent, it preliminarily indicates that the target firmware data is complete; if there is a difference, it indicates that the target firmware may be damaged or tampered with.

[0042] Sa4: If the first verification information is inconsistent with the second verification information, the verification fails and the target firmware switching operation is stopped.

[0043] Specifically, when the first verification information is inconsistent with the second verification information, the system immediately determines that the verification has failed, and terminates the switching operation of the target firmware. It also records the error log, sends an alarm to the operation and maintenance end, and keeps the current firmware running status unchanged to ensure that the device continues to work normally.

[0044] Sa5: If the first verification information is consistent with the second verification information, the digital signature is verified using the pre-stored public key to determine whether the source of the target firmware is abnormal.

[0045] Specifically, based on the consistency of the verification information, the legitimacy of the source of the target firmware is further verified. The digital signature is decrypted and verified using a public key pre-stored in the target device, where the public key is issued by a trusted institution.

[0046] Sa6: If the source of the target firmware is determined to be abnormal, the verification fails and the target firmware switching operation is stopped.

[0047] Specifically, if the digital signature verification fails, the target firmware source is determined to be abnormal, and the switching operation is also terminated. The error log is recorded, an alarm is sent to the operation and maintenance end, and the current firmware operation status is kept unchanged to ensure that the device continues to work normally.

[0048] Sa7: If the source of the target firmware is determined to be normal, check whether the version number is higher than the current firmware version.

[0049] Specifically, after confirming the integrity and source legitimacy of the firmware, the version number of the target firmware is compared with the currently running firmware version.

[0050] Sa8: If the version number is not higher than the current firmware version, the verification fails and the target firmware switching operation is stopped.

[0051] Specifically, if the version number of the target firmware is not higher than the current firmware version, the verification is determined to have failed and the firmware switching is stopped, thereby preventing firmware downgrade caused by misoperation or induction, and ensuring that the device always runs the latest and tested stable version.

[0052] Sa9: If the version number is higher than the current firmware version, the verification is successful.

[0053] Specifically, when the target firmware passes the integrity check and source legitimacy verification and has a higher version number than the current firmware, the system determines that the verification is successful.

[0054] S203: Stop processing the pending commands in the command queue, and continue processing the pending commands that have been taken out of the command queue.

[0055] Specifically, first stop receiving and processing all pending commands in the command queue of the target device to avoid interference with the switching process due to the addition of new commands during the firmware switching process. However, for the existing pending commands that have been taken out of the command queue and are in the processing process, continue to execute them until completion to ensure that the execution of these started commands will not be interrupted.

[0056] Specifically, after processing the pending commands that have been taken out of the command queue, the following steps are also included:

[0057] Sb1: Set a timeout threshold corresponding to each pending command in the inventory according to the type and complexity of each pending command.

[0058] The type of the command to be processed may be data query, device control or file transfer, and the complexity of the command to be processed includes the number of execution steps and the amount of resource usage.

[0059] Specifically, when processing the retrieved pending commands, a unique timeout threshold is set for each command based on its type and complexity. For example, a simple status query command may have a threshold of 100ms, while a complex batch data processing command may have a threshold of 500ms.

[0060] Sb2: Set a timeout counter for each pending command in stock, and monitor the execution time of each pending command in real time.

[0061] Specifically, a separate timeout counter is started for each pending command, which accumulates time in real time from the start of command execution. At the same time, the execution time of each command is continuously monitored through a timer or event monitoring mechanism.

[0062] Sb3: When it is detected that the execution time of any stored pending command exceeds the corresponding timeout threshold, the switching operation of the target firmware is stopped and the timeout alarm mechanism is triggered.

[0063] Specifically, if the execution time of any pending command exceeds the set timeout threshold, the current firmware switch operation is immediately interrupted to prevent the upgrade process from stalling due to command jams. A timeout alarm mechanism is also activated, logging the ID, type, and duration of the timed-out command and sending an exception notification to the operations and maintenance team.

[0064] Sb4: If the execution time of each stored pending command does not exceed the corresponding timeout threshold, the firmware switching process is entered.

[0065] Specifically, if all pending commands are executed within their respective timeout thresholds, it is confirmed that the current business process will not lose data or be interrupted due to the firmware switch, and the firmware switch process is automatically triggered.

[0066] S204: After the existing pending commands are processed, the currently running application layer tasks are deleted.

[0067] Specifically, after all pending commands are processed, the currently running application layer tasks are deleted. This process includes:

[0068] Sc1: calling the first interface to stop the currently running application layer tasks through the real-time operating system.

[0069] Specifically, the first interface function provided by the real-time operating system is called to send a task stop instruction to the real-time operating system. The real-time operating system sequentially pauses all running application-layer tasks according to preset task priorities and dependencies. During this process, the real-time operating system saves the current execution context of the task.

[0070] Sc2: Reset each interrupt trigger flag of the target device through the real-time operating system and shield the reception of external interrupt signal sources.

[0071] Specifically, after stopping the application layer task, all interrupt trigger flags of the target device are reset through the real-time operating system. At the same time, the reception of all external interrupt signal sources is temporarily blocked, and the interrupt controller's mask register is modified to prohibit external events from generating interrupt requests.

[0072] Sc3: Delete all currently running application layer tasks and clear the call data of the real-time operating system.

[0073] Specifically, all currently running application layer task control blocks and their related resources are deleted, and at the same time, the call history data of these tasks in the real-time operating system is cleared.

[0074] S205: configuring the firmware start address of the target device as a preset physical address of the memory through the memory management unit, and obtaining a mapping relationship between the firmware start address and the preset physical address of the memory.

[0075] Specifically, the target device's firmware start address is reconfigured through the memory management unit to point to the preset physical address in memory where the target firmware was previously stored. The MMU's address translation mechanism establishes a mapping between the firmware start address and the preset physical address in memory, enabling the system to accurately locate the storage location of the new firmware when subsequently booting or accessing the firmware.

[0076] S206: Initialize the target firmware according to the mapping relationship and resume running each application layer task.

[0077] Specifically, based on the established mapping, the system begins initializing the target firmware. This initialization process includes configuring hardware parameters and initializing hardware devices to prepare the new firmware for operation. After firmware initialization is complete, application-layer tasks that rely on the target firmware are executed. These application-layer tasks then operate within the target firmware environment, restoring the target device's business logic.

[0078] Specifically, the target firmware initialization process includes:

[0079] Sd1: According to the mapping relationship, access the global variables stored in the memory of the target firmware to determine whether the target firmware has set a status flag for uninterrupted service.

[0080] The service continuity status flag is pre-defined by the firmware developer and is used to indicate whether service continuity needs to be maintained during the firmware switching process.

[0081] Specifically, based on the established mapping between the firmware's starting address and the pre-set physical memory address, the system accesses the target firmware's global variable area stored in memory to determine whether a specific flag indicating service continuity exists. If such a flag is detected, indicating that the target firmware supports service continuity during upgrades, the system will initiate a targeted initialization process. If not, the system proceeds with the standard upgrade process, which may require suspending services.

[0082] Sd2: If the target firmware sets the service uninterrupted status flag, then during the target firmware initialization process, when an access operation to the hardware configuration parameters of the target firmware is detected, it is determined whether the storage location of the hardware configuration parameters is a shared data segment.

[0083] Specifically, when the target firmware sets the service uninterrupted status flag, during the initialization of the target firmware, the access operation to the hardware configuration parameters is monitored in real time, and the storage address of these hardware configuration parameters is obtained to determine whether they are stored in the shared data segment.

[0084] Sd3: If the storage location of the hardware configuration parameters is the shared data segment, skip the initialization of the hardware resources associated with the hardware configuration parameters.

[0085] Specifically, if it is determined that the storage location of the hardware configuration parameters is a shared data segment, the hardware resources associated with these parameters are identified, and the initialization operation of these hardware resources is skipped when initializing the target firmware.

[0086] In summary, when an upgrade command is received from the operation and maintenance end, the target firmware is first checked for integrity to ensure that the target firmware to be upgraded is legal and then stored in the preset memory address. After the execution of the pending commands taken out of the command queue is completed, the firmware start address is remapped through the memory management unit, so that the business execution of the target device jumps directly to the execution of the target firmware without switching to the boot program, saving the time for secondary loading of firmware and booting from the boot loader.

[0087] In addition, when it is detected that the target firmware has set a status flag for uninterrupted business, when an access operation to the hardware configuration parameters in the shared data segment is detected, the initialization of the hardware resources associated with the hardware configuration parameters is skipped, thereby saving the time for resource reinitialization and further speeding up the switching of the target firmware.

[0088] In another embodiment provided by the embodiments of the present application, if the processor of the target device is a multi-core processor, in which different cores are used to process different tasks, and the multi-core processor includes a master core and at least one slave core, after the multi-core processor completes processing of the pending commands, the method further includes:

[0089] S301: Stop all currently running application layer tasks and reset all interrupt trigger flags of the target device.

[0090] Specifically, in a multi-core processor environment, the master core first sends a coordinated stop command to all slave cores, stopping each currently running application-layer task in sequence according to the preset priority level to ensure that the task context is fully preserved. The master core then resets all interrupt trigger flags on the target device and clears the trigger flag of each interrupt source by accessing the interrupt controller's status register group.

[0091] S302: Stop all interrupt responses except the soft interrupt mechanism, where the soft interrupt mechanism is used for the master core and each slave core to perform firmware switching synchronization.

[0092] Specifically, the master core suspends all external hardware interrupt responses except for the soft interrupt mechanism by configuring the interrupt controller's mask register. Hardware interrupts, such as those triggered by timers and I / O devices, are temporarily disabled to prevent external events from interfering with operational flow during the firmware switch. The soft interrupt mechanism, however, remains as a dedicated communication channel between the master core and slave cores. It is triggered by software instructions and synchronizes the cores using a specific flag in shared memory.

[0093] Specifically, after stopping all interrupt responses except the soft interrupt mechanism, each slave core is controlled to jump to the entry address of a predefined interrupt service routine through a hard interrupt, so that each slave core executes the interrupt service routine, wherein the interrupt service routine is used to ensure that each slave core is in a stable state.

[0094] S303: Delete all currently running application layer tasks.

[0095] Specifically, the main control core traverses the task control block linked list and performs a deep deletion operation on each application layer task. This includes releasing the heap memory space occupied by the task, closing open file descriptors, reclaiming resources such as semaphores, and clearing the task registration information in the task scheduler.

[0096] S304: configuring the firmware start address of the target device as a preset physical address of the memory through the memory management unit, and obtaining a mapping relationship between the firmware start address and the preset physical address of the memory.

[0097] Specifically, the main control core operates the translation table register of the memory management unit to remap the target device's firmware start address to a preset physical address in the memory. By setting the base address field and permission bits of the page table entry, a new virtual address to physical address mapping relationship is established.

[0098] S305: Synchronize the mapping relationship to each slave core through a soft interrupt mechanism, so that each slave core updates the corresponding memory access context.

[0099] Specifically, the master core sends a synchronization message containing the updated memory mapping table to each slave core via a soft interrupt mechanism. Upon receiving the soft interrupt, each slave core pauses its current operation, reads the updated mapping table from shared memory, and updates its own memory management unit's translation lookaside buffer.

[0100] S306: Initialize the target firmware, create application layer tasks for the target device, and assign each application layer task to a corresponding slave core, so that each slave core configures the control information of the corresponding application layer task into the currently running task to resume running each application layer task.

[0101] Specifically, the master control core first executes the target firmware's initialization code, completing operations such as loading hardware drivers and starting system services. Subsequently, based on the new firmware's task scheduling policy, the master control core reallocates application-layer tasks, analyzing each task's characteristics, such as real-time requirements and computational intensity, and assigning them to the most appropriate slave cores. Once assigned, the master control core sends a task start instruction to each slave core. Each slave core then configures the received task control block information as the currently running task, restoring the task's execution context.

[0102] In summary, through the collaborative control mechanism of the master core and the slave core, application layer tasks are stopped in an orderly manner and resources are deeply cleaned up to avoid conflicts between old tasks and the new firmware. At the same time, tasks are dynamically allocated to the slave cores based on their characteristics, ensuring that the multi-core parallel processing capability is quickly rebuilt after the new firmware is loaded. Only soft interrupts are retained as the inter-core synchronization channel, which not only prevents interference from external hardware interrupts, but also realizes real-time communication between cores through software instructions, ensuring the atomicity of operations such as mapping relationship updates.

[0103] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.

[0104] Figure 3 This is a schematic diagram of the structure of the firmware switching device provided in the embodiment of the present application. Figure 3As shown, an embodiment of the present application also provides a firmware switching device, including: a target firmware acquisition module 301, a target firmware verification module 302, a pending command execution module 303, an application layer task deletion module 304, a firmware starting address configuration module 305 and an application layer task recovery module 306.

[0105] The target firmware acquisition module 301 is configured to receive a firmware upgrade command for a target device and acquire the target firmware according to the firmware upgrade command.

[0106] The target firmware verification module 302 is used to verify the target firmware and save the target firmware to a preset physical address in the memory after the verification passes.

[0107] The pending command execution module 303 is configured to stop processing each pending command in the command queue and continue processing the pending commands that have been taken out of the command queue.

[0108] The application layer task deletion module 304 is configured to delete the currently running application layer tasks after the existing pending commands are processed.

[0109] The firmware start address configuration module 305 is used to configure the firmware start address of the target device as a preset physical address of the memory through the memory management unit, and obtain a mapping relationship between the firmware start address and the preset physical address of the memory.

[0110] The application layer task recovery module 306 is used to initialize the target firmware according to the mapping relationship and resume running each application layer task.

[0111] In one possible implementation, the application layer task recovery module 306 is specifically configured to access the global variables stored in the memory of the target firmware based on the mapping relationship, and determine whether the target firmware has set a business uninterrupted status flag; if the target firmware has set a business uninterrupted status flag, then during the target firmware initialization process, when an access operation to the hardware configuration parameters of the target firmware is detected, determine whether the storage location of the hardware configuration parameters is a shared data segment; if the storage location of the hardware configuration parameters is a shared data segment, skip the initialization of the hardware resources associated with the hardware configuration parameters.

[0112] In one possible embodiment, the firmware switching device also includes a timeout alarm module, which is used to set a timeout threshold corresponding to each stock of pending commands according to the type and complexity of each stock of pending commands; set a timeout counter for each stock of pending commands, and monitor the execution time of each stock of pending commands in real time; when it is detected that the execution time of any stock of pending commands exceeds the corresponding timeout threshold, the switching operation of the target firmware is stopped and the timeout alarm mechanism is triggered; if the execution time of each stock of pending commands does not exceed the corresponding timeout threshold, the firmware switching process is entered.

[0113] In one possible implementation, the application layer task deletion module 304 is specifically used to call the first interface to stop the currently running application layer tasks through the real-time operating system; reset the interrupt trigger identifiers of the target device through the real-time operating system and shield the reception of external interrupt signal sources; delete the currently running application layer tasks and clear the call data of the real-time operating system.

[0114] In one possible embodiment, the firmware switching device also includes a multi-core processing module, which is used to stop the currently running application layer tasks and reset the interrupt trigger identifiers of the target device; stop all interrupt responses except the soft interrupt mechanism, wherein the soft interrupt mechanism is used for the master core and the slave cores to synchronize firmware switching; delete the currently running application layer tasks; configure the firmware start address of the target device as the preset physical address of the memory through the memory management unit, and obtain a mapping relationship between the firmware start address and the preset physical address of the memory; synchronize the mapping relationship to each slave core through the soft interrupt mechanism, so that each slave core updates the corresponding memory access context; initialize the target firmware, and create the application layer task of the target device, and assign each application layer task to the corresponding slave core, so that each slave core configures the control information of the corresponding application layer task as the currently running task to resume the operation of each application layer task.

[0115] In one possible implementation, the multi-core processing module is also used to control each slave core to jump to the entry address of a predefined interrupt service routine through a hard interrupt, so that each slave core executes the interrupt service routine, wherein the interrupt service routine is used to ensure that each slave core is in a stable state.

[0116] In one possible embodiment, the target firmware verification module 302 obtains the version number, first verification information and digital signature from the target firmware; obtains the binary data of the target firmware, and uses a preset algorithm to calculate the second verification information of the binary data; compares the first verification information and the second verification information to see whether they are consistent; if the first verification information and the second verification information are inconsistent, the verification fails and the switching operation of the target firmware is stopped; if the first verification information and the second verification information are consistent, the digital signature is verified using a pre-stored public key to determine whether the source of the target firmware is abnormal; if the source of the target firmware is determined to be abnormal, the verification fails and the switching operation of the target firmware is stopped; if the source of the target firmware is determined to be normal, the version number is checked to see if it is higher than the current firmware version; if the version number is not higher than the current firmware version, the verification fails and the switching operation of the target firmware is stopped; if the version number is higher than the current firmware version, the verification succeeds.

[0117] For the description of the features in the embodiment corresponding to the firmware switching device, reference can be made to the relevant description of the embodiment corresponding to the firmware switching method, which will not be repeated here.

[0118] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Figure 4 As shown, the electronic device provided by this embodiment includes: at least one processor 401 and a memory 402. Optionally, the electronic device further includes a communication component 403. The processor 401, the memory 402 and the communication component 403 are connected via a bus.

[0119] In a specific implementation process, at least one processor 401 executes a computer program stored in the memory 402 , so that the at least one processor 401 implements the above-mentioned firmware switching method embodiment when executing the computer program.

[0120] The specific implementation process of the processor 401 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.

[0121] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly executed by a hardware processor or by a combination of hardware and software modules within the processor.

[0122] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage.

[0123] A bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be categorized as address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.

[0124] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above-mentioned firmware switching method embodiments when running.

[0125] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0126] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned firmware switching method embodiments are implemented.

[0127] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned firmware switching method embodiments are implemented.

[0128] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0129] The above is a detailed introduction to the firmware switching method, device, equipment and storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. A firmware switching method, characterized in that: include: Receiving a firmware upgrade command for a target device, and acquiring target firmware according to the firmware upgrade command; Verifying the target firmware and saving the target firmware to a preset physical address in the memory after passing the verification; Stop processing each pending command in the command queue and continue processing the pending commands that have been taken out of the command queue; After the stored pending commands are processed, the currently running application layer tasks are deleted; Configuring the firmware start address of the target device as a preset physical address of the memory through a memory management unit, and obtaining a mapping relationship between the firmware start address and the preset physical address of the memory; Initializing the target firmware according to the mapping relationship and resuming the execution of the application layer tasks; Initializing the target firmware according to the mapping relationship and resuming the execution of each application layer task includes: According to the mapping relationship, access the global variable stored in the memory by the target firmware to determine whether the target firmware is set with a service uninterrupted status flag; If the target firmware has set a service uninterrupted status flag, then during the process of initializing the target firmware, when an access operation to the hardware configuration parameters of the target firmware is detected, determining whether the storage location of the hardware configuration parameters is a shared data segment; if the storage location of the hardware configuration parameters is a shared data segment, skipping the initialization of the hardware resources associated with the hardware configuration parameters; After the target firmware is initialized, the application layer tasks are resumed.

2. The firmware switching method according to claim 1, wherein: After continuing to process the pending commands that have been taken out of the command queue, the method further includes: Setting a timeout threshold corresponding to each of the pending commands in the inventory according to the type and complexity of the pending commands; Setting a timeout counter for each of the stored pending commands, and monitoring the execution time of each of the stored pending commands in real time; When it is detected that the execution time of any stored pending command exceeds the corresponding timeout threshold, the switching operation of the target firmware is stopped and a timeout alarm mechanism is triggered; If the execution time of each of the stored pending commands does not exceed the corresponding timeout threshold, the firmware switching process is entered.

3. The firmware switching method according to claim 1, wherein: Deleting the currently running application layer tasks includes: Calling the first interface to stop each currently running application layer task through the real-time operating system; Resetting each interrupt trigger flag of the target device and shielding the reception of external interrupt signal sources through the real-time operating system; The currently running application layer tasks are deleted, and the call data of the real-time operating system is cleared.

4. The firmware switching method according to claim 1, wherein: The processor of the target device is a multi-core processor, and the multi-core processor includes a master core and at least one slave core; Correspondingly, after the processing of the stored pending commands is completed, the method further includes: Stopping each currently running application layer task and resetting each interrupt trigger flag of the target device; Stop all interrupt responses except the soft interrupt mechanism, wherein the soft interrupt mechanism is used for the master core and each slave core to synchronize firmware switching; Deleting each currently running application layer task; Configuring the firmware start address of the target device as the preset physical address of the memory by the memory management unit, and obtaining a mapping relationship between the firmware start address and the preset physical address of the memory; Synchronizing the mapping relationship to each slave core through the soft interrupt mechanism, so that each slave core updates the corresponding memory access context; Initialize the target firmware, create application layer tasks for the target device, and assign each application layer task to a corresponding slave core, so that each slave core configures control information of the corresponding application layer task into a currently running task to resume running the application layer tasks.

5. The firmware switching method according to claim 4, characterized in that: After stopping all interrupt responses except the soft interrupt mechanism, the method further includes: Controlling each slave core to jump to an entry address of a predefined interrupt service routine through a hard interrupt, so that each slave core executes the interrupt service routine, wherein the interrupt service routine is used to ensure that each slave core is in a stable state.

6. The firmware switching method according to claim 1, wherein: The verifying the target firmware includes: Obtaining a version number, first verification information, and a digital signature from the target firmware; Obtaining binary data of the target firmware, and calculating second verification information of the binary data using a preset algorithm; comparing the first verification information with the second verification information to determine whether they are consistent; If the first verification information is inconsistent with the second verification information, the verification fails and the switching operation of the target firmware is stopped; If the first verification information is consistent with the second verification information, verifying the digital signature using a pre-stored public key to determine whether the source of the target firmware is abnormal; If it is determined that the source of the target firmware is abnormal, the verification fails and the switching operation of the target firmware is stopped; If it is determined that the source of the target firmware is normal, then checking whether the version number is higher than the current firmware version; If the version number is not higher than the current firmware version, the verification fails and the switching operation of the target firmware is stopped; If the version number is higher than the current firmware version, the verification is successful.

7. A firmware switching device, characterized in that: include: A target firmware acquisition module is configured to receive a firmware upgrade command for a target device and acquire the target firmware according to the firmware upgrade command; A target firmware verification module is used to verify the target firmware and save the target firmware to a preset physical address in the memory after the verification passes; a pending command execution module, configured to stop processing each pending command in the command queue and continue processing the pending commands that have been taken out of the command queue; An application layer task deletion module, configured to delete each currently running application layer task after completing processing of the stored pending commands; a firmware start address configuration module, configured to configure the firmware start address of the target device as a preset physical address of the memory through a memory management unit, and obtain a mapping relationship between the firmware start address and the preset physical address of the memory; An application layer task recovery module, configured to initialize the target firmware according to the mapping relationship and resume running the application layer tasks; The application layer task recovery module is specifically configured to access the global variables stored in the memory of the target firmware according to the mapping relationship, and determine whether the target firmware has set a business uninterrupted status flag; if the target firmware has set the business uninterrupted status flag, then during the initialization of the target firmware, when an access operation to the hardware configuration parameters of the target firmware is detected, determine whether the storage location of the hardware configuration parameters is a shared data segment; If the storage location of the hardware configuration parameter is a shared data segment, the initialization of the hardware resources associated with the hardware configuration parameter is skipped; after the target firmware is initialized, the application layer tasks are resumed.

8. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the firmware switching method according to any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the firmware switching method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Firmware update with logical address remapping

    US20240427588A1