Skip to content

Raspberry Pi Investigation Build Instructions

Mark Millard edited this page Jan 18, 2024 · 13 revisions

This page describes work being done to bring up the Magic Lantern Studio SDK and Titles on a Raspberry Pi platform.

Table of Contents

Resources

Dependencies

  • Ubuntu 20.04 LTS 64-bit Linux OS

Details

These instructions are derived from the Jumpnowtek Yocto Build Instructions

Setup Host Development Machine

These instructions use the Ubuntu 20.04 LTS 64-bit Linux platform for building the Raspberry Pi image using Yocto.

Install Linux packages on Host Development Machine

sudo apt-get update
sudo apt-get install build-essential chrpath diffstat gawk libncurses5-dev python3-distutils texinfo git

Configure for Bash Shell

Change the default Ubuntu shell from dash to bash by running this command from a shell:

sudo dpkg-reconfigure dash

Choose No to dash when prompted.

Configure Yocto Build System

These instructions describe how to build the Raspberry Pi images using the Yocto build system.

Clone the dependency repositories

For all upstream repositories, use the dunfell branch.

The directory layout described here is my preference. All of the paths to the meta-layers are configurable. If you choose something different, adjust the following instructions accordingly.

First retrieve the main Yocto project poky layer:

git clone -b dunfell git://git.yoctoproject.org/poky.git poky-dunfell

Then retrieve the dependency layers:

cd poky-dunfell
git clone -b dunfell git://git.openembedded.org/meta-openembedded
git clone -b dunfell https://github.com/meta-qt5/meta-qt5
git clone -b dunfell git://git.yoctoproject.org/meta-raspberrypi
git clone -b dunfell git://git.yoctoproject.org/meta-security.git

These repositories shouldn’t need modifications other then periodic updates and can be reused for different projects or different boards.

Retrieve Magic Lantern common meta-layer changing some upstream package defaults and adding a few custom recipes.

git clone -b dunfell https://github.com/jumpnow/meta-jumpnow

or, the Wizzerworks Magic Lantern fork

git clone -b dunfell https://github.com/WizzerWorks/meta-jumpnow.git

Clone the meta-rpi repositories

Create a separate sub-directory for the meta-rpi repository before cloning. This is where you will be doing your customization.

mkdir ~/rpi
cd ~/rpi
git clone -b dunfell https://github.com/jumpnow/meta-rpi.git

or, the Wizzerworks Magic Lantern fork

git clone -b dunfell https://github.com/WizzerWorks/meta-rpi.git

The meta-rpi/README.md file has the last commits from the dependency repositories that I tested. You can always checkout those commits explicitly if you run into problems.

Clone the meta-magic-lantern repositories

Download the meta-magic-lantern repository in the ~/rpi directory.

git clone git@github.com:magic-lantern-studio/meta-magic-lantern.git

Initialize the build directory

Choose a build directory. I tend to do this on a per board and/or per project basis so I can quickly switch between projects. For this example I’ll put the build directory under ~/rpi/ with the meta-rpi layer.

You could manually create the directory structure like this

mkdir -p ~/rpi/build/conf

Or you could use the Yocto environment script oe-init-build-env like this passing in the path to the build directory

source poky-dunfell/oe-init-build-env ~/rpi/build

The Yocto environment script will create the build directory if it does not already exist.

Customize the configuration files

There are some sample configuration files in the meta-rpi/conf directory.

Copy them to the build/conf directory (removing the ‘-sample’)

cp meta-rpi/conf/local.conf.sample build/conf/local.conf
cp meta-rpi/conf/bblayers.conf.sample build/conf/bblayers.conf

If you used the oe-init-build-env script to create the build directory, it generated some generic configuration files in the build/conf directory. If you want to look at them, save them with a different name before overwriting.

It is not necessary, but you may want to customize the configuration files before your first build.

Warning: Do not use the ‘~’ character when defining directory paths in the Yocto configuration files.

Edit bblayers.conf

In bblayers.conf file replace ${HOME} with the appropriate path to the meta-layer repositories on your system if you modified any of the paths in the previous instructions.

Warning: Do not include meta-yocto-bsp in your bblayers.conf. The Yocto BSP requirements for the Raspberry Pi are in meta-raspberrypi.

For example, if your directory structure does not look exactly like this, you will need to modify bblayers.conf

~/poky-dunfell/
    meta-jumpnow/
    meta-openembedded/
    meta-qt5/
    meta-raspberrypi
    ...
~/rpi/
    meta-magic-lantern/
    meta-rpi/
    build/
        conf/

Add the meta-magic-lantern layer to the build/conf/bblayers.conf configuration file:

BBLAYERS ?= " \
    ${HOME}/Projects/poky-dunfell/meta \
    ${HOME}/Projects/poky-dunfell/meta-poky \
    ${HOME}/Projects/poky-dunfell/meta-openembedded/meta-oe \
    ${HOME}/Projects/poky-dunfell/meta-openembedded/meta-multimedia \
    ${HOME}/Projects/poky-dunfell/meta-openembedded/meta-networking \
    ${HOME}/Projects/poky-dunfell/meta-openembedded/meta-perl \
    ${HOME}/Projects/poky-dunfell/meta-openembedded/meta-python \
    ${HOME}/Projects/poky-dunfell/meta-qt5 \
    ${HOME}/Projects/poky-dunfell/meta-raspberrypi \
    ${HOME}/Projects/poky-dunfell/meta-security \
    ${HOME}/Projects/poky-dunfell/meta-jumpnow \
    ${HOME}/Projects/rpi/meta-rpi \
    ${HOME}/Projects/rpi/meta-magic-lantern \
"

Edit local.conf

The variables you may want to customize are the following:

  • MACHINE
  • TMPDIR
  • DL_DIR
  • SSTATE_DIR

The defaults for all of these work fine with the exception of MACHINE.

MACHINE Environment Variable

The MACHINE variable is used to determine the target architecture and various compiler tuning flags.

See the conf files under meta-raspberrypi/conf/machine for details.

The choices for MACHINE are

  • raspberrypi (BCM2835)
  • raspberrypi0 (BCM2835)
  • raspberrypi0-wifi (BCM2835)
  • raspberrypi2 (BCM2836 or BCM2837 v1.2+)
  • raspberrypi3 (BCM2837)
  • raspberrypi4 (BCM2838)
  • raspberrypi-cm (BCM2835)
  • raspberrypi-cm3 (BCM2837)

You can only build for one type of MACHINE at a time.

There are really just two tuning families using the default Yocto configuration files

  • arm1176jzfshf - for the the BCM2835 boards
  • cortexa7thf-neon-vfpv4 - for the BCM2836 and BCM2837 boards

Boards in the same family can generally run the same software.

One exception is u-boot, which is NOT the default for the systems being built here.

One of the reasons you would want to use u-boot with the RPIs is to work with the Mender upgrade system.

TMPDIR Environment Variable

This is where temporary build files and the final build binaries will end up. Expect to use at least 50GB.

The default location is under the build directory, in this example ~/rpi/build/tmp.

If you specify an alternate location as I do in the example conf file make sure the directory is writable by the user running the build.

DL_DIR Environment Variable

This is where the downloaded source files will be stored. You can share this among configurations and builds so I always create a general location for this outside the project directory. Make sure the build user has write permission to the directory you decide on.

The default location is in the build directory, ~/rpi/build/sources.

SSTATE_DIR Environment Variable

This is another Yocto build directory that can get pretty big, greater then 8GB. I often put this somewhere else other then my home directory as well.

The default location is in the build directory, ~/rpi/build/sstate-cache.

ROOT PASSWORD

There is only one login user by default, root.

The default password is set to jumpnowtek by these two lines in the local.conf file

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -P jumpnowtek root; "

These two lines force a password change on first login

INHERIT += "chageusers"
CHAGE_USERS_PARAMS = "chage -d0 root; "

You can comment them out if you do not want that behavior.

If you want no password at all (development only hopefully), comment those four lines and uncomment this line

EXTRA_IMAGE_FEATURES = "debug-tweaks"

#INHERIT += "extrausers"
#EXTRA_USERS_PARAMS = "usermod -P jumpnowtek root; "

#INHERIT += "chageusers"
#CHAGE_USERS_PARAMS = "chage -d0 root; "

You can always add or change the password once logged in.

Add Magic Lantern Packages

Add the Magic Lantern Studio components to the image. In local.conf add the following:

# Add Magic Lantern packages.
IMAGE_INSTALL_append = " libmlutil"

Build the Raspberry Pi Image

Initialize build environment

You need to source the Yocto environment into your shell before you can use bitbake. The oe-init-build-env will not overwrite your customized conf files.

source poky-dunfell/oe-init-build-env ~/rpi/build

### Shell environment set up for builds. ###

You can now run 'bitbake '

Common targets are:
    core-image-minimal
    core-image-sato
    meta-toolchain
    meta-toolchain-sdk
    adt-installer
    meta-ide-support

You can also run generated qemu images with a command like 'runqemu qemux86'

I don’t use any of those Common targets, but instead always write my own custom image recipes.

The meta-rpi layer has some examples under meta-rpi/images/.

Build the image

To build the console-image run the following command in the ~/rpi/build directory.

bitbake console-image

The results will be found in the $TMPDIR/deploy/images/$MACHINE directory. For example, ~/rpi/build/tmp/deploy/images/raspberrypi3. You should see a file called console-image-raspberrypi3.tar.xz

If you want to generate an .img file, then add it to the IMAGE_FSTYPES variable in local.conf. For example

IMAGE_FSTYPES = "tar.xz ext3 rpi-sdimg"

will create console-image-raspberrypi3.rpi-sdimg.

Additional image targets

In addition to the console-image target, you can also build the following:

  • audio-image
  • py3qt-image
  • qt5-basic-image
  • qt5-image

Bitbake build targets

Useful bitbake build target information can be found on the Raspberry Pi Build Targets wiki.

Flash the image

Instructions for writing the image to an SD card may be found on the Raspberry Pi Investigation Flash Instructions wiki page.

Clone this wiki locally