I am using BBB to understand the yocto-project. I am not sure how patching works. This is my project directory
├── meta-testlayer
├── poky
meta-test layer contains a "helloworld" example
├── conf
│ └── layer.conf
├── COPYING.MIT
├── README
└── recipes-hello
└── helloworld
├── helloworld-0.1
│ ├── helloworld.c
│ ├── helloworld.patch
│ └── newhelloworld.c
└── helloworld_0.1.bb
"helloworld.c" and "newhelloworld.c" differ by only one printf() statement. Here is the content of "helloworld.c":
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hi, this is my first custom recipe. Have a good day\n");
return 0;
}
The content of "newhelloworld.c":
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Let see if patch works\n");
printf("Hi, this patch is from the test-layer\n");
return 0;
}
Here is the patch I created using diff helloworld.c newhelloworld.c > helloworld.patch command.
6c6,7
< printf("Hi, this is my first custom recipe. Have a good day\n");
---
> printf("Let see if patch works\n");
> printf("Hi, this patch is from the test-layer\n");
This is the content of "helloworld_0.1.bb" file
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#here we specify the source we want to build
SRC_URI = "file://helloworld.c"
SRC_URI += "file://helloworld.patch"
#here we specify the source directory, where we can do all the building and expect sources to be placed
S = "${WORKDIR}"
#bitbake task
do_compile() {
${CC} ${LDFLAGS} helloworld.c -o helloworld
}
#bitbake task
do_install() {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}
}
This is the error message when I run bitbake -c patch helloworld:
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: helloworld-0.1-r0 do_patch: Command Error: 'quilt --quiltrc /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/helloworld/0.1-r0/recipe-sysroot-native/etc/quiltrc push' exited with 0 Output:
Applying patch helloworld.patch
patch: **** Only garbage was found in the patch input.
Patch helloworld.patch does not apply (enforce with -f)
ERROR: helloworld-0.1-r0 do_patch: Function failed: patch_do_patch
ERROR: Logfile of failure stored in: /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_patch.22267
ERROR: Task (/home/guest/yocto_practice/meta-testlayer/recipes-hello/helloworld/helloworld_0.1.bb:do_patch) failed with exit code '1'
NOTE: Tasks Summary: Attempted 11 tasks of which 8 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/home/guest/yocto_practice/meta-testlayer/recipes-hello/helloworld/helloworld_0.1.bb:do_patch
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.
First, create the patch:
diff -u helloworld.c newhelloworld.c > helloworld.patch
or using Git (replace x by the number of commits you want to extract a patch):
git format-patch -x
Two ways to apply the patch:
Put it into your test-layer, add a line on your .bb file:
SRC_URI += " file://example.patch "
Put it in another layer, but it's only needed if it isn't your layer (meta-oe, meta-fsl, meta-qt...)
For this case, use in your .bbappend file:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://helloworld.patch "
Create a .bbappend file for that recipe.
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://your.patch "
Related
I am new to Yocto and doing some starter projects. I have added my own layer called meta-tutorial .
I have the following recipe file inside my layer at meta-tutorial/recipe-example/hello/hello_1.0.bb
DESCRIPTION = "Simple helloworld application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://hello.c"
S = "${WORKDIR}"
do_compile() {
${CC} hello.c ${LDFLAGS} -o hello
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
}
The hello.c source file is located at meta-tutorial/recipe-example/hello/files/hello.c
When I source the oe-init-build-env script , and try to build my recipe as follows bitbake hello_1.0.bb, I encounter the following issues :
WARNING: No bb files in default matched BBFILE_PATTERN_meta-tutorial '^/home/Yocto-test/poky/meta-tutorial/'
ERROR: Nothing PROVIDES 'hello_1.0.bb'
What is the problem here exactly, it's not clear?
A Yocto layer have a configuration file that describes where to look for recipes .bb and recipes append files .bbappend:
meta-tutorial/conf/layer.conf:
...
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
^
|
(Look closely)-----------------
...
so, your mistake is that you put your recipe under the path:
meta-tutorial/recipe-example/hello
^
|
(The mistake)-------
So, your recipe should be under:
meta-tutorial/recipes-example/hello
^
|
(Correction)---------
I have a project which contains only pytest tests, without modules or classes, which test remote project.
E.g. structure ->
.
├── __init__.py
├── test_basic_auth_app.py
├── test_basic_auth_user.py
├── test_advanced_app_id.py
├── test_advanced_user.py
└── test_oauth_auth.py
Tests look like
"""
Service requires credentials (app_id, app_key) to be passed using the Basic Auth
"""
import base64
import pytest
import authorising.auth
from authorising.resources import Service
#pytest.fixture(scope="module")
def service_settings(service_settings):
"Set auth mode to app_id/app_key"
service_settings.update({"backend_version": Service.Auth_app})
return service_settings
def test_basic_auth_app_id_key(application):
"""Test client access with Basic HTTP Auth using app id and app key
Configure Api/Service to use App ID / App Key Authentication
and Basic HTTP Auth to pass the credentials.
"""
credentials = application.authobj.credentials
encoded = base64.b64encode(
f"{creds['app_id']}:{credentials['app_key']}".encode("utf-8")).decode("utf-8")
response = application.test_request()
assert response.status_code == 200
assert response.request.headers["Auth"] == "Basic %s" % encoded
Is it possible to auto generate documentation from docstrings e.g using Sphinx ?
You can use sphinx-apidoc to generate test-documentation automatically using python-docstrings
For instance, if you have directory structure like below
.
docs
|-- rst
|-- html
tests
├── __init__.py
├── test_basic_auth_app.py
├── test_basic_auth_user.py
├── test_advanced_app_id.py
├── test_advanced_user.py
└── test_oauth_auth.py
sphinx-apidoc -o docs/rst tests
sphinx-build -a -b html docs/rst docs/html -j auto
All Your docs HTML Files will be under docs/html.
There are multiple options sphinx-apidoc supports. Here is the [link]: https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html
When using sphinx, you should add your test-folder to the Python path in the conf.py file:
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'tests')))
Then in each rst file you can simply write:
.. automodule:: test_basic_auth_app
:members:
If you want to document also the test results, please take a look into Sphinx-Test-Reports
I Build Linux kernel for my embedded board.
I want to customize the features of my board.
How can I do that ?
Thanks.
Create the following tree in your layer meta-custom:
recipes-kernel/
└── linux
├── linux-at91
│ ├── 0001-my-custom-dt.patch
└── linux-at91_%.bbappend
In linux-at91_%.bbappend, put
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://0001-my-custom-dt.patch"
To generate 0001-my-custom-dt.patch, you can use the following steps:
git clone https://github.com/linux4sam/linux-at91.git
cd linux-at91/
quilt new 0001-my-custom-dt.patch
quilt add arch/arm/boot/dts/at91-sama5d27_som1_ek.dts
vim arch/arm/boot/dts/at91-sama5d27_som1_ek.dts
# modify DT
quilt refresh
You should obtain something like:
Index: linux-at91/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts
===================================================================
--- linux-at91.orig/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts
+++ linux-at91/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts
## -538,7 +538,7 ##
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_led_gpio_default>;
- status = "okay"; /* Conflict with pwm0. */
+ status = "disabled"; /* Conflict with pwm0. */
red {
label = "red";
Finally copy patch in recipes-kernel/linux/linux-at91 and relaunch Yocto build.
Note:
you could also create an entire custom device-tree by using KERNEL_DEVICETREE bitbake variable.
I need to install a native script, call it foo, in one recipe (foo-native) and then use it in the do_compile step of another (target) recipe - call it bar.
My (minimal) native recipe
SRC_URI = "file://foo"
LICENSE = "CLOSED"
inherit native
BBCLASSEXTEND = "native"
S = "${WORKDIR}"
do_compile() {
:
}
do_install() {
install -d ${D}/usr/bin
install ${WORKDIR}/foo ${D}/usr/bin
}
The script, foo, exists in a directory called files which resides next to the recipe. i.e.
foo/
├── files
│ └── foo
└── foo.bb
My target recipe for bar
SRC_URI = ""
LICENSE = "CLOSED"
DEPENDS = "foo-native"
do_fetch[noexec] = "1"
do_configure[noexec] = "1"
do_compile() {
foo >myfile.json
}
do_install() {
install -d ${D}/etc
install ${WORKDIR}/myfile.json ${D}/etc
}
The error I get is in the do_compile task of bar, and it simply says that foo can not be found (i.e. has not been installed into a directory on the path).
First, you don't need the line
inherit native
in foo.bb. It's taken care of for you by BBCLASSEXTEND = "native".
Secondly, change your do_install to:
do_install() {
install -d ${D}${bindir}
install ${WORKDIR}/foo ${D}${bindir}
}
Note: use ${bindir} instead of /usr/bin. ${bindir} is determined using ${prefix}, which in turn is changed e.g. when building a -native version of a recipe.
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.