A method and device for dynamic programming of memory layout when an embedded system is started
By introducing a memory layout manager in an embedded system, the problems of memory allocation conflicts and errors in an embedded system are solved, and the dynamic planning and management of memory space is realized, which improves the reliability and memory utilization of the system.
Patent Information
- Application Number
- CN202111440687.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2041-11-30
AI Technical Summary
During the startup process of embedded system, the lack of effective memory layout management means leads to memory allocation conflicts and errors, especially the lack of exchanging memory allocation information between software modules, which leads to easy logical errors and software failures when adjusting business logic.
A dynamic planning method for memory layout is proposed. By setting up a memory layout manager that spans different exception levels in memory, providing application, registration, query and release functions, coordinating the management of memory space, and ensuring the uniqueness and conflict of memory allocation avoid.
It realizes convenient modification of memory space size, avoids memory allocation errors, improves software reliability and memory utilization, and simplifies the memory layout adjustment process.
Smart Images

Figure CN114116222B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to a memory management method for an embedded system, and more particularly to a method for dynamic programming of memory layout during the startup process of an embedded system. Background Art
[0002] In computers and similar devices, memory layout refers to the organization and arrangement of different types of information stored in memory space. For example, the first boot image file, the second boot image file, data, etc. are different types of information; they all need to be loaded into the memory, but they cannot conflict, otherwise the logic will be abnormal after the information is overwritten. Then, stipulating that the first boot image file is located at the beginning of the memory, the second boot image file is located after the first boot image file, and the data space (i.e., the space for storing data) is located at the end of the memory is one memory layout. Similarly, stipulating that the data space is located at the beginning of the memory, the first boot image file is located after the data space, and the second boot image file is located after the first boot image file is another memory layout. Memory layout planning refers to the process of selecting a memory layout from multiple possible memory layouts as a product layout.
[0003] The processors in embedded systems are designed to have multiple exception levels (EL), corresponding to different privileges for the processor and memory. Taking the ARM v8 architecture processor as an example, there are 6 exception levels: EL0, EL1, EL2, EL3, SEL0 and SEL1; SEL represents the secure exception level. When entering a certain exception level, the processor executes from the address corresponding to the exception level. Each exception level corresponds to a software module, where "software module" refers to all software logic under a certain exception level. The entry of the software module at each exception level is set to the execution entry address of all software logic at that exception level. Software modules at different exception levels are generally independent of each other and communicate with each other only through a small number of internal registers and mode switching commands.
[0004] In the process of embedded system startup, taking the processor of ARM v8 architecture as an example, generally only four exception levels of EL3, EL2, EL1 and SEL1 are involved. The software module of EL3 includes three software logics in the startup order, namely BOOTROM (boot read-only memory), SPL (Second Program Loader) and SLOADER (Secure Loader). BOOTROM and processor are solidified together. SLOADER can also be changed to other monitoring layer software for switching between REE (Rich Execution Environment) and TEE (Trusted Execution Environment), such as the monitor mode in the processor of ARM v7 architecture. The software module of EL2 refers to U-BOOT (full name Das U-Boot, the Universal Boot Loader), which can also be changed to other non-secure boot loaders. The software module of EL1 is REE operating system, also known as non-secure operating system, such as Linux. The software module of SEL1 refers to TEE operating system, also known as secure operating system (secure OS). During the startup of the embedded system, each of the above-mentioned software modules of the abnormal level needs to be initialized and run alternately or simultaneously.
[0005] Taking the ARM v8 architecture processor as an example, the running order of each software module and the software logic therein in the standard startup process of the embedded system is as follows. (1) Start running from BOOTROM. BOOTROM is fixed in the processor and does not occupy memory. BOOTROM is the software logic to which the first instruction executed after the processor is powered on belongs. It is generally fixed in the chip and cannot be modified. Because BOOTROM cannot be modified, considering the flexibility of later upgrades, it generally does not take on too much software logic, but only reads SPL and executes it. (2) Memory initialization is completed through SPL. SPL itself does not occupy memory, but after completing memory initialization, it will load subsequent software logic (SLOADER) and software modules (TEE operating system) into memory. Therefore, although SPL is not executed in memory, it needs to use memory. When SPL is executed, the hardware initialization has not been completed. It has only a few hardware resources available, so it will be used, for example, to initialize the advanced functions of the CPU, enable the memory management unit (MMU), enable cache, initialize memory, etc. SPL can be considered as an extension of BOOTROM, used to complete the loading of subsequent business images. However, SPL can be modified and is not fixed in the processor, so it has a high degree of flexibility. (3) SLOADER is initialized and runs in memory. (4) The secure operating system is initialized and runs in memory. (5) U-BOOT is started and runs in memory. (6) The non-secure operating system is started and runs in memory. The memory is, for example, DDR SDRAM (Double Data Rate Synchronous Dynamic Random Access Memory).
[0006] Among them, SPL and U-BOOT are both executed once during the startup process of the embedded system, and the memory space used or occupied by them can be released after execution. SLOADER, secure operating system and non-secure operating system need to be executed in memory all the time to meet business needs. SLOADER, secure operating system and non-secure operating system belong to three exception levels of software modules respectively, so it involves loading multiple exception levels of software modules running simultaneously into different memory spaces for simultaneous operation. From the perspective of saving memory, it is best for multiple exception levels of software modules running successively to reuse (staggered in time) the same memory space. This puts forward requirements for the planning of memory layout.
[0007] "Static planning module" refers to software logic or software module that uses a memory area of fixed length and fixed position. During the software development process, some software logic must specify the memory loading address during the compilation phase, and then it must be loaded to the same memory address specified during the compilation phase in order to execute correctly. If the loading address is different from that specified during the compilation phase, the software logic will be wrong. Relatively simple software logic or software modules such as SPL, SLOADER, and secure operating system generally do not have the ability to dynamically adjust the loading address. Therefore, when doing memory layout planning, it is necessary to consider that the location of these software logic or software modules is determined during compilation. When adjusting the memory layout planning, these software logic or software modules are generally not recompiled, so the loading and execution addresses originally reserved for them cannot be moved or changed.
[0008] "Dynamic programming module" refers to software logic or software modules that use memory areas with variable length and position. The information of modules such as Linux memory pool is described by DTS (Device Tree). It is relatively easy to adjust the content of DTS compared to recompiling the image. When adjusting the memory layout plan, the content of DTS can be changed. Therefore, the information of the memory pool can be adjusted by modifying DTS without compiling the image. After adjusting DTS, reread DTS after Linux starts, and you can get the new memory pool information, and complete the initialization of the memory pool based on the new information.
[0009] That is to say, when adjusting the memory layout, the dynamic planning module can be relocated and resized, while the static planning module cannot be relocated and resized. The static planning module can also be modified by completely recompiling, but after the software is released, customers cannot compile it by themselves, and development engineers generally do not compile it completely. Therefore, when planning the layout, static planning modules and dynamic planning modules are divided into two types and treated differently.
[0010] During the startup of an embedded system, there is a lack of means for exchanging memory allocation information between software modules at various exception levels, which can lead to a variety of problems, as detailed below.
[0011] First, during the startup of the embedded system, the loading addresses of BOOTROM, SPL, secure operating system, U-BOOT, and non-secure operating system are all determined at the compilation stage, so they are static and cannot be adjusted dynamically. Due to the lack of common memory layout information between them, when one of the software modules changes the memory layout due to business logic requirements, it may affect other software modules and destroy the normal logic of other software modules. For example, in the initial planning, the secure operating system occupies the [0x10000-0x1FFFF] address segment of the memory space as its code segment, and the non-secure operating system uses the [0x20000-0x40000] address segment of the memory space as its code segment, where 0x represents a hexadecimal number. However, once the secure operating system needs to introduce more secure services, there is a need to expand the secure operating system code. At this time, the expanded code segment of the secure operating system (perhaps set to [0x10000-0x2FFFF]) invades the code segment of the non-secure operating system. If the code segment of the non-secure operating system is not adjusted accordingly, then this conflict will cause a logical error in the secure operating system or the non-secure operating system. In actual product development, the software modules of various abnormal levels in these startup phases are completed by different engineers distributed in different teams, and some are even modified by customers themselves after the product is released. Therefore, a simple business logic adjustment (such as introducing a new function in the secure operating system) will lead to unexpected problems (secure operating system or non-secure operating system errors), and there is no strong correlation between the manifestation of such errors and the specific adjustments to the business logic. It is possible that the secure operating system introduces an encryption algorithm, resulting in a larger space occupied by the secure operating system, thereby causing the above-mentioned intrusion into the running space of the non-secure operating system. As a result, illegal instruction errors are encountered during the execution of the non-secure operating system, which brings great difficulties to tracking and debugging.
[0012] Second, during the startup of the embedded system, the software modules at different exception levels also need to use memory to transfer some shared information. For example, SPL reads the chip information into the memory, and U-BOOT reads it and decides to enter different software logic branches in U-BOOT. In order to achieve this function, both SPL and U-BOOT are required to know the memory address of this shared information, so that the data written by SPL can be consistent with the data read by U-BOOT. In the product life cycle, it is a very common operation to expand the size of shared memory due to product requirements. Similarly, when SPL and U-BOOT belong to different developers, if one party modifies the memory address and the other party does not modify it, the written and read data will be inconsistent, causing software failures.
[0013] Third, there are also difficulties for software logic whose loading address can be adjusted dynamically, such as the reserved memory pool after entering the non-secure operating system (the size is variable, and the specific starting point can be adjusted. As long as the adjusted starting address and size are marked to the non-secure operating system, it can be used normally). Generally speaking, in order to reduce the memory holes of the non-secure operating system, developers hope that the continuous address space left after the entire memory planning is large enough. Therefore, the memory space occupied by the static planning module (executable image) and the dynamic planning module (memory pool) should be uniformly adjusted from a global perspective to maximize the remaining continuous memory space. For example, the static planning module occupies the [0x0000-0x3FFF] address segment of the memory space, and the dynamic planning module 1 occupies the [0x4000-0x5FFF] address segment of the memory space. Then a new dynamic planning module 2 should follow the dynamic planning module 1 and occupy the [0x6000-0x7FFF] address segment of the memory space. In this way, for Linux, the [0x0000-0x7FFF] address segment of the memory space is reserved, and the remaining memory space is available and physically continuous. Then, considering that for business reasons, the dynamic programming module 1 needs to expand its range from a length of 0x2000 to a length of 0x3000. At this time, either manually adjust the memory space of dynamic programming module 1 and dynamic programming module 2 at the same time, for example, change it to the [0x4000-0x6FFF] address segment of the memory space occupied by dynamic programming module 1, and modify the [0x7000-0x8FFF] address segment of the memory space occupied by dynamic programming module 2, to ensure that the remaining address space seen by Linux is still physically continuous (after 0x9000). If only one place is changed, the position of dynamic programming module 1 can only be moved, for example, from the [0x4000-0x5FFF] address segment of the memory space to the [0x8000-0xAFFF] address segment. However, for Linux, the available memory space is divided into two parts: the [0x4000-0x5FFF] address segment vacated by the dynamic programming module 1 and the memory space after 0xB000. From the perspective of reducing modification points and thus improving software reliability, since our requirement is to adjust the size of the dynamic programming module 1, it is best to only modify the memory configuration of the dynamic programming module 1, and engineers who do not need to adjust the dynamic programming module 1 need to master all the information related to the memory layout, thereby reducing the possibility of errors.
[0014] In the prior art, a document is used to describe the layout plan of the memory during the startup process of the embedded system, and the developer of each software module is required to know this layout plan and write the logic of the software module according to this layout plan. When there is a change to the memory layout plan, it is necessary to notify the developers of all software modules to review the new layout plan together. After reaching an agreement, the various software modules and the software logic therein are adjusted and modified according to the new layout plan, thereby completing an overall software module upgrade. The prior art relies on software engineering to ensure that the upgrade and modification of a software module will not affect other software modules in a manual review and programming specification manner, but this method is time-consuming and labor-intensive, and in practice it cannot ensure that each modification of the memory layout will not cause errors. For example, the newly released memory layout document often cannot be delivered to the developer and modifier of each software module in a timely manner, so that the changes of each software module cannot be consistent, and various errors will still be introduced, and a lot of time is needed to check the errors one by one to find the cause. Summary of the invention
[0015] The technical problem to be solved by the present application is to provide a method for dynamic programming of memory layout which is convenient for modifying the size of memory space and is not prone to causing memory allocation errors.
[0016] To solve the above technical problems, the present application proposes a method for dynamic memory layout planning when an embedded system is started, comprising the following steps. Step S11: A memory layout manager for software modules across different exception levels is set in the memory, and the memory layout manager includes an application function, a registration function, a query function, a control function, a release function and a data structure for storing memory layout information. The application function is used to allocate memory for the dynamic planning module; the dynamic planning module refers to a software module or software logic that uses a memory area with an unfixed length and a variable position. The registration function is used to allocate memory for the static planning module; the static planning module refers to a software module or software logic that uses a memory area with a fixed length and a fixed position. The query function is used to query the allocated memory space according to the name. The control function is used to notify the memory layout manager which stage is currently entered. The release function is used to actively release the allocated memory space. Step S12: When the static planning module needs to use memory, the registration function is called to provide the memory base address, memory space size, and memory space name; the memory layout manager detects whether the memory base address, memory space size, and the existing memory allocation state conflict; if there is a conflict, it returns failure, otherwise the memory base address, memory space size, and memory space name are registered in the existing memory allocation state, and success is returned; the allocated memory space has a unique name. Step S13: When the dynamic planning module needs to use memory, the application function is called to provide the required memory space size and memory space name; if no suitable memory space can be found, an error is returned; otherwise, the memory dynamic allocator allocates a memory space of corresponding size in the free memory, registers the physical address, memory space size, and memory space name of the memory space in the existing memory allocation state, and marks that the memory space has been occupied, and returns the physical address to the dynamic planning module; the allocated memory space has a unique name. The order of the steps S12 and S13 can be interchanged or performed simultaneously. Step S14: the software module or software logic queries the allocated memory space according to the name of the memory space by calling the query function. Step S15: the software module or software logic releases the allocated memory space by calling the release function. The above method manages the memory usage of software logics of all exception levels by the memory layout manager, which is conducive to the transmission and use of information across different exception levels.
[0017] Furthermore, in step S11, the memory layout manager is loaded into the memory when the memory of the embedded system is just initialized; after the memory layout manager is loaded, the software modules of each exception level or the software logic therein call the function of the memory layout manager by initiating a function call.
[0018] Preferably, after the embedded system is powered on, the memory layout manager module is loaded into the memory by the boot read-only memory BOOTROM code solidified in the processor, or the BOOTROM code first loads the second stage program loader SPL to complete the memory initialization, and then the memory layout manager module is loaded into the memory by SPL.
[0019] Furthermore, in step S12 and step S13, when the size of any memory space is adjusted, the memory layout manager always searches for non-conflicting available memory areas to allocate other memory spaces during the restart of the embedded system, that is, to automatically adjust the memory layout.
[0020] Furthermore, in step S12 and step S13, a memory space name is provided when a new memory space is registered or a new memory space is applied for; the memory layout manager compares the received memory space name with the name of the allocated memory space. If there is an allocated memory space with the same name, no new memory space will be allocated, but the existing memory space information with the same name will be directly returned.
[0021] Furthermore, the data structure for storing memory layout information is used to store memory space information, and each piece of memory space information includes the starting address, size, name and attributes of the memory space; the attributes include one or more of the following information: whether the memory space is statically registered or dynamically applied for, usage phase information, and release phase information.
[0022] Furthermore, in the step S12 and step S13, the use phase and release phase information are provided when a memory space is newly registered or newly applied for. The use phase refers to the phase or phases in which a certain memory space needs to be used, and the release phase refers to the phase in which a certain memory space is no longer used and can be released. The step S15 also includes: or, the software module or software logic releases the allocated memory space when the control function of the memory layout manager notifies the corresponding phase of entering the embedded system through the release phase information specified when a certain memory space is allocated. This is another implementation scheme for releasing memory space provided by the present application.
[0023] Furthermore, in step S12 and step S13, when the use phase of a memory space to be allocated is later than the release phase of an allocated memory space, when allocating memory space for the memory space to be allocated, the allocated memory space is regarded as free and allowed to be allocated to the memory space to be allocated.
[0024] Furthermore, in step S14, software modules of different exception levels or software logic therein implement information transmission across different exception levels by writing and reading memory spaces with the same name.
[0025] The present application also proposes a device for dynamic memory layout planning when an embedded system is started, comprising a management unit, a static allocation unit, a dynamic allocation unit, a query unit and a release unit. The management unit is used to set a memory layout manager for software modules across different exception levels in the memory; the memory layout manager includes an application function, a registration function, a query function, a control function, a release function and a data structure for storing memory layout information. The application function is used to allocate memory for the dynamic planning module; the dynamic planning module refers to a software module or software logic that uses a memory area with an unfixed length and a variable position. The registration function is used to allocate memory for the static planning module; the static planning module refers to a software module or software logic that uses a memory area with a fixed length and a fixed position. The query function is used to query the allocated memory space according to the name. The control function is used to notify the memory layout manager which stage is currently entered. The release function is used to actively release the allocated memory space. The static allocation unit is used to call the registration function when the static planning module needs to use memory, provide the memory base address, memory space size, and memory space name; the memory layout manager detects whether the memory base address, memory space size, and the existing memory allocation state conflict; if there is a conflict, return failure, otherwise register the memory base address, memory space size, and memory space name into the existing memory allocation state, and return success; the allocated memory space has a unique name. The dynamic allocation unit is used to call the application function when the dynamic planning module needs to use memory, provide the required memory space size and memory space name; if no suitable memory space can be found, return an error; otherwise, the memory dynamic allocator allocates a memory space of corresponding size in the free memory, registers the physical address, memory space size, and memory space name of the memory space into the existing memory allocation state, and marks that the memory space has been occupied, and returns the physical address to the dynamic planning module; the allocated memory space has a unique name. The query unit is used to query the allocated memory space according to the name of the memory space by calling the query function. The release unit is used to release the allocated memory space by calling the release function. The above device uses a memory layout manager to manage the memory usage of software logics at all exception levels, which is conducive to the transmission and use of information across different exception levels.
[0026] The technical effects achieved by the present application are: (1) The memory layout manager manages the memory usage of software logic at all exception levels, which is conducive to the transmission and use of information across different exception levels. (2) The memory space size modification is more convenient and will not cause errors in which the allocated memory space overlaps with each other. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1It is a flow chart of the method for dynamic programming of memory layout when the embedded system is started, which is proposed in this application.
[0028] Figure 2 This is a schematic diagram of the memory layout Figure 1 .
[0029] Figure 3 This is a schematic diagram of the memory layout Figure 2 .
[0030] Figure 4 It is a structural schematic diagram of a device for dynamic memory layout planning when an embedded system is started, as proposed in this application.
[0031] Explanation of the reference numerals in the figure: 11 is a management unit, 12 is a static allocation unit, 13 is a dynamic allocation unit, 14 is a query unit, and 15 is a release unit. DETAILED DESCRIPTION
[0032] See also Figure 1 The method for dynamic planning of memory layout when the embedded system is started proposed in this application includes the following steps.
[0033] Step S11: a memory layout manager is set in the memory to span software modules of different exception levels to meet the different requirements of different software logics or software modules for memory layout. The memory layout manager needs to be called by software modules of multiple exception levels, and can be considered to be in software modules of multiple exception levels at the same time. The memory layout manager includes a set of predefined application functions, registration functions, query functions, control functions, release functions and data structures for storing memory layout information. As an independent library, the memory layout manager is loaded into the memory in the early stage of the startup process, when the memory is just initialized. Each function in the memory layout manager is an API (application programming interface), and its entry is loaded into the fixed address of the memory (resident memory). After the memory layout manager is loaded, the software modules of each exception level can enter the API exposed to the outside by the memory layout manager at any time as long as they initiate a standard function call to the fixed address of the memory (i.e., let the processor execute instructions at this fixed address), thereby realizing the call of the corresponding function.
[0034] The application function is used to allocate memory for the dynamic programming module. The dynamic programming module applies for memory space from the memory layout manager by submitting the required memory space size and memory space name to the application function. The memory layout manager finds the area that meets the required memory space size from the free memory space and returns the physical address to the dynamic programming module for use. The application function returns the physical address to support the use of software modules across exception levels.
[0035] The registration function is used to allocate memory for the static planning module. The static planning module calls the registration function according to the static memory address it needs (such as the execution address space specified at compile time), provides the memory base address (physical address), memory space size and memory space name, and registers the memory space with the memory layout manager. The memory layout manager detects whether there is a conflict between the parameters provided by the registration function and the existing memory allocation status. If there is a conflict, it returns failure; otherwise, it registers the memory base address and memory space size into the existing allocation status and returns success. The registration function provides the physical address to support the use of software modules across exception levels.
[0036] The query function is used to query whether there is a memory space with the same name in the allocated memory space according to the given memory space name. If there is, the information of this memory space is returned, that is, the content saved in the data structure of the memory layout information, including the starting address, size, name and attributes of the memory space. The attributes include one or more of the following information: whether the memory space is statically registered or dynamically applied for, usage phase information, release phase information, etc. In the specific implementation of different projects, additional attributes can also be added to support software business requirements. For example, when a software logic or software module needs a piece of memory space to complete a certain business, it first queries the memory layout manager to see if there is a memory space that meets its business needs. If it already exists, the memory layout manager will return the information of the memory space. After the software logic or software module obtains the information, it can directly use the memory space. If it does not currently exist, the software logic or software module can apply for or register a new memory space to meet business needs.
[0037] The control function is used to manage the memory layout manager, including notifying the memory layout manager which phase is currently entered. Optionally, the statically registered or dynamically applied memory space contains the use phase and release phase information. The use phase refers to the phase or phases in which a certain memory space needs to be used, and the release phase refers to the phase in which a certain memory space is no longer used and can be released. When the memory layout manager finds that it has entered the release phase of a certain memory space, it will automatically release the matching memory space to complete the memory recycling.
[0038] The release function is used to actively release the allocated memory space. On the one hand, the use phase and release phase information of the allocated memory space are supported in the application function and the registration function (optional). When the memory layout manager receives the notification of the control function, it will automatically release the memory space based on whether the release phase of the memory space matches the current phase. On the other hand, the software module or software logic itself can still actively release the memory space through the release function. This type of application is used to meet software business requirements like this: in different time periods of the same software business, there are different memory space requirements, so this mechanism can be used to autonomously apply and release, thereby improving the utilization of memory space.
[0039] Step S12: The memory demand of the static planning module is determined at the compilation stage, so it cannot be adjusted dynamically. Some software logic or software modules, such as SPL, SLOADER, and TEEOS, need to specify the address space at runtime during the compilation stage. Therefore, in the memory layout, such software logic or software modules must be loaded to a location consistent with the address specified at the compilation stage, which belongs to static memory planning. When the static planning module needs to use memory, it submits parameters to the registration function of the memory layout manager to notify the memory dynamic allocator that a certain memory space needs to be used. If this memory space is not used by other software logic or software modules, the memory dynamic allocator will agree to the registration and mark that the memory space is already occupied. If this memory space is already occupied, an error is returned directly. For the registration process, the memory layout manager does not attempt to allocate dynamically.
[0040] Step S13: The dynamic planning module only has a demand for the size of the memory, and the specific location is variable. There are some software logics or software modules whose working memory address space is allowed to change. The software logic or software module can adaptively adjust its business logic according to the dynamically allocated address space, which belongs to dynamic memory planning. For such software modules, the memory address space used for such work is allowed to change each time it is executed. When the dynamic planning module needs to use memory, it submits parameters to the application function of the memory layout manager to notify the memory dynamic allocator of the required memory size. The memory dynamic allocator finds the most reasonable (for example, minimizing memory holes, etc.) and size-satisfying memory space in the free memory space, marks the memory space as occupied, and returns the starting address to the applicant. If no suitable memory space can be found, an error is returned. In the application mode, the memory layout manager will try to dynamically allocate memory space. This allocation method of finding the most reasonable memory space that meets the application size is the meaning of "dynamically allocating memory space".
[0041] The memory space application process includes: allocating a memory space of sufficient size from the available memory, and marking the name of this memory space for other software logic or software modules to query. The design of attaching a name related to the purpose to each allocated memory space is used to help transfer business data between the same software business across multiple software modules. For example, SPL allocates a memory space named "ShareInfo" and writes the business data that needs to be transferred. When the life cycle of SPL ends, its code segment and data segment are released, but the memory space "ShareInfo" managed by the memory layout manager will not be released. After booting to UBOOT, UBOOT can query the memory space allocated in the SPL stage by the name "ShareInfo", obtain the business data written by SPL from it, and complete the transfer of shared data between software modules whose business life cycles do not overlap.
[0042] There is no strict restriction on the order of step S12 and step S13, and either step can come first.
[0043] Regardless of whether the memory space is obtained through registration or application, it has a memory space name that describes the purpose of this memory space, and the names of different memory spaces are different. For example, the memory space marked as TEE OS refers to the space used for the secure operating system. The correspondence between the name and purpose of this memory space may be different for different projects and is defined by the document. When a new memory space is newly registered or newly applied for, a memory space name is provided to describe the purpose of the memory for this registration or application. Before actually allocating new memory space to complete the registration or application, the memory layout manager compares the name provided by the caller with the name of each allocated memory space in the existing memory layout. If there is an allocated memory space with the same name, no new memory space will be allocated, but the existing memory space information will be directly returned.
[0044] Step S14: Since the memory layout manager is used to specify a name for the allocated memory space, when searching and using the allocated memory space, it is not searched according to the address of the memory space, but searched according to the name of the memory space, which is a core innovation of the present application. Because it spans different software modules, the address of the memory space can be dynamically allocated, and it is impossible to allocate memory for one software logic or software module and pass the address to another software logic or software module for use as in traditional memory allocation. Because during the startup process, there is no convenient way to pass address information between software modules that span the abnormal level (originally it is passed by shared memory, but the premise of shared memory is that the address can be passed). Therefore, using the name of the memory space pre-determined by both parties to allocate and search for the allocated memory is an implementation method of the present application to solve the problem that the content is still available after spanning software modules and hot restart. Hot restart refers to a startup method in which the content in the memory is not lost, but the embedded system will restart and go through the startup process again.
[0045] Step S15: according to the release phase information specified when a certain memory space is allocated, the allocated memory space is released when the control function of the memory layout manager notifies the corresponding phase of the embedded system. Alternatively, the software module or software logic releases the allocated memory space by calling the release function of the memory layout manager.
[0046] The difference from the memory allocator in the prior art is that the memory layout manager in this application provides services for software logic or software modules distributed in different exception levels or even in different life cycles, and is not limited to providing memory allocation services for a specific software logic or software module. For example, the malloc service in Linux can allocate available memory for processes in Linux, but the allocated memory cannot be passed to SPL or TEEOS in a unified manner for use, while the memory layout manager of this application can meet this demand. A specific software service may span different software modules. In this application, the software modules are each at different exception levels, so unlike different software logics that usually run at the same exception level, they can use similar OS functions (pipe files, semaphores) to share information, and can only pass information through shared memory. And shared memory needs to rely on memory layout.
[0047] This application solves the problem that in the memory layout across software modules, it is necessary to manually and statically plan the memory space used by each software logic or software module in different life cycles; when the number of software logic or software modules increases, such manually planned memory layout is prone to errors and the free memory is scattered. Traditional memory management requires a manager role to respond to the memory needs of subsequent requesters. However, in the scenario across software modules, the manager may have completed its life cycle and exited at some point, so the subsequent memory allocation service cannot be performed. This application removes the role of the manager, so that the allocation of memory layout can work across the life cycle of multiple different tasks. For example, the original memory allocation can only be performed in Linux. The memory allocated by Linux is currently valid, but after the device is restarted, the restarted Linux will lose the previous allocation information. In engineering practice, there is a need to capture pre-restart information for development and debugging. The existing Linux memory allocation technology cannot meet this demand. For example, software logic A runs before software logic B, and software logic A and software logic B belong to software modules with different exception levels. Both software logic A and software logic B require a section of memory space to complete their logic. In the first released version, software logic A and software logic B use statically planned memory space respectively, which are independent and non-overlapping, so that the business logic is normal. Afterwards, due to business adjustments, software logic A needs to expand the memory space. At this time, the developer of software logic A will statically expand (modify in the compilation stage) the memory space occupied by software logic A, but he may not know the business logic of software logic B, nor the memory space reserved by software logic B before. This modification may cause the memory area of software logic A and software logic B to overlap, resulting in abnormal business logic of software logic A or software logic B. From the perspective of software logic A alone, its business logic adjustment is normal behavior because it is difficult to find problems in the first place. After using the technical solution of the present application, software logic A dynamically allocates the expanded memory space during operation to meet its needs, and after the device is restarted, the memory layout manager will always find a non-conflicting available memory area to allocate new memory space for software logic B, that is, software logic B uses the memory allocation mechanism of software modules across different exception levels to ensure that it is allocated to an independent memory space, and there will be no problems with the business. This indicates that when the size of a memory space is adjusted, the present application can utilize the mechanism of registering or applying for allocation of memory space one by one by the memory layout manager during the startup process of the embedded system to realize automatic adjustment of the memory layout, thereby forming a new memory layout.
[0048] The core technical innovation of this application is to realize the memory allocation management between software modules under different exception levels of the processor, and to record information in the case of hot restart of the embedded system for use after reset. As an analogy, although the above software concept has a similar implementation under Linux, that is, the traditional memory allocation technology, it can only be used in Linux (system mode or EL1), and it is impossible for Linux to allocate a section of memory to the secure operating system, nor is it possible to allocate a section of memory and then hot restart the embedded system to use this section of memory after entering Linux again.
[0049] The following is a detailed description of the technical solution of this application using a specific embodiment. Figure 2 This is a typical memory layout planning diagram. The first row in the figure represents the software logic or software modules in the embedded system startup process, from left to right, it means starting one by one in chronological order; that is, the startup process starts from BOOTROM (not shown), and then loads SPL, SLOADER, secure operating system, U-BOOT until the non-secure operating system, and finally starts the business process in the non-secure operating system to complete the startup. Figure 2 The figure is divided into columns to show the memory space requirements of each software logic or software module. White indicates that the memory is occupied or used, and dark diagonal filling indicates that the memory is not occupied or used. For example, during the startup process of the embedded system, the SPL software logic needs to use the secure operating system area (static), security parameter area (dynamic), U-BOOT area (static), core scenario parameter area (dynamic) and RAM dump area (dynamic) in the memory. Similarly, after entering the software module of the non-secure operating system, the memory requirements are the secure operating system area (static), kernel code area (static), RAM dump area (dynamic) and two reserved shared memory pools (dynamic). Figure 2 Each row in reflects a memory space requirement. For example, the U-BOOT area (static) is allocated in the SPL stage and is released after the U-BOOT is executed. The trusted firmware area (dynamic) is only allocated and used in the SLOADER stage.
[0050] Completed using the memory layout manager proposed in this application Figure 2 The memory layout shown includes the following steps.
[0051] Step 1: After the embedded system is powered on, the BOOTROM (not shown) loads the memory layout manager (not shown) into the memory.
[0052] Step 2: The SPL software logic is executed after being loaded by BOOTROM. After SPL is started, the control function of the memory layout manager is called to notify it that it is currently in the SPL stage. After obtaining control of the processor, the memory layout manager determines that if it has not completed initialization, it will complete initialization. In the SPL software logic, in order to load subsequent software modules (secure operating system) and software logic U-BOOT, it is necessary to apply for memory space from the memory layout manager. The running addresses of the secure operating system and U-BOOT are determined during the compilation phase, so they belong to the registration mode. SPL initiates a call to the registration function to the agreed address where the memory layout manager is stored, and registers the secure operating system area (static) and U-BOOT area (static) respectively. The memory layout manager completes the logic of the registration function, marks the memory addresses that the secure operating system and U-BOOT need to use as used in the available memory space, and returns the result. If the memory addresses registered by the secure operating system and U-BOOT conflict, for example, the addresses of the two overlap, the registration function called later returns failure. SPL can capture this error and prompt the user, so that the problem can be discovered at the first time, instead of waiting until the secure operating system and U-BOOT overwrite the values in their respective memories and cause logical errors, which is more convenient for debugging. While registering, mark the name and attributes of the secure operating system area (static) memory space. For example, the attribute is that it is only reinitialized in SPL, but will not be released by any other software logic or software module. Mark the name and attributes of the U-BOOT area (static) memory space. For example, the attribute is that it can be released in the non-secure operating system stage. At the same time, the software business corresponding to SPL needs to dynamically allocate the security parameter area (dynamic) and the core scenario parameter area (dynamic), which is completed using the application function. Similarly, after being called, the application function allocates a piece of memory space from the available memory and marks it as available, and returns the allocated value to SPL. If the allocation fails, an error is returned and reported to the user by SPL. In the SPL stage, the RAM dump area (dynamic) is not accessed. It is allocated by the software module of the previous non-secure operating system and enters the SPL stage after restart. For cold start, when booting to the U-BOOT stage to query the RAM dump area (dynamic), the RAM dump area (dynamic) does not exist in the memory layout manager, so the business logic of RAM dump will not be executed. For hot start triggered by emergency (panic) and other conditions, the RAM dump area (dynamic) is dynamically allocated by the software module of the non-secure operating system calling the application function of the memory layout manager. In this way, when the system restarts to U-BOOT, the RAM dump area (dynamic) can be queried by name and the address information of the RAM dump area (dynamic) can be obtained, thereby further completing the business logic of RAM dump.
[0053] Step 3: SPL completes the necessary logic, ends its life cycle, and hands over the processor control to the SLOADER software logic. After the SLOADER software logic enters, it still first calls the control function of the memory layout manager to notify it that it is currently entering the SLOADER stage. Then SLOADER calls the query function of the memory layout manager to obtain the specific location of the memory address of the security parameter area (dynamic) allocated by SPL, and then reads the parameter information filled in by SPL from it to complete the transfer of software information across software modules and across life cycles. If the query fails, an error is reported. At the same time, the SLOADER software logic calls the application function to allocate the memory space of the trusted firmware area (dynamic) to complete its own business logic. During this allocation process, the attribute marking the trusted firmware area (dynamic) is released in the secure operating system stage. After completing its business logic, SLOADER can choose to actively release the memory space of the trusted firmware area (dynamic), or when it enters the software module that executes the secure operating system later, the memory layout manager determines that the current use stage matches the release stage of the memory space of the trusted firmware area (dynamic), thereby executing the release of the memory space of the trusted firmware area (dynamic).
[0054] Step 4: After the software module of the secure operating system enters, it first calls the control function of the memory layout manager to notify it that it has entered the secure operating system stage. If the memory space of the trusted firmware area (dynamic) is not actively released in SLOADER, then when the control function of the memory layout manager is called, because it detects that it is currently in the secure operating system stage, it matches the release stage of the memory space of the trusted firmware area (dynamic), and the memory space of the trusted firmware area (dynamic) will be released. The secure operating system calls the query function of the memory layout manager to obtain the specific location of the memory address of the secure parameter area (dynamic) allocated by SPL, and then reads the parameter information filled in by SPL from it to complete the transfer of software information across software modules and across life cycles. After the software module of the secure operating system completes its own software logic, it jumps to the U-BOOT software module.
[0055] Step 5: After the U-BOOT software module notifies the memory layout manager to enter the U-BOOT stage through the control function, the memory space of the security parameter area (dynamic) is released. Then, the U-BOOT software module allocates the kernel code area (static) through the memory layout manager for loading the kernel code of the non-secure operating system. It can be seen that because the memory space of the trusted firmware area (dynamic) and the memory space of the security parameter area (dynamic) have been released, the memory layout manager can reuse their space to allocate the kernel code area (static), thereby efficiently using the memory space. In the U-BOOT stage, the query function will be called to obtain the memory address of the core scenario parameter area (dynamic) and the RAM dump area (dynamic), so as to complete the parsing of the core scenario parameter (coresight parameter) and the processing of the data of the RAM dump area (dynamic). After completing the processing of the data of these two memory spaces, the memory space of the core scenario parameter area (dynamic) is actively released. From the last hot restart of the non-secure operating system to the completion of the memory dump by the U-boot software module this time, a business has been completed. In order to still use the memory dump service in this non-secure operating system, it is necessary to reallocate the RAM dump area (dynamic) for the next memory dump in the U-boot stage. In actual operation, since the services of the non-secure operating system remain basically unchanged during multiple restarts, there is no need to adjust the position of the RAM dump area (dynamic) in the memory, that is, it will not be released first and then allocated, but the RAM dump area (dynamic) allocated for the first time will be used.
[0056] The memory management of the reserved shared memory pool is different from that of other memory spaces. The address space of the reserved shared memory pool needs to be reserved before the non-secure operating system is started, so that it can take effect as soon as the non-secure operating system is entered, but the content of the reserved shared memory pool will not be accessed before the non-secure operating system is entered. In other words, the memory space of the reserved shared memory pool needs to be allocated before the non-secure operating system is loaded, but the actual content will not be used before the non-secure operating system is loaded. Therefore, this memory space can still be used by the U-BOOT software module before the non-secure operating system is loaded, and there will be no data overwriting and conflict. In response to this requirement, the memory layout manager considers the specific information of the "release phase" attribute when allocating memory space during the allocation process, and can complete the mechanism that even if the current memory space is still occupied and used by other software logic or software modules, it can still be allocated and there will be no conflict. The specific operation is that when considering the allocable memory space, refer to the use phase information specified in the memory space allocation request and compare it with the release phase information in the allocated memory space. When the use phase of the allocated memory space is later than the release phase in the allocated memory space, the allocated memory space is regarded as free. Specifically, if the current use phase is equal to the release phase recorded by a certain allocated memory space, then the corresponding allocated memory space has been released at this time and marked as free. When the system is started to a release phase later than the one recorded by the allocated memory space, if new memory space needs to be allocated, if the size is appropriate, it will be allocated from the free area of the memory, so that the reuse of the memory space is naturally realized. Therefore, when the reserved shared memory pool 1 (dynamic) is allocated in the U-BOOT phase, the use phase provided is a non-safe operating system. At this time, the release phase marked by the allocated memory space U-BOOT area (static) in the memory layout manager is a non-safe operating system, so for the allocation of the reserved shared memory pool 1 (dynamic), the memory space of the U-BOOT area (static) is regarded as free memory and participates in the allocation. Therefore, it can be seen that in the allocation of the reserved shared memory pool 1 (dynamic), the returned address space reuses the address space of the U-BOOT area (static), although the memory space of the U-BOOT area (static) is being used when allocating. Reserved shared memory pool 2 (dynamic) is allocated from normal free memory.
[0057] Step 6: After the software module of the non-secure operating system notifies the memory layout manager through the control function to enter the non-secure operating system stage, the memory space of the U-BOOT area (static) is released. At this time, the reserved shared memory pool 1 (dynamic) can be used normally by the software module of the non-secure operating system. When the non-secure operating system encounters an emergency (panic) situation, the memory space of the RAM transfer area (dynamic) is applied for through the memory management module, and a name is specified. In this way, after the system is hot-started, U-BOOT can find the space of the dynamically allocated RAM transfer area (dynamic) through the agreed name and complete the relevant logic of RAM transfer. It is also possible to allocate space for RAM transfer immediately after calling the control function during the initialization of the non-secure operating system. It is also possible to complete the allocation of the memory space of the RAM transfer area (dynamic) in U-BOOT, and use it for the next U-BOOT software module after startup.
[0058] Please also see Figure 2 and Figure 3 , when the memory size used by each software logic or software module changes due to business needs, for example, after the trusted firmware area (dynamic), core scenario parameter area (dynamic) and RAM dump area (dynamic) are expanded, since the memory layout manager dynamically plans the memory, there is no need to modify the specific locations of the trusted firmware area (dynamic), core scenario parameter area (dynamic) and RAM dump area (dynamic) in each software logic or software module. For example, when the size of the memory space of the core scenario parameter area (dynamic) is expanded, the address offset of the RAM dump area (dynamic) following it also changes. In the prior art, although the original intention is to modify the core scenario (coresight) software logic, the address offset defined in the RAM dump (ramdump) software logic must be modified at the same time to prevent software errors caused by memory address overlap. After applying the memory layout manager proposed in the present application, it is only necessary to modify the memory size used by the core scenario parameters in the software logic of the core scenario, and it does not involve modification of the software logic of the RAM dump. Because in the software logic of RAM transfer, the allocator (non-secure operating system) dynamically allocates the address through the memory layout manager, and specifies the name of the memory space of the RAM transfer area (dynamic) when allocating. The user (U-BOOT) obtains the dynamically allocated address offset through the memory layout manager according to the agreed name of the memory space, and does not rely on the information of the core scenario parameter area (dynamic). In this embodiment, only examples of the use of parallel memory layout by the core scenario and RAM transfer software logic are given. In actual products, there will be as many as a dozen different software logics using parallel memory spaces. In such a situation, the software logic that needs to be modified will use or occupy as many as a dozen memory spaces, which is more likely to cause errors in the modification.
[0059] Preferably, the present application statically divides 128K of memory space in the memory for placing the memory layout manager. After the embedded system is powered on, the memory layout manager module is loaded into the memory by the BOOTROM code solidified in the processor, or the BOOTROM code first loads the SPL to complete the memory initialization, and then the memory layout manager module is loaded into the memory by the SPL.
[0060] Preferably, in the memory layout manager, a piece of memory layout information includes: the starting address, size and name of a certain memory space, the use phase (optional), and the release phase (optional). Each software logic or software module at different phases can query a memory layout information through the name of the memory space, and understand the specific purpose of this layout according to the name of the memory space, and also use the name of the memory space to manage the memory layout information. Taking the U-BOOT area (static) as an example, it is allocated in the SPL phase and released in the non-secure operating system phase. Then, SPL will first apply to the memory layout manager for a piece of memory space with the name of "U-BOOT area", and specify the use phase as U-BOOT and the release phase as non-secure operating system. After receiving the allocation request, the memory layout manager finds a suitable space according to the application and records a new piece of memory layout information (starting address, size, "U-BOOT area", U-BOOT, non-secure operating system). Among them, the starting address is planned by the memory layout manager itself and may be different each time. The size and name are determined by the caller U-BOOT. After establishing this layout, SPL will use the memory space corresponding to this layout to load the U-BOOT code. This memory space is released when the system enters the non-secure operating system stage.
[0061] See also Figure 4 The device for dynamically planning memory layout when the embedded system starts up proposed in the present application includes a management unit 11, a static allocation unit 12, a dynamic allocation unit 13, a query unit 14, and a release unit 15.
[0062] The management unit 10 is used to set a memory layout manager for software modules across different exception levels in the memory. The memory layout manager includes an application function, a registration function, a query function, a control function, a release function and a data structure for storing memory layout information. The application function is used to allocate memory for the dynamic planning module. The registration function is used to allocate memory for the static planning module. The query function is used to query whether there is a memory space with the same name in the allocated memory space according to a given memory space name. The control function is used to notify the memory layout manager which stage is currently entered. The release function is used to actively release the allocated memory space.
[0063] The static allocation unit 12 is used to call the registration function of the memory layout manager to allocate memory space for the static planning module, and the allocated memory space has a unique name.
[0064] The dynamic allocation unit 13 is used to call the application function of the memory layout manager to allocate memory space for the dynamic programming module, and the allocated memory space has a unique name.
[0065] The query unit 14 is used to search for the allocated memory space according to the name.
[0066] The release unit 15 is used to release the allocated memory space when the control function of the memory layout manager notifies the corresponding stage of the embedded system according to the release stage information specified when the memory space is allocated. Alternatively, the release unit 15 releases the allocated memory space by calling the release function of the memory layout manager.
[0067] This application introduces a memory layout manager to establish a way to share information between different software logics or software modules in an embedded system (even between software logics or software modules that are independently compiled by different compilers). According to the needs of different software logics or software modules, the two methods of registering and applying for memory space allocation are combined to meet the needs of software modules that need static allocation and the needs of software modules that can be dynamically allocated. For static planning modules, when static allocation conflicts occur, error prompts can be given directly to quickly locate the problem points. For dynamic planning modules, the dynamic memory spaces of different software logics or software modules can be adaptively sorted, and the most optimized memory layout planning scheme is given to avoid the formation of a large number of memory gaps and improve the efficiency of memory use. At the same time, after using the memory layout manager, users can easily adjust the memory layout quickly and transparently by providing the required memory size, avoiding a large number of problems caused by users' unfamiliarity with the memory layout and making modifications, reducing the difficulty of customer support and saving customer support resources.
[0068] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.
Claims
1. A method for dynamic programming of memory layout when an embedded system is started, characterized in that: The method comprises the following steps: Step S11: setting a memory layout manager across software modules of different exception levels in the memory, wherein the memory layout manager includes an application function, a registration function, a query function, a control function, a release function and a data structure for storing memory layout information; The application function is used to allocate memory for a dynamic programming module; the dynamic programming module refers to a software module or software logic that uses a memory area with an unfixed length and a variable position; The registration function is used to allocate memory for a static planning module; the static planning module refers to a software module or software logic that uses a memory area of fixed length and fixed position; The query function is used to query the allocated memory space according to the name; The control function is used to notify the memory layout manager which stage is currently entered; The release function is used to actively release the allocated memory space; Step S12: When the static planning module needs to use memory, the registration function is called to provide a memory base address, a memory space size, and a memory space name; The memory layout manager detects whether the memory base address, memory space size and existing memory allocation state conflict; if there is a conflict, returns failure; otherwise, registers the memory base address, memory space size and memory space name into the existing memory allocation state and returns success; the allocated memory space has a unique name; Step S13: When the dynamic programming module needs to use memory, the application function is called to provide the required memory space size and memory space name; If suitable memory space cannot be found, an error is returned; Otherwise, the memory dynamic allocator allocates a memory space of corresponding size in the free memory, registers the physical address, size and name of the memory space into the existing memory allocation state, marks the memory space as occupied, and returns the physical address to the dynamic programming module; the allocated memory space has a unique name; The order of step S12 and step S13 may be interchanged or performed simultaneously; Step S14: the software module or software logic queries the allocated memory space according to the name of the memory space by calling the query function; Step S15: the software module or software logic releases the allocated memory space by calling the release function.
2. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: In the step S11, the memory layout manager is loaded into the memory when the memory of the embedded system is just initialized; after the memory layout manager is loaded, the software modules of each exception level or the software logic therein call the function of the memory layout manager by initiating a function call.
3. The method for dynamic programming of memory layout when an embedded system is started according to claim 2, characterized in that: After the embedded system is powered on, the memory layout manager module is loaded into the memory by the boot read-only memory BOOTROM code solidified in the processor, or the BOOTROM code first loads the second stage program loader SPL to complete the memory initialization, and then the memory layout manager module is loaded into the memory by SPL.
4. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: In step S12 and step S13, when the size of any memory space is adjusted, the memory layout manager always searches for non-conflicting available memory areas to allocate other memory spaces during the restart of the embedded system, that is, to achieve automatic adjustment of the memory layout.
5. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: In the step S12 and step S13, the memory space name is provided when a new memory space is registered or a new memory space is applied for; The memory layout manager compares the received memory space name with the name of the allocated memory space. If there is an allocated memory space with the same name, it will not allocate a new memory space, but directly return the existing memory space information with the same name.
6. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: The data structure storing memory layout information is used to store memory space information, each piece of memory space information includes the starting address, size, name and attributes of the memory space; the attributes include one or more of the following information: whether the memory space is statically registered or dynamically applied for, usage phase information, and release phase information.
7. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: In the steps S12 and S13, when a memory space is newly registered or newly applied for, use phase and release phase information are provided, where the use phase refers to the phase or phases in which a certain memory space needs to be used, and the release phase refers to the phase in which a certain memory space is no longer used and can be released; The step S15 also includes: alternatively, the software module or software logic releases the allocated memory space when the control function of the memory layout manager notifies the entry into the corresponding phase of the embedded system through the release phase information specified when a certain memory space is allocated.
8. The method for dynamic programming of memory layout when an embedded system is started according to claim 7, characterized in that: In step S12 and step S13, when the use phase of a certain memory space to be allocated is later than the release phase of a certain allocated memory space, when allocating memory space for the memory space to be allocated, the allocated memory space is regarded as free and allowed to be allocated to the memory space to be allocated.
9. The method for dynamic programming of memory layout when an embedded system is started according to claim 1, characterized in that: In step S14, software modules of different exception levels or software logic therein implement information transmission across different exception levels by writing and reading memory spaces with the same name.
10. A device for dynamic memory layout planning when an embedded system is started, characterized in that: It includes a management unit, a static allocation unit, a dynamic allocation unit, a query unit and a release unit; The management unit is used to set a memory layout manager across software modules of different exception levels in the memory; the memory layout manager includes an application function, a registration function, a query function, a control function, a release function and a data structure for storing memory layout information; The application function is used to allocate memory for a dynamic programming module; the dynamic programming module refers to a software module or software logic that uses a memory area with an unfixed length and a variable position; The registration function is used to allocate memory for a static planning module; the static planning module refers to a software module or software logic that uses a memory area of fixed length and fixed position; The query function is used to query the allocated memory space according to the name; The control function is used to notify the memory layout manager which stage is currently entered; The release function is used to actively release the allocated memory space; The static allocation unit is used to call the registration function and provide the memory base address, memory space size, and memory space name when the static planning module needs to use the memory; The memory layout manager detects whether the memory base address, memory space size and existing memory allocation state conflict; if there is a conflict, returns failure; otherwise, registers the memory base address, memory space size and memory space name into the existing memory allocation state and returns success; the allocated memory space has a unique name; The dynamic allocation unit is used to call the application function and provide the required memory space size and memory space name when the dynamic programming module needs to use memory; If suitable memory space cannot be found, an error is returned; Otherwise, the memory dynamic allocator allocates a memory space of corresponding size in the free memory, registers the physical address, size and name of the memory space into the existing memory allocation state, marks the memory space as occupied, and returns the physical address to the dynamic programming module; the allocated memory space has a unique name; The query unit is used to query the allocated memory space according to the name of the memory space by calling the query function; The release unit is used to release the allocated memory space by calling the release function.
