Yocto - applying a bbappend file to a recipe (from github) - yocto

I'm working with the meta-atmel layer in Yocto to create an image for a SAMA5D4 board.
I've created a custom layer & would like to patch a file (specifically https://github.com/linux4sam/egt/blob/master/src/app.cpp) with a diff I created:
index 869b1e2..c86ad1a 100644
--- a/app.cpp
+++ b/app.cpp.modified
## -342,8 +342,9 ## void Application::setup_inputs()
}
}
+// Modify to force use of tslib
#ifdef HAVE_LIBINPUT
- m_inputs.push_back(std::make_unique<detail::InputLibInput>(*this));
+// m_inputs.push_back(std::make_unique<detail::InputLibInput>(*this));
#endif
}
I recreated the directory structure in my custom layer to match the location of the file I'd like to alter:
yocto/meta-atmel/recipes-graphics/libegt/libegt_1.2.bb
yocto/meta-custom2/recipes-graphics/libegt/libegt_%.bbappend
My bbappend file is:
# Modify https://github.com/linux4sam/egt/src/app.cpp
# Issue with file path
SRC_URI += "file:0001-disable-libinput.patch"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
PACKAGE_ARCH = "${MACHINE_ARCH}"
How do I correctly include my patchfile to the file I'd like to modify?
Many thanks for looking!

Well looks like I may have solved the issue.
I moved my diff file to the directory:
yocto/meta-custom2/recipes-graphics/libegt/files
& corrected some errors:
Diff should be:
diff --git a/src/app.cpp b/src/app.cpp
index 869b1e2..c86ad1a 100644
--- a/src/app.cpp
+++ b/src/app.cpp
## -342,8 +342,9 ## void Application::setup_inputs()
}
}
+// Modify to force use of tslib
#ifdef HAVE_LIBINPUT
- m_inputs.push_back(std::make_unique<detail::InputLibInput>(*this));
+// m_inputs.push_back(std::make_unique<detail::InputLibInput>(*this));
#endif
}
where the '/src/app.cpp' referes to the location of the file that needs to be patched (i.e. similar if one carried out a git clone). Next my bbappend should have been:
# Modify https://github.com/linux4sam/egt/src/app.cpp
SRC_URI += "file://0001-disable-libinput.patch"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
PACKAGE_ARCH = "${MACHINE_ARCH}"
Hope this helps others & thanks to the teams working on Yocto/ OE!

Related

How to assign patch to specified git source?

In my foo_git.bb:
SRC_URI = "git://github.com/foo/foo.git;branch=main;protocol=https;name=${BPN};destsuffix=git \
git://github.com/foo2/foo2;branch=main;protocol=https;name=${FOO2};destsuffix=${FOO2} \
file://0001-Modify-A_value.patch\
"
I want my patch to apply to foo2 but it always applied to foo. ( patch failed )
I found patchdir appended after the patch can work.
ex:
file://0001-Modify-A_value.patch;patchdir=${WORKDIR}/${FOO2_path}
From the OE manual
Patch files will be copied to ${S}/patches and then applied to source from within the source directory, ${S}. so for your use case to work your patch filenames should include their base repo name.
For example let’s say 0001-Modify-A_value.patch is as follows:
diff --git a/my.txt b/my.txt
index fa5cb9a..59369cc 100644
--- a/my.txt
+++ b/my.txt
## -1 +1 ##
-I am foo who lives in bar
+I am bar who lives in foo
To make it apply to foo2 you must modify it as follows:
--- foo2/my.txt
+++ foo2/my.txt
## -1 +1 ##
-I am foo who lives in bar
+I am bar who lives in foo
Bitbake uses Quilt for patching so for errors and so on look at its manual.
Another handy tool by bitbake to help you further is the devtool which is designed to handle tasks like updating a recipe or patching it.

how to get ${THISDIR} inside do_unpack_append in .bbappend file

I'm attempting to replace a file from another layer with a .bbappend file. My goal is to overwrite a specific configuration file with a customized one during the unpack stage.
In my .bbappend I'm attempting to append the do_unpack to copy a file from the same directory as the .bbappend file into the working directory ${WORKDIR} The problem is: When inside do_unpack_append, ${THISDIR} is returning the directory of the original .bb recipe, rather than the directory of .bbappend
Here's an example:
The original recipe resides in: meta-origLayer/recipe.bb
My *.bbappend resides in: meta-newLayer/recipe.bbappend
recipe.bbappend:
`FILESEXTRAPATHS_prepend := "${THISDIR}:"`
do_unpack_append(){
bb.build.exec_func('replace_file', d)
}
replace_file(){
cp -f ${THISDIR}/fileToBeReplaced ${WORKDIR}/fileToBeReplaced
echo ${THISDIR} > ${WORKDIR}/shouldContain_meta-newLayer
}
There are two issues with recipe.bbappend:
I would expect the file shouldContain_meta-newLayer to contain meta-newLayer, but instead it contains meta-origLayer.
I'd primarily like to understand why ${THISDIR} behaves differently when placed inside do_unpack_append() from when it is used for prepending FILESEXTRAPATHS
When running bitbake, the recipe fails, producing the following error:
cp: cannot stat '/fileToBeReplaced': No such file or directory
This error occurs because fileToBeReplaced resides in a subdirectory of meta-origLayer (i.e. meta-origLayer/machine1/fileToBeReplaced) and the .bbappend expects to find the file in /fileToBeReplaced
My Question. . .
I have assumed ${THISDIR} would behave consistently within the same .bbappend, but it doesn't appear to. What is the best way to reference meta-newLayer/fileToBeReplaced from within do_unpack_append()?
This *.bbappend correctly overwrites fileToBeReplaced in the working directory during the unpack task:
FILESEXTRAPATHS_prepend := "${THISDIR}:"
SRC_URI_append += " file://fileToBeReplaced "
SAVED_DIR := "${THISDIR}"
do_unpack_append(){
bb.build.exec_func('replace_file', d)
}
replace_file(){
cp -f ${SAVED_DIR}/fileToBeReplaced ${WORKDIR}/fileToBeReplaced
}
Thanks for the explanation between bbappend parsing and execution johannes-schaub-ltb

Difference between SRC_URI and FILESEXTRAPATHS_prepend in bitbake

Why do we need to give path of files in SRC_URI even though we are including the files path in FILESEXTRAPATHS_prepend variable? For example:
SUMMARY = "Simple Hello application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = "file://Hello_1.c \
file://Hello_2.c \
"
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}${bindir}
install -m 0755 Hello ${D}${bindir}
}
In the "files" folder I have two files: hello1.c and hello2.c. When I remove SRC_URI it outputs the following error,
ERROR: Hello-1.0-r0 do_compile: oe_runmake failed
But if I remove
FILESEXTRAPATHS_prepend it is working fine.
What is the purpose of the variable FILESEXTRAPATHS_prepend?
Why error occurs when I remove SRC_URI even though I'm including my files path in FILESEXTRAPATHS_prepend?
Simple way let assume meta-layer/recipes-core/example
In above path created hello and hello.bb
Here hello is a directory having your source and other data and hello.bb is recipe.
Now
SRC_URI : The SRC_URI variable always checks the data in hello dir only.
FILESEXTRAPATHS_prepend := "${THISDIR}:" : if you add this line in your recipe, then the SRC_URI variable checks the data in present directory where the hello.bb file present.
In your case
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
The SRC_URI variable checks the data in files dir where the hello.bb is present.
Note: Most of the time people will use this FILESEXTRAPATHS variable in .bbappend files to apply patches and other files to the recipe.
For every .bb file, the SRC_URI variable is used to specify which files to fetch the source from - either from
an online repository or a local one, and the FILESEXTRAPATHS specifies where these files are looked for, and depends on your source
path.
BitBake uses the SRC_URI variable to point to source files
regardless of their location. Each recipe must have a SRC_URI
variable that points to the source.
SRC_URI = file:// Fetches files, which are usually files shipped
with the Metadata, from the local machine. The path is relative to the
FILESPATH variable. Thus, the build system searches, in order, from
the following directories, which are assumed to be a subdirectories of
the directory in which the recipe file (.bb) or append file
(.bbappend) resides:
FILESPATH: The default set of directories the OpenEmbedded build
system uses when searching for patches and files. During the build
process, BitBake searches each directory in FILESPATH in the specified
order when looking for files and patches specified by each file:// URI
in a recipe.
The default value for the FILESPATH variable is defined in the
base.bbclass class found in meta/classes in the Source Directory:
FILESPATH = "${#base_set_filespath(["${FILE_DIRNAME}/${BP}", \
"${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
Do not hand-edit the FILESPATH variable; The
default directories BitBake uses when it processes recipes are
initially defined by the FILESPATH variable. You can extend FILESPATH
variable by using FILESEXTRAPATHS.
> Best practices dictate that you accomplish this by using
FILESEXTRAPATHS from within a .bbappend file
FILESEXTRAPATHS: Extends the search path the OpenEmbedded build system
uses when looking for files and patches as it processes recipes and
append files. The default directories BitBake uses when it processes
recipes are initially defined by the FILESPATH variable.
If you want the build system to pick up files specified through a
SRC_URI statement from your append file, you need to be sure to extend
the FILESPATH variable by also using the FILESEXTRAPATHS variable from
within your append file.
http://www.yoctoproject.org/docs/2.1/ref-manual/ref-manual.html#var-FILESPATH
Back to your error, since each recipe MUST have a SRC_URI; it will not work if you delete it;
Since your recipe is not an .bbappend, adding FILESEXTRAPATHS is not appropriate and not necessary.

Yocto recipe to update /etc/fstab

I'm having trouble updating the /etc/fstab of my Linux distribution, when building it with Yocto. I'm pretty new to Yocto, so maybe I'm off my rocker.
My latest attempt is to add a recipe named base-files_%.bbappend.
mount_smackfs () {
cat >> ${IMAGE_ROOTFS}/etc/fstab <<EOF
# Generated from smack-userspace
smackfs /smack smackfs smackfsdefault=* 0 0
EOF
}
ROOTFS_POSTPROCESS_COMMAND += "mount_smackfs; "
But, the output /etc/fstab on the distribution hasn't changed. So the questions are:
Is there a better way to do this?
How can I tell if my .bbappend file was actually executed?
ROOTFS_POSTPROCESS_COMMAND is handled in image recipes and not in package recipes. You have 2 possibilities.
Update your fstab in base-files_%.bbappend:
do_install_append () {
cat >> ${D}${sysconfdir}/fstab <<EOF
# Generated from smack-userspace
smackfs /smack smackfs smackfsdefault=* 0 0
EOF
}
Update the fstab in your image's recipe: In this case, you just append
what you wrote above (in your post) in the image's recipe.
Create a new layer using
yocto-layer create mylayer
inside it, create a folder called recipes-core and inside this folder
create another folder called base-files.
Inside this folder create a file called base-files_%.bbappend, with the following content:
FILESEXTRAPATHS_append := "${THISDIR}/${PN}:"
Create another folder called base-files, inside which you should put a file called fstab with your configurations.
Make sure to enable your new layer in the bblayers.conf and it will work correctly, no need to create any append recipe or thing.
I had this issue and solved it using this method today.
Given the following directory structure:
.
└── recipes-core/
└── base-files/
├── base-files/
│ └── fstab
└── base-files_%.bbappend
and the following content for the recipe base-files_%.bbappend in question
DESCRIPTION = "Allows to customize the fstab"
PR = "r0"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " \
file://fstab \
"
do_install_append(){
install -m 0644 ${WORKDIR}/fstab ${D}${sysconfdir}/
}
You can specify the fstab you want in that file and include this in your own custom layer. Once the compilation is finished you will have the custom fstab on the target system.

Add custom.xml file to AOSP etc folder

I wanted to add a resource file/ xml file to etc folder in AOSP. I would like to have my resource file available just like platform.xml file.
So I basically added my xml file in AOSP/frameworks/base/data/etc folder and correspondingly added the following lines in the make file Android.mk
########################
include $(CLEAR_VARS)
LOCAL_MODULE := custom.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
# This will install the file in /system/etc/permissions
#
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
EDIT
With the above added I was not able to see my file in /system/etc/permissions folder. Am I missing something?
It looks that your change is device specific and not framework related. In that case you probably want to include your file in aosp / device / ... / model /
You can check how is done looking in the device makefile from samsung tuna:
https://android.googlesource.com/device/samsung/tuna/+/master/device.mk
The PRODUCT_COPY_FILES variable includes the "origin_file:destination_file"
PRODUCT_COPY_FILES += \
$(LOCAL_KERNEL):kernel \
device/samsung/tuna/init.tuna.rc:root/init.tuna.rc \
device/samsung/tuna/init.tuna.usb.rc:root/init.tuna.usb.rc \
device/samsung/tuna/fstab.tuna:root/fstab.tuna \
device/samsung/tuna/ueventd.tuna.rc:root/ueventd.tuna.rc \
device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \
device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \
device/samsung/tuna/gps.conf:system/etc/gps.conf