Qemu build ARM vexpress development environment (two) ---- started by u-boot Linux kernel

Qemu build ARM vexpress development environment (two) ---- started by u-boot Linux kernel

Tags (separated by spaces): Qemu ARM Linux


In the above "Qemu build ARM vexpress development environment (a)" tells the story of a simple method has been started by the Linux kernel Qemu direct simulation, and hanging in the SD card root file system, this method is directly boot the kernel, with practical applications starting method ARM board: u-boot, kernel, rootfs somewhat different. By Qemu build method by u-boot boot Linux kernel and root file system mounted under right now to tell the story.

1. Description of the development environment

Embedded system to function properly, should include: u-boot, kernel, rootfs, appfs. These parts positional relationship on ARM Flash development board should resemble the figure:

BootLoader BootParameters Kernel Rootfs Appfs

rootfs can be added to the development board Flash, also can not be added to the development board, but deployed to the PC, the development board runs out of kernel, when you want to mount the rootfs, it can be mounted onto the set a good PC via NFS network rootfs on the root file system (under article "Qemu build ARM vexpress development environment (three) ---- NFS network file system root" Show me how NFS network mount the root file system will be explained in detail).

2. Prepare u-boot

To use u-boot boot loader Linux kernel

2.1 Download u-boot

Select a u-boot version of the source code downloaded from the Web site http://ftp.denx.de/pub/u-boot, as used herein, it is u-boot-2017.05 version.

2.2 unzip u-boot

Unzip u-boot:

# tar -xvf u-boot-2018.09.tar.bz2

2.3 compile u-boot

Compiled directly
If you do not modify Makefile and config.mk file, you need to add ARCH and CROSS_COMPILE configuration at compile time:

# make vexpress_ca9x4_defconfig ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

This compilation is relatively straightforward way, but when debugging, you need multiple compilations u-boot, parameters too inconvenient, so through the following methods, and modify Makefile ARCH config.mk files and CROSS_COMPILE options, compiling when it will save the configuration to add compiler at compile command set.

Modify Makefile

# vim Makefile
CROSS_COMPILE = arm-linux-gnueabi-

Modify config.mk

# vim config.mk
ARCH = arm

Compile u-boot:

# make vexpress_ca9x4_defconfig
# make -j4
scripts/kconfig/conf  --syncconfig Kconfig
  CHK     include/config.h
  GEN     include/autoconf.mk.dep
  CFG     u-boot.cfg
  GEN     include/autoconf.mk
*** Your GCC is older than 6.0 and is not supported
arch/arm/config.mk:66: recipe for target 'checkgcc6' failed
make: *** [checkgcc6] Error 1

There may be some problems in compiling u-boot time, as long as you can solve the problem individually compiled, the question shown above, can be resolved by modifying the corresponding file.

# vim arch/arm/config.mk
ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y)
#archprepare: checkthumb checkgcc6
archprepare: checkthumb
checkthumb:
        @if test "$(call cc-name)" = "gcc" -a \
                        "$(call cc-version)" -lt "0404"; then \
                echo -n '*** Your GCC does not produce working '; \
                echo 'binaries in THUMB mode.'; \
                echo '*** Your board is configured for THUMB mode.'; \
                false; \
        fi
#else
#archprepare: checkgcc6
endif

#checkgcc6:
#        @if test "$(call cc-name)" = "gcc" -a \
#                        "$(call cc-version)" -lt "0600"; then \
#                echo '*** Your GCC is older than 6.0 and is not supported'; \
#                false; \
#        fi

2.4 start u-boot

Start command via Qemu start u-boot:

# qemu-system-arm -M vexpress-a9 -m 512M -nographic -kernel tools/u-boot
U-Boot 2018.09 (Sep 24 2018 - 21:50:42 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0
=>

So far, u-boot boot successfully, Next to begin configuring the kernel boot parameters u-boot and start the Linux kernel, and hang on the root file system.

Print u-boot environment variables:

=> print
arch=arm
baudrate=38400
board=vexpress
board_name=vexpress
......
scriptaddr=0x88000000
stderr=serial
stdin=serial
stdout=serial
vendor=armltd

Environment size: 4201/262140 bytes

3. Prepare the kernel

Use u-boot image to boot the kernel:
kernel will need to compile uImage format
needs to specify uImage load address in memory
specified compile the kernel: make LOADADDR = uImage -j4?

Compiled directly in the kernel directory:

# make LOADADDR=0x60003000 uImage -j4

Or add the load address configuration in the Makefile:

# vim linux/arch/arm/boot/Makefile
LOADADDR ?= 0x60003000

Then compiled uImage file:

# make uImage -j4

4. Qemu network functions provided

Qemu virtual machine in the u-boot boot needs to be loaded into memory uImage, uImage and come from? UImage can be downloaded to the memory address specified by the TFTP server. But before that we need to link to the network by bridging Xubuntu system.

4.1 Qemu configure the network connection to the host

Bridged networking Host host communications
host kernel needs to support tun / tap module

4.2 Xubuntu Host Configuration

Install two tools bridged network dependent:

# sudo apt install uml-utilities bridge-utils

Create a tun device files: / dev / net / tun (usually created automatically)
modify / etc / network / interfaces file to configure network

# sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp0s3

auto br0
iface br0 inet dhcp
bridge_ports enp0s3

Configuration / etc / qemu-ifup, / etc / qemu-ifdown script (high version will be automatically configured, no manual configuration)

4.3 Restart the system configuration to take effect

# reboot

or:

# init 6

4.4 View Qemu network environment

# ifconfig
br0       Link encap:Ethernet  HWaddr 08:00:27:63:e5:46  
          inet addr:192.168.0.105  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe63:e546/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:10471 (10.4 KB)  TX bytes:7534 (7.5 KB)

Virtual network interface br0 That Qemu virtual machine and the host communication network port Linux

5. The TFTP server

Create a TFTP server, used to simulate the development board when Qemu start uImage, uImage downloaded into memory.

1) TFTP Server Tools installation of Linux host Host:

# sudo apt install tftp-hpa tftpd-hpa xinetd

2) modify the configuration file, set the TFTP server directory:

# sudo vim /etc/default/tftpd-hpa
......
TFTP_DIRECTORY="/home/mcy/tftpboot"
......

3) Create a tftp directory on a Linux host:

# mkdir /home/mcy/tftpboot
# chmod 777 /home/mcy/tftpboot

4) Restart tftp services:

# sudo /etc/init.d/tftpd-hpa restart

6. Set the kernel boot parameters in the u-boot

Start Qemu verification

# cat boot.sh
#! /bin/sh
qemu-system-arm \
        -M vexpress-a9  \
        -m 512M \
        -kernel u-boot   \   
        #-dtb kernel/linux-4.4.157/arch/arm/boot/dts/vexpress-v2p-ca9.dtb    \   
        -nographic  \
        -net nic,vlan=0 -net tap,vlan=0,ifname=tap0    \
        #-append "root=/dev/mmcblk0 rw console=ttyAMA0"    \
        -sd rootfs.ext3

Thus, the simple rootfs directory is a root file system, it can be made into an image file, the image file to develop programming board, or by the u-boot Qemu started after the Linux kernel to mount the image file. It can also be set via NFS network file system boot, under reference article "Qemu build ARM vexpress development environment (three) ---- NFS network root file system."

Guess you like

Origin www.cnblogs.com/microxiami/p/11093241.html