Building a x86 Linux image on MAC using crops/poky docker
Setup the hardware?
The build is going to be done on a MAC mini with Apple Silicon.
Make sure that Docker Desktop is installed and running the latest version.
Download the image to use:
docker pull crops/poky:ubuntu-22.04
Once that is complete, check if the image is downloaded:
docker images
Output looks like this
IMAGE : crops/poky:ubuntu-22.04, ID : b9c23dda3
Create a shared volume that will keep the downloaded git code and also the compiled directories like sstate-cache and downloads. These two directories are critical to keep around as they will fill up the first run, but subsequent versions will only be rebuilt is something changes.
Startup the docker image
Use this command to start the docker image
docker run -it --platform linux/amd64 --name my-poky-container -v /Users/anilve/code/YoctoSamples/simplepoky:/workdir crops/poky:ubuntu-22.04 /bin/bash
Explaining this command:
docker run command is to run an image
--it is saying we want an interactive terminal
--platform linux/amd64 is specifically for the MAC hardware running on Apple Silicon. That is a ARM based hardware. If you do not add this, it assume a Intel based x86 hardware and you get errors on the MAC.
--name gives the name to th container when it is running
-v (local directory on workstation):(directory to map on the container). This is a local directory on your workstation that is mapped to a shared directory on the linux container. Makes it easy for disk space to grow as you get git code and also compile it.
crops/poky:ubuntu-22.04 is the name of the image to use.
/bin/bash is the script to use when the container terminal starts up.
Setting up poky and bitbake.
Change to the workdir:
cd /workdir
Clone the git code for poky that is labelled as scarthgap
git clone -b scarthgap --depth=1 git://git.yoctoproject.org/poky
Once we have cloned the poky, change into the poky directory
cd /workdir/poky
Initialize the poky builder:
source ./oe-init-build-env
A new directory called build is created under the /workdir/poky
This has also setup bitbake with the path and directories needed.
/workdir/poky/build/conf directory has configuration files.
bblayers.conf - which layers are included in the BB.
local.conf - Various settings including the default machine we are compiling for. Leaving the default as qemux86-64.
On a Mac, the shared location is not case sensitive and you will get an error. You can resolve this two ways:
Create a new disk that is case sensitive
Setup a temp directory on the docker since that is a case sensitive OS
Lets create a new directory /home/pokyuser/tempdir
mkdir /home/pokyuser/tempdir
Update the local conf file
Set the TMPDIR
TMPDIR = "/home/pokyuser/tempdir"
To enable this feature, add the following line to your conf/local.conf file:
INHERIT += "rm_work"
Update the thread and parallel make in local.conf
BB_NUMBER_THREADS = "2"
PARALLEL_MAKE = "-j 2"
Run the bitbake command to build
We shall run a basic core minimal build.
bitbake core-image-minimal
You will see output like this:
Loading cache: 100%
Loaded 0 entries from dependency cache.
Parsing recipes: 100%
Parsing of 920 .bb files complete (0 cached, 920 parsed). 1878 targets, 47 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "2.8.1"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "ubuntu-22.04"
TARGET_SYS = "x86_64-poky-linux"
MACHINE = "qemux86-64"
DISTRO = "poky"
DISTRO_VERSION = "5.0.17"
TUNE_FEATURES = "m64 core2"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "scarthgap:8643f911602949518c5c5474726b49f943e36b83"
The build could take upto 7-8 hours when run for the first time.
Once done, where are the files available?
The output of the bitbake command is sent into the temp directory's deploy subdirectory.
Since we have only one hardware selected as output in the local.conf, you can find the built files here:
/home/pokyuser/tempdir/deploy/images/qemux86-64
Here is the list of files that were generated for me:
pokyuser@eee20d175a47:~/tempdir/deploy/images/qemux86-64$ ls -al
bzImage--6.6.123+git0+17375dce17_af240d7d57-r0-qemux86-64-20260414200504.bin
core-image-minimal-qemux86-64.rootfs-20260414200504.ext4
core-image-minimal-qemux86-64.rootfs-20260414200504.manifest
core-image-minimal-qemux86-64.rootfs-20260414200504.qemuboot.conf
core-image-minimal-qemux86-64.rootfs-20260414200504.spdx.tar.zst
core-image-minimal-qemux86-64.rootfs-20260414200504.tar.bz2
core-image-minimal-qemux86-64.rootfs-20260414200504.testdata.json
modules--6.6.123+git0+17375dce17_af240d7d57-r0-qemux86-64-20260414200504.tgz
GitHub References
This data is also available in GitHub here:
Github Yocto Scartgap Build on Mac using Poky
Blog Series
This article is the fifth in the series. Check out the previous four here:
First: https://www.bearcreektech.com/blog/tailoring-custom-linux-with-yocto-scarthgap-introduction
Second: https://www.bearcreektech.com/blog/bake-your-own-custom-linux-w-bitbake
Third: https://www.bearcreektech.com/blog/part-3-using-poky-to-build-linux-images
Fourth: https://www.bearcreektech.com/blog/setting-up-the-foundation-for-yocto-builds