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ā€¦