Search code examples
yoctobitbakeopenembedded

How can I get "HelloWorld - BitBake Style" working on a newer version of Yocto?


In the book "Embedded Linux Systems with the Yocto Project", Chapter 4 contains a sample called "HelloWorld - BitBake style". I encountered a bunch of problems trying to get the old example working against the "Sumo" release 2.5.

If you're like me, the first error you encountered following the book's instructions was that you copied across bitbake.conf and got:

ERROR: ParseError at /tmp/bbhello/conf/bitbake.conf:749: Could not include required file conf/abi_version.conf

And after copying over abi_version.conf as well, you kept finding more and more cross-connected files that needed to be moved, and then some relative-path errors after that... Is there a better way?


Solution

  • Here's a series of steps which can allow you to bitbake nano based on the book's instructions.

    Unless otherwise specified, these samples and instructions are all based on the online copy of the book's code-samples. While convenient for copy-pasting, the online resource is not totally consistent with the printed copy, and contains at least one extra bug.

    Initial workspace setup

    This guide assumes that you're working with Yocto release 2.5 ("sumo"), installed into /tmp/poky, and that the build environment will go into /tmp/bbhello. If you don't the Poky tools+libraries already, the easiest way is to clone it with:

    $ git clone -b sumo git://git.yoctoproject.org/poky.git /tmp/poky
    

    Then you can initialize the workspace with:

    $ source /tmp/poky/oe-init-build-env /tmp/bbhello/
    

    If you start a new terminal window, you'll need to repeat the previous command which will get get your shell environment set up again, but it should not replace any of the files created inside the workspace from the first time.

    Wiring up the defaults

    The oe-init-build-env script should have just created these files for you:

    • bbhello/conf/local.conf
    • bbhello/conf/templateconf.cfg
    • bbhello/conf/bblayers.conf

    Keep these, they supersede some of the book-instructions, meaning that you should not create or have the files:

    • bbhello/classes/base.bbclass
    • bbhello/conf/bitbake.conf

    Similarly, do not overwrite bbhello/conf/bblayers.conf with the book's sample. Instead, edit it to add a single line pointing to your own meta-hello folder, ex:

    BBLAYERS ?= " \
      ${TOPDIR}/meta-hello \
      /tmp/poky/meta \
      /tmp/poky/meta-poky \
      /tmp/poky/meta-yocto-bsp \
      "    
    

    Creating the layer and recipe

    Go ahead and create the following files from the book-samples:

    • meta-hello/conf/layer.conf
    • meta-hello/recipes-editor/nano/nano.bb

    We'll edit these files gradually as we hit errors.

    Can't find recipe error

    The error:

    ERROR: BBFILE_PATTERN_hello not defined
    

    It is caused by the book-website's bbhello/meta-hello/conf/layer.conf being internally inconsistent. It uses the collection-name "hello" but on the next two lines uses _test suffixes. Just change them to _hello to match:

    # Set layer search pattern and priority
    BBFILE_COLLECTIONS += "hello"
    BBFILE_PATTERN_hello := "^${LAYERDIR}/"
    BBFILE_PRIORITY_hello = "5"
    

    Interestingly, this error is not present in the printed copy of the book.

    No license error

    The error:

    ERROR: /tmp/bbhello/meta-hello/recipes-editor/nano/nano.bb: This recipe does not have the LICENSE field set (nano)
    ERROR: Failed to parse recipe: /tmp/bbhello/meta-hello/recipes-editor/nano/nano.bb
    

    Can be fixed by adding a license setting with one of the values that bitbake recognizes. In this case, add a line onto nano.bb of:

    LICENSE="GPLv3"
    

    Recipe parse error

    ERROR: ExpansionError during parsing /tmp/bbhello/meta-hello/recipes-editor/nano/nano.bb
    [...]
    bb.data_smart.ExpansionError: Failure expanding variable PV_MAJOR, expression was ${@bb.data.getVar('PV',d,1).split('.')[0]} which triggered exception AttributeError: module 'bb.data' has no attribute 'getVar'
    

    This is fixed by updating the special python commands being used in the recipe, because @bb.data was deprecated and is now removed. Instead, replace it with @d, ex:

    PV_MAJOR = "${@d.getVar('PV',d,1).split('.')[0]}"
    PV_MINOR = "${@d.getVar('PV',d,1).split('.')[1]}"
    

    License checksum failure

    ERROR: nano-2.2.6-r0 do_populate_lic: QA Issue: nano: Recipe file fetches files and does not have license file information (LIC_FILES_CHKSUM) [license-checksum]
    

    This can be fixed by adding a directive to the recipe telling it what license-info-containing file to grab, and what checksum we expect it to have.

    We can follow the way the recipe generates the SRC_URI, and modify it slightly to point at the COPYING file in the same web-directory. Add this line to nano.bb:

    LIC_FILES_CHKSUM = "${SITE}/v${PV_MAJOR}.${PV_MINOR}/COPYING;md5=f27defe1e96c2e1ecd4e0c9be8967949"
    

    The MD5 checksum in this case came from manually downloading and inspecting the matching file.

    Done!

    Now bitbake nano ought to work, and when it is complete you should see it built nano:

    /tmp/bbhello $ find ./tmp/deploy/ -name "*nano*.rpm*"
    ./tmp/deploy/rpm/i586/nano-dbg-2.2.6-r0.i586.rpm
    ./tmp/deploy/rpm/i586/nano-dev-2.2.6-r0.i586.rpm