I can compile and install stuff on yocto by creating a bitbake recipe. I would like to run my code when a specific device is connected.

Is there an elegant way to add a udev rule from a bitbake recipe? Doing something like echo "<my udev rule>" >> /etc/udev/rules.d/90-local.rules does not sound like a good plan...

1 Answer 1


From what I can understand, you want to create a rule when you build the OS and have it reside in the rootfs. If that's correct, then you need to add a recipe for it. Store your rule in a directory such as the following distro/meta-myproject/recipes-core/rfs-myproject/rfs-myproject/*myrule.rule*. Then, up a level in the rfs-myproject folder you need a rfs-myproject_1.0.0.bb. The file should look like the following

SUMMARY = "MyProject Additional files"
PR = "r1"    

SRC_URI = "file://my-rule1.rules file://my-rule2.rules \
           file://startup.sh file://rc.local "    

do_install[nostamp] = "1"
do_unpack[nostamp] = "1"    

do_install () {
    echo "my-project install task invoked"    

    install -m 0755 ${WORKDIR}/startup.sh         ${D}/home/root/startup.sh
    install -m 0777 ${WORKDIR}/rc.local           ${D}${sysconfdir}/rc.d/rc.local
    install -m 0666 ${WORKDIR}/my-rule1.rules     ${D}/etc/udev/rules.d/my-rule1.rules
    install -m 0666 ${WORKDIR}/my-rule2.rules     ${D}/etc/udev/rules.d/my-rule2.rules

FILES_${PN} += " ${sysconfdir}/rc.local"
FILES_${PN} += " /home/root/startup.sh"
FILES_${PN} += " /etc/udev/rules.d/my-rule1.rules"
FILES_${PN} += " /etc/udev/rules.d/my-rule2.rules"    

PROVIDES = "rfs-my-project"

Hopefully this answers your question, if you need further help please let me know.

Oh yeah, don't forget to include my-project in your local.conf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .