Method, system, terminal and storage medium for indirectly accessing an SPI storage device
By registering a service program in the BIOS, encapsulating the SPI access code, and defining the I/O port, upper-layer applications are allowed to indirectly access the SPI storage device. This solves the problem of upper-layer application software having difficulty accessing the SPI storage device, avoids the risk of device damage, and improves system stability.
Patent Information
- Application Number
- CN202211181645.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-27
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-09-27
AI Technical Summary
Upper-layer application software in a computer system has difficulty directly accessing SPI storage devices, and misoperation may damage the BIOS firmware, causing the computer to fail to boot.
The service program is registered in the underlying firmware BIOS, which encapsulates the access code for the SPI protocol and timing requirements, and defines the trigger commands and agreed I/O ports, allowing upper-layer applications to indirectly access the SPI storage device through simple I/O instructions.
This enables upper-layer applications to securely access SPI storage devices without requiring hardware expertise, avoiding the risk of device damage and improving system stability.
Smart Images

Figure CN115686647B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer software technology, and in particular relates to a method, system, terminal and storage medium for indirectly accessing SPI storage devices. Background Technology
[0002] Accessing storage devices (SPI storage devices) mounted on the SPI (Serial Peripheral Interface) bus by upper-layer application software in a computer system requires strict adherence to SPI bus timing and protocol requirements. For upper-layer application software developers lacking hardware fundamentals and low-level driver development experience, reading from SPI storage devices is an extremely complex and difficult task. Furthermore, SPI storage devices typically store the computer's most crucial low-level firmware, the BIOS (Basic Input & Output System). Even slight mishandling of SPI storage by upper-layer applications can corrupt the BIOS firmware, a catastrophic consequence for the user, rendering the computer unusable and requiring repair or replacement. Summary of the Invention
[0003] The purpose of this invention is to provide a method, system, terminal, and storage medium for indirectly accessing an SPI storage device.
[0004] This invention provides a method for indirectly accessing an SPI storage device, the method being as follows:
[0005] A service program is registered in the underlying firmware BIOS. This service program encapsulates access code that can access the SPI storage device according to the SPI protocol and timing requirements, defines trigger commands to activate the service program, and specifies agreed-upon I / O ports for access by upper-layer applications. These agreed-upon I / O ports include a data port for exchanging data with the upper-layer application, an address port specifying the physical address of the SPI storage device, a data length port, a control port for executing commands, and a status port for checking the success of the current operation. The trigger commands include read, write, erase, lock, and unlock commands. The upper-layer application can be any of the following: an application program, driver, batch program, or script that can run under an operating system.
[0006] The upper-layer application triggers the service program to access the SPI device by writing a trigger command defined by the service program to the agreed IO port. After the service program is triggered, it accesses the SPI device through the following steps: a) determining whether the agreed IO port is valid; b) determining whether the SPI device allows access; c) determining the type of the trigger command and performing the corresponding operation.
[0007] Preferably, the service program is a system management interrupt service program.
[0008] A system for implementing the method of indirectly accessing an SPI storage device as described in any of the preceding claims, characterized in that it includes a low-level firmware BIOS unit and an upper-level application unit. The low-level firmware BIOS unit has a service program registered therein. The service program encapsulates code that can access the SPI storage device according to the SPI protocol and timing requirements, defines a trigger command to trigger the service program, and agrees on a designated I / O port for access by the upper-level application unit. The upper-level application unit triggers the service program to access the SPI device by writing the trigger command defined by the service program into the designated I / O port.
[0009] A terminal for indirectly accessing an SPI storage device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method as described in any of the preceding claims.
[0010] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method as described in any of the preceding claims.
[0011] Beneficial effects:
[0012] This invention registers a service program in the underlying firmware BIOS to access SPI storage devices. The service program encapsulates code that accesses the SPI storage device according to the SPI protocol and timing requirements, defines trigger commands to activate the service program, and specifies agreed-upon I / O ports for upper-layer applications. The upper-layer application triggers the service program to access the SPI device by writing the defined trigger commands to the agreed-upon I / O ports. The upper-layer application can indirectly access the SPI storage device without needing complex hardware knowledge such as the SPI protocol and timing requirements. This allows upper-layer application developers to access data in the SPI storage device without requiring hardware knowledge or low-level driver development experience, and also avoids damage to the SPI storage device due to accidental operation. Attached Figure Description
[0013] Figure 1 This is a principle block diagram of an embodiment of the present invention;
[0014] Figure 2 This is a flowchart illustrating the process of registering a service program in the underlying firmware BIOS according to an embodiment of the present invention.
[0015] Figure 3 This is a simplified flowchart of the service program accessing the SPI device according to an embodiment of the present invention; Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0017] The specific implementation of the present invention will be described in detail below with reference to specific embodiments:
[0018] like Figures 1 to 3 As shown, a method for indirectly accessing an SPI storage device is described below:
[0019] The service routine is registered in the underlying firmware program BIOS. As the underlying firmware program of the computer, the BIOS starts executing when the user presses the power button. The BIOS is responsible for the self-test, initialization, resource allocation, and providing various interrupt service routines residing in memory for upper-level applications to call. At this point, the underlying firmware program BIOS can be divided into "SPI BIOS area" and "SPI other areas," both of which are address spaces within the SPI storage device. They can be separate independent areas or nested related areas. The service routine is registered in the SPI BIOS area. Here, the selected service routine is the System Management Interrupt (SMI) service routine, and its registration process is as follows: Figure 2As shown, the service program encapsulates access code that can access the SPI storage device according to the SPI protocol and timing requirements, defines a trigger command to activate the service program, and specifies the agreed-upon I / O ports for access by upper-layer applications. The access code is written according to the SPI protocol and timing requirements; that is, in the underlying firmware BIOS, the program code for accessing the SPI storage device is written according to the SPI protocol and timing requirements and encapsulated into SPI Software. The SMI service program; trigger commands are used to trigger the service program to perform corresponding operations. These trigger commands include read, write, erase, lock, and unlock commands. Trigger commands perform read and write operations on computer hardware resources by manipulating I / O ports. A read command reads the number of bytes specified by the data length port from the SPI storage device at the address specified by the address port, according to the SPI protocol and timing requirements. A write command writes the data from the data port to the SPI storage device at the address specified by the address port and the data length specified by the data length port, according to the SPI protocol and timing requirements. An erase command writes 0x00 to the SPI storage device at the address specified by the address port and the data length specified by the data length port, according to the SPI protocol and timing requirements. A lock command writes the lock data agreed upon with the upper-layer application to the agreed address in the SPI storage device, according to the SPI protocol and timing requirements. The unlock command, according to the SPI protocol and timing requirements, writes the unlock data agreed upon with the upper-layer application into the designated address within the SPI storage device. The agreed-upon I / O port refers to the system I / O interface, i.e., the I / O port resources in the computer. This can be a designated, unused port on the computer, defined as the I / O interface used by the SPI Software SMI, such as the fixed Software SMI port 0xB2 on an x86 computer system. In this case, the agreed-upon I / O port includes a data port for exchanging data with the upper-layer application, an address port specifying the physical address of the SPI storage device, a data length port, a control port for executing commands, and a status port for checking the success of the current operation. Thus, by agreeing on the I / O port, the service program can indirectly access the SPI storage device.
[0020] The upper-layer application accesses the SPI device by writing trigger commands defined by the service program to the designated I / O port. The upper-layer application can be any application, driver, batch program, or script that runs under an operating system, such as DOS, UEFI Shell, Linux, Unix, Windows, etc. After entering the operating system, the upper-layer application only needs to write the agreed-upon trigger commands to the designated I / O port to access the SPI storage device. The upper-layer application developer does not need to understand the complex SPI timing, protocol, or other underlying implementation details; they only need to operate the given I / O ports and use a few simple I / O instructions to access the data in the SPI storage device. The service program registered in the underlying firmware BIOS, namely the SPI Software SMI service program, only responds to predefined commands and operation methods. Undefined commands and operation methods are terminated by the running SPI Software SMI service program, which returns relevant error codes for the upper-layer application developer to review and debug, preventing catastrophic consequences such as damage to the SPI storage device due to misoperation and rendering the computer unusable.
[0021] Further improvements include the following steps, after the service program is triggered, to access the SPI device: a) Determine if the agreed-upon I / O port is valid. This involves first determining if the command on the control port is valid, i.e., whether the command is predefined. If it is defined, it is valid, and the next step continues. If it is invalid, the error type is recorded on the status port, and the service program is terminated, returning to the service program call point. After determining if the command on the control port is valid, the address on the address port is then determined to be valid, i.e., whether the address exceeds the predefined address range. If valid, the next step continues; otherwise, the error type is recorded on the status port, and the service program is terminated, returning to the service program call point. b) Determine if the SPI device is allowed to access. This involves determining if the SPI storage device is allowed to access, i.e., whether the address is locked. If unlocked, the next step, i.e., the operation to be performed by the triggered command, continues. If locked, the error type is recorded on the status port, and the service program is terminated, returning to the service program call point. c) Determine the type of the triggered command and perform the corresponding operation. For read operations, determine if the read was successful. If successful, store the read data in the data port for direct access by the upper-layer application via the agreed-upon I / O port, record the success on the status port, terminate the service program, and return to the service program caller. If it fails, record the error type on the status port, terminate the service program, and return to the service program caller. For write operations, determine if the write was successful. If successful, record the success on the status port, terminate the service program, and return to the service program caller. If it fails, record the error type on the status port, terminate the service program, and return to the service program caller. For erase operations, determine if the erase was successful. If successful, record the success on the status port, terminate the service program, and return to the service program caller. If it fails, record the error type on the status port, terminate the service program, and return to the service program caller. The system records the error type on the status port, terminates the execution of the service program, and returns to the service program caller. For lock operation commands, it checks whether the lock was successful. If successful, it records success on the status port, terminates the execution of the service program, and returns to the service program caller. If it fails, it records the error type on the status port, terminates the execution of the service program, and returns to the service program caller. For unlock operation commands, it checks whether the unlock was successful. If successful, it records success on the status port, terminates the execution of the service program, and returns to the service program caller. If it fails, it records the error type on the status port, terminates the execution of the service program, and returns to the service program caller. All other operation commands besides those mentioned above are considered invalid commands. The system records the error type on the status port, terminates the execution of the service program, and returns to the service program caller.
[0022] A system for indirectly accessing an SPI storage device is characterized by comprising a low-level firmware BIOS unit and an upper-level application unit. The low-level firmware BIOS unit registers a service program, which encapsulates code capable of accessing the SPI storage device according to the SPI protocol and timing requirements, defines trigger commands to activate the service program, and agrees on designated I / O ports for access by the upper-level application unit. The upper-level application unit triggers the service program to access the SPI device by writing the trigger commands defined by the service program onto the agreed-upon I / O ports. By registering the service program (i.e., the SPI Software SMI service program) in the low-level firmware BIOS unit and then agreeing on ports and trigger commands with the upper-level application unit, the upper-level application developer does not need to understand the complex underlying implementation details of SPI timing and protocols. They only need to operate the given I / O ports; a few simple I / O instructions, i.e., the trigger commands, can access the data in the SPI storage device, avoiding the catastrophic consequence of accidental damage to the SPI storage device and rendering the computer unusable.
[0023] A terminal for indirectly accessing an SPI storage device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method as described in any of the preceding claims.
[0024] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method as described in any of the preceding claims, the storage medium including RAM, ROM, EPROM, EEPROM, flash memory or other solid-state memory technologies, CD-ROM, DVD or other optical storage, magnetic tape, disk storage or other magnetic storage devices.
[0025] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for indirectly accessing an SPI storage device, characterized in that, The method is as follows: A service program is registered in the underlying firmware BIOS. This service program encapsulates access code that can access the SPI storage device according to the SPI protocol and timing requirements, defines trigger commands to activate the service program, and specifies agreed-upon I / O ports for access by upper-layer applications. These agreed-upon I / O ports include a data port for exchanging data with the upper-layer application, an address port specifying the physical address of the SPI storage device, a data length port, a control port for executing commands, and a status port for checking the success of the current operation. The trigger commands include read, write, erase, lock, and unlock commands. The upper-layer application can be any of the following: an application, driver, batch program, and script that can run under an operating system. The upper-layer application triggers the service program to access the SPI device by writing a trigger command defined by the service program to the agreed IO port. After the service program is triggered, it accesses the SPI device through the following steps: a) determining whether the agreed IO port is valid; b) determining whether the SPI device allows access; c) determining the type of the trigger command and performing the corresponding operation.
2. The method for indirectly accessing an SPI storage device as described in claim 1, characterized in that, The service program is the system management interrupt service program.
3. A system for implementing the method for indirectly accessing an SPI memory device as described in claim 1 or 2, characterized in that, It includes a low-level firmware BIOS unit and an upper-level application unit. The low-level firmware BIOS unit has a registered service program. The service program encapsulates code that can access the SPI storage device according to the SPI protocol and timing requirements, defines a trigger command to trigger the service program, and agrees on a conventional I / O port for the upper-level application to access. The upper-level application unit triggers the service program to access the SPI device by writing the trigger command defined by the service program into the conventional I / O port.
4. A terminal for indirectly accessing an SPI storage device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 2.
5. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 2.
Citation Information
Patent Citations
Flash data access method and related equipment
CN114218129A