用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

 

未完待续。

相关文章
|
21天前
|
存储 安全 Linux
探索Linux操作系统的心脏:内核
在这篇文章中,我们将深入探讨Linux操作系统的核心—内核。通过简单易懂的语言和比喻,我们会发现内核是如何像心脏一样为系统提供动力,处理数据,并保持一切顺畅运行。从文件系统的管理到进程调度,再到设备驱动,我们将一探究竟,看看内核是怎样支撑起整个操作系统的大厦。无论你是计算机新手还是资深用户,这篇文章都将带你领略Linux内核的魅力,让你对这台复杂机器的内部运作有一个清晰的认识。
50 3
|
1月前
|
Linux
用clang编译Linux内核
用clang编译Linux内核
|
1月前
|
Linux API 调度
关于在Linux内核中使用不同延迟/休眠机制 【ChatGPT】
关于在Linux内核中使用不同延迟/休眠机制 【ChatGPT】
|
4天前
|
Linux Python Perl
Linux命令删除文件里的字符串
Linux命令删除文件里的字符串
15 7
|
4天前
|
Shell Linux
Linux shell编程学习笔记82:w命令——一览无余
Linux shell编程学习笔记82:w命令——一览无余
|
20天前
|
设计模式 Java Linux
Linux的20个常用命令
Linux的23个常用命令
Linux的20个常用命令
|
6天前
|
Linux Perl
Linux之sed命令
Linux之sed命令
|
6天前
|
Linux
深入理解Linux中的cp命令:文件与目录的复制利器
深入理解Linux中的cp命令:文件与目录的复制利器
|
6天前
|
Linux Docker 容器
9. 同步执行Linux多条命令
9. 同步执行Linux多条命令
|
6天前
|
Linux Shell
10-10|linux命令查询 关键字在文本中出现的行数
10-10|linux命令查询 关键字在文本中出现的行数
下一篇
无影云桌面