Chip boot firmware device and method based on symbol table dynamic execution
Through the dynamic execution method based on symbol tables, the chip startup firmware is solved in the initialization and configuration problems and functional limitations, and the rapid initialization and complex logic support are achieved, which improves the startup speed and versatility of the chip firmware.
Patent Information
- Application Number
- CN202410912565.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-08-28
- Filing Date
- 2023-09-01
- Publication Date
- 2024-11-05
AI Technical Summary
The existing chip startup firmware has problems such as slow initialization and configuration, cannot fix chip problems in advance, fixed configuration and cannot modify, and cannot cope with complex logic requirements. In the existing technology, there is a risk of crashing and function calling firmware programs using function pointer methods. limitation.
Using a dynamic execution method based on symbol tables, we use storing and modifying firmware symbol tables, dynamically changing function addresses, and support for program repair and complex logic functions, reducing duplicate code, and improving startup speed and flexibility.
It realizes rapid initialization and repair in the firmware startup stage, supports complex logic requirements, reduces the amount of duplicate code, improves the startup speed and versatility of the chip firmware, and avoids the risk of crashes.
Smart Images

Figure CN118897699A_ABST
Abstract
Description
[0001] This patent application is a divisional application of application number 202311128729.2 filed on September 1, 2023, and named "A chip startup firmware device and method based on dynamic execution of a symbol table". Technical Field
[0002] The present invention relates to the field of chip startup firmware control, and in particular to a chip startup firmware device and method based on symbol table dynamic execution. Background Art
[0003] Chip boot firmware (bootloader) is a code used to update its own application software and run independently. It is often used to upgrade products and fix product bugs. In embedded systems, chip boot firmware runs before the operating system kernel runs. It can initialize hardware devices and establish memory space mapping, so as to bring the system's hardware and software environment to a suitable state, so as to prepare the correct environment for the final call to the operating system kernel. In embedded systems, there is usually no firmware program like computer software, so the loading and startup task of the entire system is completely completed by the chip boot firmware.
[0004] The current chip startup firmware uses the following three solutions for some subsequent device configurations, clock initialization, and chip bug repairs:
[0005] 1. Post-stage program image processing: The post-stage program image is read from an external storage device such as flash, eMMC, network, etc., and processed by the post-stage program image.
[0006] 2. Read configuration: Use GPIO or external memory configuration to determine the built-in configuration table.
[0007] 3. Arrays composed according to certain rules: read an array of a certain length in a format specified by the manufacturer from the external memory, parse and execute it in sequence, and configure it into the corresponding registers.
[0008] However, the shortcomings of these three methods are:
[0009] 1. During the post-stage program image processing, if there is a problem with the chip, it cannot be intervened in advance through the program, and can only be processed by the subsequent program. In addition, since the clock and memory are not initialized, the running speed is slow, and the external larger storage device cannot be used. There are many requirements and restrictions on the subsequent startup process. Most post-stage images also require highly repeated program codes in the startup firmware code.
[0010] 2. When reading the configuration, the solution can only switch within a limited number of configurations. Moreover, since the specific configuration is stored in the internal fixed program, errors in the configuration cannot be modified, and additional configurations cannot be added. It is also unable to respond to additional problems and requirements, and can only be handled by subsequent programs.
[0011] 3. Arrays composed according to certain rules can only run according to the rules and cannot respond to requirements or modifications that require complex logic to implement. The time point for executing the configuration with rules is fixed due to the solidification of the program, so problems that arise in subsequent processes cannot be repaired.
[0012] However, for the second technical solution, the prior art can update the address of the chip firmware function by modifying the driver program to implement various complex logical functions. This method uses a function pointer to call the program; and the function of the firmware extension function needs to be compiled to generate a driver program (or according to a specified framework), and the extension function also needs to call the program in the firmware through a function pointer. For the driver program, the prior art needs to provide a driver model, and the subsequent function calls are completed in accordance with the format of the driver model. This method limits the type and format of the driver program, etc., and has certain limitations. In addition, before the extension function is compiled, the function address of the driver program is pre-registered in the entry function table in advance. This method may cause the firmware to freeze during the process of loading the input program, which will bring many inconveniences to the user. Summary of the invention
[0013] In order to overcome the deficiencies of the prior art, the present invention provides a chip startup firmware device and method based on dynamic execution of a symbol table.
[0014] In order to achieve the above object, the present invention provides a chip startup firmware device based on dynamic execution of a symbol table, comprising:
[0015] A storage module, used for storing a firmware symbol table generated by booting firmware compilation in a chip;
[0016] A reading module is used to read the firmware symbol table, obtain the input program and load the input program containing the symbol table, and generate the input program symbol table;
[0017] Modification module, input program determines whether to modify the firmware symbol table according to the requirements, if modified, calls the modification function to modify, and finally generates the firmware symbol table for this startup;
[0018] A calling module is used to call the entry function that completes the input program logic function and execute the entry function based on the firmware symbol table started this time;
[0019] The execution module is used to determine whether to continue the firmware startup process. If the startup is continued, the startup process is executed according to the firmware symbol table of this startup; if the startup is not continued, the input program custom process is executed.
[0020] Preferably, the data of the firmware symbol table includes function name / variable name and function address; in the modification module, if the firmware symbol table needs to be modified, the function address of the modified firmware symbol is changed to the function address in the input program symbol table after determining the modified firmware symbol, and the firmware symbol table for this startup is generated; if the firmware symbol does not need to be modified, the firmware symbol table is the firmware symbol table for this startup.
[0021] Preferably, the input program in the reading module is loaded from an external storage device.
[0022] Preferably, the logic function of the input program is set outside the chip, stored and loaded by the chip external device, and the calling module calls the entry function to implement the function required by the logic of the input program; the entry function symbol is a fixed function symbol.
[0023] Preferably, when the calling module calls the entry function, the entry function program image is verified and the symbol table is compared.
[0024] The present invention also provides a method for chip startup firmware based on dynamic execution of a symbol table, comprising:
[0025] S1: Read the firmware symbol table stored in the storage module;
[0026] S2: Obtain an input program and load the input program containing a symbol table to generate an input program symbol table;
[0027] S3: The input program determines whether to modify the firmware symbol table according to the requirements. If it is modified, the modification function is called to modify it, and finally the firmware symbol table for this startup is generated;
[0028] S4: Based on the firmware symbol table for this startup, call the entry function that completes the input program logic function and execute the entry function;
[0029] S5: Determine whether to continue the firmware startup process. If so, execute the startup process according to the firmware symbol table for this startup; if not, execute the input program customization process.
[0030] Preferably, the data of the firmware symbol table in step S3 includes function name / variable name and function address; in step S3, if the firmware symbol table needs to be modified, the function address of the modified firmware symbol is changed to the function address in the input program symbol table after determining the modified firmware symbol, and the firmware symbol table for this startup is generated; if the firmware symbol does not need to be modified, the firmware symbol table is the firmware symbol table for this startup.
[0031] Preferably, the input program in step S2 is loaded from an external memory.
[0032] Preferably, the logic function of the input program is set outside the chip and is stored and loaded by an external device of the chip. Step S4 calls the entry function to implement the function required by the logic of the input program; the entry function is a fixed function symbol.
[0033] Preferably, when the entry function is called in step S4, the entry function program image is checked and compared with the symbol table.
[0034] The beneficial effects of a chip startup firmware device and method based on symbol table dynamic execution provided by the present invention are:
[0035] 1. During the firmware startup phase, a firmware symbol table is generated through the chip firmware, and the function address in the firmware symbol table is changed according to the configuration of the input program read from the external storage, thereby modifying the abnormal chip program or abnormal firmware program to the program in the input program configuration to achieve the program repair function.
[0036] 2. No need for a post-boot program, the input program can directly use the functions in the firmware through the function addresses in the firmware symbol table, which reduces the amount of repeated code, reduces the size of the input program image, and improves the speed of chip firmware startup.
[0037] 3. In the firmware symbol table, if the clock and memory initialization functions are configured in the image of the input program, the correct function address can be directly obtained through the firmware symbol table and executed. In this way, key devices such as clock and memory can be initialized in time in the startup firmware. In the subsequent startup process, it can run at a higher main frequency and complete memory space.
[0038] 4. The present invention also provides an entry function for completing the functions required by the input program logic. The function is a fixed function symbol and serves as the total entry of the input program image. The firmware calls the entry function to implement the complex logic requirements of the input program. In addition, the program for implementing the complex logic requirements of the input program is set outside the chip and stored and loaded by an external device, which avoids the problem that the firmware program is too complex, causing functional errors, and causing the chip firmware to need to be repeatedly modified. At the same time, because the program for the complex logic requirements of the input program is stored and loaded by an external device, complex logic patches, user requirements, etc. can be added at will. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A schematic diagram of the structure of a chip startup firmware device based on dynamic execution of a symbol table provided by the present invention;
[0040] Figure 2A first example diagram of a chip startup firmware device modifying a symbol table based on dynamic execution of a symbol table provided by the present invention;
[0041] Figure 3 The file content with function name / variable name and function address generated after chip firmware is compiled;
[0042] Figure 4 A symbol table of firmware in a second example of a chip startup firmware device for dynamic execution based on a symbol table provided by the present invention;
[0043] Figure 5 A chip startup firmware device based on dynamic execution of a symbol table provided by the present invention modifies the compilation result of calling the second example function of the symbol table;
[0044] Figure 6 A modified symbol table in a second example of a chip startup firmware device modifying a symbol table based on dynamic execution of a symbol table provided by the present invention;
[0045] Figure 7 The present invention provides a flowchart of a method for chip startup firmware based on dynamic execution of a symbol table. DETAILED DESCRIPTION
[0046] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0047] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0048] All directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, horizontal, vertical...) are only used to explain the relative position relationship, movement status, etc. between the components in a certain specific posture. If the specific posture changes, the directional indication will also change accordingly.
[0049] Due to installation errors and other reasons, the parallel relationship referred to in the embodiments of the present invention may actually be an approximately parallel relationship, and the vertical relationship may actually be an approximately vertical relationship.
[0050] like Figure 1 As shown, the present invention provides a chip startup firmware device based on dynamic execution of a symbol table, including a storage module 1, a reading module 2, a modification module 3, a calling module 4 and an execution module 5. The storage module 1 is used to store the firmware symbol table generated by compiling the startup firmware in the chip. The reading module 2 is used to read the firmware symbol table, obtain the input program and load the input program containing the symbol table to generate the input program symbol table. In the modification module 3, the input program determines whether to modify the firmware symbol table according to the requirements. If modified, the modification function is called to modify it, and finally the firmware symbol table for this startup is generated. The calling module 4 is used to call the entry function that completes the logical function of the input program based on the firmware symbol table for this startup. The execution module 5 is used to determine whether to continue the firmware startup process. If the startup continues, the startup process is executed according to the firmware symbol table for this startup; if the startup does not continue, the input program custom process is executed.
[0051] In this embodiment, the input program is a user program. Before starting the storage module 1, it is also necessary to reset and release, power on the chip to start the chip, and then perform simple initialization on the clock, memory, etc. of the chip. Then the reading module 2 reads the data of the firmware symbol table in the storage module 1. The data of the firmware symbol table includes function name / variable name and function address; at the same time, the external input user program is read, and the user program containing the symbol table is loaded from the external memory, and the input program symbol table generated by the input program compilation is generated, wherein the external memory can be a flash memory, an embedded multimedia card emmc, a network, etc.
[0052] The firmware symbol table stored in the storage module 1 is a fixed function, that is, a certain function array is stored in the firmware function symbol table. The firmware symbol table is compiled by the compiler, wherein the compiler is implemented by executing the following command:
[0053] $(compiler)-nm bootloader.elf|grep -v'\(compiled\)\|\(\.o$$\)\|\([aUw]\)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)'|LC_ALL=C sort>bootloader.sym.
[0054] Among them, $(compiler)-nm is the nm tool of the current chip firmware; bootloader.elf is the elf file compiled by the chip firmware; bootloader.sym is the generated chip firmware symbol table.
[0055] After compilation, it generates Figure 3The file with function name / variable name and function address shown in the figure. During the chip design phase, after the above file is generated, it is converted into an internal symbol table in the format of a function name corresponding to an address and solidified inside the chip. During the chip use phase, after the above file is generated, it will be compared with the firmware inside the chip. According to user needs or whether the chip has bugs and added functions, the internal symbol table of the chip is modified through the interface to generate a new symbol table for use with the chip firmware and the user's input program.
[0056] Based on the input program symbol table, the modification module 3 input program determines whether to modify the firmware symbol table according to the requirements, that is, the input program determines whether the symbol table in the chip firmware meets the logical requirements of the input program or whether the chip firmware has an erroneous program according to the requirements. If an erroneous program is identified in the chip firmware or the firmware symbol table cannot meet the logical function of the input program, when modification is required, after the input program is compiled, the modification function is called to configure the function address in the input program symbol table generated by it into the symbol table of the chip startup firmware, and finally generate the firmware symbol table for this startup. The chip firmware will discard the replaced old function and replace it with the newly compiled function, thereby meeting the logical requirements of the input program. It should be noted that when modifying the function address in the firmware symbol table, the format, file type or driver of the input program will not be limited. The user can write a program arbitrarily and use the symbol table dynamic loading mode to implement a custom logical function. When the input program needs to modify the logical function or the firmware fails, the address function in the firmware symbol table can be directly replaced to achieve function modification or addition and repair firmware error information. In addition, the functions of various logical functions in the present invention complete function calls in the form of packaged specifications, which can avoid the need for compilation or program specification, is more flexible, and the calling process also ensures the accuracy of the call through verification, avoiding errors in the loaded user program during the loading process and causing a crash.
[0057] In addition, compared with the prior art method of calling the program in the firmware through a function pointer, the present invention does not require a fixed format for compilation, and the user can write code according to his own programming habits, and the call does not need to use a function pointer, and the firmware function can be directly used and directly accessed through the symbol table. To run through a function pointer, the function pointer needs to be assigned a value, and an example of its description is as follows:
[0058] If there is a func2_real function in the prior art, the address is addr2, and the code is roughly as follows:
[0059] typedef void(*func2_t)(void);
[0060] func2_t func2;
[0061] func2 = (func2_t) addr2;
[0062] func2();
[0063] Through the above code, the function pointer is transferred to the function func2_real. In this embodiment, the method of using the symbol table is adopted, and the function call can be realized by directly using func2_real(). Compared with the prior art, this solution simplifies the program code of the input program, provides convenience for users, and saves the time of users calling the addresses of various logical function functions of the input program.
[0064] like Figure 2 As shown, the fixed firmware symbol stored in the storage module 1 is the old symbol table, and the firmware symbol table generated after modification is the new symbol table. The modification process of the old and new symbol tables is as follows: during the modification process of the old and new symbols, the function name / variable name does not change, and only the function address in the symbol table is modified. For example, the function symbol of the function address 0x00020000 of the function func_b in the firmware symbol table is modified to the function symbol of the function name func_b and the function address 0x20000000 according to the input program configuration, and the remaining functions, such as the function name func_a and its function address, are retained in the new symbol table. In the modified new symbol table, whether it is the firmware or the user's input program, when calling the function func_b, the function address 0x20000000 is accessed; the program with the function address 0x00020000 in the old symbol table in the firmware is discarded. Discarding the old function means that the old function is still retained in the firmware function, but the new function is directly run when the input program is running. In this way, the chip firmware error program is repaired. At the same time, by dynamically modifying the function address in the firmware function symbol table, the chip firmware program is simplified, and the input program can arbitrarily add functions of logical functions. It is applicable to both simple and complex logic programs, thereby improving the versatility of the chip firmware.
[0065] In order to explain in more detail the implementation method of modifying the firmware function in this embodiment, the modification principle is as follows: Figure 4 As described above, after the firmware is started in the chip, the firmware symbol table starts to run, wherein the firmware symbol table includes a function variable named cancel lib by_user, and its function address is 0x00000696. When the input program (i.e., the user program) uses the firmware symbol table, cancel lib by_user is directly called. When the input program is compiled, the compiler will connect to the address 0x696, which is 2026 in decimal. The relationship diagram of the connection to the address 2026 is as follows Figure 5If the cancel lib by_user function has a problem and needs to be modified, after the user program writes a new function with the same name, a new address will be generated, such as 0x02201234, and a new symbol table will be generated, such as Figure 6 As shown in the figure, the modified symbol table is used as the symbol table of the firmware for this startup. The symbol table-related program in the startup firmware will modify all the instructions of the originally called function from the value 0x696 to 0x02201234, thereby realizing the dynamic modification of the function address.
[0066] If the symbol table in the chip firmware supports the logical function of the input program or there is no need to repair the chip firmware, that is, the fixed function in the firmware symbol table meets the logical function of the input program, the correct function address can be directly obtained through the chip firmware symbol table, the firmware symbol table for this startup is generated, and the program corresponding to the function address is executed. At this time, the chip firmware symbol table is the firmware symbol table for this startup. In addition, regardless of whether the symbol table is modified, if the clock and memory initialization functions are configured in the image of the input program (that is, the user image), the correct function address can be directly obtained through the firmware symbol table and executed. In this way, the clock, memory and other key devices can be initialized in time during the firmware startup process, so that the chip firmware can run at a higher main frequency and complete memory space in the subsequent startup process. At the same time, the input program can also directly call the function in the chip firmware, which can save the user time to rewrite the same logical function program, provide convenience for users, reduce the amount of repeated code, and speed up the startup time of the chip firmware.
[0067] In some embodiments, other methods can also be used to modify the program in the chip firmware, such as in an array; in a function pointer manner, including a function pointer definition in a structure; in a binary manner stored in ROM or RAM; in a dynamic library, a function list, a function pointer, a hook, a callback function, etc. to replace the symbol table in this embodiment. The above methods are all to complete the modification of the firmware program by replacing the function address. In addition to the modification methods described above, there can also be other methods to complete the program modification by modifying the function address, which is not limited in this embodiment again.
[0068] After the modification module 3 completes the modification of the error in the chip firmware or the function address that needs to be replaced, it generates a modified firmware symbol table for this startup. Based on the firmware symbol table for this startup, the calling module 4 calls the entry function that completes the input program logic function and executes the entry function. Among them, the entry function is a fixed function symbol, and the calling module 4 calls the function symbol as the total entry of the user program image. The user can write several sub-functions as needed to realize various requirements of the input program, such as writing complex clocks, memory initialization processes or other functional requirements. However, these several sub-functions are all integrated outside the chip and stored and loaded by external devices, avoiding the problem that the firmware program is too complex and causes functional errors, resulting in the need for repeated modification of the chip firmware. At the same time, because the program with complex logic requirements of the input program is stored and loaded by external devices, complex logic patches, user requirements, etc. can be added at will, and the input program can complete complex logic functions with a small amount of code, and when the external memory loads the code, the loading speed is improved, and the number of repeated codes is also reduced.
[0069] After calling module 4 to execute the entry function, the execution module 5 determines whether the subsequent process continues the firmware startup process. If it continues, the startup process continues to be executed according to the firmware symbol table of this startup; if it does not continue to start, the firmware program is started according to the custom process in the input program to meet the needs of users. This solves the limitations and requirements of the startup process after chip initialization in the prior art. At the same time, it also solves the highly repeated firmware program in the subsequent startup process in the prior art, speeds up the chip firmware startup speed, and improves the startup efficiency.
[0070] In this embodiment, when calling module 4 calls the entry function, in order to ensure the data integrity of the entry function program image and the symbol table version matching, the entry function program image will be subjected to data verification and hash function comparison of the symbol table. If any one or both of the verification or comparison fails, the entry function call is abandoned. After the verification and comparison are correct, the function address of the entry function is read from the header information configuration of the entry program image, and the entry function of this address is called. Among them, the symbol table compared is the input program symbol table and the firmware symbol table stored in the chip.
[0071] like Figure 7 As shown, the present invention also provides a method for chip startup firmware based on dynamic execution of a symbol table, comprising:
[0072] S1: Read the firmware symbol table stored in the storage module.
[0073] Step 1 also includes the following steps:
[0074] S1.1: Reset release, chip startup;
[0075] S1.2: Simple initialization
[0076] Specifically, the reset release powers on the chip to start the chip, and then performs simple initialization on the clock, memory, etc. of the chip. Then, the data of the firmware symbol table in the storage module 1 is read.
[0077] The firmware symbol table stored in the memory module 1 in the chip is completed by the following steps:
[0078] SI: Chip startup firmware compilation;
[0079] SII: Generate firmware symbol table;
[0080] SIII: Solidified into the chip.
[0081] Among them, in step S1, the firmware symbol table is a fixed function, that is, a certain function array is stored in the firmware function symbol table, and the firmware symbol table uses a compiler to compile the chip firmware, and the compiler generates the firmware symbol table by executing the following command:
[0082] $(compiler)-nm bootloader.elf|grep -v'\(compiled\)\|\(\.o$$\)\|\([aUw]\)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)'|LC_ALL=C sort>bootloader.sym.
[0083] Among them, $(compiler)-nm is the nm tool of the current chip firmware; bootloader.elf is the elf file compiled by the chip firmware; bootloader.sym is the generated chip firmware symbol table.
[0084] After compilation, it generates Figure 3 The file with function name / variable name and function address shown in the figure. During the chip design phase, after the above file is generated, it is converted into an internal symbol table in the format of a function name corresponding to an address and solidified inside the chip. During the chip use phase, after the above file is generated, it will be compared with the firmware inside the chip. According to user needs or whether the chip has bugs and added functions, the internal symbol table of the chip is modified through the interface to generate a new symbol table for use with the chip firmware and the user's input program.
[0085] S2: Read the firmware symbol table, obtain the input program and load the input program containing the symbol table to generate the input program symbol table.
[0086] Specifically, after the firmware symbol table is generated, the symbol table in the firmware is read, and at the same time, the external input user program is read, the user program containing the symbol table is loaded from the external memory, and the input program symbol table generated by the input program compilation is generated, wherein the external memory may be a flash memory, an embedded multimedia card emmc, a network, etc. Among them, the input program is a user program, and the data in the firmware symbol table includes function name / variable name and function address.
[0087] S3: The input program determines whether to modify the firmware symbol table according to the requirements. If modified, the modification function is called to modify it, and finally the firmware symbol table for this startup is generated.
[0088] Specifically, the input program determines whether to modify the firmware symbol table according to the requirements, that is, the input program determines whether the symbol table in the chip firmware meets the logical requirements of the input program or whether there is an erroneous program in the chip firmware according to the requirements. If an erroneous program is identified in the chip firmware or the firmware symbol table cannot meet the logical function of the input program, it needs to be modified. After the input program is compiled, the modification function is called to configure the function address in the input program symbol table generated by it into the symbol table of the chip startup firmware, and finally generate the firmware symbol table for this startup. The chip firmware will discard the replaced old function and replace it with the newly compiled function, thereby meeting the logical requirements of the input program. It should be noted that when modifying the function address in the firmware symbol table, the format, file type or driver of the input program will not be limited. The user can write the program arbitrarily and use the symbol table dynamic loading mode to implement the customized logical function. When the input program needs to modify the logical function or the firmware fails, the address function in the firmware symbol table can be directly replaced to achieve function modification or addition and repair firmware error information. In addition, the functions of various logical functions in the present invention complete function calls in the form of packaged specifications, which can avoid the need for compilation or program specification, is more flexible, and the calling process also ensures the accuracy of the call through verification, avoiding errors in the loaded user program during the loading process and causing a crash.
[0089] In addition, compared with the prior art method of calling the program in the firmware through a function pointer, the present invention does not require a fixed format for compilation, and the user can write code according to his own programming habits, and the call does not need to use a function pointer, and the firmware function can be directly used and directly accessed through the symbol table. To run through a function pointer, the function pointer needs to be assigned a value, and an example of its description is as follows:
[0090] If there is a func2_real function in the prior art, the address is addr2, and the code is roughly as follows:
[0091] typedef void(*func2_t)(void);
[0092] func2_t func2;
[0093] func2 = (func2_t) addr2;
[0094] func2();
[0095] Through the above code, the function pointer is transferred to the function func2_real. In this embodiment, the method of using the symbol table is adopted, and the function call can be realized by directly using func2_real(). Compared with the prior art, this solution simplifies the program code of the input program, provides convenience for users, and saves the time of users calling the addresses of various logical function functions of the input program.
[0096] For example Figure 2 As shown, the fixed firmware symbol stored in step 1 is the old symbol table, and the firmware symbol table generated after modification is the new symbol table. The modification process of the old and new symbol tables is as follows: during the modification process of the old and new symbols, the function name / variable name does not change, and only the function address in the symbol table is modified. For example, the function symbol of the function address 0x00020000 of the function func_b in the firmware symbol table is modified to the function symbol of the function name func_b and the function address 0x20000000 according to the input program configuration, and the remaining functions, such as the function name func_a and its function address, are retained in the input program symbol table. After the modified input program symbol table, whether the firmware or the user's input program calls the function func_b, the function address 0x20000000 is accessed; the program with the function address 0x00020000 replaced in the old symbol table of the chip firmware is discarded. Discarding the old function means that the old function is still retained in the firmware function, but the new function is directly run when the input program is running. In this way, the chip firmware error program is repaired. At the same time, by dynamically modifying the function address in the firmware function symbol table, the chip firmware program is simplified, and the input program can arbitrarily add functions of logical functions. It is applicable to both simple and complex logic programs, thereby improving the versatility of the chip firmware.
[0097] In order to explain in more detail the implementation method of modifying the firmware function in this embodiment, the modification principle is as follows: Figure 4 As described above, after the firmware is started in the chip, the firmware symbol table starts to run, wherein the firmware symbol table includes a function variable named cancel lib by_user, and its function address is 0x00000696. When the input program (i.e., the user program) uses the firmware symbol table, cancel lib by_user is directly called. When the input program is compiled, the compiler will connect to the address 0x696, which is 2026 in decimal. The relationship diagram of the connection to the address 2026 is as follows Figure 5If the cancel lib by_user function has a problem and needs to be modified, after the user program writes a new function with the same name, a new address will be generated, such as 0x02201234, and a new symbol table will be generated, such as Figure 6 As shown in the figure, the modified symbol table is used as the symbol table of the firmware for this startup. The symbol table-related program in the startup firmware will modify all the instructions of the originally called function from the value 0x696 to 0x02201234, thereby realizing the dynamic modification of the function address.
[0098] If the symbol table in the chip firmware supports the logical function of the input program or there is no need to repair the chip firmware, that is, the fixed function in the firmware symbol table meets the logical function of the input program, the correct function address can be directly obtained through the chip firmware symbol table, the firmware symbol table for this startup is generated, and the program corresponding to the function address is executed. At this time, the chip firmware symbol table is the firmware symbol table for this startup. Among them, regardless of whether the symbol table is modified or not, if the clock and memory initialization functions are configured in the image of the input program (that is, the user image), the correct function address can be directly obtained through the firmware symbol table and executed. In this way, the clock, memory and other key devices can be initialized in time during the firmware startup process, so that the chip firmware can run at a higher main frequency and complete memory space in the subsequent startup process. At the same time, the input program can also directly call the function in the chip firmware, which can save the user time to rewrite the same logical function program, provide convenience for users, reduce the amount of repeated code, and speed up the startup time of the chip firmware.
[0099] In some embodiments, other methods can also be used to modify the program in the chip firmware, such as in an array; in a function pointer manner, including a function pointer definition in a structure; in a binary manner stored in ROM or RAM; in a dynamic library, a function list, a function pointer, a hook, a callback function, etc. to replace the symbol table in this embodiment. The above methods are all to complete the modification of the firmware program by replacing the function address. In addition to the modification methods described above, other methods can also be used to complete the program by modifying the function address, which is not limited in this embodiment again.
[0100] S4: Based on the firmware symbol table for this startup, call the entry function that completes the input program logic function and execute the entry function;
[0101] Specifically, after the error in the chip firmware or the function address that needs to be replaced is modified, a modified symbol table of the firmware for this startup is generated. Based on the symbol table of the firmware for this startup, the entry function that completes the logic function of the input program is called, and the entry function is executed. Among them, the entry function is a fixed function symbol, and the function symbol is called as the total entry of the user program image. The user can write several sub-functions as needed to realize various requirements of the input program, such as writing complex clocks, memory initialization processes or other functional requirements. However, these several sub-functions are all integrated outside the chip and stored and loaded by external devices, avoiding the problem that the firmware program is too complex and causes functional errors, resulting in the need for repeated modification of the chip firmware. At the same time, because the program with complex logic requirements of the input program is stored and loaded by external devices, complex logic patches, user requirements, etc. can be added at will, and the input program can complete complex logic functions with a small amount of code, and when the external memory loads the code, the loading speed is improved, and the number of repeated codes is also reduced.
[0102] S5: Determine whether to continue the firmware startup process. If so, execute the startup process according to the firmware symbol table for this startup; if not, execute the input program customization process.
[0103] Specifically, after executing the entry function, it is determined whether the subsequent process continues the firmware startup process. If it continues, the startup process continues to be executed according to the firmware symbol table of this startup; if it does not continue to start, the firmware program is started according to the custom process in the input program to meet the needs of users. This solves the limitations and requirements of the startup process after chip initialization in the prior art. At the same time, it also solves the problem of highly repeated firmware programs in the subsequent startup process in the prior art, speeds up the chip firmware startup speed, and improves the startup efficiency.
[0104] In this embodiment, when step S4 calls the entry function, in order to ensure the data integrity of the entry function program image and the symbol table version matching, the entry function program image will be subjected to data verification and hash comparison of the hash function of the firmware symbol table started this time. If any one or both of the verification or comparison fails, the entry function call is abandoned. After the verification and comparison are correct, the function address of the entry function is read from the header information configuration of the entry program image, and the entry function of this address is called. Among them, the symbol table compared is the input program symbol table and the firmware symbol table stored in the chip.
[0105] In summary, the present invention provides a chip startup firmware device and method based on dynamic execution of a symbol table. In the firmware startup stage, a firmware symbol table is generated by the chip firmware, and the function address in the firmware symbol table is changed according to the configuration of the input program read from the external storage, so as to modify the abnormal chip program or abnormal firmware program to the program in the input program configuration to realize the function of program repair. The present invention does not require a post-level boot program, and the input program can directly use the function in the firmware through the function address in the firmware symbol table, which reduces the amount of repeated code, reduces the size of the input program image, and improves the speed of chip firmware startup. In the firmware symbol table, if the clock and memory initialization functions are configured in the image of the input program, the correct function address can be directly obtained through the firmware symbol table and executed, so that the clock, memory and other key devices can be initialized in time in the startup firmware, and in the subsequent startup process, it can run in a higher main frequency and complete memory space. The present invention also provides an entry function for completing the input program logic requirement function, which is a fixed function symbol and serves as the total entry of the input program image. The firmware realizes the complex logic requirements of the input program by calling the entry function. In addition, the program that realizes the complex logic requirements of the input program is set outside the chip and stored and loaded by an external device, which avoids the problem that the firmware program is too complex and causes functional errors, resulting in the need for repeated modification of the chip firmware. At the same time, because the program that realizes the complex logic requirements of the input program is stored and loaded by an external device, complex logic patches and user requirements can be added at will.
[0106] Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
Claims
1. A chip startup firmware device based on dynamic execution of a symbol table, characterized in that: include: A reading module is used to read the firmware symbol table, obtain the input program and load the input program containing the symbol table, and generate the input program symbol table; Modification module, input program determines whether to modify the firmware symbol table according to the requirements, if modified, calls the modification function to modify, and finally generates the firmware symbol table for this startup; The data in the firmware symbol table includes function names and function addresses; In the modification module, if the firmware symbol table needs to be modified, the function address of the firmware symbol to be modified is changed to the function address in the input program symbol table after determining the modified firmware symbol, and the firmware symbol table for this startup is generated; If there is no need to modify the firmware, the firmware symbol table is the firmware symbol table for this startup; In the modification module, if the clock and memory initialization functions are configured in the image of the input program, the correct function address can be directly obtained through the firmware symbol table and executed.
2. The chip startup firmware device based on dynamic execution of symbol table according to claim 1, characterized in that: In the modification module, when modifying the function address in the firmware symbol table, the format, file type or driver of the input program is not limited. The program can be written arbitrarily, and the symbol table dynamic loading mode is used to implement the customized logical function. When the input program needs to modify the logical function or the firmware fails, the address function in the firmware symbol table is directly replaced.
3. The chip startup firmware device based on dynamic execution of symbol table according to claim 1, characterized in that: The various logic functions of the input program are logically called by packaging in a specified form.
4. A method for chip startup firmware based on dynamic execution of symbol table, characterized in that: include: S1: Read the firmware symbol table stored in the storage module; S2: Obtain an input program and load the input program containing a symbol table to generate an input program symbol table; S3: The input program determines whether to modify the firmware symbol table according to the requirements. If it is modified, the modification function is called to modify it, and finally the firmware symbol table for this startup is generated; The data of the firmware symbol table includes function names and function addresses; in the step S3, if the firmware symbol table needs to be modified, the function address of the modified firmware symbol is changed to the function address in the input program symbol table after determining the modified firmware symbol, and the firmware symbol table for this startup is generated; If there is no need to modify the firmware, the firmware symbol table is the firmware symbol table for this startup; When modifying the symbol table in step S3, if the clock and memory initialization functions are configured in the image of the input program, the correct function address can be directly obtained through the firmware symbol table and executed.
5. The method for chip startup firmware based on dynamic execution of symbol table according to claim 4, characterized in that: In step S3, when modifying the function address in the firmware symbol table, the format, file type or driver of the input program is not limited, the program can be written arbitrarily, and the symbol table dynamic loading mode is used to implement the customized logical function. When the input program needs to modify the logical function or the firmware fails, the address function in the firmware symbol table is directly replaced.
6. The method for chip startup firmware based on dynamic execution of symbol table according to claim 4, characterized in that: The various logic functions of the input program are logically called by packaging in a specified form.
