How to configure networking using systemd in Yocto Project

the symlink appears. But for some reason I have to always restart the service(systemd-networkd) to get it work.

On every bootup. This started happening only after I moved .network file to my persistent data.

Check that networkd is not running before data partition is mounted

Assuming you have systemd-analyze installed
run ā€˜systemd-analyze plot > services.svgā€™
copy the svg to your machine and open in your image viewer (chrome will open it nicely and make it searchable)
and see if data.mount is happening later than systend-networkd

please give me a few minutes. I have to install systemd-analyze

I suspect that might be happening.
But even then. I would think that it wouldnā€™t run on the first boot. But subsequent bootup should not be having a problem right?

I would expect it to happen everytime as the symlink is broken at the point that systemd-networkd runs

I think you are right. I see my systemd-networkd service starting early than data mount.
Here is my services.png file. It might need a lot of zoom

Now in order to delay my network service. Do I have to create a patch of sorts and call that in a systemd_%.bbappend file?

I would start by using the normal systemd extend mechanism

add a file called something like 99-before-networkd.conf to your recipe folder files folder (must end in .conf)

in this file add the following

[Unit]
Before=systemd-networkd.service

add a SRC_URI entry for it in your bbappend file and add to your FILES variable just like you have done for your .network file.

in your do_install_append() function install the file to
/etc/systemd/system/data.mount.d/99-before-networkd.conf

https://www.freedesktop.org/software/systemd/man/systemd.unit.html#

1 Like

That did the trick.

1 Like

@drewmoseley Iā€™ve got it to work by linking wpa_supplicant-nl80211@.service instead of wpa_supplicant@.service.
In this case, it will go fetch the correct conf file (wpa_supplicant-nl80211@wlan0.conf)

ln -s ${systemd_unitdir}/system/wpa_supplicant@.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service

becomes

ln -s ${systemd_unitdir}/system/wpa_supplicant-nl80211@.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service
1 Like

Welcome and yer thatā€™s what had to to do also :slight_smile:

1 Like

hi,
is there a specific reason as why not to use the default /etc/wpa_supplicant.conf for configuration?

Hi @simonbuehler,

just because it is not persisted across system updates by default: the A/B partitions should be treated as completely transient. For anything that requires persistence, moving out to /data for example is needed.

Greetz,
Josef

Iā€™m trying to boot up a Raspberry Pi Zero W with WiFi.

After some days struggling with this, compiling, recompiling, I still cannot see the wlan0 interface on Raspberry Pi Zero W.

ifconfig shows only the lo interface:

Iā€™ve followed all the step 7 and Iā€™m getting the following error when booting up (in picture above):

$ dmesg | grep wlan
[    5.819020] systemd[1]: multi-user.target; Wants dependency dropin /etc/systemd/system/multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service target /lib/systemd/system/wpa_supplicant@.service has different name

Iā€™m using Yocto Kirkstone version.

Here is are my current configuration files:

$ cat build/conf/local.conf

MACHINE ??= "qemux86-64"
DISTRO ?= "poky"
PACKAGE_CLASSES ?= "package_rpm"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
USER_CLASSES ?= "buildstats"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS ??= "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    STOPTASKS,/tmp,100M,100K \
    HALT,${TMPDIR},100M,1K \
    HALT,${DL_DIR},100M,1K \
    HALT,${SSTATE_DIR},100M,1K \
    HALT,/tmp,10M,1K"
PACKAGECONFIG:append:pn-qemu-system-native = " sdl"
CONF_VERSION = "2"
MACHINE = "raspberrypi0-wifi"
MENDER_ARTIFACT_NAME = "release-1"
INHERIT += "mender-full"
RPI_USE_U_BOOT = "1"
MENDER_BOOT_PART_SIZE_MB = "40"
IMAGE_INSTALL:append = " kernel-image kernel-devicetree"
IMAGE_FSTYPES:remove = "rpi-sdimg"
MENDER_SERVER_URL = "https://hosted.mender.io"
MENDER_TENANT_TOKEN = "mender...token"
DISTRO_FEATURES:append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
INIT_MANAGER = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""
IMAGE_FSTYPES = "ext4"
DISTRO_FEATURES:append = " wifi "
IMAGE_INSTALL:append = " linux-firmware-rpidistro-bcm43430 "
$ cat conf/layer.conf
# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
            ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-stargazer"
BBFILE_PATTERN_meta-stargazer = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-stargazer = "6"

LAYERDEPENDS_meta-stargazer = "core"
LAYERSERIES_COMPAT_meta-stargazer = "kirkstone"
$ cat /home/quadfloor/release_1/src/meta-stargazer/recipes-connectivity/wpa-supplicant/wpa-supplicant_%.bbappend

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRC_URI += "file://wpa_supplicant-nl80211-wlan0.conf"

SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE:${PN}:append = " wpa_supplicant-nl80211@wlan0.service  "

do_install:append () {
   install -d ${D}${sysconfdir}/wpa_supplicant/
   install -D -m 600 ${WORKDIR}/wpa_supplicant-nl80211-wlan0.conf ${D}${sysconfdir}/wpa_supplicant/

   install -d ${D}${sysconfdir}/systemd/system/multi-user.target.wants/
   ln -s ${systemd_unitdir}/system/wpa_supplicant-nl80211@.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service}
}
$ cat /home/quadfloor/release_1/src/meta-stargazer/recipes-connectivity/wpa-supplicant/files/wpa_supplicant-nl80211-wlan0.conf
network={
	ssid="TESTWIFI"
	#psk="..."
	psk=... // Actual password psk
}

Iā€™ve tried ElioDreamā€™s comment and changed configuration, but still same error.

Iā€™ve installed RaspiOs to check hardware defect and the WiFi works nicelyā€¦

No idea of what can be done to solve this - Iā€™m really with no ideas - help appreciatedā€¦

Hi all,

some time has passed on this topic but I hope someone can help me on this one.
Iā€™m getting acquainted with yocto for a custom build on an imx8mp-var-dart with a fsl-imx-wayland distro aligned on yocto mickledore.

Iā€™ve created my own custom image starting from core-image-full-cmdline where I added my packages for python, and so far so good. Then Iā€™m trying to set a static ip address for my eth connection. I tried following step by step the procedure but nothing seems to work (even looking through all the comments).

No connection starts at boot unless I bring it up manually (ifup) and my systemd has no networkd service

root@imx8mp-var-dart:/etc/systemd/network# systemctl enable systemd.networkd
Failed to enable unit: Unit file systemd.networkd.service does not exist.

I also noticed these files in /etc/systemd/network
99-default.link
89-unmanage.network
but by removing them manually and rebooting nothing changes.

Is there any particular package that needs to be included for this to work?

Iā€™m honestly stranded, does anyone know how to tackle this?

thanks a lot

Hi @iitsam,

If ā€œnothing worksā€ around networkd, then the first and foremost thing to check is if it is actually installed and enabled. The PACKAGECONFIG assignment is given in the tutorial, but as youā€™re using a non-standard distribution as base (fsl-imx-wayland), my guess would be that there is some form of conflict.

Things to do now:

  • bitbake -e systemd | less and check if the assignment actually takes effect.
  • check your image if an alternate network manager is in effect like NetworkManager, or such.

Greetz,
Josef

Hi @TheYoctoJester

thank you for taking your time with this.
To be fair, the output of the systemd env is quite verbose. Even though I see that systemd gets processed, I do not fully understand what I should I be looking for for possible issues.

Iā€™m quite confident there are not other network manager on my image.

root@imx8mp-var-dart:~# systemctl status NetworkManager
Unit NetworkManager.service could not be found.

I still have ifupdown on it but no interfaces file, so it shouldnā€™t create conflict (??).

cheers,
Sam

Thanks to @TheYoctoJester I started diggin more into che possible systemd conflicts created by the Variscite BSP. Grepping around the bitbake environment didnā€™t really help, but by looking through the various systemd .bbappend I found that the networkd package was specifically removed.

I also found this thread on stack overflow that summarize perfectly the situation.

Now I only have to test the wlan connection.

EDIT: note that the initial setup advised by this tutorial to add networkd and resolved didnā€™t work. Not even by increasing the priority of my custom layer to be processed as the last one. The solution in the link also proposes a workaround thatā€™s not really clear to me, but does the job rather than manually changing the incriminated layer.