Using our own local linux kernel source code on Yocto Project - linux-kernel

We need use our customized linux kernel source code on Yocto Project, is it possible to use our kernel source code with tar file and put it on downloads folder, then use SRC_URI = file://xxx.tar.gz on bb file, let tar file to be the kernel source? if not, how to do this on our own software project development?
BR,
Jack

virtual/kernel recipes in Yocto are just simple recipes like all recipes.
So, you can set your recipe source to whatever Yocto supports as source type (git, file, ...)
For your case, you can:
Host your custom kernel in a local private git server and use git
Use a local kernel compressed source file and use file

SRC_URI = file://xxx.tar.gz is correct.
You should not put files into the download folder, bitbake will do that when it downloads something. Put it to your source if you use file://.
If your file is not found from the default FILESPATH you can add extra directories to search using something like FILESEXTRAPATHS_prepend := "${COREBASE}/../mysrc:".
Use bitbake -e [recipe] if you are unsure where the variables point to.

Related

How to include tools/commands in yocto image recipe?

I have a question regarding including different tools into Yocto image recipe. Currently I am building image recipe for my Avenger96 board. I have created a base image and it runs fine on the device. But when I try to do sgdisk after booting it says -sh: sgdisk: command not found. I understand that these commands are not available by default and need to install it.
But I am not sure how to do it given my board is not connected to internet. Can I include these commands/tools in image recipe? I want to use some other commands like ufw, etc but I have same issue with them too.
Can someone please let me know how to do this?
Your help will be much appreciated.
Thanks in advance.
P.S: I am using Ubuntu 20.04 with Yocto as build system.
sgdisk is present under recipe: meta/recipes-devtools/fdisk/gptdisk_xx.bb
For xx it depends on your poky version.
For dunfell this is the recipe here.
ufw is present in meta-openembedded/meta-networking/recipes-connectivity/ufw
So, make sure meta-openembedded/meta-networking is present in your bblayers.conf and to include both of them add the following line to local.conf or to your custom image file:
IMAGE_INSTALL_append = " gptfdisk ufw"
If you still do not find sgdisk try gptdisk-sgdisk.
If you want to add any recipe in the future, try to look for it in the official yocto git repositories in this link.
It is not recommended to add tools manually into the board, unless you are in the development process and you need to gain time, so here are some ideas for you:
Create an image for development that includes all dev features (gcc, g++, cmake, ..etc)
Include git and other fetching tools
Clone the tool's source code and compile it in the board
Or: bitbake the recipe with Yocto and copy the output binary directly to the image via ssh or other ways.

Buildroot - menuconfig creates config, but won't make

I'm trying to use buildroot to create a cross-compiler toolchain for MIPS64 (little endian).
I have run make menuconfig and have set the target to MIPS64 (little endian). Also I am being told that the config file has been generated and I can run make (as below)
configuration written to /home/blah/Downloads/buildroot-2018.02.6/mipsel64.config
*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
So, I then run make and I get the following:
Makefile:864: *** Please configure Buildroot first (e.g. "make menuconfig"). Stop.
Any ideas?
Try to copy your buildroot config file to .config file in your buildroot directory. It may look like:
cp /home/blah/Downloads/buildroot-2018.02.6/mipsel64.config /home/blah/Downloads/buildroot-2018.02.6/.config
assuming that /home/blah/Downloads/buildroot-2018.02.6/ is your buildroot compilation directory.
Then try to do make.
Don't ask menuconfig to save to a file, just exit and answer Yes when asked Do you wish to save your new configuration?. This way it will save a file named .config, which is exactly the file neeeded for building.

Getting kernel config from defconfig

The title says it all: I need the .config file that was used for compiling a kernel, but all I have is the defconfig file. I've seen instructions on how to produce the latter from the former, but not the other way around. Is it possible?
If you know the base config against which your defconfig file was generated, you can merge against it. Kernel version doesn't have to be exactly the same - new options will stay on default.
Assuming the base which your defconfig file was generated against was x86_64_defconfig (most likely) and you just have copied it into the linux source tree:
$ make mrproper
$ scripts/kconfig/merge_config.sh defconfig
If there are no errors, the .config file is now ready and you can run make to build the kernel.
For further help run $ scripts/kconfig/merge_config.sh -h or peek into the script.
You can't.
defconfig files are basic and minimalist config for one target architecture, and are just a starting point used to define a real .config.
You can instead retrieve .config used by other ways : look here on super-user

Using populate_sdk to include kernel headers

How do I include the linux kernel headers as part of the SDK package in Yocto?
I'm using Yocto 1.8 (fido) in an embedded project and want to do out-of-tree kernel module development. Currently, I can build my kernel modules (apart from bitbake) by pointing my $KERNEL_PATH to the poky/build/tmp/work-shared/<machine>/kernel-source/ directory when I run make. I don't want to do this in the long term, however, since others need to easily build the modules without installing and building a full image from bitbake.
I can generate an SDK using bitbake myimage -c populate_sdk. However, this doesn't include the kernel headers (all I ever see is sysroots/<mach>/usr/include/linux). How do I cause the kernel headers to be included in the SDK package? Also, I don't want the kernel headers to show up as part of my target image.
[Edit]
My image recipe is as follows:
EXTRA_IMAGE_FEATURES_append = " eclipse-debug debug-tweaks"
TOOLCHAIN_HOST_TASK_append = " nativesdk-cmake"
IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL} util-linux kernel-modules netbase busybox base-passwd base-files sysvinit initscripts bash gdbserver strace sysfsutils dtc gawk ethtool grep sed wget iptables oprofile net-tools dropbear rsync stress-ng rt-tests i2c-tools"
inherit core-image
The kernel I'm using is linux-altera-ltsi-rt in the meta-altera layer.
From the fido release, the handling of kernel builds has been changed. In previous releases, you could usually just skip down to the usage example below.
In fido or any 1.8+, if you want the kernel src and build system available in the SDK, you should add
TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc"
to your image recipe. That will ensure that the new, kernel-devsrc package is installed into your toolchain.
The procedure below is just to ensure that the rest of the workflow is fully understood (even though it's not strictly part of the original question).
Usage Example
Lets assume a module Makefile as follows:
obj-m += hello-1.o
all:
make -C $(KERNEL_SRC) M=$(PWD) modules
clean:
make -C $(KERNEL_SRC) M=$(PWD) clean
Example taken from The Linux Kernel Module Programming Guide (Note that the actual commands needs to have a tab character for indentation).
Then you'll have to define KERNEL_SRC to be sysroots/<mach>/usr/src/kernel/, either in the Makefile, or from your make call. (Using a variable like KERNEL_SRC will ensure that your module recipe automatically picks the right location when building using bitbake).
To manually build your kernel module:
Source the environment-* file for your SDK.
Go to you modules directory.
KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make However, this will fail, as fixdep can't be found. We'll fix this manually.
cd <sdk-install-path>/sysroots/<mach>/usr/src/kernel
make modules_prepare
If this needs to be run with sudo, be sure to source the environment file in the sudo environment: sudo bash -c "source <sdk-install-path>/environment-setup-<mach> && make modules_prepare"
Go back to your modules directory.
KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make
This should now allow you to build your modules.
If you don't have the kernel source under sysroots/<mach>/usr/src/kernel/, we'll have to look into that.
anders answer is very good, but in recent versions of yocto the way to add kernel-devsrc seems to be
IMAGE_INSTALL += "kernel-devsrc"
which I found here: https://www.mail-archive.com/yocto#yoctoproject.org/msg36448.html
With Yocto Zeus (3.0.x) add this to your image recipe:
TOOLCHAIN_TARGET_TASK += "kernel-devsrc"
EDIT: Same for Gatesgarth (3.2.x) but the make scripts command has a new host dependency to libyaml-dev

How can I extract the environment variables used when building a recipe in Yocto?

I am working on a kernel module for a project using Yocto Linux (version 1.3). I want to use the kernel headers and the compiler and libraries from my Yocto project, but develop the kernel module without needing to run bitbake every time. My initial solution to this was to execute the devshell task and extract the environment variables using something like this:
bitbake mykernel -c devshell
Then in the new xterm window bitbake opened for me:
env | sed 's/\=\(.*\)/\="\1"/' > buildenv #put quotes around r-values in env listing
^D #(I leave the devshell)
Then copy this to my development directory and source it before running make with all of its options
KERNEL_PATH=/mypathto/build/tmp/sysroots/socfpga_cyclone5/usr/src/kernel
source ./buildenv && make -C $KERNEL_PATH V=1 M=`pwd` \
ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf- \
KERNEL_VERSION=3.13.0-00298-g3c7cbb9 \
CC="arm-linux-gnueabihf-gcc -mno-thumb-interwork -marm" \
LD=arm-linux-gnueabihf-ld AR=arm-linux-gnueabihf-ar
Now to my questions:
Am I going about this completely wrong? What is the recommended way to cross-develop kernel modules? I am doing it this way because I don't want to open a bitbake devshell and do my code development in there every time.
This sort of works (I can compile working modules) but the make script gives me an error message saying that the kernel configuration is invalid. I have also tried this with KERNEL_PATH set to the the kernel package git directory (build/tmp/work///git (which contains what appears to be a valid .config file) and I get a similar error.
How can I extract the env without needing to open a devshell? I would like to write a script that extracts it so my coworkers don't have to do it manually. The devshell command opens a completely separate Xterm window, which rather dampens its scriptability...
the sdk installer is what you are looking for:
bitbake your-image -c populate_sdk
then, from your build directory go to tmp/deploy/sdk
and execute the generated shell script.
this script will allow you to generate and install an sdk.
Not only the sdk will allow you to (cross) compile your kernel by providing the needed environment variables and tools, but it will also provide a sysroot + a standalone toolchain to help you easily (and by easily I mean really easily) crosscompile applications with the autotools (as long as you provide Makefile.am and configure.ac)
just source the environment-setup-* file, got to your kernel directory and compile.
Or, for application developpment based on the autotools,
go to the folder containing your project (sources + Makefile.am and configure.ac)
and do:
libtoolize --automake
aclocal
autoconf
automake -a
now your project is ready for compilation:
./configure $CONFIGURE_FLAGS
make
make install DESTDIR=path/to/destination/dir
If you're after a quick hack, instead of Ayman's more complete solution, the scripts run to complete each build stage are available in the directory:
./build/tmp/work/{target_platform}/{package}/{version}/temp/run.do_{build_stage}
These scripts can be run standalone from the ./temp/ directory, and contain all of the environment variables required.

Resources