Developing ARM-based embedded systems with GNU tools

Publisher:vettykattyLatest update time:2012-09-26 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This article introduces how to use GNU tools to develop ARM -based embedded systems, as well as specific methods for using compilers, connectors and debugging tools, to provide a low-cost development method for the majority of embedded system developers. At present, ARM's 32-bit RISC processors, with their low core power consumption, low cost, powerful functions, and unique 16/32-bit dual instruction sets, have become the RISC standard for embedded solutions such as mobile communications, handheld computing, and multimedia digital consumption, with a market share of more than 75%. Many companies have launched their own processor products based on the ARM core, and more and more developers have begun to develop for the ARM platform. Usually, developers need to purchase development boards provided by chip manufacturers or third parties, and also purchase development software, such as C compilers or development environments integrated with real-time operating systems. The price of development boards ranges from hundreds to thousands of dollars, while the price of compilers and real-time operating systems is easily thousands to tens of thousands of dollars. In this way, in the early stages of development, the investment in software and hardware requires tens of thousands of dollars, which is undoubtedly too expensive for most domestic developers. Fortunately, the free software advocated by GNU has brought good news to developers. In 1984, the goal was to develop a complete operating system and supporting tools similar to Unix that were completely free: the GNU system (pronounced "guh-NEW"). GNU's operating system and development tools are free and follow the GNU General Public License (GPL) agreement. Anyone can obtain all the source code from the Internet. For detailed information about GNU and the public license agreement, readers can refer to the Chinese introduction of the GNU website: http://www.gnu.org/home.cn.html. In addition to the well-known Linux operating system, GNU's 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 that they use command lines, which are difficult for users to master and use, and are not as easy to use as development tools based on Windows systems. However, the complexity of GNU tools is due to its closer proximity to the bottom layer of compilers and operating systems and greater flexibility. Once you learn and master 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 agreement. Anyone can get them from the Internet. The author participated in the development of an embedded Linux system based on the ARM platform, using the Motorola Dragon Ball series MC928MX1. From test code, boot program, embedded Linux porting, application program, and graphical interface, GNU tools can be used for development without additional investment in development tools. The development method introduced in this article is also applicable to ARM-based products of other companies. 1 Hardware Platform MC928MX1 (hereinafter referred to as MX1) is Motorola's first MCU based on the ARM core , mainly for high-end embedded applications. It uses the ARM920T core internally and integrates SDRAM/Flash, LCD, USB, Bluetooth (bluetooth), Multimedia Flash Card ( MMC ), CMOS camera and other controllers. For detailed information about MX1, interested readers can refer to http://www.motorola.com.cn/semiconductors/. As the minimum system for application development, it must include RAM (program running space), Flash (storing target code) and serial interface (for debugging and downloading programs). MX1 provides 6 chip select terminals (CS0~CS5), built-in SDRAM controller, and data width of 32 bits. In the author's system, two 8M×16-bit SDRAMs and two 4M×16-bit synchronous Flash memories are used, which are connected to the lower 16 bits and higher 16 bits of the data line respectively, as shown in Figure 1. In Figure 1, SDRAM is connected to the chip select terminal CS2, Flash is connected to the chip select terminal CS3, and the rest are control signals of SDRAM/Flash. The minimum system also includes at least one serial interface, which can use the built-in UART controller of MX1, which is omitted in the figure.











2 Bootstrap mode

Currently, many embedded processors provide a bootstrap mode for users to write boot code. The bootstrap mode uses a boot program that is fixed inside the chip. When the processor is reset, if a signal is added to a specific pin, the processor will execute the program in the fixed ROM after reset. For example, MX1 provides 4 reset pins. Different combinations of pin levels during reset can start the system from different chip select ends. The program in the bootstrap ROM completes the initialization of the serial port and then waits for the user to write the user code from the serial port. The bootstrap mode can accept a text file in a special format, including data and the address to be written/read. For the code format of the bootstrap mode, please refer to the manual of the relevant chip. Motorola's website also provides many small tools to help developers convert files in other formats into the bootstrap mode format. The program downloaded through the bootstrap mode is usually a program that communicates with the host computer software (such as the hyperterminal) to complete the operation of receiving data and writing it to the Flash. The data written can be the user's own application, data or the kernel of the operating system. The bootstrap program downloaded through the bootstrap mode can also be developed with GNU tools.

3 GNU compiler and development tools

The compilation tools provided by GNU include assembler as, C compiler gcc, C++ compiler g++, linker ld and binary conversion tool objcopy. The tools based on ARM platform are arm-linux-as, arm-linux-gcc, arm-linux-g++, arm -linux-ld and arm-linux-objcopy. All GNU development tools can be downloaded from www.gnu.org, and ARM-based tools can be obtained from www.uclinux.org. GNU compiler is very powerful, with hundreds of operation options, which is why such tools give beginners a headache. However, only a limited number of them are needed in actual development, 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, use gcc or g++ to generate target files, write connection script files, use the linker to generate the final target file (elf format), and use the binary conversion tool to generate downloadable binary code. GNU tools all run under Linux, and developers need a PC running Linux as the host computer. Due to space limitations, the entire embedded operating system development process cannot be fully introduced. The development process will be explained using the boot program downloaded through the boot mode mentioned in Section 2 as an example. For large systems such as Linux, the basic development process is the same.

The boot program will be downloaded to the MX1's on-chip RAM through the boot mode, starting from address 0x00300000 and executing. After completing the initialization of the serial port and SDRAM, the boot program will wait to receive the application or operating system kernel and place the received data in the SDRAM. After the data is received, the boot program writes the data in the SDRAM to the Flash, and the system can be directly booted from the Flash next time. Since the operating system kernel is relatively large, such as Linux, which is more than 1 MB, error correction must be considered during the download process. Therefore, the receiving part uses the Xmode protocol, and the file can be sent using the Xmode sending method of the Windows HyperTerminal. [page]

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

Usually, the assembly source program is used for the most basic initialization of the system, such as initializing the stack pointer, setting the page table, and operating the ARM coprocessor. After the initialization is completed, you can jump to the C code for execution. It should be noted that the GNU assembler follows AT&T's assembly syntax. Readers can download the relevant specifications from the GNU website (www.gnu.org). The default entry point of the assembler is the start label. Users can also use the ENTRY flag in the linker script file to specify other entry points (see the description of the linker script below).

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

If the application includes multiple files, they need to be compiled separately and finally connected with a connector. For example, the author's boot program includes 3 files: init.s (assembly code, initialization hardware), xmrecever.c (communication module, using Xmode protocol) and flash.c (Flash erase module).

Use the following commands to generate the target files respectively:

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

The -c command means only generating the target code without linking; the -o command specifies the name of the target file; -O2 means using secondary optimization, which can make the generated code shorter and run faster. If the project contains many files, you need to write a makefile. For the content of makefile, interested readers are welcome to refer to relevant materials.

(3) Write a connection script file

. Compilers such as gcc have built-in default connection scripts. If the default script is used, the generated target code needs the operating system to load and run. In order to run directly on the embedded system, you need to write your own connection script file. To write a connection script, you must first have a certain understanding of the format of the target file. The target file generated by the GNU compiler is in elf format by default. The elf file consists of several sections. If not specified, the target code generated by the C source program includes the following sections: .text (text section) contains the program's instruction code; .data (data section) contains fixed data, such as constants and strings; .bss (uninitialized data section) contains uninitialized variables, arrays, etc. The target 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 relevant materials. The connector's task is to connect the .text, .data, and .bss sections of multiple target files together, and the linker script file tells the connector where to start placing these sections. For example, the author's boot program connection file link.lds is:

ENTRY(begin)

SECTION

{ .=0x00300000;

.text : { *(.text) }

.data: { *(.data) }

.bss: { *(.bss) }

}

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

(4) Generate the final target file using the linker

With the linker script file, the following command can generate the final target file:

arm-linux-ld-nostadlib-o bootstrap.elf-T link.lds init.o xmrecever.o flash.o

Among them, ostadlib means not to connect to the system runtime library, but directly from the begin entry; -o specifies the name of the target file; -T specifies the connection script file to be used; and finally, there is a list of target files to be connected.

(5) Generate binary code

The elf file generated by the connection cannot be downloaded and executed directly. The final binary file can be generated by the objcopy tool:

arm-linux-objcopy-O binary bootstrap.elf bootstrap.bin,

where -Obinary specifies that the file is generated in binary format. Objcopy can also generate S format files by replacing the parameter with -O srec. If you want to disassemble the generated target code, you can also use the objdump tool:

arm-linux-objdump-D bootstrap.elf.

At this point, the generated target file can be directly written to the Flash and run. If you want to download it in boot mode, you also need to convert it to the file format of the boot mode. The relevant conversion tools can be found on Motorola's website.

After mastering the GNU tools, developers can develop or port programs in C or C++ code. Users can directly develop simple applications without an operating system. But for more complex applications, an operating system is indispensable. Currently popular operating systems with open source code such as Linux and μC/OS can be compiled with GNU tools. ARM's Linux has many mature versions that can support multiple processors such as ARM720, ARM920, ARM1020, etc. Readers can get the latest information from www.uclinux.org or www.armdevzone.com. The processor-related codes in the Linux porting process are all placed in the arch/arm directory. For the kernel, what users need to do is to set the memory image, RAM start address, I/O address space and virtual I/O address space of their own system, see the arch/arm/mach-integrator/arch.c file. In addition to the kernel, users also need to compile various drivers for their own 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 Linux applications on the target board. gdbserver is a very small application that runs on the target board, can monitor the operation of the debugged process, and communicate with gdb on the host computer through the serial port. Developers can input commands through the gdb of the host computer to control the running of the process on the target board and view the contents of the memory and registers. Versions after gdb5.1.1 have added support for ARM processors. Adding the -target==arm parameter during initialization can directly generate a gdbserver based on the ARM platform. The gdb tool can be downloaded from ftp://ftp.gnu.org/pub/gnu/gdb/.

For debugging the Linux kernel, the kgdb tool can be used. It also needs 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 about the specific usage methods from http://oss.sgi.com/projects/kgdb/.

Conclusion

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

Reference address:Developing ARM-based embedded systems with GNU tools

Previous article:Debugging Technology for 32-bit ARM Embedded Processors
Next article:Application and selection of 32-bit RISC CPU ARM chips

Recommended ReadingLatest update time:2024-11-16 18:02

Analysis and Design of BootLoader for ARM-Linux Embedded System
0 Preface The boot loader of an embedded system is composed of the Boot Loader and the Boot code (optional) solidified in the firmware. Its role and function are like a ROM chip program BIOS (basic input output system) solidified on the motherboard of the computer. However, it is generally not configured with a firmwa
[Microcontroller]
Analysis and Design of BootLoader for ARM-Linux Embedded System
ARM core pipeline - ARM7, ARM9E, ARM11, Cortex-A series processors
This article mainly introduces the pipeline of ARM7, ARM9E, ARM11 and Cortex-A series processors, from instruction fetch, instruction decoding to each stage of instruction execution. Refer to ARM's website http://www.arm.com/about/company-profile/index.php. ARM was founded in 1990 and has sold more than 15 billion chi
[Microcontroller]
Overview of the instruction set of ARM microprocessors (Part 2) - Detailed notes on ARM application system development
A jump instruction         Jump instructions are used to implement program flow jumps. There are two ways to implement program flow jumps in ARM programs:                 — Use dedicated jump instructions.                 — Directly write the jump address value to the program counter PC.         The jump instructions
[Microcontroller]
ARM development board system transplantation---rootfs production
The previous two articles introduced the bootloader and kernel running on the mini2440 development board. At this point, the system is actually stuck in a "dead" state after startup - the root file system cannot be mounted. Here we will introduce how to make a root file system and mount it to the kernel --- that is,
[Microcontroller]
ARM development board system transplantation---rootfs production
arm-linux-gcc and Makefile
Makefile file writing all:     arm-linux-gcc -c -o led_on.o led_on.s     arm-linux-ld -Ttext 0 led_on.o -o led_on.elf //arm-linux-ld is used to link multiple target files and library files into executable files. The -T option is used to specify the starting address of the code segment, data segment, and bss segment.
[Microcontroller]
ARM development - nfs boot linux
Setting Environment Variables Start the uboot we burned and press Enter to enter set ipaddr "172.16.3.222" //Set the IP address of the board set severip "172.16.3.94" //Set the host's IP address set gatewayip "172.16.3.254" //Set gateway set bootargs "root =/dev/nfs nfs =172.16.3.94:/home/user/roots ip =172.16.3.222
[Microcontroller]
Keil ARM software Debug review
The program uses the assembly code that was successfully compiled before. Then use the following script to debug the script /*** Use Configuration !disalbe! Wizard in Context Menu ***/  /*Name: DebugINRam.ini*/    FUNC void Setup (void)  {      // o Program Entry Point, .AXF File download Address      PC = 0x0
[Microcontroller]
Learn ARM development(17)
Because all embedded systems use interrupts, how does my S3C44B0 interrupt process? Then I need to understand the whole process. To understand it in depth, the best way is to write a program and then debug it continuously. Before this program, you must first have a deep understanding of ARM's interrupt mode and know
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号