介绍
我在一个BitBake配方中编写了一个名为do_install
的任务,用于驱动程序,在该任务中我执行一个自定义的install
脚本。该任务失败,因为安装脚本无法在<the image rootfs>/usr/src/kernel
中找到内核源文件头。该脚本在生成的操作系统上运行良好。
发生了什么
这是我配方的相关部分:
SRC_URI += "file://${TOPDIR}/example"
DEPENDS += " virtual/kernel linux-libc-headers "
do_install () {
( cd ${TOPDIR}/example/Install ; ./install )
}
这是install
脚本的相关部分:
if [ ! -d "/usr/src/kernel/include" ]; then
echo ERROR: Linux kernel source include directory not found.
exit 1
fi
cd /usr/src/kernel
make scripts
...
./install_drv pci ${DRV_ARGS}
我尝试更改为
if [ ! -d "/usr/src/kernel" ]
,但仍然失败了。 install
命令将不同的选项传递给install_drv
,下面是相关部分:cd ${DRV_PATH}/pci
make NO_SYSFS=${ARG_NO_SYSFS} NO_INSTALL=${ARG_NO_INSTALL} ${ARGS_HWINT}
if [ ${ARG_NO_INSTALL} == 0 ]; then
if [ `/sbin/lsmod | grep -ci "uceipci"` -eq 1 ]; then
./unload_pci
fi
./load_pci DEBUG=${ARG_DEBUG}
fi
${DRV_PATH}/pci
目录下的make
目标build:
实际上是这样的:
make -C /usr/src/kernel SUBDIRS=${PWD} modules
我的研究
我发现在 linux-libc-headers.inc
中有以下相关评论:
# You're probably looking here thinking you need to create some new copy
# of linux-libc-headers since you have your own custom kernel. To put
# this simply, you DO NOT.
#
# Why? These headers are used to build the libc. If you customise the
# headers you are customising the libc and the libc becomes machine
# specific. Most people do not add custom libc extensions to the kernel
# and have a machine specific libc.
#
# But you have some kernel headers you need for some driver? That is fine
# but get them from STAGING_KERNEL_DIR where the kernel installs itself.
# This will make the package using them machine specific but this is much
# better than having a machine specific C library. This does mean your
# recipe needs a DEPENDS += "virtual/kernel" but again, that is fine and
# makes total sense.
#
# There can also be a case where your kernel extremely old and you want
# an older libc ABI for that old kernel. The headers installed by this
# recipe should still be a standard mainline kernel, not your own custom
# one.
我有些不清楚如果我没有使用make,是否能够正确地获取STAGING_KERNEL_DIR
的头文件。
在meta/classes
目录中提供的kernel.bbclass
中,有这个变量赋值:
# Define where the kernel headers are installed on the target as well as where
# they are staged.
KERNEL_SRC_PATH = "/usr/src/kernel"
这条路径稍后将在此 .bbclass
文件中打包:
PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules"
...
FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build"
更新(1/21):
在yocto IRC频道上的建议是使用以下行:
do_configure[depends] += "virtual/kernel:do_shared_workdir"
这一点得到了Yocto项目参考手册的证实,该手册说明在版本1.8中有以下更改:
The kernel build process was changed to place the source in a common shared work area and to place build artifacts separately in the source code tree. In theory, migration paths have been provided for most common usages in kernel recipes but this might not work in all cases. In particular, users need to ensure that
${S}
(source files) and${B}
(build artifacts) are used correctly in functions such asdo_configure
anddo_install
. For kernel recipes that do not inherit fromkernel-yocto
or includelinux-yocto.inc
, you might wish to refer to thelinux.inc
file in themeta-oe
layer for the kinds of changes you need to make. For reference, here is the commit where thelinux.inc
file inmeta-oe
was updated.Recipes that rely on the kernel source code and do not inherit the module classes might need to add explicit dependencies on the
do_shared_workdir
kernel task, for example:
do_configure[depends] += "virtual/kernel:do_shared_workdir"
但我在将此应用于我的食谱时遇到了困难。据我所知,我应该能够将上述行更改为:
do_install[depends] += "virtual/kernel:do_shared_workdir"
这将意味着现在必须在virtual/kernel配方的do_shared_workdir任务之后运行do_install任务,这意味着我应该能够使用共享工作目录(请参见下面的问题3),但我仍然有相同的缺少内核头文件问题。
我的问题
我正在使用来自git.kernel.org的自定义Linux内核(v3.14),它继承了kernel类。以下是我的一些问题:
- 如果继承了
kernel
类,那么kernel-dev
包不应该成为任何配方的一部分吗? (变量词汇表中的这个部分) - 如果我将
virtual/kernel
添加到DEPENDS
变量中,那么kernel-dev
会被引入吗? - 如果
kernel-dev
是我的配方的依赖项之一,那么我是否可以从我的配方指向/usr/src/kernel
目录?根据Yocto邮件列表上的这篇回复,我认为我可以。 如何正确引用内核源文件头文件,最好不更改安装脚本?
example/Install
脚本是做什么的吗?它需要哪些内核头文件?你需要真正的内核头文件,还是只需要 linux-libc-headers? - Anders