qemu加载uboot直接启动系统

        上一节讲的qemu加载NFS文件系统启动,需要再uboot阶段输入加载参数,这一节,我们将输入的参数保存到uboot的配置文件中,让uboot自动驱动配置加载内核启动。

1、 uboot调用的命令

vi .config
CONFIG_USE_BOOTCOMMAND=y
CONFIG_BOOTCOMMAND="run distro_bootcmd; run bootflash"
# CONFIG_USE_PREBOOT is not set
CONFIG_DEFAULT_FDT_FILE="vexpress-v2p-ca9.dtb"

        打开uboot的配置文件搜索"CONFIG_BOOTCOMMAND",可以看到uboot启动的默认参数命令为“run distro_bootcmd; run bootflash”我们搜索修改这2个参数即可。

2、修改配置文件

vexpress模拟硬件的配置文件位于include/configs/下

include/configs/vexpress_ca9x4.h
include/configs/vexpress_common.h
include/config_distro_bootcmd.h

        上面3个文件是调用关系。我们首先修改vexpress_common.h文件。修改CFG_EXTRA_ENV_SETTINGS字段如下,同时可以看到包含了config_distro_bootcmd.h文件

#include <config_distro_bootcmd.h>

#define CFG_EXTRA_ENV_SETTINGS \
                "loadaddr=0x60100000\0" \
                "kernel_addr_r=0x60100000\0" \
                "fdt_addr_r=0x60000000\0" \
                "bootargs=root=/dev/nfs rw nfsroot=192.168.2.100:/data/nfs,proto=tcp,nfsvers=4,nolock init=/linuxrc ip=192.168.2.101 console=ttyAMA0\0" \
                BOOTENV \
        "console=ttyAMA0,38400n8\0" \
        "dram=1024M\0" \
        "bootflash=bootm 0x60003000 - 0x60800000\0" \

然后修改config_distro_bootcmd.h文件

#define BOOTENV \
    BOOTENV_SHARED_HOST \
    BOOTENV_BOOT_TARGETS \
    "distro_bootcmd=" "setenv ipaddr 192.168.2.101;"                     \
                        "setenv serverip 192.168.2.100;" \
                        "tftp 0x60003000 uImage;" \
                        "tftp 0x60800000 vexpress-v2p-ca9.dtb;" \

        这2个地方修改完成以后,可以看到“distro_bootcmd”和“bootflash”保护了uboot加载内核启动所需的命令。

3、编译uboot

make ARCH=arm CROSS_COMPILE=arm-ca9-linux-gnueabihf-

  UPD     include/generated/timestamp_autogenerated.h
  CC      common/version.o
  AR      common/built-in.o
  LD      u-boot
  OBJCOPY u-boot.srec
  OBJCOPY u-boot-nodtb.bin
  COPY    u-boot.bin
  SYM     u-boot.sym
===================== WARNING ======================
CONFIG_OF_EMBED is enabled. This option should only
be used for debugging purposes. Please use
CONFIG_OF_SEPARATE for boards in mainline.
See doc/develop/devicetree/control.rst for more info.
====================================================
  OFCHK   .config
#复制uboot到启动目录
cp u-boot /data/tftp/

4、qemu启动uboot测试

启动如下命令

qemu-system-arm -M vexpress-a9 -m 512M -kernel /data/tftp/u-boot -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no

可以看到默认参数少了很多。都是我们启动所需的默认参数

U-Boot 2025.04-rc3 (Mar 27 2025 - 11:00:19 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Core:  23 devices, 11 uclasses, devicetree: embed
Flash: 128 MiB
MMC:   mmci@5000: 0
Loading Environment from Flash... *** Warning - bad CRC, using default environment

In:    uart@9000
Out:   uart@9000
Err:   uart@9000
Net:   eth0: ethernet@3,02000000
Hit any key to stop autoboot:  0
=> print
arch=arm
baudrate=38400
board=vexpress
board_name=vexpress
boot_targets=mmc1 mmc0 pxe dhcp
bootargs=root=/dev/nfs rw nfsroot=192.168.2.100:/data/nfs,proto=tcp,nfsvers=4,nolock init=/linuxrc ip=192.168.2.101 console=ttyAMA0
bootcmd=run distro_bootcmd; run bootflash
bootdelay=2
bootflash=bootm 0x60003000 - 0x60800000
cpu=armv7
distro_bootcmd=setenv ipaddr 192.168.2.101;setenv serverip 192.168.2.100;tftp 0x60003000 uImage;tftp 0x60800000 vexpress-v2p-ca9.dtb;console=ttyAMA0,38400n8
dram=1024M
ethaddr=52:54:00:12:34:56
fdt_addr_r=0x60000000
fdtcontroladdr=7ffe0b50
kernel_addr_r=0x60100000
loadaddr=0x60100000
stderr=uart@9000
stdin=uart@9000
stdout=uart@9000
vendor=armltd

Environment size: 678/262140 bytes

重新启动uboot,可以看到uboot正常加载启动了。

=> reset
resetting ...


U-Boot 2025.04-rc3 (Mar 27 2025 - 11:00:19 +0800)

DRAM:  512 MiB
WARNING: Caches not enabled
Core:  23 devices, 11 uclasses, devicetree: embed
Flash: 128 MiB
MMC:   mmci@5000: 0
Loading Environment from Flash... *** Warning - bad CRC, using default environment

In:    uart@9000
Out:   uart@9000
Err:   uart@9000
Net:   eth0: ethernet@3,02000000
Hit any key to stop autoboot:  0
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using ethernet@3,02000000 device
TFTP from server 192.168.2.100; our IP address is 192.168.2.101
Filename 'uImage'.
Load address: 0x60003000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ###########################
         12.9 MiB/s
done
Bytes transferred = 4206624 (403020 hex)
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using ethernet@3,02000000 device
TFTP from server 192.168.2.100; our IP address is 192.168.2.101
Filename 'vexpress-v2p-ca9.dtb'.
Load address: 0x60800000
Loading: ##
         4.7 MiB/s
done
Bytes transferred = 14692 (3964 hex)
smc911x: MAC 52:54:00:12:34:56
## Booting kernel from Legacy Image at 60003000 ...
   Image Name:   Linux-4.14.1
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4206560 Bytes = 4 MiB
   Load Address: 60003000
   Entry Point:  60003000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 60800000
   Booting using the fdt blob at 0x60800000
Working FDT set to 60800000
   Loading Kernel Image to 60003000
   Loading Device Tree to 7eb14000, end 7eb1a963 ... OK
Working FDT set to 7eb14000

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.14.1 (xxxxxx@qrs) (gcc version 6.5.0 (Buildroot 2019.05.2)) #3 SMP Fri Mar 21 17:55:31 CST 2025
[    0.000000] CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt: Machine model: V2P-CA9
[    0.000000] Memory policy: Data cache writeback
[    0.000000] CPU: All CPU(s) started in SVC mode.
[    0.000000] random: fast init done
[    0.000000] percpu: Embedded 16 pages/cpu @dfbae000 s36428 r8192 d20916 u65536
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 130048
[    0.000000] Kernel command line: root=/dev/nfs rw nfsroot=192.168.2.100:/data/nfs,proto=tcp,nfsvers=4,nolock init=/linuxrc ip=192.168.2.101 console=ttyAMA0
[    0.000000] log_buf_len individual max cpu contribution: 4096 bytes
[    0.000000] log_buf_len total cpu_extra contributions: 12288 bytes
[    0.000000] log_buf_len min size: 16384 bytes
[    0.000000] log_buf_len: 32768 bytes
[    0.000000] early log buf free: 14904(90%)
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 509472K/524288K available (6144K kernel code, 523K rwdata, 1552K rodata, 1024K init, 171K bss, 14816K reserved, 0K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xe0800000 - 0xff800000   ( 496 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xe0000000   ( 512 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0700000   (7136 kB)
[    0.000000]       .init : 0xc0900000 - 0xc0a00000   (1024 kB)
[    0.000000]       .data : 0xc0a00000 - 0xc0a82e30   ( 524 kB)
[    0.000000]        .bss : 0xc0a8a048 - 0xc0ab4d94   ( 172 kB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000]  RCU event tracing is enabled.
[    0.000000]  RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] GIC CPU mask not found - kernel will fail to boot.
[    0.000000] GIC CPU mask not found - kernel will fail to boot.
[    0.000000] L2C: platform modifies aux control register: 0x02020000 -> 0x02420000
[    0.000000] L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000
[    0.000000] L2C-310 enabling early BRESP for Cortex-A9
[    0.000000] L2C-310 full line of zeros enabled for Cortex-A9
[    0.000000] L2C-310 dynamic clock gating disabled, standby mode disabled
[    0.000000] L2C-310 cache controller enabled, 8 ways, 128 kB
[    0.000000] L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001
[    0.000000] smp_twd: clock not found -2
[    0.000181] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.002445] clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.003128] Failed to initialize '/smb@4000000/motherboard/iofpga@7,00000000/timer@12000': -22
[    0.006342] Console: colour dummy device 80x30
[    0.006680] Calibrating local timer... 90.81MHz.
[    0.062745] Calibrating delay loop... 973.20 BogoMIPS (lpj=4866048)
[    0.099076] pid_max: default: 32768 minimum: 301
[    0.100005] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.100033] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.108981] CPU: Testing write buffer coherency: ok
[    0.116487] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[    0.120033] Setting up static identity map for 0x60100000 - 0x60100060
[    0.121011] Hierarchical SRCU implementation.
[    0.124224] smp: Bringing up secondary CPUs ...
[    0.128106] smp: Brought up 1 node, 1 CPU
[    0.128198] SMP: Total of 1 processors activated (973.20 BogoMIPS).
[    0.128246] CPU: All CPU(s) started in SVC mode.
[    0.164062] devtmpfs: initialized
[    0.170825] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0
[    0.181843] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.182521] futex hash table entries: 1024 (order: 4, 65536 bytes)
[    0.211356] NET: Registered protocol family 16
[    0.213836] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.330126] cpuidle: using governor ladder
[    0.331244] hw-breakpoint: debug architecture 0x4 unsupported.
[    0.332424] Serial: AMBA PL011 UART driver
[    0.344583] OF: amba_device_add() failed (-19) for /memory-controller@100e0000
[    0.345785] OF: amba_device_add() failed (-19) for /memory-controller@100e1000
[    0.346356] OF: amba_device_add() failed (-19) for /watchdog@100e5000
[    0.359115] 10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 35, base_baud = 0) is a PL011 rev1
[    0.377323] console [ttyAMA0] enabled
[    0.378777] 1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 36, base_baud = 0) is a PL011 rev1
[    0.380022] 1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 37, base_baud = 0) is a PL011 rev1
[    0.381644] 1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 38, base_baud = 0) is a PL011 rev1
[    0.382428] OF: amba_device_add() failed (-19) for /smb@4000000/motherboard/iofpga@7,00000000/wdt@f000
[    0.416503] SCSI subsystem initialized
[    0.419739] usbcore: registered new interface driver usbfs
[    0.420021] usbcore: registered new interface driver hub
[    0.420334] usbcore: registered new device driver usb
[    0.423918] Advanced Linux Sound Architecture Driver Initialized.
[    0.433263] clocksource: Switched to clocksource arm,sp804
[    0.510555] NET: Registered protocol family 2
[    0.514008] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.514392] TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
[    0.514714] TCP: Hash tables configured (established 4096 bind 4096)
[    0.516139] UDP hash table entries: 256 (order: 1, 8192 bytes)
[    0.516367] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[    0.517392] NET: Registered protocol family 1
[    0.520301] RPC: Registered named UNIX socket transport module.
[    0.520462] RPC: Registered udp transport module.
[    0.520562] RPC: Registered tcp transport module.
[    0.520656] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.526625] hw perfevents: enabled with armv7_cortex_a9 PMU driver, 5 counters available
[    0.530662] workingset: timestamp_bits=30 max_order=17 bucket_order=0
[    0.542194] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.544025] NFS: Registering the id_resolver key type
[    0.544803] Key type id_resolver registered
[    0.544929] Key type id_legacy registered
[    0.545135] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.545519] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[    0.546778] 9p: Installing v9fs 9p2000 file system support
[    0.549941] io scheduler noop registered (default)
[    0.550076] io scheduler mq-deadline registered
[    0.550187] io scheduler kyber registered
[    0.552614] clcd-pl11x 10020000.clcd: PL111 designer 41 rev2 at 0x10020000
[    0.558247] clcd-pl11x 10020000.clcd: /clcd@10020000 hardware, 1024x768@59 display
[    0.660262] Console: switching to colour frame buffer device 128x48
[    0.672323] clcd-pl11x 1001f000.clcd: PL111 designer 41 rev2 at 0x1001f000
[    0.673963] clcd-pl11x 1001f000.clcd: /smb@4000000/motherboard/iofpga@7,00000000/clcd@1f000 hardware, 640x480@59 display
[    0.960153] 40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
[    0.961022] Intel/Sharp Extended Query Table at 0x0031
[    0.962039] Using buffer write method
[    0.964149] 40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
[    0.964580] Intel/Sharp Extended Query Table at 0x0031
[    0.965092] Using buffer write method
[    0.965322] Concatenating MTD devices:
[    0.965476] (0): "40000000.flash"
[    0.965617] (1): "40000000.flash"
[    0.965751] into device "40000000.flash"
[    0.975744] libphy: Fixed MDIO Bus: probed
[    1.033731] libphy: smsc911x-mdio: probed
[    1.039993] smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56
[    1.144410] isp1760 4f000000.usb: bus width: 32, oc: digital
[    1.146245] isp1760 4f000000.usb: NXP ISP1760 USB Host Controller
[    1.147385] isp1760 4f000000.usb: new USB bus registered, assigned bus number 1
[    1.149830] isp1760 4f000000.usb: Scratch test failed.
[    1.150558] isp1760 4f000000.usb: can't setup: -19
[    1.151756] isp1760 4f000000.usb: USB bus 1 deregistered
[    1.159756] usbcore: registered new interface driver usb-storage
[    1.180179] rtc-pl031 10017000.rtc: rtc core: registered pl031 as rtc0
[    1.182233] IR NEC protocol handler initialized
[    1.182558] IR RC5(x/sz) protocol handler initialized
[    1.182870] IR RC6 protocol handler initialized
[    1.183150] IR JVC protocol handler initialized
[    1.183432] IR Sony protocol handler initialized
[    1.183732] IR SANYO protocol handler initialized
[    1.184026] IR Sharp protocol handler initialized
[    1.184331] IR MCE Keyboard/mouse protocol handler initialized
[    1.184646] IR XMP protocol handler initialized
[    1.191380] mmci-pl18x 10005000.mmci: Got CD GPIO
[    1.191745] mmci-pl18x 10005000.mmci: Got WP GPIO
[    1.193538] mmci-pl18x 10005000.mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 31,32 (pio)
[    1.252647] ledtrig-cpu: registered to indicate activity on CPUs
[    1.255004] usbcore: registered new interface driver usbhid
[    1.255203] usbhid: USB HID core driver
[    1.272692] 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
[    1.287584] aaci-pl041 10004000.aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 30
[    1.287841] aaci-pl041 10004000.aaci: FIFO 512 entries
[    1.288472] oprofile: using arm/armv7-ca9
[    1.289343] NET: Registered protocol family 17
[    1.290079] 9pnet: Installing 9P2000 support
[    1.290394] Key type dns_resolver registered
[    1.290697] Registering SWP/SWPB emulation handler
[    1.297195] rtc-pl031 10017000.rtc: setting system clock to 2025-03-27 03:18:35 UTC (1743045515)
[    1.302074] Generic PHY 4e000000.ethernet-ffffffff:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=4e000000.ethernet-ffffffff:01, irq=POLL)
[    1.303326] smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xe1290000, IRQ: 28
[    1.859544] 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
[    2.307352] IP-Config: Guessing netmask 255.255.255.0
[    2.308135] IP-Config: Complete:
[    2.309180]      device=eth0, hwaddr=52:54:00:12:34:56, ipaddr=192.168.2.101, mask=255.255.255.0, gw=255.255.255.255
[    2.310366]      host=192.168.2.101, domain=, nis-domain=(none)
[    2.311056]      bootserver=255.255.255.255, rootserver=192.168.2.100, rootpath=
[    2.317699] ALSA device list:
[    2.318208]   #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 30
[    2.421963] VFS: Mounted root (nfs4 filesystem) on device 0:14.
[    2.447581] Freeing unused kernel memory: 1024K
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Starting network: ip: RTNETLINK answers: File exists
FAIL

Welcome to Buildroot
buildroot login: root
Password:
# ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56
          inet addr:192.168.2.101  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2056 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1282 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2519332 (2.4 MiB)  TX bytes:241368 (235.7 KiB)
          Interrupt:28

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值