【記錄】嘗試用QEMU模擬ARM開發板去加載並運行Uboot,kernel,rootfs【轉】

轉自:https://www.crifan.com/try_use_qemu_emulate_arm_board_to_load_and_run_uboot_kernel_rootfs/php

【背景】html

手上有一個嵌入式Linux的項目。linux

已經用交叉編譯器arm-xscale-linux-gnueabi去編譯了Uboot和kernel:ios

【記錄】Ubuntu下用arm-xscale-linux-gnueabi交叉編譯ubootshell

【記錄】Ubuntu下用arm-xscale-linux-gnueabi交叉編譯linux-2.6.19.1內核json

且已經有了對應的rootfs了,因此算是基本齊全了。ubuntu

後來得知有個QEMU,和SkyEye相似,能夠模擬arm開發板。api

因此,嘗試去試試,可否在Ubuntu下,用QEMU去模擬加載並運行Uboot,kernel,rootfs。app

【折騰過程】eclipse

1.再去看看關於QEMU的介紹資料:

QEMU (簡體中文)

QEMU Main Page

2.其下載頁面:

http://wiki.qemu.org/Download

下載QEMU:

http://wiki.qemu-project.org/download/qemu-1.6.0-rc3.tar.bz2

解壓獲得源碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
crifan@ubuntu:qemu-1.6.0-rc3$ tar xvfj qemu-1.6.0-rc3. tar .bz2
 
crifan@ubuntu:qemu-1.6.0-rc3$ ls
aio-posix.c              cputlb.c          linux-headers     qdict- test -data.txt     qmp-commands.hx    target-sparc
aio-win32.c              default-configs   linux-user        qemu-bridge-helper.c    qobject            target-unicore32
arch_init.c              device-hotplug.c  main-loop.c       qemu-char.c             qom                target-xtensa
async.c                  device_tree.c     MAINTAINERS       qemu-coroutine.c        qtest.c            tcg
audio                    disas             Makefile          qemu-coroutine-io.c     readline.c         tcg-runtime.c
backends                 disas.c           Makefile.objs     qemu-coroutine-lock.c   README             tci.c
balloon.c                dma-helpers.c     Makefile.target   qemu-coroutine- sleep .c  roms               tests
block                    docs              memory.c          qemu-doc.texi           rules.mak          thread-pool.c
block.c                  dtc               memory_mapping.c  qemu-img.c              savevm.c           thunk.c
blockdev.c               dump.c            migration.c       qemu-img-cmds.hx        scripts            tpm.c
blockdev-nbd.c           exec .c            migration- exec .c  qemu-img.texi           slirp              trace
blockjob.c               fpu               migration-fd.c    qemu-io.c               spice-qemu-char.c  trace-events
block-migration.c        fsdev             migration-rdma.c  qemu-io-cmds.c          stubs              translate-all.c
bsd-user                 gdbstub.c         migration-tcp.c   qemu-log.c              sysconfigs         translate-all.h
bt-host.c                gdb-xml           migration-unix.c  qemu-nbd.c              target-alpha       ui
bt-vhci.c                HACKING           monitor.c         qemu-nbd.texi           target-arm         user- exec .c
Changelog                hmp.c             nbd.c             qemu.nsi                target-cris        util
CODING_STYLE             hmp-commands.hx   net               qemu-options.h          target-i386        VERSION
configure                hmp.h             os-posix.c        qemu-options.hx         target-lm32        version.rc
COPYING                  hw                os-win32.c        qemu-options-wrapper.h  target-m68k        vl.c
COPYING.LIB              include           page_cache.c      qemu.sasl               target-microblaze  xbzrle.c
coroutine-gthread.c      iohandler.c       pc-bios           qemu-seccomp.c          target-mips        xen-all.c
coroutine-sigaltstack.c  ioport.c          pixman            qemu-tech.texi          target-moxie       xen-mapcache.c
coroutine-ucontext.c     kvm-all.c         po                qemu-timer.c            target-openrisc    xen-stub.c
coroutine-win32.c        kvm-stub.c        qapi              qga                     target-ppc
cpu- exec .c               libcacard         qapi-schema.json  QMP                     target-s390x
cpus.c                   LICENSE           qdev-monitor.c    qmp.c                   target-sh4
crifan@ubuntu:qemu-1.6.0-rc3$ pwd
/home/crifan/develop/embedded/qemu/qemu-1 .6.0-rc3

3.參考官網的文檔:

http://wiki.qemu.org/Manual

中的:

Virtual Development Board

Debian on an emulated ARM machine

QEMU Emulator User Documentation

去折騰。

4.先去在Ubuntu的Host上爲arm平臺安裝QEMU:

【記錄】在Ubuntu 13.04上爲arm平臺安裝QEMU

5.而後再去下載測試軟件:

http://wiki.qemu.org/download/arm-test-0.2.tar.gz

而後解壓:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
crifan@ubuntu:qemu-1.6.0-rc3$ pwd
/home/crifan/develop/embedded/qemu/qemu-1 .6.0-rc3
crifan@ubuntu:qemu-1.6.0-rc3$ cd ..
crifan@ubuntu:qemu$ ls
qemu-1.6.0-rc3  qemu-1.6.0-rc3. tar .bz2
crifan@ubuntu:qemu$ mkdir test
crifan@ubuntu:qemu$ cd test
crifan@ubuntu: test $ mkdir arm
crifan@ubuntu: test $ cd arm
crifan@ubuntu:arm$ wget http: //wiki .qemu.org /download/arm-test-0 .2. tar .gz
--2013-08-15 03:02:29--  http: //wiki .qemu.org /download/arm-test-0 .2. tar .gz
Resolving wiki.qemu.org (wiki.qemu.org)... 140.211.15.109
Connecting to wiki.qemu.org (wiki.qemu.org)|140.211.15.109|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3310162 (3.2M) [application /x-gzip ]
Saving to: ‘arm- test -0.2. tar .gz’
 
100%[=======================================================================================================>] 3,310,162    978KB /s   in 3.4s  
 
2013-08-15 03:02:35 (938 KB /s ) - ‘arm- test -0.2. tar .gz’ saved [3310162 /3310162 ]
 
crifan@ubuntu:arm$ ls
arm- test -0.2. tar .gz
crifan@ubuntu:arm$ tar xf arm- test -0.2. tar .gz
crifan@ubuntu:arm$ ls
arm- test  arm- test -0.2. tar .gz
crifan@ubuntu:arm$ cd arm- test /
crifan@ubuntu:arm- test $ ls
arm_root.img  README  zImage.integrator
crifan@ubuntu:arm- test $ pwd
/home/crifan/develop/embedded/qemu/test/arm/arm-test
crifan@ubuntu:arm- test $

6.再去測試,結果只輸出一行VNC:

【已解決】QUEMU安裝完畢後測試arm出錯:只有一行VNC server running on `127.0.0.1:5900′沒其餘輸出

解決後,能夠看到QEMU的arm的linux界面了:

7.再去測試測試arm的hello world是否可用。

先寫個hello_qemu.c:

?
1
2
3
4
5
6
7
#include <stdio.h>
 
int main( void )
{
     printf ( "Hello QEMU for ARM !\n" );
     return 0;
}

再去用本身的交叉編譯器arm-xscale-linux-gnueabi去編譯:

?
1
2
3
4
crifan@ubuntu:helloworld$ arm-xscale-linux-gnueabi-gcc -o hello_qemu hello_qemu.c
crifan@ubuntu:helloworld$ file hello_qemu
hello_qemu: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU /Linux 2.6.19, not stripped
crifan@ubuntu:helloworld$

而後去運行試試:

先去找到sysroot的路徑,是參考以前的折騰:

【已解決】Eclipse經過Makefile調用交叉編譯器交叉編譯C項目出錯:Type ‘FILE’ could not be resolved

的路徑:

/opt/crosscompile/xscale/gcc-4.6.0-glibc-2.9/arm-xscale-linux-gnueabi/sysroot/usr/include

因此sysroot,應該是:

/opt/crosscompile/xscale/gcc-4.6.0-glibc-2.9/arm-xscale-linux-gnueabi/sysroot

因此去試試:

?
1
2
3
crifan@ubuntu:helloworld$ qemu-arm -L /opt/crosscompile/xscale/gcc-4 .6.0-glibc-2.9 /arm-xscale-linux-gnueabi/sysroot hello_qemu
Hello QEMU for ARM !
crifan@ubuntu:helloworld$

說明交叉工具鏈是正常的。

8.再去折騰uboot:

【記錄】Ubuntu下測試QEMU中加載和測試Uboot

9.而後再去下載編譯kernel:

【記錄】Ubuntu下測試QEMU中加載和測試Linux內核

10.而後再去弄Open TFTP Server:

【記錄】Ubuntu下爲QEMU安裝Open TFTP Server

11.而後再去折騰qemu-ifup & qemu-ifdown:

【記錄】Ubuntu下爲QEMU準備qemu-ifup和qemu-ifdown

12.都準備好了,就能夠去啓動內核了:

【記錄】Ubuntu下使用QEMU啓動Linux內核

13.折騰完畢內核,就能夠去弄rootfs了:

【記錄】Ubuntu下爲QEMU創建一個arm平臺的可用的根文件系統rootfs

 

【總結】

此處,已經能夠正常運行,一個基於busybox的,從ram啓動的rootfs了。

至此,算是基本可用了。

有空再折騰,如何從uboot啓動內核,從nfs加載rootfs等等內容。

轉載請註明:在路上 » 【記錄】嘗試用QEMU模擬ARM開發板去加載並運行Uboot,kernel,rootfs

相關文章
相關標籤/搜索