Developing ARM-based embedded systems with GNU tools

At present, ARM's 32-bit RISC processor has become a embedded solution for mobile communication, handheld computing, multimedia digital consumption, etc. due to its low power consumption, low cost, strong function and unique 16/32-bit dual instruction set. The RISC standard has a market share of more than 75%. Many companies have launched their own ARM core-based processor products, and more and more developers have begun to develop for the ARM platform. Developers often need to purchase a development board from a chip vendor or a third party, as well as a development software such as a C compiler or a development environment that integrates a real-time operating system. The price of the development board ranges from hundreds to thousands of dollars, while the price of compilers and real-time operating systems is thousands to tens of thousands of dollars. In this way, in the early stage of development, the investment in software and hardware needs tens of thousands of dollars, which is undoubtedly too expensive for most developers in China.

Fortunately, the free software promoted by GNU brings the gospel to developers. In 1984, it was designed to develop a complete Unix-like and completely free operating system and companion tool: the GNU system (pronounced "guh-NEW"). GNU's operating system and development tools are free and follow the GNU General Public License (GPL) protocol, and anyone can get all the source code online. For more information on the GNU and the Public License Agreement, the reader can refer to the Chinese introduction on the GNU website: http://.

In addition to the well-known Linux operating system, GNU software also includes compilers (gcc, g++), binary conversion tools (objdump, objcopy), debugging tools (gdb, gdbserver, kgdb) and development libraries based on different hardware platforms. The main disadvantage of GNU development tools is the use of the command line, which is difficult for users to master and use. It is not as easy to use as a Windows-based development tool. However, the complexity of the GNU tool is due to its closer proximity to the underlying compiler and operating system and provides greater flexibility. Once you have learned and mastered the relevant tools, you will understand the basics of system design and lay the foundation for future development work. GNU development tools are free and follow the GPL and are available to anyone online. The author participated in the development of an embedded Linux system based on the ARM platform, using the MC928MX1 of the Motorola Dragon Ball series. From test code, bootloader, embedded Linux porting, application, and graphical interface, you can use GNU tools for development without the need for additional investment in development tools. The development methods described in this article are equally applicable to ARM-based products from other companies.

1 hardware platform

The MC928MX1 (hereafter referred to as MX1) is Motorola's first MCU based on the ARM core, mainly for high-end embedded applications. The ARM920T core is used internally, and integrated controllers such as SDRAM/Flash, LCD, USB, Bluetooth, multimedia flash card (MMC), and CMOS camera are integrated. For more information on MX1, interested readers can refer to http:// /semiconductors/. The smallest system developed as an application must include RAM (program run space), Flash (store target code), and serial interface (for debugging and downloading programs). MX1 provides 6 chip select terminals (CS0 "CS5", built-in SDRAM controller, data width 32 bits. In the author's system, 2 8M% 26; #215; 16-bit SDRAM and 2 4M% 26; #215; 16-bit synchronous flash memory, respectively access the lower 16 bits and upper 16 bits of the data line, as shown in Figure 1.

In Figure 1, the SDRAM chip selects the terminal CS2, the Flash chip selects the terminal CS3, and the rest is the SDRAM/Flash control signal. The minimum system also includes at least one serial interface, which can be used with the UART controller built into the MX1.

2 Bootstrap mode

Currently, many embedded processors provide bootstrapping mode (Bootstrap) for users to write boot code. Bootstrap mode utilizes a bootloader that cures inside the chip. When the processor is reset, if a signal is applied to a particular pin, the processor will execute the program in the firmware ROM after reset. For example, the MX1 provides four reset pins that can be used to boot the system from different chip selects at different levels when reset. The program in the boot ROM completes the initialization of the serial port and then waits for the user to write the user code from the serial port. What is acceptable for boot mode is a specially formatted text file that includes data and the address to be written/read. For the code format of the bootstrap mode, refer to the manual of the relevant chip. The Motorola website also provides a number of gadgets to help developers convert files in other formats into a bootstrapping mode format. The program downloaded through the bootstrap mode is usually a program that communicates with the host computer software (such as HyperTerminal) to complete the operation of receiving data and writing to Flash. The data written can be the user's own application, data, or the kernel of the operating system. Bootstraps downloaded through bootstrap mode can also be developed using GNU tools.

3 GNU compilers and development tools

Compilation tools provided by GNU include assembler as, C compiler gcc, C++ compiler g++, connector ld, and binary conversion tool objcopy. The tools based on the ARM platform are arm-linux-as, arm-linux-gcc, arm-linux-g++, arm-linux-ld and arm-linux-objcopy. All of GNU's development tools are available for download from ARM, and ARM-based tools are available. The GNU compiler is very powerful, with hundreds of operating options, which is why these tools give beginners a headache. However, only a limited number of actual developments are required, and most of them can use the default options. The development process of GNU tools is as follows: write C, C++ language or assembly source program, generate object files with gcc or g++, write connection script files, use the connector to generate final object files (elf format), and generate downloadable files with binary conversion tools. Binary code. The GNU tools are all running under Linux. The developer needs a PC running Linux as the host computer. Due to space limitations, the development process of the entire embedded operating system cannot be fully introduced. The boot process downloaded in the bootstrapping mode mentioned in the second section is taken as an example to illustrate the development process. For large systems like Linux, the basic development process is the same.

The bootloader will be downloaded to MX1's on-chip RAM via bootstrapping mode, starting at address 0x00300000 and executing. After the serial port and SDRAM are initialized, the bootloader will wait to receive the application or operating system kernel and place the received data in SDRAM. After the data is received, the boot program writes the data in the SDRAM to the Flash, and the next time you can boot the system directly from the Flash. Since the kernel of the operating system is relatively large, such as Linux has more than 1 MB, the download process must consider error correction. Therefore, the receiving part adopts the Xmode protocol, and the file can be sent by the Xmode transmission mode of the HyperTerminal under Windows.

(1) Write C, C++ language or assembler source program

Usually the assembler source is used for the most basic initialization of the system, such as initializing the stack pointer, setting the page table, operating the ARM coprocessor, and so on. After the initialization is complete, you can jump to the C code execution. It should be noted that the GNU assembler follows the AT%26;amp;T assembly syntax, and the reader can download the specification from the GNU site(). The default entry for the assembler is the start label, and the user can also specify other entry points in the connection script file with the ENTRY flag (see the description of the connection script below).

(2) Generate target files with gcc or g++

If the application includes multiple files, you need to compile separately and finally connect them with connectors. For example, the author's boot program includes three files: init.s (assembly code, initialization hardware) xmrecever.c (communication module, using Xmode protocol) and flash.c (flash erase module). Use the following command to generate the target file: arm-linux-gcc-c-O2-o init.o init.s arm-linux-gcc-c-O2-o xmrecever.o xmrecever.c arm-linux-gcc-c- O2-o flash.o flash.c where the -c command indicates that only the target code is generated and no connection is made; the -o command indicates the name of the target file; -O2 indicates that the second-level optimization is used, and the optimized code can be used to make the generated code shorter. , running faster. If your project contains many files, you will need to write a makefile. For the contents of the makefile, please refer to the relevant materials for interested readers.

(3) Write a connection script file

The compiler such as gcc has a built-in default connection script. If the default script is used, the generated object code requires the operating system to load and run. In order to run directly on an embedded system, you need to write your own connection script file. To write a connection script, you must first understand the format of the target file. The target file generated by the GNU compiler defaults to the elf format. The elf file consists of several segments (secTIon). If not specified, the object code generated by the C source program contains the following segments: .text (text segment) contains the program instruction code; .data (data segment) contains fixed data. , such as constants, strings; .bss (uninitialized data segments) contain uninitialized variables, arrays, and so on. The object code generated by the C++ source program also includes .fini (destructor code) and .init (constructor code). For the elf file format, readers can refer to the relevant materials. The task of the connector is to connect the .text, .data, and .bss segments of multiple object files together, and the connection script file tells the connector where to start placing the segments. For example, the author's bootstrap connection file link.lds is: ENTRY(begin) SECTION { . =0x00300000; .text : { *(.text) } .data: { *(.data) } .bss: { *(.bss) } }

Where ENTRY(begin) indicates that the entry point of the program is a begin label; =0x00300000 indicates that the starting address of the target code is 0x00300000, which is the on-chip RAM of MX1; .text : { *(.text) } indicates the code segment from which all target files are placed starting from 0x00300000, followed by .data: { *(.data) } indicates that the data segment starts at the end of the code segment and then the .bss segment.

(4) use the connector to generate the final target file

With the connection script file, the following command can generate the final object file: arm-linux-ld-nostadlib-o bootstrap.elf-T link.lds init.o xmrecever.o flash.o where ostadlib means no connection to the system The library, but directly from the begin entry; -o indicates the name of the target file; -T indicates the connection script file to be used; and finally the list of target files to be connected.

(5) generate binary code

The elf file generated by the connection cannot be directly downloaded and executed. The final binary file can be generated by the objcopy tool: arm-linux-objcopy-O binary bootstrap.elf bootstrap.bin where -Obinary is specified to be generated as a binary format file. Objcopy can also generate files in S format by simply changing the parameters to -O srec. If you want to disassemble the generated object code, you can also use the objdump tool: arm-linux-objdump-D bootstrap.elf At this point, the generated object file can be directly written to Flash. If you want to download through bootstrapping mode, you also need to convert to the bootstrapping mode file format, the relevant conversion tool can be found on the Motorola website.

With the GNU tools in place, developers can develop or port programs for C or C++ code. Users can develop simple applications directly without the need for an operating system. But for more complex applications, the operating system is essential. Currently popular source code open operating systems such as Linux, μC/OS can be compiled with GNU tools. ARM's Linux has many mature versions, can support ARM720, ARM920, ARM1020 and other processors, readers can get the latest information from or on. The processor-related code during the Linux migration process is placed in the arch/arm directory. For the kernel, what the user needs to do is set the memory image of the system, the RAM start address, the I/O address space, and the virtual I/O address space. See the arch/arm/mach-integrator/arch.c file. In addition to the kernel, users also need to build a variety of drivers for their systems.

4 debugging tools

The GNU debugging tools under Linux are mainly gdb, gdbserver and kgdb. Among them, gdb and gdbserver can complete the remote debugging of the application under Linux on the target board. Gdbserver is a small application running on the target board to monitor the running of the debugged process and communicate with gdb on the host computer through the serial port. Developers can use the gdb input command of the host computer to control the running of the process on the target board and view the contents of the memory and registers. The gdb5.1.1 and later versions have added support for the ARM processor. Adding the -target==arm parameter during initialization can directly generate gdbserver based on the ARM platform. The gdb tool can be downloaded from ftp://ftp.gnu.org/pub/gnu /gdb/.

For the debugging of the Linux kernel, you can use the kgdb tool. You also need to communicate with the gdb on the host computer through the serial port to debug the Linux kernel of the target board. Due to space limitations, interested readers can learn more about how to use it from http://oss.sgi.com/projects/kgdb/.

Conclusion

This article takes a specific example as an example to introduce the common functions in the GNU tool. In fact, the functions of GNU tools are far more than these. Further operations include: software optimization for different processors, different algorithms, efficient inline assembly, and large project management functions. I believe that GNU can be the choice of more and more developers.

UK Series Extension Sockets

Trailing Lead Socket,Extension Wire Socket,Two Pin Plug Extension,Heavy Duty Extension Socket

Heikki Technology Co., Ltd. , https://www.heikkipower.com