23

I have a directory of 'binary' (i.e. not to be compiled) files and just want them to be installed onto my target root file system.

I have looked at several articles, none of which seem to work for me.

The desired functionality of this recipe is:

myRecipe/myFiles/ --> myRootFs/dir/to/install

My current attempt is:

SRC_URI += "file://myDir"

do_install() {
         install -d ${D}/path/to/dir/on/fs
         install -m ${WORKDIR}/myDir ${D}/path/to/dir/on/fs
}

I can't complain about the Yocto documentation overall, it's really good! Just can't find an example of something like this!

urnenfeld
  • 1,030
  • 9
  • 25
Ben Turner
  • 725
  • 1
  • 6
  • 23
  • For a good example of this see psplash_git.bb -> do_install_append – Stephano Nov 21 '16 at 18:03
  • Modify this line "install -m ${WORKDIR}/myDir ${D}/path/to/dir/on/fs" to "install -m ${WORKDIR}/myDir/* ${D}/path/to/dir/on/fs" – ashwanth selvam Nov 29 '16 at 06:51
  • Possible duplicate of [How to install recursively my directories and files in BitBake recipe](https://stackoverflow.com/questions/39980145/how-to-install-recursively-my-directories-and-files-in-bitbake-recipe) – LetoThe2nd Oct 23 '19 at 06:10

4 Answers4

18

You just have to copy these files into your target rootfs. Do not forget to pakage them if they are not installed in standard locations.

SRC_URI += "file://myDir"

do_install() {
    install -d ${D}/path/to/dir/on/fs
    cp -r ${WORKDIR}/myDir ${D}/path/to/dir/on/fs
}
FILES_${PN} += "/path/to/dir/on/fs"
john madieu
  • 1,209
  • 12
  • 16
  • This seems to copy the directory, but none of the files or other directories within it. I'm assuming I have to state all of these explicitly then. Is there a sensible, quick way to do this? – Ben Turner Nov 22 '16 at 15:08
  • Of course it does. It's why I used `cp -r` for recursive copy. – john madieu Nov 22 '16 at 19:28
  • I used cp -r, it copies the 'myDir' directory to the FS but none of its contents... – Ben Turner Nov 23 '16 at 15:13
  • Ok. Try `cp -r ${WORKDIR}/myDir/* ${D}/path/to/dir/on/fs`. It is strange. I'll have a look. Are you sure `myDir` is not empty ? – john madieu Nov 23 '16 at 15:36
4

Take care that with a simple recursive copy, you will end up having host contamination warnings so you would need to copy with the following parameters:

do_install() {
     [...]
     cp --preserve=mode,timestamps -R ${S}${anydir}/Data/* ${D}${anyotherdir}/Data
     [...]
}

As other recipes in poky do, or just follow the official recommendations to avoid problems with ownership and permissions.

Michael Thompson
  • 541
  • 4
  • 21
urnenfeld
  • 1,030
  • 9
  • 25
  • What are the differences between using `cp` and `install -m` as other users suggested? – Mark Oct 13 '19 at 08:20
  • 1
    I just added a direct link to documentation. My advice is to use always install, except when you need some recursive copying. – urnenfeld Oct 13 '19 at 20:29
  • This is pretty much the only correct answer, the thread itself being a dupe of [this](https://stackoverflow.com/questions/39980145/how-to-install-recursively-my-directories-and-files-in-bitbake-recipe/47084404#47084404) – LetoThe2nd Oct 23 '19 at 06:12
2

For a recipe folder like this:

.
├── files
│   ├── a.txt
│   ├── b.c
│   └── Makefile
└── myrecipe.bb

You can use the following recipe to install it on a specific folder into your rootfs:

SRC_URI = " file://*"
do_install() {
    install -d ${WORKDIR}/my/dir/on/rootfs
    install -m 0755 ${S}/* ${WORKDIR}/my/dir/on/rootfs/*
}
FILES_${PN} = "/my/dir/on/rootfs/* "
PierreOlivier
  • 1,387
  • 9
  • 23
1

I think it did not work for you becuase you forgot to add mode value, after "install -m",

see man page of install command: https://linux.die.net/man/1/install

install -m [mode] src destination
ransh
  • 1,589
  • 4
  • 30
  • 56