yocto-第32篇-qemu Linux kernle默认的配置

By: fu linux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!

qemu虚拟机Linux kernle默认的配置

我们在修改、配置或者更换Linux源码之前,先熟悉下qemu是如何配置Linux Kernel的。

Linux recipe

在poky/meta/recipes-kernel/linux/目录中存放着yocto自带的一些linux recipes文件:

poky]$ ls meta/recipes-kernel/linux/
kernel-devsrc.bb  linux-dummy.bb      linux-yocto-dev.bb  linux-yocto-rt_5.4.bb
linux-dummy       linux-yocto_5.4.bb  linux-yocto.inc     linux-yocto-tiny_5.4.bb
  • 1
  • 2
  • 3

而我们的qemu86-64使用到的linux recipe是linux-yocto_5.4.bb,为什么说是这个呢?
可以从两个途径看:

1.从编译的结果看:

build]$ bitbake -e linux-yocto | grep ^S=
S="/home/peeta/poky/build/tmp/work-shared/qemux86-64/kernel-source"
build]$ cd /home/peeta/poky/build/tmp/work-shared/qemux86-64/kernel-source
kernel-source]$ git log
9466719 Merge tag 'v5.4.50' into v5.4/standard/base (Bruce Ashfield, 6 months ago)
...

 poky]$ ls build/tmp/work/qemux86_64-poky-linux/linux-yocto/5.4.50+gitAUTOINC+416566e1f0_94667198aa-r0/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.从最初的配置看:
首先我们在poky/build/conf/local.conf配置文件中指定了MACHINE变量:

 MACHINE ??= "qemux86-64"
  • 1

source环境后,会进一步调用下面的目录中的qemux86-64.conf配置文件:

poky]$ ls meta/conf/machine/
include         qemuarm.conf    qemumips64.conf  qemuppc.conf      qemux86-64.conf
qemuarm64.conf  qemuarmv5.conf  qemumips.conf    qemuriscv64.conf  qemux86.conf
  • 1
  • 2
  • 3

参考qemux86-64.conf配置文件:

poky]$ cat meta/conf/machine/qemux86.conf 
#@TYPE: Machine
#@NAME: QEMU x86 machine
#@DESCRIPTION: Machine configuration for running an x86 system on QEMU

PREFERRED_PROVIDER_virtual/xserver ?= "xserver-xorg"
PREFERRED_PROVIDER_virtual/libgl ?= "mesa"
PREFERRED_PROVIDER_virtual/libgles1 ?= "mesa"
PREFERRED_PROVIDER_virtual/libgles2 ?= "mesa"

require conf/machine/include/qemu.inc
DEFAULTTUNE ?= "core2-32"
require conf/machine/include/tune-corei7.inc
require conf/machine/include/qemuboot-x86.inc

UBOOT_MACHINE ?= "qemu-x86_defconfig"

KERNEL_IMAGETYPE = "bzImage"

SERIAL_CONSOLES ?= "115200;ttyS0 115200;ttyS1"

XSERVER = "xserver-xorg \
           ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast xserver-xorg-extension-glx', '', d)} \
           xf86-video-cirrus \
           xf86-video-fbdev \
           xf86-video-vmware \
           xf86-video-modesetting \
           xf86-video-vesa \
           xserver-xorg-module-libint10 \
           "

MACHINE_FEATURES += "x86 pci"

MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "v86d"

MACHINE_EXTRA_RRECOMMENDS = "kernel-module-snd-ens1370 kernel-module-snd-rawmidi"

WKS_FILE ?= "qemux86-directdisk.wks"
do_image_wic[depends] += "syslinux:do_populate_sysroot syslinux-native:do_populate_sysroot mtools-native:do_populate_sysroot dosfstools-native:do_populate_sysroot"

#For runqemu
QB_SYSTEM_NAME = "qemu-system-i386"
  • 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
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

在meta/conf/machine/qemux86.conf 文件中又引用了:

require conf/machine/include/qemu.inc
  • 1

参考:require conf/machine/include/qemu.inc:

poky]$ cat meta/conf/machine/include/qemu.inc 
PREFERRED_PROVIDER_virtual/xserver ?= "xserver-xorg"
PREFERRED_PROVIDER_virtual/egl ?= "mesa"
PREFERRED_PROVIDER_virtual/libgl ?= "mesa"
PREFERRED_PROVIDER_virtual/libgles1 ?= "mesa"
PREFERRED_PROVIDER_virtual/libgles2 ?= "mesa"

XSERVER ?= "xserver-xorg \
            ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast xserver-xorg-extension-glx', '', d)} \
            xf86-video-fbdev \
            "

MACHINE_FEATURES = "alsa bluetooth usbgadget screen vfat"

MACHINEOVERRIDES =. "qemuall:"

IMAGE_FSTYPES += "tar.bz2 ext4"

# Don't include kernels in standard images
RDEPENDS_${KERNEL_PACKAGE_NAME}-base = ""

# Use a common kernel recipe for all QEMU machines
PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"

EXTRA_IMAGEDEPENDS += "qemu-native qemu-helper-native"

# Provide the nfs server kernel module for all qemu images
KERNEL_FEATURES_append_pn-linux-yocto = " features/nfsd/nfsd-enable.scc"
KERNEL_FEATURES_append_pn-linux-yocto-rt = " features/nfsd/nfsd-enable.scc"

IMAGE_CLASSES += "qemuboot"
  • 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

重点看下上面的"PREFERRED_PROVIDER_virtual/kernel",注释也说了对所有QEMU机器使用一个通用的Linux kernel recipe,
即linux-yocto。

linux版本在哪里设置?

而在meta/recipes-kernel/linux/linux-yocto_5.4.bb文件中又进一步具体规定了linux的版本:

LINUX_VERSION ?= "5.4.50"
  • 1

linux源码在哪里下载?

在meta/recipes-kernel/linux/linux-yocto_5.4.bb文件中:

SRC_URI = "git://git.yoctoproject.org/linux-yocto.git;name=machine;branch=${KBRANCH}; \
           git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-5.4;destsuffix=${KMETA}"
  • 1
  • 2

其中KBRANCH变量是分支,对应的是:

KBRANCH ?= "v5.4/standard/base"
  • 1

yocto-kernel-cache是什么?

上面的SRC_URI中出现了一个yocto-kernel-cache,是什么呢?
其中KMETA变量如下:

KMETA = "kernel-meta"
  • 1

构建过程中yocto-kernel-cache项目会改名为kernel-meta,并放在如下目录:

poky]$ ls build/tmp/work/qemux86_64-poky-linux/linux-yocto/5.4.50+gitAUTOINC+416566e1f0_94667198aa-r0/kernel-meta/
00-README  backports  cfg  COPYING.GPLv2  features          ktypes  patches  small
arch       bsp        cgl  COPYING.MIT    kern-features.rc  kver    scripts  staging
  • 1
  • 2
  • 3

这里面会有一些kernel配置在cfg文件中,还有一些补丁在patches中。

Linux-yocto使用哪个config配置呢?

Kernel recipe append文件

除了上面的meta目录中放置了QEMU机器通用的kernel recipe外,在如下目录有kernel recipe的append:

poky]$ ls meta-yocto-bsp/recipes-kernel/linux/
linux-yocto_5.4.bbappend  linux-yocto-dev.bbappend
  • 1
  • 2

我们用到了linux-yocto_5.4.bbappend文件,参考如下:

poky]$ cat meta-yocto-bsp/recipes-kernel/linux/linux-yocto_5.4.bbappend   
KBRANCH_genericx86  = "v5.4/standard/base"
KBRANCH_genericx86-64  = "v5.4/standard/base"
...

KMACHINE_genericx86 ?= "common-pc"
KMACHINE_genericx86-64 ?= "common-pc-64"
KMACHINE_beaglebone-yocto ?= "beaglebone"

SRCREV_machine_genericx86 ?= "ec485bd4afef57715eb45ba331b04b3f941e43bb"
SRCREV_machine_genericx86-64 ?= "ec485bd4afef57715eb45ba331b04b3f941e43bb"
...

COMPATIBLE_MACHINE_genericx86 = "genericx86"
COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64"
...

LINUX_VERSION_genericx86 = "5.4.49"
LINUX_VERSION_genericx86-64 = "5.4.49"
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

该文件中同事定义了分支,也定义了KMACHINE变量,我们的是:

KMACHINE_genericx86-64 ?= "common-pc-64"
  • 1

因此对于的kernel configure配置文件就是common-pc-64.*,这个文件就在上面提及的kernel-meta【或yocto-kernel-cache】目录中,如下:

poky]$ cd build/tmp/work/qemux86_64-poky-linux/linux-yocto/5.4.50+gitAUTOINC+416566e1f0_94667198aa-r0/kernel-meta/
kernel-meta]$ find -iname common-pc-64*
./bsp/common-pc-64
./bsp/common-pc-64/common-pc-64.scc
./bsp/common-pc-64/common-pc-64-cpu.cfg
./bsp/common-pc-64/common-pc-64-developer.scc
./bsp/common-pc-64/common-pc-64-preempt-rt.scc
./bsp/common-pc-64/common-pc-64-standard.scc

kernel-meta]$ cat ./bsp/common-pc-64/common-pc-64.scc
# SPDX-License-Identifier: MIT
kconf hardware common-pc-64-cpu.cfg
kconf hardware bsp/common-pc/common-pc-drivers.cfg
kconf hardware bsp/common-pc/common-pc-eth.cfg
kconf hardware bsp/common-pc/common-pc-gfx.cfg
kconf hardware bsp/common-pc/common-pc-wifi.cfg

include cfg/efi-ext.scc

include cfg/x86_64.scc
include cfg/amd.scc
include cfg/intel.scc
include features/pci/pci.scc
include features/pci-iov/pci-iov.scc
include features/mmc/mmc-sdhci.scc
include features/usb/ehci-hcd.scc
include features/usb/uhci-hcd.scc
include features/usb/ohci-hcd.scc
include features/usb/xhci-hcd.scc
include features/usb/touchscreen-composite.scc
include features/usb-net/usb-net.scc
include features/intel-e1xxxx/intel-e100.scc
include features/intel-e1xxxx/intel-e1xxxx.scc
include features/igb/igb.scc
include features/scsi/cdrom.scc

include features/x2apic/x2apic.scc

# generic Bluetooth support
include features/bluetooth/bluetooth.scc

# generic power management
include features/power/intel.scc

# serial port
include cfg/8250.scc

# sugarbay graphics
include features/i915/i915.scc
  • 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
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

在poky/meta/recipes-kernel/linux/linux-yocto_5.4.bb文件中,还append另外的FEATURES(特性),也就是configuration,参考:

KERNEL_FEATURES_append_qemux86-64=" cfg/sound.scc cfg/paravirt_kvm.scc"
  • 1

同时COMPATIBLE_MACHINE变量也声明了兼容的机器:

COMPATIBLE_MACHINE_genericx86-64 = "genericx86-64"
  • 1

内核编译选项查看

在meta/recipes-kernel/linux/linux-yocto.inc文件中有这样的定义:

KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
  • 1
  • 2

分别是编译和连接时候的选项,通过如下命令查看:

build]$ bitbake -e linux-yocto | grep TOOLCHAIN_OPTIONS
#     "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
...
TOOLCHAIN_OPTIONS=" --sysroot=/home/peeta/poky/build/tmp/work/qemux86_64-poky-linux/linux-yocto/5.4.50+gitAUTOINC+416566e1f0_94667198aa-r0/recipe-sysroot"
  • 1
  • 2
  • 3
  • 4

带来sysroot参数,同时查看HOST_CC_ARCH变量的值如下:

build]$ bitbake -e linux-yocto | grep ^HOST_CC_ARCH
HOST_CC_ARCH=" -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security"
  • 1
  • 2

这个变量可以告诉我们,在使用外部SDK编译内核的时候可以指定这些编译选项。当然我们现在只需知道是这么回事。

内核镜像文件格式查看

对于Linux内核,编译可以生成不同格式的镜像文件,比如有bzImage和uImage,如下查看:

build]$ bitbake -e linux-yocto | grep ^KERNEL_IMAGETYPE=
KERNEL_IMAGETYPE="bzImage"
  • 1
  • 2

该定义位于meta/conf/machine/qemux86-64.conf文件中:

KERNEL_IMAGETYPE = "bzImage"
  • 1

dts/dtb文件查看

我专门查找了一下dts文件配置情况,但是找遍了好像也没有找到,在源码里面:

poky]$ cd /home/peeta/poky/build/tmp/work-shared/qemux86-64/kernel-source
kernel-source]$ find ./arch/x86/ -iname *.dts
./arch/x86/platform/ce4100/falconfalls.dts
  • 1
  • 2
  • 3

可见在linux内核源码x86架构中是没有发现dts文件的,不同于arm架构。