当前位置: 首页 > article >正文

使用qemu搭建armv7嵌入式开发环境

目录

目录

1 概述

2 环境准备

2.1 vexpress系列开发板介绍

2.2 安装工具

2.2.1 安装交叉工具链

2.2.2 安装qemu

2.2.3 安装其他工具

3 启动uboot

3.1 uboot下载与编译

3.1.1 下载

3.1.2 编译

3.2 使用qemu启动uboot

4 启动kernel

4.1 下载和编译kernel

4.1.1 下载kernel

4.1.2 编译kernel

4.2 启动Linux内核

5 加载文件系统

5.1 制作文件系统

5.1.1 busybox下载与编译

5.1.2 制作文件系统

5.1.2.1 单分区镜像制作

5.1.2.1 双分区镜像制作

5.2 启动加载文件系统

6 uboot加载kernel和rootfs到命令行

6.1 修改uboot

6.2 生成boot.scr

6.3 重新打包进行文件系统

6.4 使用qemu启动

7 网络搭建

7.1 etc目录完善

7.2 搭建互通网络

7.2.2 启动qemu绑定增加虚拟网卡

7.2.3 配置虚拟机里的eth0网卡

7.2 tftp搭建

7.2.1 在宿主机搭建tftp服务器

7.2.2 测试文件下载

7.3 scp支持

8 引用


1 概述

        本文介绍如何使用qemu搭建一个嵌入式开发环境,从uboot依次启动kernel和文件系统,使用Vexpress系列开发板的Express A9x4板子。

        本实验宿主机是Ubuntu22.04虚拟机。

2 环境准备

2.1 vexpress系列开发板介绍

        全称versatile express family,是 ARM公司自己推出的开发板,主要用于SOC厂商设计,验证和测试自己的SOC芯片,采用主板+子板设计,主板提供各种外围接口,子板提供CPU运算。本文使用的Vexpress A9X4芯片手册在arm官网可以搜到:

https://developer.arm.com/documentation/dui0448/i/?lang=en

2.2 安装工具

2.2.1 安装交叉工具链

        Vexpress A9X4是armv7架构芯片,这里使用arm-linux-gnueabi-,使用如下命令安装:

sudo apt install -y gcc-arm-linux-gnueabi

sudo apt install -y g++-arm-linux-gnueabi

2.2.2 安装qemu

        使用命令安装:

# For full system emulation

sudo apt install qemu-system

#For emulating Linux binaries

sudo apt install qemu-user-static

        使用源码安装

#https://www.qemu.org/

#https://wiki.qemu.org/Hosts/Linux

git clone https://gitlab.com/qemu-project/qemu.git

git checkout remotes/origin/stable-8.2 -b stable-8.2

sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build

sudo apt-get install git-email

sudo apt-get install libaio-dev libbluetooth-dev libcapstone-dev libbrlapi-dev libbz2-dev

sudo apt-get install libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev

sudo apt-get install libibverbs-dev libjpeg8-dev libncurses5-dev libnuma-dev

sudo apt-get install librbd-dev librdmacm-dev

sudo apt-get install libsasl2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh-dev

sudo apt-get install libvde-dev libvdeplug-dev libvte-2.91-dev libxen-dev liblzo2-dev

sudo apt-get install valgrind xfslibs-dev

sudo apt-get install libnfs-dev libiscsi-dev

./configure --target-list=arm-softmmu --audio-drv-list=

make

sudo make install

        验证:

qemu-system-arm --version

2.2.3 安装其他工具

sudo apt-get install kpartx parted #制作文件系统使用

sudo apt install -y u-boot-tools #uboot编译依赖相关工具

        其他的编译期间出错缺少依赖,按照提示安装即可。

3 启动uboot

3.1 uboot下载与编译

3.1.1 下载

        从官网下载uboot源码

https://ftp.denx.de/pub/u-boot/

        或者使用git下载

git clone https://github.com/u-boot/u-boot.git

笔者的环境访问不了github,从官网下载了u-boot-2023.07.tar.bz2

3.1.2 编译

        解压后的uboot文件夹为u-boot-2023.07,进入该目录编译

#!/bin/bash

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabi-

make vexpress_ca9x4_defconfig # vexpress 配置

make -j8

        编译后在顶层下得到u-boot可执行文件

3.2 使用qemu启动uboot

        上述uboot编译后,即可通过如下命令启动u-boot到命令行

#-M 使用qemu仿真 vexpress-a9 machine,

#-m 指定qemu虚拟机内存 512M

#-nographic 不使用图形化界面(串口输出)

qemu-system-arm \

        -M vexpress-a9 \

        -m 512M \

        -kernel /home/xxx/workspace/labs/u-boot-2023.07/u-boot \

        -nographic \

4 启动kernel

4.1 下载和编译kernel

4.1.1 下载kernel

        去Linux kernel官网下载

Index of /pub/linux/kernel/

        或者使用命令行下载:

git clone https://github.com/torvalds/linux.git

        笔者直接从官网下载,版本为linux-5.15.158.tar.xz

4.1.2 编译kernel

        使用如下命令来编译Linux内核

#!/bin/bash

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabi-

#配置内核

make vexpress_defconfig

#编译内核,本实验使用的是uImage,镜像结果在arch/arm/boot下

make -j4 && make LOADADDR=0x60003000 uImage -j4

#编译内核模块

make modules -j4

#编译device tree,生成.dtb文件,这里是vexpress-v2p-ca9.dtb   

make dtbs

4.2 启动Linux内核

        由于uboot启动kernel,需要uboot修改些地方,这里先不使用uboot启动kernel,直接启动运行kernel,后面章节整体介绍uboot启动kernel。

        使用如下命令来启动Linux kernel

#-M 使用qemu仿真 vexpress-a9 machine,

#-m 指定qemu虚拟机内存 512M

#-kernel 指定 qemu使用的kernel image

#-dtb 指定 qemu boot kernel 时使用的设备树

#-nographic 不使用图形化界面(串口输出)

#-append "xx"  指定kernel启动参数(串口输出参数)

qemu-system-arm \

    -M vexpress-a9 \

    -m 512M \

    -kernel arch/arm/boot/zImage \

    -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb \

    -nographic \

    -append "console=ttyAMA0"

最后在挂载文件系统时停下来,文件系统此时还没加。

5 加载文件系统

5.1 制作文件系统

5.1.1 busybox下载与编译

        在busybox官网https://busybox.net/downloads/ 下载一个版本,笔者下载的是1.38.0版本。

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabi-

make defconfig #先生成默认配置

make menuconfig #配置生成静态库,不使用动态库,如下

        Settings  --->

                -Build static binary (no shared libs)

make -j4 #开始编译

make install #安装生成的文件,在_install下

        编译过程笔者遇到sha硬件加速接口找不到的错误:

error: ‘sha1_process_block64_shaNI’ undeclared (first use in this function);

        把include/autoconf.h文件 #define ENABLE_SHA1_HWACCEL 1这一行注释掉即可,实际虚拟机里没有物理加速硬件也不支持硬件加速,所以注释掉也合理。

5.1.2 制作文件系统

        制作文件系统镜像多制作多个分区,前面编译生成_install下的根目录文件还不够完整,执行如下命令补全脚本(etc还没加进来,自行发挥,不影响启动)

#!/bin/bash
mkdir rootfs
cp -ra _install/* rootfs/
mkdir -p rootfs/lib
cp -ra /usr/arm-linux-gnueabi/lib/* rootfs/lib/
cd rootfs
mkdir dev proc sys tmp root var mnt etc 
cd ../..

5.1.2.1 单分区镜像制作

        使用如下命令生成一个文件32M的系统镜像

#!/bin/bash


dd if=/dev/zero of=vexpress.img bs=1M count=32
mkfs.ext3 vexpress.img
echo "123456" | sudo -S mount -t ext3 vexpress.img /mnt -o loop
echo "123456"| sudo -S cp -ra rootfs/* /mnt
echo "123456" | sudo -S umount /mnt

        最后生成的文件系统镜像为vexpress.img

5.1.2.1 双分区镜像制作

        制作双分区镜像目的是为了让后面介绍uboot自动加载kernel使用,在qemu没有实际的存储系统下,需要借助外部介质例如网络tftp等或者打包所有启动镜像到文件系统中让uboot加载跳转。这里用到了一个boot.scr的脚本,参考后面章节,本章节可以先看后面制作boot.src再来做。

        使用如下命令制作一个双分区镜像,主要是在rootfs.img镜像中创建两个分区,将kernel镜像uImage、dtb和启动脚本boot.scr拷贝到第一分区(boot.scr必须在第一分区),将文件系统拷贝到第二分区。

#!/bin/bash
set -e
IMG_NAME=rootfs.img
PW=123456
KERNEL_NAME=uImage
DTB_NAME=vexpress-v2p-ca9.dtb
KERNEL_PATH=/home/xxx/workspace/labs/linux-5.15.158/arch/arm/boot
DTB_PATH=/home/xxx/workspace/labs/linux-5.15.158/arch/arm/boot/dts
BOOTSRC=/home/xxx/workspace/labs/u-boot-2023.07/boot.scr
MOUNT_FAT_TMPDIR=fat_dir
MOUNT_EXT_TMPDIR=ext_dir

#制作一个含有两个分区的镜像,第一个分区放kernel+dtb,第二个分区是rootfs用于挂载
rm $IMG_NAME || true
dd if=/dev/zero of=$IMG_NAME bs=1M count=64
echo $PW | sudo -S parted $IMG_NAME --script -- mklabel msdos   #这三步用fdisk做也行
echo $PW | sudo -S  parted $IMG_NAME --script -- mkpart primary fat32 2048s 40959s #分区1 2048-40960
echo $PW | sudo -S  parted $IMG_NAME --script -- mkpart primary ext4 40960s -1 # 分区2 40961-
#建立映射,然后格式化两个分区
devname=$(echo $PW | sudo -S losetup -f --show $IMG_NAME) 
echo "current unused $devname"
echo $PW | sudo -S kpartx -va $devname 
loopname=$(echo ${devname##*/})
echo $PW | sudo -S mkfs.vfat /dev/mapper/${loopname}p1
echo $PW | sudo -S mkfs.ext4 /dev/mapper/${loopname}p2
#mount到ubuntu主机
mkdir $MOUNT_EXT_TMPDIR $MOUNT_FAT_TMPDIR
echo $PW | sudo -S mount /dev/mapper/${loopname}p1 $MOUNT_EXT_TMPDIR
echo $PW | sudo -S mount /dev/mapper/${loopname}p2 $MOUNT_FAT_TMPDIR
#拷贝文件系统和内核镜像
echo $PW | sudo -S cp -ra rootfs/* $MOUNT_FAT_TMPDIR/
echo $PW | sudo -S cp $KERNEL_PATH/$KERNEL_NAME $MOUNT_EXT_TMPDIR/ 
echo $PW | sudo -S cp $DTB_PATH/$DTB_NAME  $MOUNT_EXT_TMPDIR/ 
echo $PW | sudo -S cp $BOOTSRC  $MOUNT_EXT_TMPDIR/
#释放
echo $PW | sudo -S umount $MOUNT_FAT_TMPDIR
echo $PW | sudo -S umount $MOUNT_EXT_TMPDIR
echo $PW | sudo -S kpartx -d $devname
echo $PW | sudo -S losetup -d $devname
echo $PW | sudo -S rm -rf $MOUNT_EXT_TMPDIR $MOUNT_FAT_TMPDIR

echo "generate sd image $IMG_NAME successfully"

        最后生成rootfs.img镜像。

5.2 启动加载文件系统

        这里使用单分区文件系统加载,在前面kernel的基础上,加载文件系统,使用如下命令配置加上文件系统。

#!/bin/sh
#-M 使用qemu仿真 vexpress-a9 machine,
#-m 指定qemu虚拟机内存 512M
#-kernel 指定 qemu使用的kernel image
#-dtb 指定 qemu boot kernel 时使用的设备树
#-nographic 不使用图形化界面(串口输出)
#-append "xx"  指定kernel启动参数(串口输出参数)
KERNEL_PATH=/home/xxx/workspace/labs/linux-5.15.158
ROOTFS_FILE=/home/xxx/workspace/labs/busybox/vexpress.img
qemu-system-arm \
        -M vexpress-a9 \
        -m 512M \
        -kernel $KERNEL_PATH/arch/arm/boot/zImage \
        -dtb $KERNEL_PATH/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
        -nographic \
        -append "root=/dev/mmcblk0 rw console=ttyAMA0" \
    	  -sd $ROOTFS_FILE 

加载后进行命令行:

6 uboot加载kernel和rootfs到命令行

6.1 修改uboot

        为了让uboot能加载kernel,需要让uboot知道kernel的位置以及加载方式,这里使用boot.scr脚本加载(关于uboot启动kernel命令过程,参考笔者之前写过的文章uboot启动kernel使用命令过程分析_uboot 启动kernel-CSDN博客)

        修改uboot include/configs/vexpress_common.h板级头文件,添加如下代码scriptaddr的地址定义,用于执行boot.scr的内存空间。

#define VEXPRESS_SCRIPT_ADDR        0x70000000
#define CFG_EXTRA_ENV_SETTINGS \
                "loadaddr=0x60100000\0" \
                .... \
        "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
        "scriptaddr=" __stringify(VEXPRESS_SCRIPT_ADDR) "\0" //添加这一行

        重新编译uboot得到u-boot镜像文件

6.2 生成boot.scr

        boot.scr在文件系统制作双分区的时候有提到要打包进文件系统第一分区,该脚本用来告诉uboot如何加载kernel,使用如下命令生成:

#!/bin/bash
CMD_FILE=boot_vp.cmd
mkimage -C none -A arm -T script -d $CMD_FILE boot.scr

        其中boot_vp.cmd是定义的命令集合文件

setenv bootargs "init=/linuxrc root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyAMA0"
        fatload mmc 0:1 60003000 uImage
        fatload mmc 0:1 60500000 vexpress-v2p-ca9.dtb
        bootm 60003000 - 60500000

        bootargs中init=/linuxrc 告诉kernel起来后执行一下 /linuxrc(启动后如果不存在用户启动脚本则报告 can't run '/etc/init.d/rcS': No such file or directory)。root=/dev/mmcblk0p2告诉内核文件系统所在的分区,rw为文件系统属性,earlyprintk console=ttyAMA0为打印,告诉内核支持早期打印和后期打印设备。当rootwait参数被传递给内核时,内核会在启动过程中进入一个等待状态,直到根文件系统所在的设备准备好被挂载。

fatload mmc 0:1 60003000 uImage: 从mmc0的第一个分区,加载uImage到内存0x6000300中。

fatload mmc 0:1 60500000 vexpress-v2p-ca9.dtb:同理

bootm 60003000 - 60500000:使用bootm命令启动内核,带kernel地址和dtb地址。

6.3 重新打包进行文件系统

        完成上述修改后,需要将kernel、dtb和boot.scr一起打包进文件系统中。打包方式参考前面章节 5.1.2.1 双分区镜像制作。

6.4 使用qemu启动

        最后使用如下命令启动uboot加载kernel、rootfs到命令行

#!/bin/bash

UBOOT_PATH=/home/xxx/workspace/labs/u-boot-2023.07
ROOTFS_IMG=/home/xxx/workspace/labs/busybox/rootfs.img
qemu-system-arm \
    -M vexpress-a9 \
    -m 512M \
    -kernel $UBOOT_PATH/u-boot \
    -nographic \
    -sd $ROOTFS_IMG 

启动日志如下:

xxx@vin:~/workspace/labs$ ./boot_from_uboot.sh
WARNING: Image format was not specified for '/home/xxx/workspace/labs/busybox/rootfs.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument

U-Boot 2023.07-rc6 (Dec 18 2024 - 11:11:10 +0800)
DRAM:  512 MiB
WARNING: Caches not enabled
Core:  18 devices, 10 uclasses, devicetree: embed
Flash: 64 MiB
MMC:   mmci@5000: 0
Loading Environment from Flash... *** Warning - bad CRC, using default environment
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@3,02000000
Hit any key to stop autoboot:  0
MMC Device 1 not found
no mmc device at slot 1
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
272 bytes read in 5 ms (52.7 KiB/s)
## Executing script at 70000000
5030872 bytes read in 769 ms (6.2 MiB/s)
14081 bytes read in 10 ms (1.3 MiB/s)
## Booting kernel from Legacy Image at 60003000 ...
   Image Name:   Linux-5.15.158
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    5030808 Bytes = 4.8 MiB
   Load Address: 60003000
   Entry Point:  60003000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 60500000
   Booting using the fdt blob at 0x60500000
Working FDT set to 60500000
   Loading Kernel Image
   Loading Device Tree to 7eb11000, end 7eb17700 ... OK
Working FDT set to 7eb11000
Starting kernel ...
Booting Linux on physical CPU 0x0
Linux version 5.15.158 (byd@vin) (arm-linux-gnueabi-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #2 SMP Tue Dec 17 14:38:10 CST 2024
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt: Machine model: V2P-CA9
OF: fdt: Ignoring memory block 0x80000000 - 0x80000004
Memory policy: Data cache writeback
Reserved memory: created DMA memory pool at 0x4c000000, size 8 MiB
OF: reserved mem: initialized node vram@4c000000, compatible id shared-dma-pool
cma: Reserved 16 MiB at 0x7f000000
Zone ranges:
  Normal   [mem 0x0000000060000000-0x000000007fffffff]
Movable zone start for each node
Early memory node ranges
  node   0: [mem 0x0000000060000000-0x000000007fffffff]
Initmem setup node 0 [mem 0x0000000060000000-0x000000007fffffff]
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 15 pages/cpu s30220 r8192 d23028 u61440
Built 1 zonelists, mobility grouping on.  Total pages: 130048
Kernel command line: init=/linuxrc root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyAMA0
Unknown kernel command line parameters "earlyprintk", will be passed to user space.
printk: log_buf_len individual max cpu contribution: 4096 bytes
printk: log_buf_len total cpu_extra contributions: 12288 bytes
printk: log_buf_len min size: 16384 bytes
printk: log_buf_len: 32768 bytes
printk: early log buf free: 14784(90%)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
mem auto-init: stack:off, heap alloc:off, heap free:off
Memory: 490916K/524288K available (8192K kernel code, 592K rwdata, 1780K rodata, 1024K init, 151K bss, 16988K reserved, 16384K cma-reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
trace event string verifier disabled
rcu: Hierarchical RCU implementation.
rcu:    RCU event tracing is enabled.
rcu:    RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
GIC CPU mask not found - kernel will fail to boot.
GIC CPU mask not found - kernel will fail to boot.
L2C: platform modifies aux control register: 0x02020000 -> 0x02420000
L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 dynamic clock gating disabled, standby mode disabled
L2C-310 cache controller enabled, 8 ways, 128 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001
sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
smp_twd: clock not found -2
Console: colour dummy device 80x30
Calibrating local timer... 94.45MHz.
Calibrating delay loop... 1931.67 BogoMIPS (lpj=9658368)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: using BPIALL workaround
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x60100000 - 0x60100060
rcu: Hierarchical SRCU implementation.
smp: Bringing up secondary CPUs ...
smp: Brought up 1 node, 1 CPU
SMP: Total of 1 processors activated (1931.67 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
NET: Registered PF_NETLINK/PF_ROUTE protocol family
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
hw-breakpoint: debug architecture 0x4 unsupported.
Serial: AMBA PL011 UART driver
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
PTP clock support registered
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm,sp804
NET: Registered PF_INET protocol family
IP idents hash table entries: 8192 (order: 4, 65536 bytes, linear)
tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
TCP established hash table entries: 4096 (order: 2, 16384 bytes, linear)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes, linear)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
NET: Registered PF_UNIX/PF_LOCAL protocol family
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 5 counters available
workingset: timestamp_bits=30 max_order=17 bucket_order=0
squashfs: version 4.0 (2009/01/31) Phillip Lougher
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
9p: Installing v9fs 9p2000 file system support
io scheduler mq-deadline registered
io scheduler kyber registered
sii902x 0-0060: supply iovcc not found, using dummy regulator
sii902x 0-0060: supply cvcc12 not found, using dummy regulator
physmap-flash 40000000.flash: physmap platform flash device: [mem 0x40000000-0x43ffffff]
40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
physmap-flash 40000000.flash: physmap platform flash device: [mem 0x44000000-0x47ffffff]
40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
Concatenating MTD devices:
(0): "40000000.flash"
(1): "40000000.flash"
into device "40000000.flash"
physmap-flash 48000000.psram: physmap platform flash device: [mem 0x48000000-0x49ffffff]
smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56
isp1760 4f000000.usb: isp1760 bus width: 32, oc: digital
isp1760 4f000000.usb: NXP ISP1760 USB Host Controller
isp1760 4f000000.usb: new USB bus registered, assigned bus number 1
isp1760 4f000000.usb: Scratch test failed. 0x00000000
isp1760 4f000000.usb: can't setup: -19
isp1760 4f000000.usb: USB bus 1 deregistered
usbcore: registered new interface driver usb-storage
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
NET: Registered PF_PACKET protocol family
9pnet: Installing 9P2000 support
Registering SWP/SWPB emulation handler
aaci-pl041 10004000.aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 28
aaci-pl041 10004000.aaci: FIFO 512 entries
mmci-pl18x 10005000.mmci: Got CD GPIO
mmci-pl18x 10005000.mmci: Got WP GPIO
10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 33, base_baud = 0) is a PL011 rev1
mmci-pl18x 10005000.mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 29,30 (pio)
printk: console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 34, base_baud = 0) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 35, base_baud = 0) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 36, base_baud = 0) is a PL011 rev1
rtc-pl031 10017000.rtc: registered as rtc0
rtc-pl031 10017000.rtc: setting system clock to 2024-12-18T05:34:02 UTC (1734500042)
amba 10020000.clcd: Fixing up cyclic dependency with 0-0039
drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
sii902x 0-0039: supply iovcc not found, using dummy regulator
sii902x 0-0039: supply cvcc12 not found, using dummy regulator
i2c i2c-0: Added multiplexed i2c bus 2
drm-clcd-pl111 1001f000.clcd: assigned reserved memory node vram@4c000000
drm-clcd-pl111 1001f000.clcd: using device-specific reserved memory
drm-clcd-pl111 1001f000.clcd: core tile graphics present
drm-clcd-pl111 1001f000.clcd: this device will be deactivated
drm-clcd-pl111 1001f000.clcd: Versatile Express init failed - -19
drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
drm-clcd-pl111 10020000.clcd: found bridge on endpoint 0
drm-clcd-pl111 10020000.clcd: Using non-panel bridge
[drm] Initialized pl111 1.0.0 20170317 for 10020000.clcd on minor 0
input: AT Raw Set 2 keyboard as /devices/platform/bus@40000000/bus@40000000:motherboard-bus@40000000/bus@40000000:motherboard-bus@40000000:iofpga@7,00000000/10006000.kmi/serio0/input/input0
mmc0: new SD card at address 4567
mmcblk0: mmc0:4567 QEMU! 64.0 MiB
 mmcblk0: p1 p2
Console: switching to colour frame buffer device 128x48
drm-clcd-pl111 10020000.clcd: [drm] fb0: pl111drmfb frame buffer device
clk: Disabling unused clocks
ALSA device list:
  #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 28
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/bus@40000000/bus@40000000:motherboard-bus@40000000/bus@40000000:motherboard-bus@40000000:iofpga@7,00000000/10007000.kmi/serio1/input/input2
EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null). Quota mode: disabled.
VFS: Mounted root (ext4 filesystem) on device 179:2.
Freeing unused kernel image (initmem) memory: 1024K
Run /linuxrc as init process
random: crng init done
can't run '/etc/init.d/rcS': No such file or directory
Please press Enter to activate this console.
~ #

7 网络搭建

        搭建宿主机与qemu互通网络,实现宿主机与qemu之间的文件拷贝,方便后续环境开发时进行文件互传提高开发效率。

7.1 etc目录完善

        前面搭建的etc目录是空目录,搭建网络或者其他开发都需要用户环境基本的初始化。以下是笔者在etc目录下增加的文件。

├── etc
│   ├── fstab -->列出启动时要挂载的文件系统,rcS里mount -a将从这里读取挂载
│   ├── group -->用户属组配置
│   ├── init.d
│   │   └── rcS -->启动脚本
│   ├── inittab -->系统初始化时进程配置文件
│   ├── passwd -->用户密钥文件
│   ├── profile -->登录用户配置文件
│   └── shadow -->用户配置文件

        笔者使用的每个文件内容如下,读者可自行拓展。

        fstab文件

# proc    /proc    proc    defaults    0    0
# sysfs   /sys     sysfs   defaults    0    0
tmpfs   /tmp     tmpfs   defaults    0    0

        group文件

root:x:0:root
byd:x:1000:

        rcS文件

#!/bin/sh

echo "qemu armv7 monitor system @tsq"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
mount -a
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
mount -o remount,rw /
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

        inittab文件

::sysinit:/etc/init.d/rcS
::askfirst:-/bin/ash
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount ‐a ‐r
::restart:/sbin/init

        passwd文件

root:x:0:0:root:/root:/bin/sh
byd:x:1000:1000:byd,,,:/home/byd:/bin/sh

shadow文件

root:!:19992:0:99999:7:::
byd:$y$j9T$AvbLn77pwrMsrXkijf1Mm/$VEMdzyZvyxQqEn3PQ.QwcWuBJsM2lrdOAIRdqujOPf4:19992:0:99999:7:::

        profile文件

PATH=/bin:/sbin:/usr/bin:/usr/sbin          #可执行程序 环境变量
export LD_LIBRARY_PATH=/lib:/usr/lib        #动态链接库 环境变量
/bin/hostname qemu_armv7 
USER="`id -un`"
LOGNAME=$USER
HOSTNAME='/bin/hostname'
PS1='[\u@\h \W]# '                          #显示主机名、当前路径等信息

7.2 搭建互通网络

7.2.1 宿主机网络搭建

        在宿主机增加一个rap0网卡,用来和qemu通信

sudo ip tuntap add dev tap0 mode tap
sudo ip link set dev tap0 up
sudo ip address add dev tap0 192.168.2.128/24

        增加后的网卡

tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.128  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::44f3:1eff:fef8:ccb5  prefixlen 64  scopeid 0x20<link>
        ether 46:f3:1e:f8:cc:b5  txqueuelen 1000  (Ethernet)
        RX packets 29  bytes 2180 (2.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 130  bytes 17449 (17.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

7.2.2 启动qemu绑定增加虚拟网卡

        在前面启动脚本的基础之上增加网卡配置的参数

#!/bin/bash
UBOOT_PATH=/home/xxx/workspace/labs/u-boot-2023.07
ROOTFS_IMG=/home/xxx/workspace/labs/busybox/rootfs.img
qemu-system-arm \
        -M vexpress-a9 \
        -m 512M \
        -kernel $UBOOT_PATH/u-boot \
        -nographic \
        -sd $ROOTFS_IMG \
        -net nic -net tap,ifname=tap0,script=no,downscript=no

        执行上述命令之后,qemu默认生成eth0网卡

7.2.3 配置虚拟机里的eth0网卡

        进入虚拟机后,查询当前网卡如下

[root@qemu_armv7 ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:26 

lo        Link encap:Local Loopback  
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

        执行命令配置网卡ip并激活网卡

ip addr add 192.168.2.129/24 dev eth0
ip link set eth0 up

        测试ping 宿主机ip,网络互通

[root@qemu_armv7 ~]# ping 192.168.2.128
PING 192.168.2.128 (192.168.2.128): 56 data bytes
64 bytes from 192.168.2.128: seq=0 ttl=64 time=6.143 ms
64 bytes from 192.168.2.128: seq=1 ttl=64 time=0.680 ms
64 bytes from 192.168.2.128: seq=2 ttl=64 time=0.597 ms
64 bytes from 192.168.2.128: seq=3 ttl=64 time=0.663 ms
64 bytes from 192.168.2.128: seq=4 ttl=64 time=0.704 ms
64 bytes from 192.168.2.128: seq=5 ttl=64 time=0.683 ms
64 bytes from 192.168.2.128: seq=6 ttl=64 time=0.708 ms
64 bytes from 192.168.2.128: seq=7 ttl=64 time=0.821 ms
64 bytes from 192.168.2.128: seq=8 ttl=64 time=1.083 ms

7.2 tftp搭建

        前面步骤完成了宿主机与虚拟机的网络互通,接下来使用任意网络工具拷贝文件,以tftp为例子。

7.2.1 在宿主机搭建tftp服务器

        执行如下命令安装tftp

sudo apt-get install -y tftpd-hpa tftp-hpa xinetd

        配置tftp服务,将共享文件夹配置到/home/xxx/tftp

sudo vim /etc/default/tftpd-hpa
    TFTP_USERNAME="tftp"
    TFTP_DIRECTORY="/home/xxx/tftp"
    TFTP_ADDRESS=":69"
    TFTP_OPTIONS="-l -c -s"

        建立共享目录

sudo mkdir -p /home/xxx/tftp
sudo chown lei:lei /home/xxx/tftp
chmod 777 -R /home/tftp

        最后重启服务

sudo service tftpd-hpa restart

7.2.2 测试文件下载

        在/home/xxx/tftp里创建一个名为demo.txt的文件,内容如下

xxx@vin:~/tftp$ cat demo.txt 
i am tftp test file
xxx@vin:~/tftp$ 

        进入qume虚拟机里,执行如下命令,从宿主机里拉取该文件到本地

~ $ tftp -g -r demo.txt 192.168.2.128
demo.txt             100% |********************************|    20  0:00:00 ETA
~ $ ls
demo.txt
~ $ cat demo.txt 
i am tftp test file
~ $ 

如上对文件的拉取验证,也可向宿主机传文件

tftp -p -l file 192.168.2.128

7.3 scp支持

        也可以用scp来支持文件互传,BusyBox 是为嵌入式系统设计的,提供了一个轻量级的文件系统和一组命令工具,scp默认busybox没有支持,需要用户自己集成。

8 引用

qemu构建嵌入式环境_嵌入式qemu-CSDN博客

uboot启动kernel使用命令过程分析_uboot 启动kernel-CSDN博客

https://developer.arm.com/documentation/dui0448/i/?lang=en

Linux 内核调试 七:qemu网络配置-CSDN博客

9 后记

(1)如何使用自定义宏CONFIG_BOOTCOMMAND启动kernel

        一般uboot板级都配置好了CONFIG_BOOTCOMMAND的默认值,

CONFIG_BOOTCOMMAND="run distro_bootcmd; run bootflash"

        如果想取代该值,需要去掉该值的定义

 Boot options  --->
    [ ] Enable a default value for bootcmd -->关闭此行

        在板级头文件include/configs/vexpress_common.h添加

#define CONFIG_BOOTCOMMAND \
    "fatls mmc 0:1; \
    fatload mmc 0:1 60003000 uImage; \
    fatload mmc 0:1 60500000 vexpress-v2p-ca9.dtb; \
    setenv bootargs 'init=/linuxrc root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyAMA0'; \
    bootm 60003000 - 60500000; "

(2)如何使用tftp加载kernel、rootf并启动

        使用tftp下载镜像后,再用命令启动。基于上一个问题解决方案,可以将tftp下载镜像命令到CONFIG_BOOTCOMMAND里来做,例如:

#define CONFIG_BOOTCOMMAND \
    "tftp 0x60003000 uImage; tftp 0x60500000 vexpress-v2p-ca9.dtb; \
    setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0'; \
    bootm 0x60003000 - 0x60500000; "
#define CONFIG_IPADDR 192.168.2.128
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_SERVERIP 192.168.2.129


http://www.kler.cn/a/447977.html

相关文章:

  • 文件操作(File类)
  • 探索 Seaborn Palette 的奥秘:为数据可视化增色添彩
  • [bug] StarRocks borker load意向之外的bug
  • 【spring-cloud-gateway总结】
  • Java操作Xml
  • LNMP 平台构建与应用全析:深度总结与展望
  • word文档中有大量空白行删除不掉,怎么办?
  • E46.【C语言】练习:面试题:循环多少次?
  • 探秘 Go 语言赋值表达式的奇妙之旅
  • 类型注解:基本类型
  • Linux驱动开发应用层 2 点亮一个LED
  • python2和python3的区别
  • Mysql学习笔记之SQL-3
  • Nginx:刷新显示404
  • 【数据分析】活动效果评估
  • java中的继承
  • ARM 处理器平台 Ethernet Compliance 测试流程示例
  • 电脑运行库DirectX出问题怎么办?
  • 开源轮子 - Apache Common
  • 九大高效的前端测试工具与框架
  • 答:C++需要学到什么程度再开始学 qt 比较合理?
  • 【优选算法---分治】快速排序三路划分(颜色分类、快速排序、数组第K大的元素、数组中最小的K个元素)
  • Vue3 根据窗口的大小动态调整列表的长度
  • Java中双指针的介绍、分类及使用技巧示例
  • 游戏AI实现-寻路算法(Dijkstra)
  • 【机器人】机械臂位置、轨迹和转矩控制概要