用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

 

未完待续。

相关文章
|
5月前
|
安全 网络协议 Linux
深入理解Linux内核模块:加载机制、参数传递与实战开发
本文深入解析了Linux内核模块的加载机制、参数传递方式及实战开发技巧。内容涵盖模块基础概念、加载与卸载流程、生命周期管理、参数配置方法,并通过“Hello World”模块和字符设备驱动实例,带领读者逐步掌握模块开发技能。同时,介绍了调试手段、常见问题排查、开发规范及高级特性,如内核线程、模块间通信与性能优化策略。适合希望深入理解Linux内核机制、提升系统编程能力的技术人员阅读与实践。
542 1
|
5月前
|
监控 Ubuntu Linux
什么Linux,Linux内核及Linux操作系统
上面只是简单的介绍了一下Linux操作系统的几个核心组件,其实Linux的整体架构要复杂的多。单纯从Linux内核的角度,它要管理CPU、内存、网卡、硬盘和输入输出等设备,因此内核本身分为进程调度,内存管理,虚拟文件系统,网络接口等4个核心子系统。
380 0
|
5月前
|
Web App开发 缓存 Rust
|
5月前
|
Ubuntu 安全 Linux
Ubuntu 发行版更新 Linux 内核,修复 17 个安全漏洞
本地攻击者可以利用上述漏洞,攻击 Ubuntu 22.10、Ubuntu 22.04、Ubuntu 20.04 LTS 发行版,导致拒绝服务(系统崩溃)或执行任意代码。
|
Linux 网络架构
u-boot引导友善之臂Linux内核
u-boot引导友善之臂Linux内核 作者:kangear                        Email:kangear@163.com                       Blog:kangear.blog.chinaunix.net 当我刚接触u-boot时,不想自产自用,先用人家移植好的。
964 0
|
4月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
570 1
二、Linux文本处理与文件操作核心命令
|
4月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
364 137
|
4月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
841 57
|
3月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
718 2