TipsAndTricks/BuildingZephyrImages: Difference between revisions

From Yocto Project
Jump to navigationJump to search
No edit summary
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Back to [[TipsAndTricks]]
== Introduction ==
== Introduction ==
Yocto offers an alternative way of building [https://www.zephyrproject.org/ Zephyr Project] images by using the [http://git.yoctoproject.org/cgit/cgit.cgi/meta-zephyr meta-zephyr] layer.  
Yocto offers an alternative way of building [https://www.zephyrproject.org/ Zephyr Project] images by using the [http://git.yoctoproject.org/cgit/cgit.cgi/meta-zephyr meta-zephyr] layer.  


== Configuration ==
== Configuration ==
You'll need to install the following additional package <tt>python3-pexpect</tt>. If you're going to using the Arduino 101 board, you'll also need <tt>dfu-util</tt>.
You'll need to install the following additional package <tt>python3-pexpect</tt>. If you're going to using the Arduino 101 board, you'll also need to configure <tt>dfu-util</tt> as follows:


Checkout the meta-zephyr layer
=== Using DFU ===
git clone git://git.yoctoproject.org/meta-zephyr
Device Firmware Update (DFU) allows you to flash A101 images over USB without the need for a JTAG adaptor. First you'll need to install the package <tt>dfu-util</tt> on your Linux distro. By default dfu-util needs root privileges to run. You work around this with the following udev rules
The layer supports morty and master branches and is dependent on the equivalent poky branch.
* If on Fedora, you need to create the system group plugdev
$ sudo groupadd -r plugdev
* Add user to plugdev group
$ sudo usermod -a -G plugdev $USER
* Create file <tt>etc/udev/rules.d/50-arduino101.rules</tt> and add the following linr
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0aba", GROUP="plugdev", MODE="0666"
* Reload udev rules
$ sudo udevadm control --reload-rules
 
=== Zephyr Layer ===
meta-zephyr layer can be found at git://git.yoctoproject.org/meta-zephyr. The layer supports dunfell and master branches and is dependent on the equivalent poky branch.


== Boards and Machines ==
== 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"
Zephyr BOARDS typically map to bitbake MACHINES, but underscores become dashes. e.g. BOARD=arduino_101_sss maps to MACHINE = "arduino-101-sss"
== Building Qemu Image ==
 
Here are the steps. We'll use the morty branch for stability.
== 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 <tt>inhert zephyr-in-tree-build</tt> instead ?
* <tt>inhert deploy</tt> adds a deploy task (it's a standard poky base class)
* ZEPHYR_SRC_DIR sets location of application
* do_deploy puts image in a known location
 
<pre>
<pre>
$ git clone -b morty git://git.yoctoproject.org/poky
require zephyr-kernel.inc
$ git clone -b morty git://git.yoctoproject.org/meta-zephyr
require zephyr-kernel-common.inc
$ source poky/oe-init-build-env
inherit deploy
$ bitbake-layers add-layer ../meta-zephyr
 
ZEPHYR_SRC_DIR = "${S}/samples/philosophers"
ZEPHYR_BASE = "${S}"
OECMAKE_SOURCEPATH = "${ZEPHYR_SRC_DIR}"
 
do_deploy () {
    install -D ${B}/zephyr/${ZEPHYR_MAKE_OUTPUT} ${DEPLOYDIR}/${PN}.elf
}
 
addtask deploy after do_compile
do_install[noexec] = "1"
</pre>
</pre>
In local.conf (or set on command line)
 
DISTRO = "zephyr"
=== Targeting QEMU ===
MACHINE = "qemu-x86"
Here are the steps. We'll use the kirkstone (LTS) branch for stability.
<pre>
export MACHINE=qemu-x86
export DISTRO="zephyr"
branch=kirkstone
 
git clone -b ${branch} --recursive --depth 1 git://git.yoctoproject.org/meta-zephyr/
git clone -b ${branch} --recursive --depth 1 git://git.yoctoproject.org/poky
git clone -b ${branch} --recursive --depth 1 git://git.openembedded.org/meta-openembedded
source poky/oe-init-build-env
bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-openembedded/meta-python
bitbake-layers add-layer ../meta-zephyr/meta-zephyr-core
bitbake-layers add-layer ../meta-zephyr/meta-zephyr-bsp
 
</pre>
 
Now build a Qemu image of the canonical Zephyr sample
Now build a Qemu image of the canonical Zephyr sample
  bitbake zephyr-philosophers
  bitbake zephyr-philosophers
Running zephyr qemu images is still a bit clunky
Running zephyr qemu image
  ./tmp/sysroots/x86_64-linux/usr/bin/qemu-system-i386 -kernel ./tmp/deploy/images/qemu-x86/philosophers.elf -nographic -machine type=pc-0.14 -display none -clock dynticks -no-acpi -balloon none
  runqemu qemu-x86
And will produce output like this  
And will produce output like this  
:[[File:Zehpyr-philosophers-screen-shot.png]]
:[[File:Zehpyr-philosophers-screen-shot.png]]
=== Arduino 101 ===
Let's build the philosophers sample for Arduino 101 x86 core. Set up as for [[TipsAndTricks/BuildingZephyrImages#QEMU|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, use the flash_usb task to flash the target via DFU
bitbake zephyr-philosophers  -c flash_usb
Sample text output will appear on serial port.
== Arduino 101 and Multiconfig ==
Inter Processor Mailbox (IPM) is a Zephyr driver that allows communications between processors. The IPM sample shows communication between the x86 and ARC cores and is good way to exercise multi-config.
=== Configuration ===
Add the following to <tt>local.conf</tt>
DISTRO = "zephyr"
MACHINE ?= "arduino-101"
BBMULTICONFIG ?= "arduino-101 arduino-101-sss"
Create folder <tt>multiconfig</tt> under <tt>conf</tt> with a file <tt>arduino-101-sss.conf</tt>
+ conf
    + multiconfig
        arduino-101.conf
        arduino-101-sss.conf
The file <tt>conf/multiconfig/arduino-101.conf</tt> should contain:
MACHINE="arduino-101"
TMPDIR="${TOPDIR}/tmp-arduino-101"
The file <tt>conf/multiconfig/arduino-101-sss.conf</tt> should contain:
MACHINE="arduino-101-sss"
TMPDIR="${TOPDIR}/tmp-arduino-101-sss"
The TMPDIR settings are a workaround a multiconfig bug exposed by the meta-zephyr.
=== Building ===
Build both images:
$ bitbake multiconfig:arduino-101:zephyr-ipm multiconfig:arduino-101-sss:zephyr-ipm
=== Flashing ===
Once the build is finished (both images are built), flash:
$ bitbake multiconfig:*:zephyr-ipm -cflash_usb
=== Running ===
Press reset, serial output should look like this
<pre>
===== app started ========
Hello from application processor (x86)! (0) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
sending messages for IPM device 0xa80064e4
sending messages for IPM device 0xa80064d8
sending messages for IPM device 0xa80064cc
Hello from application processor (x86)! (1) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
pinging sensor subsystem (ARC) for counter status
ipm_console0: 'counters: 148 6 7'
ipm_console0: 'Hello from ARC!'
Hello from application processor (x86)! (2) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
pinging sensor subsystem (ARC) for counter status
ipm_console0: 'counters: 69 50 35'
</pre>

Latest revision as of 10:51, 25 September 2022

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 to configure dfu-util as follows:

Using DFU

Device Firmware Update (DFU) allows you to flash A101 images over USB without the need for a JTAG adaptor. First you'll need to install the package dfu-util on your Linux distro. By default dfu-util needs root privileges to run. You work around this with the following udev rules

  • If on Fedora, you need to create the system group plugdev
$ sudo groupadd -r plugdev
  • Add user to plugdev group
$ sudo usermod -a -G plugdev $USER
  • Create file etc/udev/rules.d/50-arduino101.rules and add the following linr
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0aba", GROUP="plugdev", MODE="0666"
  • Reload udev rules
$ sudo udevadm control --reload-rules

Zephyr Layer

meta-zephyr layer can be found at git://git.yoctoproject.org/meta-zephyr. The layer supports dunfell 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_deploy 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}"
OECMAKE_SOURCEPATH = "${ZEPHYR_SRC_DIR}"

do_deploy () {
    install -D ${B}/zephyr/${ZEPHYR_MAKE_OUTPUT} ${DEPLOYDIR}/${PN}.elf
}

addtask deploy after do_compile
do_install[noexec] = "1"

Targeting QEMU

Here are the steps. We'll use the kirkstone (LTS) branch for stability.

export MACHINE=qemu-x86
export DISTRO="zephyr"
branch=kirkstone

git clone -b ${branch} --recursive --depth 1 git://git.yoctoproject.org/meta-zephyr/
git clone -b ${branch} --recursive --depth 1 git://git.yoctoproject.org/poky
git clone -b ${branch} --recursive --depth 1 git://git.openembedded.org/meta-openembedded
source poky/oe-init-build-env
bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-openembedded/meta-python
bitbake-layers add-layer ../meta-zephyr/meta-zephyr-core
bitbake-layers add-layer ../meta-zephyr/meta-zephyr-bsp

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 philosophers 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, use the flash_usb task to flash the target via DFU

bitbake zephyr-philosophers  -c flash_usb

Sample text output will appear on serial port.


Arduino 101 and Multiconfig

Inter Processor Mailbox (IPM) is a Zephyr driver that allows communications between processors. The IPM sample shows communication between the x86 and ARC cores and is good way to exercise multi-config.

Configuration

Add the following to local.conf

DISTRO = "zephyr"
MACHINE ?= "arduino-101"
BBMULTICONFIG ?= "arduino-101 arduino-101-sss"

Create folder multiconfig under conf with a file arduino-101-sss.conf

+ conf
   + multiconfig
        arduino-101.conf
        arduino-101-sss.conf

The file conf/multiconfig/arduino-101.conf should contain:

MACHINE="arduino-101"
TMPDIR="${TOPDIR}/tmp-arduino-101"

The file conf/multiconfig/arduino-101-sss.conf should contain:

MACHINE="arduino-101-sss"
TMPDIR="${TOPDIR}/tmp-arduino-101-sss"

The TMPDIR settings are a workaround a multiconfig bug exposed by the meta-zephyr.

Building

Build both images:

$ bitbake multiconfig:arduino-101:zephyr-ipm multiconfig:arduino-101-sss:zephyr-ipm

Flashing

Once the build is finished (both images are built), flash:

$ bitbake multiconfig:*:zephyr-ipm -cflash_usb

Running

Press reset, serial output should look like this

===== app started ========
Hello from application processor (x86)! (0) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
sending messages for IPM device 0xa80064e4
sending messages for IPM device 0xa80064d8
sending messages for IPM device 0xa80064cc
Hello from application processor (x86)! (1) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
pinging sensor subsystem (ARC) for counter status
ipm_console0: 'counters: 148 6 7'
ipm_console0: 'Hello from ARC!'
Hello from application processor (x86)! (2) Sensor Subsystem (ARC) is sleeping, mailbox status: 00000000 mask fffff0ef
pinging sensor subsystem (ARC) for counter status
ipm_console0: 'counters: 69 50 35'