TipsAndTricks/BuildingZephyrImages

From Yocto Project
Revision as of 00:14, 3 March 2017 by Henry Bruce (talk | contribs)
Jump to navigationJump to search

Back to TipsAndTricks

Introduction

Yocto offers an alternative way of building Zephyr Project images by using the meta-zephyr layer.

Configuration

You'll need to install the following additional package python3-pexpect. If you're going to using the Arduino 101 board, you'll also need dfu-util.

meta-zephyr layer can be found at git://git.yoctoproject.org/meta-zephyr. The layer supports morty and master branches and is dependent on the equivalent poky branch.

Boards and Machines

Zephyr BOARDS typically map to bitbake MACHINES, but underscores become dashes. e.g. BOARD=arduino_101_sss maps to MACHINE = "arduino-101-sss"

Building Zephyr samples

The following instructions build the philosophers sample.

Recipe

The recipe is pretty simple, see below.

  • Think of the require statements as the zephyr base class (could/should be inhert zephyr-in-tree-build instead ?
  • inhert deploy adds a deploy task (it's a standard poky base class)
  • ZEPHYR_SRC_DIR sets location of application
  • do_compile is straightforward. Could/should be in a base class?
  • do_deply puts image in a known location
require zephyr-kernel.inc
require zephyr-kernel-common.inc
inherit deploy

ZEPHYR_SRC_DIR = "${S}/samples/philosophers"
ZEPHYR_BASE = "${S}"

do_compile () {
    cd ${ZEPHYR_SRC_DIR}
    oe_runmake ${ZEPHYR_MAKE_ARGS}
}

do_deploy () {
    install -D samples/philosophers/outdir/${BOARD}/zephyr.elf ${DEPLOYDIR}/${PN}.elf
    install -D samples/philosophers/outdir/${BOARD}/zephyr.bin ${DEPLOYDIR}/${PN}.bin
}

addtask deploy after do_compile

QEMU

Here are the steps. We'll use the morty branch for stability.

$ git clone -b morty git://git.yoctoproject.org/poky
$ git clone -b morty git://git.yoctoproject.org/meta-zephyr
$ source poky/oe-init-build-env
$ bitbake-layers add-layer ../meta-zephyr

In local.conf (or set on command line)

DISTRO = "zephyr"
MACHINE = "qemu-x86"

Now build a Qemu image of the canonical Zephyr sample

bitbake zephyr-philosophers

Running zephyr qemu image

runqemu qemu-x86

And will produce output like this

Zehpyr-philosophers-screen-shot.png

Arduino 101

Let's build the philosphers sample for Arduino 101 x86 core. Set up as for QEMU but set machine as follows

MACHINE = "arduino-101"

Then run

bitbake zephyr-philosophers

Note that there will be significant rebuild, as although both qemu-x86 and arduino-101 are 386 class devices, arduino-101 uses the subtly different IAMCU toolchain.

After build complete, image will in tmp/deploy/images/arduino-101/zephyr-philosophers.bin. Flash as follows using dfu

dfu-util -a x86_app -D tmp/deploy/images/arduino-101/zephyr-philosophers.bin

Sample text output will appear on serial port.