Search code examples
linux-kernelkernel-modulebitbakeyocto

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:

  1. 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.

  2. 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.

  3. 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...


Solution

  • 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