How to transfer python3-flask project into yocto image? - python-3.x

I am a beginner in yocto. Till now i have learnt about how to build a yocto image and add recipes through layers.openembedded. But i am not able to figure out e.g. i have developed a python3-flask project in my PC and then i want to copy/transfer that project into my yocto os. how can i do that? do i have to make something like executable of that project and then copy that into my os using some recipe?
I have seen this recipe but i am not able to understand what does LIC_FILES_CHSUM means and where to get it? where should i put these file e.g. setup.py? in the same directory as my .bb file?
and on building where my project would be copied in the yocto os?
DESCRIPTION = "Simple Python setuptools hello world application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://python-helloworld.py \
file://helloworld/__init__.py \
file://helloworld/main.py"
S = "${WORKDIR}"
inherit setuptools
do_install_append () {
install -d ${D}${bindir}
install -m 0755 python-helloworld.py ${D}${bindir}
}

The LICENSE field should obviously correspond to the license you picked for your SW. LIC_FILES_CHKSUM needs a file that holds the actual license defined in LICENSE and its md5sum passed as an "argument". It is just a way to monitor if the license ever changes. Then its md5sum changes and then the recipe fail to build because the license probably changed and requires the maintainer's attention.
THISDIR being the directory containing the recipe (not exactly but enough for the example), files in SRC_URI will be searched for in FILESPATH (which is first ${THISDIR}/<recipe_name>-<recipe_version> then ${THISDIR}/<recipe-name> then ${THISDIR}/files). So you need to put files (the ones starting with file://) declared in SRC_URI into one of those directories.
Best would actually to have your SW in a git repo somewhere. This better follows the philosophy of having SW source code separate from your build system (what if you decide you want to use a different build system later?).
When you're wondering what some variables or tasks are doing, I highly recommend looking them up on the mega manual: https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html. This works extremely well as a "dictionary". The documentation is great albeit dense and long but it is rare not to found what you look for as a beginner.
Update
LIC_FILES_CHKSUM can be found in yocto meta/files/common-licenses in the Source Directory. You can also take your own license and check the checksum with md5sum filename and copy that to bb file. If your SW is to be distributed, it is highly recommended to have the license mentioned somewhere in your sources. So better use that part of the code in LIC_FILES_CHKSUM than using the ones in ${COMMON_LICENSE_DIR} so that people will know if and when there is a license change in your project.
The below recipe works fine and you can find your app in /usr/bin directory.
DESCRIPTION = "Simple Python setuptools application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://packagetest.py \
file://example/__init__.py \
file://example/file1.py \
file://example/file2.py \
file://example/file3.py"
S = "${WORKDIR}"
inherit pypi setuptools3
do_install_append () {
install -d ${D}${bindir}
install -m 0755 packagetest.py ${D}${bindir}
}

Related

How to add header file to /usr/include in Yocto

I am working with Linux built with Yocto. I would like to add to the image my app to /bin and some header file to /usr/include. I have no problem with adding the app to /bin, but I am not able to add the header file to my rootfs. The .h file is added to a proper package, but it is not copied to rootfs.
Here is my recipe:
bindir = "${localdir}/bin"
incldir = "${localdir}/usr/include"
FILESEXTRAPATHS_prepend := "${THISDIR}/files/:"
SRC_URI = "file://My_app_dir/* \
\
"
S = "${WORKDIR}"
FILES_${PN} += "${incldir}/*"
do_compile() {
cd My_app_dir/src
make
}
do_install() {
install -d ${D}${bindir}
cp "${S}/My_app_dir/src/my_app" "${D}${bindir}/my_app"
install -d ${D}${incldir}
cp "${S}/My_app_dir/some_lib.h" "${D}${incldir}/some_lib.h"
}
After building the image, the include file exists in /build/tmp/work/<machine>/<my_app>/image/usr/include.
Do you have any idea why I cannot add .h file to /usr/include in rootfs? Thank you in advance for any help.
The header files (among other files like pkgconfig and shared library symlinks) are not added to the main package (say foo), but to the development package (e.g. foo-dev). This is called package split and you can learn more in the Package Splitting of the official documentation. The development packages (and BTW also the debug foo-dbg) are not installed by default.
But please be aware that adding the development package may pull other dependencies (because of various runtime dependencies) and files (there are other files in the development package).
Please note that your line FILES_${PN} += "${incldir}/*" has no effect, as the files in $includedir (i.e. FILES_${PN}-dev) are split before the FILES_${PN} are processed. The order is defined in the variable PACKAGES (check the official documentation).
BTW, there are minor things in the recipe which you can update (unrelated to your question though):
You can use location of standard system paths in the respective variables bindir, includedir etc.
install is preferred over the cp in do_install.
The line FILESEXTRAPATHS_prepend := "${THISDIR}/files/:" is needed only in bbappends. The files directory inside the recipe's directory is in the standard search path of files (among other paths like ${PN} etc.).

Yocto generated nativesdk-cmake SDK is incomplete

For the past couple of days I have been trying to generate a viable CMake SDK with Yocto Project. I'm trying to generate SDK based on an image file which is given below:
#To build SDK, use bitbake meta-toolchain
DESCRIPTION = "Embeddev-LXDE image."
LICENSE="CLOSED"
IMAGE_INSTALL = "packagegroup-core-boot \
packagegroup-core-x11 \
packagegroup-lxde-base \
kernel-modules \
"
IMAGE_INSTALL_append = " nano git cmake qtbase qtchooser dbus packagegroup-core-ssh-openssh xterm"
#Framebuffer driver for tft
IMAGE_INSTALL_append = " xf86-video-fbdev"
IMAGE_INSTALL_append = " apt dpkg sudo tzdata glibc-utils localedef networkmanager pointercal xinit xkeyboard-config base-passwd liberation-fonts pkgconfig"
IMAGE_INSTALL_append = " wiringpi"
#Maybe consider connman instead of networkmanager
#vc-graphics is problematic with userland..
inherit populate_sdk
## SDK stuff, to build sdk use bitbake rpi-embeddev-lxde-image -c populate_sdk
# Add all static packages: SDKIMAGE_FEATURES += "staticdev-pkgs"
SDKIMAGE_FEATURES += "staticdev-pkgs"
SDKIMAGE_FEATURES += "dev-pkgs"
TOOLCHAIN_TARGET_TASK_append = " wiringpi-dev"
TOOLCHAIN_HOST_TASK_append = " nativesdk-cmake"
##
inherit distro_features_check
REQUIRED_DISTRO_FEATURES = "x11"
IMAGE_LINGUAS ?= " "
LICENSE = "MIT"
export IMAGE_BASENAME = "rpi-embeddev-lxde-image"
inherit core-image
ENABLE_SPI_BUS = "1"
ENABLE_I2C = "1"
# qtwebengine qtwebkit ...
do_image_prepend() {
}
I create my SDK with bitbake rpi-embeddev-lxde-image -c populate_sdk.
I would like to describe the exact problem. The problem is that nativesdk-cmake is not correctly installed in the SDK. Cmake 3.10.2 recipe gives:
do_install_append_class-nativesdk() {
mkdir -p ${D}${datadir}/cmake
install -m 644 ${WORKDIR}/OEToolchainConfig.cmake ${D}${datadir}/cmake/
mkdir -p ${D}${SDKPATHNATIVE}/environment-setup.d
install -m 644 ${WORKDIR}/environment.d-cmake.sh ${D}${SDKPATHNATIVE}/environment-setup.d/cmake.sh
}
FILES_${PN}_append_class-nativesdk = " ${SDKPATHNATIVE}"
FILES_${PN} += "${datadir}/cmake-${CMAKE_MAJOR_VERSION}"
FILES_${PN}-doc += "${docdir}/cmake-${CMAKE_MAJOR_VERSION}"
BBCLASSEXTEND = "nativesdk"
Tracing the root of the problem, I have seen that the cmake/ directory that should be created is created in:
/home/<user>/poky/build/tmp/work/x86_64-nativesdk-pokysdk-linux/nativesdk-cmake/3.10.2-r0/image/opt/poky/2.4+snapshot/sysroots/x86_64-pokysdk-linux/usr/share/cmake/
However, this cmake directory is not valid in /opt/poky/2.4+snapshot/sysroots/x86_64-pokysdk-linux/usr/share/, -where it is actually needed- when I install the SDK to /opt, unfortunately.
Do I need to know anything else or do anything else regarding how to properly generate SDK?
I am really stuck here any help is much appreciated indeed.
Thanks in advance.
EDIT: I moved TOOLCHAIN_TASK statements to layer.conf and used bitbake meta-toolchain which also didn't work.
EDIT2: I used cmake version 3.6 with PREFERRED_PROVIDER_cmake = "3.6.1", which also did not work.
There seems to be a bug in the imminent Yocto Project 2.5, Sumo, release. Here, sysroots/x86_64-chargestorm-linux/usr/share/cmake/OEToolchainConfig.cmake seems to be omitted.
The temporary solution for this is to add
TOOLCHAIN_HOST_TASK += "nativesdk-cmake-dev"
And yes, using a release is always helpful, especially if your new to some project. Just remember to always use the same release branches for all your included layers. And personally, I'd not start a new project based on Morty, which was released 1.5 years ago when writing this, as it's likely to go out of official Yocto Project support rather soon.
As an aside, it seems that it is still a bug (Or would this be mis-feature at this point...?) in Sumo. Just got bit by this...workaround looks to be the same as described.
(Note: This is a release at this point in time... X-D)
Problem solved by using a release (I used "morty", and not the "master branch") for every layer and poky itself. This is apparently very important.

Library installation with yocto recipe

have a bit of a problem creating a recipe for yocto. More specifically i have to install a library from git that normally installs like this:
./bootstrap
./configure --sysconfdir=/etc
make
sudo make install
My question is how can I add this to the recipe functions do_configure, do_compile, do_install. Haven't found much information or examples online.
Update 1:
This is the library that i want to integrate into yocto
https://github.com/NXPNFCLinux/linux_libnfc-nci
It's just a regular autotools based library. The main issues, that someone ought to fix, are to make the build create versioned libraries and to add a LICENSE or COPYING file.
However, a quick recipe could look like:
SUMMARY = "Linux NFC stack for NCI based NXP NFC Controllers"
HOMEPAGE = ""
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://src/include/linux_nfc_api.h;endline=17;md5=42fdb99b3ff2c12f594b22a774cb7308"
SECTION = "libs"
SRC_URI = "git://github.com/NXPNFCLinux/linux_libnfc-nci.git"
SRCREV = "118ea118cecda55c1b6a87d151a77b04515687df"
PV = "2.0+git${SRCPV}"
S = "${WORKDIR}/git"
inherit autotools
FILES_${PN} += "${libdir}/libnfc_nci_linux-1.so"
# Make sure it isn’t in the dev package’s files list
FILES_SOLIBSDEV = "${libdir}/libnfc_nci_linux.so"
A versioned library would allow us to remove the last three lines.

Bitbake recipe to have pre and post install action

I am writing an custom recipe for the Bitbake for an Makefile based project. We are able to create the RPMs with all the files place in the package but we are not able to find a way for pre and post install action.
As the application runs as service we want to stop it in pre-install step and then start it in post-install step.
But I am not able to find the same so any thoughts to achieve it.
Below is the sample recipe we written for it.
DESCRIPTION = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
SRC_URI = "file://helloworld.c"
DEPENDS = "boost"
S = "${WORKDIR}"
do_compile() {
${CC} helloworld.c -o helloworld
}
PACKAGES = "helloworld"
do_install() {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}
install -d ${D}${sysconfig}/init.d
install -m 0755 ${S}/service ${D}${sysconfig}/init.d
}
I do see INITSCRIPT_PACKAGES and INITSCRIPT_PARAMS but their description doesn't talk about being pre and post action.
So any thoughts for putting %pre and %post (in terms of RPM spec) for this purpose.
You can add post install scripts in your .bb:
pkg_postinst_PACKAGENAME() {
#!/bin/sh -e
# Commands to carry out
}
Reference: Section 5.3.16 http://www.yoctoproject.org/docs/1.7.1/mega-manual/mega-manual.html
According to the documentation the examples only runs during image creation time. There is also another function that will only run on the first boot (and never after it). It uses the meta/recipes-devtools/run-postinsts recipe to accomplish this.
I ran into the same issue. See this post for how I did the post install script. Hopefully you can glean from that answer enough to modify it for your script.

How to write own package for recipe in arago project build

How can i write own package for recipe in arago project build? I know little bit that it can be bitbake files. But how can i write, no idea. I searched on internet, but failed to find any good source to start. can someone provide me link or example to start?
Regards
Linux Learner.
Create own recipe with Yocto using Bitbake:
Use Yocto Project for Embedded systems. It's documentation and support is awesome. You can get started Yocto Project.
Build your own recipe(for the first time build takes quiet good amount of time)
Getting Yocto Project:
Follow step-by-step procedure given Gumstix-YoctoProject-Repo till bitbake gumstix-console-image
Now you got yocto project on your machine. Start writing your own recipes. I will show you how to create a hello world recipe.
1) goto /yocto/poky/<create a folder as meta-robot>
2) goto /yocto/poky/meta-robot/<create a folder as /recipes-robot> and <another folder /conf>
3) goto /yocto/poky/meta-robot/recipes-robot/<create another folder /hello>
4) goto /yocto/poky/meta-robot/recipes-robot/hello/<create a file as 'hello_2.7.bb'>
5) Paste this in your hello_2.7.bb
DESCRIPTION = "GNU Helloworld application"
SECTION = "examples"
LICENSE = "GPLv3+"
LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
PR = "r0"
SRC_URI[md5sum] = "fc01b05c7f943d3c42124942a2a9bb3a"
SRC_URI[sha256sum] = "fd593b5bcf6d1bb6d7d1bb7eefdccdc0010cf2c4985ccb445ef490f768b927c0"
SRC_URI = "ftp://ftp.gnu.org/gnu/hello/hello-2.7.tar.gz"
inherit autotools gettext
6) goto /yocto/poky/meta-robot/conf/<create a file as layer.conf>
7) paste this in your layer.conf file
# We have a conf directory, append to BBPATH
BBPATH .= ":${LAYERDIR}"
# We have a recipes directory, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "meta-robot"
BBFILE_PATTERN_meta-robot := "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-robot = "7"
8) Open /yocto/build/conf/bblayers.conf file
9) Add your recipe folder path in bblayers file
ex: /home/xyz/yocto/poky/meta-robot \
10) open /yocto/poky/meta-gumstix-extras/recipes-images/gumstix/gumstix-console-image.bb file and under TOOLS_INSTALL add your recipe name i.e.hello \
11) Open your terminal type $ cd /yocto
12) $ source ./poky/oe-init-build-env
13) type bitbake gumstix-console-image
That's it. Your image with your own package will be ready in some time.
You can find your image in /yocto/build/tmp/deploy/images/
All the Best.
Arago is a distribution based on OpenEmbedded project and Bitbake build tool. Logically, you should start with Bitbake manual and OpenEmbedded manual. These are slightly outdated, but still relevant in most part. After that, there is a good, simple tutorial found here.
Also I find #oe channel on FreeNode to be very useful.
EDIT: There is a newer manual for Yocto/Poky that also covers Bitbake and OpenEmbedded.
I think what the other guy has answered to create a new recipe is actually creating a layer.
You can do it by
$ . ./setup-environment build-dir
$ yocto-layer create custom #here you may change the name to your custom layer name.
If you do this, it will automatically ask you to create an example recipe for you.
But I guess that's not the question.
You need to change or customize .bb file.
It has few fields namely
SOURCE_URI=" "
This is the one where you are getting the source tar file for the package.
Then do_compile = " " and do_install = " ". This may not be easy for a newbee like you and me.
You can create a recipe using create-recipe or recipetool.
Check the below link for their usage
http://ashversity.blogspot.in/2016/02/creating-new-yocto-recipe.html

Resources