其他分享
首页 > 其他分享> > 从0开始使用QEMU模拟ARM开发环境之uboot通过sd卡加载uImage

从0开始使用QEMU模拟ARM开发环境之uboot通过sd卡加载uImage

作者:互联网

文章目录

其他相关文章:

从0开始使用QEMU模拟ARM开发环境之编译 uboot、Linux 内核和 busybox 制作 rootfs 并仿真

从0开始使用QEMU模拟ARM开发环境之uboot通过tftp加载uImage并指定nfs挂载根文件系统

uboot通过sd卡加载uImage

制作SD卡镜像

可以参见 linux 制作分区镜像img文件

在名为 SDCard (可以是其他地方)的文件夹中进行

  1. 生成一个空的SD卡镜像
dd if=/dev/zero of=uboot.disk bs=1M count=250
# 注意自己控制 count 大小 ,总大小 1*250 = 250 M
  1. 创建分区

创建两个分区(一个用来存放kernel和设备树,另一个存放根文件系统)

sgdisk -n 0:0:+10M -c 0:kernel uboot.disk
sgdisk -n 0:0:0 -c 0:rootfs uboot.disk

查看分区:

sgdisk -p uboot.disk

在这里插入图片描述

  1. 映射SD卡镜像到空闲loop设备
LOOPDEV=`losetup -f`   # 查找空闲的loop设备
echo $LOOPDEV	# 我这边时 /dev/loop0
sudo losetup $LOOPDEV  uboot.disk
sudo partprobe $LOOPDEV
sudo losetup -l
ls /dev/loop*
# 如果需要解映射 : sudo losetup -d /dev/loop0

在这里插入图片描述

会看到/dev/loop0p1 和/dev/loop0p2 两个节点

  1. 格式化并挂载loop设备
# 格式化 
sudo mkfs.ext4 /dev/loop0p1
sudo mkfs.ext4 /dev/loop0p2
# 挂载
mkdir p1 p2
sudo mount -t ext4 /dev/loop0p1 p1   # 存放kernel和设备树
sudo mount -t ext4 /dev/loop0p2 p2   # 存放根文件系统
# 查看挂载情况
 df -h
  1. 拷贝文件
# 将 zImage 和 dtb 拷贝到 p1  
# 之前编译内核的内核目录(linux-5.4.95 文件夹中)
sudo cp arch/arm/boot/zImage /home/leacock/QEMU/SDCard/p1
sudo cp arch/arm/boot/dts/vexpress-v2p-ca9.dtb /home/leacock/QEMU/SDCard/p1

# 将 文件系统中的文件拷贝到 p2
# 之前制作rootfs的 busybox-1.32.1 目录中 文件夹 rootfs 下为 文件系统(未打包直接拷贝,如果制作的文件系统在镜像中需挂载)
# busybox 根目录 busybox-1.32.1 中执行
sudo cp rootfs/* /home/leacock/QEMU/SDCard/p2 -arf
# 最后 查看 p1 p2 是否有对应的文件
  1. 取消挂载
# 在名为 SDCard (可以是其他地方)的文件夹中进行,否则 p1 p2 需要路径
sudo umount p1 p2
sudo losetup -d /dev/loop0

启动uboot 查看sd卡情况

从 之前编译u-boot的文件夹(u-boot-master)中拷贝 u-boot 文件到 名为 SDCard 的文件夹中

# 在名为 SDCard (可以是其他地方)的文件夹中进行 ,因为上面制作的 SD卡镜像 在这个文件夹中
qemu-system-arm -M vexpress-a9 -m 1024M -smp 1 -nographic -kernel u-boot -sd ./uboot.disk

在倒计时结束之前打断它,不要让其进入自主模式

U-Boot 2021.04-rc1 (Feb 05 2021 - 09:02:59 +0800)

DRAM:  1 GiB
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 
=> 

在这里插入图片描述

查看 SD卡的情况,可以用下面的命令查看(默认SD卡就是出于可用状态):
mmc dev 0mmc info,使用part list mmc 0查看分区内容。

查看SD卡2个分区:分区1: ls mmc 0:1 或者 ext4ls mmc 0:1分区2: ls mmc 0:2 或者 ext4ls mmc 0:2

在这里插入图片描述

加载kernel、设备树

加载sd卡分区中指定的文件(内核)到指定的内存: load mmc 0:1 0x60008000 zImage或者ext4load mmc 0:1 0x60008000 zImage

=> load mmc 0:1 0x60008000 zImage
4659968 bytes read in 1607 ms (2.8 MiB/s)

加载sd卡分区中指定的文件(设备树)到指定的内存:load mmc 0:1 0x61000000 vexpress-v2p-ca9.dtb 或者 ext4load mmc 0:1 0x61000000 vexpress-v2p-ca9.dtb

=> load mmc 0:1 0x61000000 vexpress-v2p-ca9.dtb   
14143 bytes read in 56 ms (246.1 KiB/s)

设置bootargs

setenv bootargs 'root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait earlycon console=tty0 console=ttyAMA0 init=/linuxrc ignore_loglevel'
# rootwait是无限期等待,而rootdelay可以指定等待的时间

引导内核

bootz 0x60008000 - 0x61000000
# bootz是启动zImage

固化启动命令

如果上面 引导内核 没有问题的话,那么可以在uboot的代码中将上面的命令固化进程序中

同样也是include/configs/vexpress_common.h中修改CONFIG_BOOTCOMMAND(注意备份)
改成

#define CONFIG_BOOTCOMMAND  "load mmc 0:1 0x60008000 zImage ;load mmc 0:1 0x61000000 vexpress-v2p-ca9.dtb; setenv bootargs \"root=/dev/mmcblk0p2 earlycon console=ttyAMA0\"; bootz 0x60008000 - 0x61000000"

再重新编译即可。 从0开始使用QEMU模拟ARM开发环境之uboot通过tftp加载uImage并指定nfs挂载根文件系统 的 重新编译uboot

测试完整启动

拷贝上面新生成的 u-boot 到 之前 存放 SD 卡镜像 (uboot.disk)的目录(我这边就是名为 SDCard的文件夹 )下面,执行 以下命令 测试 uboot通过sd卡加载uImage

qemu-system-arm -M vexpress-a9 -m 1024M -smp 1 -nographic -kernel u-boot -sd uboot.disk

完整输出

leacock@leacock-virtual-machine:~/QEMU/SDCard$ qemu-system-arm -M vexpress-a9 -m 1024M -smp 1 -nographic -kernel u-boot -sd uboot.disk
WARNING: Image format was not specified for 'uboot.disk' 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.


U-Boot 2021.04-rc1 (Feb 05 2021 - 11:28:42 +0800)

DRAM:  1 GiB
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 
4659968 bytes read in 1558 ms (2.9 MiB/s)
14143 bytes read in 55 ms (251 KiB/s)
Kernel image @ 0x60008000 [ 0x000000 - 0x471b00 ]
## Flattened Device Tree blob at 61000000
   Booting using the fdt blob at 0x61000000
   Loading Device Tree to 7fe6c000, end 7fe7273e ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 5.4.95 (leacock@leacock-virtual-machine) (gcc version 6.5.0 (Linaro GCC 6.5-2018.12)) #3 SMP Thu Feb 4 14:42:48 CST 2021
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
Malformed early option 'earlycon'
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 0x9f000000
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 19 pages/cpu s45516 r8192 d24116 u77824
Built 1 zonelists, mobility grouping on.  Total pages: 260096
Kernel command line: root=/dev/mmcblk0p2 earlycon console=ttyAMA0
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: 131072 (order: 7, 524288 bytes, linear)
Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
mem auto-init: stack:off, heap alloc:off, heap free:off
Memory: 1011944K/1048576K available (7168K kernel code, 426K rwdata, 1708K rodata, 1024K init, 158K bss, 20248K reserved, 16384K cma-reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
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
random: get_random_bytes called from start_kernel+0x320/0x4c4 with crng_init=0
sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
Failed to initialize '/smb@4000000/motherboard/iofpga@7,00000000/timer@12000': -22
smp_twd: clock not found -2
Console: colour dummy device 80x30
Calibrating local timer... 87.46MHz.
Calibrating delay loop... 1254.19 BogoMIPS (lpj=6270976)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: using BPIALL workaround
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 (1254.19 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 protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
hw-breakpoint: debug architecture 0x4 unsupported.
Serial: AMBA PL011 UART driver
10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 25, base_baud = 0) is a PL011 rev1
printk: console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 26, base_baud = 0) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 27, base_baud = 0) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 28, base_baud = 0) is a PL011 rev1
OF: amba_device_add() failed (-19) for /smb@4000000/motherboard/iofpga@7,00000000/wdt@f000
OF: amba_device_add() failed (-19) for /memory-controller@100e0000
OF: amba_device_add() failed (-19) for /memory-controller@100e1000
OF: amba_device_add() failed (-19) for /watchdog@100e5000
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm,sp804
NET: Registered protocol family 2
tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
TCP established hash table entries: 8192 (order: 3, 32768 bytes, linear)
TCP bind hash table entries: 8192 (order: 4, 65536 bytes, linear)
TCP: Hash tables configured (established 8192 bind 8192)
UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
NET: Registered protocol family 1
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=18 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
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: initializing Versatile Express PL111
drm-clcd-pl111 1001f000.clcd: core tile graphics present
drm-clcd-pl111 1001f000.clcd: this device will be deactivated
Error: Driver 'vexpress-muxfpga' is already registered, aborting...
drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
drm-clcd-pl111 10020000.clcd: found bridge on endpoint 0
drm-clcd-pl111 10020000.clcd: Using non-panel bridge
[drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[drm] No driver support for vblank timestamp query.
[drm] Initialized pl111 1.0.0 20170317 for 10020000.clcd on minor 0
Console: switching to colour frame buffer device 128x48
drm-clcd-pl111 10020000.clcd: fb0: pl111drmfb frame buffer device
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]
libphy: Fixed MDIO Bus: probed
libphy: smsc911x-mdio: probed
smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56
isp1760 4f000000.usb: 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.
isp1760 4f000000.usb: can't setup: -19
isp1760 4f000000.usb: USB bus 1 deregistered
usbcore: registered new interface driver usb-storage
rtc-pl031 10017000.rtc: registered as rtc0
mmci-pl18x 10005000.mmci: Got CD GPIO
mmci-pl18x 10005000.mmci: Got WP GPIO
mmci-pl18x 10005000.mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 21,22 (pio)
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
aaci-pl041 10004000.aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 20
aaci-pl041 10004000.aaci: FIFO 512 entries
oprofile: using arm/armv7-ca9
NET: Registered protocol family 17
9pnet: Installing 9P2000 support
Registering SWP/SWPB emulation handler
rtc-pl031 10017000.rtc: setting system clock to 2021-02-05T03:32:35 UTC (1612495955)
ALSA device list:
  #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 20
mmc0: new SD card at address 4567
input: AT Raw Set 2 keyboard as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10006000.kmi/serio0/input/input0
mmcblk0: mmc0:4567 QEMU! 250 MiB 
random: fast init done
 mmcblk0: p1 p2
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
EXT4-fs (mmcblk0p2): INFO: recovery required on readonly filesystem
EXT4-fs (mmcblk0p2): write access will be enabled during recovery
EXT4-fs (mmcblk0p2): recovery complete
EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
Freeing unused kernel memory: 1024K
Run /sbin/init as init process
random: crng init done

Processing /etc/profile... Done

/ # ls
bin         lib         mnt         sbin        usr
dev         linuxrc     proc        sys         var
etc         lost+found  root        tmp
/ # df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               227.4M     12.7M    198.8M   6% /
/ # 

QEMU参数

参见: qemu参数大全

希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充!

标签:uboot,uImage,bytes,dev,device,clcd,QEMU,mmc
来源: https://blog.csdn.net/leacock1991/article/details/113704439