How do I modify a rootfs configuration file with Yocto?

China☆狼群 提交于 2021-02-17 00:01:15

问题


I'm using Thud (2.6) and I'd like to clear the contents of /etc/default/dropbear. ROOTFS_POSTPROCESS_COMMAND seemed promising but the following failed to create the empty file. There were no errors.

Other work done by the recipe succeeds.

SRC_URI += "file://authorized_keys"
SRC_URI += "file://dropbear_rsa_host_key"
# Configuration file to be installed in /etc/default.
# SRC_URI += "file://dropbear"

S = "${WORKDIR}"

do_install() {

install -d ${D}/etc/dropbear
install -m 0600 ${S}/authorized_keys ${D}/etc/dropbear
install -m 0600 ${S}/dropbear_rsa_host_key ${D}/etc/dropbear

}

clear_dropbear_default_configuration() {

rm ${D}/etc/default/dropbear
touch ${D}/etc/default/dropbear
echo "Hello" > hello.txt

}

FILES_${PN} += "/etc/dropbear"

FILES_${PN} += "/etc/dropbear/authorized_keys"

FILES_${PN} += "/etc/dropbear/dropbear_rsa_host_key"

ROOTFS_POSTPROCESS_COMMAND += "clear_dropbear_default_configuration;"

# FILES_${PN} += "/etc/default/dropbear"

回答1:


I believe ROOTFS_POSTPROCESS_COMMAND is what you want, but you can't call it from a package recipe like that. In our application, we created a new .inc file with some common functions in the same directory as our .bb image creation recipes and included it in the recipes that build our target images. This is where we put these directives and functions (I have 4 to make symlinks and reset the root password). The challenge is that the postprocess can't call your recipe again, and I'm not sure how it might work to try to predeclare a function like this to be called later. Note the syntax is exactly right by the looks of it, just not in the right location to run when needed.

image-base.inc

ROOTFS_POSTPROCESS_COMMAND += "clear_dropbear_default_configuration;"

clear_dropbear_default_configuration() {
    rm ${D}/etc/default/dropbear
    touch ${D}/etc/default/dropbear
    echo "Hello" > hello.txt
}

image-name.bb

require image-base.inc

You could also just add this to the .bb which is your bitbake directly if you wanted. I like the .inc files though as they make it easier to share among similar entries. Note this example ignores the other content, but you can freeform where it belongs.

If you don't want to change the existing target, you can create your own and then require the image.bb in your new image recipe.



来源:https://stackoverflow.com/questions/56712338/how-do-i-modify-a-rootfs-configuration-file-with-yocto

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