Skip to content

Instantly share code, notes, and snippets.

@decagondev
Last active July 1, 2025 18:01
Show Gist options
  • Save decagondev/6c91903f904b164998363b0cf97a2604 to your computer and use it in GitHub Desktop.
Save decagondev/6c91903f904b164998363b0cf97a2604 to your computer and use it in GitHub Desktop.

Building a Yocto Linux Image with Node.js, GCC, and npm for a 64-bit Arm Target

This guide describes how to build a Yocto Linux image for a 64-bit Arm target using the Poky reference distribution (tag yocto-5.0.10, part of the scarthgap release), including Node.js, GCC, and npm. It uses the scarthgap branch for meta-openembedded to ensure compatibility with Yocto 5.0, resolving the previous pathspec 'yocto-5.0.10' error.

Prerequisites

Ensure you have a Linux system (e.g., Ubuntu) with sufficient disk space (20-50 GB recommended) and memory. The build process requires a robust development environment.

Step 1: Install Required Packages

Install the necessary packages for building and running Yocto:

sudo apt update
sudo apt-get install -y gawk wget git-core diffstat unzip texinfo build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libgl1 libglx-mesa0 libsdl1.2-dev pylint xterm python3-subunit mesa-common-dev lz4

Step 2: Download Poky and meta-openembedded

Clone the Poky reference distribution and check out the yocto-5.0.10 tag (part of the scarthgap release):

cd /home/mint
git clone git://git.yoctoproject.org/poky
cd poky
git checkout tags/yocto-5.0.10 -b yocto-5.0.10-local

Clone the meta-openembedded repository, which contains the meta-oe layer required for Node.js, and check out the scarthgap branch (compatible with Yocto 5.0):

cd /home/mint
git clone git://git.openembedded.org/meta-openembedded
cd meta-openembedded
git checkout scarthgap

Note: The scarthgap branch in meta-openembedded is compatible with Poky’s yocto-5.0.10 (Yocto 5.0 release).

Step 3: Initialize the Build Environment

Source the environment script to set up the build environment for the 64-bit Arm QEMU target:

cd /home/mint/poky
source oe-init-build-env build-qemu-arm64

This creates a build-qemu-arm64 directory with configuration files (conf/local.conf and conf/bblayers.conf) and sets up the build environment. The output will suggest common targets like core-image-full-cmdline.

Step 4: Configure the Target Machine

Set the target machine to qemuarm64 by uncommenting the relevant line in conf/local.conf:

sed -i '/qemuarm64/s/^#//g' conf/local.conf

Step 5: Add meta-openembedded to bblayers.conf

Add the meta-oe layer to conf/bblayers.conf to include the Node.js recipe. Append the following line to the BBLAYERS variable:

echo 'BBLAYERS += "/home/mint/meta-openembedded/meta-oe"' >> conf/bblayers.conf

Alternatively, manually edit conf/bblayers.conf with a text editor (e.g., nano) to include:

BBLAYERS ?= " \
  /home/mint/poky/meta \
  /home/mint/poky/meta-poky \
  /home/mint/poky/meta-yocto-bsp \
  /home/mint/meta-openembedded/meta-oe \
"

Step 6: Add Node.js, GCC, and npm to the Image

Modify conf/local.conf to include Node.js, GCC, and npm in the core-image-full-cmdline image by appending:

echo 'IMAGE_INSTALL:append = " nodejs gcc g++"' >> conf/local.conf

Note: The nodejs recipe includes npm, and gcc and g++ provide the C and C++ compilers.

Step 7: Unlock Unprivileged User Namespace (if needed)

On modern Ubuntu systems, disable AppArmor restrictions for unprivileged user namespaces:

sudo echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns

Step 8: Build the Image

Build the core-image-full-cmdline image, which now includes Node.js, GCC, and npm:

cd /home/mint/poky/build-qemu-arm64
bitbake core-image-full-cmdline

This process may take an hour or more, depending on your machine's performance. The resulting images will be located in build-qemu-arm64/tmp/deploy/images/qemuarm64.

Step 9: Run the Image on QEMU

Launch the built image on the 64-bit Arm QEMU target without a graphical interface:

runqemu qemuarm64 nographic

The Linux system will boot on your console. Log in with the username root (no password required).

Step 10: Verify the Installation

Check the Linux distribution and architecture:

uname -a

Expected output (version may vary slightly):

Linux qemuarm64 5.15.78-yocto-standard #1 SMP PREEMPT Wed Nov 16 14:17:41 UTC 2022 aarch64 GNU/Linux

Verify that Node.js, npm, and GCC are installed:

node --version
npm --version
gcc --version

Example outputs (versions may vary depending on the scarthgap branch):

node --version
v18.12.1

npm --version
8.19.2

gcc --version
gcc (GCC) 11.3.0

Step 11: Exit QEMU

To exit QEMU, press Ctrl-a followed by x.

Conclusion

You have successfully built and run a Yocto Linux image with Node.js, GCC, and npm on a 64-bit Arm QEMU target. Using the scarthgap branch for meta-openembedded ensures compatibility with Poky’s yocto-5.0.10 (Yocto 5.0 release), resolving the pathspec 'yocto-5.0.10' error.

Troubleshooting

  • Layer Errors: Ensure the meta-openembedded branch is scarthgap to match Poky’s yocto-5.0.10. Verify paths in bblayers.conf.
  • Git Error: If you encounter pathspec errors, run git fetch --tags in the meta-openembedded repository to ensure all branches are available, then confirm the scarthgap branch exists with git branch -r.
  • Build Time: Adding nodejs, gcc, and npm increases build time and disk usage.
  • Further Help: Consult the Yocto Project documentation at https://docs.yoctoproject.org or the OpenEmbedded website at https://www.openembedded.org/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment