Method and device for self-moving and decompressing link script of swan gap system
By specifying efficient memory space and self-moving and self-decompression programs in the link script of the Hongmeng system, the problem of inefficient application operation is solved, and more efficient memory utilization and operation performance is achieved.
Patent Information
- Application Number
- CN202411605109.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-11-12
AI Technical Summary
The operation efficiency of applications in Hongmeng system is limited by the choice of memory space, especially when the application code is large, it runs in a memory space with large capacity but low efficiency, resulting in inefficient code running.
By specifying the loading memory address for the application block that needs to improve operational efficiency in the link script as the memory space with sufficient capacity and the highest operating efficiency in the memory, and implementing self-moving and self-decompression programs in the Hongmeng system, dynamically adjusting the loading address and data status of the application block in memory.
It realizes flexible allocation of memory space in different segments of the application, improves the operation efficiency of the application, and self-decompression processing improves the efficiency of self-moving and saving storage space.
Smart Images

Figure CN119536843A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to an embedded system, and more particularly to a method for self-moving and decompressing via a link script in a Hongmeng system. Background Art
[0002] When developing an embedded system, the bootloader, kernel, file system, and application are usually developed independently, and the first three are all operating systems. After development, the above parts are integrated together to make a system image file, which is burned into the non-volatile memory of the embedded device, such as flash. After the embedded device is powered on, the operating system code will be loaded from the non-volatile memory into the memory to run during the startup phase. When an application needs to be run, the embedded system loads the application from the non-volatile memory into the memory to run, or executes it in the non-volatile memory in XIP (execute in place) mode.
[0003] Typically, embedded devices have multiple memory spaces to run application code, such as ITCM (instruction tightly-coupled memory), SRAM (static random-access memory), PSRAM (pseudo static random access memory), etc. The code running efficiency is ITCM>SRAM>PSRAM, while the memory space capacity is PSRAM>SRAM>ITCM. In particular, the space of ITCM is very small and can only accommodate a small amount of code.
[0004] The development and design of embedded systems use compilers, linkers, and debuggers. A linker is a program that links one or more object files generated by a compiler or assembler plus libraries into an executable file. A linker can be simply understood as merging one or more input files (object files) into an output file (executable file). A linker usually uses a linker script. The linker script describes how to put each section in the input file into the output file and controls the layout of each section in the output file in memory. Sometimes the segments of the input file are called input segments, and the segments of the output file are called output segments.
[0005] A section can be marked as loadable, which means that the contents of the section need to be loaded into memory before the output file is run. A section with no contents is allocatable, which means that an area should be reserved in memory, but nothing needs to be loaded there (in some cases, that memory must be zeroed). Sections that are neither loadable nor allocatable usually contain some kind of debugging information.
[0006] Each loadable or allocatable output segment has two addresses. The first is VMA (Virtual Memory Area), and the second is LMA (Load Memory Address). The virtual memory address is the link address. When compiling a program, each target file is compiled from the source code, and multiple target files are linked to generate an executable file. The link address indicates the location of each target file in the executable program. For example, an executable program (output file) a.out consists of three target files (input files) a1.0, a2.o, and a3.o. The order of the input files in the output file is determined by the link address. The load address indicates the address where each segment of the executable file (application) is loaded into the memory for execution. In most cases, the link address and load address of each segment are the same, but they may also be different.
[0007] The normal process of starting an application in the Hongmeng system is to load the application through the boot program, read the application from the non-volatile memory into the memory for execution, or run it in the non-volatile memory in XIP mode. The first instruction executed in the application is called the entry point. After the Hongmeng system loads the application, it enters the entry point of the application. This mode of operation stipulates that an application must all run in the same memory space. When the amount of code of an application is relatively large, it usually runs in a memory space with large capacity but relatively low operating efficiency-such as PSRAM, which will cause the code of the application to run inefficiently, especially for some modules that need to be called frequently or some modules that need to improve operating efficiency. It will have a great negative impact. Summary of the invention
[0008] The technical problem to be solved by this application is how to make the link script of the Hongmeng system support self-moving and decompression, so as to improve the operating efficiency of the application in the Hongmeng system.
[0009] To solve the above technical problems, the present application proposes a method for self-moving and decompressing the link script of the Hongmeng system, comprising the following steps. Step S1: When generating the system image file of the embedded device, compress the data of at least some segments of the application program to reduce the volume. Step S2: The "segment of the application program that needs to improve the operating efficiency" is called the segment that needs to be moved, and the loading memory address is specified in the link script file for the segment that needs to be moved as a memory space with sufficient capacity and the highest operating efficiency; a global list is created according to the rules for memory layout of each segment of each application program in the link script; the global list saves the source address, destination address, source data size, and destination data size of the segment that needs to be moved recorded in the link script, and also saves the segment that needs to be cleared recorded in the link script; the destination data size of the segment that needs to be cleared is 0. Step S3: Implement a self-moving and self-decompression program in the Hongmeng system. Step S4: When the Hongmeng system loads each segment of each application program into the memory space of the embedded device, it first queries the segment in the global list pre-loaded into the memory. If the destination data size of the segment recorded in the global list is 0, clear the segment data. If the source data size of the segment recorded in the global list is the same as the destination data size, copy the segment from the source address of the segment recorded in the global list to the destination address of the segment. If the source data size of the segment recorded in the global list is different from the destination data size, first read the segment data from the source address of the segment recorded in the global list, then call the self-moving and self-decompression program to decompress the read segment data, and then write the decompressed segment data to the destination address of the segment recorded in the global list.
[0010] Furthermore, in step S1, the segment includes any one or more of a code segment, a data segment, a BSS segment, and a read-only data segment.
[0011] Furthermore, in step S2, the embedded device has multiple memory spaces for running applications, and the order from high to low according to the code running efficiency is instruction tightly coupled memory ITCM>static random access memory SRAM>pseudo-static random access memory PSRAM; and the order from large to small according to the capacity of the memory space is PSRAM>SRAM>ITCM.
[0012] Furthermore, in step S2, a virtual memory address VMA is specified for each segment in the link script, and a load memory address LMA is specified for a segment through the AT keyword; if the link script does not specify LMA for a segment through the AT keyword, the linker assumes that the LMA of the segment is equivalent to the VMA.
[0013] Furthermore, in step S2, the segment to be moved refers to a segment in the link script whose LMA and VMA are inconsistent as specified by the AT keyword.
[0014] Furthermore, in step S2, the segment that needs to be cleared refers to a segment that will be cleared when loaded into the memory or a segment that is not loaded into the memory.
[0015] Furthermore, in the step S3, the self-migrating and self-decompressing program is placed at the very beginning of the startup position of the Hongmeng system and cannot be moved or decompressed. It is used to perform self-migrating and self-decompressing processing on the segments that need to be moved.
[0016] Furthermore, in step S4, if the destination data size of the segment recorded in the global list is 0, it indicates that the segment is a segment that needs to be cleared. If the source data size of the segment recorded in the global list is the same as the destination data size, it indicates that the segment is a segment that needs to be moved and the data of the segment is not compressed. If the source data size of the segment recorded in the global list is different from the destination data size, it indicates that the segment is a segment that needs to be moved and the data of the segment is compressed.
[0017] The present application also proposes a device for self-moving and decompressing link scripts of the Hongmeng system, including a compression unit, a setting and creation unit, an implementation unit, and a query and processing unit. The compression unit is used to compress data of at least some segments of some applications when generating a system image file for an embedded device. The setting and creation unit is used to refer to "segments of applications that need to improve operating efficiency" as segments that need to be moved, and to specify the loading memory address of the segments that need to be moved in the link script file as a memory space with sufficient capacity and the highest operating efficiency; a global list is created according to the rules for memory layout of each segment of each application in the link script; the global list saves the source address, destination address, source data size, and destination data size of the segments that need to be moved recorded in the link script, and also saves the segments that need to be cleared recorded in the link script; the destination data size of the segments that need to be cleared is 0. The implementation unit is used to implement a self-moving and self-decompression program in the Hongmeng system. The query and processing unit is used to query each segment of each application program in the global list pre-loaded into the memory when loading each segment into the memory of the embedded device; if the destination data size of the segment recorded in the global list is 0, clear the segment data to zero; if the source data size of the segment recorded in the global list is the same as the destination data size, copy the segment from the source address of the segment recorded in the global list to the destination address of the segment; if the source data size of the segment recorded in the global list is different from the destination data size, first read the segment data from the source address of the segment recorded in the global list, then call the self-moving and self-decompression program to decompress the read segment data, and then write the decompressed segment data to the destination address of the segment recorded in the global list.
[0018] The technical effect achieved by this application is: self-migration and self-decompression of certain segments are realized in the Hongmeng system, which can more flexibly and reasonably allocate the memory space loaded by different segments of the application, which is conducive to improving the operating efficiency of the application. The self-decompression process improves the efficiency of self-migration and saves storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a flowchart of the method for self-moving and decompressing link scripts of the Hongmeng system proposed in this application.
[0020] Figure 2 This is a structural diagram of the device for self-moving and decompressing the link script of the Hongmeng system proposed in this application.
[0021] Explanation of the reference numerals in the figure: compression unit 1, setting and creation unit 2, implementation unit 3, query and processing unit 4. DETAILED DESCRIPTION
[0022] See also Figure 1 The method for self-moving and decompressing the link script of the Hongmeng system proposed in this application includes the following steps.
[0023] Step S1: When generating a system image file of an embedded device, data compression is performed on at least some segments of the application program to reduce the size. The types of the segments include, for example, code segments (text), data segments (data), BSS (block started by symbol) segments, read-only data segments (rodata), etc., wherein the code segments and data segments are preferably compressed. If data compression is performed on some segments, the amount of data read and written to the segment is reduced, and the space occupied by storing the segment in the non-volatile memory of the embedded device is saved.
[0024] Step S2: The "segments of the application program that need to improve operating efficiency" are called segments that need to be moved, and the loading memory address is specified as a memory space with higher operating efficiency for the segments that need to be moved in the link script file. A global list is created according to the rules for memory layout of each segment of each application program in the link script. The global list saves the source address, destination address, source data (original data before moving) size, and destination data (data after moving) size of the "segments that need to be moved" recorded in the link script, and also saves the "segments that need to be cleared" recorded in the link script.
[0025] The link script specifies the virtual memory address (VMA) for each segment, and optionally the load memory address (LMA) through the AT keyword. If the link script does not specify the LMA for a segment through the AT keyword, the linker assumes that the LMA of the segment is equal to the VMA. If the link script specifies the LMA for a segment through the AT keyword, the LMA can be different from the VMA.
[0026] The segment that needs to be moved refers to the segment whose LMA and VMA specified by the AT keyword in the link script are inconsistent. For example, the link script specifies that the VMA of a certain code segment is in PSRAM, and the segment does not use the AT keyword, then the LMA of the segment is equal to the VMA, and there is no need to perform a self-migration operation on the code segment. For another example, the link script specifies that the VMA of a certain code segment is in PSRAM, and in order to improve the operating efficiency of the code segment, it is prepared to be loaded into ITCM for execution, so the segment uses the AT keyword to specify that the LMA is in ITCM. At this time, it is necessary to perform a self-migration operation on the code segment, and the self-migration and self-decompression program will copy the code segment from FLASH or PSRAM to ITCM.
[0027] The segments that need to be cleared are segments that will be cleared when loaded into the memory or segments that are not loaded into the memory. For example, the BSS segment stores global variables or static variables that are not initialized or initialized to 0, and the BSS segment data will be cleared when loaded. For another example, the type (type) of a segment recorded in the link script is NOLOAD (not loaded), and the segment is not loaded into the memory when the application is running. Therefore, the BSS segment and the NOLOAD type segment are the segments that need to be cleared. The destination data size of the "segment that needs to be cleared" is 0.
[0028] Step S3: Implement a self-moving and self-decompressing program in the Hongmeng system. The self-moving and self-decompressing program is placed at the very beginning of the Hongmeng system startup position, cannot be moved or decompressed, and is used to perform self-moving and self-decompressing processing on the "segments that need to be moved".
[0029] Step S4: When the Hongmeng system loads each segment of each application into the memory space of the embedded device, it first queries the segment in the global list pre-loaded into the memory.
[0030] If the destination data size of the segment recorded in the global list is 0, it indicates that the segment is a segment that needs to be cleared, and the data of the segment is cleared.
[0031] If the source data size of the segment recorded in the global list is the same as the destination data size, it indicates that the segment is the segment that needs to be moved and the data of the segment is not compressed. The segment is copied from the source address of the segment recorded in the global list to the destination address of the segment.
[0032] If the source data size of the segment recorded in the global list is different from the destination data size, indicating that the segment is a segment that needs to be moved and the segment data is compressed, the segment data is first read from the source address of the segment recorded in the global list, and then the self-moving and self-decompressing program is called to decompress the read segment data, and then the decompressed segment data is written to the destination address of the segment recorded in the global list. This process is the self-moving and self-decompressing described in this application.
[0033] The native link script of Hongmeng system does not support self-relocation and self-decompression. This application is to implement a self-relocation and self-decompression program in Hongmeng system, which can flexibly run different segments of the application in different memory spaces. Assuming that an application was originally running on PSRAM, some codes of the application (such as system scheduling, algorithms, some processing of UI, etc.) need to be processed quickly and frequently called. If the running speed of these codes is too slow, it will affect the efficiency of the system, so it is hoped that this part of the code can run at high speed. Since the space occupied by these codes is relatively small, one or more code segments or data segments can be run in the ITCM space with high running efficiency. On the one hand, this application sets the LMA of the "segment that needs to improve running efficiency" of the application to the ITCM space through the AT keyword in the link script, so that it can be loaded and run from ITCM. On the other hand, this application uses the self-relocation and self-decompression program implemented by Hongmeng system to self-move and self-decompress the "segment that needs to improve running efficiency" of the application, and then runs the application after completion. There are two forms of self-migration: one is to run in XIP mode, which is to move from non-volatile memory (such as FALSH) to ITCM; the other is to run by loading into PSRAM memory space, then the Hongmeng system first copies the code from FLASH to PSRAM, and then moves it from PSRAM to ITCM through the self-migration and self-decompression program.
[0034] Compared with the native Hongmeng system, the native Hongmeng system limits an application to running in the same memory space or non-volatile memory. When some code modules need to be processed quickly and are frequently called, such as an algorithm, if the original code design cannot meet the efficiency requirements, it may take manpower to optimize the algorithm or replace it with other solutions. The amount of code may become larger and may not meet the requirements. However, this application does not require in-depth optimization of the original code or change the original framework design. By using the AT keyword in the link script and the new self-moving and self-decompression program in the Hongmeng system, the code modules that need to be executed quickly can be moved to an address space with higher operating efficiency (such as ITCM) before the application runs. This can greatly improve the operating efficiency of the code and meet actual requirements. It will not change the original code solution or increase the amount of code, nor will it cost extra manpower to make optimization solutions. It is simple and convenient.
[0035] See also Figure 2 The device for self-moving and decompressing the link script of the Hongmeng system proposed in this application includes a compression unit 1, a setting and creation unit 2, an implementation unit 3, and a query and processing unit 4. Figure 2 The device shown corresponds to Figure 1 The method shown.
[0036] The compression unit 1 is used to compress data of at least part of the application program segments when generating a system image file of an embedded device.
[0037] The setting and creating unit 2 is used to refer to the "segments of the application program that need to improve the running efficiency" as the segments that need to be moved, and in the link script file, the loading memory address is specified as the memory space with higher running efficiency for the segments that need to be moved. A global list is created according to the rules for memory layout of each segment of each application program in the link script. The global list saves the source address, destination address, source data size, and destination data size of the "segments that need to be moved" recorded in the link script, and also saves the "segments that need to be cleared" recorded in the link script.
[0038] The implementation unit 3 is used to implement a self-migrating and self-decompression program in the Hongmeng system.
[0039] The query and processing unit 4 is used to query the segment in the global list pre-loaded into the memory when loading each segment of each application into the memory of the embedded device. If the destination data size of the segment recorded in the global list is 0, the segment data is cleared. If the source data size of the segment recorded in the global list is the same as the destination data size, the segment is copied from the source address of the segment recorded in the global list to the destination address of the segment. If the source data size of the segment recorded in the global list is different from the destination data size, the segment data is first read from the source address of the segment recorded in the global list, and then the self-migration and self-decompression program is called to decompress the read segment data, and then the decompressed segment data is written to the destination address of the segment recorded in the global list. This process is the self-migration and self-decompression described in the present application.
[0040] In summary, the present application can complete the movement of code segments or data segments in different spaces according to actual needs. For example, if the code volume of some segments of the application is small and needs to be executed repeatedly, the code can be moved from FLASH or PSRAM to ITCM before the code is started through the self-migration operation, which will greatly improve the running efficiency of the code. At the same time, the original code segment may be compressed, and the self-decompression process is completed during the self-migration process, which reduces the amount of self-migration data and improves the efficiency of self-migration.
[0041] 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 self-moving and decompressing link scripts of Hongmeng system, characterized in that: The method comprises the following steps: Step S1: when generating a system image file of an embedded device, compressing data of at least some segments of the application program to reduce the size; Step S2: "the segment of the application program that needs to improve the running efficiency" is called the segment that needs to be moved, and the loading memory address is specified as a memory space with sufficient capacity and the highest running efficiency for the segment that needs to be moved in the link script file; a global list is created according to the memory layout rules for each segment of each application program in the link script; the global list stores the source address, destination address, source data size, and destination data size of the segment that needs to be moved recorded in the link script, and also stores the segment that needs to be cleared recorded in the link script; the destination data size of the segment that needs to be cleared is 0; Step S3: Implement a self-migration and self-decompression program in the Hongmeng system; Step S4: when the Hongmeng system loads each segment of each application into the memory space of the embedded device, it first searches for the segment in the global list pre-loaded into the memory; If the destination data size of the segment recorded in the global list is 0, clear the segment data; If the source data size of the segment recorded in the global list is the same as the destination data size, copying the segment from the source address of the segment recorded in the global list to the destination address of the segment; If the source data size of the segment recorded in the global list is different from the destination data size, the segment data is first read from the source address of the segment recorded in the global list, and then the self-migration and self-decompression program is called to decompress the read segment data, and then the decompressed segment data is written to the destination address of the segment recorded in the global list.
2. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In the step S1, the segment includes any one or more of a code segment, a data segment, a BSS segment, and a read-only data segment.
3. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In step S2, the embedded device has multiple memory spaces for running application programs, which are arranged from high to low in terms of code running efficiency: instruction tightly coupled memory ITCM>static random access memory SRAM>pseudo-static random access memory PSRAM; and arranged from large to small in terms of memory space capacity: PSRAM>SRAM>ITCM.
4. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In step S2, a virtual memory address VMA is specified for each segment in the link script, and a load memory address LMA is specified for a segment through the AT keyword; if the link script does not specify LMA for a segment through the AT keyword, the linker assumes that the LMA of the segment is equivalent to the VMA.
5. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 4 is characterized in that: In step S2, the segment to be moved refers to the segment in the link script whose LMA and VMA are inconsistent as specified by the AT keyword.
6. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In step S2, the segment that needs to be cleared refers to a segment that will be cleared when loaded into the memory or a segment that is not loaded into the memory.
7. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In step S3, the self-migrating and self-decompressing program is placed at the very beginning of the startup position of the Hongmeng system and cannot be moved or decompressed. It is used to perform self-migrating and self-decompressing processing on the segments that need to be moved.
8. The method for self-moving and decompressing link scripts of the Hongmeng system according to claim 1 is characterized in that: In the step S4, if the destination data size of the segment recorded in the global list is 0, it indicates that the segment is a segment that needs to be cleared; If the source data size of the segment recorded in the global list is the same as the destination data size, it indicates that the segment is a segment that needs to be moved and the data of the segment is not compressed; If the source data size of the segment recorded in the global list is different from the destination data size, it indicates that the segment is a segment that needs to be moved and the data of the segment is compressed.
9. A device for automatically moving and decompressing link scripts of Hongmeng system, characterized in that: It includes a compression unit, a setting and creation unit, an implementation unit, and a query and processing unit; The compression unit is used to compress data of at least some segments of the application program when generating a system image file of the embedded device; The setting and creating unit is used to refer to "segments of applications that need to improve operating efficiency" as segments that need to be moved, and to specify in the link script file a memory space with sufficient capacity and the highest operating efficiency as the loading memory address for the segments that need to be moved; a global list is created according to the rules for memory layout of each segment of each application in the link script; the global list stores the source address, destination address, source data size, and destination data size of the segments that need to be moved recorded in the link script, and also stores the segments that need to be cleared recorded in the link script; the destination data size of the segments that need to be cleared is 0; The implementation unit is used to implement a self-migrating and self-decompressing program in the Hongmeng system; The query and processing unit is used to query each segment of each application program into the memory of the embedded device first in the global list pre-loaded into the memory; if the destination data size of the segment recorded in the global list is 0, clear the segment data to zero; if the source data size of the segment recorded in the global list is the same as the destination data size, copy the segment from the source address of the segment recorded in the global list to the destination address of the segment; if the source data size of the segment recorded in the global list is different from the destination data size, first read the segment data from the source address of the segment recorded in the global list, then call the self-moving and self-decompression program to decompress the read segment data, and then write the decompressed segment data to the destination address of the segment recorded in the global list.
Citation Information
Patent Citations
Linux program runtime verification and control method and system based on a Merkle tree
CN109766688A
Link time address allocation method for reuse of on-chip memory
CN112445724A
Program dynamic loading method and device and electronic equipment
CN114721735A
ELF loading method based on microkernel operating system
CN117193882A
Shared library system and method of building the system
US20050010911A1