Dynamic code loading method and system, electronic equipment and upper computer

By splitting the code into the first code segment and the second code segment that is dynamically loaded, and transmitting it from the upper computer to the RAM memory when needed, the cost problem caused by the small FLASH memory capacity is solved, and consumer electronic products are realized low-cost design and dynamic code updates.

CN119065745AInactive Publication Date: 2024-12-03ZHUHAI GUANGXIN INTELLIGENT CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411569968.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-06
Publication Date
2024-12-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Among existing consumer electronic products, the small capacity of FLASH memory leads to a large occupancy of firmware files, increasing costs.

Method used

Using the dynamic loading method, the target code is split into the first code segment to be written and the second code segment that can be loaded dynamically. Through the compilation and linking stage, the dynamic code is configured. The files are stored in the upper computer and transferred from the upper computer to the RAM memory when needed.

Benefits of technology

It reduces the FLASH memory space usage of electronic devices, reduces costs, and supports dynamic code updates and saves FLASH storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065745A_ABST
    Figure CN119065745A_ABST
Patent Text Reader

Abstract

The invention discloses a dynamic code loading method and system, electronic equipment and an upper computer, and the method comprises the steps that a target code is compiled and linked to obtain a first executable file, and the target code comprises a first code segment to be programmed and a second code segment capable of being dynamically loaded; configuring a target running address of the second code segment in the RAM in a compiling stage; separating the second code segment from the first executable file to obtain a dynamic code file and a programming firmware file; storing the dynamic code file to a target upper computer and programming the programming firmware file to a FLASH memory; and under the condition that the target electronic equipment is in communication connection with the target upper computer and the target electronic equipment needs to execute the second code segment, the target electronic equipment receives the dynamic code file transmitted from the target upper computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory. According to the invention, the space occupation of the FLASH memory of the electronic equipment can be reduced, and the cost can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electronic products, and in particular to a method and system for dynamically loading codes, electronic equipment and a host computer. Background Art

[0002] With the continuous development and popularization of contemporary electronic technology, consumer electronic products have occupied an important position in people's lives, such as Bluetooth headsets, IoT devices, children's electronic toys, etc. However, most consumer electronic products have strict requirements on cost, such as the capacity of FLASH memory used to store code and data. The smaller the capacity of FLASH memory, the lower the cost. In general embedded systems, all source codes are compiled, linked, and other steps to generate a firmware file that can be burned to a storage medium (usually FLASH memory). The firmware file contains code instructions, initialized code data, and other contents. All contents are burned into the FLASH memory, which requires a large storage space of the FLASH memory, which is not conducive to reducing costs. Summary of the invention

[0003] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention provides a method, system, electronic device and host computer for dynamically loading code, which can reduce the space occupied by the FLASH memory of the electronic device and help reduce costs.

[0004] An embodiment of the present invention provides a method for dynamically loading code, comprising: Compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device during the compiling stage; Separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records the target running address; The dynamic code file is stored in the target host computer, and the burning firmware file is burned into the FLASH memory of the target electronic device; When the target electronic device and the target host computer are in communication connection and the target electronic device needs to execute the second code segment, the target electronic device sends a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; The target host computer sends the corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

[0005] An embodiment of the present invention provides a method for dynamically loading code, comprising: Compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device during the compiling stage; Separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records the target running address; The dynamic code file is stored in the target host computer, and the burning firmware file is burned into the FLASH memory of the target electronic device; When the target electronic device is in communication connection with the target host computer, the target electronic device sends a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; The target host computer sends the corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

[0006] An embodiment of the present invention provides a method for dynamically loading code, which is applied to an electronic device, wherein a FLASH memory of the electronic device is burned with a first code segment, and the electronic device is communicatively connected to a target host computer, and the method for dynamically loading code includes: Run the first code segment; When it is necessary to execute the dynamic loading code, sending a dynamic loading code request to the target host computer, wherein the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file; In response to the target host computer's response to the dynamic code loading request, receiving a dynamic code file transmitted from the target host computer; According to the target running address recorded in the dynamic code file, the second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory.

[0007] An embodiment of the present invention provides a method for dynamically loading code, which is applied to an electronic device, wherein a FLASH memory of the electronic device is burned with a first code segment, and the method for dynamically loading code includes: Starting and running the first code segment to establish a communication connection with a target host computer; Sending a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of a number, a name or a function code of a dynamic code file; In response to the target host computer's response to the dynamic code loading request, receiving a dynamic code file transmitted from the target host computer; According to the target running address recorded in the dynamic code file, the second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory.

[0008] An embodiment of the present invention provides a method for dynamically loading code, which is applied to a host computer and includes: In response to a dynamic code loading request of a target electronic device, determining a dynamic code file to be sent according to the dynamic code loading request, wherein the dynamic code loading request includes at least one of a number, a name or a function code of the dynamic code file; Sending the dynamic code file to the target electronic device, the dynamic code file comprising a second code segment and a target execution address of the second code segment in a RAM memory of the target electronic device; or, In response to a communication connection request from the target electronic device, establishing a communication connection; In the case of establishing a communication connection, in response to a dynamic code loading request of the target electronic device, the dynamic code loading request including at least one of the number, name or function code of the dynamic code file, determining the dynamic code file to be sent; A dynamic code file is sent to the target electronic device, wherein the dynamic code file includes a second code segment and a target execution address of the second code segment in a RAM memory of the target electronic device.

[0009] An embodiment of the present invention provides a dynamic code loading system, including: An electronic device, comprising a FLASH memory and a RAM memory, wherein a first code segment is stored in the FLASH memory; A host computer is communicatively connected with the electronic device, wherein a dynamic code file is stored in the host computer, wherein the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the electronic device; upon receiving a dynamic code loading request from the electronic device, the host computer transmits the dynamic code file to the electronic device so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

[0010] An embodiment of the present invention provides a dynamic code loading system, including: An electronic device, comprising a FLASH memory and a RAM memory, wherein a first code segment is stored in the FLASH memory; A host computer stores a dynamic code file, wherein the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the electronic device; when the host computer establishes a communication connection with the electronic device, the host computer transmits the dynamic code file to the electronic device so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

[0011] An embodiment of the present invention provides an electronic device, comprising a processor and a communication module, a FLASH memory and a RAM memory connected to the processor, wherein a first code segment is stored in the FLASH memory, and the processor is communicatively connected to a target host computer via the communication module; when the processor runs the first code segment and needs to execute a dynamic loading code, a dynamic loading code request is sent to the target host computer via the communication module, and a dynamic code file is received from the target host computer, and according to a target running address recorded in the dynamic code file, a second code segment that needs to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory, wherein the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

[0012] An embodiment of the present invention provides an electronic device, comprising a processor and a communication module, a FLASH memory and a RAM memory connected to the processor, wherein a first code segment is stored in the FLASH memory, and when the processor establishes a communication connection with a target host computer through the communication module, a dynamic code loading request is sent to the target host computer through the communication module, and a dynamic code file is received from the target host computer, and according to a target running address recorded in the dynamic code file, a second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

[0013] An embodiment of the present invention provides a host computer, wherein a dynamic code file is stored in the host computer, wherein the dynamic code file includes a second code segment and a target running address of the second code segment in a RAM memory of a target electronic device; the host computer is in communication connection with the target electronic device, and upon receiving a dynamic code loading request from the target electronic device, the host computer transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; Alternatively, a dynamic code file is stored in the host computer, and the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the target electronic device; when the host computer establishes a communication connection with the target electronic device, the host computer receives a dynamic loading code request from the target electronic device and transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

[0014] The embodiments of the present invention have at least the following beneficial effects: The complete firmware file is split into a first code segment to be burned and a second code segment that can be dynamically loaded, and a burned firmware file and a dynamic code file are obtained, the dynamic code file is stored in a host computer, and the burned firmware file is burned into a FLASH memory of an electronic device. When the second code segment needs to be executed or a communication connection is established with the host computer, the second code segment is copied from the dynamic code file transmitted by the host computer to a RAM memory, thereby reducing the space occupied by the FLASH memory of the electronic device and helping to reduce costs.

[0015] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which: Figure 1 A schematic diagram of the address space of the FLASH memory and the RAM memory according to an embodiment of the present invention; Figure 2 A schematic diagram of an address space for a storage method of a dynamic code file in the related art; Figure 3 A schematic diagram of an address space for a storage method of a dynamic code file according to an embodiment of the present invention; Figure 4 This is one of the step flow charts of the method for dynamically loading code according to an embodiment of the present invention; Figure 5 This is the second step flow chart of the method for dynamically loading code according to an embodiment of the present invention; Figure 6 This is a flowchart of the steps of the method for dynamically loading code according to an embodiment of the present invention; Figure 7 This is a fourth step flow chart of the method for dynamically loading code according to an embodiment of the present invention; Figure 8 The figure is a functional block diagram of a dynamic code loading system according to an embodiment of the present invention. DETAILED DESCRIPTION

[0017] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.

[0018] In the description of the present invention, "several" means one or more, "multiple" means more than two, greater than, less than, and exceeding are understood as not including the number itself, and "above", "below", and "within" are understood as including the number itself. If there is a description of "first", "second", etc., it is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.

[0019] In the description of the present invention, unless otherwise clearly defined, words such as "connection" and "configuration" should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above words in the present invention in combination with the specific content of the technical solution.

[0020] Suppose there is an embedded electronic device (such as a Bluetooth headset, an IoT device, a children's electronic toy, etc.), which contains a code instruction (hereinafter referred to as CRC code), whose function is to calculate the CRC value of the input data. In order to run efficiently, it needs to be executed in the RAM memory. At the same time, due to the limited space of the FLASH memory of the electronic device, the CRC code cannot be stored. When the electronic device is actually used, it needs to communicate with the PC (personal computer) side (or server side) through a communication module (such as a UART interface module, a Bluetooth interface module, a WIFI interface module, etc.). It should be considered that the PC side is equipped with an executable program developed for the electronic device. The communication module can realize wireless communication or wired communication.

[0021] The address space of the FLASH memory and RAM memory of this electronic device is distributed as follows Figure 1 As shown, the label flash represents the address space distribution of the FLASH memory, and the label ram represents the address space distribution of the RAM memory. The address space of the FLASH memory is: 0~0x7FFFF, a total of 512K bytes; the address space of the RAM memory is: 0x80000~0xBFFFF, a total of 256K bytes.

[0022] 1) Program development is divided into stages such as compilation and linking. After the source code is compiled and linked, it generates a firmware file (also called an executable file) that can be burned into the electronic device. During the compilation stage, the running address of the CRC code is assigned to the area space of the RAM memory. For example, for the GCC compiler, this can be achieved through __attribute__((section(.calc_crc))).

[0023] In the linking stage, the memory layout of the relevant code instructions or data can be controlled by the linker script. For example, the following content can be added to the linker script: .calc_crc ALIGN(32): { * (.calc_crc) = ALIGN(32); } > ram Among them, .calc_crc indicates the function name of the CRC code, and ALIGN(32) indicates that the address must be aligned to 32 bytes, so as to control the memory layout location of the related code instructions or data. The specific linker script syntax is not introduced here.

[0024] 2) After successful compilation and linking, assuming that the executable file generated by the complete code originally downloaded to the electronic device is named burn.elf (the first executable file below), the CRC code can be extracted separately through the following instructions (assuming that the objcopy tool is used): objcopy -O binary -j .calc_crc burn.elf calc_crc.bin The binary file name of the extracted CRC code is: calc_crc.bin (i.e. the dynamic code file below). Assume that the size of the CRC code is 10K bytes and the running address space is: 0x80000~0x827FF.

[0025] 3) In order to save FLASH memory space, the calc_crc.bin file is not burned, and only the executable file without the CRC code (i.e. the burning firmware file below) is burned into the FLASH memory of the electronic device.

[0026] 4) After the electronic device is running and can communicate with the PC normally through the communication module (such as the UART interface module), when the CRC code needs to be executed, the PC first sends the calc_crc.bin file to the electronic device through the communication module. After the electronic device receives the calc_crc.bin file, it copies the file content to the 0x80000~0x827FF address space of the RAM memory.

[0027] 5) Finally, you can execute the CRC code in the calc_crc.bin file to calculate the CRC value of the input data. Using this method, you can save 10K bytes of FLASH memory space (the space saved depends on the size of the dynamic code file). The storage space comparison is as follows: Figure 2 and Figure 3 As shown, the label flash represents the address space distribution of the FLASH memory, and the label ram represents the address space distribution of the RAM memory. Figure 2 and Figure 3 It can be seen from the comparison that the calc_crc.bin file originally stored in the FLASH memory is sent externally instead, which can save the space occupied by the FLASH memory. The method of this embodiment can achieve the following beneficial effects: 1) It can save the storage space of FLASH memory; 2) It can dynamically load the code for execution when it is needed; 3) It can be applied to the dynamic update of third-party code, and there is no need to perform traditional OTA (Over-the-Air Technology) upgrades. It should be known that OTA upgrade is to download and upgrade the entire firmware in the electronic device, rather than dynamically update the local code.

[0028] Based on the inventive concept of the above-mentioned application examples, the technical principle of the present invention is further described from different dimensions below.

[0029] For the development, production and use stages of electronic products, please refer to Figure 4 This embodiment discloses a method for dynamically loading code, including steps S110 to S160. It should be noted that the steps in this embodiment are numbered only for the convenience of review and understanding, and do not limit the execution order of the steps. The contents of each step are described in detail below: S110, compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device during the compiling stage; S120, separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records a target running address; S130, storing the dynamic code file in the target host computer, and burning the firmware file into the FLASH memory of the target electronic device; S140, when the target electronic device and the target host computer are in communication connection and the target electronic device needs to execute the second code segment, the target electronic device sends a dynamic code loading request to the target host computer, where the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; S150, the target host computer sends a corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; S160: The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

[0030] Exemplarily, in programming technology, a complete program includes a main program and a subroutine. The main program usually contains the logic and control flow of the entire program, and the subroutine is a part of the main program, which can be called by the main program or other subroutines, and automatically returns after completing a specific function. Based on the characteristics of the main program and the subroutine, the code of the main program can be used as the first code segment, and the code of the subroutine can be used as the second code segment. After the burning firmware file corresponding to the first code segment is burned into the FLASH memory of the electronic device, the electronic device can independently run the first code segment, such as initialization or communication connection with the target host computer, etc., without being affected by the second code segment. When the second code segment needs to be executed, the dynamic code file is received from the target host computer, and the second code segment is copied from the dynamic code file to the target running address of the RAM memory, without occupying the storage space of the FLASH memory, and efficient operation can be achieved. The second code segment can be divided into one or more dynamic code files, each of which represents a relatively complete subroutine, such as the call function and music playback function of a Bluetooth headset. When the corresponding dynamic code file needs to be called, the electronic device and the host computer communicate through a preset communication protocol, that is, a dynamic code loading request is transmitted through the communication protocol. The dynamic code loading request includes at least one of the number, name or function code of the dynamic code file, such as the number of the dynamic code file corresponding to the call function of the Bluetooth headset is set to 1, and the number of the dynamic code file corresponding to the music playback function is set to 2. The host computer determines the dynamic code file to be sent according to the number of the dynamic code file. Similarly, the name of the dynamic code file can also be attached to the dynamic code loading request. Alternatively, the electronic device and the host computer can determine the dynamic code file to be transmitted by configuring the corresponding function code (such as 0, 1, etc.).

[0031] It is worth noting that the target running addresses of different dynamic code files in the RAM memory can be the same or different. For example, the target addresses of the dynamic code files corresponding to the call function and the music playback function of the Bluetooth headset are the same. During the music playback process, when the Bluetooth headset needs to run the call function, the dynamic code file corresponding to the call function will give priority to the corresponding target running address in the RAM memory, that is, overwriting the dynamic code file corresponding to the music playback function with the same target running address in the RAM memory, so that the address reuse of the RAM memory can be achieved. Of course, for application scenarios with sufficient address space in the RAM memory, different running addresses can be assigned to the dynamic code files corresponding to the call function and the music playback function in the RAM memory, so as to achieve the simultaneous operation of the call function and the music playback function.

[0032] It should be noted that steps S110 and S120 can be executed in the developer of the code, step S130 can be executed in the manufacturer of the target electronic product, and steps S140 to S160 can be executed in the use phase of the target electronic product. Of course, steps S110 to S160 can also be executed in the manufacturer of the target electronic product. Among them, the target host computer can be the user's PC or the server of the operator of the target electronic product.

[0033] By splitting a complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a target host computer, and burning the burned firmware file into a FLASH memory of a target electronic device, when the second code segment needs to be executed, the second code segment is copied from the dynamic code file transmitted by the target host computer to a RAM memory, which can reduce the space occupied by the FLASH memory of the target electronic device, and is conducive to reducing costs. In addition, since the dynamic code file of the second code segment is stored in the host computer, when the second code segment needs to be updated, it will not affect the first code segment of the electronic device, and the dynamic update of the second code segment can be achieved.

[0034] For the development, production and use stages of electronic products, please refer to Figure 5 This embodiment also discloses a method for dynamically loading code, including steps S210 to S260. It should be noted that the steps in this embodiment are numbered only for the convenience of review and understanding, and do not limit the execution order of the steps. The contents of each step are described in detail below: S210, compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device in the compiling stage; S220, separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records a target running address; S230, storing the dynamic code file in the target host computer, and burning the firmware file into the FLASH memory of the target electronic device; S240, when the target electronic device and the target host computer are in communication connection, the target electronic device sends a dynamic code loading request to the target host computer, where the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; S250, the target host computer sends the corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; S260: The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

[0035] Exemplarily, the contents of steps S210~S230 are the same as the above-mentioned steps S110~S130. The contents not involved can be referred to above and will not be repeated here. Steps S140~S160 are to receive the dynamic code file from the target host computer only when the electronic device needs to execute the corresponding second code segment. Although this method can ensure that the operating space of the RAM memory is sufficient to a certain extent, it has certain requirements on the communication rate between the target electronic device and the target host computer. Therefore, in steps S240~S260, when the target electronic device establishes a communication connection with the target host computer, the target electronic device sends a dynamic code loading request to the target host computer, and the target electronic device receives the dynamic code file from the target host computer and preloads it into the RAM memory. When the second code segment needs to be executed, it can be directly called in the RAM memory without waiting for the transmission of the dynamic code file and the copying of the second code segment. This can not only save the storage space of the FLASH memory, but also improve the smoothness of the operation of the target electronic device. Taking a Bluetooth headset as an example of a target electronic device and a computer device as an example of a target host computer, the Bluetooth headset runs the second code segment to send a request to the computer device to establish a communication connection, and the computer device responds to the request for a communication connection. When the Bluetooth headset and the computer device establish a communication connection, the Bluetooth headset sends a dynamic code loading request to the computer device, and the computer device determines the dynamic code file to be sent based on at least one of the number, name or function code of the dynamic code file in the dynamic code loading request. For example, for a Bluetooth headset with a call function and a music playback function, the function codes of the call function and the music playback function can be set to 0 and 1 respectively. By default, the Bluetooth headset loads the dynamic code file corresponding to the music playback function, that is, the corresponding content of the dynamic loading code request can be set to 1.

[0036] It is worth noting that the target running addresses of different dynamic code files in the RAM memory can be the same or different. For example, the target addresses of the dynamic code files corresponding to the call function and the music playback function of the Bluetooth headset are the same. During the music playback process, when the Bluetooth headset needs to run the call function, the dynamic code file corresponding to the call function will give priority to the corresponding target running address in the RAM memory, that is, overwriting the dynamic code file corresponding to the music playback function with the same target running address in the RAM memory, so that the address reuse of the RAM memory can be achieved. Of course, for application scenarios with sufficient address space in the RAM memory, different running addresses can be assigned to the dynamic code files corresponding to the call function and the music playback function in the RAM memory, so as to achieve the simultaneous operation of the call function and the music playback function.

[0037] By splitting a complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a target host computer, and burning the burned firmware file into a FLASH memory of a target electronic device, and only when the target electronic device establishes a communication connection with the target host computer, the second code segment is copied from the dynamic code file transmitted by the target host computer to a RAM memory, thereby reducing the space occupied by the FLASH memory of the target electronic device, and helping to reduce costs.

[0038] It should be noted that the following also provides corresponding dynamic code loading methods for different execution terminals. The inventive concepts of the following embodiments are the same or similar to those of the above. To avoid redundancy, the contents not mentioned below can be referred to above. Figure 6 This embodiment discloses a method for dynamically loading code, which is applied to an electronic device, wherein a first code segment is burned into the FLASH memory of the electronic device, and the electronic device is connected to a target host computer for communication, and the method for dynamically loading code includes steps S310 to S340. It should be noted that the steps in this embodiment are numbered only for the convenience of review and understanding, and do not limit the execution order of the steps. The contents of each step are described in detail below: S310, running the first code segment; S320, when it is necessary to execute the dynamic loading code, sending a dynamic loading code request to the target host computer, the dynamic loading code request including at least one of the number, name or function code of the dynamic code file; S330, in response to the target host computer's response to the dynamic code loading request, receiving the dynamic code file transmitted from the target host computer; S340. According to the target execution address recorded in the dynamic code file, copy the second code segment to be dynamically loaded from the dynamic code file to the target execution address of the RAM memory.

[0039] Exemplarily, as above, the first code end corresponds to the main program, which can be independently run in the electronic device, for example, when the electronic device is started, the electronic device is initialized, wherein the initialization operation includes suggesting a communication connection with the target host computer, or the communication connection function between the electronic device and the target host computer is triggered by the user. After completing the initialization, the electronic device can continue to run the first code segment to wait for user operation or execute the corresponding preset event. When the second code segment needs to be executed, such as calling a subroutine, the electronic device sends a request for dynamically loading the code to the target host computer, and the target host computer responds to the request of the electronic device to transmit a dynamic code file to the electronic device, wherein the dynamic code file contains the second code segment and records the target running address of the second code segment in the RAM memory of the electronic device. After the electronic device receives and parses the dynamic code file, according to the target running address recorded in the dynamic code file, the second code segment that needs to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory, thereby executing the code instruction of the second code segment.

[0040] By splitting the complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, the dynamic code file is stored in a host computer, and the burning firmware file corresponding to the second code segment is burned into the FLASH memory of the electronic device. When the second code segment needs to be executed, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory, which can reduce the space occupied by the FLASH memory of the electronic device and help reduce costs.

[0041] Please refer to Figure 7 This embodiment also discloses a method for dynamically loading code, which is applied to an electronic device, wherein a FLASH memory of the electronic device is burned with a first code segment, and the method for dynamically loading code includes steps S410 to S440. It should be noted that the steps in this embodiment are numbered only for the convenience of review and understanding, and do not limit the execution order of the steps. The contents of each step are described in detail below: S410, starting and running the first code segment to establish a communication connection with a target host computer; S420, sending a dynamic code loading request to the target host computer, where the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; S430, in response to the target host computer's response to the dynamic code loading request, receiving the dynamic code file transmitted from the target host computer; S440. According to the target execution address recorded in the dynamic code file, copy the second code segment to be dynamically loaded from the dynamic code file to the target execution address of the RAM memory.

[0042] Exemplarily, different from the application example corresponding to steps S310~S340, in this embodiment, after the electronic device establishes a communication connection with the target host computer, the target host computer transmits the dynamic code file to the electronic device, the electronic device parses the dynamic code file, and copies the second code segment that needs to be dynamically loaded from the dynamic code file to the target running address of the RAM memory. As mentioned above, the first code segment corresponds to the main program, and the electronic device can perform initialization settings when running the first code segment, for example, including the establishment of a communication connection between the electronic device and the target host computer. When the electronic device establishes a communication connection with the target host computer, the electronic device receives the dynamic code file from the target host computer and preloads it into the RAM memory. When the second code segment needs to be executed, it can be directly called in the RAM memory without waiting for the transmission of the dynamic code file and the copying of the second code segment, which can save the storage space of the FLASH memory and improve the smoothness of the operation of the electronic device.

[0043] The complete firmware file is split into a first code segment to be burned and a second code segment that can be dynamically loaded, and a burned firmware file and a dynamic code file are obtained, the dynamic code file is stored in a target host computer, and the burned firmware file is burned into a FLASH memory of an electronic device. When the electronic device establishes a communication connection with the target host computer, the second code segment is copied from the dynamic code file transmitted by the target host computer to a RAM memory, thereby reducing the space occupied by the FLASH memory of the electronic device and helping to reduce costs.

[0044] This embodiment provides a method for dynamically loading code, which is applied to a host computer and includes: In response to a dynamic code loading request of the target electronic device, determining a dynamic code file to be sent according to the dynamic code loading request, the dynamic code loading request including at least one of a number, a name or a function code of the dynamic code file; Sending a dynamic code file to a target electronic device, so that the target electronic device copies a second code segment to be dynamically loaded from the dynamic code file to the target running address of a RAM memory according to the target running address recorded in the dynamic code file, wherein the dynamic code file includes the second code segment and the target running address of the second code segment in the RAM memory of the target electronic device; or, In response to a communication connection request from the target electronic device, establishing a communication connection; In the case of establishing a communication connection, in response to a dynamic code loading request of the target electronic device, the dynamic code loading request including at least one of a number, a name or a function code of the dynamic code file, determining a dynamic code file to be sent; A dynamic code file is sent to a target electronic device so that the target electronic device copies a second code segment that needs to be dynamically loaded from the dynamic code file to the target running address of a RAM memory according to the target running address recorded in the dynamic code file, wherein the dynamic code file includes the second code segment and the target running address of the second code segment in the RAM memory of the target electronic device.

[0045] By splitting a complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, the dynamic code file is stored in a host computer, and the burned firmware file is burned into the FLASH memory of the target electronic device. When the target electronic device needs to execute the second code segment or establish a communication connection with the host computer, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory, which can reduce the space occupied by the FLASH memory of the target electronic device and is conducive to reducing costs.

[0046] Please refer to Figure 8 , an embodiment of the present invention provides a dynamic code loading system, including an electronic device and a host computer. The electronic device includes a FLASH memory 130 and a RAM memory 140, and a first code segment is stored in the FLASH memory 130; the host computer is in communication connection with the electronic device, and a dynamic code file is stored in the host computer, and the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory 140 of the electronic device; when receiving a dynamic code loading request from the electronic device, the host computer transmits the dynamic code file to the electronic device, so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory 140, and the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

[0047] It should be noted that the electronic device further includes a processor 110 and a communication module 120, and the processor 110 is respectively connected to the communication module 120, the FLASH memory 130 and the RAM memory 140. The host computer may be a PC device or a server, etc. The communication module 120 may be a UART interface module, a Bluetooth interface module, a WIFI interface module, etc., and the communication connection between the electronic device and the host computer may be a wireless communication connection or a wired communication connection.

[0048] The first code segment and the second code segment can form a complete program code, for example, the first code segment corresponds to the main program of the electronic device, and the second code segment corresponds to the subprogram of the electronic device. The first code segment can be burned into the FLASH memory 130 of the electronic device by burning the firmware file generated by the first code segment during the production stage of the electronic device, and the dynamic code file corresponding to the second code segment is stored in the host computer.

[0049] When the electronic device is running, the processor 110 of the electronic device copies the first code segment from the FLASH memory 130 to the RAM memory 140 for execution, such as performing initialization or establishing a communication connection with the host computer through the communication module 120. When the second code segment needs to be executed, the processor 110 sends a request for dynamic code loading to the host computer through the communication module 120, and the host computer responds to the request to transmit the dynamic code file. After receiving the dynamic code file through the communication module 120, the processor 110 performs file parsing to copy the second code segment from the dynamic code file to the target running address of the RAM memory 140 according to the target running address recorded in the dynamic code file, thereby executing the second code segment.

[0050] By splitting the complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a host computer, and burning the burned firmware file into the FLASH memory 130 of the electronic device, when the electronic device needs to execute the second code segment, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory 140, which can reduce the space occupied by the FLASH memory 130 of the target electronic device, which is conducive to reducing costs.

[0051] Please continue to refer to Figure 8 , an embodiment of the present invention provides a dynamic code loading system, including an electronic device and a host computer. The electronic device includes a FLASH memory 130 and a RAM memory 140, and a first code segment is stored in the FLASH memory 130; the host computer stores a dynamic code file, and the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory 140 of the electronic device; when the host computer establishes a communication connection with the electronic device, the host computer transmits the dynamic code file to the electronic device, so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory 140, and the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

[0052] When the electronic device establishes a communication connection with the target host computer, the electronic device receives the dynamic code file from the target host computer and preloads it into the RAM memory 140. When the second code segment needs to be executed, it can be directly called in the RAM memory 140 without waiting for the transmission of the dynamic code file and the copying of the second code segment. This can not only save the storage space of the FLASH memory 130, but also improve the smoothness of the operation of the electronic device.

[0053] By splitting the complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a host computer, and burning the burned firmware file into the FLASH memory 130 of the electronic device, and only when the electronic device establishes a communication connection with the host computer, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory 140, which can reduce the space occupied by the FLASH memory 130 of the target electronic device, which is conducive to reducing costs.

[0054] Please continue to refer to Figure 8 This embodiment also provides an electronic device, including a processor 110 and a communication module 120, a FLASH memory 130 and a RAM memory 140 connected to the processor 110, wherein a first code segment is stored in the FLASH memory 130, and the processor 110 is connected to a target host computer through the communication module 120; when the processor 110 runs the first code segment and needs to execute a dynamic loading code, a dynamic loading code request is sent to the target host computer through the communication module 120, and a dynamic code file is received from the target host computer, and according to the target running address recorded in the dynamic code file, a second code segment that needs to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory 140, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

[0055] By splitting the complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a host computer, and burning the burned firmware file into the FLASH memory 130 of the electronic device, when the electronic device needs to execute the second code segment, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory 140, which can reduce the space occupied by the FLASH memory 130 of the target electronic device, which is conducive to reducing costs.

[0056] Please continue to refer to Figure 8This embodiment also provides an electronic device, including a processor 110 and a communication module 120, a FLASH memory 130 and a RAM memory 140 connected to the processor 110, wherein a first code segment is stored in the FLASH memory 130, and when the processor 110 establishes a communication connection with a target host computer through the communication module 120, a dynamic code loading request is sent to the target host computer through the communication module 120, and a dynamic code file is received from the target host computer, and according to the target running address recorded in the dynamic code file, a second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory 140, and the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

[0057] When the electronic device establishes a communication connection with the target host computer, the electronic device receives the dynamic code file from the target host computer and preloads it into the RAM memory 140. When the second code segment needs to be executed, it can be directly called in the RAM memory 140 without waiting for the transmission of the dynamic code file and the copying of the second code segment. This can not only save the storage space of the FLASH memory 130, but also improve the smoothness of the operation of the electronic device.

[0058] By splitting the complete firmware file into a first code segment to be burned and a second code segment that can be dynamically loaded, and obtaining a burned firmware file and a dynamic code file, storing the dynamic code file in a host computer, and burning the burned firmware file into the FLASH memory 130 of the electronic device, and only when the electronic device establishes a communication connection with the host computer, the second code segment is copied from the dynamic code file transmitted by the host computer to the RAM memory 140, which can reduce the space occupied by the FLASH memory 130 of the target electronic device, which is conducive to reducing costs.

[0059] The present embodiment further provides a host computer, in which a dynamic code file is stored, the dynamic code file includes a second code segment and a target running address of the second code segment in a RAM memory of a target electronic device; the host computer is in communication connection with the target electronic device, and upon receiving a dynamic code loading request from the target electronic device, the host computer transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, the dynamic code loading request including at least one of the number, name or function code of the dynamic code file; Alternatively, a dynamic code file is stored in the host computer, and the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the target electronic device; when the host computer establishes a communication connection with the target electronic device, the host computer receives a dynamic loading code request from the target electronic device and transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

[0060] The complete firmware file is split into a first code segment to be burned and a second code segment that can be dynamically loaded, and a burned firmware file and a dynamic code file are obtained, the dynamic code file is stored in a host computer, and the burned firmware file is burned into a FLASH memory of an electronic device. When the second code segment needs to be executed or a communication connection is established with the host computer, the second code segment is copied from the dynamic code file transmitted by the host computer to a RAM memory, thereby reducing the space occupied by the FLASH memory of the electronic device and helping to reduce costs.

[0061] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge scope of ordinary technicians in the relevant technical field without departing from the purpose of the present invention.

Claims

1. A method for dynamically loading code, characterized in that: include: Compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device during the compiling stage; Separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records the target running address; The dynamic code file is stored in the target host computer, and the burning firmware file is burned into the FLASH memory of the target electronic device; When the target electronic device and the target host computer are in communication connection and the target electronic device needs to execute the second code segment, the target electronic device sends a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; The target host computer sends the corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

2. A method for dynamically loading code, characterized in that: include: Compiling and linking the target code to obtain a first executable file, wherein the target code includes a first code segment to be burned and a second code segment that can be dynamically loaded, and configuring a target running address of the second code segment in a RAM memory of a target electronic device during the compiling stage; Separating the second code segment from the first executable file to obtain a dynamic code file and a burning firmware file, wherein the dynamic code file records the target running address; The dynamic code file is stored in the target host computer, and the burning firmware file is burned into the FLASH memory of the target electronic device; When the target electronic device is in communication connection with the target host computer, the target electronic device sends a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file; The target host computer sends the corresponding dynamic code file to the target electronic device in response to the dynamic code loading request; The target electronic device receives the dynamic code file transmitted from the target host computer, and copies the second code segment from the dynamic code file to the target running address of the RAM memory.

3. A method for dynamically loading code, applied to electronic equipment, characterized in that: The FLASH memory of the electronic device is programmed with a first code segment, and the electronic device is communicatively connected with a target host computer, and the dynamic code loading method includes: Run the first code segment; When it is necessary to execute the dynamic loading code, sending a dynamic loading code request to the target host computer, wherein the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file; In response to the target host computer's response to the dynamic code loading request, receiving a dynamic code file transmitted from the target host computer; According to the target running address recorded in the dynamic code file, the second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory.

4. A method for dynamically loading code, applied to electronic equipment, characterized in that: The FLASH memory of the electronic device is programmed with a first code segment, and the dynamic code loading method includes: Starting and running the first code segment to establish a communication connection with a target host computer; Sending a dynamic code loading request to the target host computer, wherein the dynamic code loading request includes at least one of a number, a name or a function code of a dynamic code file; In response to the target host computer's response to the dynamic code loading request, receiving a dynamic code file transmitted from the target host computer; According to the target running address recorded in the dynamic code file, the second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory.

5. A method for dynamically loading code, applied to a host computer, characterized in that: include: In response to a dynamic code loading request of a target electronic device, determining a dynamic code file to be sent according to the dynamic code loading request, wherein the dynamic code loading request includes at least one of a number, a name or a function code of the dynamic code file; Sending the dynamic code file to the target electronic device, the dynamic code file comprising a second code segment and a target execution address of the second code segment in a RAM memory of the target electronic device; or, In response to a communication connection request from the target electronic device, establishing a communication connection; In the case of establishing a communication connection, in response to a dynamic code loading request of the target electronic device, the dynamic code loading request including at least one of the number, name or function code of the dynamic code file, determining the dynamic code file to be sent; A dynamic code file is sent to the target electronic device, wherein the dynamic code file includes a second code segment and a target execution address of the second code segment in a RAM memory of the target electronic device.

6. A dynamic code loading system, characterized in that: include: An electronic device, comprising a FLASH memory and a RAM memory, wherein a first code segment is stored in the FLASH memory; A host computer is communicatively connected with the electronic device, wherein a dynamic code file is stored in the host computer, wherein the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the electronic device; upon receiving a dynamic code loading request from the electronic device, the host computer transmits the dynamic code file to the electronic device so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, wherein the dynamic code loading request includes at least one of the number, name or function code of the dynamic code file.

7. A dynamic code loading system, characterized in that: include: An electronic device, comprising a FLASH memory and a RAM memory, wherein a first code segment is stored in the FLASH memory; A host computer stores a dynamic code file, wherein the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the electronic device; when the host computer establishes a communication connection with the electronic device, the host computer transmits the dynamic code file to the electronic device so that the electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

8. An electronic device, characterized in that: The invention comprises a processor and a communication module, a FLASH memory and a RAM memory connected to the processor, wherein a first code segment is stored in the FLASH memory, and the processor is connected to a target host computer through the communication module for communication; when the processor runs the first code segment and needs to execute a dynamic loading code, a dynamic loading code request is sent to the target host computer through the communication module, and a dynamic code file is received from the target host computer, and according to the target running address recorded in the dynamic code file, a second code segment that needs to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

9. An electronic device, characterized in that: The invention comprises a processor and a communication module, a FLASH memory and a RAM memory connected to the processor, wherein a first code segment is stored in the FLASH memory, and when the processor establishes a communication connection with a target host computer through the communication module, a dynamic code loading request is sent to the target host computer through the communication module, and a dynamic code file is received from the target host computer, and according to the target running address recorded in the dynamic code file, a second code segment to be dynamically loaded is copied from the dynamic code file to the target running address of the RAM memory, and the dynamic code loading request comprises at least one of the number, name or function code of the dynamic code file.

10. A host computer, characterized in that: The host computer stores a dynamic code file, the dynamic code file includes a second code segment and a target running address of the second code segment in a RAM memory of a target electronic device; the host computer is in communication connection with the target electronic device, and upon receiving a dynamic code loading request from the target electronic device, the host computer transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, the dynamic code loading request including at least one of the number, name or function code of the dynamic code file; Alternatively, a dynamic code file is stored in the host computer, and the dynamic code file includes a second code segment and a target running address of the second code segment in the RAM memory of the target electronic device; when the host computer establishes a communication connection with the target electronic device, the host computer receives a dynamic loading code request from the target electronic device and transmits the dynamic code file to the target electronic device, so that the target electronic device copies the second code segment from the dynamic code file to the target running address of the RAM memory, and the dynamic loading code request includes at least one of the number, name or function code of the dynamic code file.

Citation Information

Patent Citations

  • Method and terminal for loading executable file

    CN106648740A

  • Decoupling method for Android application

    CN108287722A

  • Operation system-free algorithm dynamic loading method based on ARM (Advanced RISC Machines) processor

    CN114816581A

  • Dynamically loadable composite software application

    US20160055014A1