歡迎您光臨本站 註冊首頁

在qemu下實戰linux內核

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  



在qemu下練習linux內核是十分方便的:不用修改內核后每次啟動機器,而且可以很好的調試內核。

安裝交叉編譯器。

這裡選擇The Embedded Linux Development Kit (ELDK),可以從http://www.denx.de/wiki/DULG/ELDK下載。安裝十分簡單,注意需要磁碟上有3G空間。


編譯內核

qemu支持arm的cpu,我們使用下面的命令可以知道qemu能夠模擬的機器。
apple@apple-desktop:~$ qemu-system-arm -M ?
Supported machines are:
syborg     Syborg (Symbian Virtual Platform)
musicpal   Marvell 88w8618 / MusicPal (ARM926EJ-S)
mainstone  Mainstone II (PXA27x)
n800       Nokia N800 tablet aka. RX-34 (OMAP2420)
n810       Nokia N810 tablet aka. RX-44 (OMAP2420)
cheetah    Palm Tungsten|E aka. Cheetah PDA (OMAP310)
sx1        Siemens SX1 (OMAP310) V2
sx1-v1     Siemens SX1 (OMAP310) V1
tosa       Tosa PDA (PXA255)
akita      Akita PDA (PXA270)
spitz      Spitz PDA (PXA270)
borzoi     Borzoi PDA (PXA270)
terrier    Terrier PDA (PXA270)
connex     Gumstix Connex (PXA255)
verdex     Gumstix Verdex (PXA270)
lm3s811evb Stellaris LM3S811EVB
lm3s6965evb Stellaris LM3S6965EVB
realview   ARM RealView Emulation Baseboard (ARM926EJ-S)
versatilepb ARM Versatile/PB (ARM926EJ-S)
versatileab ARM Versatile/AB (ARM926EJ-S)
integratorcp ARM Integrator/CP (ARM926EJ-S) (default)

這裡我選擇versatilepb這個機器。

make mrproper
移除以前產生的文件

make allnoconfig
用這個命令讓內核選項全部是N。這樣我們可以製作出一個最精簡的內核。

make menuconfig

如下是編譯內核的選項。
versatilepb ARM Versatile/PB (ARM926EJ-S)
General setup --->
    * Initial RAM filesystem and RAM disk
System Type --->
    * MMU-based paged Memory Management support
    ARM System type (ARM Ltd. Versatile family)
    Versatile platform type --->
        * Support versatile/PB platform
Kernel Fetures --->
    * use the ARM EABI to compile the kernel
Userspace binary formats --->
    * kernel support for ELE binaries
Device Drivers
    Input device support
        * Key boards
            * AT keyboard
        Hardware I/o ports --->
            * AMBA KMI keyboard controller
    Graphic support
        * support for frame buffer devices->
            *ARM primecell PL110 Support
    Console display driver support
        * Framebuffer console support
File systems --->
    * second extended fs support

make -j4
在雙核cpu上4個進程編譯內核。   


下面是啟動內核的腳本,如果是ubuntu把這個腳本放到$HOME/bin下是十分方便的。

#!/bin/sh

ARGS="-kernel $HOME/arm-test/myzImage -initrd $HOME/arm-test/myinitrd.img "

echo "Starting QEMU with…"
echo $ARGS
echo "…."
exec qemu-system-arm -M versatilepb $ARGS

提示: $HOME/arm-test/myzImage 是上面編譯出的內核
             $HOME/arm-test/myinitrd.img 是自己製作的initrd.


調試內核
           首先要編譯一個帶有調式符號信息的內核

          配置內核下面的選項:
             Kernel hacking --->
                  * Kernel debugging
                  * Compile the kernel with debug info

           qemu運行后在qemu窗口裡按ctrl+alt+2,輸入gdbserver.
           進入內核代碼目錄,在命令行執行arm-gdb vmlinuz
           然後輸入:
                   target remote localhost:1234
                   b 斷點
                   c
            這樣就可以調試內核了。


          





[火星人 ] 在qemu下實戰linux內核已經有404次圍觀

http://coctec.com/docs/program/show-post-71600.html