1

I am new, yocto build at imx6q embedded system.

I want to overwrite linux system files after do_rootfs. For example, target system files are below.

  • /etc/network/interface
  • /etc/issue
  • /etc/init.d/rcS
  • /home/root/mytest.sh

so, i made custom layer and custom recipe. helloworld binary is copy ok.
but, do_mytask function is not called.

what's wrong with my code? or any other method for my purpose.

#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
#
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://helloworld.c"

S = "${WORKDIR}"

do_compile() {
         ${CC} helloworld.c -o helloworld
}

do_install() {
         install -d ${D}${bindir}
         install -m 0755 helloworld ${D}${bindir}
}   

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
  file://interfaces \
  file://issue \
  file://mytest.sh \
"

addtask mytask after do_rootfs before do_image
do_mytask() {
         install -d ${D}/etc/network
         cp -af ${WORKDIR}/interfaces ${D}/etc/network/interfaces
         cp -af ${WORKDIR}/issue ${D}/etc/issue
}
Chris Gong
  • 8,031
  • 4
  • 30
  • 51
dev j
  • 39
  • 3
  • 6

4 Answers4

7

You'll need to extend the recipes that provide the files you want to replace.

Using /etc/network/interfaces as an example, the first step is to figure out which recipe installs that file.

From the bitbake prompt:

$ oe-pkgdata-util find-path /etc/network/interfaces
init-ifupdown: /etc/network/interfaces

So this tells us that /etc/network/interfaces is installed by the init-ifupdown receipe.

A file search shows that init-ifupdown is part of poky:

$ find . -name init-ifupdown*.bb
./poky/meta/recipes-core/init-ifupdown/init-ifupdown_1.0.bb

Now, since you need to modify the output of init-ifupdown, you'll need to extend init-ifupdown by creating a similarly named .bbappend in your own layer.

You might create the new .bbappend at

my-layer/receipes-core/init-ifupdown/init-ifupdown_%.bbappend

The % is a wildcard that ensures the .bbappend will apply to all future versions of the init-ifupdown recipe, which is probably what you want.

Place your custom interfaces file in a folder below the .bbappend:

my-layer/receipes-core/init-ifupdown/files/interfaces

The .bbappend then only needs to contain a single line to enable bitbake to pick up the new interfaces file:

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

Finally, repeat the above with each system file you'd like to replace.

Carsten Hansen
  • 1,508
  • 2
  • 21
  • 27
  • Do I need to add `init-ifupdown` into the image? Or `init-ifupdown` will always be in the image? –  Sep 23 '20 at 14:26
  • If you want to use the suggested `.bbappend` to install a custom `interfaces` file, then yes `init-ifupdown` needs to be added to the image – Carsten Hansen Sep 23 '20 at 14:38
2

It depends on the file to modify. For example, if you search 'interfaces' in poky directories, you'll find it in 'meta/recipes-core/init-ifupdown/init-ifupdown-${PV}/'. You just need to create a recipe named init-ifupdown-${PV}.bbappend in your meta, recreating the path seen in poky (recipes-core/init-ifupdown/). This recipe can contain a single line :

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

Then you create a 'files' folder with the 'interfaces' file you want to have.

For 'issue', like others found in the /etc directory (profile, fstab, ...), it's the same procedure, with the sources in poky/meta/recipes-core/base-files/.

For init.d scripts, use the 'update-rc' class.

Tuxin
  • 170
  • 11
  • I totally understand. But I wanted to make it my own layer recipe. just one. – dev j Feb 11 '19 at 12:05
  • This is not the way to go. When a file is provided by an existing recipe, it is good practice to extend this recipe (create a bbappend) in order to customize it. All these personalized recipes (and those you created from scratch) must be in your own meta. – Tuxin Feb 11 '19 at 13:09
  • 1
    Your solution worked, but it contains a typo: the colon should be put next to the equal for it to work: `:=`. – MicroJoe May 24 '20 at 08:11
1

You recipe is not "image recipe" (and it shouldn't be for hello world) thus you cannot use tasks do_rootfs and do_image in this case. A bit of clarification: image recipe is .bb file that you use to build image with bitbake or devtool (in your case some containing imx6q, you can find them with bitbake-layers show-recipes "*-image-*").

It looks like you are looking really is a way to override do_install of some recipe that installs that mentioned files. Then find what recipe installs those files and create bbappend file in your top layer. This bbappend file may contain do_install_append task where you can place your install <file> <dir> lines (note, using cp as not recommended, everything should be done with install tool).

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thank you for your reply, I am beginner and I understood it roughly. In the end, do you mean making an image recipe? Anyway i will do it your way. – dev j Feb 11 '19 at 12:07
  • @devj No, "override do_install of some recipe that installs that mentioned files" means creating bbappend for init-ifupdown in your case. the same as in the link I shared. – pmod Feb 11 '19 at 15:23
  • @devj I don't see where you need to copy directory. install "correctly" copies files (cp + chown + chgrp) - single or multiple (with *), check original recipe to get example http://cgit.openembedded.org/openembedded-core/tree/meta/recipes-core/init-ifupdown/init-ifupdown_1.0.bb?h=master – pmod Feb 13 '19 at 21:29
1

Adding an extra comment based on Carsten Hansen original answer for folks working with Xilinx/Petalinux.

Under Petalinux environment we don't really have the command: oe-pkgdata-util, so the strategy is to do a search in the Xilinx SDK folder. You might have it installed on Linux under /opt according to the documentation. If you do a:

grep -r syslog-startup.conf .

you will see busybox recipe being the one that does the installation of the syslog-startup.conf.

You can create the override recipe called busybox_%.bbappend under:

../project-spec/meta-user/recipes-core/busybox/

Put the modified syslog-startup.conf file under:

../project-spec/meta-user/recipes-core/busybox/files/syslog-startup.conf

Rebuild via petalinux-build. You can also force the creation of the rootfs via petalinux-build -c rootfs and the system should populate your new file.

Mickael T
  • 895
  • 2
  • 8
  • 19