I. Basic Environment
0. Install virtualbox
Download and install the latest virtualbox (4.2)
1. Install ubuntu12.04
Download ubuntu-12.04 for DVD installation ISO, search for download
2. When Ubuntu is installed in virtualbox, allocate a 100 GB Dynamic Disk.
3. After Ubuntu is installed, install virtualbox enhancement and restart
4. Set shared folders, automatic mounting + fixed allocation, and restart
5. sudo adduser XXX vboxsf, set the user to be added to the vboxsf group, get the permission, and restart
6. Modify the Ubuntu source. NetEase is very powerful:
Deb http://mirrors.163.com/ubuntu/ precise main restricted
Deb http://mirrors.163.com/ubuntu/ precise-Updates main restricted
Deb http://mirrors.163.com/ubuntu/ precise universe
Deb http://mirrors.163.com/ubuntu/ precise-Updates universe
Deb http://mirrors.163.com/ubuntu/ precise multiverse
Deb http://mirrors.163.com/ubuntu/ precise-Updates multiverse
Deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
Deb http://mirrors.163.com/ubuntu/ precise-security main restricted
Deb http://mirrors.163.com/ubuntu/ precise-security universe
Deb http://mirrors.163.com/ubuntu/ precise-security multiverse
Sudo apt-Get update
Ii. Install the cross tool chain
- Sudo apt-Get insatll gcc-arm-Linux-gnueabi
- Sudo apt-Get insatll g ++-arm-Linux-gnueabi
Note: Arm-Linux-gnueabi-GDB is not installed here. You can compile one by yourself:
(1) Search download gdb-7.4.1.tar.bz2
(2) Installation
Sudo apt-Get install libncurses5-dev
The termcap library is here
(3) decompress the configuration
./Configure -- target = arm-Linux-gnueabi
(4) Installation
Default address/usr/local
Sudo make install
(5) The sudo ldconfig System Configuration takes effect.
(6) Available
3. Install qemu
Sudo apt-Get install qemu-system qemu-utils
4. Download U-boot
Www.denx.de is the official website of uboot. denx software and hardware are available, and the tool chain ELDK is also very useful. It can be compiled using the tool chain of ELDK. During FTP download, HTTP is used, do not use ftp. You may not be able to see anything.
Http://ftp.denx.de/pub/eldk/-toolchain address
Http://ftp.denx.de/pub/u-boot/-uboot address
Http://ftp.denx.de/pub/u-boot/u-boot-2012.04.tar.bz2 download this
V. Compile uboot
To compile uboot, You need to determine the Board. The Board is closely related to CPU and SOC. Check the boards in the uboot source code root directory. CFG, you can know the names of all supported boards, the corresponding architecture, CPU, vendor, etc,
Because we want to use qemu to simulate this board, we need to find a board that qemu and uboot support at the same time, but also the core of the cortex-a9 architecture.
One row in boards. cfg:
Ca9x4_ct_vxp arm armv7 vexpress armltd
Vexpress is the name of the Board, arm is the architecture arch, armv7 is the CPU, and actually the architecture, armltd is the vendor vendar Ca9x4_ct_vxp Is the configuration name.
In addition, qemu-system-arm-m? Command to view the list of supported boards, including:
Vexpress-a9 arm versatile express for Cortex-A9
That is to say, the vexpress board, in uboot and qemu, also supports, and is cortex-a9.
(1) Export arch = arm
(2) Export cross_compile = arm-Linux-gnueabi-
(3) makeCa9x4_ct_vxp_ Config
(4) make
After the compilation is successful, the U-boot u-boot.bin and other files appear in the source code root directory.
6. Run
-
- Qemu-system-arm-M vexpress-a9-M 256 m-nographic-kernel U-boot this command has no graphics and only command line output
-
- Or
-
- Qemu-system-arm-M vexpress-a9-M 256 m-serial stdio-kernel U-boot this command includes graphical and command line output
GDB debugging:
Note:
(1) GDB debugging
Qemu-system-arm-M vexpress-a9-M 256 m-kernel U-boot-s
Same as qemu-system-arm-M 256-kernel U-boot-gdb tcp: 1234-S
-S indicates-gdb tcp: 1234
-S indicates that it is stopped. Another terminal can use arm-Linux-gnueabi-GDB. After the terminal is started, use the target remote TCP: 1234 parameter to connect to it.
Of course, before the connection, you need to use file to create a signed target, such as U-boot.
At the same time, the directory command of GDB can be used to specify the source file search path.
(2) Kernel File Type
Elf files linked by LD are supported, and the gdb debugging end needs to use files to load the corresponding elf files with debugging information symbols.
7. Compile and run the Linux Kernel
1. Obtain the kernel
Ftp://ftp.kernel.org/pub/linux/kernel/v3.x/linux-3.8.tar.bz2
2. Compile
Export arch = arm
Export cross_compile = arm-Linux-gnueabi-
Make clean distclean
Make vexpress_defconfig
Make-J4
3. Start
Qemu-system-arm-M vexpress-a9-M 256 m-kernel Linux/linux-3.8/ARCH/ARM/boot/zimage-APPEND "console = tty0"
8. root file system
1. busybox Compilation
(1) download source code
Http://www.busybox.net/downloads/busybox-1.21.0.tar.bz2
(2) Compile
Export arch = arm
Export cross_compile = arm-Linux-gnueabi-
Make-J4
Make install
(3) The _ install directory is the result of all busybox compilation.
2. Create the root file system directory
(0) root directory
Mkdir rootfs
CD rootfs
(1) directory structure
Mkdir bin etc Dev lib proc TMP root home sys USR sbin var mnt
(2) Runtime Library-from tool chain
CP-A/usr/ARM-Linux-gnueabi/lib/* lib
(3) configuration file-from busybox
CP-A <busybox_dir>/examples/bootfloppy/etc/* etc
(4) busybox tool set
CP-A <busybox_dir>/_ install /*.
(5) Device Files
Sudo CP-A/dev/console/dev/loop0/dev/loop1/dev/null/dev/ram0/dev/tty/dev/tty0/dev/tty1/dev/zero /dev
(6) modify the mdev configuration. mdev is responsible for Automatically Generating Device nodes, and mdev. conf is the configuration file.
Vi etc/mdev. conf
- Controlc [0-9] 0: 0 0660 = snd/
- PCM. * 0: 0 0660 = snd/
- Seq. * 0: 0 0660 = snd/
- Mix. * 0: 0 0660 = snd/
- Timer 0: 0 0660 = snd/
The same applies to other device files with special requirements.
(7) modify the startup configuration
VI etc/init. d/RCS
Add
Mount-n-t proc NONE/proc
-
Mount-n-t sysfs NONE/sys
Mdev-S is very important. All device nodes are generated.
If NFS is used, you can use the above directory.
3. root file system image
Dd If =/dev/Zero of = rootfs. img bs = 1 m COUNT = 32 #32 m Image
Mkfs. ext3 rootfs. img
Mkdir tmpfs
Sudo Mount-o loop rootfs. IMG tmpfs
Sudo CP-A rootfs/* tmpfs/
Sudo umount tmpfs
Rootfs. IMG has a file system image in ext3 format.
4. The file system image starts qemu-at this time, you do not need u-boot. Simply start the kernel and specify the parameter.
Qemu-system-arm-M vexpress-a9-M 256 m-kernel Linux/linux-3.8/ARCH/ARM/boot/zimage-APPEND "root =/dev/mmcblk0 console = tty0 init =/ linuxrc "-SD rootfs. IMG
9. qemu Network Configuration
0. qemu supports the tap Network
1. The ubuntu-12.04 kernel itself supports Tun devices, so there is no need to compile the module.
2. Install NFS
(1) sudo apt-Get install nfs-kernel-Server
(2) sudo VI/etc/exports
/Home/xxxx/work/rootfs/fs * (RW, sync, no_subtree_check, all_squash, insecure, anonuid = 1000, anongid = 1000)
(3) Service Portmap restart
(4) Service NFS restart
3. Modify the qemu network Startup Script
Sudo VI/etc/qemu-IFUP
#! /Bin/sh
/Sbin/ifconfig $1 172.20.0.1
The IP address of the host is 172.20.0.1.
4. Enable NFS Kernel
Sudo qemu-system-arm-M vexpress-a9-M 256 m-kernel Linux/linux-3.8/ARCH/ARM/boot/zimage-APPEND "root =/dev/nfs nfsroot = 172.20.0.1: /home/RDA/work/rootfs/fs rw ip = 172.20.0.2: 172.20.0.1: 172.20.0.1: 255.255.255.0 init =/linuxrc console = tty0 "-net NIC-net tap
IP = Local IP: Peer IP: gateway IP: mask
Nfsroot = NFS address peer IP Address: Path-same as the path exported in/etc/exports
10. Cross-compilation and use of GDB and gdbserver
1. gdbserver
Gdbserver is easy to use. As a device application, it provides required information for PC-side GDB, and compilation is simple.
(1) download source code
Gdb-7.5.tar.bz2
Address: ftp://prep.ai.mit.edu/pub/gnu/
(2) Compile
CD gdb-7.5/GDB/gdbserver
./Configure -- Host = arm-Linux-gnueabi -- target = arm-Linux-gnueabi
Make-J4
Generate a gdbserver, file to view the file type, copy to the board
(3) Use
Board:
./Gdbserver localhost: 1234 helloworld # helloworld isProgram, Wait for connection after execution
On PC:
Arm-Linux-gnueabi-GDB helloworld
Target remote 172.20.0.2: 1234
You can directly debug the above connection.
2. GDB
(1) Source Code-GDB dependency on the termcap Library
Termcap-1.3.1.tar.gz
Address: ftp://prep.ai.mit.edu/pub/gnu/
(2) Cross-compile termcap
CD termcap-1.3.1
./Configure
Then, modify the makefile as follows:
VI makefile
Cc = arm-Linux-gnueabi-gcc
AR = arm-Linux-gnueabi-ar
Ranlib = arm-Linux-gnueabi-ranlib
Make
(3) Cross-compile GDB
Copy the compiled libtermcap. A to gdb-7.5/GDB
CP-A libtermcap. A gdb-7.5/GDB
CD gdb-7.5
Modify GDB/configure
Case $ host_ OS in
Cygwin *)
If test-d $ srcdir/libtermcap; then
........
Esac
------->
Ac_cv_search_rgetent = "libtermcap."
Configuration
./Configure -- target = arm-Linux-gnueabi -- Host = arm-Linux-gnueabi
Make-J4
(4) Run GDB
Copy GDB to the board, just like debugging PC programs.
11. Questions
1. Reference
Http://www.linuxidc.com/Linux/2012-07/65478.htm
Http://www.cnblogs.com/huqingyu/archive/2005/04/03/131102.html qemu Network
2. uboot Problems
DRAM: 256 MIB
Warning: caches not enabled
Flash: # unknown flash on bank 1-size = 0x00000000 = 0 MB
# Unknown flash on bank 2-size = 0x00000000 = 0 MB
* ** Failed ***
### Error ### Please reset the Board ###
If you stop running after detecting flash failed, it is because it is in arch/ARM/lib/board. in C, the board_init_r () function calls hang () after detecting that flash fails. Now, you can remove hang () to run it.
3. GDB running
"Remote 'G' packet reply is too long"
In GDB/remote. c
Comment out:
If (buf_len> 2 * RSA-> sizeof_g_packet) error (_ ("remote 'G' packet reply is too long: % s"), RS-> BUF );
Add:
If (buf_len> 2 * RSA-> sizeof_g_packet) {RSA-> sizeof_g_packet = buf_len; for (I = 0; I <gdbarch_num_regs (gdbarch); I ++) {If (RSA-> regs [I]. pnum =-1) continue; If (RSA-> regs [I]. offset >=rsa-> sizeof_g_packet) RSA-> regs [I]. in_g_packet = 0; else RSA-> regs [I]. in_g_packet = 1 ;}}
The reason is that gdbserver has too many register numbers. For details, seeCodeYou can.
4. High Version GDB may encounter debugging errors, segment errors, etc., can be replaced with lower version GDB, such as gdb-7.0, gdb-6.8
Gdb-7.0a this version is useful.
5. If a compilation error occurs
If werror is related, the configuration is as follows:
./Configure -- enable-werror = No ......
6. Note that gdbserver and GDB must use the same version
7. Shared Library symbols during communication between GDB and gdbserver
Because the library path on the board is different from the pc library path, GDB on the PC may fail to load the dynamic library:
Set solib-absolute-Prefix/usr/ARM-Linux-gnueabi/
Set solib-search-path/uar/ARM-Linux-gnueabi/lib/