Yocto - select the right configuration file based on image type

江枫思渺然 提交于 2021-02-20 00:40:30

问题


In my pretty standard Yocto build I have the openssh included. Its configuration file, /etc/ssh/sshd_config, should naturally be different for production and development images (for example one would like root login on development image and not on production one). The production and the development images are different recipes (.bb files) in recipes-core/images under my layer, which includes some other stuff as well. In order to achieve customization for the sshd_config file, I've created recipes-connectivity/openssh directory under my layer with openssh_%.bbappend with just the following content:

SUMMARY = "OpenSSH configuration"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

And in the files directory, I've got my own sshd_conf. This works fine, my file is used instead of openssh's default one. But how can I have, say, two separate files that will affect the two different resulting rootfs's? The closest I've seen is this question, and this answer seems just too simple to be true. I've tried using my image names for folders, but all I got is the default conf file in both resulting image builds. The second answer seams reasonable, but AFAIK I can't replace a file coming from other recipe (please correct me if I'm wrong), so probably that was quite a specific case for the OP that worked. Running a post-install script is not an option, since the rootfs is read-only on the target. Studying the _append_xxxx stuff in the manual did not push me to the right direction as well.

Hope someone could share some experience on that, as this seems a pretty straightforward issue that should have some built-in solution.

Thanks.


回答1:


With the kind help I've received so far and several other answers, I've reached a working solution.

In my layer there's the recipes-connectivity/openssh/openssh_%.bbappend with the following contents:

do_install_append () {
    rm ${D}${sysconfdir}/ssh/sshd_config
}

This removes the sshd_config file installed by the original openssh recipe.

Next, there are two additional recipes in my layer: recipes-core/openssh_conf_prod/openssh_conf_dev_0.1.bb and recipes-core/openssh_conf_prod/openssh_conf_prod_0.1.bb. In both recipe directories under files subdirectory there's an opensshd_conf file, different for dev and prod. The .bb recipes are identical for both cases, though:

DEPENDS = "openssh"

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

SRC_URI = "file://sshd_config"

S = "${WORKDIR}"

do_install() {
    install -d ${D}${sysconfdir}/ssh
    install ${WORKDIR}/sshd_config ${D}${sysconfdir}/ssh
}

(*) Note the DEPENDS in the beginning.

What the recipe does is just verifies there's a destination directory to copy the file to, and copies the file it has under the files directory to the target rootfs.

Then, of course, the prod and dev image files under my recipe's recipes-core/images directory include each the relevant openssh_conf_dev or openssh_conf_prod recipes under, for example, the CORE_IMAGE_EXTRA_INSTALL_append variable.

To conclude, the flow is:

  1. openssh is being installed as required by the image recipe.
  2. The sshd_config is being deleted by the new .bbappend recipe for openssh.
  3. Each type of image calls its own recipe, which adds the right configuration file to the right folder.

I am not sure how elegant this is, but it does the job.



来源:https://stackoverflow.com/questions/56504824/yocto-select-the-right-configuration-file-based-on-image-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!