Zybo Board bringup using Yocto Project

Requirements

For this tutorial you need an Ubuntu 14.04 and access to it via ssh plus an advanced text editor. My personal setup has Ubuntu 14.04 Server running as virtual machine in VMWare Fusion 7.0 and Eclipse Kepler for remote text editing. Basic GNU/Linux experience is needed, at least to install Ubuntu and navigate on CLI.

Yocto Project

Before to start is necessary to explain basic components of Yocto Project:

Yocto

The Yocto Project is an open source collaboration project that provides templates, tools and methods to help you create custom Linux-based systems for embedded products regardless of the hardware architecture.

Poky

Poky is a reference system of the Yocto Project – a collection of Yocto Project tools and metadata that serves as a set of working examples.

Bitbake

BitBake is a build engine that follows recipes in a specific format in order to perform sets of tasks. BitBake is a core component of the Yocto Project.

Yocto Installation

Let’s start installing Yocto. My personal suggestion is to install it on /opt/poky:

emcongiu@ubuntu:~$ sudo mkdir -p /opt/poky/1.7.1/prj-zybo
emcongiu@ubuntu:~$ sudo mkdir -p /opt/poky/downloads
emcongiu@ubuntu:~$ sudo mkdir -p /opt/poky/sstate-cache

Yocto works as normal user, so let’s change the ownership of ‘poky’ directory. My username is ’emcongiu’ so substitute it with your own:

emcongiu@ubuntu:~$ sudo chown -R emcongiu:emcongiu /opt/poky

Some repositories are needed to make poky works:

emcongiu@ubuntu:~$ sudo apt-get install openssh-server vim git build-essential diffstat texinfo gawk chrpath libsdl1.2-dev

The directories ‘downloads’ and ‘sstate-cache’ are outside any project so is possible to use them for different version and projects, decreasing the needs to downloads sources or build already prepared compiled objects.
It’s time to create base poky.

emcongiu@ubuntu:~$ cd /opt/poky/1.7.1/
emcongiu@ubuntu:/opt/poky/1.7.1$ git clone -b dizzy git://git.yoctoproject.org/poky prj-zybo

Extra Layers

Once the poky repository is ready we need to clone meta-xilinx and meta-zybo:

emcongiu@ubuntu:/opt/poky/1.7.1$ cd prj-zybo
emcongiu@ubuntu:/opt/poky/1.7.1/prj-zybo$ git clone -b dizzy git://git.yoctoproject.org/meta-xilinx
emcongiu@ubuntu:/opt/poky/1.7.1/prj-zybo$ git clone -b dizzy https://github.com/emcongiu/meta-zybo.git

Everything now is in place, we need to set poky environment to create all files needed by Zybo board:

emcongiu@ubuntu:/opt/poky/1.7.1/prj-zybo$ source oe-init-build-env

Edit file conf/bblayers.conf to add meta-xilinx and meta-zybo layers:

# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
/opt/poky/1.7.1/prj-zybo/meta \
/opt/poky/1.7.1/prj-zybo/meta-yocto \
/opt/poky/1.7.1/prj-zybo/meta-yocto-bsp \
/opt/poky/1.7.1/prj-zybo/meta-xilinx \
/opt/poky/1.7.1/prj-zybo/meta-zybo \
"
BBLAYERS_NON_REMOVABLE ?= " \
/opt/poky/1.7.1/prj-zybo/meta \
/opt/poky/1.7.1/prj-zybo/meta-yocto \
"

This enable poky to add all recipes and machines present in these extra layers to be used.

Local configuration file

The file conf/local.conf is used by poky to set what machine you wants to build and what directories will be used during ‘baking’.
To reach our scope we have to set the following variables at the end of the file:

MACHINE = "zybo-zynq7"
DL_DIR = "/opt/poky/downloads"
SSTATE_DIR = "/opt/poky/sstate-cache"

Bitbake recipes

It’s time to let Yocto to create all the toolchain, libraries and executables needed to have few files to copy on SD card. First time ‘bitbake’ will be launched will take a while, depending on your internet speed and computing power, so account for at least 45 minutes till several hours to get the bake done.
Pay attention to have at least 40G of space on where /opt is mounted and to have ‘sourced’ environment as we done in previous step (in ‘/opt/poky/1.7.1/prj-zybo’ directory type command ‘source oe-init-build-env’).

emcongiu@ubuntu:/opt/poky/1.7.1/prj-zybo/build$ bitbake core-image-minimal

SD Card preparation

In this tutorial SD Card will be formatted to have two partition as follow:

  • First Partition: 32M formatted as msdos
  • Second Partition: remaining card space formatted as ext4

In my experience I had always troubles in using embedded SD card readers in virtual machines, so in case you are using virtual environment I suggest to use a single microSD to USB adapter and connect it to virtual machine to handle microSD Card storage.

Partitioning

Before to partitioning we have to be sure to point to correct storage otherwise we risk to brush away the wrong disk.
Once the microSD to USB adapter is connect the system should recognize it and at the end of ‘dmesg’ printout you should find something like this:

$ dmesg
...
[ 1971.103846] usb 1-2: new high-speed USB device number 3 using ehci-pci
[ 1971.323890] usb 1-2: New USB device found, idVendor=0bda, idProduct=0153
[ 1971.323903] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1971.323906] usb 1-2: Product: USB2.0-CRW
[ 1971.323907] usb 1-2: Manufacturer: Generic
[ 1971.323909] usb 1-2: SerialNumber: 20120926571200000
[ 1971.365298] usb-storage 1-2:1.0: USB Mass Storage device detected
[ 1971.365864] scsi33 : usb-storage 1-2:1.0
[ 1971.366091] usbcore: registered new interface driver usb-storage
[ 1972.368666] scsi 33:0:0:0: Direct-Access Generic- SD/MMC/MS PRO 1.00 PQ: 0 ANSI: 4
[ 1972.369298] sd 33:0:0:0: Attached scsi generic sg2 type 0
[ 1973.092259] sd 33:0:0:0: [sdb] 7774208 512-byte logical blocks: (3.98 GB/3.70 GiB)
[ 1973.094588] sd 33:0:0:0: [sdb] Write Protect is off
[ 1973.094594] sd 33:0:0:0: [sdb] Mode Sense: 2f 00 00 00
[ 1973.096919] sd 33:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 1973.106386] sdb: sdb1 sdb2
[ 1973.113640] sd 33:0:0:0: [sdb] Attached SCSI removable disk

Depending on manufacturer and size of your microSD Card you will have different values on this part of dmesg printout but the point is that your Direct-Access Generic- SD/MMC/MS PRO device is attached as [sbd] device.
This device will be used exclusively for Zybo board so we need to remove all previous partition, if any:

$ sudo fdisk /dev/sdb

Once entered let’s check for actual state with ‘p’ command:
Command (m for help): p
...
Device Boot Start End Blocks Id System
/dev/sdb1 2048 67583 32768 83 Linux
/dev/sdb2 67584 7774207 3853312 83 Linux

In case microSD Card is new you will probably find just one partition in FAT32 system type of the size of the card.
We need to delete all previous partition using ‘d’ command:
Command (m for help): d
Partition number (1-4): 2
Command (m for help): d
Selected partition 1

Again, in this example we have two partition, but probably your microSD Card is new and have just a single partition, so just a single ‘d’ command is what is needed.
Now at ‘p’ command you do not find any partition:
Command (m for help): p
...
Device Boot Start End Blocks Id System

Perfect, this means that we are ready to partition the card as we need. The sequence is the following:
n
p
1
[enter]
+32M
This is what should like on console:
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-7774207, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-7774207, default 7774207): +32M

First partition is msdos type so we need to change ID to it.
Sequence:
t
1
c
Console:
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Ready for second partition. This is the command sequence:
n
p
2
[enter]
[enter]
Console:
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (67584-7774207, default 67584):
Using default value 67584
Last sector, +sectors or +size{K,M,G} (67584-7774207, default 7774207):
Using default value 7774207

This second partition will contain an ext4 filesystem so we change type ID to 83:
t
2
83
Console:
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 83

Almost done, just check with ‘p’ command if everything is in place:
Command (m for help): p
...
Device Boot Start End Blocks Id System
/dev/sdb1 2048 67583 32768 c W95 FAT32 (LBA)
/dev/sdb2 67584 7774207 3853312 83 Linux

Last step is to write MBT with command ‘w’:
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Formatting

Now that the microSD Card is correctly partitioned is possible to format it:

$ sudo mkfs.msdos /dev/sdb1
mkfs.fat 3.0.26 (2014-03-07)
$ sudo mkfs.ext4 /dev/sdb2
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
977280 inodes, 3902976 blocks
195148 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3997171712
120 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Populating

First partition should contain all files related to bootstrap (in the case FSBL, u-boot, environment file, device-tree and linux kernel).
The second one will contain root file system.
Bitbake already created all files and publish them in ‘build/tmp/deploy’ directory, you just need to copy them in the correct partition.
First we need to mount both partition:

$ sudo mkdir -p /media/mmc0p1
$ sudo mkdir -p /media/mmc0p2
$ sudo mount /dev/sdb1 /media/mmc0p1
$ sudo mount /dev/sdb2 /media/mmc0p2

Then copy the files for first partition:

$ sudo cp tmp/deploy/images/zybo-zynq7/boot.bin /media/mmc0p1/
$ sudo cp tmp/deploy/images/zybo-zynq7/u-boot.img /media/mmc0p1/
$ sudo cp tmp/deploy/images/zybo-zynq7/uEnv.txt /media/mmc0p1/
$ sudo cp tmp/deploy/images/zybo-zynq7/zybo-zynq7.dtb /media/mmc0p1/
$ sudo cp tmp/deploy/images/zybo-zynq7/uImage /media/mmc0p1/

Last untar root filesystem to second partition:

$ cd /media/mmc0p2
/media/mmc0p2$ sudo tar xzvf /opt/poky/1.7.1/prj-zybo/build/tmp/deploy/images/zybo-zynq7/core-image-minimal-zybo-zynq7.tar.gz

Almost done, just unmount and eject microSD Card:

/media/mmc0p2$ cd
$ sync
$ sudo umount /media/mmc0p1
$ sudo umount /media/mmc0p2
$ sudo eject /dev/sdb

Now is safe to extract microSD Card from adapter and insert it to your Zybo board.

Board Testing

Connect USB cable to the board and power on. After few seconds LD4 should blink like an heart (the LED trigger is call heartbeat…) and you should be able to connect to board terminal and start playing.
Enjoy!

8 thoughts on “Zybo Board bringup using Yocto Project

  1. Hi, good job, I enjoyed this.
    Only one question, What is the login and password for init the system?.

    Thanks so much.
    Best regards,
    Fer.

    Like

  2. Hi Enzo,

    One question again, I’ve been reading and seeing your page but I don’t understand all so well, the question is, Why we need the extra layer meta-xilinx?, is not enough with the layer meta-zybo?
    I wish, you can help me.

    Regards,
    Fer.

    Like

    1. Hi Fernando,

      meta-xilinx layer is needed to deploy and configure linux-xlnx, a Xilinx patched version of mainline Linux Kernel that is needed for zynq processor (at least up until FPGA Manager framework will be incorporated in mainline kernel).

      Regards,
      Enzo

      Like

      1. Again thanks so much Enzo, really you’re great, thanks for that.

        Now I wish to help me with last question, I hope you do not mind.
        Well, I have my bitstream (.bit) generated on Vivado, now I want to know how can I create the boot.bin with Yocto using this bitstream.
        I think, I must write this on one recipe but really I don’t know.
        Really thanks for all this, I wish can you help me with that.

        Regards,
        Fer.

        Like

    1. Hi Gary,

      To have zc702 board running you do not needs my meta layer, just add meta-xilinx and set variable MACHINE in local.conf as ‘zc702-zynq7’. Should be enough.

      Regards,
      Enzo

      Like

Leave a comment