CN113703920B - Hardware simulation method and platform - Google Patents

Hardware simulation method and platform Download PDF

Info

Publication number
CN113703920B
CN113703920B CN202111000101.5A CN202111000101A CN113703920B CN 113703920 B CN113703920 B CN 113703920B CN 202111000101 A CN202111000101 A CN 202111000101A CN 113703920 B CN113703920 B CN 113703920B
Authority
CN
China
Prior art keywords
hardware
file system
firmware
ramdisk
image
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111000101.5A
Other languages
Chinese (zh)
Other versions
CN113703920A (en
Inventor
李宏勇
刘勇刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fiberhome Telecommunication Technologies Co Ltd
Original Assignee
Fiberhome Telecommunication Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fiberhome Telecommunication Technologies Co Ltd filed Critical Fiberhome Telecommunication Technologies Co Ltd
Priority to CN202111000101.5A priority Critical patent/CN113703920B/en
Publication of CN113703920A publication Critical patent/CN113703920A/en
Application granted granted Critical
Publication of CN113703920B publication Critical patent/CN113703920B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a hardware simulation method and a platform, wherein the method comprises the following steps: manufacturing a packaging adapting firmware of hardware to be simulated, wherein the packaging adapting firmware comprises a head script, middle data and tail version information; loading an RAMDISK file system image and packaging adaptation firmware, executing a head script, and judging whether to inject the packaging adaptation firmware into the RAMDISK file system image according to tail version information; for the RAMDISK file system mirror image injected with the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system mirror image, and updating the RAMDISK file system mirror image of the hardware to be simulated; and migrating the middle data in the updated RAMDISK file system image of the hardware to be simulated to a root file system, running a user program in the environment of the root file system, and starting the user program of the hardware to be simulated to obtain a simulation result. The simulation method has strong compatibility and can highly simulate the use scene of the physical hardware platform.

Description

Hardware simulation method and platform
Technical Field
The invention belongs to the field of computer hardware simulation, and particularly relates to a hardware simulation method and a platform.
Background
Due to cost, manufacturing, maintenance and other reasons, resources of the hardware platform are often lacking in the development and testing processes of the product software, and in order to improve the delivery efficiency and the software quality of the product, the hardware platform is often required to be subjected to full-system virtualization simulation. The hardware simulation platform of the whole system can provide a large amount of simulation hardware resources based on limited server resources, and meets the development and test verification requirements of user software before the hardware platform finishes production and manufacture or when the resources are insufficient. Virtual operating system Simulators (QEMUs) are currently widely used open source hardware virtualization technology, and have the advantages of being cross-platform, high-speed, portable, and the like, and the QEMUs serve as a virtual machine monitor (virtual machine monitor, VMM) on a host computer, simulate a CPU processor through dynamic binary conversion, and provide a series of hardware models. In addition, the QEMU can also combine with Kernel-based virtual machine (Kernel-based Virtual Machine, KVM) technology to realize hardware virtualization acceleration, so that the performance of the simulation platform processor is close to that of an actual physical device.
Although QEMU technology has strong hardware simulation capability, there are often a wide variety of hardware modules in a complete hardware system, and if QEMU is used to implement hardware simulation of the whole system, the required manpower and time costs are enormous. The hardware simulated based on the QEMU open source technology has the advantages that the direct interaction object is a kernel, so that the simulated hardware is obtained by abstract modeling of the logic of the actual hardware, and the logic behavior of the simulated hardware is completely consistent with that of the actual hardware for kernel codes. The physical devices covered by a hardware platform of a whole system are usually very many, and besides core units such as a processor, a peripheral controller and the like, the periphery is also usually provided with a hardware module with special functions, so that QEMU simulation of all hardware in the system is realized, the modeling difficulty is large, the workload is great, and the rapid iteration of the hardware platform is difficult to adapt.
For the complete running and testing of the user program, if the QEMU cannot realize the simulation of all hardware in the system, the incompleteness of the hardware simulation makes the binary code of the user program often unable to run directly on the hardware simulation platform. At this time, there are generally two common treatments:
a user program suitable for operating a simulation platform is modified and generated based on source codes, but the application is poor in applicability, the code maintenance workload of application software developers is increased, and the purpose of verifying the software operation effect of physical equipment based on a simulation environment is difficult to achieve.
And the other is to generate only the adaptation file of the difference part based on the source code, and enable the existing user program to run in the simulation environment through hot patching or replacement after the system is started. This approach has a significant limitation on read-only file systems, which are difficult to replace with applications that automatically execute after the system is started, since the contents of the read-only file system cannot be modified. In addition, the adaptation file for replacement is usually required to be stored in a storage medium, and for a software development flow that is updated iteratively, when an operation such as an operating system or a user software upgrade is performed, there is an operation of formatting the content of the storage medium, so that the adaptation file is cleared.
Disclosure of Invention
Aiming at the defects or improvement demands of the prior art, the invention provides a hardware simulation method and a platform, which aim to shorten the system hardware simulation modeling period and improve the running compatibility of a user program, thereby solving the technical problem of reducing the realization difficulty of the hardware simulation of the whole system.
To achieve the above object, according to one aspect of the present invention, there is provided a hardware simulation method, including:
manufacturing a packaging adapting firmware of hardware to be simulated, wherein the packaging adapting firmware comprises a head script, middle data and tail version information;
loading an RAMDISK file system image and the encapsulation adaptation firmware, executing the head script, and judging whether the encapsulation adaptation firmware is injected into the RAMDISK file system image or not according to the tail version information;
for the RAMDISK file system image injected with the packaging adapting firmware, decompressing and migrating middle data in the packaging adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated;
and migrating the middle data in the updated RAMDISK file system image of the hardware to be simulated to a root file system, running a user program in the environment of the root file system, and starting the user program of the hardware to be simulated to obtain a simulation result.
Preferably, the specific method for manufacturing the package adapting firmware of the hardware to be emulated comprises the following steps:
in the C file, recoding operation is carried out on the interface function of the hardware to be simulated;
compiling the C file into a dynamic link library based on a compiling chain of an operating system;
injecting the firmware comprising the hardware to be simulated into a script, an adaptation script, the shared library and a configuration file of the hardware to be simulated;
and adding version information of the package adapting firmware after the package is completed.
Preferably, the package adapting firmware includes head script, middle data and tail version information, and is specifically divided into:
the header script is the firmware injection script;
the middle data is the configuration file of the adaptation script, the shared library and the hardware to be simulated;
the tail version information is version information of the package adapting firmware.
Preferably, the adaptation script of the middle data is a chain type, and the adaptation script and the dynamic link library of the shared library establish a corresponding relation with the so file according to a preset rule.
Preferably, the method for determining whether to inject the package adapting firmware into the mirror image of the RAMDISK file system according to the tail version information includes:
Comparing mirror image tail version information of the RAMDISK file system with tail version information of the encapsulation adaptation firmware;
if the tail information of the RAMDISK file system image is consistent with the firmware tail version information of the encapsulation adapting firmware, loading the RAMDISK file system image into a memory space of a hardware simulation platform, and starting a user program of hardware to be simulated;
if the tail information of the RAMDISK file system image does not have the information corresponding to the tail version information of the encapsulation adapting firmware, or the tail information of the RAMDISK file system image is inconsistent with the firmware tail version information of the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated.
Preferably, the middle data in the package adapter is decompressed and migrated to the mirror image of the RAMDISK file system, and the specific method comprises the following steps:
stripping the image header of the RAMDISK file system image to obtain a RAMDISK compressed image file;
decompressing the RAMDISK compressed image file to obtain an uncompressed RAMDISK image file, and mounting the uncompressed RAMDISK image file;
Decompressing the compressed package of the middle data in the encapsulation adapter and copying the data to the mounting catalog of the RAMDISK mirror image file;
modifying a starting file in the RAMDISK image file according to the middle data in the encapsulation adapting firmware, and updating the RAMDISK file system image data of the hardware to be simulated;
unloading the mounting catalog of the RAMDISK file system image and compressing the updated file system image to obtain a RAMDISK file system compressed image of hardware to be simulated;
adding an image header to a RAMDISK file system compressed image of the hardware to be simulated, and adding firmware version information to the tail of the RAMDISK file system compressed image of the hardware to be simulated to obtain the RAMDISK file system image of the hardware to be simulated;
and loading the RAMDISK file system image of the hardware to be simulated into a memory space of the hardware simulation platform.
Preferably, the method for migrating the middle data in the updated RAMDISK file system image of the hardware to be emulated to a root file system includes:
after the kernel of the hardware simulation platform is started, entering a memory file system into which the packaging adapting firmware is injected;
completing dynamic modification of the configuration file of the middle data of the packaging adapting firmware in the first process of the user program, and generating updated middle data of the packaging adapting firmware;
And modifying the starting file content of the root file system, and switching to the starting flow of the root file system.
Preferably, the method modifies the start file of the root file system and switches to the start flow of the root file system, and specifically includes:
migrating the updated encapsulation adapter to a directory node of a root file system;
executing the starting file of the root file system after migration is completed;
and executing a first script of the middle data in the starting process, and deploying the middle data.
Preferably, the root file system deploys the middle data in the starting process, and the specific method comprises the following steps:
injecting the shared library into a system process address space or an application program address space of a hardware simulation platform by an adaptation script in the middle data;
placing the shared library in a first order of a system process address space or an application program address space of the hardware simulation platform;
and redirecting the original code flow to a hardware custom simulation module in a shared library in the middle data, and directly simulating a simulation result obtained by hardware logic execution in the hardware custom simulation module.
According to another aspect of the present invention, there is provided a hardware simulation platform, characterized in that the hardware simulation platform includes: QEMU module and adaptation firmware module, wherein:
the QEMU module comprises a processor, a peripheral controller, a peripheral and a starting guide, wherein a hardware model in the QEMU module corresponds to logic simulation of hardware to be simulated and is used for carrying simulation operation of a kernel and an upper software instruction level;
the adaptation firmware module is used for encapsulating the adaptation script, the shared library and the configuration file into encapsulated adaptation firmware in a host machine environment, adding firmware version information to the encapsulated adaptation firmware, loading the encapsulated adaptation firmware into an image file of the RAMDISK by the QEMU module when the hardware simulation platform is started, deploying the encapsulated adaptation firmware into a memory space of the hardware simulation platform in the starting process of the hardware simulation platform, hijacking and managing necessary hardware access operation within the range of an operating system process or a user program, and simulating the simulation hardware functions which are not equipped in the QEMU module.
In general, compared with the prior art, the above technical solution conceived by the present invention has the following beneficial effects:
In a first aspect, the hardware simulation method provided by the invention has strong compatibility, and can be directly compatible with the operating system and user program binary codes which are not modified in the operation of the simulation platform, so that the use scene of the physical hardware platform is highly simulated; meanwhile, the method has strong expansibility, and for different hardware platforms of the same processor, based on the framework of the invention, relevant application program developers can also complete the adaptation simulation of different hardware.
In a second aspect, the hardware simulation platform provided by the invention has weak coupling, the QEMU module and the packaging adapting firmware are built into the hardware simulation platform independently of an operating system and user software, and a user can directly upgrade the system and the user software to realize evolution along with a physical equipment software version.
Drawings
FIG. 1 is a flow chart of a hardware simulation method in the first embodiment;
fig. 2 is a schematic diagram of the internal components of the package adapter according to the first embodiment;
FIG. 3 is a firmware adapting flow of the hardware simulation platform according to the first embodiment;
FIG. 4 is a schematic diagram of a hardware simulation platform according to the first embodiment;
fig. 5 is a flowchart of the start-up of the hardware simulation platform in the first embodiment.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention. In addition, the technical features of the embodiments of the present invention described below may be combined with each other as long as they do not collide with each other.
Embodiment one:
the first embodiment provides a hardware simulation method, as shown in fig. 1, including:
s101, manufacturing a packaging adapting firmware of hardware to be simulated, wherein the packaging adapting firmware comprises head script, middle data and tail version information.
In the first embodiment, the simulation hardware is obtained based on the QEMU open source technology, and the obtained simulation hardware directly interacts with the kernel, so that the obtained simulation hardware is obtained by abstract modeling on the logic of the actual hardware, and the logic behavior of the simulation hardware is completely consistent with that of the actual hardware for the kernel code.
The encapsulation adaptation firmware of the hardware to be simulated comprises an adaptation script and a shared library file with a redirection function, relevant files of the hardware to be simulated are encapsulated into firmware, the encapsulation adaptation firmware is loaded into a memory file system by a QEMU module when a simulation platform is started, the encapsulation adaptation firmware is automatically deployed into a system memory in the system starting process, and necessary hardware access operation within the range of an operating system process or a user program is hijacked and managed, so that the hardware access operation simulation system is used for simulating the hardware function or the custom function which is not simulated by the existing QEMU module.
S102, loading the RAMDISK file system image and the encapsulation adaptation firmware, executing the head script, and judging whether the encapsulation adaptation firmware is injected into the RAMDISK (virtual memory disk) file system image according to the tail version information.
In the first embodiment, after the image of the ram isk memory file system and the encapsulated adapting firmware are loaded, the QEMU module directly invokes and executes the encapsulated adapting firmware, that is, executes the fix_ram disk.sh script of the header of the encapsulated adapting firmware to perform the adapting firmware injection action of middle data, and before injection, determines whether to inject the encapsulated adapting firmware into the image of the ram isk file system according to the tail version information of the encapsulated adapting firmware.
If the tail information of the RAMDISK file system image is consistent with the firmware tail version information of the encapsulation adapting firmware, loading the RAMDISK file system image into a memory space of a hardware simulation platform, and starting a user program of hardware to be simulated;
if the tail information of the RAMDISK file system image does not have the information corresponding to the tail version information of the encapsulation adapting firmware, or the tail information of the RAMDISK file system image is inconsistent with the firmware tail version information of the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated.
S103, decompressing and migrating middle data in the packaging adapting firmware to the RAMDISK file system mirror image of the injected packaging adapting firmware, and updating the RAMDISK file system mirror image of the hardware to be simulated.
In the first embodiment, the middle data in the encapsulation adapter includes an adapter script, a shared library and a configuration file of the hardware to be emulated, and relevant data of the hardware to be emulated is decompressed and migrated to the mirror image of the RAMDISK file system to obtain the mirror image of the RAMDISK file system belonging to the hardware to be emulated.
And S104, migrating the middle data in the updated RAMDISK file system image of the hardware to be simulated to a root file system, running a user program in the environment of the root file system, and starting the user program of the hardware to be simulated to obtain a simulation result.
In the first embodiment, the updated RAMDISK file system image of the hardware to be simulated is loaded into the memory space of the hardware simulation platform, then the middle data in the updated RAMDISK file system image of the hardware to be simulated is migrated to the root file system, and when the root file system is started, the user program execution flow of the hardware to be simulated is hijacked according to the middle data corresponding to the hardware to be simulated, so as to generate the simulation result of the hardware to be simulated.
In the first embodiment, the QEMU module is a base layer of the overall architecture of the system, and the kernel runs on the QEMU simulation hardware and interacts with the QEMU simulation hardware directly; the package adapting firmware and the related function simulation module are located in the user space, and when the user space needs to access the hardware which is not simulated by the QEMU through the kernel, the package adapting firmware hives and redirects to the function simulation unit.
In the first embodiment, the package adapting firmware exists independently, and the QEMU module completes dynamic loading and injecting into the system memory, and is not dependent on the storage device of the system, so that the hardware simulation platform in the first embodiment can realize the complete formatting and upgrading process of the operating system or the user program.
The hardware simulation method provided by the first embodiment has strong compatibility, can directly run unmodified operating system and user program binary codes on the simulation platform, and highly simulates the use scene of the physical hardware platform; meanwhile, the method has strong expansibility, and for different hardware platforms of the same processor, based on the framework of the invention, relevant application program developers can also complete the adaptation simulation of different hardware.
In order to realize that the QEMU module in the existing hardware platform has no simulated hardware function or custom function, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, the method for manufacturing the package adapter of the hardware to be simulated includes:
editing an interface function of hardware to be simulated in a C file, and simulating an execution result of the hardware logic to be simulated;
compiling the C file into a dynamic link library based on a compiling chain of an operating system;
Injecting the firmware comprising the hardware to be simulated into a script, an adaptation script, the shared library and a configuration file of the hardware to be simulated;
and adding version information of the package adapting firmware after the package is completed.
In the first embodiment, the C file is independent and independent of the source code environment of the user program. The recoding operation of the interface function of the hardware to be simulated comprises a rewriting or appending (dlopen+dlsym) operation and simulates the execution result of the logic of the hardware to be simulated. Taking an I2C temperature sensor as an example, only the temperature acquisition interface function in the application program is needed to be rewritten, the needed temperature value is directly returned, hardware simulation is not needed to be carried out on equipment such as an I2C controller, I2C equipment (temperature sensor) and the like, and the simulation development workload is greatly reduced.
The shared library formed by the so files has a redirection function, and the redirection can solve the problem of hardware function simulation in a user space, for example, the problem of accessing unrealized bottom simulation hardware through a kernel is avoided, and the code execution flow is simplified.
And injecting the firmware comprising the hardware to be simulated into a script, an adaptation script, a shared library and packaging the configuration file of the hardware to be simulated through a firmware making module.
In order to facilitate distinguishing the functional areas of the package adapter, in combination with the embodiment of the present invention, there is a preferred implementation scheme, specifically, as shown in fig. 2, the package adapter includes a header script, middle data, and tail version information, which is specifically divided into:
the header script is the firmware injection script;
the middle data is the configuration file of the adaptation script, the shared library and the hardware to be simulated;
the tail version information is version information of the package adapting firmware.
In the first embodiment, the internal composition of the package adapter is shown in fig. 2, and the header script of the package adapter is a fix_ramdisk.sh injection script for injecting the package adapter into the RAMDISK file system image. The tail version information of the packaging adapting firmware is the version information of the current firmware, and if the packaging adapting firmware has version updating, the tail version information of the packaging adapting firmware can be reflected by the tail version number of the packaging adapting firmware. The middle data of the encapsulation adapter is a compressed package file, which contains Head-script, next-script, sh chain-type adapter scripts, shared library files and related configuration file data of the hardware to be emulated.
In order to add an adaptive shared library to a system process address space or any application program address space of a hardware simulation platform, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, as shown in fig. 2, an adaptive script of the middle data is a chain type, and a correspondence is established between the adaptive script and a dynamic link library of the shared library.
In the first embodiment, as shown in fig. 2, the partial data of the encapsulated adapting firmware is divided into a first script and an adapting script, the first script Head-script is used as a trigger source, the adapting script Next-script behind the first script and the dynamic link library of the shared library, so files establish a corresponding relation according to a preset rule, and the dynamic link library so files are correspondingly executed after executing the adapting script Next-script and the following scripts.
The middle data of the encapsulation adaptation firmware needs to be added into a system process address space or an application program address space of the hardware simulation platform, but a corresponding process address space does not exist when the program is not started, and if a corresponding Next-script does not exist when the program is started, the shared library cannot be injected into the program address space. In the first embodiment, the chain script can ensure that the whole process running on the simulation platform can execute the injection of the shared library, and if a certain program corresponds to the Nth Next-script, the execution of the Nth Next-script when the program is started can be ensured, and the corresponding Nth dynamic link library is injected into the address space of the program.
In order to avoid repeatedly injecting the package adapting firmware into the RAMDISK file system, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, the method for determining whether to inject the package adapting firmware into the mirror image of the RAMDISK file system according to the tail version information includes:
Comparing mirror image tail version information of the RAMDISK file system with tail version information of the encapsulation adaptation firmware;
if the tail information of the RAMDISK file system image is consistent with the firmware tail version information of the encapsulation adapting firmware, loading the RAMDISK file system image into a memory space of a hardware simulation platform, and starting a user program of hardware to be simulated;
if the tail information of the RAMDISK file system image does not have the information corresponding to the tail version information of the encapsulation adapting firmware, or the tail information of the RAMDISK file system image is inconsistent with the firmware tail version information of the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated.
In the first embodiment, as shown in fig. 2, the naming rule of the mirror tail version information of the RAMDISK file system is the same as the naming rule of the tail version information of the package adapter. If the same version of encapsulation adaptation firmware exists in the mirror image of the RAMDISK file system, the injection is not performed, and the RAMDISK mirror image file is loaded into a memory space of the hardware simulation platform.
In order to obtain the mirror image of the RAMDISK file system related to the hardware to be emulated, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, the method for decompressing and migrating the middle data in the package adapter to the mirror image of the RAMDISK file system includes:
and stripping the image header of the RAMDISK file system image to obtain the RAMDISK compressed image file.
Decompressing the RAMDISK compressed image file to obtain an uncompressed RAMDISK image file, and mounting the uncompressed RAMDISK image file.
In the first embodiment, the uncompressed RAMDISK image file is installed in the HOST environment.
And decompressing the compressed package of the middle data in the packaging adapting firmware and copying the data to the mounting catalog of the RAMDISK mirror image file.
And modifying a starting file in the RAMDISK file according to the middle data in the encapsulation adaptation firmware, and updating the RAMDISK file system image data of the hardware to be simulated.
In the first embodiment, the modification of the init startup file in the RAMDISK image file is to add the middle data deployment and migration actions in the encapsulation adapter, and the operation of adding the Head-script, i.e. the injection operation of the sh script, to the startup file of the root file system, so that the updating of the RAMDISK file system image data of the hardware to be emulated is completed.
And unloading the mounting directory of the RAMDISK file system image and compressing the updated file system image to obtain the RAMDISK file system compressed image of the hardware to be simulated.
Adding an image header to the RAMDISK file system compressed image of the hardware to be simulated, and adding firmware version information to the tail of the RAMDISK file system compressed image of the hardware to be simulated to obtain the RAMDISK file system image of the hardware to be simulated.
In the first embodiment, for updated image data of the RAMDISK file system of the hardware to be simulated, image is added at the head of the compressed image of the RAMDISK file system of the hardware to be simulated, and firmware version information is added at the tail of the compressed image of the RAMDISK file system of the hardware to be simulated, so as to obtain the image of the RAMDISK file system of the hardware to be simulated.
And loading the RAMDISK file system image of the hardware to be simulated into a memory space of the hardware simulation platform.
In order to synchronously update the adapting firmware of the hardware to be emulated in the root file system, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, the migration of the middle data in the updated ramdbisk file system image of the hardware to be emulated to the root file system includes:
and after the kernel of the hardware simulation platform is started, entering a memory file system into which the packaging adapting firmware is injected.
In the first embodiment, when the kernel software of the simulation platform is started, the starting environment enters the memory file system into which the encapsulated adapter firmware is injected.
And finishing dynamic modification of the configuration file of the middle data of the package adaptation firmware in the first process of the user program, and generating updated middle data of the package adaptation firmware.
In the first embodiment, the configuration file of the middle data of the adapting firmware is configuration information of hardware to be simulated, the unique modification mark is performed in the simulation platform according to the configuration information of the hardware to be simulated, each piece of hardware to be simulated corresponds to one modification mark, and the middle data of the packaging adapting firmware is updated due to modification of the configuration information of the hardware to be simulated, so that updated middle data of the packaging adapting firmware is generated.
And modifying the starting file content of the root file system, and switching to the starting flow of the root file system.
In the first embodiment, the execution operation of the first script Head-script, which encapsulates the middle data of the adapter, is injected into the boot file of the root file system, and the injection operation uniformly adopts a copy-injection-binding mount mode, which is applicable to the modification operation in the application scenario of the read-only file system. Under the existing application scene of the read-only file system, the modification of the read-only file in the system is only manually operated by a user after the system is started, and only the program running range after the system is started is covered, so that the program executing process in the starting process of the operating system cannot be influenced.
In order to deploy the intermediate data so as to inject the shared library into the corresponding address space, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, modifying the boot file of the root file system, and the specific method includes:
and migrating the updated encapsulation adaptation firmware to a directory node of a root file system.
And executing the starting file of the root file system after migration is completed.
And executing a first script of the middle data in the starting process, and deploying the middle data.
In the first embodiment, as shown in fig. 3, the first script Head-script of the middle data is executed in the starting process, after the flow is started, an execution operation of an adaptation script Next-script is added at a node where the shared library needs to be injected, then when the system executes the node, the adaptation script Next-script is executed, and the injection operation of the shared library and the execution operation of the Next adaptation script Next-script are completed by the adaptation script Next-script.
After the execution of the memory file system is finished, switching to a starting flow of the root file system, and meanwhile, migrating the encapsulation adapter to a directory node of the root file system to ensure that the encapsulation adapter continuously exists in two stages of the memory file system and the root file system.
In order to improve the priority of the adaptation script in the encapsulation adaptation firmware, in combination with the embodiment of the present invention, there is also a preferred implementation scheme, specifically, the root file system deploys the middle data in the starting process, and the specific method includes:
injecting the shared library into a system process address space or an application program address space of a hardware simulation platform by an adaptation script in the middle data;
placing the shared library in a first order of a system process address space or an application program address space of the hardware simulation platform;
and redirecting the original code flow to a hardware custom simulation module in a shared library in the middle data, and directly simulating a simulation result obtained by hardware logic execution in the hardware custom simulation module.
In the first embodiment, an adaptation flow of the encapsulated adapting firmware in the boot process of the root file system is shown in fig. 3, and the encapsulated adapting firmware chain-type adaptation script injects the shared library into the whole system process address space or the application program address space, and the injection mode of the environment variable ld_reload is adopted to enable the shared library to have higher priority in the program execution process, so that functions and symbols in other libraries can be covered.
LD_PRELOAD is an environment variable of the Linux system, and can affect the links of the program at runtime, allowing the user to define the dynamic link libraries that are loaded preferentially before the program runs, for selectively loading the same function in different dynamic link libraries. Through ld_reload, the user can load another dynamic link library in the middle of the main program and its dynamic link library, even covering the normal function library. On the one hand, the user can use the function or better function (without the source code of other people) by the function, and on the other hand, the user can inject the program into the program of other people, so that the specific purpose is achieved.
And redirecting the original code flow to a hardware custom simulation module in a shared library of the packaging adapting firmware, and directly simulating functional data obtained by hardware logic execution in the hardware custom simulation module.
Embodiment two:
the second embodiment provides a hardware simulation platform, and the simulation method of the hardware simulation platform of the second embodiment is according to the hardware simulation method in the first embodiment, where the hardware simulation platform includes: QEMU module and adaptation firmware module, wherein:
the QEMU module comprises a processor, a peripheral controller, a peripheral and a starting guide, wherein a hardware model in the QEMU module corresponds to logic simulation of hardware to be simulated and is used for carrying simulation operation of a kernel and an upper software instruction level;
The adaptation firmware module is used for encapsulating the adaptation script, the shared library and the configuration file into encapsulated adaptation firmware in a host machine environment, adding firmware version information to the encapsulated adaptation firmware, loading the encapsulated adaptation firmware into an image file of the RAMDISK by the QEMU module when the hardware simulation platform is started, deploying the encapsulated adaptation firmware into a memory space of the hardware simulation platform in the starting process of the hardware simulation platform, hijacking and managing necessary hardware access operation within the range of an operating system process or a user program, and simulating the simulation hardware functions which are not equipped in the QEMU module.
In the second embodiment, the building of the simulation platform is started by the QEMU module creating the hardware model, and the hardware simulation in the minimum system is completed through the device model modeling mechanism of the QEMU module, for example, QOM (QOM is a set of object-oriented mechanism that the QEMU implements on the basis of the C file and is responsible for abstracting the devices into objects). In order to ensure normal and stable operation of the operating system software and the upper layer software, the minimum set of hardware modeling requirements of the QEMU module is composed of a processor, a peripheral controller, a peripheral and a starting guide. The specific characteristics are as follows:
The processor emulation comprises at least a CPU, an interrupt controller GIC and an associated processor configuration unit. The CPU is responsible for instruction set simulation of codes, the interrupt controller is responsible for interrupt connection and distribution between system hardware and the CPU, and the processor configuration unit stores hardware information of the processor and ensures normal starting flow of the kernel.
The peripheral controller at least comprises a serial controller UART, a watchdog WDOG, a storage controller and a PCI controller. The UART is used for running a system console and is a primary interaction interface between a user and the system; the watchdog is mainly used for simulating normal restarting and closing operations of the system; the storage controller is responsible for data interaction between the operating system and the external storage device; the PCI controller is used for downloading network cards and other PCI devices, various mature PCI network card hardware models are integrated in the QEMU, and the simulation of the PCI controller can also realize the rapid construction of interfaces of other PCI devices on the basis of reducing the independent modeling of the network controller.
The peripheral device at least comprises a memory card and network card equipment. The external storage device is used for storing a file system, user data and the like; the network card device is used for supporting the simulation platform to communicate with an external network.
The starting guide is used for simulating a hardware guiding unit and a part of functions of the software starting guide in the processor, so that the cutting of differential hardware between a minimum system hardware simulation platform and an actual hardware platform is completed, and the exception of the kernel starting process caused by the hardware deficiency is avoided; completing loading of package adaptation firmware, kernel mirror image, equipment tree and RAMDISK memory file system mirror image; detecting whether the memory file system image is injected with the packaging adapting firmware or not, and if the packaging adapting firmware is not detected or the injected packaging adapting firmware is inconsistent with the version loaded with the packaging adapting firmware, injecting the contained adapting file into the memory file system image through an injection script embedded in the packaging adapting firmware and adding relevant version information.
As shown in fig. 4, the QEMU minimum system hardware module in this embodiment is a base layer of the overall architecture of the system, and the kernel runs on the QEMU simulation hardware and directly interacts with the QEMU simulation hardware; the package adapting firmware and the related function simulation module are located in the user space, and when the user space needs to access the simulation hardware which is not equipped with the QEMU through the kernel, the package adapting firmware hives and redirects to the function simulation unit.
As shown in fig. 5, the flow of the hardware simulation platform includes the following steps:
s201, starting a full-system hardware simulation platform.
S202, a QEMU system hardware model is created.
S203, cutting out the equipment tree.
In the second embodiment, the boot loader completes the clipping of the difference hardware between the minimum system hardware simulation platform and the actual hardware platform, so as to ensure that the kernel boot process is not abnormal due to the lack of hardware, and avoid the occurrence of redundant hardware.
S204, loading an operating system image and packaging the adapting firmware.
S205, manufacturing a package adapting firmware.
In the second embodiment, step S201 is performed while step S205 is performed.
S206, compiling and generating a relocation shared library.
S207, packaging the adapting firmware.
S208 loading the operating system image and packaging the adapter firmware.
In the second embodiment, after S203 and S207 are completed, the operating system image and the package adapter are loaded on the QEMU module, respectively.
S209, judging whether the RAMDISK has the package adapting firmware. If yes, S210 is executed, and if no, S211 is executed.
S210, judging whether the RAMDISK has the packaging adapting firmware with the consistent version. If yes, S212 is executed, and if no, S211 is executed.
In the second embodiment, if the tail information of the RAMDISK file system image is consistent with the firmware tail version information of the encapsulation adapter, loading the RAMDISK file system image into the memory space of the hardware simulation platform, and starting the user program of the hardware to be simulated;
if the tail information of the RAMDISK file system image does not have the information corresponding to the tail version information of the encapsulation adapting firmware, or the tail information of the RAMDISK file system image is inconsistent with the firmware tail version information of the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated.
S211, injecting package adapting firmware into the RAMDISK.
S212, starting the RAMDISK memory file system.
S213, deploying package adaptation firmware.
S214, injecting a chain type adaptation script, and migrating and packaging the adaptation firmware into the directory node of the root file system.
In the second embodiment, the triggering operation of the chain-type adaptation script header encapsulates the middle data of the adaptation firmware into a first script and an adaptation script, the first script Head-script is used as a triggering source to perform the triggering operation, the chain-type script can ensure that the injection of the shared library can be executed in the whole running process of the simulation platform, after the triggering process is started, the execution operation of the adaptation script Next-script is added at the node where the shared library is required to be injected, then the adaptation script Next-script is executed when the system executes the node, and the injection operation of the shared library and the execution operation of the Next adaptation script Next-script are completed by the adaptation script Next-script.
Because the dynamic link library of the encapsulated adapter is loaded preferentially before the program is run, the necessary hardware access operations within the scope of the operating system process or the user program can be hijacked and managed.
S215, switching to start the root file system.
In the second embodiment, after the execution of the memory file system is finished, the boot flow is switched to the root file system, and at the same time, the encapsulation adapter is migrated to the directory node of the root file system, so as to ensure that the encapsulation adapter exists continuously in two stages of the memory file system and the root file system.
The shared library is injected into the whole system process address space or the application program address space by the chain-type adaptation script of the encapsulation adaptation firmware, and the injection mode of the environment variable LD_PRELOAD is adopted to ensure that the shared library has higher priority in the program execution process, so that functions and symbols in other libraries can be covered.
S216, running a user program to obtain simulation hardware.
And finally, the simulation hardware is obtained, and the user can directly upgrade the system and the user software to realize the common evolution along with the software version of the physical equipment. The hardware simulation platform in the second embodiment has weak coupling, and the QEMU module and the hardware simulation platform built by the package adapting firmware are independent of the operating system and the user software.
It will be readily appreciated by those skilled in the art that the foregoing description is merely a preferred embodiment of the invention and is not intended to limit the invention, but any modifications, equivalents, improvements or alternatives falling within the spirit and principles of the invention are intended to be included within the scope of the invention.

Claims (9)

1. A hardware simulation method, the method comprising:
manufacturing a packaging adapting firmware of hardware to be simulated, wherein the packaging adapting firmware comprises a head script, middle data and tail version information; wherein, the head script is a firmware injection script; the middle data is a configuration file of an adaptation script, a shared library and hardware to be simulated; the tail version information is version information of the encapsulation adapting firmware;
Loading an RAMDISK file system image and the encapsulation adaptation firmware, executing the head script, and judging whether the encapsulation adaptation firmware is injected into the RAMDISK file system image or not according to the tail version information;
for the RAMDISK file system image injected with the packaging adapting firmware, decompressing and migrating middle data in the packaging adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated;
and migrating the middle data in the updated RAMDISK file system image of the hardware to be simulated to a root file system, running a user program in the environment of the root file system, and starting the user program of the hardware to be simulated to obtain a simulation result.
2. The hardware emulation method of claim 1, wherein the fabricating a package adapter for hardware to be emulated comprises:
in the C file, recoding operation is carried out on the interface function of the hardware to be simulated;
compiling the C file into a dynamic link library based on a compiling chain of an operating system;
injecting the firmware comprising the hardware to be simulated into a script, an adaptation script, the shared library and a configuration file of the hardware to be simulated;
And adding version information of the package adapting firmware after the package is completed.
3. The hardware simulation method of claim 1, wherein the adaptation script of the middle data is a chain type, and the adaptation script and the dynamic link library of the shared library are in a corresponding relation with each other according to a preset rule.
4. The hardware emulation method of claim 1, wherein said determining whether to inject said package adapter into an image of a ramisk file system according to said tail version information comprises:
comparing mirror image tail version information of the RAMDISK file system with tail version information of the encapsulation adaptation firmware;
if the tail information of the RAMDISK file system image is consistent with the firmware tail version information of the encapsulation adapting firmware, loading the RAMDISK file system image into a memory space of a hardware simulation platform, and starting a user program of hardware to be simulated;
if the tail information of the RAMDISK file system image does not have the information corresponding to the tail version information of the encapsulation adapting firmware, or the tail information of the RAMDISK file system image is inconsistent with the firmware tail version information of the encapsulation adapting firmware, decompressing and migrating middle data in the encapsulation adapting firmware to the RAMDISK file system image, and updating the RAMDISK file system image of the hardware to be simulated.
5. The hardware emulation method of claim 1, wherein the middle data in the package adapter is decompressed and migrated into an image of the ramdsk file system, the specific method comprising:
stripping the image header of the RAMDISK file system image to obtain a RAMDISK compressed image file;
decompressing the RAMDISK compressed image file to obtain an uncompressed RAMDISK image file, and mounting the uncompressed RAMDISK image file;
decompressing the compressed package of the middle data in the encapsulation adapter and copying the data to the mounting catalog of the RAMDISK mirror image file;
modifying a starting file in the RAMDISK image file according to the middle data in the encapsulation adapting firmware, and updating the RAMDISK file system image data of the hardware to be simulated;
unloading the mounting catalog of the RAMDISK file system image and compressing the updated file system image to obtain a RAMDISK file system compressed image of hardware to be simulated;
adding an image header to a RAMDISK file system compressed image of the hardware to be simulated, and adding firmware version information to the tail of the RAMDISK file system compressed image of the hardware to be simulated to obtain the RAMDISK file system image of the hardware to be simulated;
And loading the RAMDISK file system image of the hardware to be simulated into a memory space of the hardware simulation platform.
6. The hardware emulation method of claim 5, wherein said migrating said middle data in said updated RAMDISK file system image of said hardware to be emulated to a root file system comprises:
after the kernel of the hardware simulation platform is started, entering a memory file system into which the packaging adapting firmware is injected;
completing dynamic modification of the configuration file of the middle data of the packaging adapting firmware in the first process of the user program, and generating updated middle data of the packaging adapting firmware;
and modifying the starting file content of the root file system, and switching to the starting flow of the root file system.
7. The hardware emulation method of claim 6, wherein modifying the boot file of the root file system switches to a boot flow of the root file system, the specific method comprising:
migrating the updated encapsulation adapter to a directory node of a root file system;
executing the starting file of the root file system after migration is completed;
and executing a first script of the middle data in the starting process, and deploying the middle data.
8. The hardware emulation method of claim 7, wherein the root file system deploys the middle data during a startup process, the specific method comprising:
injecting a shared library into a system process address space or an application program address space of a hardware simulation platform by an adaptation script in the middle data;
placing the shared library in a first order of a system process address space or an application program address space of the hardware simulation platform;
and redirecting the original code flow to a hardware custom simulation module in a shared library in the middle data, and directly simulating a simulation result obtained by hardware logic execution in the hardware custom simulation module.
9. A hardware simulation platform, the hardware simulation platform comprising: QEMU module and adaptation firmware module, wherein:
the QEMU module comprises a processor, a peripheral controller, a peripheral and a starting guide, wherein a hardware model in the QEMU module corresponds to logic simulation of hardware to be simulated and is used for carrying simulation operation of a kernel and an upper software instruction level;
the adaptation firmware module is used for encapsulating the adaptation script, the shared library and the configuration file into encapsulated adaptation firmware in a host machine environment, adding firmware version information to the encapsulated adaptation firmware, loading the encapsulated adaptation firmware into an image file of the RAMDISK by the QEMU module when the hardware simulation platform is started, deploying the encapsulated adaptation firmware into a memory space of the hardware simulation platform in the starting process of the hardware simulation platform, hijacking and managing necessary hardware access operation within the range of an operating system process or a user program, and simulating the simulation hardware functions which are not equipped in the QEMU module.
CN202111000101.5A 2021-08-27 2021-08-27 Hardware simulation method and platform Active CN113703920B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111000101.5A CN113703920B (en) 2021-08-27 2021-08-27 Hardware simulation method and platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111000101.5A CN113703920B (en) 2021-08-27 2021-08-27 Hardware simulation method and platform

Publications (2)

Publication Number Publication Date
CN113703920A CN113703920A (en) 2021-11-26
CN113703920B true CN113703920B (en) 2023-08-08

Family

ID=78656426

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111000101.5A Active CN113703920B (en) 2021-08-27 2021-08-27 Hardware simulation method and platform

Country Status (1)

Country Link
CN (1) CN113703920B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105701298A (en) * 2016-01-15 2016-06-22 天津大学 Simulation platform design method based on Power PC SoC framework
CN111597109A (en) * 2020-04-24 2020-08-28 清华大学 Defect detection method and system for cross-architecture firmware stack memory
US10846113B1 (en) * 2017-03-30 2020-11-24 Amazon Technologies, Inc. Board management controller firmware virtualization
CN112241311A (en) * 2020-10-22 2021-01-19 杭州安恒信息技术股份有限公司 Firmware simulation method and device, electronic equipment and readable storage medium
CN112417444A (en) * 2020-12-03 2021-02-26 南京邮电大学 Attack trapping system based on firmware simulation

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070204271A1 (en) * 2006-02-28 2007-08-30 Andrew Gaiarsa Method and system for simulating a multi-CPU/multi-core CPU/multi-threaded CPU hardware platform
US20100257411A1 (en) * 2009-04-07 2010-10-07 Kabushiki Kaisha Toshiba Emulation device and emulator activation method
GB2554942B (en) * 2016-10-14 2018-11-21 Imagination Tech Ltd Verifying firmware binary images using a hardware design and formal assertions
US10871955B2 (en) * 2018-02-08 2020-12-22 Insyde Software Corp. System and method for providing firmware data updates

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105701298A (en) * 2016-01-15 2016-06-22 天津大学 Simulation platform design method based on Power PC SoC framework
US10846113B1 (en) * 2017-03-30 2020-11-24 Amazon Technologies, Inc. Board management controller firmware virtualization
CN111597109A (en) * 2020-04-24 2020-08-28 清华大学 Defect detection method and system for cross-architecture firmware stack memory
CN112241311A (en) * 2020-10-22 2021-01-19 杭州安恒信息技术股份有限公司 Firmware simulation method and device, electronic equipment and readable storage medium
CN112417444A (en) * 2020-12-03 2021-02-26 南京邮电大学 Attack trapping system based on firmware simulation

Also Published As

Publication number Publication date
CN113703920A (en) 2021-11-26

Similar Documents

Publication Publication Date Title
US8621279B1 (en) System and method for generating emulation-based scenarios for Error Handling
CN109408393B (en) Application testing method, device and equipment and computer readable storage medium
CN111309451A (en) Method for realizing cross compilation of Docker mirror images
CN100492387C (en) Method and system for software protected development based on Keil C51
CN113986395B (en) Packaging method for application-dependent self-contained technology under linux system
CN112948024B (en) Loading method and device of dynamic link library, storage medium and electronic equipment
CN106293870A (en) Computer system and strategy thereof guide compression method
CN112667361A (en) Management method and device based on system virtual machine, electronic equipment and storage medium
CN111123737A (en) Digital hardware virtual simulation system
CN115629971A (en) Application development system and method
CN111459606A (en) Method for quickly creating virtual machine under virtualization and server
Wang Can “micro VM” become the next generation computing platform?: Performance comparison between light weight Virtual Machine, container, and traditional Virtual Machine
CN113703920B (en) Hardware simulation method and platform
CN111966470B (en) Loading method and device of virtual machine monitor and electronic equipment
CN112667352A (en) Multi-CPU instruction cross compiling unified construction method, equipment and medium
CN111610976B (en) Heterogeneous application transplanting method and device and computer equipment
CN116401003A (en) Android application running method, system and storage medium based on desktop operating system
US7752030B2 (en) Virtualization as emulation support
CN113342389B (en) Service updating method and device and computer readable storage medium
US11188361B1 (en) Cross-architecture software distribution using a virtual instruction set architecture
CN101470657A (en) Verification method for BIOS refreshing content
CN114443221A (en) Method and system for constructing cross-platform container mirror image based on build dah and electronic equipment
CN114416031A (en) Operating system for supporting RISC-V processor facing AIoT scene
CN113177292A (en) Universal BIM secondary development implementation method and device
CN115545136B (en) Method for managing RAID card in domestic processor platform firmware

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant