yocto系列讲解 (实战篇) 60 - 定义自己的临时配置模板的目录

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

返回总目录 Yocto开发讲解系列 - 总目录

问题来源

在上一篇 yocto系列讲解 (实战篇) 59 - 程序开机自启动(systemd) 中我们发现一个问题,就是在某个 recipe 的bb文件中添加的某些 feature (比如还有某些可选的软件包,编译属性,还有一些顶层配置)语句,并不能在全局上面生效。这个很容易理解,比如 core-image-sato systemd 都是相对独立的 recipes ,那么我们在 core-image-sato 中去添加某个 DISTRO_FEATURES ,并不会在 systemd 中去生效,所以我们在单独编译systemd的时候就出现了在 DISTRO_FEATURES 中没有systemd的 feature 的错误。
后来我们就在 build/local.conf 文件中添加了需要的 feature 等变量,也确实生效了。但是话又说回来,这个 build 目录下的东西都是临时的,那其他用户在编译前都得在local.conf中去添加一些配置(比如MACHINE和DISTRO等变量)那多费事。而且也有修改local.conf的实际需求,那么,我们能不能将修改后的local.conf给固定起来集成到meta-mylayer中去呢?答案是可以的。

conf目录

我们知道下载下来的 poky 源码目录中是没有 build 目录的,是通过 source 命令间接创建的,这个 build 目录下一个关键的目录就是 conf 目录了,见下面:

poky]$ ls build/conf/
bblayers.conf  devtool.conf  local.conf  templateconf.cfg
  • 1
  • 2

实际上这个目录下的配置文件是有模板的,它们都是来自如下目录:

poky]$ ls meta-poky/conf/
bblayers.conf.sample  distro      local.conf.sample           site.conf.sample
conf-notes.txt        layer.conf  local.conf.sample.extended
  • 1
  • 2
  • 3

比如这个:

poky]$ cat meta-poky/conf/bblayers.conf.sample    
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  ##OEROOT##/meta \
  ##OEROOT##/meta-poky \
  ##OEROOT##/meta-yocto-bsp \
  "
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

很显然,对于其他小白开发人员而言,它们并不知道如何使用命令去添加某个 metadata ,比如我们之前创建的 meta-mylayer 或者 meta-mybsp 等,如果不想让他们麻烦可以直接这些 layers 添加到这个 bblayers.conf.sample 中即可,例如:

# bblayers.conf.sample
...

BBLAYERS ?= " \
  ##OEROOT##/meta \
  ##OEROOT##/meta-poky \
  ##OEROOT##/meta-yocto-bsp \
  ##OEROOT##/meta-mylayer \ #添加这个
  "
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

But, 我们的原则是不修改poky源码目录,避免以后升级维护等等带来麻烦。应该怎么做比较好呢?

创建自己的conf目录

我们最好的做法是将这些配置文件的模板放到自己的layer目录中,比如放到 meta-mylayer 目录中。首先是将meta-poky/conf模板复制到meta-mylayer目录中:

poky]$ cp meta-poky/conf/*.sample meta-mylayer/conf/
poky]$ cp meta-poky/conf/conf-notes.txt meta-mylayer/conf/
  • 1
  • 2

复制完上面的模板后,我们参考build/conf目录下的一些配置文件(之前开发过程中已经修改的内容),对模板文件进行修改,或者也可以直接复制,例如:

poky]$ cp build/conf/local.conf meta-mylayer/conf/local.conf.sample
poky]$ vim meta-mylayer/conf/bblayers.conf.sample
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  ##OEROOT##/meta \
  ##OEROOT##/meta-poky \
  ##OEROOT##/meta-yocto-bsp \
  ##OEROOT##/meta-mylayer \ #添加了这些内容
  ##OEROOT##/meta-mybsp \
  ##OEROOT##/meta-qt5 \
  "
poky]$ vim meta-mylayer/conf/conf-notes.txt
... 
Hello, You can now run 'bitbake <target>' #添加了Hello,
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

完成了,上面的步骤后,我们还需要修改一个文件,那就是在poky根目录下.templateconf文件,查看源内容:

poky]$ vim .templateconf
# Template settings
TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  • 1
  • 2
  • 3

此时我们需要将其模板的路径来源改成meta-mylayer/,如下:

poky]$ vim .templateconf
# Template settings
TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/conf}
  • 1
  • 2
  • 3

验证方法

验证的话,我们可以删除build目录,但是也可以将原先的build目录改个名字:

poky]$ mv build/ build.bak
  • 1

然后,source环境和开始编译:

poky]$ source oe-init-build-env 
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.

You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.

The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
    http://yoctoproject.org/documentation

For more information about OpenEmbedded see their website:
    http://www.openembedded.org/


### Shell environment set up for builds. ###

Hello, You can now run 'bitbake <target>' #有Hello, 

Common targets are:
    core-image-minimal
    core-image-sato
    meta-toolchain
    meta-ide-support
...
  • 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

查看下build目录下新建的配置文件:

build]$ ls conf/
bblayers.conf  local.conf  templateconf.cfg
build]$ cat conf/bblayers.conf  #例如
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/peeta/poky/meta \
  /home/peeta/poky/meta-poky \
  /home/peeta/poky/meta-yocto-bsp \
  /home/peeta/poky/meta-mylayer \
  /home/peeta/poky/meta-mybsp \
  /home/peeta/poky/meta-qt5 \
  "
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

大家可以具体看下,每个配置文件是否来源于模板。

可以根据需要开始编译,如果不需要自己定义的模板,可以将下面的文件内容改回来。

poky]$ vim .templateconf
# Template settings
TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
  • 1
  • 2
  • 3

总之,这个方法可以帮助我们定义临时的配置目录,但是它人就需要修改原始的.templateconf文件,这个对于我们的原则而言,问题大也不算大,不过我后面还会寻求更加理想的做法。

感谢阅读!您的点赞加收藏就是我持续更新的动力!