AT91RM9200 bootloader creation (I) Creating a cross-compilation tool chain

Publisher:创意航海Latest update time:2016-06-17 Source: eefocusKeywords:AT91RM9200 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Written in front:

    This series of articles will describe in detail the process of establishing the AT91RM9200 boot program, including the establishment of a cross-compilation tool chain, the compilation, installation and use of gdb+gdbserver, the installation and use of tftp, NFS, the use of hyperterminal or minicom, the compilation and upgrade of the kernel, the transplantation of U-Boot, the establishment and production of Ramdisk and root file systems, the compilation and application of busybox, etc., so as to reproduce the complete development process. In the process of writing this document, I referred to a lot of information. I would like to thank the Internet, all the communities, and colleagues in the forum for their selfless help. Special thanks to Mr. Lu Yu, who helped me successfully transplant U-Boot on AT91RM92001.1.4. I have come all the way from not knowing anything, and I have recorded the development process in detail in the process. I wrote this series of articles from a beginner's perspective so that other beginners can get some help and avoid some detours. This series of articles mainly describes the development process and practical applications, and cannot explain some principles very well, so when you read this article, it is best to refer to other materials to form a complete knowledge chain. I wish you a pleasant journey.

Development Environment

Software Environment

              Host machine: Redhat9.0, virtual machine vmware5.5.1

U-Boot 1.1.4, busybox1.2.2.1

Hardware Environment

              CPU:AT91RM9200,180MHz(200MIPS)

              Memory:32M   SDRAM(MT48LC8M16A2)

                            64Mbits Flash (SST39VF6401B)

              USB interface: USB-Host USB-Device

           Network interfaces: 10/100M    DM9161E

              DBGU serial debug interface

            JTAG interface

 

Transplantation process

virtual machine

Regarding the installation and use of virtual machines, I will not introduce them here. It is very convenient to use, and there is a lot of information on the Internet. You can check it yourself. We use5.5.1Of course, you can use the latest version.

Build a cross-compilation toolchain.

The purpose of the cross-compilation tool chain is to compile, link, process and debug programs under one platform architecture (such as X86 PC) under another platform architecture (such as ARM), so that the compiled programs can run on another platform.

The tool chain software used by Linux is: Binutils, gcc, glibc, gdb.

Among them, binutils is a binary program processing tool. gcc is a compiler. glibc is a function library file software package for application programming. gdb is a debugging tool.

Compiling a cross-compilation toolchain is a very troublesome and tedious task. If you compile one by one, you may encounter various troubles. Fortunately, someone has made a set of scripts that can easily generate the cross-compilation toolchain you need. The script we use is crosstool. For more information, you can visit http://kegel.com/crosstool/ , where you can download its scripts, patches and documents.

This article uses the i686 platform and the virtual machine vmware5.5.1, redhat9.0 to build the arm cross-compilation tool chain.

We use crosstool0.42 as the script for compiling the cross-compilation toolchain. For detailed usage instructions, please read the document crosstool-how to on the website.

[zzl@localhost] tar -xzvf crosstool-0.42.tar.gz

[zzl@localhost]cd crosstool-0.42

We can see that there are many .sh scripts and .dat configuration files in the directory. Each supported CPU has its corresponding script. For example, we choose demo-arm-softfloat.sh to build a cross-compilation tool chain for arm that supports soft floating point. There are three important variables we need to remember:
             TARBALLS_DIR=$HOME/downloads  

RESULT_TOP=/opt/crosstool

GCC_LANGUAGES="c,c++"

The first line indicates the directory where we place the source code package. My home directory is /home/zzl. The second line indicates that the cross-compilation tool chain we generated is in /opt/crosstool. The third line indicates that our cross-compilation tool chain supports C and C++ languages.

We need the following compressed packages:
gcc-3.4.1.tar.gz glibc-2.3.3.tar.gz linux-2.6.17
binutils-2.15.tar.gz glibc-linuxthreads-2.3.3.tar.gz

So, your first task is to download these source code packages and place them under /home/zzl/downloads, making sure that the owner of these packages is the current user instead of the root user.

Since our future kernel version is2.6.17, so we also need to download the kernel package of linux2.6.17 and put it in /home/zzl/downloads/.

The configuration we chose is: demo-arm-softfloat.sh, and its content is as follows:

                #!/bin/sh

set -ex

TARBALLS_DIR=$HOME/downloads

RESULT_TOP=/opt/crosstool

export TARBALLS_DIR RESULT_TOP

GCC_LANGUAGES="c,c++"

export GCC_LANGUAGES

 

# Really, you should do the mkdir before running this,

# and chown /opt/crosstool to yourself so you don't need to run as root.

mkdir -p $RESULT_TOP

 

# Build the toolchain. Takes a couple hours and a couple gigabytes.

 

#eval `cat arm-softfloat.dat gcc-3.3.3-glibc-2.3.2.dat` sh all.sh --notest

#eval `cat arm-softfloat.dat gcc-3.4.0-glibc-2.3.2.dat` sh all.sh --notest

 eval `cat arm-softfloat.dat gcc-3.4.1-glibc-2.3.3.dat` sh all.sh --notest

#eval `cat arm-softfloat.dat gcc-3.4.1-glibc-20040827.dat` sh all.sh --notest

 

echo Done.

From this line eval `cat arm-softfloat.dat gcc-3.4.1-glibc-2.3.3.dat` sh all.sh --notest

It can be seen that our gcc version uses3.4.1, glibc version is 2.3.3.
       Let's look at the file gcc-3.4.1-glibc-2.3.3.dat

BINUTILS_DIR=binutils-2.15

GCC_DIR=gcc-3.4.1

GLIBC_DIR=glibc-2.3.3

LINUX_DIR=linux-2.6.8

GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.3

Since we use Linux-2.6.17Therefore, we need to change linux-2.6.8 to linux-2.6.17. Otherwise, the script will not be able to find the Linux source code package when it is decompressed.

Create our target build directory

[zzl@localhost]sudo mkdir /opt/crosstool

[zzl@localhost]sudo chown zzl /opt/crosstool

 

Execute our configuration file arm-softfloat.sh

[zzl@localhost]sh demo-arm-softfloat.sh

    Please note that you cannot run this configuration file as root. crosstool-0.42, /opt/crosstool is owned by a non-root user.

If everything goes well, after a period of waiting, you will get a new directory: (If it does not go well and you still cannot find the cause of the error, I suggest you reinstall the redhat9.0 operating system and then follow the previous steps. :))

/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu

The cross-compilation tool is in the bin/ directory

[zzl@localhost]ls –l /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/bin

Total usage 29184

-rwxr-xr-x 1 zzl zzl 1806212 December 29 09:02 arm-softfloat-linux-gnu-addr2line

-rwxr-xr-x 2 zzl zzl 1864030 December 29 09:02 arm-softfloat-linux-gnu-ar

-rwxr-xr-x 2 zzl zzl 3248953 December 29 09:02 arm-softfloat-linux-gnu-as

-rwxr-xr-x 2 zzl zzl 287996 December 29 09:43 arm-softfloat-linux-gnu-c++

-rwxr-xr-x 1 zzl zzl 1761855 December 29 09:02 arm-softfloat-linux-gnu-c++filt

-rwxr-xr-x 1 zzl zzl 287111 December 29 09:43 arm-softfloat-linux-gnu-cpp

-rwxr-xr-x 2 zzl zzl 287996 December 29 09:43 arm-softfloat-linux-gnu-g++

-rwxr-xr-x 2 zzl zzl 285852 December 29 09:43 arm-softfloat-linux-gnu-gcc

-rwxr-xr-x 2 zzl zzl 285852 December 29 09:43 arm-softfloat-linux-gnu-gcc-3.4.1

-rwxr-xr-x 1 zzl zzl 16241 December 29 09:43 arm-softfloat-linux-gnu-gccbug

-rwxr-xr-x 1 zzl zzl 103366 December 29 09:43 arm-softfloat-linux-gnu-gcov

-rwxr-xr-x 1 zzl zzl 2286490 December 29 09:02 arm-softfloat-linux-gnu-gprof

-rwxr-xr-x 2 zzl zzl 2542659 December 29 09:02 arm-softfloat-linux-gnu-ld

-rwxr-xr-x 2 zzl zzl 1840205 December 29 09:02 arm-softfloat-linux-gnu-nm

-rwxr-xr-x 1 zzl zzl 2344807 December 29 09:02 arm-softfloat-linux-gnu-objcopy

-rwxr-xr-x 1 zzl zzl 2487727 December 29 09:01 arm-softfloat-linux-gnu-objdump

-rwxr-xr-x 2 zzl zzl 1864029 December 29 09:02 arm-softfloat-linux-gnu-ranlib

-rwxr-xr-x 1 zzl zzl 384396 December 29 09:02 arm-softfloat-linux-gnu-readelf

-rwxr-xr-x 1 zzl zzl 1712993 December 29 09:01 arm-softfloat-linux-gnu-size

-rwxr-xr-x 1 zzl zzl 1689683 December 29 09:02 arm-softfloat-linux-gnu-strings

-rwxr-xr-x 2 zzl zzl 2344806 December 29 09:02 arm-softfloat-linux-gnu-strip

-rwxrwxr-x 1 zzl zzl 19084 December 29 09:43 fix-embedded-paths

We can see that all the tools for cross-compilation are here.

Add this path to your PATH variable:

[zzl@localhost]export PATH=$PATH :/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/bin

If you have to enter the above shell command every time, it is indeed annoying. We can add this statement in the Linux startup script to avoid re-entering it every time after booting. I added the environment variable in the startup script /etc/profile.

Find this line export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

Add the following line above it:

PATH=$PATH :/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/bin

 

When we compile programs in the future, we will use arm-softfloat-linux-gnu-gcc to compile our programs.

Of course, application debugging is an essential part of the development process. The GNU debugger under Linux is GDB. So after we have this cross-compilation toolchain, we can use it to compile gdb and gdbserver. If you don't need GDB for the time being, you can skip this step.

Compile and install GDB

The latest version is GDB6.6. Its official website is http://www.gnu.org/software/gdb/ .

Download the gdb-6.6.tar.gz source code package to /usr/src.

[root@localhost]tar –zxvf gdb-6.6.tar.gz

[root@localhost]cd gdb-6.6

Configuration is simple and only requires specifying the target board architecture and the installation path.

[root@localhost]mkdir /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/gdb6.6

[root@localhost]./configure --target=arm-softfloat-linux-gnu --prefix=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/gdb6.6 -v

[root@localhost]make

[root@localhost]make install

If everything goes well, a new directory will be generated under gdb6.6, and the gdb tool will be in the bin directory.

[root@localhost]ls –l /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/gdb6.6

/bin

Total usage 30476

-rwxr-xr-x 1 root root 14335251 December 29 15:53 ​​arm-softfloat-linux-gnu-gdb

-rwxr-xr-x 1 root root 14335296 December 29 15:53 ​​arm-softfloat-linux-gnu-gdbtui

-rwxr-xr-x 1 root root 2489663 December 29 15:52 arm-softfloat-linux-gnu-run

Also add the gdb path to the environment variables

[root@localhost]export PATH=$PATH :/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/gdb6.6/bin

When debugging programs in the future, use arm-softfloat-linux-gnu-gdb to debug.

Compilation of gdbserver

[root@localhost]cd gdb-6.6

[root@localhost]cd gdb/gdbserver

[root@localhost] ./configure --target=arm-softfloat-linux-gnu –-host=arm-softfloat-linux-gnu

[root@localhost] make CC=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/bin/arm-softfloat-linux-gnu-gcc

If everything goes well, two executable files will be generated in the current directory: gdbserver and gdbreplay. In the future, we can use gdb+gdbserver to debug the program on our development board. So far, our cross-compilation tool chain has been basically established. It can be used as the compilation environment for our bootloader.

 

Use of GDB+GDBServer

Start gdbserver on the target system, which is actually to start gdbserver in the hyperterminal or minicom. Here, put gdbserver in the shared directory /home/zzl of the NFS setting of the host machine, and mount the directory in /work of the target board. The IP of the host machine is 192.168.1.1, and the IP of the target board is 192.168.1.33

HyperTerminal or minicom

[root@localhost]cd /work

[root@localhost]./gdbserver 192.168.1.1:1234 hello

A prompt appears:
Process /work/hello created: pid=69
Listening on port 1234

At this time, switch to the host console and run

[root@localhost] arm-softfloat-linux-gnu-gdb hello

(gdb) target remote 192.168.2.33:1234

A prompt appears:
Remote debugging using 192.168.1.33:1234
[New thread 80]
[Switching to thread 80]
0x40002a90 in ??()
At the same time, a prompt appears under minicom:
Remote debugging from host 192.168.2.100
(gdb).
The connection is successful. Now you can enter various gdb commands such as list, continue, next, step, break, etc. to debug the program.

 

Problems with GDBServer

1. Packet error occurs during GDBServer debugging.

The main reason is that the network connection between the virtual machine and the target machine has to go through Windows, so data packets are easily lost. Switching to Linux system will restore to normal.

Keywords:AT91RM9200 Reference address:AT91RM9200 bootloader creation (I) Creating a cross-compilation tool chain

Previous article:arm embedded cross-compilation toolchain
Next article:Establishing ARM+Linux operating environment

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号