A virtual machine system, storage medium, electronic device and working method

By implementing an RTOS-based virtual machine system on the MCU, independent storage and security isolation between applications are achieved, solving the problems of RTOS development complexity and large upgrade data volume, and improving stability and security.

CN114327786BActive Publication Date: 2025-10-17WUHAN TIANYU INFORMATION IND
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111681183.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2025-10-17
Estimated Expiration
2041-12-28

AI Technical Summary

Technical Problem

In existing MCU software development, there is a lack of security protection between threads when using RTOS, which makes independent development difficult for multiple people. Source code changes significantly affect program bytecode, and the amount of software upgrade data is large.

Method used

A virtual machine system is used to create virtual machine threads based on RTOS, allocate independent memory resources to applications, configure firewall mechanisms, encapsulate MCU hardware functions through APIs, and achieve communication and management between applications.

Benefits of technology

Reduce development difficulty, ensure system stability, run multiple applications in parallel, improve security and confidentiality, and reduce the amount of software upgrade data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327786B_ABST
    Figure CN114327786B_ABST
Patent Text Reader

Abstract

This application relates to a virtual machine system, storage medium, electronic device, and working method, and relates to the field of virtual machine technology. The virtual machine system includes: a virtual machine for creating a virtual machine thread based on an RTOS; a virtual machine thread for running corresponding applications, with corresponding memory resources allocated to the applications, and the memory resources of different applications being independent of each other; an application manager for allocating corresponding memory resources to applications and for downloading, installing, deleting, starting, and stopping applications; and an API for abstracting and encapsulating MCU hardware and functions for application calls. This application is based on mature RTOS functions, reducing development workload and ensuring system stability.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of virtual machines, in particular to a virtual machine system, a storage medium, an electronic device and a working method. BACKGROUND

[0002] The existing MCU software development is mostly developed by using C language, and for a function slightly more complex, RTOS is often used, and common RTOS includes freertos, ucos, rt_thread, etc. The technical means requires the developer to have a detailed understanding of the MCU hardware used, and also needs to have a detailed understanding of the functions of the RTOS.

[0003] However, the source code of the RTOS and the thread source code written by the developer need to be compiled together, and there is no safety protection between threads, which is not conducive to independent development and use of the functions of the MCU by multiple people, and slight changes in the source code will cause great changes in the program bytecode compiled, and the amount of data to be updated for software upgrading is large.

[0004] Therefore, in order to solve the above technical problems, the present application provides a virtual machine technology based on RTOS. SUMMARY

[0005] The present application provides a virtual machine system, a storage medium, an electronic device and a working method, which is based on mature RTOS functions, reduces the development workload and ensures system stability.

[0006] In a first aspect, the present application provides a virtual machine system, which comprises:

[0007] a virtual machine, configured to create a virtual machine thread based on an RTOS;

[0008] the virtual machine thread is configured to run a corresponding application, the application is allocated with a corresponding memory resource, and the memory resources of different applications are independent of each other;

[0009] an application manager, configured to allocate a corresponding memory resource for the application, and further configured to perform download, installation, deletion, start and stop operations of the application;

[0010] an API, configured to abstract and encapsulate the MCU hardware and functions, for calling by the application.

[0011] Further, the virtual machine threads of different applications can run in parallel and can be switched between a ready state, a running state and a suspended state.

[0012] Further, when a new application needs to be started, a corresponding virtual machine thread is created;

[0013] When the running application needs to be stopped, the corresponding virtual machine thread is deleted.

[0014] Further, different applications are configured with corresponding running priorities.

[0015] Further, the virtual machine is configured with a firewall mechanism, and the applications are only allowed to access the memory resources corresponding to themselves.

[0016] Specifically, different applications communicate with each other based on the API.

[0017] In a second aspect, the present application provides a storage medium, which stores a computer program, and the computer program is executed by a processor to implement the virtual machine system mentioned in the first aspect.

[0018] In a third aspect, the present application provides an electronic device, which comprises a memory and a processor, and the memory stores a computer program running on the processor, and the processor executes the computer program to implement the virtual machine system mentioned in the first aspect.

[0019] In a fourth aspect, the present application provides a working method of a virtual machine system, which comprises the following steps:

[0020] In response to a program download instruction, the corresponding application is downloaded and installed, and the corresponding virtual machine thread is created;

[0021] In response to a program deletion instruction, the application is deleted, and the corresponding virtual machine thread is deleted; wherein,

[0022] The virtual machine system comprises:

[0023] The virtual machine is used to create a virtual machine thread based on an RTOS;

[0024] The virtual machine thread is used to run the corresponding application, and the application is allocated with corresponding memory resources, and the memory resources of different applications are independent of each other;

[0025] The application manager is used to allocate the corresponding memory resources for the application, and is also used to execute the download, installation, deletion, start and stop operations of the application;

[0026] The API is used to abstract and encapsulate the MCU hardware and functions, and is called by the application.

[0027] Further, the method further comprises the following steps:

[0028] The firewall mechanism is configured, and the application is only allowed to access the memory resources corresponding to itself.

[0029] The beneficial effects brought by the technical solutions provided in the application include:

[0030] (1) The application is based on the OS common functions such as multi-threading, inter-thread communication and semaphore of a mature RTOS, reduces the development workload, and ensures system stability.

[0031] (2) The application can realize concurrent running of multiple applications, and can realize more flexible and rich functions.

[0032] (3) Each application in the application runs in an independent and isolated space, effectively prevents the stored information from being maliciously or accidentally damaged and leaked, and effectively improves the security and confidentiality.

[0033] (4) The application encapsulates the functions and common functions related to MCU hardware into API for application calling, greatly reduces the development difficulty of the application. BRIEF DESCRIPTION OF DRAWINGS

[0034] TERMS EXPLANATION:

[0035] RTOS: Real Time Operating System, real-time operating system;

[0036] OS: Operating System, operating system;

[0037] MCU: Microcontroller Unit, microcontroller unit;

[0038] NVM: Non-Volatile Memory, non-volatile memory;

[0039] RAM: Random Access Memory, random access memory;

[0040] SPI: Serial Peripheral Interface, serial peripheral interface;

[0041] API: Application Programming Interface, application programming interface

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.

[0043] Fig. 1 is a structural block diagram of the virtual machine system provided in the embodiments of the application;

[0044] Fig. 2 A schematic diagram of a virtual machine system provided in the embodiments of the present application. DETAILED DESCRIPTION

[0045] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0046] The embodiments of the present application are further described below in combination with the drawings.

[0047] The embodiments of the present application provide a virtual machine system, a storage medium, an electronic device and a working method, which are based on mature OS common functions such as multi-threading, inter-thread communication and semaphore of RTOS, so that the development workload is reduced and the system stability is ensured.

[0048] To achieve the above technical effects, the general idea of the present application is as follows:

[0049] A virtual machine system, comprising:

[0050] a virtual machine, configured to create a virtual machine thread based on an RTOS;

[0051] the virtual machine thread is configured to run a corresponding application, the application is allocated with a corresponding memory resource, and the memory resources of different applications are independent of each other;

[0052] an application manager, configured to allocate a corresponding memory resource for the application, and further configured to perform download, installation, deletion, start and stop operations of the application;

[0053] an API, configured to abstract and encapsulate MCU hardware and functions, for calling by the application.

[0054] The embodiments of the present application are further described below in combination with the drawings.

[0055] In a first aspect, referring to Figs. 1-2 The embodiments of the present application provide a virtual machine system, comprising:

[0056] a virtual machine, configured to create a virtual machine thread based on an RTOS;

[0057] The virtual machine thread is used to run a corresponding application, and the application is allocated with a corresponding memory resource, and the memory resources of different applications are independent of each other;

[0058] An application manager is used to allocate a corresponding memory resource for the application, and is also used to perform download, installation, deletion, start and stop operations of the application;

[0059] An API is used to abstract and encapsulate MCU hardware and functions for the application to call.

[0060] It should be noted that the virtual machine system in the embodiments of the present application is specifically a virtual machine system running on an MCU and based on an RTOS.

[0061] In the embodiments of the present application, the OS common functions such as multi-threading, inter-thread communication and semaphores based on a mature RTOS are implemented, which reduces the development workload and ensures the stability of the system.

[0062] In addition, the functions and common functions related to the MCU hardware are encapsulated as APIs for the application to call, which greatly reduces the development difficulty of the application.

[0063] Specifically, the virtual machine thread and the application are one-to-one corresponding.

[0064] Specifically, the virtual machine threads of different applications can run in parallel and can be switched between ready state, running state and suspended state.

[0065] Multiple applications can run concurrently, enabling more flexible and rich functions.

[0066] Further, when a new application needs to be started, a corresponding virtual machine thread is created.

[0067] When the running application needs to be stopped, the corresponding virtual machine thread is deleted.

[0068] Preferably, different applications are configured with corresponding running priorities.

[0069] Specifically, the virtual machine is configured with a firewall mechanism, and the application is only allowed to access its own corresponding memory resource.

[0070] Each application runs in an independent and isolated space, effectively preventing stored information from being maliciously or accidentally damaged and leaked, and effectively improving the security and confidentiality of the virtual machine.

[0071] Specifically, different applications communicate with each other based on the API.

[0072] If necessary, the application manager can run as an independent thread, enabling the application to run and manage simultaneously.

[0073] Based on the technical solutions of the embodiments of the present application, in the specific implementation, referring to the system structure block diagram shown in Fig. 1 The virtual machine system comprises a virtual machine, an application manager, an application and an application API, and the virtual machine system runs on an RTOS system on the MCU hardware, and the specific conditions are as follows:

[0074] The virtual machine is designed as a thread entry function of the RTOS, and the thread interprets and runs the bytecode of the application. During the process of interpreting the bytecode by the virtual machine, various firewall checks are performed to prevent the application from accessing the memory content that does not belong to itself. If multiple applications need to be run, multiple virtual machine threads are created, and one virtual machine thread is responsible for interpreting and running one application. Each application has its own independent memory and is protected by the firewall to prevent illegal access.

[0075] The application manager is a thread that runs independently and is responsible for the management of the downloading, installation, deletion, start and stop of the application.

[0076] The application is installed with installation parameters to set the running priority of the application, the required memory resource size, the private information of the application and the like. If the installation parameters specify that the NVM memory needs to be allocated, a special NVM memory is allocated for the application during the installation. The NVM memory is also protected by the firewall and only allows the application to access, and other applications are prohibited from accessing. The information of the NVM memory does not disappear even when the device is powered off. Regardless of whether the application is in the start or stop state, the NVM memory is always reserved for the application. The NVM memory resource is recycled only when the application is deleted, and the information in the NVM memory is destroyed to prevent sensitive information from being leaked when the NVM memory is allocated to other applications again.

[0077] The application manager is responsible for starting and stopping the application, when an application needs to be started, a virtual machine thread is created, and the application is allocated independent RAM memory resources as the storage space of the global variables, local variables and virtual machine stack of the application; when an application needs to be stopped, the virtual machine thread is deleted, and the RAM memory content allocated for the application is emptied and recycled, which can be allocated to other applications for use;

[0078] The application manager can flexibly use various external communication methods to receive application download, installation, deletion and other management instructions, such as serial port, SPI, Internet, etc.

[0079] The application is written by the application developer according to the functional requirements of the source code on the virtual machine, the source code is compiled using the corresponding compiler of the virtual machine to generate bytecode, and then the bytecode is downloaded and installed by the application manager to form the application on the MCU.

[0080] The application API, that is, the API, abstracts and encapsulates the MCU hardware and common functions, is developed in C language, and is a program interface called by the application;

[0081] There are mainly the following types of APIs: MCU hardware related APIs, such as uart, spi, adc, etc.;

[0082] Application management class API, such as starting and stopping the application, sending messages to other applications, etc.;

[0083] Various encryption and decryption algorithm APIs, such as aes, des, rsa, etc.; Common functions in the MCU are provided on demand, such as: socket, http, mqtt, etc.

[0084] Fig. 2application1 and application2 are in the starting state, and application3 is in the stopping state: application1 and application2 are each interpreted and executed by a virtual machine thread, and each has its own NVM memory and RAM memory; application3 is in the stopping state, so no virtual machine thread interprets and runs it, the NVM memory is allocated at installation and is exclusively occupied by the application before the application is deleted, the RAM is a temporary data storage area, and application3 does not need the temporary data storage area because it is in the stopping state; the application manager thread is created when the MCU is started, always runs, and has a higher thread priority than the virtual machine thread, so that the application manager can manage the applications at any time.

[0085] In a second aspect, an embodiment of the present application provides a storage medium, which stores a computer program. The computer program is executed by a processor to implement the virtual machine system in the first aspect.

[0086] In a third aspect, an embodiment of the present application provides an electronic device, which includes a memory and a processor. The memory stores a computer program running on the processor. The processor executes the computer program to implement the virtual machine system in the first aspect.

[0087] In a fourth aspect, an embodiment of the present application provides a working method of a virtual machine system, which includes the following steps.

[0088] In response to a program download instruction, downloading and installing a corresponding application, and creating a corresponding virtual machine thread;

[0089] In response to a program deletion instruction, deleting the application and deleting the corresponding virtual machine thread; wherein,

[0090] The virtual machine system includes:

[0091] The virtual machine is configured to create a virtual machine thread based on an RTOS;

[0092] The virtual machine thread is configured to run a corresponding application, and the application is allocated with a corresponding memory resource, and the memory resources of different applications are independent of each other;

[0093] The application manager is configured to allocate a corresponding memory resource for the application, and is further configured to perform a download, installation, deletion, starting, and stopping operation of the application;

[0094] APIs for abstracting and encapsulating MCU hardware and functions for the applications to call.

[0095] It should be noted that the virtual machine system in the embodiments of the present application is specifically a virtual machine system running on an MCU and based on an RTOS.

[0096] In the embodiments of the present application, the OS common functions such as multi-threading, inter-thread communication and semaphores based on a mature RTOS are implemented, thereby reducing the development workload and ensuring the stability of the system.

[0097] In addition, the functions and common functions related to the MCU hardware are encapsulated as APIs for the applications to call, thereby greatly reducing the development difficulty of the applications.

[0098] Specifically, the virtual machine threads and the applications are one-to-one corresponding.

[0099] Specifically, the virtual machine threads of different applications can run in parallel and can be switched between the ready state, the running state and the suspended state.

[0100] Multiple applications can run concurrently, and more flexible and rich functions can be implemented.

[0101] Further, when a new application needs to be started, a corresponding virtual machine thread is created.

[0102] When the running application needs to be stopped, the corresponding virtual machine thread is deleted.

[0103] Preferably, different applications are configured with corresponding running priorities.

[0104] Specifically, the virtual machine is configured with a firewall mechanism, and the applications are only allowed to access the memory resources corresponding to themselves.

[0105] Each application runs in an independent and isolated space, effectively preventing the stored information from being maliciously or accidentally damaged and leaked, and effectively improving the security and confidentiality of the virtual machine.

[0106] Specifically, different applications communicate with each other based on the APIs.

[0107] If necessary, the application manager can be an independently running thread, which can enable the running and management of the applications to be performed simultaneously.

[0108] Based on the technical solutions of the embodiments of the present application, in specific implementation, the virtual machine system includes a virtual machine, an application manager, an application and an application API, the virtual machine system runs on an RTOS system on an MCU hardware, and the specific conditions are as follows:

[0109] Virtual machine, designed as a thread entry function of RTOS, the thread interprets the bytecode of the application, and the virtual machine interprets the bytecode. During the process of interpreting the bytecode, various firewall checks are performed to prevent the application from accessing memory content that does not belong to itself; if multiple applications need to be run, multiple virtual machine threads will be created, with one virtual machine thread responsible for interpreting and running one application, and each application has its own independent memory and is protected by a firewall to prevent illegal access.

[0110] Application manager, i.e. application manager, a thread running independently, is responsible for the management of application download, installation, deletion, start, stop, etc.

[0111] Application, i.e. application, when installed, can carry installation parameters to set the running priority of the application, the size of various required memory resources, private information of the application, etc. If the installation parameters specify that NVM memory needs to be allocated, a special NVM memory will be allocated for it during installation. This memory is also protected by the firewall and only allows access by the application to which it belongs. Other applications are prohibited from accessing it. The information of the NVM memory does not disappear even when the device is powered off. Whether the application is in a start or stop state, it is always reserved for the application. The NVM memory resource is only recovered when the application is deleted. The information in it will be destroyed to prevent sensitive information from being leaked when it is allocated to other applications again.

[0112] The application manager is responsible for starting and stopping the application. When an application needs to be started, a virtual machine thread is created, and independent RAM memory resources are allocated for the application as global variables, local variables, and virtual machine stack storage space. When an application needs to be stopped, the virtual machine thread is deleted, and the RAM memory allocated for the application is emptied and recycled, which can be allocated to other applications for use.

[0113] The application manager can flexibly use various external communication methods to receive application download, installation, deletion, and other management instructions, such as serial port, SPI, Internet, etc.

[0114] application, the application developer writes source code on the virtual machine according to the functional requirements, compiles the source code using the corresponding compiler of the virtual machine to generate bytecode, and then downloads and installs the bytecode through the application manager to form the application on the MCU.

[0115] application API, that is, API, which abstracts and encapsulates the MCU hardware and common functions, is developed using C language and is a program interface called by the application;

[0116] There are mainly the following types of API: MCU hardware-related API, such as uart, spi, adc, etc.;

[0117] application management class API, such as starting and stopping the application, sending messages to other applications, etc.;

[0118] Various encryption and decryption algorithm API, such as aes, des, rsa, etc.; commonly used functions in the MCU are provided on demand, such as: socket, http, mqtt, etc.

[0119] When there are three applications on the MCU, application 1 and application 2 are in the started state, and application 3 is in the stopped state, the state of thread and resource allocation: application 1 and application 2 are each interpreted and executed by a virtual machine thread, and each has its own NVM memory and RAM memory; application 3 is in the stopped state, so there is no virtual machine thread to interpret and run it, the NVM memory is allocated when it is installed and is exclusively occupied by the application before it is deleted, the RAM is a temporary data storage area, and application 3 does not need the temporary data storage area because it is in the stopped state; the application manager thread is created when the MCU starts and runs all the time, and its thread priority is higher than that of the virtual machine thread, so that the application can be managed at any time.

[0120] It has to be noted that, in the present application, the terms "first", "second", etc. are used merely to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the presence of additional identical elements in the process, method, article, or apparatus that comprises the element.

[0121] The foregoing detailed description has set forth various embodiments of the application via the use of specific terminology. However, embodiments thereof can be practiced without the specific details ("every" embodiment) set forth above. In general, the terms used are intended to be illustrative and not restrictive, and it will be apparent to those skilled in the art that other variations and modifications of the application can be made without departing from the spirit or scope of the application. Accordingly, the scope of the application should be determined not with the foregoing description alone, but instead should be determined in accordance with the appended claims and their equivalents.

Claims

1. A virtual machine system, characterized in that: The system comprises: A virtual machine, which is used to create a virtual machine thread based on the RTOS; The virtual machine thread is used to run a corresponding application, the application is allocated with corresponding memory resources, and the memory resources of different applications are independent of each other; An application manager, which is used to allocate corresponding memory resources to the application and to execute download, installation, deletion, start and stop operations of the application; API, which is used to abstract and encapsulate MCU hardware and functions for the application to call; The virtual machine threads of different applications can run in parallel and can switch between a ready state, a running state, and a suspended state; The virtual machine is configured with a firewall mechanism, and the application is only allowed to access the memory resources corresponding to the application.

2. The virtual machine system according to claim 1, wherein: When a new application needs to be started, a corresponding virtual machine thread is created; When the running application needs to be stopped, the corresponding virtual machine thread is deleted.

3. The virtual machine system according to claim 1, wherein: The running priorities corresponding to different application configurations.

4. The virtual machine system according to claim 1, wherein: Different applications communicate with each other based on the API.

5. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the virtual machine system according to any one of claims 1 to 4 is implemented.

6. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that runs on the processor, wherein: When the processor executes the computer program, the virtual machine system according to any one of claims 1 to 4 is implemented.

7. A method for operating a virtual machine system, characterized in that: The method comprises the following steps: Respond to the program download instruction, download and install the corresponding application, and create the corresponding virtual machine thread; In response to the program deletion instruction, the application is deleted, and the corresponding virtual machine thread is deleted; The virtual machine threads of different applications can run in parallel and can switch between a ready state, a running state, and a suspended state; The virtual machine is configured with a firewall mechanism, and the application is only allowed to access its corresponding memory resources; in, The virtual machine system includes: The virtual machine is used to create a virtual machine thread based on the RTOS; The virtual machine thread is used to run a corresponding application, the application is allocated with corresponding memory resources, and the memory resources of different applications are independent of each other; An application manager, which is used to allocate corresponding memory resources to the application and to execute download, installation, deletion, start and stop operations of the application; The API is used to abstract and encapsulate the MCU hardware and functions for the application to call.

Citation Information

Patent Citations

  • Synchronizing virtual machine and application life cycles

    CN102057355A