A chip FLASH program burning method based on OpenOCD
Through the OpenOCD platform and JTAG interface, the efficient FLASH program writing of embedded chips is realized, which solves the problems of slow writing speed and dependence on dedicated hardware in the existing technology, improves development efficiency and convenience, and has low cost and high capability. Transplantability.
Patent Information
- Application Number
- CN202410978206.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2044-07-22
AI Technical Summary
During the development and debugging of embedded systems, it is difficult for the existing technology to achieve efficient, reliable and fast FLASH program writing, and it relies on PC, chip emulator and debugging software, which affects the development efficiency and convenience.
Through the OpenOCD platform, the PC and the target chip are connected using the JTAG interface to realize the development of on-chip applets and FLASH drivers. The Telnet debugging command line is used to issue fever write commands, OpenOCD parses and executes the burn-in instructions, and the data is transferred from RAM through the on-chip applet. Move to FLASH and complete the writing.
Reduces dependence on dedicated hardware and software, improves the speed of writing FLASH programs, improves debugging convenience and efficiency, reduces costs, and has high portability and wide application value.
Smart Images

Figure CN118519646B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of electronic engineering, and in particular to a chip FLASH program burning method based on OpenOCD. Background Art
[0002] With the widespread application of embedded systems, the requirements for their performance and reliability are constantly increasing, especially in the development and debugging of FLASH modules of embedded chips. OpenOCD provides a cost-effective and flexible debugging solution that supports multiple communication interfaces and debugging protocols and can work with various types of target devices. Developers can program, debug and verify the FLASH modules of embedded chips directly through standard debugging ports by customizing the development of OpenOCD FLASH drivers and configuration files without relying on dedicated hardware and development platforms. Therefore, it is particularly important to study and develop an efficient, reliable and fast FLASH program burning method based on OpenOCD, which will greatly promote the convenience and efficiency of embedded chip development work based on the Cortex_R5 architecture. Summary of the invention
[0003] The purpose of the present invention is to provide a method for burning FLASH programs of embedded chips based on OpenOCD, so as to reduce the dependence on PCs, chip emulators and debugging software, increase the burning speed of FLASH programs, and improve the convenience and efficiency of debugging.
[0004] In order to solve the above technical problems, the present invention provides a method for burning FLASH program of embedded chip based on OpenOCD, using JTAG interface to connect PC with target chip, burning program into FLASH module of embedded chip through OpenOCD, comprising the following steps:
[0005] Step S1: Implementing the on-chip applet for transferring data and starting the FLASH driver in OpenOCD, and compiling and generating the OpenOCD debugging agent program according to the compilation rule file;
[0006] Step S2: Configure the OpenOCD configuration file, connect to the chip through the OpenOCD debugging agent program, and issue the FLASH debugging command through the Telnet debugging command line;
[0007] Step S3: OpenOCD parses the FLASH burning command, and writes the on-chip applet into the RAM address of the embedded chip and starts it by running the FLASH driver. The on-chip applet moves the burning data written by OpenOCD into the RAM to the FLASH, and the burning is completed.
[0008] Preferably, the step S1 specifically includes the following steps:
[0009] Step S1-1: write assembly code according to ARM assembly instructions to start the on-chip applet that can be executed on RAM, that is, write RAM in the write function and start it. The function of the on-chip applet is used to move data from RAM to FLASH;
[0010] Step S1-2: Implementing erase function, read function, write function and verify function in the FLASH driver to ensure reliable storage and access of data;
[0011] Step S1-3: modify the OpenOCD compilation rule file, and compile and generate the OpenOCD debugging agent program.
[0012] Preferably, the step S2 specifically includes the following steps:
[0013] Step S2-1: Configure OpenOCD configuration file;
[0014] Step S2-2: Start the OpenOCD debugging agent program to connect to the chip;
[0015] Step S2-3: Initialize the Telnet debugging command line to connect to OpenOCD through a single port;
[0016] Step S2-4: Receive FLASH debugging command.
[0017] Preferably, configuring the OpenOCD configuration file includes: initializing OpenOCD, initializing JTAG, initializing the chip, and initializing the chip FLASH driver.
[0018] Preferably, the step S3 specifically includes the following steps:
[0019] Step S3-1: Parse the FLASH programming instruction through OpenOCD;
[0020] Step S3-2: Erase FLASH address;
[0021] Step S3-3: write the on-chip applet into the chip RAM destination address;
[0022] Step S3-4: Start the on-chip applet and start moving the burning data written by OpenOCD into RAM to FLASH;
[0023] Step S3-5: Verify the correctness of the programming.
[0024] Preferably, the on-chip applet includes:
[0025] The start function module performs code initialization, sets initial conditions and enters the waiting state;
[0026] The write_fifo function module is a loop. It loads the write pointer wp through the ARM general register r6 and the read pointer rp through the ARM general register r5. By comparing the values of the ARM general register r5 and the ARM general register r6, if they are equal, it means that there is no new data to be written at present, and continue to wait in the write_fifo function module; if they are not equal, it means that there is new data to be written at present, and the data is read from the address pointed by the read pointer rp and written to the target address; at the same time, it is necessary to check whether the read pointer rp exceeds the range of the working area. If it does not exceed the end address of the working area, it will directly jump to the no_warp function module to continue execution; if it exceeds or reaches the end of the working area, the read pointer rp is reset to the starting address of the working area, and the working area is restarted;
[0027] The no_warp function module processes the position of the read pointer rp in the work area for wrapping processing, ensuring that the read pointer rp does not exceed the boundary of the work area. If the read pointer rp moves beyond the end of the work area, the no_wrap function module resets the read pointer rp to the beginning of the work area, thereby achieving wrapping;
[0028] special_set function module is a module for special processing;
[0029] The busy waiting function module reads the current status from the status register of the flash memory controller and checks the busy status BSY bit. When the busy status is 1, the jump instruction will jump the execution flow back to the busy label, forming a loop until the BSY bit is cleared.
[0030] The error function module is used to handle errors detected during the writing process, and the read pointer rp is set to 0;
[0031] The exit function module ends the program execution, returns to the final state through the ARM general register r0, and executes the breakpoint instruction to indicate that the program is executing normally.
[0032] Preferably, the on-chip applet also includes: being implemented by ARM assembly code, being able to use ARM general registers r0-r7 to store data at different runtimes, and being able to move the burning data written into RAM to FLASH.
[0033] The present invention also provides an embedded chip FLASH program burning system based on OpenOCD, which adopts the chip FLASH program burning method based on OpenOCD as described above, including: a PC, a target board and a JTAG interface; a Telnet debugging command line and OpenOCD are installed in the PC, the Telnet debugging command line is connected to OpenOCD through a single port and sends a debugging command, the OpenOCD is a debugging agent program compiled after adding assembly code, FLASH driver and configuration file, and controls the target board through the JTAG interface, the PC and the target board are connected through the JTAG interface, and the target board returns debugging information to the OpenOCD in the PC through the JTAG interface.
[0034] Compared with the prior art, the present invention has the following beneficial effects:
[0035] The present invention only needs to complete the development of the on-chip applet, FLASH driver and configuration file of OpenOCD, and the JTAG interface can be made according to the JTAG protocol without relying on other software or emulators. After the chip is initialized by JTAG, a burning command can be sent to OpenOCD through the Telnet command, and OpenOCD automatically executes the erase, write and verify process. In the writing process, OpenOCD first writes the on-chip applet into RAM and starts it, and moves the burning data written into RAM into FALSH through the on-chip applet. The present invention has a fast burning speed, saves costs, has high portability, improves debugging efficiency, and has a wide range of application significance and practical value for debugging FLASH on embedded chips. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a schematic diagram of the main framework of the debugging system in the embodiment of the present invention.
[0037] Figure 2 Schematic diagram of the basic flow of the FLASH programming method in an embodiment of the present invention.
[0038] Figure 3 Schematic diagram of the state machine of the on-chip applet in an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become more apparent from the following description. It should be noted that the accompanying drawings are in very simplified form and in non-precise proportions, and are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.
[0040] like Figure 1As shown, an embodiment of the present invention provides an embedded chip FALSH program burning system based on OpenOCD, which mainly includes a PC, a target board, and a JTAG interface. The PC is installed with a Telnet debugging command line and OpenOCD, the Telnet debugging command line connects to OpenOCD through a single port and sends debugging commands, the OpenOCD is a debugging agent program compiled after adding assembly code, FLASH driver and configuration file, and controls the target board through the JTAG interface, the PC and the target board are connected through the JTAG interface, and the target board returns debugging information to the OpenOCD in the PC through the JTAG interface.
[0041] like Figure 2 As shown, the embodiment of the present invention provides an embedded chip FLASH program burning method based on OpenOCD, and its basic process is as follows:
[0042] First, according to the ARM assembly instructions, write assembly code to start the on-chip applet that can be executed on RAM, and implement key functions in the FLASH driver, such as erase function, read function, write function and verify function; compile and generate the OpenOCD debugging agent by modifying the OpenOCD compilation rule file. The above-mentioned on-chip applet is written to RAM and started through the FLASH driver. Next, configure the OpenOCD configuration file, set the OpenOCD, JTAG, chip, and chip FLASH initialization parameters, and start the OpenOCD debugging agent to connect to the chip. Then, initialize the Telnet debugging command line, connect to OpenOCD through a single port and issue debugging commands. After that, execute the burning instruction, first erase the FLASH, write the on-chip applet to the chip RAM destination address, and then start the on-chip applet to move the burning data written to RAM to FALSH. Finally, verify the correctness of the data burning.
[0043] like Figure 3 As shown, the functional modules and state machines of the on-chip applet in the embodiment of the present invention are as follows:
[0044] The on-chip applet is implemented by ARM assembly code. It can use ARM general registers r0-r7 to store different runtime data, and can move the burning data written to RAM to FLASH. The "start" function module performs code initialization, sets the initial conditions and enters the waiting state. The "write_fifo" function module is a loop, which loads the write pointer wp through register r6 and the read pointer rp through register r5. Compare the values of r5 and r6. If they are equal, it means that there is no new data to write at present, and continue to wait in "write_fifo"; if they are not equal, it means that there is new data to write at present, and read the data from the address pointed to by pointer rp and write it to the target address. At the same time, it is necessary to check whether rp exceeds the range of the work area. If it does not exceed the end address of the work area, it will directly jump to "no_warp" to continue execution; if it exceeds or reaches the end of the work area, rp will be reset to the starting address of the work area and the work area will be used again. The "no_warp" function module is a wrap-around module that processes the position of the read pointer rp in the work area to ensure that rp does not exceed the boundary of the work area. If rp moves beyond the end of the work area, no_wrap will reset rp to the beginning of the work area to achieve wrap-around. The "special_set" function module is a module that does special processing. The "busy" busy wait module reads the current status from the status register of the flash controller and checks the busy status BSY bit. When the busy status is 1, the jump instruction will jump the execution flow back to the busy label, forming a loop until the BSY bit is cleared. The "error" function module handles errors detected during the writing process, and the read pointer rp is set to 0. The "exit" function module ends the program execution, returns the final status through register r0, and executes the breakpoint instruction to indicate that the program is executing normally. The general registers r0-r7 of the ARM chip can be used to store data of the state machine in different operating states. rp is a pointer to the location where the data is read, and wp is a pointer to the location where the data is written.
[0045] In summary, the present invention uses the debugging agent OpenOCD to realize an efficient, reliable, and fast-burning method for FLASH burning of embedded chips. The method of the present invention can be independent of dedicated emulator hardware and embedded development software. Through customized development of OpenOCD FLASH driver and configuration files, the FLASH module of the embedded chip is directly programmed, debugged, and verified through a standard debugging port. The method has fast burning speed, high efficiency, low cost, good portability, and strong portability.
[0046] The above description is only a description of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any changes or modifications made by a person skilled in the art in the field of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. A chip FLASH program burning method based on OpenOCD, characterized in that: The steps include: Step S1: Implementing the on-chip applet for transferring data and starting the FLASH driver in OpenOCD, and compiling and generating the OpenOCD debugging agent program according to the compilation rule file; Step S2: Configure the OpenOCD configuration file, connect to the chip through the OpenOCD debugging agent program, and issue the FLASH debugging command through the Telnet debugging command line; Step S3: OpenOCD parses the FLASH burning command, writes the on-chip applet into the RAM address of the embedded chip and starts it by running the FLASH driver, and the on-chip applet moves the burning data written by OpenOCD into the RAM to the FLASH, completing the burning; The on-chip applet includes: The start function module performs code initialization, sets initial conditions and enters the waiting state; The write_fifo function module is a loop. It loads the write pointer wp through the ARM general register r6 and the read pointer rp through the ARM general register r5. By comparing the values of the ARM general register r5 and the ARM general register r6, if they are equal, it means that there is no new data to be written at present, and continue to wait in the write_fifo function module; if they are not equal, it means that there is new data to be written at present, and the data is read from the address pointed by the read pointer rp and written to the target address; at the same time, it is necessary to check whether the read pointer rp exceeds the range of the working area. If it does not exceed the end address of the working area, it will directly jump to the no_warp function module to continue execution; if it exceeds or reaches the end of the working area, the read pointer rp is reset to the starting address of the working area, and the working area is restarted; The no_warp function module processes the position of the read pointer rp in the work area for wrapping processing, ensuring that the read pointer rp does not exceed the boundary of the work area. If the read pointer rp moves beyond the end of the work area, the no_wrap function module resets the read pointer rp to the beginning of the work area, thereby achieving wrapping; special_set function module is a module for special processing; The busy waiting function module reads the current status from the status register of the flash memory controller and checks the busy status BSY bit. When the busy status is 1, the jump instruction will jump the execution flow back to the busy label, forming a loop until the BSY bit is cleared. The error function module is used to handle errors detected during the writing process, and the read pointer rp is set to 0; The exit function module ends the program execution, returns to the final state through the ARM general register r0, and executes the breakpoint instruction to indicate that the program is executing normally.
2. A chip FLASH program burning method based on OpenOCD as claimed in claim 1, characterized in that, The step S1 specifically includes the following steps: Step S1-1: write assembly code according to ARM assembly instructions to start the on-chip applet that can be executed on RAM, that is, write RAM in the write function and start it. The function of the on-chip applet is used to move data from RAM to FLASH; Step S1-2: Implementing the erase function, read function, write function and verify function in the FLASH driver; Step S1-3: modify the OpenOCD compilation rule file, and compile and generate the OpenOCD debugging agent program.
3. A chip FLASH program burning method based on OpenOCD as claimed in claim 1, characterized in that, The step S2 specifically includes the following steps: Step S2-1: Configure OpenOCD configuration file; Step S2-2: Start the OpenOCD debugging agent program to connect to the chip; Step S2-3: Initialize the Telnet debugging command line to connect to OpenOCD through a single port; Step S2-4: Receive FLASH debugging command.
4. A chip FLASH program burning method based on OpenOCD as claimed in claim 3, characterized in that, The configuration of the OpenOCD configuration file includes: initializing OpenOCD, initializing JTAG, initializing the chip, and initializing the chip FLASH driver.
5. A chip FLASH program burning method based on OpenOCD as claimed in claim 1, characterized in that: The step S3 specifically includes the following steps: Step S3-1: Parse the FLASH programming instruction through OpenOCD; Step S3-2: Erase FLASH address; Step S3-3: write the on-chip applet into the chip RAM destination address; Step S3-4: Start the on-chip applet and start moving the burning data written by OpenOCD into RAM to FLASH; Step S3-5: Verify the correctness of the programming.
6. A chip FLASH program burning method based on OpenOCD as claimed in claim 1, characterized in that: The on-chip applet also includes: being implemented by ARM assembly code, being able to use ARM general registers r0-r7 to store data in different operating states, and being able to move the burning data written into RAM to FLASH.
7. An embedded chip FLASH program burning system based on OpenOCD, using a chip FLASH program burning method based on OpenOCD as described in any one of claims 1 to 6, characterized in that: include: A PC, a target board and a JTAG interface; the PC is installed with a Telnet debugging command line and OpenOCD, the Telnet debugging command line is connected to OpenOCD through a single port and sends debugging commands, the OpenOCD is a debugging agent program compiled after adding assembly code, FLASH driver and configuration files, and controls the target board through the JTAG interface, the PC and the target board are connected through the JTAG interface, and the target board returns debugging information to the OpenOCD in the PC through the JTAG interface.
