Raspberry Pi Zero with Ubuntu-style Yocto-gcc with libusb

Thing you want to do

Run Yocto Project on Raspberry Pi Zero WH. You can use Wi-Fi, you can use gcc, and you can control USB with libusb. I referred to various information, but I was in trouble here and there. Now that it's finally working, I'll summarize what I've done.

It looks like this when I write it in a diagram. linux_Yocto概要(一般).PNG

environment

Approximately as shown in the figure above.

On the host PC side

The target side

So, Yocto Projecto will use 3.1 (Dunfell). I use Dunfell because it's close to the release date of Ubuntu 20.04.1.

About 128GB of virtual HDD is allocated to Ubuntu. Even with 64GB, I think that what is written after that can be done at the last minute. At 32GB, DiskFull build failed. Please be careful.

Reference material

https://blog.web.nifty.com/engineer/1040 I used this as a reference. I'm doing almost the same flow as here. It is different in some places due to the difference in version and the package you want to put.

Create a Yocto environment

We will assume that you have Virtual Box 6.1 on your Windows 10 PC and Ubuntu 20.04.1 is running. I will not explain the environment so far in detail.

Installation of packages required for Yocto environment

Install by referring to this article

$ sudo apt-get install sed wget subversion git-core coreutils unzip texi2html texinfo libsdl1.2-dev docbook-utils fop gawk python-pysqlite2 diffstat make gcc build-essential xsltproc g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev autoconf automake groff libtool xterm libxml-parser-perl

I feel that this wasn't enough. I will add it if I remember.

Bring Poky and prepare the build environment

It's like working in yocto / rpi0 in your home directory. This area is your choice. Bring the dunfell branch of Poky and meta-raspberry pi.

$ mkdir yocto
$ cd yocto
$ mkdir rpi0
$ cd rpi0
$ git clone git://git.yoctoproject.org/poky.git -b dunfell
$ cd poky
$ git clone git://git.yoctoproject.org/meta-raspberrypi -b dunfell
$ source oe-init-build-env ../build

If the command is successful, a build directory will be created and you will be moved to it.

Edit layer

I bring meta-openembedded and meta-linaro. Branch at dunfell to fit above. I brought meta-linaro with the intention of making gcc linaro, but I didn't actually use it. Maybe it will work after this without it. However, I have not confirmed it without meta-linaro, so I will leave it here for the time being.

$ cd ../poky
$ git clone git://git.openembedded.org/meta-openembedded -b dunfell
$ git clone git://git.linaro.org/openembedded/meta-linaro.git -b dunfell
$ cd ../build
$ nano conf/bblayers.conf

I often use it on Raspberry Pi, so it's a nano group. Add meta-openembedded series and meta-raspberrypi to bblayers.conf.

bblayers.conf


# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

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

BBLAYERS ?= " \
  /home/mine/yocto/rpi0/poky/meta \
  /home/mine/yocto/rpi0/poky/meta-poky \
  /home/mine/yocto/rpi0/poky/meta-yocto-bsp \
  /home/mine/yocto/rpi0/poky/meta-openembedded/meta-oe \
  /home/mine/yocto/rpi0/poky/meta-openembedded/meta-networking \
  /home/mine/yocto/rpi0/poky/meta-openembedded/meta-perl \
  /home/mine/yocto/rpi0/poky/meta-openembedded/meta-python \
  /home/mine/yocto/rpi0/poky/meta-raspberrypi \
  "

edit local.conf and add packages

Editing local.conf

$ nano conf/local.conf

Copy and paste reference almost as it is. The differences are explained below. I've added these at the top of local.conf and left the others at their defaults. dl_dir ?= "${topdir}/downloads"Line is uncommented and enabled.

local.conf


# machine setting
MACHINE = "raspberrypi0-wifi"

DISTRO_FEATURES_append = " bluez5"
COMBINED_FEATURES_append = " alsa ext2 usb-gadget usbhost wifi bluetooth"

# images
IMAGE_INSTALL_append = " linux-firmware-bcm43430 connman connman-client pulseaudio pulseaudio-server usbutils sudo "
IMAGE_INSTALL_append = " libusb-compat libusb-compat-dev libusb1 nano net-tools bash libjpeg-turbo libjpeg-turbo-dev tiff "
IMAGE_FEATURES_append = " ssh-server-dropbear"
EXTRA_IMAGE_FEATURES_append = " tools-sdk "
 
# use systemd
DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""
IMX_DEFAULT_DISTRO_FEATURES_append = " systemd"
 
# host setup
hostname_pn-base-files = "yoctopi"
INHERIT_append = " extrausers"
EXTRA_USERS_PARAMS = "useradd -P raspberry pi;usermod -P raspberry root;"

Finally build

Build

Build with the bitbake command in the build directory. I've written on various sites to build with $ bitbake rpi-hwup-image, but when I tried it, I got a warning like" rpi-hwup-image is deprecated ". The new one seems to use core-image-base.

$ bitbake core-image-base

In my environment, wait for about 8 hours. .. If successful, you will have a file in build / tmp / deploy / images / raspberrypi0-wifi /. It seems that there is a file with the extension .rpi-sdimg in the old environment, but it seems that it can not be created by default from some time (it seems that it can be created depending on the setting).

So, I use a file with a name like core-image-base-raspberrypi0-wifi-YYYYMMDDhhmmss.rootfs.wic.bz2. Does YYYYMMDDhhmmss contain the build start time? Is there a build end time? (I don't care too much)

Write to SD card

Write with the dd command from Ubuntu.

Plug the USB card reader into your Windows 10 PC and select [Device]-> [USB]-> [Card Reader device-like name] from the VirtualBox menu to make it visible to Ubuntu. When I checked it with the "Disk" app, it was assigned to / dev / sdb in my environment. I think this is different in each environment.

Also, I don't know if it is necessary or unnecessary, but for the time being, I initialize all the partitions of the SD card every time, format it with ext4 and write it. It takes a few minutes to write, so it is troublesome to start over, so to prevent failure.

$ cp tmp/deploy/images/raspberrypi0-wifi/core-image-base-raspberrypi0-wifi-YYYYMMDDhhmmss.rootfs.wic.bz2 [Somewhere suitable directory]
$ cd [Somewhere suitable directory]
$ bunzip2 core-image-base-raspberrypi0-wifi-YYYYMMDDhhmmss.rootfs.wic.bz2
$ sudo dd if=core-image-base-raspberrypi0-wifi-YYYYMMDDhhmmss.rootfs.wic of=/dev/sdb bs=1M

I'm scared when something strange happens, so I copy it to a suitable directory and work on it. It seems that you can extract the .wic.bz2 file with bunzip2 and write it to the SD card as it is with the dd command.

I'll finally move it

Insert the SD card with Yocto written in it into the Raspberry Pi Zero WH, connect HDMI and keyboard, and turn on the power.

Launch from the rainbow screen familiar to Raspi users. Then, a startup message came out, ...

yoctopi login:

If the message comes out, it is a success. You can log in as pi user or root and use it as much as you want.

Try using gcc for the time being

Is it like this?

$ nano hoge.c

hoge.c


#include <stdio.h>

int main()
{
    printf("hogehoge!\n");
    return 0;
}
$ gcc hoge.c -o hoge
$ ./hoge
hogehoge!

I won't write "Hello world!" Oh, it was an alphabetic keyboard layout in the default state. If you connect a Japanese keyboard, you will be confused by typing symbols.

libusb test

$ nano testUsb.c

testUsb.c


#include <stdio.h>
#include <usb.h>

int main()
{
    usb_init();
    printf("usb_init(): OK\n");
    return 0;
}
$ gcc testUsb.c -o testUsb -lusb
$ ./testUsb
usb_init(): OK

There was nothing OK, but if you build without -lusb, you will get a link error because there is no usb_init (), so libusb seems to be working as it is.

Try connecting to Wi-Fi

I've included connman in the edit of local.conf, so let's connect it to Wi-Fi. Like this.

$ connmanctl
connmanctl> technologies
connmanctl> enable wifi
connmanctl> scan wifi
connmanctl> services
[A lot of scanned access points come out]
connmanctl> agent on
connmanctl> connect [Enter one of the scanned access points]
  Passphrase? [Enter passphrase]
connmanctl> quit

If you connect to an open access point, you don't need agent on. If you connect to the access point with this, you can also connect to SSH from a PC on the LAN. It seems that the settings of the access point that was connected once are saved somewhere, and from the next time it was connected without permission.

Summary

For the time being, Yocto Project 3.1 (Dunnfell) has run on the Raspberry Pi Zero WH. It seems that you can do various things because it is connected to Wi-Fi and C language works, but in reality it is undecided what to use.

Also, with the settings introduced here, Perl and Python were supposed to work, but Perl was working and Python wasn't. I'm investigating what's wrong, but if anyone knows how to get Python working, please let me know.

Recommended Posts

Raspberry Pi Zero with Ubuntu-style Yocto-gcc with libusb
Find Raspberry Pi from Android with mDNS
Launched Redmine with Docker on Raspberry Pi 3
I couldn't install docker with raspberry pi2 b +.
How to run javafx with Raspberry Pi Posted on 2020/07/12
Play down with Raspberry PI4 as a server. Part 2
Display characters on I2C 1602 LCD with Raspberry Pi 3 & Java
Read temperature / humidity with Java from Raspberry Pi 3 & DHT11