A method, device, electronic device, and storage medium for updating BIOS
By storing the data to be updated by BIOS in the operating system and using firmware to update the flag bits and capsule space, the problem that the X86 architecture BIOS cannot be updated independently is solved, and the applicability and efficiency of the independent update of the BIOS is achieved.
Patent Information
- Application Number
- CN202211297274.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-21
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-10-21
AI Technical Summary
In the prior art, the BIOS of the X86 architecture cannot be directly updated under the operating system, especially in devices without BMC or OS is not mature enough, and effective BIOS updates cannot be performed.
The firmware mirror data to be updated is stored in the EFI partition through the operating system, and the firmware update flag bits and capsule space is used to realize the independent update of the BIOS, including data transmission of storage address, size and verification, and is directly updated when the BIOS restarts.
It realizes the completion of BIOS updates without relying on external devices and firmware, which improves the applicability and efficiency of updates and reduces production costs.
Smart Images

Figure CN115658106B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, an electronic device, and a computer-readable storage medium for updating a BIOS. Background Art
[0002] With the development of communication technologies, various computer devices have become increasingly perfect and have more and more complete functions. The X86 architecture has become the most commonly used CPU (Central Processing Unit) for various computer devices due to its excellent performance advantages. For the X86 architecture, the BIOS (Basic Input Output System) is essential. Due to the continuous improvement of hardware functions, the BIOS also has more and more functions, including a series of functions such as troubleshooting, hardware initialization, firmware update, and error reporting. However, for security reasons, the X86 architecture hides the SPI interface of the BIOS Flash from the OS, resulting in the inability to directly update the BIOS under the OS (Operating System).
[0003] In the prior art, the BIOS is generally updated through an external firmware BMC (Baseboard Management Controller) or a third-party tool, which is relatively dependent on external tools and environments; in devices without a BMC or devices with an immature OS, the BIOS cannot be updated. Summary of the Invention
[0004] In view of the above problems, embodiments of the present invention are proposed to provide a method, an apparatus, an electronic device, and a computer-readable storage medium for updating a BIOS that can overcome or at least partially solve the above problems.
[0005] To solve the above problems, an embodiment of the present invention discloses a method for updating a BIOS, which is applied to a terminal device. The terminal device includes an operating system OS, a basic input output system BIOS, and a central processing unit CPU. The method includes:
[0006] The OS obtains the firmware image data to be updated of the BIOS through a preset program interface and stores the firmware image data to be updated in the EFI partition;
[0007] The OS determines the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated from the EFI partition, sends the storage address, the size of the image data, and the checksum of the image data to the BIOS, and sets the firmware update flag in the BIOS.
[0008] After the firmware update flag position is set, the OS sends a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set;
[0009] If it is determined that the firmware update flag bit is set, the BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data, and stores the corresponding firmware image data to be updated in a preset capsule space;
[0010] After the storage is completed, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the flash space of the BIOS;
[0011] After writing to the BIOS flash space, the BIOS performs an initialization operation;
[0012] After the initialization is completed, the BIOS loads the updated firmware image data.
[0013] Optionally, the method further includes:
[0014] If it is determined that the firmware update flag bit is not set, the CPU starts, and at the same time the BIOS performs an initialization operation. After the initialization is completed, the original firmware image data is loaded.
[0015] Optionally, the sending the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS includes:
[0016] The OS triggers a system management interrupt SMI through the preset program interface;
[0017] After the SMI is triggered, the OS sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI and writes them into the non-volatile random access memory NvRam of the BIOS.
[0018] Optionally, the OS triggering the system management interrupt SMI through the preset program interface includes:
[0019] The OS calls the underlying IO interface driver through the preset program interface to write an instruction for triggering the system management interrupt to the oxb2 port address of the CPU;
[0020] After receiving the instruction for triggering the system management interrupt, the CPU triggers the SMI.
[0021] Optionally, the OS sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI, including:
[0022] The OS calls the underlying IO interface driver through the preset program interface to write the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the oxb3 port address of the CPU;
[0023] The oxb3 port address sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI.
[0024] Optionally, after the step of determining that the firmware update flag bit is set, the method further includes:
[0025] The BIOS reads the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the NvRam in the PEI phase and stores them in the handover block HOB;
[0026] In the DXE phase, the BIOS establishes a corresponding number of capsule spaces according to the number of image data in the firmware image data to be updated in the HOB, and the capsule spaces are used to store different image data.
[0027] Optionally, the firmware image data to be updated includes BIOS image data, ME image data, and KR image data. The BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address, size, and checksum of the firmware image data to be updated, and stores the corresponding firmware image data to the preset capsule space, including:
[0028] The BIOS queries the preset area where the firmware image data to be updated is located in the EFI partition according to the storage address in the HOB;
[0029] The BIOS reads the BIOS image data, ME image data, and KR image data in the preset area according to the sizes and checksums of the BIOS image data, ME image data, and KR image data;
[0030] The BIOS stores the BIOS image data, ME image data, and KR image data into different preset capsule spaces respectively.
[0031] Optionally, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the BIOS flash space, including:
[0032] The present invention also discloses an updating device for BIOS, which is applied to a terminal device. The terminal device includes an operating system OS, a basic input / output system BIOS, and a central processing unit CPU. The device includes:
[0033] An acquisition module, configured to enable the OS to acquire the firmware image data to be updated of the BIOS through a preset program interface and store the firmware image data to be updated in the EFI partition;
[0034] A sending module, configured to enable the OS to determine the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated from the EFI partition, send the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the BIOS, and set the firmware update flag bit in the BIOS;
[0035] A restart module, configured to, after the firmware update flag bit is set, enable the OS to send a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set;
[0036] A storage module, configured to, if it is determined that the firmware update flag bit is set, enable the BIOS to read the corresponding firmware image data to be updated from the EFI according to the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated, and store the corresponding firmware image data to be updated in a preset capsule space;
[0037] A writing module, configured to, after the storage is completed, enable the BIOS to call the serial interface SPI to write the firmware image data to be updated in the capsule space into the flash space of the BIOS;
[0038] An initialization module, configured to, after writing to the BIOS flash space, enable the BIOS to perform an initialization operation;
[0039] A first loading module, configured to, after the initialization is completed, enable the BIOS to load the updated firmware image data.
[0040] Optionally, the device further includes:
[0041] A second loading module, configured to, if it is determined that the firmware update flag bit is not set, start the CPU. At the same time, the BIOS performs an initialization operation and loads the original firmware image data after the initialization is completed.
[0042] Optionally, the sending module includes:
[0043] A trigger sub-module for the OS to trigger a System Management Interrupt (SMI) through the preset program interface;
[0044] A sending sub-module for, after the SMI is triggered, the OS to send the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI and write them into the non-volatile random access memory (NvRam) of the BIOS.
[0045] Optionally, the trigger sub-module includes:
[0046] A first writing unit for the OS to call the underlying IO interface driver through the preset program interface to write an instruction for triggering a system management interrupt to the oxb2 port address of the CPU;
[0047] A trigger unit for the CPU to trigger the SMI after receiving the instruction for triggering a system management interrupt.
[0048] Optionally, the sending sub-module includes:
[0049] A second writing unit for the OS to call the underlying IO interface driver through the preset program interface to write the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the oxb3 port address of the CPU;
[0050] A sending unit for sending the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI from the oxb3 port address.
[0051] Optionally, the device further includes;
[0052] A reading module for the BIOS to read the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the NvRam during the PEI phase and store them in a Hand-Over Block (HOB);
[0053] An establishing module for the BIOS to establish a corresponding number of capsule spaces according to the number of image data in the firmware image data to be updated in the HOB during the DXE phase, where the capsule spaces are used to store different image data.
[0054] Optionally, the firmware image data to be updated includes BIOS image data, ME image data, and KR image data, and the storage module includes:
[0055] A query sub-module, configured to enable the BIOS to query a preset area where the firmware image data to be updated is located in the EFI partition according to the storage address in the HOB;
[0056] A reading sub-module, configured to enable the BIOS to read the BIOS image data, ME image data, and KR image data in the preset area according to the sizes and checksums of the BIOS image data, ME image data, and KR image data;
[0057] A storage sub-module, configured to enable the BIOS to store the BIOS image data, ME image data, and KR image data into different preset capsule spaces respectively.
[0058] The present invention also discloses an electronic device, including: a processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, the steps of the BIOS update method as described above are implemented.
[0059] The present invention also discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the BIOS update method as described above are implemented.
[0060] The embodiments of the present invention have the following advantages:
[0061] In the present invention, the operating system stores the obtained data to be updated in the EFI partition, and sends the storage address, size, and checksum of the data to be updated to the BIOS, so that when the BIOS needs to be updated, it can read the data to be updated according to the storage address, size, and checksum of the data to be updated, rather than obtaining the firmware image data to be updated from an external firmware; by setting the firmware update flag bit of the BIOS, when the BIOS restarts, it can determine whether it is a restart for firmware update according to the flag bit, and then determine whether the BIOS directly restarts or restarts after updating the firmware image data, without manual control, reducing the production cost; in the present invention, the capsule space is used to store the read firmware image data to be updated, and after the storage is completed, the firmware image data to be updated in the capsule space can be written into the flash space of the BIOS, thereby completing the update of the BIOS. The present invention can complete the update of the BIOS without relying on external devices and firmware, enhancing the applicability of updating the BIOS. Description of the Drawings
[0062] Figure 1 is a flowchart of the steps of a BIOS update method provided by an embodiment of the present invention;
[0063] Figure 2It is a flowchart of steps of another BIOS update method provided by an embodiment of the present invention;
[0064] Figure 3 It is a structural block diagram of a BIOS update device provided by an embodiment of the present invention. Detailed implementation manners
[0065] To make the above objects, features, and advantages of the present invention more obvious and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation manners.
[0066] Currently, for the BIOS update methods commonly used on various computer devices, in devices such as servers and switches with BMC firmware, from the perspective of unified firmware supervision and update, generally, firmware updates are completed by the BMC. The specific method is that while the BIOS SPI Flash link is connected to the X86 CPU, it is also connected to the SPI interface of the BMC. When firmware update is required, the BMC directly performs the burning and updating of the image; for some devices without BMC, generally, IBV manufacturers will provide some third-party tools for update; therefore, in some devices without BMC or with an immature OS, the BIOS cannot be updated.
[0067] Based on this, one of the core concepts of the embodiments of the present invention is to provide a BIOS update method. The operating system stores the to-be-updated data obtained into the EFI partition, and sends the storage address, size, and checksum of the to-be-updated data to the BIOS, so that when the BIOS needs to be updated, it can read the to-be-updated data according to the storage address, size, and checksum of the to-be-updated data, store the read to-be-updated firmware image data in the capsule space, and after the storage is completed, write the to-be-updated firmware image data in the capsule space into the flash space of the BIOS, thereby completing the update of the BIOS. The present invention can complete the update of the BIOS without relying on external devices and firmware, enhancing the applicability of updating the BIOS.
[0068] Refer to Figure 1 , which shows a flowchart of steps of a BIOS update method provided by an embodiment of the present invention, applied to a terminal device. The terminal device includes an operating system OS (Operating system), a basic input / output system BIOS (Basic Input Output System), and a central processing unit CPU (central processing unit). The method may include the following steps:
[0069] Step 101, the OS obtains the to-be-updated firmware image data of the BIOS through a preset program interface and stores the to-be-updated firmware image data in the EFI partition.
[0070] In the embodiment of the present invention, BIOS is a set of programs fixed to a ROM chip on the motherboard of the computer, which stores the most important basic input and output programs of the computer, the self-test program after power-on, and the system self-starting program. It can read and write specific information of system settings from CMOS. Its main function is to provide the lowest-level and most direct hardware settings and control for the computer;
[0071] The terminal device is mainly composed of devices such as a display adapter, a monitor and a keyboard. The terminal device platforms mainly include Windows terminals, Web terminals and Linux terminals. The specific type is not limited here.
[0072] The preset program interface may refer to the UEFI (Unified Extensible Firmware Interface) of the terminal device, which is used to define the software interface between the operating system and the system firmware, and is responsible for the power-on self-test (POST), contacting the operating system, and providing an interface connecting the operating system and the hardware; the EFI (EFI System partition) partition is a small partition in the FAT 32 format on the data storage device, which is used in computers that follow the Unified Extensible Firmware Interface. It is automatically generated when the Windows or Mac OS operating system is installed. When booting the PC, the UEFI firmware interface loads the basic files stored on the ESP to start the installed operating system and various utilities required to start the computer. The EFI system partition contains boot loaders, device drivers, system utilities, and some key data files that are absolutely necessary to boot Windows.
[0073] In one example, the BIOS firmware image data to be updated is burned on the CD. After the CD is driven, the OS can store the firmware image data to be updated in the EFI partition through the UEFI interface. The storage location, data size and checksum of the firmware image data to be updated can be determined in the EFI partition.
[0074] Step 102, the OS determines the storage address, size, and checksum of the firmware image data to be updated from the EFI partition, sends the storage address, size, and checksum of the firmware image data to be updated to the BIOS, and sets the firmware update flag in the BIOS.
[0075] In an embodiment of the present invention, the OS can determine the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the EFI partition, so that the BIOS can read the corresponding firmware image data to be updated according to the storage address, can read the specified image data according to the size of the image data, and can determine whether the data is consistent during the data transmission process according to the checksum of the image data. In one example, the checksum can be calculated by MD5 (Message-Digest Algorithm 5). The function of MD5 is to "compress" large-capacity information into a confidential format before signing the private key with digital signature software, so as to determine whether the data is modified or lost artificially during the data transmission process, ensuring the security of data transmission;
[0076] The firmware update flag bit is divided into unset and set. When it is unset, it means that the current BIOS does not need to be updated. When the CPU restarts next time, the BIOS directly loads the original firmware image data. When it is set, it means that the current BIOS needs to be updated. When the CPU restarts next time, the BIOS needs to update the firmware image data first and then load the updated firmware image data. The BIOS of the present invention can determine the restart method according to whether the firmware update flag bit is set, so that the firmware image data of the BIOS can be updated in time, avoiding the BIOS directly skipping the firmware image data to be updated and directly initializing when the CPU starts, improving the efficiency of BIOS update;
[0077] After the OS sends the firmware image data to be updated to the BIOS, it can set the firmware update flag bit of the BIOS, so that the BIOS can determine the startup method of the BIOS according to the firmware update flag bit when restarting next time.
[0078] Step 103, after the firmware update flag bit is set, the OS sends a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set.
[0079] In an embodiment of the present invention, the sleep restart signal means that the terminal device enters a short sleep state and then restarts. The time of the sleep state can be set according to requirements. For example, S3 means starting after sleeping for 3 seconds. After receiving the signal, the CPU sleeps for 3 seconds and then restarts and wakes up again. At the same time, the BIOS will read the firmware update flag bit to determine whether the current restart method is a normal restart or a restart for firmware image data update.
[0080] Step 104, if it is determined that the firmware update flag bit is set, the BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data, and stores the corresponding firmware image data to be updated in a preset capsule space.
[0081] In the embodiment of the present invention, the preset capsule space refers to an array used to store the firmware image data to be updated; the BIOS can read the complete firmware image data to be updated from the EFI according to the storage address of the updated firmware image data transmitted, the size of the image data, and the checksum of the image data, and then store the firmware image data to be updated in the capsule space.
[0082] Step 105, after the storage is completed, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the flash space of the BIOS.
[0083] Specifically, the BIOS flash space is used to store the loaded program. In one example, the flash space can be a FLASH flash memory. The FLASH flash memory is a type of memory device and is a non-volatile memory that can permanently store data without current supply, and its storage characteristics are equivalent to a hard disk.
[0084] Step 106, after writing to the BIOS flash space, the BIOS performs an initialization operation.
[0085] In the embodiment of the present invention, after the firmware image data to be updated is written to the BIOS flash space, the BIOS can issue a global reset Global Reset instruction to the CPU. At this time, the CPU can perform a complete restart, and at the same time, the BIOS initializes the motherboard. Initializing the motherboard includes conventional tasks such as creating interrupt vectors, setting registers, detecting some external devices, and setting hardware parameters.
[0086] Step 107, after the initialization is completed, the BIOS loads the updated firmware image data.
[0087] In the embodiment of the present invention, after the BIOS initialization is completed, the BIOS can load the latest firmware image data to complete the update of the BIOS function.
[0088] The present invention stores the to-be-updated data obtained through the operating system in the EFI partition, and sends the storage address, size, and checksum of the to-be-updated data to the BIOS, so that when the BIOS needs to be updated, it can read the to-be-updated data according to the storage address, size, and checksum of the to-be-updated data, rather than obtaining the to-be-updated firmware image data from external firmware; by setting the firmware update flag bit of the BIOS, when the BIOS restarts, it can determine whether it is a restart for firmware update according to the flag bit, and then determine whether the BIOS directly restarts or restarts after updating the firmware image data, without the need for manual control, reducing production costs; the present invention stores the read to-be-updated firmware image data in the capsule space, and after the storage is completed, the to-be-updated firmware image data in the capsule space can be written into the flash space of the BIOS, thereby completing the update of the BIOS. The present invention can complete the update of the BIOS without relying on external devices and firmware, enhancing the applicability of updating the BIOS.
[0089] Referring to Figure 2 , a step flowchart of another BIOS update method provided by an embodiment of the present invention is shown, which is applied to a terminal device. The terminal device includes an operating system OS, a basic input / output system BIOS, and a central processing unit CPU. The method may include the following steps:
[0090] Step 201, the OS obtains the to-be-updated firmware image data of the BIOS through a preset program interface and stores the to-be-updated firmware image data in the EFI partition.
[0091] Step 202, the OS determines the storage address of the to-be-updated firmware image data, the size of the image data, and the checksum of the image data from the EFI partition, and the OS triggers a system management interrupt SMI through the preset program interface.
[0092] In an embodiment of the present invention, the OS triggers the system management interrupt SMI through the preset program interface, including:
[0093] The OS calls the underlying IO interface driver through the preset program interface to write an instruction for triggering the system management interrupt to the oxb2 port address of the CPU; after receiving the instruction for triggering the system management interrupt, the CPU triggers the SMI.
[0094] In an embodiment of the present invention, SMI (System Management Interruption) is an interruption triggered by hardware and processed by the BIOS. The hardware has corresponding instructions to trigger it. After being triggered, the CPU will enter the SMM mode (System Management Mode). At this time, the execution process related to the OS will be suspended, and the ISR (interrupt service routine) registered in the BIOS will be executed. An interruption means that when the CPU is processing something, an external event (such as a change in a level, the occurrence of a pulse edge, or the overflow of a timer count, etc.) requests the CPU to process it quickly. So the CPU temporarily suspends the current work, turns to process the occurred event, and after the interruption service finishes processing the event, it returns to the place where it was suspended before and continues the original work;
[0095] There are generally two ways to trigger SMI. One is through the external SMI# pin, just like an external interruption, which is mainly triggered by external devices, such as BMC. The other is a method that can be used by software. X86 provides a port address of 0xb2. The OS can write 0xAB to the port address of 0xb2 of the CPU by calling the underlying IO interface driver through a preset program interface. After the CPU receives 0xAB, SMI is triggered.
[0096] Step 203, after SMI is triggered, the OS sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through SMI, and writes them into the non-volatile random access memory NvRam of the BIOS, and sets the firmware update flag bit in the BIOS.
[0097] In an embodiment of the present invention, NVRAM (Non-Volatile Random Access Memory) is a random access memory whose stored data does not get lost after power-off, avoiding the situation of data loss in the terminal device after power-off. There is a dedicated processor in NVRAM that moves data and will move the data to NVRAM on behalf of the CPU. Therefore, NVRAM can be randomly accessed;
[0098] SMI is a way for the OS to communicate with the BIOS. Since the SMI interrupt has the highest priority, the SMI interrupt enables the computer system to handle emergencies, improving the CPU's working efficiency. After the SMI is triggered, the OS can send the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI and write them into the NvRam. At the same time, the firmware update flag stored in the NvRam by the BIOS is set in the SMI.
[0099] In an embodiment of the present invention, the OS sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI, including:
[0100] The OS calls the underlying IO interface driver through a preset program interface to write the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the oxb3 port address of the CPU; the oxb3 port address sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI.
[0101] In a specific implementation, the OS calls the underlying IO interface driver through the UEFI interface to write the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the oxb3 port address of the CPU. Then, the oxb3 port address transfers the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the SMI. Since the SMI is an interrupt processed by the BIOS, that is, the BIOS can receive various parameters through the SMI.
[0102] Step 204, after the firmware update flag is set, the OS sends a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag is set.
[0103] Step 205, if it is determined that the firmware update flag is set, the BIOS reads the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the NvRam in the PEI stage and stores them in the Hand-Over Block (HOB).
[0104] In the embodiment of the present invention, the BIOS startup process is divided into four stages: the SEC stage, the PEI stage, the DXE stage, and the BDS stage. The SEC (Security Phase) stage is the first stage of platform initialization. After the computer system is powered on or restarted, it enters this stage to receive and process system startup and restart signals, that is, the sleep restart signal received by the CPU;
[0105] In the PEI (Pre-EFI Initialization) stage, many services have not been fully started yet, and the driver for the SPI interface is not ready either. Memory is initialized only in the later stage of PEI. Its main function is to prepare the execution environment for DXE, form a list of HOB (Handoff Block) with the information to be passed to DXE, and finally hand over the control to DXE;
[0106] In the DXE (Driver Execution Environment) stage, most of the system initialization work is performed. At this stage, memory can be fully used, so a large number of complex tasks can be carried out. From the perspective of program design, the DXE stage is similar to the PEI stage;
[0107] As the name implies, the main function of the BDS (Boot Device Select) stage is to execute the startup policy. The BIOS boots the operating system at this stage and hands over the control to the operating system.
[0108] In an embodiment of the present invention, the method further includes:
[0109] If it is determined that the firmware update flag bit is not set, the CPU starts, and at the same time, the BIOS performs initialization operations. After the initialization is completed, the original firmware image data is loaded.
[0110] In an embodiment of the present invention, after the CPU receives the hibernation restart signal, it starts. At the same time, when the BIOS determines that the firmware update flag bit is not set, it means that there is no firmware image data to be updated in the BIOS at this time, which is a restart under normal circumstances. The initialization operation can be directly performed, and the original firmware image data is loaded after the operation is completed.
[0111] Step 206, in the DXE stage of the BIOS, according to the number of mirror data in the firmware image data to be updated in the HOB, a corresponding number of capsule spaces are established. According to the storage address, size, and checksum of the mirror data of the firmware image data to be updated, the corresponding firmware image data to be updated is read from the EFI, and the corresponding firmware image data to be updated is stored in the preset capsule spaces. The capsule spaces are used to store different mirror data.
[0112] In an embodiment of the present invention, corresponding capsule spaces can be established according to the number of mirror data in the HOB. For example, if there are three firmware images to be updated in the HOB, three capsule spaces can be established to store different data to be updated respectively. By establishing different capsule spaces to store different firmware image data to be updated, the present invention can avoid reading errors when the BIOS updates and reads.
[0113] In an embodiment of the present invention, the firmware image data to be updated includes BIOS image data, ME image data, and KR image data. The BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address, size, and checksum of the firmware image data to be updated, and stores the corresponding firmware image data to be updated in a preset capsule space, including:
[0114] The BIOS queries the preset area where the firmware image data to be updated is located in the EFI partition according to the storage address in the HOB; the BIOS reads the BIOS image data, ME image data, and KR image data in the preset area according to the sizes and checksums of the BIOS image data, ME image data, and KR image data; the BIOS stores the BIOS image data, ME image data, and KR image data into different preset capsule spaces respectively.
[0115] In the embodiment of the present invention, the preset area refers to the area where the firmware image data to be updated is stored in the EFI partition. The BIOS can query the preset area where the firmware image data to be updated is located in the EFI partition according to the storage address, then reads the accurate firmware image data to be updated according to the size of the data, then calculates the checksum of the read firmware image data to be updated, and compares the calculated checksum with the checksum in the HOB. If they are consistent, there is no abnormality in the data transmission process. If they are inconsistent, it means that the data has changed or been damaged during the transmission process. At this time, the firmware image data to be updated can be stopped from being stored in the corresponding capsule space;
[0116] In an example, the firmware image data to be updated includes BIOS image data, ME image data, and KR image data. Since there are various types of data stored in the HOB, the preset areas in the EFI partition where they are located can be queried first according to the storage addresses of the respective image data, then the corresponding BIOS image data, ME image data, and KR image data can be read according to the sizes of the respective firmware image data to be updated, and then the corresponding checksums are calculated respectively based on the read BIOS image data, ME image data, and KR image data, and compared with the checksums of the respective data stored in the HOB to ensure the security of data transmission.
[0117] Step 207, after the storage is completed, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the flash memory space of the BIOS.
[0118] In an embodiment of the present invention, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the BIOS flash memory space, including:
[0119] The BIOS calls the serial interface SPI to write the BIOS image data, ME image data, and KR image data in the capsule space into the BIOS flash memory space in the order of storage.
[0120] Specifically, when the storage order of the BIOS image data, ME image data, and KR image data in the capsule space is to store the BIOS image data first, then the ME image data, and finally the KR image data, the writing order into the BIOS flash memory space is also to store the BIOS image data first, then the ME image data, and finally the KR image data, so as to avoid data chaos caused by inconsistent order during the data writing process.
[0121] In an embodiment of the present invention, the BIOS can also call the serial interface SPI to write any mirror data in the capsule space into the BIOS flash memory space to achieve single firmware update.
[0122] In an example, when the selected mirror data is the KR mirror, the BIOS calls the serial interface SPI to write the KR mirror in the capsule space into the BIOS flash memory space, then performs an initialization operation, and after the initialization is completed, loads the updated KR mirror; when the selected mirror data is the ME mirror, the BIOS calls the serial interface SPI to write the ME mirror in the capsule space into the BIOS flash memory space, then performs an initialization operation, and after the initialization is completed, loads the updated ME mirror; when the selected mirror data is the BIOS mirror, the BIOS calls the serial interface SPI to write the BIOS mirror in the capsule space into the BIOS flash memory space, then performs an initialization operation, and after the initialization is completed, loads the updated BIOS mirror; The present invention can update any mirror data in the firmware mirror data to be updated according to user needs, improving the pertinence of BIOS update, providing convenience for users, and enabling users to perform firmware update of the BIOS according to their own needs.
[0123] Step 208, after writing into the BIOS flash memory space, the BIOS performs an initialization operation.
[0124] Step 209, after the initialization is completed, the BIOS loads the updated firmware mirror data.
[0125] The present invention stores the to-be-updated data obtained through the operating system in the EFI partition, and sends the storage address, size, and checksum of the to-be-updated data to the BIOS, so that when the BIOS needs to be updated, it can read the to-be-updated data according to the storage address, size, and checksum of the to-be-updated data, rather than obtaining the to-be-updated firmware image data from external firmware; by setting the firmware update flag bit of the BIOS, when the BIOS restarts, it can determine whether it is a restart for firmware update according to the flag bit, and then determine whether the BIOS directly restarts or restarts after updating the firmware image data, without the need for manual control, reducing the production cost; the present invention stores the read to-be-updated firmware image data in the capsule space, and after the storage is completed, the to-be-updated firmware image data in the capsule space can be written into the flash space of the BIOS, thereby completing the update of the BIOS. The present invention can complete the update of the BIOS without relying on external devices and firmware, enhancing the applicability of updating the BIOS.
[0126] It should be noted that for the method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the embodiments of the present invention are not limited by the described action sequence, because according to the embodiments of the present invention, certain steps can be performed in other sequences 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 involved are not necessarily essential for the embodiments of the present invention.
[0127] Refer to Figure 3 , which shows the structural block diagram of an update device for a BIOS provided by an embodiment of the present invention, and specifically may include the following modules:
[0128] An acquisition module 301, configured to obtain the to-be-updated firmware image data of the BIOS by the OS through a preset program interface, and store the to-be-updated firmware image data in the EFI partition;
[0129] A sending module 302, configured to determine the storage address of the to-be-updated firmware image data, the size of the image data, and the checksum of the image data from the EFI partition by the OS, send the storage address of the to-be-updated firmware image data, the size of the image data, and the checksum of the image data to the BIOS, and set the firmware update flag bit in the BIOS;
[0130] A restart module 303, configured to send a sleep restart signal to the CPU by the OS after the firmware update flag bit is set, and after the CPU receives the sleep restart signal, it exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set;
[0131] A storage module 304, configured to, if it is determined that the firmware update flag bit is set, the BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data, and stores the corresponding firmware image data to be updated in a preset capsule space;
[0132] A writing module 305, configured to, after the storage is completed, the BIOS calls the serial peripheral interface SPI to write the firmware image data to be updated in the capsule space into the flash space of the BIOS;
[0133] An initialization module 306, configured to, after writing to the BIOS flash space, the BIOS performs an initialization operation;
[0134] A first loading module 307, configured to, after the initialization is completed, the BIOS loads the updated firmware image data.
[0135] In an embodiment of the present invention, the apparatus further includes:
[0136] A second loading module, configured to, if it is determined that the firmware update flag bit is not set, the CPU starts, and at the same time the BIOS performs an initialization operation, and loads the original firmware image data after the initialization is completed.
[0137] In an embodiment of the present invention, the sending module 302 includes:
[0138] A triggering sub-module, configured to the OS triggers a system management interrupt SMI through the preset program interface;
[0139] A sending sub-module, configured to, after the SMI is triggered, the OS sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI and writes them into the non-volatile random access memory NvRam of the BIOS.
[0140] In an embodiment of the present invention, the triggering sub-module includes:
[0141] A first writing unit, configured to the OS calls a low-level IO interface driver through the preset program interface to write an instruction for triggering a system management interrupt to the oxb2 port address of the CPU;
[0142] A triggering unit, configured to, after the CPU receives the instruction for triggering a system management interrupt, trigger the SMI.
[0143] In an embodiment of the present invention, the sending sub-module includes:
[0144] A second writing unit, configured to write, by the OS through the preset program interface to call the underlying IO interface driver, the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the oxb3 port address of the CPU.
[0145] A sending unit, configured to send, by the oxb3 port address, the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI.
[0146] In an embodiment of the present invention, the apparatus further includes;
[0147] A reading module, configured to read, by the BIOS in the PEI stage, the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the NvRam and store them in a handover block HOB.
[0148] A building module, configured to build, by the BIOS in the DXE stage, a corresponding number of capsule spaces according to the number of image data in the firmware image data to be updated in the HOB, where the capsule spaces are used to store different image data.
[0149] In an embodiment of the present invention, the firmware image data to be updated includes BIOS image data, ME image data, and KR image data, and the storage module includes:
[0150] A query sub-module, configured to query, by the BIOS according to the storage address in the HOB, a preset area where the firmware image data to be updated is located in the EFI partition.
[0151] A reading sub-module, configured to read, by the BIOS according to the sizes and checksums of the BIOS image data, ME image data, and KR image data, the BIOS image data, ME image data, and KR image data in the preset area.
[0152] A storing sub-module, configured to store, by the BIOS, the BIOS image data, ME image data, and KR image data into different preset capsule spaces respectively.
[0153] In an embodiment of the present invention, the writing module 305 includes:
[0154] A writing sub-module, configured to write, by the BIOS calling the serial interface SPI, the BIOS image data, ME image data, and KR image data in the capsule spaces into the BIOS flash space in the storage order.
[0155] The present invention discloses a BIOS update device, including: an acquisition module, a sending module, a restart module, a storage module, a writing module, an initialization module, and a first loading module. The present invention stores the acquired data to be updated in the EFI partition through an operating system, so that when the BIOS needs to be updated, the data to be updated can be read according to the storage address, size, and checksum of the data to be updated, rather than obtaining the firmware image data to be updated from an external firmware. By setting the firmware update flag bit of the BIOS, when the BIOS restarts, it can determine whether it is a restart for firmware update according to the flag bit, and then determine whether the BIOS directly restarts or restarts after updating the firmware image data, without the need for manual control, reducing production costs. The present invention stores the read firmware image data to be updated in a capsule space, and after the storage is completed, the firmware image data to be updated in the capsule space can be written into the flash memory space of the BIOS, thereby completing the update of the BIOS. The update of the BIOS can be completed without relying on external devices and firmware, enhancing the applicability of updating the BIOS.
[0156] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For the related parts, please refer to the partial description of the method embodiment.
[0157] The embodiment of the present invention further provides an electronic device, including:
[0158] including a processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, it implements each process of the above-mentioned BIOS update method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0159] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by the processor, it implements each process of the above-mentioned BIOS update method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0160] Each embodiment in this specification is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other.
[0161] Those skilled in the art should understand that the embodiments of the present invention may be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0162] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be realized by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing terminal devices generate a device for realizing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0163] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device realizes the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0164] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device, such that a series of operation steps are executed on the computer or other programmable terminal device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable terminal device provide steps for realizing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0165] Although the preferred embodiments of the present invention have been described, those skilled in the art can make additional changes and modifications once they know the basic creative concept. Therefore, the appended claims are intended to be construed as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.
[0166] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or terminal device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or terminal device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or terminal device comprising said element.
[0167] The above has introduced in detail a method, apparatus, electronic device, and computer-readable storage medium for updating a BIOS provided by the present invention. Specific examples are used in this text to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.
Claims
1. A method for updating BIOS, applied to a terminal device, the terminal device including an operating system OS, a basic input / output system BIOS, and a central processing unit CPU, characterized in that, The method includes: The OS obtains the firmware image data to be updated of the BIOS through a preset program interface and stores the firmware image data to be updated in the EFI partition; The OS determines the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated from the EFI partition, sends the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the BIOS, and sets the firmware update flag bit in the BIOS; After the firmware update flag bit is set, the OS sends a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set; If it is determined that the firmware update flag bit is set, the BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated, and stores the corresponding firmware image data to be updated in a preset capsule space; After the storage is completed, the BIOS calls the serial interface SPI to write the firmware image data to be updated in the capsule space into the flash space of the BIOS; After writing to the BIOS flash space, the BIOS performs an initialization operation; After the initialization is completed, the BIOS loads the updated firmware image data; The sending the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the BIOS includes: The OS triggers a system management interrupt SMI through the preset program interface; After the SMI is triggered, the OS sends the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the BIOS through the SMI and writes them into the non-volatile random access memory NvRam of the BIOS.
2. The method according to claim 1, wherein The method further includes: If it is determined that the firmware update flag bit is not set, the CPU starts, and at the same time, the BIOS performs an initialization operation. After the initialization is completed, the original firmware image data is loaded.
3. The method according to claim 1, wherein The OS triggers a system management interrupt SMI through the preset program interface, including: The OS calls the underlying IO interface driver through the preset program interface to write an instruction for triggering the system management interrupt to the oxb2 port address of the CPU; After receiving the instruction for triggering the system management interrupt, the CPU triggers the SMI.
4. The method according to claim 3, characterized in that, The OS sends the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the BIOS through the SMI, including: The OS calls the underlying IO interface driver through the preset program interface to write the storage address, the size of the image data, and the checksum of the image data of the firmware image data to be updated to the oxb3 port address of the CPU. The oxb3 port address sends the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI.
5. The method according to claim 1, characterized in that, After the step of determining that the firmware update flag bit is set, the method further includes: In the PEI phase, the BIOS reads the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the NvRam and stores them in the Hand-Off Block (HOB). In the DXE phase, the BIOS creates a corresponding number of capsule spaces according to the number of image data in the firmware image data to be updated in the HOB, and the capsule spaces are used to store different image data.
6. The method according to claim 5, characterized in that, The firmware image data to be updated includes BIOS image data, ME image data, and KR image data. The BIOS reads the corresponding firmware image data to be updated from the EFI according to the storage address, the size of the image data, and the checksum of the image data, and stores the corresponding firmware image data to a preset capsule space, including: The BIOS queries the preset area where the firmware image data to be updated is located in the EFI partition according to the storage address in the HOB. The BIOS reads the BIOS image data, ME image data, and KR image data in the preset area according to the sizes and checksums of the BIOS image data, ME image data, and KR image data. The BIOS stores the BIOS image data, ME image data, and KR image data into different preset capsule spaces respectively.
7. A BIOS update device is applied to a terminal device, where the terminal device includes an operating system (OS), a basic input / output system (BIOS), and a central processing unit (CPU). It is characterized in that The device includes: An acquisition module, configured to enable the OS to obtain the firmware image data to be updated of the BIOS through a preset program interface and store the firmware image data to be updated in the EFI partition. A sending module, configured to enable the OS to determine the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data from the EFI partition, send the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS, and set the firmware update flag bit in the BIOS. A restart module, configured to, after the firmware update flag bit is set, enable the OS to send a sleep restart signal to the CPU. After receiving the sleep restart signal, the CPU exits the sleep mode and restarts. At the same time, the BIOS determines whether the firmware update flag bit is set. A storage module, configured to, if it is determined that the firmware update flag bit is set, enable the BIOS to read the corresponding firmware image data to be updated from the EFI according to the storage address, the size of the image data, and the checksum of the image data, and store the corresponding firmware image data to a preset capsule space. A writing module, configured to, after the storage is completed, enable the BIOS to call the Serial Peripheral Interface (SPI) to write the firmware image data to be updated in the capsule space into the flash memory space of the BIOS. An initialization module, which is used for the BIOS to perform an initialization operation after writing to the BIOS flash space; A first loading module, which is used for the BIOS to load the updated firmware image data after the initialization is completed; The sending module includes: A trigger sub-module, which is used for the OS to trigger a system management interrupt SMI through the preset program interface; A sending sub-module, which is used for the OS to send the storage address of the firmware image data to be updated, the size of the image data, and the checksum of the image data to the BIOS through the SMI after the SMI is triggered, and write them into the non-volatile random access memory NvRam of the BIOS.
8. An electronic device, characterized in that, It includes: A processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, the steps of the BIOS update method described in any one of claims 1-6 are implemented.
9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the steps of the BIOS update method described in any one of claims 1-6 are implemented.
Citation Information
Patent Citations
Capsule type custom-made updating method based on unified extensible firmware interface firmware system
CN103207797A
Microprocessor, BIOS firmware updating method, computer equipment and storage medium
CN114721693A