用Qemu模拟vexpress-a9 (三)--- 实现用u-boot引导Linux内核

简介: 用Qemu模拟vexpress-a9 (三)--- 实现用u-boot引导Linux内核

 

环境介绍

Win7 64 + Vmware 11 + ubuntu14.04 32

u-boot 版本:u-boot-2015-04

Linux kernel版本:linux-3.16.y

busybox版本:1_24_stable

交叉编译工具链:arm-linux-gnueabi-

qemu版本:stable-2.4

 

概述

这里我采用的方法是,利用网络引导的方式启动Linux内核。具体方式如下:

开启Qemu的网络支持功能,启动u-boot,设置u-boot的环境变量,u-boot采用tftp的方式将uImage格式的Linux内核下载到内存地址0x60003000处,为什么是0x60000000起始的地址,参考文件u-boot的配置文件 include/configs/vexpress_common.h。如果用Qemu直接启动Kernel,是通过-append parameter 的方式给kernel传参的,现在是通过u-boot,那么需要通过u-boot的环境变量bootargs,可以设置为如下值 setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0 console=tty0'。 然后设置u-boot环境变量bootcmd,如下: setenv bootcmd 'tftp 0x60003000 uImage; bootm 0x60003000'.

具体步骤

1、启动Qemu的网络支持

这个请参考博客:http://www.cnblogs.com/pengdonglin137/p/5023340.html

 

2、配置u-boot

主要是修改include/configs/vexpress_common.h

diff --git a/include/configs/vexpress_common.h b/include/configs/vexpress_common.h

index 0c1da01..9fa7d9e 100644

--- a/include/configs/vexpress_common.h

+++ b/include/configs/vexpress_common.h

@@ -48,6 +48,11 @@

#define CONFIG_SYS_TEXT_BASE   0x80800000

#endif

 

+/* netmask */

+#define CONFIG_IPADDR   192.168.11.5

+#define CONFIG_NETMASK  255.255.255.0

+#define CONFIG_SERVERIP 192.168.11.20

+

/*

 * Physical addresses, offset from V2M_PA_CS0-3

 */

@@ -202,7 +207,9 @@

#define CONFIG_SYS_INIT_SP_ADDR                CONFIG_SYS_GBL_DATA_OFFSET

 

/* Basic environment settings */

-#define CONFIG_BOOTCOMMAND             "run bootflash;"

+/* #define CONFIG_BOOTCOMMAND          "run bootflash;" */

+#define CONFIG_BOOTCOMMAND             "tftp 0x60003000 uImage; setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0'; bootm 0x60003000

+

 

说明:

这里我把ipaddr等设置为了192.168.11.x网段,这个需要跟br0的网址一致,br0的地址在/etc/qemu-ifuo中修改:

#!/bin/sh


echo sudo tunctl -u $(id -un) -t $1

sudo tunctl -u $(id -un) -t $1


echo sudo ifconfig $1 0.0.0.0 promisc up

sudo ifconfig $1 0.0.0.0 promisc up


echo sudo brctl addif br0 $1

sudo brctl addif br0 $1


echo brctl show

brctl show


sudo ifconfig br0 192.168.11.20

然后重新编译u-boot代码

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j2

 

测试:

qemu-system-arm -M vexpress-a9 \

    -kernel u-boot \

    -nographic \

    -m 512M \

    -net nic,vlan=0 -net tap,vlan=0,ifname=tap0

运行:

U-Boot 2015.07-rc3-00092-gf3edfd3-dirty (Dec 05 2015 - 22:00:46 -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

Warning: smc911x-0 using MAC address from net device


Hit any key to stop autoboot:  0 

VExpress# ping 192.168.11.20

smc911x: MAC 52:54:00:12:34:56

smc911x: detected LAN9118 controller

smc911x: phy initialized

smc911x: MAC 52:54:00:12:34:56

Using smc911x-0 device

smc911x: MAC 52:54:00:12:34:56

host 192.168.11.20 is alive

 

2、配置Linux Kernel

因为要用u-boot引导,所以需要把Kernel编译成uImage格式。

执行如下命令:

make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm O=./out_vexpress_3_16 uImage -j2

编译时会报错:

make[1]: Entering directory `/root/tq2440_work/kernel/linux-stable/out_vexpress_3_16'

 CHK     include/config/kernel.release

 GEN     ./Makefile

 CHK     include/generated/uapi/linux/version.h

 Using .. as source for kernel

 CHK     include/generated/utsrelease.h

make[2]: `include/generated/mach-types.h' is up to date.

 CALL    ../scripts/checksyscalls.sh

 CHK     include/generated/compile.h

 CHK     kernel/config_data.h

 Kernel: arch/arm/boot/Image is ready

 Kernel: arch/arm/boot/zImage is ready

multiple (or no) load addresses:

This is incompatible with uImages

Specify LOADADDR on the commandline to build an uImage

make[2]: *** [arch/arm/boot/uImage] Error 1

make[1]: *** [uImage] Error 2

make: *** [sub-make] Error 2

这里需要我们制定LOADADDR的值,即uImage的加载地址,根据u-boot,我们可以将其设置为0x60003000.

修改后的命令如下:

make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm O=./out_vexpress_3_16 LOADADDR=0x60003000  uImage -j2

编译信息:

make[1]: Entering directory `/root/tq2440_work/kernel/linux-stable/out_vexpress_3_16'

 CHK     include/config/kernel.release

 GEN     ./Makefile

 CHK     include/generated/uapi/linux/version.h

 Using .. as source for kernel

 CHK     include/generated/utsrelease.h

make[2]: `include/generated/mach-types.h' is up to date.

 CALL    ../scripts/checksyscalls.sh

 CHK     include/generated/compile.h

 CHK     kernel/config_data.h

 Kernel: arch/arm/boot/Image is ready

 Kernel: arch/arm/boot/zImage is ready

 UIMAGE  arch/arm/boot/uImage

Image Name:   Linux-3.16.7

Created:      Sat Dec  5 23:10:41 2015

Image Type:   ARM Linux Kernel Image (uncompressed)

Data Size:    3326696 Bytes = 3248.73 kB = 3.17 MB

Load Address: 0x60003000

Entry Point:  0x60003000

 Image arch/arm/boot/uImage is ready

 

编译生成的uImage在 linux-stable/out_vexpress_3_16/arch/arm/boot下,然后将uImage拷贝到/tftpboot目录下,关于tftp服务器的配置请参考:

https://files.cnblogs.com/files/pengdonglin137/ubuntu-12.04%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.pdf

 

3、测试

执行如下命令:

qemu-system-arm -M vexpress-a9 \

    -kernel /root/tq2440_work/u-boot/u-boot/u-boot \

    -nographic \

    -m 512M \

    -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \

    -sd /root/tq2440_work/busybox_study/a9rootfs.ext3

 

启动信息:

sudo tunctl -u root -t tap0

sudo ifconfig tap0 0.0.0.0 promisc up

sudo brctl addif br0 tap0

brctl show

bridge name    bridge id        STP enabled    interfaces

br0        8000.000c290bd2f3    no        eth0

                           tap0



U-Boot 2015.07-rc3-00092-gf3edfd3-dirty (Dec 05 2015 - 23:20:40 -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

Warning: smc911x-0 using MAC address from net device


Hit any key to stop autoboot:  0 

smc911x: MAC 52:54:00:12:34:56

smc911x: detected LAN9118 controller

smc911x: phy initialized

smc911x: MAC 52:54:00:12:34:56

Using smc911x-0 device

TFTP from server 192.168.11.20; our IP address is 192.168.11.5

Filename 'uImage'.

Load address: 0x60003000

Loading: #################################################################

    #################################################################

    #################################################################

    ################################

    796.9 KiB/s

done

Bytes transferred = 3326760 (32c328 hex)

smc911x: MAC 52:54:00:12:34:56

## Booting kernel from Legacy Image at 60003000 ...

  Image Name:   Linux-3.16.7

  Image Type:   ARM Linux Kernel Image (uncompressed)

  Data Size:    3326696 Bytes = 3.2 MiB

  Load Address: 60003000

  Entry Point:  60003000

  Verifying Checksum ... OK

  Loading Kernel Image ... OK


Starting kernel ...


Booting Linux on physical CPU 0x0

Initializing cgroup subsys cpuset

Linux version 3.16.7 (root@ubuntu) (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1) ) #5 SMP Sat Dec 5 21:17:17 PST 2015

CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c53c7d

CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache

Machine: ARM-Versatile Express

Memory policy: Data cache writeback

CPU: All CPU(s) started in SVC mode.

sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956969942ns

PERCPU: Embedded 7 pages/cpu @9fbed000 s7552 r8192 d12928 u32768

Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048

Kernel command line: root=/dev/mmcblk0 console=ttyAMA0

PID hash table entries: 2048 (order: 1, 8192 bytes)

Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)

Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)

Memory: 513272K/524288K available (4563K kernel code, 190K rwdata, 1292K rodata, 239K init, 149K bss, 11016K reserved)

Virtual kernel memory layout:

   vector  : 0xffff0000 - 0xffff1000   (   4 kB)

   fixmap  : 0xffc00000 - 0xffe00000   (2048 kB)

   vmalloc : 0xa0800000 - 0xff000000   (1512 MB)

   lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)

   modules : 0x7f000000 - 0x80000000   (  16 MB)

     .text : 0x80008000 - 0x805c01b0   (5857 kB)

     .init : 0x805c1000 - 0x805fcd80   ( 240 kB)

     .data : 0x805fe000 - 0x8062dba0   ( 191 kB)

      .bss : 0x8062dba8 - 0x8065336c   ( 150 kB)

SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

Hierarchical RCU implementation.

   RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.

RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1

NR_IRQS:16 nr_irqs:16 16

GIC CPU mask not found - kernel will fail to boot.

GIC CPU mask not found - kernel will fail to boot.

smp_twd: clock not found -2

Console: colour dummy device 80x30

Calibrating local timer... 88.21MHz.

Calibrating delay loop... 310.68 BogoMIPS (lpj=1553408)

pid_max: default: 32768 minimum: 301

Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)

Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)

CPU: Testing write buffer coherency: ok

missing device node for CPU 0

CPU0: thread -1, cpu 0, socket 0, mpidr 80000000

Setting up static identity map for 0x604546d0 - 0x60454728

Brought up 1 CPUs

SMP: Total of 1 processors activated.

CPU: All CPU(s) started in SVC mode.

devtmpfs: initialized

VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0

regulator-dummy: no parameters

NET: Registered protocol family 16

DMA: preallocated 256 KiB pool for atomic coherent allocations

cpuidle: using governor ladder

cpuidle: using governor menu

hw-breakpoint: debug architecture 0x4 unsupported.

Serial: AMBA PL011 UART driver

mb:uart0: ttyAMA0 at MMIO 0x10009000 (irq = 37, base_baud = 0) is a PL011 rev1

console [ttyAMA0] enabled

mb:uart1: ttyAMA1 at MMIO 0x1000a000 (irq = 38, base_baud = 0) is a PL011 rev1

mb:uart2: ttyAMA2 at MMIO 0x1000b000 (irq = 39, base_baud = 0) is a PL011 rev1

mb:uart3: ttyAMA3 at MMIO 0x1000c000 (irq = 40, base_baud = 0) is a PL011 rev1

fixed-dummy: no parameters

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.

Switched to clocksource v2m-timer1

NET: Registered protocol family 2

TCP established hash table entries: 4096 (order: 2, 16384 bytes)

TCP bind hash table entries: 4096 (order: 3, 32768 bytes)

TCP: Hash tables configured (established 4096 bind 4096)

TCP: reno registered

UDP hash table entries: 256 (order: 1, 8192 bytes)

UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)

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.

CPU PMU: probing PMU on CPU 0

hw perfevents: enabled with ARMv7 Cortex-A9 PMU driver, 1 counters available

futex hash table entries: 256 (order: 2, 16384 bytes)

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

msgmni has been set to 1002

io scheduler noop registered (default)

clcd-pl11x ct:clcd: PL111 rev2 at 0x10020000

clcd-pl11x ct:clcd: CT-CA9X4 hardware, XVGA display

Console: switching to colour frame buffer device 128x48

physmap platform flash device: 04000000 at 40000000

physmap-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 platform flash device: 04000000 at 44000000

physmap-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): "physmap-flash"

(1): "physmap-flash"

into device "physmap-flash"

libphy: smsc911x-mdio: probed

smsc911x smsc911x eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=smsc911x-fffffff:01, irq=-1)

smsc911x smsc911x eth0: MAC Address: 52:54:00:12:34:56

isp1760 isp1760: NXP ISP1760 USB Host Controller

isp1760 isp1760: new USB bus registered, assigned bus number 1

isp1760 isp1760: Scratch test failed.

isp1760 isp1760: can't setup: -19

isp1760 isp1760: USB bus 1 deregistered

isp1760: Failed to register the HCD device

usbcore: registered new interface driver usb-storage

mousedev: PS/2 mouse device common for all mice

rtc-pl031 mb:rtc: rtc core: registered pl031 as rtc0

mmci-pl18x mb:mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 41,42 (pio)

input: AT Raw Set 2 keyboard as /devices/mb:kmi0/serio0/input/input0

ledtrig-cpu: registered to indicate activity on CPUs

usbcore: registered new interface driver usbhid

usbhid: USB HID core driver

mmc0: host does not support reading read-only switch. assuming write-enable.

mmc0: new SD card at address 4567

mmcblk0: mmc0:4567 QEMU! 32.0 MiB

mmcblk0: unknown partition table

aaci-pl041 mb:aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 43

aaci-pl041 mb:aaci: FIFO 512 entries

oprofile: using arm/armv7-ca9

TCP: cubic registered

NET: Registered protocol family 17

9pnet: Installing 9P2000 support

rtc-pl031 mb:rtc: setting system clock to 2015-12-06 07:22:11 UTC (1449386531)

ALSA device list:

 #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 43

input: ImExPS/2 Generic Explorer Mouse as /devices/mb:kmi1/serio1/input/input2

kjournald starting.  Commit interval 5 seconds

EXT3-fs (mmcblk0): using internal journal

EXT3-fs (mmcblk0): recovery complete

EXT3-fs (mmcblk0): mounted filesystem with writeback data mode

VFS: Mounted root (ext3 filesystem) on device 179:0.

Freeing unused kernel memory: 236K (805c1000 - 805fc000)

random: nonblocking pool is initialized

mount: mounting none on /proc/bus/usb failed: No such file or directory


Please press Enter to activate this console.


[root@vexpress ]#

[root@vexpress ]#

[root@vexpress ]#

[root@vexpress ]#

[root@vexpress ]#

[root@vexpress ]# ls

bin         etc         linuxrc     mnt         root        sys         usr

dev         lib         lost+found  proc        sbin        tmp         var

[root@vexpress ]# ifconfig 

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:0 

         RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


[root@vexpress ]# ifconfig eth0 192.168.11.5

smsc911x smsc911x eth0: SMSC911x/921x identified at 0xa0a40000, IRQ: 47

[root@vexpress ]# ping 192.168.11.20

PING 192.168.11.20 (192.168.11.20): 56 data bytes

64 bytes from 192.168.11.20: seq=0 ttl=64 time=20.928 ms

64 bytes from 192.168.11.20: seq=1 ttl=64 time=1.250 ms

64 bytes from 192.168.11.20: seq=2 ttl=64 time=0.573 ms

^C

--- 192.168.11.20 ping statistics ---

3 packets transmitted, 3 packets received, 0% packet loss

round-trip min/avg/max = 0.573/7.583/20.928 ms

[root@vexpress ]#

 

可以在/etc/init.d/rcS中设置eth0的ip地址为 ifconfig eth0 192.168.11.5

 

4、开启图形界面

修改u-boot的bootargs环境变量为:

setenv bootargs 'root=/dev/mmcblk0 console=ttyAMA0 console=tty0';

执行命令:

qemu-system-arm -M vexpress-a9 \

    -kernel /root/tq2440_work/u-boot/u-boot/u-boot \

    -nographic \

    -m 512M \

    -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \

    -sd /root/tq2440_work/busybox_study/a9rootfs.ext3

截图:

image.png

 

未完待续。

相关文章
|
2月前
|
安全 Linux 测试技术
Intel Linux 内核测试套件-LKVS介绍 | 龙蜥大讲堂104期
《Intel Linux内核测试套件-LKVS介绍》(龙蜥大讲堂104期)主要介绍了LKVS的定义、使用方法、测试范围、典型案例及其优势。LKVS是轻量级、低耦合且高代码覆盖率的测试工具,涵盖20多个硬件和内核属性,已开源并集成到多个社区CICD系统中。课程详细讲解了如何使用LKVS进行CPU、电源管理和安全特性(如TDX、CET)的测试,并展示了其在实际应用中的价值。
|
2月前
|
Ubuntu Linux 开发者
Ubuntu20.04搭建嵌入式linux网络加载内核、设备树和根文件系统
使用上述U-Boot命令配置并启动嵌入式设备。如果配置正确,设备将通过TFTP加载内核和设备树,并通过NFS挂载根文件系统。
130 15
|
3月前
|
算法 Linux
深入探索Linux内核的内存管理机制
本文旨在为读者提供对Linux操作系统内核中内存管理机制的深入理解。通过探讨Linux内核如何高效地分配、回收和优化内存资源,我们揭示了这一复杂系统背后的原理及其对系统性能的影响。不同于常规的摘要,本文将直接进入主题,不包含背景信息或研究目的等标准部分,而是专注于技术细节和实际操作。
|
3月前
|
存储 缓存 网络协议
Linux操作系统的内核优化与性能调优####
本文深入探讨了Linux操作系统内核的优化策略与性能调优方法,旨在为系统管理员和高级用户提供一套实用的指南。通过分析内核参数调整、文件系统选择、内存管理及网络配置等关键方面,本文揭示了如何有效提升Linux系统的稳定性和运行效率。不同于常规摘要仅概述内容的做法,本摘要直接指出文章的核心价值——提供具体可行的优化措施,助力读者实现系统性能的飞跃。 ####
|
3月前
|
缓存 监控 网络协议
Linux操作系统的内核优化与实践####
本文旨在探讨Linux操作系统内核的优化策略与实际应用案例,深入分析内核参数调优、编译选项配置及实时性能监控的方法。通过具体实例讲解如何根据不同应用场景调整内核设置,以提升系统性能和稳定性,为系统管理员和技术爱好者提供实用的优化指南。 ####
|
1月前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
74 24
Linux系统之whereis命令的基本使用
|
4月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
417 8
|
5天前
|
Linux
Linux od命令
本文详细介绍了Linux中的 `od`命令,包括其基本语法、常用选项和示例。通过这些内容,你可以灵活地使用 `od`命令查看文件内容,提高分析和调试效率。确保理解每一个选项和示例的实现细节,应用到实际工作中时能有效地处理各种文件查看需求。
41 19
|
16天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
99 25
|
14天前
|
缓存 Linux
Linux查看内存命令
1. free free命令是最常用的查看内存使用情况的命令。它显示系统的总内存、已使用内存、空闲内存和交换内存的总量。 free -h • -h 选项:以易读的格式(如GB、MB)显示内存大小。 输出示例: total used free shared buff/cache available Mem: 15Gi 4.7Gi 4.1Gi 288Mi 6.6Gi 9.9Gi Swap: 2.0Gi 0B 2.0Gi • to
27 2