Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

bitbake - How do I add a file to the build root filesystem?

I need to include a file when I build a package, but the file itself is not required at all at runtime.

I have been told to look at how to do it using a do_ function, but have been unable to find a suitable function in any documentation. I would assume this could be done trivially, but simply specifying which file to add.

Again, I'm not looking for a way to add the files to the final image. This is just for building.

question from:https://stackoverflow.com/questions/65881654/how-do-i-add-a-file-to-the-build-root-filesystem

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is full documentation about tasks. They all start with do_, so you were advised to extend one of them. Also (as written in docs) packages may have additional tasks, that come from classes - files .bbclass, that are applied to your package's recipe with inherit keyword. To get full list of exactly your package tasks use command

bitbake -c listtasks <your package name>

Actually this way you just call task do_listtasks of your package, do_listtasks is also... a task)

So.. first you need to understand to what task you need to append your file. Tasks have pretty straightforward names, so to use your file during compilation, you need task do_compile, and so on.

Now, it is not clear, how you are going to actually add your file to the build, but looks like also somehow by recipe of your package. That means you should place your file in folder files (there are options about this folder naming) next by your recipe, than add file to variable SRC_URI like this:

SRC_URI = " 
.....
file://your-file-in-folder-files.ext 
.....
"

By doing this, you tell bitbake to append this file to WORKDIR during do_unpack task. More on this here, especially in 3.3.5.

Now to actually your question)) Suppose you need to use your file during do_compile task, but before the actual compilation actions. Than in your recipe extend do_compile like this:

do_compile_prepend() {
  cp ${WORKDIR}/your-file-in-folder-files.ext ${S}/some/subpath/inside/sources
}

Similarly to do something with your file after some actual task actions, create function with _append suffix. For example, do_configure_append or do_compile_append.

Here WORKDIR is some folder under Yocto build directory, where all your package stuff, needed for build your package, is placed, S is a special folder with downloaded and unpacked source code under WORKDIR and do_compile_prepend (and others) is just a bash-script.

Also consider folder D (it is also locates under WORKDIR). It contains files, that actually shall go into resulting image during image creating. So if somehow your file finds the way to the resulting image, remove it directly from D like this:

do_install_append() {
  rm -f ${D}/path/to/your/file/in/resulting/rootfs/your-file-in-folder-files.ext
}

Well... this is more overview, than a exact answer, but hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...