关于qemu的二三事(4)————qemu源码的下载与编译,以及fdt

 

本来这篇文章打算从qemu的源码入手,简要分析一下qemu的执行过程的,但是巧妇难为无米之炊呀,分析qemu源码你得先有源码啊,所以这篇文章就是来解决这个问题的,下一篇文章会通过简要分析一下qemu的源码来理解一下qemu的大致执行流程。


首先来说下,从哪儿下载源码。

我是在qemu的github主页 复制链接,git clone的,你也可以到qemu的官网  去找下载链接,这个可能速度回快点吧,我不太确定。


其次,编译源码。

简单来说,一般的开源软件都会提供README之类的文档告诉你怎么玩的,qemu也不例外。

README里面说的很简单,进入qemu源码目录,然后:

  mkdir build
  cd build
  ../configure
  make
我是这么做的,为了方便自己的debug,创建了一个bin/debug/native/的文件夹,然后:

[root@localhost native]# ../../../configure

ERROR: DTC (libfdt) version >= 1.4.0 not present. Your options:
         (1) Preferred: Install the DTC (libfdt) devel package
         (2) Fetch the DTC submodule, using:
             git submodule update --init dtc

反正按照上边来说的是不行的。yum search  libfdt啥玩意儿也没用找到,用git submodule update --init dtc也不行,好像是被公司防火墙挡住了。

google搜一圈,有说下载libfdt的安装包的,有说去弄什么submodule的,对我而言都不是什么简便方法。

那么vim打开这个 qemu源码根目录下的configure脚本看看,发现是个很长的解析和配置的脚本,里面定义了很多函数和变量。那么我们去来执行一下configure  --help来试试,哈哈,出来了一个usage界面:

[root@localhost qemu]# ./configure --help

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:
  --help                   print this message
  --prefix=PREFIX          install in PREFIX [/usr/local]
  --interp-prefix=PREFIX   where to find shared libraries, etc.
                           use %M for cpu name [/usr/gnemul/qemu-%M]
  --target-list=LIST       set target list (default: build everything)
                           Available targets: aarch64-softmmu alpha-softmmu
                           arm-softmmu cris-softmmu i386-softmmu lm32-softmmu
                           m68k-softmmu microblazeel-softmmu microblaze-softmmu
                           mips64el-softmmu mips64-softmmu mipsel-softmmu
                           mips-softmmu moxie-softmmu or32-softmmu
                           ppc64-softmmu ppcemb-softmmu ppc-softmmu

... ....

很长的一段,我就不单独列举出来了,诸位可以自己试试。最终我给的参数是这样的:
../../../configure --target-list=x86_64-softmmu --enable-debug --enable-kvm     --enable-vnc

成功解决了上边的那个libfdt的问题。这里面的几个参数意义很好理解,第一个参数是说就是x86_64的体系结构,第二个是说要支持代码的debug,第三个是说要支持kvm,第四个参数则是用来支持vnc的,这个很有必要,因为有时候需要进到guest OS里面看看或者操作的,vnc有时候比ssh还是好用多了。

然后,在这个 qemu/bin/debug/native 下面输入:

make

慢慢等它跑完,这就算完了。



一点额外的东西:

那么这个fdt是个什么玩意儿呢?

网上查了查,是这么说的:

The Flattened Device Tree (FDT) is a data structure for describing the hardware in a system. It is a derived from the device tree format used by Open Firmware to encapsulate platform information and convey it to the- operating system. The operating system uses the FDT data to find and register the devices in the system.

Currently the Linux kernel can read device tree information in the x86, Microblaze, PowerPC, and Sparc architectures. There is interest in extending support for device trees to other platforms, to unify the handling of platform description across kernel architectures.

The Flattened Device Tree is...

The Flattened Device Tree (FDT) is a data structure. Nothing more.

It describes a machine hardware configuration. It is derived from the device tree format used by Open Firmware. The format is expressive and able to describe most board design aspects including:

  • the number and type of CPUs,
  • base addresses and size of RAM,
  • busses and bridges,
  • peripheral device connections, and
  • interrupt controllers and IRQ line connections.

Just like initrd images, an FDT image can either be statically linked into the kernel or passed to the kernel at boot time.

反正大致意思就是说FDT就是一个用来描述系统上硬件设备信息的数据结构。








你可能感兴趣的:(Virtualization)