make changes to linux os - linux-device-driver

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.

Related

How does DVC store differences on the directory level into DVC cache?

Can someone explain how DVC stores differences on the directory level into DVC cache.
I understand that the DVC-files (.dvc) are metafiles to track data, models and reproduce pipeline stages. However, it is not clear for me how the process of creating branches, commiting them and switching back to a master file is exactly saved in differences.
Short version:
.dvc file contains info (md5) about JSON file inside cache that describes current state of directory.
When directory gets updated, there is new md5 in .dvc file and new JSON file is created with updated state of directory.
In git, you store the .dvc file, so that DVC know (basing on md5) where to look for information about directory.
Longer version:
Let me try to break particular steps of directory handling with DVC.
Lets assume we have some data directory you want to add under DVC control:
data
├── 1
└── 2
You are using dvc add data to make DVC track you directory. In result, DVC produces data.dvc file. As you noted this file contains metadata required to connect your git repository with your data storage. Inside this file (besides other things) you can see:
outs:
- md5: f437247ec66d73ba66b0ade0246fcb49.dir
path: data
The md5 part is used to store information about directory in DVC cache (.dvc/cache):
(dvc3.7) ➜ repo$ tree .dvc/cache
.dvc/cache
├── 26
│   └── ab0db90d72e28ad0ba1e22ee510510
├── b0
│   └── 26324c6904b2a9cb4b88d6d61c81d1
└── f4
└── 37247ec66d73ba66b0ade0246fcb49.dir
If you will open the file with .dir suffix, you will see that it contains description of current data state:
(dvc3.7) ➜ repo$ cat .dvc/cache/f4/37247ec66d73ba66b0ade0246fcb49.dir
[{"md5": "b026324c6904b2a9cb4b88d6d61c81d1", "relpath": "1"},
{"md5": "26ab0db90d72e28ad0ba1e22ee510510", "relpath": "2"}]
As you can see, particular files(1 and 2) are described by entries in this file
When you change your directory:
(dvc3.7) ➜ repo$ echo 3 >> data/3
(dvc3.7) ➜ repo$ dvc commit data.dvc
The content of data.dvc will be updated:
outs:
- md5: 12f4b7d54a32e58818e27fba28376fba.dir
path: data
And there is new file inside the cache:
├── 12
│   └── f4b7d54a32e58818e27fba28376fba.dir
...
(dvc3.7) ➜ repo$ cat .dvc/cache/12/f4b7d54a32e58818e27fba28376fba.dir
[{"md5": "b026324c6904b2a9cb4b88d6d61c81d1", "relpath": "1"},
{"md5": "26ab0db90d72e28ad0ba1e22ee510510", "relpath": "2"},
{"md5": "6d7fce9fee471194aa8b5b6e47267f03", "relpath": "3"}]
From perspecitve of git the only change is inside data.dvc.
(Assuming you did git commit after adding data with 1 and 2 inside):
diff --git a/data.dvc b/data.dvc
index 098aec5..88d1a90 100644
--- a/data.dvc
+++ b/data.dvc
## -1,6 +1,6 ##
-md5: a427c5bf8680fbf8d1951806b28b82fe
+md5: 1b674d61c195eea7a6b14f176c020b9c
outs:
-- md5: f437247ec66d73ba66b0ade0246fcb49.dir
+- md5: 12f4b7d54a32e58818e27fba28376fba.dir
path: data
cache: true
metric: false
NOTE: First md5 corresponds to md5 of this file, so it had to change with dir md5 change

Is possible to auto generate documentation for pytest tests?

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

Simple installation of native script for use in other recipe

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.

How patching works in yocto

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 "

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.