A method, apparatus and electronic device for determining a global offset table

By determining the target global offset table based on the target firmware's running address and burning address during the firmware upgrade process, the problems of firmware operation abnormalities and RAM resource occupation are solved, and efficient firmware operation is achieved.

CN118295669BActive Publication Date: 2025-12-16RUIJIE NETWORKS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211697790.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-28
Publication Date
2025-12-16
Estimated Expiration
2042-12-28

AI Technical Summary

Technical Problem

During firmware upgrades, the execution addresses of various functions and variables in firmware C are inconsistent with their compilation addresses, causing firmware C to malfunction. Existing technologies modify the global offset table by copying it to RAM, resulting in low execution efficiency and excessive RAM consumption of the target firmware.

Method used

By obtaining the target firmware's running address and the solid-state storage space's burning address, the target burning address is determined. The target global offset table can be used directly without copying it to RAM for modification, reducing operations and improving operating efficiency.

Benefits of technology

It improves the operating efficiency of the target firmware, avoids RAM resource occupation, simplifies the firmware operation process, and solves the problems of low efficiency and resource occupation in the existing technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118295669B_ABST
    Figure CN118295669B_ABST
Patent Text Reader

Abstract

The application discloses a method and device for determining a global offset table and an electronic device. The method comprises the following steps: obtaining a current running address of a target firmware, and a respective burning address of each storage region in a solid-state storage space, wherein each storage region is associated with a global offset table; selecting a target burning address matched with the current running address of the target firmware from the respective burning addresses of the storage regions; and associating the global offset table of the storage region corresponding to the target burning address as a target global offset table used by the target firmware during running. Through the technical scheme provided by the embodiment of the application, the target firmware does not need to copy the global offset table to a random memory to modify the compiling addresses of each function and each variable stored in the global offset table during running, so that the running efficiency of the target firmware is improved, and the random memory resource is avoided from being occupied.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data communication, and particularly relates to a method and device for determining a global offset table and electronic equipment. BACKGROUND

[0002] In the field of data communication, there is a demand for firmware upgrade due to iteration of new functions and the like. In order to ensure the reliability of firmware upgrade, multiple copies of firmware are generally stored in a read-only memory (ROM) / flash memory (FLASH) so that the device can return to a runnable firmware after firmware upgrade fails. In the running scenario of firmware upgrade, it is assumed that firmware a and firmware b are stored in the FLASH, wherein firmware a and firmware b are two different versions of firmware, and the version of firmware a is higher than that of firmware b. If firmware a is upgraded to obtain upgraded firmware c, firmware c is overwritten on firmware b, and then firmware a restarts the device to run firmware c.

[0003] In the above scenario, it is assumed that the storage area of firmware a on the FLASH is image0, and the storage area of firmware b on the FLASH is image1. When compiling the code to generate firmware c, firmware c is preset to be burned to the storage area image0, wherein the address corresponding to image0 is the preset burning address.

[0004] Further, when compiling the code to generate firmware c, the respective compiling addresses of each function and each variable in firmware c also need to be compiled, wherein the compiling address is used to call each function in firmware c or access each variable in firmware c, and thus the compiling address is obtained according to the preset burning address.

[0005] Since firmware c needs to overwrite firmware b, that is, the generated firmware c is actually burned to image1, and the burning address corresponding to image1 is inconsistent with the burning address corresponding to image0, that is, the actual burning address after the firmware c is generated is inconsistent with the preset burning address when the firmware c is generated, and the running address of each function and each variable in firmware c is obtained according to the actual burning address, thereby causing the running address of each function and each variable in firmware c to be inconsistent with the compiling address of each function and each variable in firmware c.

[0006] When the firmware c is running, calling each function in the firmware c or accessing each variable in the firmware c is according to the compiling address corresponding to each function and each variable in the firmware c. Since the running address of each function and each variable in the firmware c is inconsistent with the compiling address of each function and each variable in the firmware c, when the firmware c is running, each function and each variable in the firmware c in the image1 cannot be correctly called or accessed, and thus the firmware c deviates from the correct running path, that is, the firmware c runs abnormally.

[0007] To solve the above problem, when the code is compiled to generate the firmware, a global offset table (English: Global Offset Table, abbreviated as GOT) is generated in the firmware, and the compiling address of each function and each variable in the firmware is stored in the GOT. Further, when the firmware is running, based on the difference between the actual burning address of the firmware and the preset burning address, the compiling address of each function and each variable in the GOT is modified to obtain the modified compiling address of each function and each variable, and then the firmware is called or accessed according to the modified compiling address of each function and each variable in the GOT when running, avoiding the problem that the firmware deviates from the correct running path when the running address is inconsistent with the compiling address.

[0008] Further, the prior art usually first copies the GOT in the target firmware from the ROM / FLASH to the random access memory (English: Random Access Memory, abbreviated as RAM), wherein the target firmware is the firmware currently loaded and running, and then the compiling address of each function and each variable in the GOT is modified in the RAM. In other words, the prior art refers to the RAM to realize the modification of the compiling address of each function and each variable in the GOT.

[0009] In the above manner, once the running address of the target firmware changes, the RAM needs to be referred to once to realize the modification of the compiling address of each function and each variable in the GOT, which leads to extremely cumbersome operation of the target firmware when running, and further leads to low running efficiency of the target firmware and occupation of the RAM resource which has small capacity and is difficult to expand. SUMMARY

[0010] The present application provides a method and device for determining a global offset table and an electronic device, to solve the problem that referring to the random access memory to modify the compiling address of each function and each variable in the global offset table after the running address changes leads to low running efficiency of the target firmware and occupation of the random access memory resource. The specific implementation scheme is as follows:

[0011] In a first aspect, the present application provides a method for determining a global offset table, comprising:

[0012] obtain a current running address of a target firmware and a respective burn address of each storage region in a solid-state storage space, wherein each storage region is associated with a global offset table;

[0013] filter a target burn address matching the current running address of the target firmware from the respective burn addresses of the storage regions;

[0014] associate the global offset table of the storage region corresponding to the target burn address as a target global offset table used by the target firmware during running.

[0015] In the respective burn addresses of the storage regions in the solid-state storage space, the target burn address is determined according to the current running address of the target firmware, and the target global offset table used by the target firmware during running is determined through the global offset table associated with the storage region corresponding to the target burn address, so that the target global offset table can be directly used by the target firmware during running, without the need to copy the global offset table to the random memory to modify the compilation addresses of each function and each variable stored in the global offset table, thereby reducing the operation during running of the target firmware, improving the running efficiency of the target firmware, and avoiding the occupation of random memory resources.

[0016] In a possible design, before the obtaining of the current running address of the target firmware and the respective burn address of each storage region in the solid-state storage space, the method further includes:

[0017] obtaining a candidate global offset table set of the target firmware and a preset burn address during compilation of the target firmware, wherein the preset burn address is a burn address corresponding to any one of the storage regions in the solid-state storage space;

[0018] calculating a respective compilation address of each function and each variable in the target firmware based on the preset burn address;

[0019] storing the respective compilation address of each function and each variable in the target firmware in a first candidate global offset table in the candidate global offset table set, to obtain a first global offset table;

[0020] sequentially modifying the remaining candidate global offset tables in the candidate global offset table set based on the first global offset table and the preset burn address, to obtain corresponding global offset tables.

[0021] Before generating the target firmware, based on the preset burning address, the corresponding compiling address of each function and each variable in the target firmware is obtained, and then a first global offset table is obtained, so that the candidate global offset table can be modified based on the first global offset table, thereby avoiding modifying the global offset table in the target firmware stored on the solid-state storage space when the target firmware is running, and further avoiding the problem of difficulty in modifying the global offset table on the solid-state storage space.

[0022] In a possible design, the modifying the remaining candidate global offset tables in the candidate global offset table set based on the first global offset table and the preset burning address to obtain the corresponding global offset tables comprises the following steps.

[0023] In the candidate global offset table set, the following modification operation is performed on the remaining candidate global offset tables in the candidate global offset table set.

[0024] Copy the corresponding compiling address of each function and each variable in the first global offset table to the current candidate global offset table.

[0025] Calculate the difference between the burning address corresponding to the storage area associated with the current candidate global offset table and the preset burning address.

[0026] Based on the difference, modify the corresponding compiling address of each function and each variable in the current candidate global offset table to obtain the current global offset table.

[0027] Until the modification operation is completed on the remaining candidate global offset tables in the candidate global offset table set, the corresponding global offset table is obtained.

[0028] Based on the difference between the burning address corresponding to the storage area and the preset burning address, the remaining candidate global offset tables in the candidate global offset table set are modified, and the modification of the global offset table on the solid-state storage space when the target firmware is running is further avoided.

[0029] In a possible design, after the global offset table associated with the storage area corresponding to the target burning address is used as the target global offset table used when the target firmware is running, the following steps are further included.

[0030] Obtain the corresponding position identifier of each function and each variable in the target global offset table in the target firmware and the original position of the target global offset table in the target firmware, wherein the original position is the position of the target global offset table in the target firmware calculated based on the preset burning address when the target firmware is compiled.

[0031] adding the original position to a difference between the target burning address and the preset burning address to obtain a first accumulated value;

[0032] calculating a product value between each position identifier and a preset value, and adding each product value to the first accumulated value to obtain a second accumulated value corresponding to each function and each variable in the target firmware respectively;

[0033] based on the second accumulated value corresponding to each function and each variable in the target firmware respectively, reading a compiling address corresponding to each function and each variable in the target global offset table, and calling each function in the target firmware and accessing each variable in the target firmware.

[0034] Based on the original position of the target global offset table in the target firmware, the target burning address, and the calculated address of each function and each variable in the target firmware corresponding to the position identifier, the compiling address of each function and each variable in the target global offset table is read, and then based on the compiling address of each function and each variable in the target global offset table, it is ensured that the address used by the target firmware during runtime is a correct address, avoiding the target firmware from deviating from the correct running path during runtime, and thus avoiding the target firmware from running abnormally.

[0035] In a second aspect, the present application also provides a device for determining a global offset table, the device comprising:

[0036] an acquisition module configured to acquire a current running address of a target firmware and a burning address corresponding to each storage region in a solid-state storage space, wherein each storage region is associated with a global offset table;

[0037] a matching module configured to filter a target burning address matching the current running address of the target firmware from the burning addresses corresponding to the storage regions respectively;

[0038] a processing module configured to associate a global offset table corresponding to the storage region of the target burning address as a target global offset table used by the target firmware during runtime.

[0039] In a possible design, the acquisition module is specifically configured to acquire a candidate global offset table set of the target firmware and a preset burning address during compiling the target firmware, wherein the preset burning address is a burning address corresponding to any one of the storage regions in the solid-state storage space;

[0040] based on the preset burning address, calculating a compiling address corresponding to each function and each variable in the target firmware;

[0041] store the respective compiling addresses of the respective functions and the respective variables in the target firmware in a first candidate global offset table in the candidate global offset table set, to obtain a first global offset table;

[0042] modify the remaining candidate global offset tables in the candidate global offset table set based on the first global offset table and the preset burning address, to obtain corresponding global offset tables.

[0043] In a possible design, the obtaining module is specifically configured to, in the candidate global offset table set, sequentially perform the following modification operation on the remaining candidate global offset tables in the candidate global offset table set:

[0044] copy the respective compiling addresses of the respective functions and the respective variables in the first global offset table to a current candidate global offset table;

[0045] calculate a difference value between the respective burning addresses of the storage areas associated with the current candidate global offset table in the storage areas and the preset burning address;

[0046] modify the respective compiling addresses of the respective functions and the respective variables in the current candidate global offset table based on the difference value, to obtain a current global offset table;

[0047] until the modification operation is completed on the remaining candidate global offset tables in the candidate global offset table set, to obtain corresponding global offset tables.

[0048] In a possible design, the processing module is specifically configured to obtain respective position identifiers of the respective functions and the respective variables in the target firmware in the target global offset table and an original position of the target global offset table in the target firmware, wherein the original position is a position of the target global offset table in the target firmware calculated based on a preset burning address when the target firmware is compiled;

[0049] add the difference value between the target burning address and the preset burning address to the original position, to obtain a first accumulated value;

[0050] calculate a product value between each position identifier and a preset value, and add each product value to the first accumulated value, to obtain respective second accumulated values of the respective functions and the respective variables in the target firmware;

[0051] read the respective compiling addresses of the respective functions and the respective variables in the target global offset table based on the respective second accumulated values of the respective functions and the respective variables in the target firmware, and call the respective functions in the target firmware and access the respective variables in the target firmware.

[0052] In a third aspect, the present application provides an electronic device, comprising:

[0053] a memory for storing a computer program;

[0054] a processor for executing the computer program stored in the memory to implement the method steps of determining a global offset table.

[0055] In a fourth aspect, the present application provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method steps of determining a global offset table.

[0056] The above-mentioned second aspect to fourth aspect and the technical effects that can be achieved by each aspect are described above in the first aspect or the various possible solutions in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0057] Figure 1 A method for determining a global offset table is provided in the present application.

[0058] Figure 2 A firmware relationship diagram is provided in the present application.

[0059] Figure 3 A flowchart of a method for determining a global offset table applied to a dual firmware scenario is provided in the present application.

[0060] Figure 4 A structure diagram of a device for determining a global offset table is provided in the present application.

[0061] Figure 5 An electronic device diagram is provided in the present application. DETAILED DESCRIPTION

[0062] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be described in further detail below with reference to the accompanying drawings. The specific operation method in the method embodiment can also be applied to the device embodiment or the system embodiment. It should be noted that in the description of the present application, “multiple” is understood as “at least two”. The association relationship between the associated objects is described, which means that there can be three relationships, for example, A and / or B, which means that there are three cases: A exists alone, A and B exist together, and B exists alone. A and B are connected, which means that A and B are directly connected and A and B are connected through C. In addition, in the description of the present application, “first”, “second”, etc. are used only for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can it be understood as indicating or implying order.

[0063] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0064] Currently, the modification of the compiling addresses of each function and each variable in the GOT is usually performed by copying the GOT in the target firmware from the ROM / FLASH to the RAM, and then modifying the compiling addresses of each function and each variable in the GOT in the RAM. However, once the running address of the target firmware changes, the RAM needs to be referenced once to modify the compiling addresses of each function and each variable in the GOT, which leads to extremely cumbersome operations during the running of the target firmware, and further leads to low efficiency of the running of the target firmware and occupation of the resources of the RAM which has small capacity and is difficult to expand.

[0065] Therefore, the present application provides a method for determining a global offset table, determines a target burning address based on the current running address of the target firmware and the respective burning addresses of each storage region in the solid-state storage space, determines the target GOT used during the running of the target firmware through the GOT associated with the storage region corresponding to the target burning address, so that the target GOT can be directly used during the running of the target firmware, without the need to copy the GOT to the RAM to modify the compiling addresses of each function and each variable stored in the GOT, which reduces the operations during the running of the target firmware, and further improves the running efficiency of the target firmware, and avoids occupation of the RAM memory resources.

[0066] Reference Figure 1 Fig. 1 shows a flowchart of a method for determining a global offset table according to an embodiment of the present application, and the method comprises the following steps:

[0067] S1, obtaining the current running address of the target firmware and the respective burning addresses of each storage region in the solid-state storage space;

[0068] Before obtaining the current running address of the target firmware and the respective burning addresses of each storage region in the solid-state storage space, the target firmware needs to be loaded first.

[0069] Specifically, first, a firmware loading program is started, the firmware loading program reads configuration information, and the target firmware can be determined according to the configuration information; then the firmware loading program loads the target firmware.

[0070] Further, after loading the target firmware, the current running address of the target firmware and the respective burning addresses of each storage region in the solid-state storage space are obtained, wherein the storage region and the burning address have a one-to-one correspondence, and each storage region is associated with a GOT, and each GOT stores the compiling addresses of each function and each variable in the target firmware updated according to the corresponding storage region.

[0071] It should be noted that in the embodiments of the present application, the current running address of the target firmware can be obtained by sending a current address instruction and according to the current running address information output by the current address instruction.

[0072] In addition, it should be noted that in the embodiments of the present application, the solid-state storage space can be a ROM for storing firmware or a FLASH for storing firmware, and the specific solid-state storage space is not limited in the embodiments of the present application; and each storage area in the solid-state storage space can store one firmware.

[0073] The relationship among the firmware, the solid-state storage space and the GOT can be referred to the firmware relationship diagram as shown in Figure 2 There are three storage areas in the FLASH, that is, storage area 1, storage area 2 and storage area 3, wherein the storage area 1 stores the firmware 1, the storage area 2 stores the firmware 2, and the storage area 3 stores the firmware 3, and each firmware stores three GOTs associated with the respective storage areas; in the three GOTs stored in each firmware, each GOT stores the compiled address of each function and each variable in the corresponding firmware modified according to the burning address of the storage area associated with the GOT, for example, the GOT1_1 stored in the firmware 1 stores the compiled address of each function and each variable in the firmware 1 modified according to the burning address of the storage area 1, and the GOT1_1 is associated with the storage area 1.

[0074] Further, before generating the target firmware, the GOT associated with each storage area has been modified, and the GOT associated with each storage area is stored in the target firmware, so when obtaining a GOT associated with each storage area, a GOT associated with each storage area can be directly obtained by sending a GOT instruction.

[0075] It should be noted that in the embodiments of the present application, the modification of the GOT associated with each storage area is as follows:

[0076] First, the candidate GOT set of the target firmware and the preset burning address when compiling the target firmware are obtained, wherein the preset burning address is the burning address corresponding to any storage area in the solid-state storage space.

[0077] Then, based on the preset burning address, the respective compiled addresses of each function and each variable in the target firmware are calculated.

[0078] It should be noted that in the embodiment of the present application, when the compiling addresses corresponding to each function and each variable in the target firmware are calculated, the compiling addresses corresponding to each function and each variable in the target firmware are automatically calculated by the compiling tool chain.

[0079] Further, the compiling addresses corresponding to each function and each variable in the target firmware are stored in the first candidate GOT in the candidate GOT set, to obtain a first GOT, the first GOT stores the compiling addresses corresponding to each function and each variable in the target firmware, and the first GOT is associated with the storage region corresponding to the preset burning address.

[0080] Further, the compiling addresses corresponding to each function and each variable in the target firmware are stored in the first candidate GOT in the candidate GOT set, to obtain a first GOT, the first GOT stores the compiling addresses corresponding to each function and each variable in the target firmware, and the first GOT is associated with the storage region corresponding to the preset burning address.

[0081] It should be noted that in the embodiment of the present application, when the compiling addresses corresponding to each function and each variable in the target firmware are calculated, the compiling addresses corresponding to each function and each variable in the target firmware are automatically calculated by the compiling tool chain.

[0082] First, the compiling addresses corresponding to each function and each variable in the first GOT are copied to the current candidate GOT; then, one storage region associated with the current candidate GOT in each storage region in the solid-state storage space is determined, and the difference between the burning address corresponding to the storage region associated with the current candidate GOT and the preset burning address is calculated; then, the compiling addresses corresponding to each function and each variable stored in the current candidate GOT are respectively added by the difference, and the compiling addresses corresponding to each function and each variable stored in the current candidate GOT are modified, to finally obtain the current GOT, the current GOT is associated with one of the storage regions.

[0083] For example, when the target firmware is compiled, the preset burning address is 0x10000000, each function and each variable in the target firmware are function A, function B and variable C, the compiling address of function A is 0x1000AB00, the compiling address of function B is 0x1000CD00, and the compiling address of variable C is 0x1000EF00, the compiling addresses of each function and each variable in the target firmware are stored in the first GOT, that is, 0x1000AB00, 0x1000CD00 and 0x1000EF00 are stored in the first GOT.

[0084] Firstly, 0x1000AB00, 0x1000CD00 and 0x1000EF00 stored in the first GOT are copied to the current candidate GOT; the current candidate GOT is associated with a second storage area in the FLASH, and the burning address corresponding to the second storage area is 0x20000000, and the difference between the burning address and the preset burning address is 0x10000000; then 0x1000AB00, 0x1000CD00 and 0x1000EF00 stored in the current candidate GOT are added by the above difference, that is, 0x1000AB00 is added by 0x10000000, 0x1000CD00 is added by 0x10000000, and 0x1000EF00 is added by 0x10000000, to obtain the current GOT, and the compilation addresses of the function A, the function B and the variable C stored in the current GOT are 0x2000AB00, 0x2000CD00 and 0x2000EF00 respectively.

[0085] Finally, after the modification operation is sequentially completed on the remaining candidate GOTs in the candidate GOT set, the corresponding GOT can be obtained.

[0086] In the above manner, before the target firmware is generated, the candidate GOTs in the candidate GOT set are modified in sequence based on the difference between the preset burning address and the burning address corresponding to the storage area associated with the candidate GOT in each storage area, and the corresponding GOT is obtained, thereby avoiding modifying the GOT stored in the target firmware on the solid-state storage space when the target firmware is running, and further avoiding the problem of difficulty in modifying the GOT on the solid-state storage space.

[0087] S2, from the burning addresses corresponding to each of the storage areas, a target burning address matching the current running address of the target firmware is screened out;

[0088] After obtaining the current running address of the target firmware and the burning addresses corresponding to each of the storage areas in the solid-state storage space, a target burning address matching the current running address of the target firmware needs to be screened out from the burning addresses corresponding to each of the storage areas.

[0089] Specifically, the current running address of the target firmware is compared with each of the burning addresses corresponding to each of the storage areas, and then in the burning addresses corresponding to each of the storage areas, the burning address closest to the current running address of the target firmware and smaller than the current running address of the target firmware is taken as the target burning address.

[0090] It should be noted that in the embodiment of the present application, since the burning addresses corresponding to each of the storage areas are different, the target burning address obtained at this time will be only one burning address.

[0091] For example, the current running address of the target firmware is 0x20000100, and there are three storage areas on the solid storage space FLASH, wherein the first storage area corresponds to a burning address of 0x100000000, the second storage area corresponds to a burning address of 0x20000000, and the third storage area corresponds to a burning address of 0x30000000. Among them, the burning address less than the current running address of the target firmware (i.e. 0x20000100) includes the burning address of the first storage area (i.e. 0x100000000) and the burning address of the second storage area (i.e. 0x20000000). The burning address of the second storage area (i.e. 0x20000000) is closest to the current running address of the target firmware (i.e. 0x20000100), and therefore the target burning address is the burning address of the second storage area, i.e. the target burning address is 0x200000000.

[0092] S3, the global offset table associated with the storage area corresponding to the target burning address is used as the target global offset table used by the target firmware when running.

[0093] After obtaining the target burning address, first, the GOT associated with the storage area corresponding to the target burning address is obtained from the GOT associated with each storage area in the solid storage space; and then the GOT is used as the target GOT used by the target firmware when running.

[0094] For example, there are three storage areas in the FLASH, wherein the first storage area corresponds to a burning address of 0x100000000, the second storage area corresponds to a burning address of 0x20000000, and the third storage area corresponds to a burning address of 0x30000000. In the target firmware, the GOT associated with the first storage area is GOT1, the GOT associated with the second storage area is GOT2, and the GOT associated with the third storage area is GOT3. The target burning address is 0x20000000, and therefore the GOT associated with the storage area corresponding to the target burning address is GOT2. Then GOT2 is used as the target GOT used by the target firmware when running.

[0095] Further, after obtaining the target GOT, the original position of the target GOT in the target firmware is obtained, wherein the original position is the position of the target GOT in the target firmware automatically calculated by the compiling tool chain based on the preset burning address when compiling the target firmware.

[0096] In addition, after obtaining the original position of the target GOT in the target firmware, the respective position identifiers of the functions and the variables in the target GOT also need to be obtained, wherein the position identifier indicates the item number of the function or the variable in the target GOT.

[0097] For example, when the target firmware is compiled, the compiling address of function A (i.e. 0x2000AB00) is stored in the first item of GOT2 (i.e. the target GOT) by using the compiling tool chain, the compiling address of function B (i.e. 0x2000CD00) is stored in the second item of GOT2, and the compiling address of variable C (i.e. 0x2000EF00) is stored in the third item of GOT2, so the position identifier of function A is 1, the position identifier of function B is 2, and the position identifier of variable C is 3.

[0098] After obtaining the respective position identifiers of the functions and the variables in the target GOT and the original position of the target GOT in the target firmware, the first accumulated value is obtained by adding the difference between the target burning address and the preset burning address to the original position; then the product value between each position identifier and the preset value is calculated; then each product value is added to the first accumulated value respectively to obtain the respective second accumulated values of the functions and the variables in the target firmware, at this time, the respective compiling addresses of the functions and the variables in the target GOT can be read according to the respective second accumulated values of the functions and the variables in the target firmware; finally, the functions in the target firmware are called and the variables in the target firmware are accessed according to the compiling addresses, and thus the target firmware can be normally run.

[0099] For example, the preset value is set to 4, the preset burning address is 0x10000000, the original position of GOT1 (i.e. the target GOT) in the target firmware is 0x10001100, and after obtaining the target burning address 0x20000000, the difference between the preset burning address and the target burning address is calculated to be 0x10000000, and then the first accumulated value is obtained by adding the difference to the original position, which is 0x20001100; the position identifiers of function A and function B stored in GOT1 are 1 and 2 respectively, and the product value corresponding to function A is 4 and the product value corresponding to function B is 8 after multiplying each position identifier by the preset value; then each product value is added to the first accumulated value respectively to obtain the second accumulated value corresponding to function A, which is 0x20001104, and the second accumulated value corresponding to function B, which is 0x20001108; the compiling addresses of function A and function B in GOT1 are 0x200000AB and 0x200000EF respectively according to 0x20001104 and 0x20001108, based on which the correct functions A and B can be correctly called, and thus the target firmware can be normally run.

[0100] By the above manner, the compiling addresses of the functions and the variables in the target GOT are read based on the original position of the target GOT in the target firmware, the target burning address, and the address calculated based on the position identifier corresponding to each function and each variable in the target firmware, and then the compiling addresses of the functions and the variables in the target GOT are used to ensure that the address used by the target firmware during running is a correct address, avoid the target firmware deviating from a correct running path during running, and thus avoid problems in the running of the target firmware.

[0101] In summary, the method for determining a global offset table provided in the present application determines the target burning address of the target firmware based on the current running address of the target firmware and the burning address corresponding to each storage region in the solid-state storage space, determines the target GOT used by the target firmware during running through the GOT associated with the storage region corresponding to the target burning address, so that the target GOT can be directly used by the target firmware during running, without the need to copy the GOT to the RAM to modify the compiling addresses of the functions and the variables stored in the GOT, thereby reducing the operation during running of the target firmware, improving the running efficiency of the target firmware, and avoiding the occupation of RAM memory resources.

[0102] In addition, the GOT associated with each storage region is modified before the target firmware is generated, and one of the GOTs is used according to requirements during running of the target firmware, thereby avoiding the modification of the compiling addresses of the parameters and the variables in the target firmware stored in the GOT during running of the target firmware, and thus avoiding the difficulty in modifying the GOT on the solid-state storage space.

[0103] The technical solutions of the present application will be further described below in combination with a specific application process.

[0104] As shown in FIG. 1, the method for determining a global offset table is applied to a single firmware scene. Figure 3 As shown in FIG. 2, the method for determining a global offset table is applied to a dual firmware scene.

[0105] S301: It is determined that the storage region image0 on the FLASH stores firmware 0, and the storage region image1 stores firmware 1.

[0106] The burning address corresponding to the storage region image0 is addr0, and the burning address corresponding to the storage region image1 is addr1.

[0107] S302: During the compilation of the firmware, GOT0 and GOT1 are stored in the firmware 0, and GOT0' and GOT1' are stored in the firmware 1.

[0108] The GOT0 and the GOT0' are associated with the storage area image0, the GOT1 and the GOT1' are associated with the storage area image1, in other words, the data stored in the GOT0 is the compiled address of each function and each variable in the firmware 0 after the modification of the addr0 when the firmware 0 is burned into the image0, the data stored in the GOT1 is the compiled address of each function and each variable in the firmware 0 after the modification of the addr1 when the firmware 0 is burned into the image1, the data stored in the GOT0' is the compiled address of each function and each variable in the firmware 1 after the modification of the addr0 when the firmware 1 is burned into the image0, and the data stored in the GOT1' is the compiled address of each function and each variable in the firmware 1 after the modification of the addr1 when the firmware 1 is burned into the image1.

[0109] S303: loading the target firmware, determining whether the target firmware is the firmware 0; if yes, turning to S304; if no, turning to S305.

[0110] S304: determining whether the target firmware is burned into the storage area image0; if no, turning to S306; if yes, turning to S307.

[0111] S305: determining whether the target firmware is burned into the storage area image0; if yes, turning to S308; if no, turning to S309.

[0112] S306: using the GOT1 when running the target firmware.

[0113] S307: using the GOT0 when running the target firmware.

[0114] S308: using the GOT0' when running the target firmware.

[0115] S309: using the GOT1' when running the target firmware.

[0116] In the above manner, based on the generated firmware 0 and firmware 1 and the GOT contained in each firmware, the target GOT is determined according to the storage area where the target firmware is burned into, and the data in the target GOT can be directly used when running the target firmware, so that the data in the GOT does not need to be copied to the RAM for modification, the operation when running the target firmware is reduced, the running efficiency of the target firmware is improved, and the memory resources of the RAM occupied by the GOT are avoided.

[0117] Based on the same inventive concept, the embodiment of the present application further provides a device for determining a global offset table, as shown in Figure 4 The device for determining a global offset table provided by the present application has the structure as shown in the figure, and the device comprises:

[0118] The obtaining module 401 is configured to obtain a current running address of a target firmware and a respective burn address of each storage region in a solid-state storage space, where each storage region is associated with a GOT.

[0119] The matching module 402 is configured to filter a target burn address matching the current running address of the target firmware from the respective burn addresses of the storage regions.

[0120] The processing module 403 is configured to associate the GOT of the storage region corresponding to the target burn address as a target GOT used by the target firmware during running.

[0121] In a possible design, the obtaining module 401 is specifically configured to obtain a candidate GOT set of the target firmware and a preset burn address when the target firmware is compiled, where the preset burn address is a burn address corresponding to any storage region in the solid-state storage space.

[0122] Based on the preset burn address, a respective compiling address of each function and each variable in the target firmware is calculated.

[0123] The first candidate GOT in the candidate GOT set stores the respective compiling address of each function and each variable in the target firmware, to obtain a first GOT.

[0124] Based on the first GOT and the preset burn address, the remaining candidate GOTs in the candidate GOT set are modified in sequence to obtain respective GOTs.

[0125] In a possible design, the obtaining module 401 is specifically configured to perform the following modification operations in sequence for the remaining candidate GOTs in the candidate GOT set:

[0126] The respective compiling address of each function and each variable in the first GOT is copied to the current candidate GOT.

[0127] The difference between the respective burn address of the storage region associated with the current candidate GOT in each storage region and the preset burn address is calculated.

[0128] Based on the difference, the respective compiling address of each function and each variable in the current candidate GOT is modified to obtain a current GOT.

[0129] The modification operations are performed in sequence for the remaining candidate GOTs in the candidate GOT set until the respective GOTs are obtained.

[0130] In a possible design, the processing module 403 is specifically configured to acquire respective position identifiers of each function and each variable in the target firmware in the target GOT and an original position of the target GOT in the target firmware, where the original position is a position of the target GOT in the target firmware calculated based on a preset programming address when the target firmware is compiled.

[0131] The original position is added by a difference between the target programming address and the preset programming address to obtain a first accumulated value.

[0132] A product value between each position identifier and a preset value is calculated, and each product value is added by the first accumulated value to obtain a second accumulated value corresponding to each function and each variable in the target firmware.

[0133] Based on the second accumulated value corresponding to each function and each variable in the target firmware, a compiled address corresponding to each function and each variable in the target GOT is read, and each function in the target firmware is called and each variable in the target firmware is accessed.

[0134] Based on the same inventive concept, the embodiment of the present application further provides an electronic device, which can realize the functions of the foregoing device for determining a global offset table, and refer to the foregoing description. Figure 5 The electronic device includes:

[0135] At least one processor 501 and a memory 502 connected with the at least one processor 501, and the specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application, Figure 5 for example, the processor 501 and the memory 502 are connected through a bus 500. The bus 500 is represented by a thick line in Figure 5 the description, and the connection mode between other components is only schematically illustrated and is not limited. The bus 500 can be divided into an address bus, a data bus, a control bus, and the like, and for the convenience of representation, Figure 5 only one thick line is used in the description, but it does not mean that there is only one bus or only one type of bus. Alternatively, the processor 501 can also be called a controller, and the name is not limited.

[0136] In the embodiment of the present application, the memory 502 stores instructions executable by the at least one processor 501, and the at least one processor 501 can execute the foregoing method for determining a global offset table by executing the instructions stored in the memory 502. The processor 501 can realize the functions of each module in the device shown in Figure 5 the description.

[0137] The processor 501 is the control center of the apparatus, and can connect all parts of the apparatus through various interfaces and lines. The apparatus performs various functions and processes data by running or executing instructions stored in the memory 502 and calling data stored in the memory 502, thereby monitoring the apparatus as a whole.

[0138] In a possible design, the processor 501 can include one or more processing units, and the processor 501 can integrate an application processor and a modem processor. The application processor mainly processes operating systems, user interfaces, and application programs, and the modem processor mainly processes wireless communication. It can be understood that the modem processor can also not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 can be implemented on the same chip, and in some embodiments, they can also be implemented on separate chips respectively.

[0139] The processor 501 can be a general-purpose processor, for example, a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array, or other programmable logic device, a discrete gate or transistor logic component, a discrete hardware component, and can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method for determining a global offset table disclosed in the embodiments of the present application can be directly embodied by a hardware processor for execution, or be executed by a combination of hardware and software modules in the processor.

[0140] The memory 502, as a non-volatile computer readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 can include at least one type of storage medium, for example, can include flash memory, hard disk, multimedia card, card type memory, RAM, static random access memory (SRAM), programmable read only memory (PROM), ROM, electrically erasable programmable read only memory (EEPROM), magnetic memory, magnetic disk, optical disk, etc. The memory 502 is any other medium capable of carrying or storing desired program code in the form of instructions or data structures and capable of being accessed by a computer, but is not limited to this. The memory 502 in the embodiments of the present application can also be a circuit or any other device capable of realizing the storage function, used for storing program instructions and / or data.

[0141] By designing and programming the processor 501, the code corresponding to the method for determining the global offset table introduced in the foregoing embodiments can be fixed in the chip, so that the chip can execute the steps of the method for determining the global offset table of the embodiments shown in the figure at runtime. Figure 4 How to design and program the processor 501 is a technology known to those skilled in the art, and will not be described here.

[0142] Based on the same inventive concept, the embodiments of the present application also provide a storage medium storing computer instructions, when the computer instructions run on a computer, the computer instructions make the computer execute the method for determining the global offset table discussed above.

[0143] In some possible implementations, various aspects of the method for determining the global offset table provided by the present application can also be implemented in the form of a program product, which includes program code, when the program product runs on a device, the program code is used to make the control device execute the steps in the method for determining the global offset table according to various exemplary embodiments of the present application described above in the specification.

[0144] Those skilled in the art will appreciate that embodiments of the application can be devised for a method, a system, or a computer program product. Accordingly, the present application can be embodied in the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, and the like) embodying computer readable program code.

[0145] The present application is described in reference to the flowchart illustrations and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0146] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0147] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0148] Obviously, numerous modifications and variations of the present application are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.

Claims

1. A method for determining a global offset table, characterized in that, The method includes: Obtain the current running address of the target firmware and the corresponding burning address of each storage area in the solid-state storage space. Each storage area is associated with a global offset table. From the burning addresses corresponding to each of the storage areas, select the target burning address that matches the current running address of the target firmware; The global offset table associated with the storage area corresponding to the target burning address is used as the target global offset table for the target firmware during runtime.

2. The method as described in claim 1, characterized in that, Before obtaining the current running address of the target firmware and the corresponding burning addresses of each storage area in the solid-state storage space, the method further includes: Obtain the candidate global offset table set of the target firmware and the preset burning address when compiling the target firmware, wherein the preset burning address is the burning address corresponding to any storage area in the solid-state storage space. Based on the preset burning address, calculate the compilation address corresponding to each function and variable in the target firmware; The first candidate global offset table in the candidate global offset table set stores the compilation addresses corresponding to each function and each variable in the target firmware, thus obtaining the first global offset table; Based on the first global offset table and the preset burning address, the remaining candidate global offset tables in the candidate global offset table set are modified sequentially to obtain the corresponding global offset table.

3. The method as described in claim 2, characterized in that, Based on the first global offset table and the preset burning address, the remaining candidate global offset tables in the candidate global offset table set are modified sequentially to obtain the corresponding global offset tables, including: In the set of candidate global offset tables, for the remaining candidate global offset tables in the set, the following modification operations are performed sequentially: Copy the compilation addresses of each function and variable in the first global offset table to the current candidate global offset table; Calculate the difference between the burning address corresponding to the storage region associated with the current candidate global offset table in each storage region and the preset burning address; Based on the difference, the compilation addresses corresponding to each function and each variable in the current candidate global offset table are modified to obtain the current global offset table; The modification operation is performed on the remaining candidate global offset tables in the candidate global offset table set in sequence until the corresponding global offset table is obtained.

4. The method according to any one of claims 1-3, characterized in that, After establishing the global offset table that associates the storage region corresponding to the target burning address as the target global offset table used by the target firmware during runtime, the system further includes: Obtain the position identifiers of each function and variable in the target firmware in the target global offset table, as well as the original position of the target global offset table in the target firmware. The original position is the position of the target global offset table in the target firmware calculated based on a preset burning address when compiling the target firmware. The first accumulated value is obtained by adding the difference between the target burning address and the preset burning address to the original position; Calculate the product value between each location identifier and the preset value, and add the first accumulated value to each product value to obtain the second accumulated value corresponding to each function and each variable in the target firmware; Based on the second accumulated value corresponding to each function and variable in the target firmware, the compilation address corresponding to each function and variable in the target global offset table is read, and each function in the target firmware is called and each variable in the target firmware is accessed.

5. An apparatus for determining a global offset table, characterized in that, The device includes: The acquisition module is used to obtain the current running address of the target firmware and the burning address corresponding to each storage area in the solid-state storage space. Each storage area is associated with a global offset table. The matching module is used to filter out the target burning address that matches the current running address of the target firmware from the burning addresses corresponding to each of the storage areas. The processing module is used to associate the global offset table of the storage area corresponding to the target burning address as the target global offset table used by the target firmware during runtime.

6. The apparatus as claimed in claim 5, characterized in that, The acquisition module is further configured to acquire the candidate global offset table set of the target firmware and the preset burning address when compiling the target firmware, wherein the preset burning address is the burning address corresponding to any storage area in the solid-state storage space. Based on the preset burning address, calculate the compilation address corresponding to each function and variable in the target firmware; The first candidate global offset table in the candidate global offset table set stores the compilation addresses corresponding to each function and each variable in the target firmware, thus obtaining the first global offset table; Based on the first global offset table and the preset burning address, the remaining candidate global offset tables in the candidate global offset table set are modified sequentially to obtain the corresponding global offset table.

7. The apparatus as claimed in claim 6, characterized in that, The acquisition module is configured to perform the following modification operations sequentially on the remaining candidate global offset tables in the candidate global offset table set: Copy the compilation addresses of each function and variable in the first global offset table to the current candidate global offset table; Calculate the difference between the burning address corresponding to the storage region associated with the current candidate global offset table in each storage region and the preset burning address; Based on the difference, the compilation addresses corresponding to each function and each variable in the current candidate global offset table are modified to obtain the current global offset table; The modification operation is performed on the remaining candidate global offset tables in the candidate global offset table set in sequence until the corresponding global offset table is obtained.

8. The apparatus according to any one of claims 5-7, characterized in that, The processing module is further configured to obtain the position identifiers of each function and each variable in the target firmware corresponding to the target global offset table and the original position of the target global offset table in the target firmware, wherein the original position is the position of the target global offset table in the target firmware calculated based on a preset burning address when compiling the target firmware; The first accumulated value is obtained by adding the difference between the target burning address and the preset burning address to the original position; Calculate the product value between each location identifier and the preset value, and add the first accumulated value to each product value to obtain the second accumulated value corresponding to each function and each variable in the target firmware; Based on the second accumulated value corresponding to each function and variable in the target firmware, the compilation address corresponding to each function and variable in the target global offset table is read, and each function in the target firmware is called and each variable in the target firmware is accessed.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a computer program stored in the memory, implements the method steps of any one of claims 1-4.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-4.

Citation Information

Patent Citations

  • Method for covering and solidifying off-line calibration data

    CN103176812A

  • Program burning method and device

    CN109656584A