Yocto rebuild is not overwriting - yocto

I made some changes on u-boot source /tmp/work/beaglebone_my-poky-linux-gnueabi/u-boot/1_2018.07-r0/git
When I rebuild with bitbake core-image-minimal. Bitbake is not overwriting images in the path /images/.
Then I used clean, cleansstate, but both of them deleted all my changes in the u-boot/1_2018.07-r0/git directory.
What is the most efficient way to customize the u-boot and kernel?
Thank you.

Changing a recipe's fetched sources directory is not enough to permanently modify source code in Yocto as it is just a temporary working directory that, as you experienced, can be cleaned and all.
Changes to Yocto recipes sources can be made by:
modifying the source code in the working directory
creating a patch for your changes
change/create some recipe to apply your patch
the patch will be applied in build time
This section describes the process of modifying source code and creating a patch:
https://www.yoctoproject.org/docs/1.6.1/kernel-dev/kernel-dev.html#modifying-source-code
This section describes the process of creating an extra layer and a recipe for the patches you created in order to apply them during build time:
https://www.yoctoproject.org/docs/1.6.1/kernel-dev/kernel-dev.html#modifying-source-code

Related

bitbake devtool not creating .bbappend

I'm trying to change the alsa-utils recipe to add a configure option for the state dir. I need to move it to '/etc'.
I used devtool to modify, edit-recipe, and build without any issues. When I try to update-recipe, I get the following message:
INFO: No patches or local source files needed updating
And it's not creating the .bbappend for my recipe changes. I haven't changed anything in the source directory.
Any ideas of what I'm doing wrong?
update-recipe creates a proper directory tree with .bbappend and .patch files in your layer only if you have commited any changes to the source directory.
If you don't want to create .bbappend manually, commit some changes to the source code you've got via devtool, run update-recipe, remove any reference to the patch file in your newly created recipe.

How to apply patch in yocto

I built the yocto image for my board . Now I need to apply this patch
First, how do I figure out which recipe the patch goes to?
Second, how do I apply this patch?
(I checked similar question but its patching yocto system itself, I don't want that)
I can list all my recipes with this command I found
bitbake-layers show-recipes
But I still don't know which of these recipes builds the file drivers/rpmsg/virtio_rpmsg_bus.c, the file I need to patch.
I also found three directories that have this c file:
find . -name virtio_rpmsg_bus.c
./build_wayland/tmp/work-shared/imx8mm-var-dart/kernel-source/drivers/rpmsg/virtio_rpmsg_bus.c
./build_wayland/tmp/work/aarch64-fslc-linux/linux-libc-headers/5.4-r0/linux-5.4/drivers/rpmsg/virtio_rpmsg_bus.c
./build_wayland/tmp/work/aarch64-mx8mm-fslc-linux/linux-imx-headers/5.4-r0/git/drivers/rpmsg/virtio_rpmsg_bus.c
These recipe folders have recipes-kernel/linux directory
sources/meta-freescale-3rdparty/recipes-kernel
sources/meta-freescale/recipes-kernel
sources/poky/meta-skeleton/recipes-kernel
sources/poky/meta/recipes-kernel
sources/poky/meta-yocto-bsp/recipes-kernel
sources/meta-virtualization/recipes-kernel
sources/meta-variscite-fslc/recipes-kernel
sources/meta-openembedded/meta-gnome/recipes-kernel
sources/meta-openembedded/meta-initramfs/recipes-kernel
sources/meta-openembedded/meta-networking/recipes-kernel
sources/meta-openembedded/meta-oe/recipes-kernel
I don't know which of these recipes might be building my c file virtio_rpmsg_bus.c
So I haven't done the build myself but here is what I could gather (this is a bit of a long shot on certain points... hope everything works, I'm open to discussion if that's not the case).
Finding the recipe to patch: In my opinion this might be often tricky to find what recipe does what in Yocto. If I'm not mistaken (which is very much a possibility) you should have a layer called meta-xilinx-bsp. Wihtin this layer there should be recipes-kernel/linux/linux_xlnx_[version].bb. This should be the recipe the patch should go to.
Applying the patch: To apply the patch the simplest way is to append the recipe.
Create the folder structure: In your own layer you need to reproduce the structure where the recipe is in the original layer. Here: meta-myLayer/recipes-kernel/linux/. In this folder create linux-xlnx_%.bbappend.
Create a .bbappend file: With this structure and name yocto will know this is an append to the original linux-xlnx_[verion_number].bb recipe. The % is put here instead of a version number. This is a wildcard and will append any version of the linux-xlnx recipe. Should you want to append only a specific version you can replace % by a version number.
Add the patch file to your directory: To do so create a folder called linux-xlnx next to you recipe. And within this folder create your patch file by copying the content you have in something like my-xlnx-patch.patch
Reference the patch file in the .bbappend: Indicate the file path in your linux-xlnx_%.bbappend as follow:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI_append = " \
file://my-xlnx-patch.patch \
"
I'm not 100% sure you need the first line but this will tell yocto that you have a patch file for this recipe and if I'm not mistaken yocto will take care of applying it.

Execute bitbake recipe discarding what sstate_cache is

I have a yocto project where I added some recipes and some of the functions in them are crucial when building (the functions consist inly some links creations, some files "equilibristics"). Although when first build all is done and the sstate_cache is saved to shared/sstate_cache so that those recipes are mentioned executed. When I make some changings on building system, also delete some of the built files or the hole build dir and rerun the build, bitbake does not execute the recipes.
The only solution is to:
bitbake -c cleanall <list_of_my_recipes_to_be_rerun>
So I have to explicitly clean the cache to tell bitbake to rerun them.
So my questions are:
Is there some way to explicitly set the recipe to be executed no matter what the shared cache saved on it?
Or maybe save the state locally in the build dir?
Or maybe tell bitbake not to save state for the recipe?
You could set BB_DONT_CACHE = "1" in the recipe, rerun the recipe with the -C option, or make the task checksum depend upon these things which you're changing so it automatically rebuilds when you change them. You could also just clean the recipe and then use the --no-setscene to bitbake.
Easy way:
$ bitbake <recipe> -C unpack
This builds recipe but forces unpack to rerun, which means everything else has to rerun too.
However if the recipe doesn't work with sstate then that is a problem with your recipe.
Is there some way to explicitly set the recipe to be executed no matter what the shared cache saved on it?
To force a recipe to run regardless of what is in the shared-state cache (or anything else),
pass the -f | --force option to the bitbake command, e.g.
bitbake -f [other_options...] recipe_name ...
See the bitbake commmandline options in the manual.

add one more source to the repo manifest

I need to build an image for a Xilinx FPGA. Followed these directions. Everything worked and I managed to build it. Now I need to add an extra layer. I thought all I needed to do is to modify .repo/manifests/default.xml (add this layer, https://github.com/sbabic/meta-swupdate/tree/rocko) and then execute
repo sync
but I'm getting errors saying that changes to multitude of files will be overwritten by a checkout (these are the files that were built).
So how do I add a layer to my current environment and rebuild with a new layer without actually rebuilding the whole thing?
cd ./sources/
git clone https://github.com/sbabic/meta-swupdate.git
cd ../conf/
vi ./bblayers.conf
add **{BSPDIR}/sources/meta-swupdate \** before (")
vi ./local.conf
add **IMAGE_INSTALL_append = " swupdate" **
bitbake
How to add Layer example: https://www.youtube.com/watch?v=3HsaoVqX7dg

What is best practice to do small changes in source code in Yocto

Is it good practice to edit source code in poky/build/tmp/work directory ? because if we accidentally cleansstate ,the changes will be erased.
Alternatively we can edit source code in "files" directory along with recipe file but since mostly code here is in zipped form due to large number of files , so we will need to unzip and zip again just to change one line of code.
So what is best way to edit source code in yocto ?
If your question is about permanent changes, then Dan's answer is the one to follow. I.e. add a <recipe name>.bbappend to the recipe in your own layer, in which you add
SRC_URI += "file://mypatch1.patch \
file://mypatch2.patch \
"
enumerating all the patches you need.
If there's a large number of patches, it might make sense to fork the upstream repository, and maintain your own branch in your fork. In that case, you'll likely want to reference your own repository, instead of either the upstream repository or tarball.
OTOH, if your question was more about work-in-progress; then sure, doing it in oky/build/tmp/workoky/build/tmp/work/xxxx will work. (And quite likely, it's what most people have been doing for a long time).
However, there's a much better way in recent releases (from 1.8, fido). The new tool is called devtool. You can use it as follows:
devtool modify -x <recipe-name> <path-to-unpack-source>
unpacks the source and creates a new bbappend to build from the unpacked source. It also creates a git repo in the source directory.
Now you can modify the source. You can test-build your modified source by running devtool build <recipe-name>. Once you're satisfied, use git add ... and git commit to commit your changes to the local repo. Once you've commited the changes to the local repo, you can run:
devtool update-recipe <recipe-name>
to update the recipe in question. When you're satisfied, you can run devtool reset <recipe-name> to remove the temporary bbappend.
See also: Yocto manual on modifying source code
If you are continuously "patching" a given package manually, I would recommend you to look at implementing a .bbappend file in a separate layer which applies your patch using the do_patch function (http://www.yoctoproject.org/docs/2.0/mega-manual/mega-manual.html#patching-dev-environment).