用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
深入理解Linux内核调度器
本文探讨了Linux操作系统核心组件之一——内核调度器的工作原理和设计哲学。不同于常规的技术文章,本摘要旨在提供一种全新的视角来审视Linux内核的调度机制,通过分析其对系统性能的影响以及在多核处理器环境下的表现,揭示调度器如何平衡公平性和效率。文章进一步讨论了完全公平调度器(CFS)的设计细节,包括它如何处理不同优先级的任务、如何进行负载均衡以及它是如何适应现代多核架构的挑战。此外,本文还简要概述了Linux调度器的未来发展方向,包括对实时任务支持的改进和对异构计算环境的适应性。
18 6
|
3天前
|
缓存 Linux 开发者
Linux内核中的并发控制机制:深入理解与应用####
【10月更文挑战第21天】 本文旨在为读者提供一个全面的指南,探讨Linux操作系统中用于实现多线程和进程间同步的关键技术——并发控制机制。通过剖析互斥锁、自旋锁、读写锁等核心概念及其在实际场景中的应用,本文将帮助开发者更好地理解和运用这些工具来构建高效且稳定的应用程序。 ####
17 5
|
1天前
|
算法 Linux 调度
深入理解Linux内核调度器:从基础到优化####
本文旨在通过剖析Linux操作系统的心脏——内核调度器,为读者揭开其高效管理CPU资源的神秘面纱。不同于传统的摘要概述,本文将直接以一段精简代码片段作为引子,展示一个简化版的任务调度逻辑,随后逐步深入,详细探讨Linux内核调度器的工作原理、关键数据结构、调度算法演变以及性能调优策略,旨在为开发者与系统管理员提供一份实用的技术指南。 ####
14 4
|
3天前
|
算法 Unix Linux
深入理解Linux内核调度器:原理与优化
本文探讨了Linux操作系统的心脏——内核调度器(Scheduler)的工作原理,以及如何通过参数调整和代码优化来提高系统性能。不同于常规摘要仅概述内容,本摘要旨在激发读者对Linux内核调度机制深层次运作的兴趣,并简要介绍文章将覆盖的关键话题,如调度算法、实时性增强及节能策略等。
|
3天前
|
缓存 运维 网络协议
深入Linux内核架构:操作系统的核心奥秘
深入Linux内核架构:操作系统的核心奥秘
17 2
|
9天前
|
缓存 监控 Linux
|
12天前
|
Linux Shell 数据安全/隐私保护
|
13天前
|
域名解析 网络协议 安全
|
1天前
|
Linux
在 Linux 系统中,“cd”命令用于切换当前工作目录
在 Linux 系统中,“cd”命令用于切换当前工作目录。本文详细介绍了“cd”命令的基本用法和常见技巧,包括使用“.”、“..”、“~”、绝对路径和相对路径,以及快速切换到上一次工作目录等。此外,还探讨了高级技巧,如使用通配符、结合其他命令、在脚本中使用,以及实际应用案例,帮助读者提高工作效率。
10 3
|
1天前
|
安全 网络协议 Linux
本文详细介绍了 Linux 系统中 ping 命令的使用方法和技巧,涵盖基本用法、高级用法、实际应用案例及注意事项。
本文详细介绍了 Linux 系统中 ping 命令的使用方法和技巧,涵盖基本用法、高级用法、实际应用案例及注意事项。通过掌握 ping 命令,读者可以轻松测试网络连通性、诊断网络问题并提升网络管理能力。
8 3