This guide sets up Yocto for a Raspberry Pi 4, using the scarthgap branch and enabling SSH access via Dropbear. It also includes steps for setting up Wi-Fi credentials, using the ghcr.io/crops/poky:ubuntu-22.04 Docker image, and configuring Shared State Cache for faster builds.
-
Docker: Ensure Docker is installed and running:
sudo apt update sudo apt install docker.io sudo systemctl start docker sudo systemctl enable docker -
Docker Permissions: Add your user to the Docker group:
sudo usermod -aG docker $USER newgrp docker -
Balena Etcher: Download and install Balena Etcher to flash images onto the SD card.
-
Pull the CROPS Docker Image:
docker pull ghcr.io/crops/poky:ubuntu-22.04
-
Create a Working Directory:
mkdir ~/yocto-work -
Start the CROPS Container: Run the following command to start the container with your working directory mounted:
docker run --rm -it -v ~/yocto-work:/workdir ghcr.io/crops/poky:ubuntu-22.04 --workdir=/workdirThis opens a shell in the CROPS environment with access to your
~/yocto-workdirectory as/workdirinside the container.
-
Clone Yocto and Required Layers: Inside the CROPS container, run:
cd /workdir git clone -b scarthgap git://git.yoctoproject.org/poky.git cd poky git clone -b scarthgap git://git.yoctoproject.org/meta-raspberrypi git clone -b scarthgap git://git.openembedded.org/meta-openembedded
-
Source the Yocto Build Environment:
source oe-init-build-env -
Configure Layer Paths: Open
conf/bblayers.confand add paths to themeta-raspberrypiandmeta-openembeddedlayers:BBLAYERS ?= " \ /workdir/poky/meta \ /workdir/poky/meta-poky \ /workdir/poky/meta-yocto-bsp \ /workdir/poky/meta-raspberrypi \ /workdir/poky/meta-openembedded/meta-oe \ /workdir/poky/meta-openembedded/meta-networking \ /workdir/poky/meta-openembedded/meta-python \ " -
Configure Build Settings: In
conf/local.conf, set up the target machine, enable SSH, add Dropbear, configure SSTATE, and add Wi-Fi support:MACHINE = "raspberrypi4" DISTRO_FEATURES:append = " wifi" IMAGE_INSTALL:append = " wpa-supplicant dropbear" # Configure Shared State Cache (SSTATE) Mirrors SSTATE_MIRRORS ?= "file://.* https://sstate.yoctoproject.org/dev/PATH;downloadfilename=PATH" # Enable Hash Equivalence for faster rebuilds ENABLE_CACHE = "1" BB_HASHSERVE = "auto" BB_HASHSERVE_UPSTREAM = "hashserv.yoctoproject.org:8687"
-
Create
wpa_supplicant.conf: In thepokydirectory, create awpa_supplicant.conffile with your Wi-Fi network credentials:ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YourNetworkSSID" psk="YourNetworkPassword" key_mgmt=WPA-PSK } -
Copy
wpa_supplicant.confto the Yocto Root Filesystem: To ensure the Raspberry Pi uses your Wi-Fi credentials on boot, modifylocal.confto include thewpa_supplicant.conffile in the root filesystem:FILES_${PN}-base += "/etc/wpa_supplicant.conf" -
Add
wpa_supplicant.confto the Image Recipe: To include this file during the build, edit your image recipe or create a new.bbappendfile (e.g.,core-image-base.bbappend) in your layer to copywpa_supplicant.conf:install -m 644 ${WORKDIR}/wpa_supplicant.conf ${D}/etc/wpa_supplicant.conf
-
Run Bitbake to Build the Image: Inside the CROPS container, use
bitbaketo build the desired image (e.g.,core-image-base):bitbake core-image-base
This process may take some time. The output image file will be located in the
tmp/deploy/images/raspberrypi4directory within your Yocto build directory.
-
Locate the Output Image: The built image should be in:
/workdir/poky/build/tmp/deploy/images/raspberrypi4/core-image-base-raspberrypi4.wic -
Use Balena Etcher to Write the Image to the SD Card:
- Open Balena Etcher.
- Select the
.wicimage file located in the directory above. - Select your SD card as the target.
- Click "Flash!" and wait for the process to complete.
-
Insert the SD Card into the Raspberry Pi 4: Once flashing is complete, insert the SD card into your Raspberry Pi 4, connect power, and it should boot with the configured SSH access and Wi-Fi credentials.